Added population chart to statistics panel

This commit is contained in:
Max Robinson
2021-02-08 17:19:10 -07:00
parent 7087c5b4ae
commit 382794bf3f
10 changed files with 614 additions and 26 deletions

View File

@@ -5,8 +5,8 @@ const FossilRecord = {
this.extant_species = [];
this.extinct_species = [];
// if an organism has fewer than this cumulative pop, discard them
this.discard_pop = 5;
// if an organism has fewer than this cumulative pop, discard them on extinction
this.min_discard = 5;
},
setEnv: function(env) {
@@ -15,31 +15,54 @@ const FossilRecord = {
addSpecies: function(org, ancestor) {
// console.log("Adding Species")
var new_species = new Species(org.anatomy, ancestor, this.env.total_ticks)
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;
},
addSpeciesObj: function(species) {
// console.log("Adding Species")
this.extant_species.push(species);
return species;
},
fossilize: function(species) {
// console.log("Extinction")
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) {
if (species.cumulative_pop < this.min_pop) {
return false;
}
this.extinct_species.push(s);
// console.log("Extant:", this.extant_species.length)
// console.log("Extinct:", this.extinct_species.length)
// console.log("Extant species:", this.extant_species.length)
// console.log("Extinct species:", this.extinct_species.length)
return true;
}
}
},
resurrect: function(species) {
// console.log("Resurrecting species")
if (species.extinct) {
for (i in this.extinct_species) {
var s = this.extinct_species[i];
if (s == species) {
this.extinct_species.splice(i, 1);
this.extant_species.push(species);
species.extinct = false;
}
}
}
},
clear_record: function() {
this.species = [];
this.extant_species = [];
this.extinct_species = [];
// console.log("Cleared", this.extant_species, this.extinct_species)
},
}