Added population chart to statistics panel
This commit is contained in:
@@ -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)
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ class Species {
|
||||
this.start_tick = start_tick;
|
||||
this.end_tick = -1;
|
||||
this.color = '#asdfasdf';
|
||||
this.name = "crabuloid";
|
||||
this.name = '_' + Math.random().toString(36).substr(2, 9);;
|
||||
this.extinct = false;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,14 @@ class Species {
|
||||
this.population--;
|
||||
if (this.population <= 0) {
|
||||
this.extinct = true;
|
||||
// console.log("Extinction");
|
||||
const FossilRecord = require("./FossilRecord");
|
||||
FossilRecord.fossilize(this);
|
||||
}
|
||||
}
|
||||
|
||||
lifespan() {
|
||||
return this.end_tick - this.start_tick;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Species;
|
||||
Reference in New Issue
Block a user