Index: experiments/frams/foraminifera/data/scripts/foraminifera.expdef
===================================================================
--- experiments/frams/foraminifera/data/scripts/foraminifera.expdef	(revision 553)
+++ experiments/frams/foraminifera/data/scripts/foraminifera.expdef	(revision 554)
@@ -85,11 +85,5 @@
 	World.wrldsiz = micronsToFrams(100000);
 	World.wrldbnd = 1;
-	ExpProperties.stress = 1;
-	ExpProperties.creath = -0.99; //just above the bottom
-	ExpProperties.autorestart = 0;
-
-	//time
-	ExpProperties.secPerStep = 300;
-	ExpProperties.foramSpeedMmPerMin = 0.05;
+
 	movePerStep = getMovePerStep();
 
@@ -99,24 +93,11 @@
 	ExpProperties.logPref = "";
 
-	//reproduction
-	ExpProperties.foramPop = 20;	
-	ExpProperties.crossprob = 0;
-	ExpProperties.mutationprob = 0;
-	ExpProperties.repro_time = 720;
-	ExpProperties.gametoPeriod = 21600;
-	ExpProperties.divisionCost = 20;
-	reprocounter = 0;
-
 	species_genes = [];
 
+	//morphology
 	init_chambers();
-
 	curColor = retColors[0];
-	//morphology
-	ExpProperties.dir_change_sec = 30000;
 	ExpProperties.zone1_range = micronsToFrams(1000);
 	ExpProperties.zone2_range = micronsToFrams(3000);
-	ExpProperties.chamber_growth_time = 720;
-	ExpProperties.chamberCostPerSec = 0.000001;
 	ExpProperties.chamber_proculus_haplo = micronsToFrams(50);
 	ExpProperties.chamber_difference_haplo = 0.0;
@@ -133,32 +114,10 @@
 	}
 
-	//energetics
-	ExpProperties.min_repro_energ_haplo = 4;
-	ExpProperties.min_repro_energ_diplo = 6;
-
-	ExpProperties.e_meta = 0.0000005; 
-	ExpProperties.energy_hib = 0.0000001;
-	ExpProperties.energy_move = 0.0000005;
-
-	ExpProperties.energies0_haplo = 20;
-	ExpProperties.energies0_diplo = 1.25;
-	ExpProperties.feedtrans = 0.001;
-	ExpProperties.e_repro_cost_haplo = 0.3; 
-	ExpProperties.e_repro_cost_diplo = 0.2;
-
-	ExpProperties.e_death_level_haplo = 0.5;
-	ExpProperties.e_death_level_diplo = 0.5;
-
 	//nutrients
-	changePeriod = 0;
-	phase = "low";
-	nutrientSqrCm = 10;
-	ExpProperties.foodperiod = 14400;
-	ExpProperties.foodPeriodChange = 0;
 	ExpProperties.nutrientradius = micronsToFrams(10);
 	ExpProperties.energy_nut = 200 * energyFromVolume(ExpProperties.nutrientradius,1);
+	nutrientSqrCm = 10;
 	ExpProperties.nutrient_pop = Math.pow(framsToMicrons(World.wrldsiz)*0.0001,2)/nutrientSqrCm;
-	ExpProperties.ingestion = 0.25;
-	nutrientenergywaiting = 0;
+
 	ExpState.totaltestedcr = 0;
 	ExpState.nutrient = "";
@@ -169,4 +128,8 @@
 
 @include "standard_placement.inc"
+
+function secToSimSteps(value_in_sec){
+	return value_in_sec/ExpProperties.secPerStep;
+}
 
 function volumeInMicrons(radiusInFrams)
@@ -226,8 +189,7 @@
 	cr.energy0 = energyFromVolume(max_chamber_volume[ploid][chambernum],0);
 	cr.energy = cr.energy0;
-	setGenotype({"opt" : 0, "cr" : cr, "species" : species, "energy0" : cr.energy0, "genes" : species_genes[species]});
+	setGenotype({"opt" : "birth", "cr" : cr, "gen" : ploid, "species" : species, "energy0" : cr.energy0, "genes" : species_genes[species]});
 	if (ploid == 1)
 	{
-		cr.data->lifeparams->gen = 1;
 		cr.data->genes = [cr.data->genes, cr.data->genes]; //TODO two different genes sets
 	}
@@ -277,4 +239,9 @@
 	o = Populations[0][0].getMechPart(0).orient.clone();
 	ExpState.totaltestedcr = 0;
+
+	reprocounter = 0;
+	nutrientenergywaiting = 0;
+	changePeriod = 0;
+	phase = "low";
 }
 
