add radiation damage

This commit is contained in:
yuni 2024-09-22 07:15:29 +02:00
parent 56bab3f526
commit b6b8e6a8d0
3 changed files with 32 additions and 16 deletions

View file

@ -71,7 +71,7 @@ pub enum DamageType {
Asphyxiation, Asphyxiation,
Depressurization, Depressurization,
//Poison, //Poison,
//Radiation, Radiation,
//Freeze, //Freeze,
//Burn, //Burn,
} }
@ -175,6 +175,7 @@ pub struct OrbitsJupiter;
#[derive(Component)] #[derive(Component)]
pub struct LifeForm { pub struct LifeForm {
pub is_alive: bool, pub is_alive: bool,
pub is_radioactively_damaged: bool,
pub adrenaline: f32, pub adrenaline: f32,
pub adrenaline_baseline: f32, pub adrenaline_baseline: f32,
pub adrenaline_jolt: f32, pub adrenaline_jolt: f32,
@ -183,6 +184,7 @@ impl Default for LifeForm {
fn default() -> Self { fn default() -> Self {
Self { Self {
is_alive: true, is_alive: true,
is_radioactively_damaged: false,
adrenaline: 0.3, adrenaline: 0.3,
adrenaline_baseline: 0.3, adrenaline_baseline: 0.3,
adrenaline_jolt: 0.0, adrenaline_jolt: 0.0,
@ -339,10 +341,12 @@ pub fn update_power(
pub fn update_physics_lifeforms( pub fn update_physics_lifeforms(
time: Res<Time>, time: Res<Time>,
mut query: Query<(&mut LifeForm, &mut HitPoints, &mut Suit, &LinearVelocity)>, settings: Res<Settings>,
id2pos: Res<game::Id2Pos>,
mut query: Query<(&mut LifeForm, &mut HitPoints, &mut Suit, &LinearVelocity, &Position, Option<&Player>)>,
) { ) {
let d = time.delta_seconds(); let d = time.delta_seconds();
for (mut lifeform, mut hp, mut suit, velocity) in query.iter_mut() { for (mut lifeform, mut hp, mut suit, velocity, pos, player) in query.iter_mut() {
if lifeform.adrenaline_jolt.abs() > 1e-3 { if lifeform.adrenaline_jolt.abs() > 1e-3 {
lifeform.adrenaline_jolt *= 0.99; lifeform.adrenaline_jolt *= 0.99;
} else { } else {
@ -355,6 +359,20 @@ pub fn update_physics_lifeforms(
lifeform.adrenaline = lifeform.adrenaline =
(lifeform.adrenaline - 0.0001 + lifeform.adrenaline_jolt * 0.01).clamp(0.0, 1.0); (lifeform.adrenaline - 0.0001 + lifeform.adrenaline_jolt * 0.01).clamp(0.0, 1.0);
if player.is_some() {
lifeform.is_radioactively_damaged = if settings.reactor_state == 2 {
true
} else if let Some(pos_jupiter) = id2pos.0.get(cmd::ID_JUPITER) {
pos_jupiter.distance(pos.0) < 140_000_000.0
} else {
false
};
if lifeform.is_radioactively_damaged {
hp.damage += 0.3 * d;
hp.damagetype = DamageType::Radiation;
}
}
let mut oxygen_drain = nature::OXY_S; let mut oxygen_drain = nature::OXY_S;
let integr_threshold = 0.5; let integr_threshold = 0.5;
if suit.integrity < integr_threshold { if suit.integrity < integr_threshold {

View file

@ -331,7 +331,14 @@ fn handle_player_death(
duration: 1.0, duration: 1.0,
}); });
} }
_ => { actor::DamageType::Radiation => {
settings.death_cause = "Acute radiation poisoning".to_string();
ew_effect.send(visual::SpawnEffectEvent {
class: visual::Effects::FadeIn(Color::BLACK),
duration: 4.0,
});
}
actor::DamageType::Unknown => {
settings.death_cause = "Unknown".to_string(); settings.death_cause = "Unknown".to_string();
ew_effect.send(visual::SpawnEffectEvent { ew_effect.send(visual::SpawnEffectEvent {
class: visual::Effects::FadeIn(css::MAROON.into()), class: visual::Effects::FadeIn(css::MAROON.into()),

View file

@ -682,8 +682,7 @@ pub fn setup(
fn update_dashboard( fn update_dashboard(
timer: ResMut<FPSUpdateTimer>, timer: ResMut<FPSUpdateTimer>,
mut q_dashboard: Query<(&mut Visibility, &Dashboard)>, mut q_dashboard: Query<(&mut Visibility, &Dashboard)>,
id2pos: Res<game::Id2Pos>, q_player: Query<(&actor::Suit, &actor::Battery, &actor::LifeForm), With<actor::Player>>,
q_player: Query<(&actor::Suit, &actor::Battery, &Position), With<actor::Player>>,
settings: Res<Settings>, settings: Res<Settings>,
) { ) {
if !settings.hud_active || !timer.0.just_finished() { if !settings.hud_active || !timer.0.just_finished() {
@ -693,7 +692,7 @@ fn update_dashboard(
if player.is_err() { if player.is_err() {
return; return;
} }
let (suit, battery, pos) = player.unwrap(); let (suit, battery, lifeform) = player.unwrap();
for (mut vis, icon) in &mut q_dashboard { for (mut vis, icon) in &mut q_dashboard {
*vis = bool2vis(match icon { *vis = bool2vis(match icon {
@ -702,15 +701,7 @@ fn update_dashboard(
Dashboard::Battery => battery.overloaded_recovering, Dashboard::Battery => battery.overloaded_recovering,
Dashboard::RotationStabiliser => !settings.rotation_stabilizer_active, Dashboard::RotationStabiliser => !settings.rotation_stabilizer_active,
Dashboard::CruiseControl => settings.cruise_control_active, Dashboard::CruiseControl => settings.cruise_control_active,
Dashboard::Radioactivity => { Dashboard::Radioactivity => lifeform.is_radioactively_damaged,
if settings.reactor_state == 2 {
true
} else if let Some(pos_jupiter) = id2pos.0.get(cmd::ID_JUPITER) {
pos_jupiter.distance(pos.0) < 140_000_000.0
} else {
false
}
}
}); });
} }
} }