Compare commits
No commits in common. "8b425898a1479fb0d85d3c9c40c6b5ec1ca282e7" and "926abae31bc4800e0f785724cc9ddbe6be6b58cb" have entirely different histories.
8b425898a1
...
926abae31b
|
@ -84,7 +84,6 @@ class Vessel(N)
|
||||||
orders.sort!
|
orders.sort!
|
||||||
order = orders.pop # remove last order and execute it
|
order = orders.pop # remove last order and execute it
|
||||||
order.execute
|
order.execute
|
||||||
# orders.unshift order if order.keep
|
|
||||||
order
|
order
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -103,9 +102,8 @@ class Vessel(N)
|
||||||
class Order(N)
|
class Order(N)
|
||||||
setter :station
|
setter :station
|
||||||
getter :priority, :group
|
getter :priority, :group
|
||||||
# property :keep
|
|
||||||
|
|
||||||
def initialize(@priority : Int32 = 0, @group : Symbol = :default, @station : Station(N)? = nil, @keep : Bool = false, &@block : Order(N) -> Nil)
|
def initialize(@priority : Int32 = 0, @group : Symbol = :default, @station : Station(N)? = nil, &@block : Order(N) -> Nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io : IO) : Nil
|
def to_s(io : IO) : Nil
|
||||||
|
@ -147,10 +145,10 @@ class Vessel(N)
|
||||||
property current_selected_body : Gravity::Body(N)?
|
property current_selected_body : Gravity::Body(N)?
|
||||||
# this is a hard limit for thrust so the pilot can avoid killing all the people aboard
|
# this is a hard limit for thrust so the pilot can avoid killing all the people aboard
|
||||||
property max_thrust
|
property max_thrust
|
||||||
# permanent mode is the default modes to apply at all time
|
# permanent mode is the default mode to apply at all time
|
||||||
property permanent_modes : Array(Mode)
|
property permanent_mode
|
||||||
# temporary mode must be set at each tick and will be reset each time it is applied
|
# temporary mode must be set at each tick and will be reset each time it is applied
|
||||||
property temporary_modes : Array(Mode)
|
property temporary_mode
|
||||||
|
|
||||||
enum Mode
|
enum Mode
|
||||||
Constant
|
Constant
|
||||||
|
@ -159,14 +157,17 @@ class Vessel(N)
|
||||||
AntiSpeed
|
AntiSpeed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@permanent_mode : Mode?
|
||||||
|
@temporary_mode : Mode?
|
||||||
|
|
||||||
def initialize(*p, **o)
|
def initialize(*p, **o)
|
||||||
super
|
super
|
||||||
@permanent_modes = Array(Mode).new
|
@permanent_mode = nil
|
||||||
@temporary_modes = Array(Mode).new
|
@temporary_mode = nil
|
||||||
@low_thrust_save = 0.0
|
@low_thrust_save = 0.0
|
||||||
@low_thrust_pressed = false
|
@low_thrust_pressed = false
|
||||||
@computer_input_thrust = Vector(Float64, N).zero
|
@computer_input_thrust = Vector(Float64, N).zero
|
||||||
@max_thrust = 20.0
|
@max_thrust = 10.0
|
||||||
@current_selected_body = nil
|
@current_selected_body = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -189,37 +190,25 @@ class Vessel(N)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def immediate_modes : Array(Mode)
|
def immediate_mode
|
||||||
if !@temporary_modes.empty?
|
@temporary_mode || @permanent_mode
|
||||||
@temporary_modes
|
|
||||||
else
|
|
||||||
@permanent_modes
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_current_mode
|
def apply_current_mode
|
||||||
new_acceleration_axis = Vector(Float64, N).zero
|
if immediate_mode == Mode::AntiGrav
|
||||||
must_update_acceleration_axis = false
|
# somehow it doesn't work as expected... :thinking:
|
||||||
if immediate_modes.includes?(Mode::AntiGrav)
|
set_exact_acceleration_axis(-vessel.gravity)
|
||||||
must_update_acceleration_axis = true
|
elsif immediate_mode == Mode::AntiSpeed
|
||||||
new_acceleration_axis.add!(-vessel.gravity)
|
|
||||||
end
|
|
||||||
|
|
||||||
if immediate_modes.includes?(Mode::AntiSpeed)
|
|
||||||
must_update_acceleration_axis = true
|
|
||||||
reset_acceleration = true
|
|
||||||
if (current_selected_body = @current_selected_body)
|
if (current_selected_body = @current_selected_body)
|
||||||
relative_speed = vessel.gravity_body.speed - current_selected_body.speed
|
relative_speed = vessel.gravity_body.speed - current_selected_body.speed
|
||||||
new_acceleration_axis.add!(-relative_speed)
|
if relative_speed.magnitude > @max_thrust
|
||||||
|
relative_speed.normalize.mult!(@max_thrust)
|
||||||
|
end
|
||||||
|
set_exact_acceleration_axis(-relative_speed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if new_acceleration_axis.magnitude > @max_thrust
|
@temporary_mode = nil # each time we apply the temporary_mode, reset it
|
||||||
new_acceleration_axis.normalize.mult!(@max_thrust)
|
|
||||||
end
|
|
||||||
set_exact_acceleration_axis(new_acceleration_axis) if must_update_acceleration_axis
|
|
||||||
|
|
||||||
@temporary_modes.clear # each time we apply the temporary_mode, reset it
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def accelerate_current_vector!(coef : Float64)
|
def accelerate_current_vector!(coef : Float64)
|
||||||
|
|
|
@ -54,16 +54,13 @@ module PhysicsSandboxDraw
|
||||||
draw_slider(
|
draw_slider(
|
||||||
label: "###acceleration_analogue_x",
|
label: "###acceleration_analogue_x",
|
||||||
data: @vessel.gravity_body.acceleration[0],
|
data: @vessel.gravity_body.acceleration[0],
|
||||||
min: -@vessel.pilot.max_thrust,
|
|
||||||
max: @vessel.pilot.max_thrust,
|
|
||||||
flags: (
|
flags: (
|
||||||
ImGui::ImGuiSliderFlags::Logarithmic
|
ImGui::ImGuiSliderFlags::Logarithmic
|
||||||
),
|
),
|
||||||
) do |value|
|
) do |value|
|
||||||
@vessel.pilot.order(priority: 10, group: :acceleration_x) do
|
@vessel.pilot.order(priority: 10, group: :acceleration_x) do
|
||||||
@vessel.pilot.set_exact_acceleration_axis(0, value)
|
@vessel.pilot.set_exact_acceleration_axis(0, value)
|
||||||
@vessel.pilot.permanent_modes.clear
|
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::Constant
|
||||||
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::Constant
|
|
||||||
@vessel.pilot.low_thrust_pressed = false
|
@vessel.pilot.low_thrust_pressed = false
|
||||||
@vessel.pilot.low_thrust_save = value
|
@vessel.pilot.low_thrust_save = value
|
||||||
end
|
end
|
||||||
|
@ -73,16 +70,13 @@ module PhysicsSandboxDraw
|
||||||
draw_slider(
|
draw_slider(
|
||||||
label: "###acceleration_analogue_y",
|
label: "###acceleration_analogue_y",
|
||||||
data: @vessel.gravity_body.acceleration[1],
|
data: @vessel.gravity_body.acceleration[1],
|
||||||
min: -@vessel.pilot.max_thrust,
|
|
||||||
max: @vessel.pilot.max_thrust,
|
|
||||||
flags: (
|
flags: (
|
||||||
ImGui::ImGuiSliderFlags::Logarithmic
|
ImGui::ImGuiSliderFlags::Logarithmic
|
||||||
),
|
),
|
||||||
) do |value|
|
) do |value|
|
||||||
@vessel.pilot.order(priority: 10, group: :acceleration_y) do
|
@vessel.pilot.order(priority: 10, group: :acceleration_y) do
|
||||||
@vessel.pilot.set_exact_acceleration_axis(1, value)
|
@vessel.pilot.set_exact_acceleration_axis(1, value)
|
||||||
@vessel.pilot.permanent_modes.clear
|
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::Constant
|
||||||
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::Constant
|
|
||||||
@vessel.pilot.low_thrust_pressed = false
|
@vessel.pilot.low_thrust_pressed = false
|
||||||
@vessel.pilot.low_thrust_save = value
|
@vessel.pilot.low_thrust_save = value
|
||||||
end
|
end
|
||||||
|
@ -98,11 +92,9 @@ module PhysicsSandboxDraw
|
||||||
draw_slider(
|
draw_slider(
|
||||||
label: "###acceleration_low_analogic_x",
|
label: "###acceleration_low_analogic_x",
|
||||||
data: @vessel.gravity_body.acceleration[0],
|
data: @vessel.gravity_body.acceleration[0],
|
||||||
min: -@vessel.pilot.max_thrust,
|
|
||||||
max: @vessel.pilot.max_thrust,
|
|
||||||
) do |value|
|
) do |value|
|
||||||
@vessel.pilot.order(priority: 10, group: :maneuvers) do
|
@vessel.pilot.order(priority: 10, group: :maneuvers) do
|
||||||
@vessel.pilot.temporary_modes << Vessel::Pilot::Mode::Pulse
|
@vessel.pilot.temporary_mode = Vessel::Pilot::Mode::Pulse
|
||||||
if !@vessel.pilot.low_thrust_pressed
|
if !@vessel.pilot.low_thrust_pressed
|
||||||
@vessel.pilot.low_thrust_save = @vessel.gravity_body.acceleration[0]
|
@vessel.pilot.low_thrust_save = @vessel.gravity_body.acceleration[0]
|
||||||
end
|
end
|
||||||
|
@ -126,11 +118,9 @@ module PhysicsSandboxDraw
|
||||||
draw_slider(
|
draw_slider(
|
||||||
label: "###acceleration_low_analogic_y",
|
label: "###acceleration_low_analogic_y",
|
||||||
data: @vessel.gravity_body.acceleration[1],
|
data: @vessel.gravity_body.acceleration[1],
|
||||||
min: -@vessel.pilot.max_thrust,
|
|
||||||
max: @vessel.pilot.max_thrust,
|
|
||||||
) do |value|
|
) do |value|
|
||||||
@vessel.pilot.order(priority: 10, group: :maneuvers) do
|
@vessel.pilot.order(priority: 10, group: :maneuvers) do
|
||||||
@vessel.pilot.temporary_modes << Vessel::Pilot::Mode::Pulse
|
@vessel.pilot.temporary_mode = Vessel::Pilot::Mode::Pulse
|
||||||
if !@vessel.pilot.low_thrust_pressed
|
if !@vessel.pilot.low_thrust_pressed
|
||||||
@vessel.pilot.low_thrust_save = @vessel.gravity_body.acceleration[1]
|
@vessel.pilot.low_thrust_save = @vessel.gravity_body.acceleration[1]
|
||||||
end
|
end
|
||||||
|
@ -159,8 +149,6 @@ module PhysicsSandboxDraw
|
||||||
draw_input(
|
draw_input(
|
||||||
label: "###acceleration_digit_x",
|
label: "###acceleration_digit_x",
|
||||||
data: @vessel.pilot.computer_input_thrust[0],
|
data: @vessel.pilot.computer_input_thrust[0],
|
||||||
min: -@vessel.pilot.max_thrust,
|
|
||||||
max: @vessel.pilot.max_thrust,
|
|
||||||
) do |value|
|
) do |value|
|
||||||
@vessel.pilot.order(priority: 9, group: :maneuvers) do
|
@vessel.pilot.order(priority: 9, group: :maneuvers) do
|
||||||
@vessel.pilot.computer_input_thrust[0] = value
|
@vessel.pilot.computer_input_thrust[0] = value
|
||||||
|
@ -171,8 +159,6 @@ module PhysicsSandboxDraw
|
||||||
draw_input(
|
draw_input(
|
||||||
label: "###acceleration_digit_y",
|
label: "###acceleration_digit_y",
|
||||||
data: @vessel.pilot.computer_input_thrust[1],
|
data: @vessel.pilot.computer_input_thrust[1],
|
||||||
min: -@vessel.pilot.max_thrust,
|
|
||||||
max: @vessel.pilot.max_thrust,
|
|
||||||
) do |value|
|
) do |value|
|
||||||
@vessel.pilot.order(priority: 9, group: :maneuvers) do
|
@vessel.pilot.order(priority: 9, group: :maneuvers) do
|
||||||
@vessel.pilot.computer_input_thrust[1] = value
|
@vessel.pilot.computer_input_thrust[1] = value
|
||||||
|
@ -181,42 +167,13 @@ module PhysicsSandboxDraw
|
||||||
},
|
},
|
||||||
"m/s²",
|
"m/s²",
|
||||||
)
|
)
|
||||||
|
|
||||||
draw_table_line(
|
|
||||||
"[Security] Max thurst",
|
|
||||||
->{
|
|
||||||
draw_input(
|
|
||||||
label: "###pilot_input_max_thurst",
|
|
||||||
data: @vessel.pilot.max_thrust,
|
|
||||||
min: 9,
|
|
||||||
max: 900,
|
|
||||||
) do |value|
|
|
||||||
@vessel.pilot.max_thrust = value
|
|
||||||
end
|
|
||||||
},
|
|
||||||
->{
|
|
||||||
draw_slider(
|
|
||||||
label: "###pilot_slider_max_thurst",
|
|
||||||
data: @vessel.pilot.max_thrust,
|
|
||||||
min: 9,
|
|
||||||
max: 900,
|
|
||||||
) do |value|
|
|
||||||
@vessel.pilot.max_thrust = value
|
|
||||||
end
|
|
||||||
},
|
|
||||||
->{
|
|
||||||
ImGui.text @vessel.pilot.max_thrust > 20 ? "Inertia Dampers needed" : "No danger"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Manual reset
|
# Manual reset
|
||||||
draw_table_line(
|
draw_table_line(
|
||||||
"",
|
"",
|
||||||
->{
|
->{
|
||||||
if ImGui.button("Comfirm")
|
if ImGui.button("Comfirm")
|
||||||
@vessel.pilot.order(priority: 100, group: :maneuvers) do
|
@vessel.pilot.order(priority: 100, group: :maneuvers) do
|
||||||
@vessel.pilot.permanent_modes.clear
|
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::Constant
|
||||||
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::Constant
|
|
||||||
@vessel.pilot.set_exact_acceleration_axis(@vessel.pilot.computer_input_thrust)
|
@vessel.pilot.set_exact_acceleration_axis(@vessel.pilot.computer_input_thrust)
|
||||||
# @vessel.pilot.set_exact_acceleration_axis(0, @vessel.pilot.computer_input_thrust[0])
|
# @vessel.pilot.set_exact_acceleration_axis(0, @vessel.pilot.computer_input_thrust[0])
|
||||||
# @vessel.pilot.set_exact_acceleration_axis(1, @vessel.pilot.computer_input_thrust[1])
|
# @vessel.pilot.set_exact_acceleration_axis(1, @vessel.pilot.computer_input_thrust[1])
|
||||||
|
@ -226,8 +183,6 @@ module PhysicsSandboxDraw
|
||||||
->{
|
->{
|
||||||
if ImGui.button("Reset")
|
if ImGui.button("Reset")
|
||||||
@vessel.pilot.order(priority: 100, group: :prepare) do
|
@vessel.pilot.order(priority: 100, group: :prepare) do
|
||||||
@vessel.pilot.permanent_modes.clear
|
|
||||||
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::Constant
|
|
||||||
@vessel.pilot.set_exact_acceleration_axis(@vessel.pilot.computer_input_thrust)
|
@vessel.pilot.set_exact_acceleration_axis(@vessel.pilot.computer_input_thrust)
|
||||||
# @vessel.pilot.computer_input_thrust[0] = @vessel.gravity_body.acceleration[0]
|
# @vessel.pilot.computer_input_thrust[0] = @vessel.gravity_body.acceleration[0]
|
||||||
# @vessel.pilot.computer_input_thrust[1] = @vessel.gravity_body.acceleration[1]
|
# @vessel.pilot.computer_input_thrust[1] = @vessel.gravity_body.acceleration[1]
|
||||||
|
@ -243,15 +198,14 @@ module PhysicsSandboxDraw
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
draw_table_line(
|
draw_table_line(
|
||||||
"",
|
"",
|
||||||
# AntiGrav
|
# AntiGrav
|
||||||
->{
|
->{
|
||||||
if !@vessel.pilot.permanent_modes.includes?(Vessel::Pilot::Mode::AntiGrav)
|
if @vessel.pilot.permanent_mode != Vessel::Pilot::Mode::AntiGrav
|
||||||
if ImGui.button("Anti-grav")
|
if ImGui.button("Anti-grav")
|
||||||
@vessel.pilot.order(priority: 10, group: :fly_mode) do
|
@vessel.pilot.order(priority: 10, group: :fly_mode) do
|
||||||
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::AntiGrav
|
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::AntiGrav
|
||||||
# @vessel.gravity_body.acceleration[0] = @vessel.gravity[0]
|
# @vessel.gravity_body.acceleration[0] = @vessel.gravity[0]
|
||||||
# @vessel.gravity_body.acceleration[1] = @vessel.gravity[1]
|
# @vessel.gravity_body.acceleration[1] = @vessel.gravity[1]
|
||||||
end
|
end
|
||||||
|
@ -259,8 +213,8 @@ module PhysicsSandboxDraw
|
||||||
else
|
else
|
||||||
if ImGui.button("Disable anti-grav")
|
if ImGui.button("Disable anti-grav")
|
||||||
@vessel.pilot.order(priority: 11, group: :fly_mode) do
|
@vessel.pilot.order(priority: 11, group: :fly_mode) do
|
||||||
if @vessel.pilot.permanent_modes.includes?(Vessel::Pilot::Mode::AntiGrav)
|
if @vessel.pilot.permanent_mode == Vessel::Pilot::Mode::AntiGrav
|
||||||
@vessel.pilot.permanent_modes.delete Vessel::Pilot::Mode::AntiGrav
|
@vessel.pilot.permanent_mode = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -269,10 +223,10 @@ module PhysicsSandboxDraw
|
||||||
|
|
||||||
# AntiSpeed
|
# AntiSpeed
|
||||||
->{
|
->{
|
||||||
if !@vessel.pilot.permanent_modes.includes?(Vessel::Pilot::Mode::AntiSpeed)
|
if @vessel.pilot.permanent_mode != Vessel::Pilot::Mode::AntiSpeed
|
||||||
if ImGui.button("Anti-speed")
|
if ImGui.button("Anti-speed")
|
||||||
@vessel.pilot.order(priority: 10, group: :fly_mode) do
|
@vessel.pilot.order(priority: 10, group: :fly_mode) do
|
||||||
@vessel.pilot.permanent_modes << Vessel::Pilot::Mode::AntiSpeed
|
@vessel.pilot.permanent_mode = Vessel::Pilot::Mode::AntiSpeed
|
||||||
@vessel.pilot.current_selected_body = @star.gravity_body
|
@vessel.pilot.current_selected_body = @star.gravity_body
|
||||||
# @vessel.antispeed[0] = @vessel.speed[0]
|
# @vessel.antispeed[0] = @vessel.speed[0]
|
||||||
# @vessel.antispeed[1] = @vessel.speed[1]
|
# @vessel.antispeed[1] = @vessel.speed[1]
|
||||||
|
@ -281,15 +235,14 @@ module PhysicsSandboxDraw
|
||||||
else
|
else
|
||||||
if ImGui.button("Disable anti-speed")
|
if ImGui.button("Disable anti-speed")
|
||||||
@vessel.pilot.order(priority: 11, group: :fly_mode) do
|
@vessel.pilot.order(priority: 11, group: :fly_mode) do
|
||||||
if @vessel.pilot.permanent_modes << Vessel::Pilot::Mode::AntiSpeed
|
if @vessel.pilot.permanent_mode == Vessel::Pilot::Mode::AntiSpeed
|
||||||
@vessel.pilot.permanent_modes.delete Vessel::Pilot::Mode::AntiSpeed
|
@vessel.pilot.permanent_mode = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user