Johann Woelper 7 years ago
parent
commit
9062402b38
2 changed files with 93 additions and 13 deletions
  1. 66 3
      server/config.json
  2. 27 10
      server/src/main.rs

+ 66 - 3
server/config.json

@@ -17,7 +17,7 @@
       "mass_starve": 5.0,
       "digestive_capacity": 2.0,
       "digestive_content": 0.0,
-      "age": 1307.9536,
+      "age": 1007.9536,
       "maxage": 1298.9431,
       "water_intake": 0.8018272,
       "nutrient_intake": 1.0,
@@ -32,6 +32,69 @@
       "speed": 170695.16,
       "ocurrence_per_sq_km": 15.0
     },
+    {
+      "name": "Wolf",
+      "mass": 40.0,
+      "mass_starve": 15.0,
+      "digestive_capacity": 4.0,
+      "digestive_content": 0.0,
+      "age": 1307.9536,
+      "maxage": 2298.9431,
+      "water_intake": 0.8018272,
+      "nutrient_intake": 1.0,
+      "diet": "Carnivore",
+      "kind": "Fauna",
+      "alive": true,
+      "position": [
+        0.0,
+        0.0,
+        0.0
+      ],
+      "speed": 170695.16,
+      "ocurrence_per_sq_km": 0.3
+    },
+    {
+      "name": "Fox",
+      "mass": 8.0,
+      "mass_starve": 3.0,
+      "digestive_capacity": 0.6,
+      "digestive_content": 0.0,
+      "age": 0.0,
+      "maxage": 2298.9431,
+      "water_intake": 0.8018272,
+      "nutrient_intake": 0.1,
+      "diet": "Carnivore",
+      "kind": "Fauna",
+      "alive": true,
+      "position": [
+        0.0,
+        0.0,
+        0.0
+      ],
+      "speed": 170695.16,
+      "ocurrence_per_sq_km": 1.3
+    },
+    {
+      "name": "Mouse",
+      "mass": 0.02,
+      "mass_starve": 0.005,
+      "digestive_capacity": 0.001,
+      "digestive_content": 0.0,
+      "age": 0.0,
+      "maxage": 200.0,
+      "water_intake": 0.008,
+      "nutrient_intake": 0.001,
+      "diet": "Omnivore",
+      "kind": "Fauna",
+      "alive": true,
+      "position": [
+        0.0,
+        0.0,
+        0.0
+      ],
+      "speed": 48.0,
+      "ocurrence_per_sq_km":300.3
+    },
     {
       "name": "Tree",
       "mass": 5481.323,
@@ -72,9 +135,9 @@
         0.0
       ],
       "speed": 0.0,
-      "ocurrence_per_sq_km": 8000.0
+      "ocurrence_per_sq_km": 1000.0
     }
   ],
-  "simtime": 100.0,
+  "simtime": 300.0,
   "simsteps": 1.0
 }

+ 27 - 10
server/src/main.rs

@@ -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();
 }