implement reactor overload and shutdown

This commit is contained in:
yuni 2024-09-22 06:38:44 +02:00
parent 0b5058abf5
commit bb539c00cc
3 changed files with 25 additions and 3 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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,