Index: experiments/frams/foraminifera/data/scripts/foraminifera.expdef
===================================================================
--- experiments/frams/foraminifera/data/scripts/foraminifera.expdef	(revision 486)
+++ experiments/frams/foraminifera/data/scripts/foraminifera.expdef	(revision 487)
@@ -33,4 +33,5 @@
 global changePeriod;
 global phase;
+global species_genes; 
 
 @include "foraminifera.inc"
@@ -52,8 +53,9 @@
 	pop.death = 1;
 	pop.energy = 1;
-	pop.selfmask = 0x10001;
-	pop.othermask = 0x20001;
+	pop.selfmask = 0;
+	pop.othermask = 0;
 	//pop.selfmask = 0x20002; pop.othermask = 0x10002;
 	pop.perfperiod = 25; 
+	pop.bodysim = 0;
 
 	pop = Populations.addGroup("Nutrients");
@@ -62,7 +64,8 @@
 	pop.death = 1;
 	pop.energy = 1;
-	pop.selfmask = 0x20002;
-	pop.othermask = 0x10000;
+	pop.selfmask = 0;
+	pop.othermask = 0;
 	//pop.othermask = 0x10002;
+	pop.bodysim = 0;
 
 	pop = Populations.addGroup("ReticulopodiaNutrients");
@@ -71,6 +74,7 @@
 	pop.death = 0;
 	pop.energy = 0;
-	pop.selfmask = 0x20002;
-	pop.othermask = 0x10000;
+	pop.selfmask = 0;
+	pop.othermask = 0;
+	pop.bodysim = 0;
 
 	//world
@@ -90,5 +94,5 @@
 	//ExpProperties.visualize = 1; //uncomment to visualize reticulopodia and indicate nutrients positions
 
-	//ExpProperties.logging = 1; //uncomment to enable logging simulation parameters to log files
+	//ExpProperties.logging = 1; //uncomment to enable logging simulation parameters to log files	
 
 	//reproduction
@@ -100,4 +104,6 @@
 	ExpProperties.divisionCost = 15.6;
 	reprocounter = 0;
+
+	species_genes = [];
 
 	init_chambers();
@@ -143,5 +149,5 @@
 	changePeriod = 0;
 	phase = "high";
-	ExpProperties.foodperiod = 21600;
+	ExpProperties.foodperiod = 3600;
 	ExpProperties.foodPeriodChange = 0;
 	ExpProperties.nutrientradius = micronsToFrams(10);
@@ -195,7 +201,15 @@
 }
 
+function getGene(cr, gen_id, gen_set)
+{
+	if (cr.data->lifeparams->gen == 0) 
+		return cr.data->genes[gen_id];
+	else 
+		return cr.data->genes[gen_set][gen_id];
+}
+
 function addForam(species, iter, chambernum, ploid)
 {
-	var geno = createForamGenotype(ploid, species, chambernum);
+	var geno = createForamMorphology(species_genes[species]->morphotype, ploid, chambernum);
 	var cr = Populations[0].add(geno);
 	cr.name = "Initial creature" + species + "_" + iter;
@@ -203,5 +217,5 @@
 	cr.energy0 = energyFromVolume(max_chamber_volume[ploid][chambernum],0);
 	cr.energy = cr.energy0;
-	setGenotype({"opt" : 0, "cr" : cr, "species" : species});
+	setGenotype({"opt" : 0, "cr" : cr, "species" : species, "energy0" : cr.energy0, "genes" : species_genes[species]});
 	if (ploid == 1)
 	{
@@ -219,5 +233,16 @@
 	}	
 	//add new foram with random energy bewtween starting energy and reproduction treshold
-	addForam(species, iter, Math.rndUni(0,getProperty(ploid, "min_repro_energ")),ploid);
+	addForam(species, iter, Math.rndUni(0,species_genes[species]->min_repro_energies[ploid]),ploid);
+}
+
+//new species can be added as a dictionary with parameter values that are different than default values
+function addSpecies(new_genes)
+{
+	species_genes.add({"min_repro_energies" : [4,6], "energies0" : [20, 1.25], "hibernation" : 0, "morphotype" : 0});
+	for (var i = 0; i < new_genes.size; i++)
+	{
+		var key = new_genes.getKey(i);
+		species_genes[species_genes.size-1][key] = new_genes[key];
+	} 
 }
 
