diff --git a/src/main.rs b/src/main.rs index 2a3b63c..69a259c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -397,7 +397,7 @@ async fn game_tick(state: &mut GameState) -> Result<()> { } let original_size = plant.current_size; - plant.current_size += plant.genome.base_growth_rate(soil_nutrients, water, temperature, salt, terrain) * PLANT_GROWTH_SCALE * plant.current_size.powf(-0.25); // allometric scaling law + plant.current_size += plant.genome.base_growth_rate(soil_nutrients, water, temperature, salt, terrain) * PLANT_GROWTH_SCALE * plant.current_size.max(0.1).powf(-0.25); // allometric scaling law let difference = (plant.current_size - original_size).max(0.0); if plant.can_reproduce() { @@ -425,7 +425,8 @@ async fn game_tick(state: &mut GameState) -> Result<()> { if difference > 0.0 { plant.growth_ticks += 1; if let Ok(mut health) = state.world.get::<&mut Health>(entity) { - health.apply(HealthChangeType::NaturalRegeneration, difference); + health.max += difference; + health.apply(HealthChangeType::NaturalRegeneration, difference * 2.0); } } @@ -485,7 +486,7 @@ async fn game_tick(state: &mut GameState) -> Result<()> { buffer.cmd.spawn(( Position::single_tile(newpos, MapLayer::Entities), Render('+'), - Health::new(10.0, 10.0), + Health::new(1.0, 1.0), Plant::new(hybrid_genome.clone()), NewlyAdded )); @@ -906,7 +907,7 @@ async fn main() -> Result<()> { batch.push(( Position::single_tile(pos, MapLayer::Entities), Render('+'), - Health::new(10.0, 10.0), + Health::new(1.0, 1.0), //ShrinkOnDeath, Plant::new(genome), NewlyAdded diff --git a/src/plant.rs b/src/plant.rs index cec1f44..5c5eb63 100644 --- a/src/plant.rs +++ b/src/plant.rs @@ -127,9 +127,9 @@ impl Genome { } } - // TODO: this might be unreasonable + // TODO: do this better pub fn water_efficiency(&self) -> f32 { - sigmoid(self.optimal_water_level * 3.0 - 1.0) + sigmoid(self.optimal_water_level) } pub fn hybridize(&self, rng: &mut fastrand::Rng, other: &Genome) -> Option { diff --git a/src/render.rs b/src/render.rs index 58b70db..2a93068 100644 --- a/src/render.rs +++ b/src/render.rs @@ -125,9 +125,11 @@ define_fields! { SeaDistance => "sea_distance", Plants => "plant_growth", PlantsAge => "plant_age", - PlantsLifespanFraction => "plant_lifespan_fraction", + PlantsLifespanFraction => "plant_life", DynamicGroundwater => "dynamic_groundwater", DynamicSoil => "dynamic_soil", + EntityHealth => "health", + EntityHealthFraction => "health_fraction", } } @@ -176,6 +178,8 @@ struct RenderData { plants_lifespan_fraction: Map, dynamic_groundwater: Map, dynamic_soil: Map, + entity_health: Map, + entity_health_fraction: Map, } struct RenderedImage { @@ -216,6 +220,8 @@ fn sample_field(field: Field, position: Coord, data: &RenderData) -> f32 { Field::PlantsLifespanFraction => data.plants_lifespan_fraction[position], Field::DynamicGroundwater => data.dynamic_groundwater[position], Field::DynamicSoil => data.dynamic_soil[position], + Field::EntityHealth => data.entity_health[position], + Field::EntityHealthFraction => data.entity_health_fraction[position], } } @@ -300,6 +306,17 @@ fn build_derived_data( plants_lifespan_fraction[pos] = plant.age as f32 / (plant.genome.lifespan() * PLANT_LIFESPAN_SCALE); } + let mut entity_health = Map::new(world.radius, 0.0f32); + let mut entity_health_fraction = Map::new(world.radius, 0.0f32); + for (position, health) in ecs_world.query::<(&Position, &Health)>().iter() { + let pos = position.head(); + if !plants.in_range(pos) { + continue; + } + entity_health[pos] = health.current; + entity_health_fraction[pos] = health.current / health.max; + } + RenderData { world, ecs_world, @@ -312,7 +329,9 @@ fn build_derived_data( plants_age, plants_lifespan_fraction, dynamic_groundwater, - dynamic_soil: dynamic_soil_nutrients + dynamic_soil: dynamic_soil_nutrients, + entity_health, + entity_health_fraction, } } diff --git a/src/util.rs b/src/util.rs index b6b0cf9..a04ef3d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -20,8 +20,8 @@ pub mod config { pub const PLANT_GROWTH_SCALE: f32 = 0.01; pub const SOIL_NUTRIENT_CONSUMPTION_RATE: f32 = 0.5; pub const SOIL_NUTRIENT_FIXATION_RATE: f32 = 0.002; - pub const WATER_CONSUMPTION_RATE: f32 = 0.06; - pub const PLANT_IDLE_WATER_CONSUMPTION_OFFSET: f32 = 0.05; + pub const WATER_CONSUMPTION_RATE: f32 = 0.1; + pub const PLANT_IDLE_WATER_CONSUMPTION_OFFSET: f32 = 0.2; pub const PLANT_DIEOFF_THRESHOLD: f32 = 0.3; pub const PLANT_DIEOFF_RATE: f32 = 0.2; pub const AUTOSAVE_INTERVAL_TICKS: u64 = 1024; diff --git a/src/worldgen.rs b/src/worldgen.rs index cc6d612..85b7ef8 100644 --- a/src/worldgen.rs +++ b/src/worldgen.rs @@ -205,13 +205,13 @@ pub fn compute_groundwater(water: &Map, rain: &Map, heightmap: &Map 0.0 { Some(c) } else { None })); - percentilize(&mut groundwater, |x| (1.0 - x).powf(0.3)); + percentilize(&mut groundwater, |x| (1.0 - x).powf(1.1)); for (coord, gw) in groundwater.iter_mut() { - *gw -= heightmap[coord] * 0.05; - *gw += rain[coord] * 0.15; + //*gw -= heightmap[coord] * 0.05; + *gw += rain[coord] * 0.5; + *gw = gw.clamp(0.0, 1.0); } - percentilize(&mut groundwater, |x| x.powf(0.7)); groundwater }