implement reactor overload and shutdown
This commit is contained in:
parent
0b5058abf5
commit
bb539c00cc
|
@ -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 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_LIGHTAMP: [f32; 4] = [0.0, 200e3, 400e3, 800e3];
|
||||||
pub const POWER_DRAIN_AR: f32 = 300e3;
|
pub const POWER_DRAIN_AR: f32 = 300e3;
|
||||||
|
pub const POWER_GAIN_REACTOR: [f32; 3] = [0.0, 2000e3, 10000e3];
|
||||||
|
|
||||||
pub struct ActorPlugin;
|
pub struct ActorPlugin;
|
||||||
impl Plugin for ActorPlugin {
|
impl Plugin for ActorPlugin {
|
||||||
|
@ -259,7 +260,6 @@ const SUIT_SIMPLE: Suit = Suit {
|
||||||
pub struct Battery {
|
pub struct Battery {
|
||||||
pub power: f32, // Watt-seconds
|
pub power: f32, // Watt-seconds
|
||||||
pub capacity: f32, // Watt-seconds
|
pub capacity: f32, // Watt-seconds
|
||||||
pub reactor: f32, // Watt (production)
|
|
||||||
pub overloaded_recovering: bool,
|
pub overloaded_recovering: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,6 @@ impl Default for Battery {
|
||||||
Self {
|
Self {
|
||||||
power: 10e3 * 3600.0,
|
power: 10e3 * 3600.0,
|
||||||
capacity: 10e3 * 3600.0, // 10kWh
|
capacity: 10e3 * 3600.0, // 10kWh
|
||||||
reactor: 2000e3, // 2MW
|
|
||||||
overloaded_recovering: false,
|
overloaded_recovering: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +328,8 @@ pub fn update_power(
|
||||||
if power_down {
|
if power_down {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::PowerDown));
|
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 {
|
if battery.overloaded_recovering && battery.power > battery.capacity * 0.5 {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::PowerUp));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::PowerUp));
|
||||||
battery.overloaded_recovering = false;
|
battery.overloaded_recovering = false;
|
||||||
|
|
20
src/menu.rs
20
src/menu.rs
|
@ -69,6 +69,7 @@ pub const MENUDEF: &[(&str, MenuAction)] = &[
|
||||||
("", MenuAction::ModLightAmp),
|
("", MenuAction::ModLightAmp),
|
||||||
("", MenuAction::ModFlashlightPower),
|
("", MenuAction::ModFlashlightPower),
|
||||||
("", MenuAction::ModThrusterBoost),
|
("", MenuAction::ModThrusterBoost),
|
||||||
|
("", MenuAction::ModReactor),
|
||||||
("", MenuAction::ToggleSound),
|
("", MenuAction::ToggleSound),
|
||||||
("", MenuAction::ToggleMusic),
|
("", MenuAction::ToggleMusic),
|
||||||
("", MenuAction::ToggleCamera),
|
("", MenuAction::ToggleCamera),
|
||||||
|
@ -86,6 +87,7 @@ pub enum MenuAction {
|
||||||
ModLightAmp,
|
ModLightAmp,
|
||||||
ModFlashlightPower,
|
ModFlashlightPower,
|
||||||
ModThrusterBoost,
|
ModThrusterBoost,
|
||||||
|
ModReactor,
|
||||||
ToggleSound,
|
ToggleSound,
|
||||||
ToggleMusic,
|
ToggleMusic,
|
||||||
ToggleCamera,
|
ToggleCamera,
|
||||||
|
@ -513,6 +515,17 @@ pub fn update_menu(
|
||||||
let kw = if p > 0.0 { format!(" ({p}kW)") } else { String::from("") };
|
let kw = if p > 0.0 { format!(" ({p}kW)") } else { String::from("") };
|
||||||
text.sections[i].value = format!("Thruster Boost: {state}{kw}\n");
|
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 => {
|
MenuAction::ChangeARAvatar => {
|
||||||
if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) {
|
if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) {
|
||||||
let avatar_title = ava.3;
|
let avatar_title = ava.3;
|
||||||
|
@ -634,6 +647,13 @@ pub fn handle_input(
|
||||||
}
|
}
|
||||||
ew_updatemenu.send(UpdateMenuEvent);
|
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 => {
|
MenuAction::ToggleMusic => {
|
||||||
ew_game.send(GameEvent::SetMusic(Next));
|
ew_game.send(GameEvent::SetMusic(Next));
|
||||||
ew_updatemenu.send(UpdateMenuEvent);
|
ew_updatemenu.send(UpdateMenuEvent);
|
||||||
|
|
|
@ -86,6 +86,7 @@ pub struct Settings {
|
||||||
pub chat_speed: f32,
|
pub chat_speed: f32,
|
||||||
pub ar_avatar: usize,
|
pub ar_avatar: usize,
|
||||||
pub flashlight_active: bool,
|
pub flashlight_active: bool,
|
||||||
|
pub reactor_state: usize,
|
||||||
pub hud_active: bool,
|
pub hud_active: bool,
|
||||||
pub map_active: bool,
|
pub map_active: bool,
|
||||||
pub deathscreen_active: bool,
|
pub deathscreen_active: bool,
|
||||||
|
@ -222,6 +223,7 @@ impl Default for Settings {
|
||||||
chat_speed: DEFAULT_CHAT_SPEED,
|
chat_speed: DEFAULT_CHAT_SPEED,
|
||||||
ar_avatar: 0,
|
ar_avatar: 0,
|
||||||
flashlight_active: false,
|
flashlight_active: false,
|
||||||
|
reactor_state: 1,
|
||||||
hud_active: true,
|
hud_active: true,
|
||||||
map_active: false,
|
map_active: false,
|
||||||
deathscreen_active: false,
|
deathscreen_active: false,
|
||||||
|
|
Loading…
Reference in a new issue