Compare commits
3 Commits
926abae31b
...
8b425898a1
Author | SHA1 | Date | |
---|---|---|---|
8b425898a1 | |||
f3219b8eb1 | |||
1d9b26cd4e |
|
@ -84,6 +84,7 @@ class Vessel(N)
|
|||
orders.sort!
|
||||
order = orders.pop # remove last order and execute it
|
||||
order.execute
|
||||
# orders.unshift order if order.keep
|
||||
order
|
||||
end
|
||||
end
|
||||
|
@ -102,8 +103,9 @@ class Vessel(N)
|
|||
class Order(N)
|
||||
setter :station
|
||||
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
|
||||
|
||||
def to_s(io : IO) : Nil
|
||||
|
@ -145,10 +147,10 @@ class Vessel(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
|
||||
property max_thrust
|
||||
# permanent mode is the default mode to apply at all time
|
||||
property permanent_mode
|
||||
# permanent mode is the default modes to apply at all time
|
||||
property permanent_modes : Array(Mode)
|
||||
# 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
|
||||
Constant
|
||||
|
@ -157,17 +159,14 @@ class Vessel(N)
|
|||
AntiSpeed
|
||||
end
|
||||
|
||||
@permanent_mode : Mode?
|
||||
@temporary_mode : Mode?
|
||||
|
||||
def initialize(*p, **o)
|
||||
super
|
||||
@permanent_mode = nil
|
||||
@temporary_mode = nil
|
||||
@permanent_modes = Array(Mode).new
|
||||
@temporary_modes = Array(Mode).new
|
||||
@low_thrust_save = 0.0
|
||||
@low_thrust_pressed = false
|
||||
@computer_input_thrust = Vector(Float64, N).zero
|
||||
@max_thrust = 10.0
|
||||
@max_thrust = 20.0
|
||||
@current_selected_body = nil
|
||||
end
|
||||
|
||||
|
@ -190,25 +189,37 @@ class Vessel(N)
|
|||
end
|
||||
end
|
||||
|
||||
def immediate_mode
|
||||
@temporary_mode || @permanent_mode
|
||||
def immediate_modes : Array(Mode)
|
||||
if !@temporary_modes.empty?
|
||||
@temporary_modes
|
||||
else
|
||||
@permanent_modes
|
||||
end
|
||||
end
|
||||
|
||||
def apply_current_mode
|
||||
if immediate_mode == Mode::AntiGrav
|
||||
# somehow it doesn't work as expected... :thinking:
|
||||
set_exact_acceleration_axis(-vessel.gravity)
|
||||
elsif immediate_mode == Mode::AntiSpeed
|
||||
new_acceleration_axis = Vector(Float64, N).zero
|
||||
must_update_acceleration_axis = false
|
||||
if immediate_modes.includes?(Mode::AntiGrav)
|
||||
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)
|
||||
relative_speed = vessel.gravity_body.speed - current_selected_body.speed
|
||||
if relative_speed.magnitude > @max_thrust
|
||||
relative_speed.normalize.mult!(@max_thrust)
|
||||
end
|
||||
set_exact_acceleration_axis(-relative_speed)
|
||||
new_acceleration_axis.add!(-relative_speed)
|
||||
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
|
||||
|
||||
def accelerate_current_vector!(coef : Float64)
|
||||
|
|
|
@ -54,13 +54,16 @@ module PhysicsSandboxDraw
|
|||
draw_slider(
|
||||
label: "###acceleration_analogue_x",
|
||||
data: @vessel.gravity_body.acceleration[0],
|
||||
min: -@vessel.pilot.max_thrust,
|
||||
max: @vessel.pilot.max_thrust,
|
||||
flags: (
|
||||
ImGui::ImGuiSliderFlags::Logarithmic
|
||||
),
|
||||
) do |value|
|
||||
@vessel.pilot.order(priority: 10, group: :acceleration_x) do
|
||||
@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_save = value
|
||||
end
|
||||
|
@ -70,13 +73,16 @@ module PhysicsSandboxDraw
|
|||
draw_slider(
|
||||
label: "###acceleration_analogue_y",
|
||||
data: @vessel.gravity_body.acceleration[1],
|
||||
min: -@vessel.pilot.max_thrust,
|
||||
max: @vessel.pilot.max_thrust,
|
||||
flags: (
|
||||
ImGui::ImGuiSliderFlags::Logarithmic
|
||||
),
|
||||
) do |value|
|
||||
@vessel.pilot.order(priority: 10, group: :acceleration_y) do
|
||||
@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_save = value
|
||||
end
|
||||
|
@ -92,9 +98,11 @@ module PhysicsSandboxDraw
|
|||
draw_slider(
|
||||
label: "###acceleration_low_analogic_x",
|
||||
data: @vessel.gravity_body.acceleration[0],
|
||||
min: -@vessel.pilot.max_thrust,
|
||||
max: @vessel.pilot.max_thrust,
|
||||
) do |value|
|
||||
@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
|
||||
@vessel.pilot.low_thrust_save = @vessel.gravity_body.acceleration[0]
|
||||
end
|
||||
|
@ -118,9 +126,11 @@ module PhysicsSandboxDraw
|
|||
draw_slider(
|
||||
label: "###acceleration_low_analogic_y",
|
||||
data: @vessel.gravity_body.acceleration[1],
|
||||
min: -@vessel.pilot.max_thrust,
|
||||
max: @vessel.pilot.max_thrust,
|
||||
) do |value|
|
||||
@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
|
||||
@vessel.pilot.low_thrust_save = @vessel.gravity_body.acceleration[1]
|
||||
end
|
||||
|
@ -149,6 +159,8 @@ module PhysicsSandboxDraw
|
|||
draw_input(
|
||||
label: "###acceleration_digit_x",
|
||||
data: @vessel.pilot.computer_input_thrust[0],
|
||||
min: -@vessel.pilot.max_thrust,
|
||||
max: @vessel.pilot.max_thrust,
|
||||
) do |value|
|
||||
@vessel.pilot.order(priority: 9, group: :maneuvers) do
|
||||
@vessel.pilot.computer_input_thrust[0] = value
|
||||
|
@ -159,6 +171,8 @@ module PhysicsSandboxDraw
|
|||
draw_input(
|
||||
label: "###acceleration_digit_y",
|
||||
data: @vessel.pilot.computer_input_thrust[1],
|
||||
min: -@vessel.pilot.max_thrust,
|
||||
max: @vessel.pilot.max_thrust,
|
||||
) do |value|
|
||||
@vessel.pilot.order(priority: 9, group: :maneuvers) do
|
||||
@vessel.pilot.computer_input_thrust[1] = value
|
||||
|
@ -167,13 +181,42 @@ module PhysicsSandboxDraw
|
|||
},
|
||||
"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
|
||||
draw_table_line(
|
||||
"",
|
||||
->{
|
||||
if ImGui.button("Comfirm")
|
||||
@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(0, @vessel.pilot.computer_input_thrust[0])
|
||||
# @vessel.pilot.set_exact_acceleration_axis(1, @vessel.pilot.computer_input_thrust[1])
|
||||
|
@ -183,6 +226,8 @@ module PhysicsSandboxDraw
|
|||
->{
|
||||
if ImGui.button("Reset")
|
||||
@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.computer_input_thrust[0] = @vessel.gravity_body.acceleration[0]
|
||||
# @vessel.pilot.computer_input_thrust[1] = @vessel.gravity_body.acceleration[1]
|
||||
|
@ -198,14 +243,15 @@ module PhysicsSandboxDraw
|
|||
end
|
||||
},
|
||||
)
|
||||
|
||||
draw_table_line(
|
||||
"",
|
||||
# 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")
|
||||
@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[1] = @vessel.gravity[1]
|
||||
end
|
||||
|
@ -213,8 +259,8 @@ module PhysicsSandboxDraw
|
|||
else
|
||||
if ImGui.button("Disable anti-grav")
|
||||
@vessel.pilot.order(priority: 11, group: :fly_mode) do
|
||||
if @vessel.pilot.permanent_mode == Vessel::Pilot::Mode::AntiGrav
|
||||
@vessel.pilot.permanent_mode = nil
|
||||
if @vessel.pilot.permanent_modes.includes?(Vessel::Pilot::Mode::AntiGrav)
|
||||
@vessel.pilot.permanent_modes.delete Vessel::Pilot::Mode::AntiGrav
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -223,10 +269,10 @@ module PhysicsSandboxDraw
|
|||
|
||||
# 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")
|
||||
@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.antispeed[0] = @vessel.speed[0]
|
||||
# @vessel.antispeed[1] = @vessel.speed[1]
|
||||
|
@ -235,14 +281,15 @@ module PhysicsSandboxDraw
|
|||
else
|
||||
if ImGui.button("Disable anti-speed")
|
||||
@vessel.pilot.order(priority: 11, group: :fly_mode) do
|
||||
if @vessel.pilot.permanent_mode == Vessel::Pilot::Mode::AntiSpeed
|
||||
@vessel.pilot.permanent_mode = nil
|
||||
if @vessel.pilot.permanent_modes << Vessel::Pilot::Mode::AntiSpeed
|
||||
@vessel.pilot.permanent_modes.delete Vessel::Pilot::Mode::AntiSpeed
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
},
|
||||
)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user