implement suit integrity and oxygen drain

This commit is contained in:
yuni 2024-03-20 18:37:10 +01:00
parent 4626e6c1da
commit 40489b3aad
3 changed files with 45 additions and 2 deletions

View file

@ -103,6 +103,7 @@ pub struct Suit {
pub power: f32,
pub oxygen_max: f32,
pub power_max: f32,
pub integrity: f32, // [0.0 - 1.0]
}
impl Default for Suit { fn default() -> Self { SUIT_SIMPLE } }
@ -111,6 +112,7 @@ const SUIT_SIMPLE: Suit = Suit {
power_max: 1e5,
oxygen: nature::OXY_D,
oxygen_max: nature::OXY_D,
integrity: 1e5,
};
pub fn update_physics_actors(
@ -139,7 +141,27 @@ pub fn update_physics_lifeforms(
lifeform.adrenaline_jolt = 0.0
}
lifeform.adrenaline = (lifeform.adrenaline - 0.0001 + lifeform.adrenaline_jolt * 0.01).clamp(0.0, 1.0);
suit.oxygen = (suit.oxygen - nature::OXY_S*d).clamp(0.0, 1.0);
let mut oxygen_drain = nature::OXY_S;
let integr_threshold = 0.5;
if suit.integrity < integr_threshold {
// The oxygen drain from suit integrity scales with (2 - 2x)^4,
// which is a function with ~16 at x=0 and 0 at x=1.
// Furthermore, x is divided by the integrity threshold (e.g. 0.5)
// to squeeze the function horizontally, and change the range for
// the x parameter from [0-1] to [0-integritythreshold]
//
// 16 |.
// |.
// |'.
// | '.
// | '..
// |______''....
// x=0 x=1
let drain_scaling = (2.0 - 2.0 * suit.integrity / integr_threshold).powf(4.0);
oxygen_drain += suit.oxygen * 0.01 * drain_scaling;
}
suit.oxygen = (suit.oxygen - oxygen_drain*d).clamp(0.0, suit.oxygen_max);
}
}

View file

@ -218,6 +218,24 @@ fn setup(
..default()
}
),
TextSection::new(
"\nSuit Integrity ",
TextStyle {
font: asset_server.load(FONT),
font_size: settings.font_size_hud,
color: Color::GRAY,
..default()
},
),
TextSection::new(
"",
TextStyle {
font: asset_server.load(FONT),
font_size: settings.font_size_hud,
color: Color::GRAY,
..default()
}
),
TextSection::new(
"\n\n",
TextStyle {
@ -344,6 +362,8 @@ fn update(
text.sections[7].value = format!("{adrenaline:.0}pg/mL");
let all_actors = query_all_actors.iter().len();
text.sections[10].value = format!("{all_actors:.0}");
let integrity = suit.integrity * 100.0;
text.sections[12].value = format!("{integrity:.0}%");
}
}

View file

@ -80,7 +80,8 @@ pub fn setup(
},
actor::LifeForm::default(),
actor::Suit {
oxygen: nature::OXY_M,
oxygen: nature::OXY_H,
integrity: 0.3,
..default()
},
Camera3dBundle {