@@ -411,5 +378,5 @@
 		cr2.energy = cr2.energy0;
 
-		setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : 2, "energy0" : cr.energy0});
+		setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : "growth", "energy0" : cr.energy0});
 		cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
 		setForamMeta(cr2);
@@ -496,5 +463,14 @@
 
 	//adjustment in z axis
-	cr.moveAbs(fence(cr.pos_x, getZoneRange(cr, 1)), fence(cr.pos_y,getZoneRange(cr, 1)), 0);
+	var change_direction = 0;
+	var new_x = fence(cr.pos_x, getZoneRange(cr, 1));
+	var new_y = fence(cr.pos_y,getZoneRange(cr, 1));
+
+	if ((new_x != cr.pos_x) || (new_y != cr.pos_y) || (cr.data->lifeparams->dir_counter >= int(secToSimSteps(ExpProperties.dir_change_sec))))
+	{
+		change_direction = 1;
+	}
+
+	cr.moveAbs(new_x, new_y, 0);
 
 	//are there any nutrients in zone 1 or 2?
@@ -515,5 +491,5 @@
 	}
 	//random move
-	else if (cr.data->lifeparams->dir_counter >= int(ExpProperties.dir_change_sec/ExpProperties.secPerStep))
+	else if (change_direction == 1)
 	{
 		cr.data->lifeparams->dir = randomDir();
@@ -656,5 +632,5 @@
 			if ((cr.data->lifeparams->max_energy_level >= energyFromVolume(max_chamber_volume[cr.data->lifeparams->gen][lastChamberNum(cr)],0))) 	
 			{
-				cr.data->lifeparams->chamber_growth = int(ExpProperties.chamber_growth_time/ExpProperties.secPerStep);
+				cr.data->lifeparams->chamber_growth = int(secToSimSteps(ExpProperties.chamberGrowthSec));
 			}	
 		}
