Compare commits
3 Commits
926abae31b
...
8b425898a1
Author | SHA1 | Date | |
---|---|---|---|
8b425898a1 | |||
f3219b8eb1 | |||
1d9b26cd4e |
|
@ -84,6 +84,7 @@ 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
|
||||||
|
@ -102,8 +103,9 @@ 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, &@block : Order(N) -> Nil)
|
def initialize(@priority : Int32 = 0, @group : Symbol = :default, @station : Station(N)? = nil, @keep : Bool = false, &@block : Order(N) -> Nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io : IO) : Nil
|
def to_s(io : IO) : Nil
|
||||||
|
@ -145,10 +147,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 mode to apply at all time
|
# permanent mode is the default modes to apply at all time
|
||||||
property permanent_mode
|
property permanent_modes : Array(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_mode
|
property temporary_modes : Array(Mode)
|
||||||
|
|
||||||
enum Mode
|
enum Mode
|
||||||
Constant
|
Constant
|
||||||
|
@ -157,17 +159,14 @@ class Vessel(N)
|
||||||
AntiSpeed
|
AntiSpeed
|
||||||
end
|
end
|
||||||
|
|
||||||
@permanent_mode : Mode?
|
|
||||||
@temporary_mode : Mode?
|
|
||||||
|
|
||||||
def initialize(*p, **o)
|
def initialize(*p, **o)
|
||||||
super
|
super
|
||||||
@permanent_mode = nil
|
@permanent_modes = Array(Mode).new
|
||||||
@temporary_mode = nil
|
@temporary_modes = Array(Mode).new
|
||||||
@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 = 10.0
|
@max_thrust = 20.0
|
||||||
@current_selected_body = nil
|
@current_selected_body = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -190,25 +189,37 @@ class Vessel(N)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def immediate_mode
|
def immediate_modes : Array(Mode)
|
||||||
@temporary_mode || @permanent_mode
|
if !@temporary_modes.empty?
|
||||||
|
@temporary_modes
|
||||||
|
else
|
||||||
|
@permanent_modes
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_current_mode
|
def apply_current_mode
|
||||||
if immediate_mode == Mode::AntiGrav
|
new_acceleration_axis = Vector(Float64, N).zero
|
||||||
# somehow it doesn't work as expected... :thinking:
|
must_update_acceleration_axis = false
|
||||||
set_exact_acceleration_axis(-vessel.gravity)
|
if immediate_modes.includes?(Mode::AntiGrav)
|
||||||
elsif immediate_mode == Mode::AntiSpeed
|
must_update_acceleration_axis = true
|
||||||
|
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
|
||||||
if relative_speed.magnitude > @max_thrust
|
new_acceleration_axis.add!(-relative_speed)
|
||||||
relative_speed.normalize.mult!(@max_thrust)
|
|
||||||
end
|
|
||||||
set_exact_acceleration_axis(-relative_speed)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@temporary_mode = nil # each time we apply the temporary_mode, reset it
|
if new_acceleration_axis.magnitude > @max_thrust
|
||||||
|
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,13 +54,16 @@ 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_mode = Vessel::Pilot::Mode::Constant
|
@vessel.pilot.permanent_modes.clear
|
||||||
|
@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
|
||||||
|
@ -70,13 +73,16 @@ 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_mode = Vessel::Pilot::Mode::Constant
|
@vessel.pilot.permanent_modes.clear
|
||||||
|
@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
|
||||||
|
@ -92,9 +98,11 @@ 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_mode = Vessel::Pilot::Mode::Pulse
|
@vessel.pilot.temporary_modes << 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
|
||||||
|
@ -118,9 +126,11 @@ 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_mode = Vessel::Pilot::Mode::Pulse
|
@vessel.pilot.temporary_modes << 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
|
||||||
|
@ -149,6 +159,8 @@ 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
|
||||||
|
@ -159,6 +171,8 @@ 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
|
||||||
|
@ -167,13 +181,42 @@ 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_mode = Vessel::Pilot::Mode::Constant
|
@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.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])
|
||||||
|
@ -183,6 +226,8 @@ 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]
|
||||||
|
@ -198,14 +243,15 @@ module PhysicsSandboxDraw
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
draw_table_line(
|
draw_table_line(
|
||||||
"",
|
"",
|
||||||
# AntiGrav
|
# AntiGrav
|
||||||
->{
|
->{
|
||||||
if @vessel.pilot.permanent_mode != Vessel::Pilot::Mode::AntiGrav
|
if !@vessel.pilot.permanent_modes.includes?(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_mode = Vessel::Pilot::Mode::AntiGrav
|
@vessel.pilot.permanent_modes << 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
|
||||||
|
@ -213,8 +259,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_mode == Vessel::Pilot::Mode::AntiGrav
|
if @vessel.pilot.permanent_modes.includes?(Vessel::Pilot::Mode::AntiGrav)
|
||||||
@vessel.pilot.permanent_mode = nil
|
@vessel.pilot.permanent_modes.delete Vessel::Pilot::Mode::AntiGrav
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -223,10 +269,10 @@ module PhysicsSandboxDraw
|
||||||
|
|
||||||
# AntiSpeed
|
# AntiSpeed
|
||||||
->{
|
->{
|
||||||
if @vessel.pilot.permanent_mode != Vessel::Pilot::Mode::AntiSpeed
|
if !@vessel.pilot.permanent_modes.includes?(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_mode = Vessel::Pilot::Mode::AntiSpeed
|
@vessel.pilot.permanent_modes << 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]
|
||||||
|
@ -235,14 +281,15 @@ 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_mode == Vessel::Pilot::Mode::AntiSpeed
|
if @vessel.pilot.permanent_modes << Vessel::Pilot::Mode::AntiSpeed
|
||||||
@vessel.pilot.permanent_mode = nil
|
@vessel.pilot.permanent_modes.delete Vessel::Pilot::Mode::AntiSpeed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user