|
@@ -76,6 +76,7 @@ Ideally, I wanted to have next to no logic here, but I realized my lifeforms nee
|
|
|
for example to re-deposit their weight back on death, to query for food, etc. I'd like to pass this to a
|
|
|
lifeform so it can access it and modify it.
|
|
|
*/
|
|
|
+// Maybe biome needs a hashmap that can be locked to hold lifeforms
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
|
struct Biome {
|
|
|
water: f32,
|
|
@@ -89,19 +90,35 @@ struct Biome {
|
|
|
impl Biome {
|
|
|
fn tick(&mut self, timescale: f32){
|
|
|
|
|
|
+
|
|
|
for mut lifeform in &mut self.lifeforms {
|
|
|
if lifeform.alive {
|
|
|
if self.water > 0.0 {
|
|
|
- self.water -= lifeform.water_intake * timescale as f32;
|
|
|
+ self.water -= lifeform.water_intake * timescale;
|
|
|
+ }
|
|
|
+
|
|
|
+ if lifeform.digestive_content / lifeform.digestive_capacity < 0.2 {
|
|
|
+ // hungry, let's eat
|
|
|
+ //this is expensive to calc...
|
|
|
+
|
|
|
+ lifeform.mass += lifeform.nutrient_intake * timescale;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if lifeform.mass <= lifeform.mass_starve {
|
|
|
+ lifeform.alive = false;
|
|
|
+ println!("Died of starvation: {:?}", lifeform);
|
|
|
}
|
|
|
- lifeform.mass += lifeform.nutrient_intake * timescale as f32;
|
|
|
+
|
|
|
+ // age
|
|
|
lifeform.age += 1.0 * timescale;
|
|
|
if lifeform.age > lifeform.maxage {
|
|
|
lifeform.alive = false;
|
|
|
- //println!("Died: {:?}", lifeform);
|
|
|
+ println!("Died of age: {:?}", lifeform);
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
move_random(&mut lifeform, &self.rect, timescale);
|
|
|
} else {
|
|
|
// fuck, we're dead
|
|
@@ -118,12 +135,12 @@ impl Biome {
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
|
struct Lifeform {
|
|
|
name: String, //just for fun
|
|
|
- mass: f32, //how much it weights
|
|
|
+ mass: f32, //how much it weights in kg
|
|
|
mass_starve: f32, //at this mass, starvation begins
|
|
|
digestive_capacity: f32,//a food "buffer"; stomach or tree trunk
|
|
|
digestive_content: f32, //how much the digestive buffer can store
|
|
|
- age: f32, //age in ticks
|
|
|
- maxage: f32, //maximum age
|
|
|
+ age: f32, //age in days
|
|
|
+ maxage: f32, //maximum age in days
|
|
|
water_intake: f32, //how much water it consumes per tick
|
|
|
nutrient_intake: f32, //how much food it consumes per tick
|
|
|
diet: Diets, //the type of stuff it eats
|
|
@@ -258,9 +275,9 @@ fn sim() {
|
|
|
for lf in deserialized_config.lifeforms {
|
|
|
|
|
|
let sq_km = (loaded_biome.rect.width*loaded_biome.rect.width)/1000000.0;
|
|
|
- let num_instances = sq_km * lf.ocurrence_per_sq_km;
|
|
|
- println!("\nInstantiating from {:?} {:?} times", lf.name, num_instances);
|
|
|
- for _i in 0..num_instances as i32 {
|
|
|
+ let num_instances: i32 = (sq_km * lf.ocurrence_per_sq_km).floor() as i32;
|
|
|
+ println!("Instantiating from {:?} {:?} times", lf.name, num_instances);
|
|
|
+ for _i in 0..num_instances {
|
|
|
let mut instance = lf.clone();
|
|
|
loaded_biome.lifeforms.push(instance);
|
|
|
}
|
|
@@ -282,6 +299,6 @@ fn sim() {
|
|
|
|
|
|
fn main() {
|
|
|
//let start = SystemTime::now();
|
|
|
- println!("Starting simulation");
|
|
|
+ println!("\n\n=== === === Starting simulation === === ===");
|
|
|
sim();
|
|
|
}
|