@@ -716,5 +692,5 @@
 	{
 		var nutsize = ExpProperties.nutrientradius*10;
-		var nut = Populations[2].add("//0\nm:Vstyle=nutrient_visual\np:sh=2,sx="+nutsize+",sy="+nutsize+",sz="+nutsize+",ry=1.5,vr=0.0,1.0,0.0");
+		var nut = Populations[2].add("//0\np:sh=2,sx="+nutsize+",sy="+nutsize+",sz="+nutsize+",ry=1.5,vr=0.0,1.0,0.0");
 		cr.data->reticulopodiacreature = nut;
 		nut.moveAbs(cr.pos_x-1.5*nutsize, cr.pos_y-1.5*nutsize, 0.5);
@@ -735,5 +711,5 @@
 	{
 			changePeriod += 1;
-			if (phase=="low" && (changePeriod*ExpProperties.secPerStep) >= 23328000) //9 months
+			if (phase=="low" && changePeriod >= secToSimSteps(23328000)) //9 months
 			{
 				ExpProperties.foodperiod = ExpProperties.foodperiod/ExpProperties.foodPeriodChange;
@@ -742,5 +718,5 @@
 			}
 		
-			else if (phase == "high" && (changePeriod*ExpProperties.secPerStep) >= 7776000) //3 months
+			else if (phase == "high" && changePeriod >= secToSimSteps(7776000)) //3 months
 			{
 				ExpProperties.foodperiod = ExpProperties.foodperiod*ExpProperties.foodPeriodChange;
@@ -750,5 +726,5 @@
 	}
 	nutrientenergywaiting = nutrientenergywaiting + 1;
-	if (nutrientenergywaiting*ExpProperties.secPerStep >= ExpProperties.foodperiod)
+	if (nutrientenergywaiting >= secToSimSteps(ExpProperties.foodperiod))
 	{
 		for (var i = 0; i < ExpProperties.nutrient_pop; i++)
@@ -783,5 +759,5 @@
 	//reproduction --------------------------------------------
 	reprocounter += 1;
-	if (reprocounter*ExpProperties.secPerStep > ExpProperties.repro_time)
+	if (reprocounter > secToSimSteps(ExpProperties.reproTimeSec))
 	{
 		reprocounter = 0;
@@ -881,10 +857,17 @@
 name:Show reticulopodia and nutrients
 type:d 0 1 0
-group:Foraminifera
+group:
 
 property:
 id:maxSteps
-name:Stop after the given number of simulation steps
+name:Maximum number of steps
 type:d 0 10000000 0
+group:
+
+property:
+id:logging
+name:Log statistics to file
+type:d 0 1 0
+group:
 
 property:
@@ -894,70 +877,100 @@
 
 property:
-id:foramSpeedMmPerMin
-name:Speed of foraminfera in mm/min
-type:f 0.1
-flags: 16
-group:Foraminifera
-
-property:
-id:gametSuccessRate
-name:Ratio of successful gamets
-type:f 0.001
-group:Foraminifera
-
-property:
-id:dir_change_sec
-name:Number of seconds before direction change
-type:d 30000
-group:Foraminifera
-
-property:
-id:gametoPeriod
-name:Time of gametogenesis
-type:f 720
-group:Foraminifera
-
-property:
-id:picoCarbonPerMikro
-name:Picograms of carbon in cubed micrometer
-type:f 0.13
-group:Foraminifera
-
-property:
 id:secPerStep
 name:Seconds per simulation step
 help:Number of seconds of foraminifera time per simulation step
-type:f 60.0
+type:f 1 480 300
+flags: 16
+group:
+
+property:
+id:foramSpeedMmPerMin
+name:Speed of foraminfera in mm/min
+type:f 0.01 0.1 0.05
 flags: 16
 group:Foraminifera
 
 property:
-id:e_repro_cost_haplo
-name:Cost of reproduction
-type:f 0.1 0.9 0.5
+id:dir_change_sec
+name:Number of seconds before direction change
+type:d 300 300000 6000
 group:Foraminifera
+
+property:
+id:foramPop
+name:Initial forams population size
+type:d 1 1000 20
+group:Foraminifera
+
+property:
+id:gametoPeriodSec
+name:Time of gametogenesis
+type:f 300 300000 21600
+group:Reproduction
+
+property:
+id:gametSuccessRate
+name:Ratio of successful gamets
+type:f 0.0001 0.01 0.001
+group:Reproduction
 
 property:
 id:divisionCost
 name:Cost of division in pG
-type:f
-group:Foraminifera
-
-property:
-id:e_repro_cost_diplo
-name:Cost of reproduction
-type:f 0.1 0.9 0.3
-group:Foraminifera
-
-property:
-id:chamber_growth_time
+type:f 15 25 20
+group:Reproduction
+
+property:
+id:min_repro_energ_haplo
+name:Min reproduction energy of haploid
+type:f 0 -1 4
+group:Energy
+
+property:
+id:min_repro_energ_diplo
+name:Min reproduction energy of diploid
+type:f 0 -1 6
+group:Energy
+
+property:
+id:repro_prob
+name:Probability of reproduction
+type:f 0 1 0.8
+group:Reproduction
+
+property:
+id:energies0_haplo
+name:Energy of offspring from diploid forams
+type:f 0 -1 20
+group:Energy
+
+property:
+id:energies0_diplo
+name:Energy of offspring from diploid forams
+type:f 0 -1 1.25
+group:Energy
+
+property:
+id:crossprob
+name:Crossover probability
+type:f 0 1 0
+group:Reproduction
+
+property:
+id:mutationprob
+name:Mutation probability
+type:f 0 1 0
+group:Reproduction
+
+property:
+id:reproTimeSec
+name:Time before reproduction
+type:d 0 10000 720
+group:Reproduction
+
+property:
+id:chamberGrowthSec
 name:Time of the chamber growth in seconds
-type:f
-group:Foraminifera
-
-property:
-id:chamberCostPerSec
-name:Cost of growning chamber per second
-type:f
+type:f 360 1440 720
 group:Foraminifera
 
@@ -977,5 +990,5 @@
 id:chamber_difference_haplo
 name:Difference in size between subsequent chambers
-type:f
+type:f 0 -1 0
 group:Foraminifera
 
@@ -983,5 +996,5 @@
 id:chamber_difference_diplo
 name:Difference in size between subsequent chambers
-type:f
+type:f 0 -1 0.08
 group:Foraminifera
 
@@ -990,10 +1003,10 @@
 name:Probability of being hunted
 type:f 0 1 0
-group:Forminifera
+group:Foraminifera
 
 property:
 id:zone1_range
 name:Zone 1 range 
-type:f 0 200
+type:f 0 200 10
 group:Foraminifera
 
@@ -1001,122 +1014,56 @@
 id:zone2_range
 name:Zone 2 range
-type:f 0 3000
+type:f 0 3000 30
 group:Foraminifera
 
 property:
-id:colors
-name:Haploid and diploid colors
-type:x
-group:Foraminifera
-
-property:
-id:min_repro_energ_haplo
-name:Min reproduction energy of forams
-type:f
-group:Foraminifera
-
-property:
-id:min_repro_energ_diplo
-name:Min reproduction energy of forams
-type:f
-group:Foraminifera
-
-property:
-id:repro_prob
-name:Probability of reproduction
-type:f 0 1 0.8
-group:Foraminifera
-
-property:
-id:energies0_haplo
-name:Energy of offspring from diploid forams
-type:f
-group:Foraminifera
-
-property:
-id:energies0_diplo
-name:Energy of offspring from diploid forams
-type:f
-group:Foraminifera
+id:chamberCostPerSec
+name:Cost of growning chamber per second
+type:f 0 1 0.000001
+group:Energy
 
 property:
 id:e_death_level_haplo
 name:Minimal level of energy to sustain life of haploid
-type:f 0 20 0.2
-group:Foraminifera
+type:f 0 1 0.5
+group:Energy
 
 property:
 id:e_death_level_diplo
 name:Minimal level of energy to sustain life of diploid
-type:f 0 20 0.2
-group:Foraminifera
+type:f 0 1 0.5
+group:Energy
 
 property:
 id:energy_hib
 name:Energy used for hibernation during one step
-type:f 0 1 0.001
-group:Foraminifera
+type:f 0 1 0.0000001
+group:Energy
 
 property:
 id:energy_move
 name:Energy used for movement during one step
-type:f 0 20 0.001
-group:Foraminifera
-
-property:
-id:min_vol
-name:Minimal volume for reproduction
-type:f 100 900 100
-group:Foraminifera
-
-property:
-id:max_size
-name:Maximal size
-type:d 1 10 5 
-group:Foraminifera
-
-property:
-id:foramPop
-name:Initial forams population size
-type:d 1 1000 100
-group:Foraminifera
-
-property:
-id:crossprob
-name:Crossover probability
-type:f 0 1 0
-group:Foraminifera
-
-property:
-id:mutationprob
-name:Mutation probability
-type:f 0 1 0
-group:Foraminifera
+type:f 0 1 0.0000005
+group:Energy
 
 property:
 id:e_meta
 name:Idle metabolism
-type:f 0 1
+type:f 0 1 0.0000005
 group:Energy
 help:Each stick consumes this amount of energy in one time step
-
-property:
-id:nutrient_pop
-name:Feeding rate
-type:f 0 1000000
-group:Energy
-help:How fast energy is created in the world
-
-property:
-id:foodPeriodChange
-name:Set variable feed rate
-type:f 0
-group:Energy
 
 property:
 id:ingestion
 name:Ingestion rate
-type:f
-group:Energy
+type:f 0 -1 0.25
+group:Energy
+
+property:
+id:nutrient_pop
+name:Nutrient population
+type:f 0 1000000
+group:Energy
+help:How fast energy is created in the world
 
 property:
@@ -1127,16 +1074,4 @@
 
 property:
-id:feedtrans
-name:Energy transfer per second
-type:f 0 100000
-group:Energy
-
-property:
-id:foodperiod
-name:Time between food occurrences
-type:f 0 1000000
-group:Energy
-
-property:
 id:nutrientradius
 name:Nutrient size
@@ -1145,8 +1080,32 @@
 
 property:
+id:picoCarbonPerMikro
+name:Picograms of carbon in cubed micrometer
+type:f 0 -1 0.13
+group:Energy
+
+property:
+id:feedtrans
+name:Energy transfer per second
+type:f 0 1 0.001
+group:Energy
+
+property:
+id:foodperiod
+name:Time between food occurrences
+type:f 0 1000000 14400
+group:Energy
+
+property:
+id:foodPeriodChange
+name:Set variable feed rate
+type:f 0 -1 0
+group:Energy
+
+property:
 id:stress
 name:Environmental stress
 type:d 0 1 1
-group:World
+group:
 
 property:
@@ -1154,15 +1113,10 @@
 name:Reproduction trigger
 type:d 0 1 1
-group:World
-
-property:
-id:repro_time
-name:Time before reproduction
-type:d 0 10000
+group:Reproduction
 
 property:
 id:creath
 name:Creation height
-type:f -1 50
+type:f -1 50 -0.99
 help:~
 Vertical position (above the surface) where new Forams are revived.
@@ -1172,4 +1126,10 @@
 -1   = just above the bottom~
 
+property:
+id:autorestart
+name:Restart after extinction
+help:Restart automatically this experiment after the last creature has died?
+type:d 0 1 0
+
 state:
 id:nutrient
@@ -1178,10 +1138,4 @@
 type:x
 flags:32
-
-property:
-id:autorestart
-name:Restart after extinction
-help:Restart automatically this experiment after the last creature has died?
-type:d 0 1
 
 state:
@@ -1199,7 +1153,2 @@
 type:d
 flags:16
-
-property:
-id:logging
-name:Log statistics to file
-type:d 0 1 0
