Separated anatomy from org / made species tracker

This commit is contained in:
Max Robinson
2021-02-04 17:27:47 -07:00
parent 56b27c65b6
commit d26f195100
15 changed files with 707 additions and 147 deletions

49
src/Stats/FossilRecord.js Normal file
View File

@@ -0,0 +1,49 @@
const Species = require("./Species");
const FossilRecord = {
init: function(){
this.extant_species = [];
this.extinct_species = [];
// if an organism has fewer than this cumulative pop, discard them
this.discard_pop = 5;
},
setEnv: function(env) {
this.env = env;
},
addSpecies: function(org, ancestor) {
console.log("Adding Species")
var new_species = new Species(org.anatomy, ancestor, this.env.total_ticks)
this.extant_species.push(new_species);
org.species = new_species;
return new_species;
},
fossilize: function(species) {
species.end_tick = this.env.total_ticks;
for (i in this.extant_species) {
var s = this.extant_species[i];
if (s == species) {
this.extant_species.splice(i, 1);
if (species.cumulative_pop <= this.discard_pop) {
return false;
}
this.extinct_species.push(s);
console.log("Extant:", this.extant_species.length)
console.log("Extinct:", this.extinct_species.length)
return true;
}
}
},
clear_record: function() {
this.species = [];
},
}
FossilRecord.init();
module.exports = FossilRecord;

30
src/Stats/Species.js Normal file
View File

@@ -0,0 +1,30 @@
class Species {
constructor(anatomy, ancestor, start_tick) {
this.anatomy = anatomy;
this.ancestor = ancestor;
this.population = 1;
this.cumulative_pop = 1;
this.start_tick = start_tick;
this.end_tick = -1;
this.color = '#asdfasdf';
this.name = "crabuloid";
this.extinct = false;
}
addPop() {
this.population++;
this.cumulative_pop++;
}
decreasePop() {
this.population--;
if (this.population <= 0) {
this.extinct = true;
console.log("Extinction");
const FossilRecord = require("./FossilRecord");
FossilRecord.fossilize(this);
}
}
}
module.exports = Species;