From 40489b3aad6749616f0aca5d3e85b05008466673 Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 20 Mar 2024 18:37:10 +0100 Subject: [PATCH] implement suit integrity and oxygen drain --- src/actor.rs | 24 +++++++++++++++++++++++- src/hud.rs | 20 ++++++++++++++++++++ src/world.rs | 3 ++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 79eca9d..6ee91d8 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -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); } } diff --git a/src/hud.rs b/src/hud.rs index ef25b68..aaf504c 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -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}%"); } } diff --git a/src/world.rs b/src/world.rs index ab64859..bfd96a6 100644 --- a/src/world.rs +++ b/src/world.rs @@ -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 {