1
0
mirror of https://github.com/osmarks/ewo3.git synced 2026-03-23 02:09:44 +00:00

Retune plants more

This commit is contained in:
osmarks
2026-03-14 15:16:53 +00:00
parent 3051d2ca22
commit 6eda6c2f98
5 changed files with 34 additions and 14 deletions

View File

@@ -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

View File

@@ -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<Genome> {

View File

@@ -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<f32>,
dynamic_groundwater: Map<f32>,
dynamic_soil: Map<f32>,
entity_health: Map<f32>,
entity_health_fraction: Map<f32>,
}
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,
}
}

View File

@@ -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;

View File

@@ -205,13 +205,13 @@ pub fn compute_groundwater(water: &Map<f32>, rain: &Map<f32>, heightmap: &Map<f3
let mut groundwater = distance_map(
water.radius,
water.iter().filter_map(|(c, i)| if *i > 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
}