From bb539c00cca6788e50c43c383c1b8450b752789e Mon Sep 17 00:00:00 2001 From: yuni Date: Sun, 22 Sep 2024 06:38:44 +0200 Subject: [PATCH] implement reactor overload and shutdown --- src/actor.rs | 6 +++--- src/menu.rs | 20 ++++++++++++++++++++ src/var.rs | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 434e387..832615b 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -27,6 +27,7 @@ pub const POWER_DRAIN_FLASHLIGHT: [f32; 3] = [200e3, 1500e3, 2500e3]; pub const FLASHLIGHT_INTENSITY: [f32; 3] = [10e6, 400e6, 2e9]; // in lumens pub const POWER_DRAIN_LIGHTAMP: [f32; 4] = [0.0, 200e3, 400e3, 800e3]; pub const POWER_DRAIN_AR: f32 = 300e3; +pub const POWER_GAIN_REACTOR: [f32; 3] = [0.0, 2000e3, 10000e3]; pub struct ActorPlugin; impl Plugin for ActorPlugin { @@ -259,7 +260,6 @@ const SUIT_SIMPLE: Suit = Suit { pub struct Battery { pub power: f32, // Watt-seconds pub capacity: f32, // Watt-seconds - pub reactor: f32, // Watt (production) pub overloaded_recovering: bool, } @@ -268,7 +268,6 @@ impl Default for Battery { Self { power: 10e3 * 3600.0, capacity: 10e3 * 3600.0, // 10kWh - reactor: 2000e3, // 2MW overloaded_recovering: false, } } @@ -329,7 +328,8 @@ pub fn update_power( if power_down { ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::PowerDown)); } - battery.power = (battery.power + battery.reactor * d).clamp(0.0, battery.capacity); + let reactor = POWER_GAIN_REACTOR[settings.reactor_state]; + battery.power = (battery.power + reactor * d).clamp(0.0, battery.capacity); if battery.overloaded_recovering && battery.power > battery.capacity * 0.5 { ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::PowerUp)); battery.overloaded_recovering = false; diff --git a/src/menu.rs b/src/menu.rs index 2974e91..db15f83 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -69,6 +69,7 @@ pub const MENUDEF: &[(&str, MenuAction)] = &[ ("", MenuAction::ModLightAmp), ("", MenuAction::ModFlashlightPower), ("", MenuAction::ModThrusterBoost), + ("", MenuAction::ModReactor), ("", MenuAction::ToggleSound), ("", MenuAction::ToggleMusic), ("", MenuAction::ToggleCamera), @@ -86,6 +87,7 @@ pub enum MenuAction { ModLightAmp, ModFlashlightPower, ModThrusterBoost, + ModReactor, ToggleSound, ToggleMusic, ToggleCamera, @@ -513,6 +515,17 @@ pub fn update_menu( let kw = if p > 0.0 { format!(" ({p}kW)") } else { String::from("") }; text.sections[i].value = format!("Thruster Boost: {state}{kw}\n"); } + MenuAction::ModReactor => { + let state = match settings.reactor_state { + 0 => "Off", + 1 => "Slow burn", + 2 => "Overload", + _ => "ERROR", + }; + let p = actor::POWER_GAIN_REACTOR[settings.reactor_state] / 1e3; + let kw = if p > 0.0 { format!(" (+{p}kW)") } else { String::from("") }; + text.sections[i].value = format!("Reactor: {state}{kw}\n"); + } MenuAction::ChangeARAvatar => { if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) { let avatar_title = ava.3; @@ -634,6 +647,13 @@ pub fn handle_input( } ew_updatemenu.send(UpdateMenuEvent); } + MenuAction::ModReactor => { + settings.reactor_state += 1; + if settings.reactor_state > 2 { + settings.reactor_state = 0; + } + ew_updatemenu.send(UpdateMenuEvent); + } MenuAction::ToggleMusic => { ew_game.send(GameEvent::SetMusic(Next)); ew_updatemenu.send(UpdateMenuEvent); diff --git a/src/var.rs b/src/var.rs index 67c2081..0838281 100644 --- a/src/var.rs +++ b/src/var.rs @@ -86,6 +86,7 @@ pub struct Settings { pub chat_speed: f32, pub ar_avatar: usize, pub flashlight_active: bool, + pub reactor_state: usize, pub hud_active: bool, pub map_active: bool, pub deathscreen_active: bool, @@ -222,6 +223,7 @@ impl Default for Settings { chat_speed: DEFAULT_CHAT_SPEED, ar_avatar: 0, flashlight_active: false, + reactor_state: 1, hud_active: true, map_active: false, deathscreen_active: false,