@@ -228,12 +253,18 @@
 	Populations[2].clear(); //reticulopodia and nutrients
 
-	for (var i = 0; i < ExpProperties.foramPop; i++)
-	{
-		addInitialForam(0, i);	
-		//addInitialForam(1, i);
+	if (species_genes.size == 0)
+	{
+		addSpecies({}); //default
+	}
+
+	for (var spec = 0; spec < species_genes.size; spec++)
+	{
+		for (var i = 0; i < ExpProperties.foramPop; i++)
+		{
+			addInitialForam(spec, i);	
+		}
 	}
 	o = Populations[0][0].getMechPart(0).orient.clone();
 	ExpState.totaltestedcr = 0;
-	nutrientenergywaiting = ExpProperties.energy_nut;
 }
 
@@ -361,5 +392,5 @@
 	if ((chamber_num+1) < chambers[cr.data->lifeparams->species].size)
 	{
-		var geno = createForamGenotype(cr.data->lifeparams->gen, cr.data->lifeparams->species, chamber_num+1);
+		var geno = createForamMorphology(getGene(cr, "morphotype", 0), cr.data->lifeparams->gen, chamber_num+1);
 		var cr2 = Populations[0].add(geno);
 
@@ -367,5 +398,5 @@
 		cr2.energy = cr2.energy0;
 
-		setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : 2});
+		setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : 2, "energy0" : cr.energy0});
 		cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
 		setForamMeta(cr2);
@@ -442,4 +473,9 @@
 }
 
+function fence(pos)
+{
+	return Math.min(Math.max(0,pos),World.wrldsiz);
+}
+
 function foramMove(cr)
 {
@@ -447,5 +483,5 @@
 
 	//adjustment in z axis
-	cr.moveAbs(cr.pos_x, cr.pos_y, 0);
+	cr.moveAbs(fence(cr.pos_x), fence(cr.pos_y), 0);
 
 	//are there any nutrients in zone 1 or 2?
@@ -459,9 +495,5 @@
 
 	//no nutrients in zone 2
-	var hibernation = 0;
-	if (cr.data->lifeparams->gen == 0) hibernation =  cr.data->genes->hibernation;
-	else hibernation =  cr.data->genes[0]->hibernation;
-	//hibernation
-	if (hibernation == 1)
+	if (getGene(cr, "hibernation",0) == 1)
 	{
 		reverseHib(cr);
@@ -469,5 +501,5 @@
 	}
 	//random move
-	else if (cr.lifespan%int(dir_change/ExpProperties.secPerStep) == 0)
+	else if (Simulator.stepNumber%int(dir_change/ExpProperties.secPerStep) == 0)
 	{
 		cr.data->lifeparams->dir = randomDir();
@@ -732,7 +764,13 @@
 function createStatistics()
 {	
-	var number = [[0, 0],[0,0]]; // [species][gen]
-	var e_inc = [[0, 0],[0,0]];
+	var number = [];
+	var e_inc = [];
 	var e_nut = 0.0;
+
+	for (var s = 0; s < species_genes.size; s++)
+	{
+		number.add([0,0]);// [haplo][diplo]
+		e_inc.add([0,0]);
+	}
 
 	for (var i = 0; i < Populations[0].size; i++)
@@ -752,6 +790,18 @@
 	}
 
-	var log_numbers = [number[1][0], number[1][1], number[0][0], number[0][1], Populations[1].size];
-	var log_energies = [e_inc[1][0], e_inc[1][1], e_inc[0][0], e_inc[0][1], e_nut];
+	var log_numbers = [];
+	var log_energies = [];
+
+	for (var s = 0; s < species_genes.size; s++)
+	{
+		for (var p = 0; p < 2; p++)
+		{
+			log_numbers.add(number[s][p]);
+			log_energies.add(e_inc[s][p]);
+		}
+	}
+	
+	log_numbers.add(Populations[1].size);
+	log_energies.add(e_nut);
 
 	log(log_numbers, "forams_log.txt");
