Ignore:
Timestamp:
04/29/14 18:26:49 (11 years ago)
Author:
sz
Message:

Adjusted experiment scripts to comply with the current Framsticks API (don't use static Genotype/Creature/GenePool/Population? objects and deprecated functions)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • experiments/frams/deathmatch/data/scripts/deathmatch.expdef

    r231 r233  
    2626  initPopulations();
    2727 
    28   Shapes.set("1p_weaponbox","//0\n"+
    29   "p:-0.5, -0.5, -0.5\n"+
    30   "p: 0.5, -0.5, -0.5\n"+
    31   "p: 0.5, 0.5, -0.5\n"+
    32   "p: -0.5, 0.5, -0.5\n"+
    33   "p:-0.5, -0.5, 0.5\n"+
    34   "p:0.5, -0.5, 0.5\n"+
    35   "p:0.5, 0.5, 0.5\n"+
    36   "p:-0.5, 0.5, 0.5\n"+
    37   "j: 0,1\n"+
    38   "j: 1,2\n"+
    39   "j: 2,3\n"+
    40   "j: 3,0\n"+
    41   "j: 4,5\n"+
    42   "j: 5,6\n"+
    43   "j: 6,7\n"+
    44   "j: 7,4\n"+
    45   "j: 0,4\n"+
    46   "j: 1,5\n"+
    47   "j: 2,6\n"+
    48   "j: 3,7", 0x0FAA0F);
    49  
    50   Shapes.set("1p_hpbox","//0\n"+
    51   "p:-0.5, -0.5, -0.5\n"+
    52   "p: 0.5, -0.5, -0.5\n"+
    53   "p: 0.5, 0.5, -0.5\n"+
    54   "p: -0.5, 0.5, -0.5\n"+
    55   "p:-0.5, -0.5, 0.5\n"+
    56   "p:0.5, -0.5, 0.5\n"+
    57   "p:0.5, 0.5, 0.5\n"+
    58   "p:-0.5, 0.5, 0.5\n"+
    59   "j: 0,1\n"+
    60   "j: 1,2\n"+
    61   "j: 2,3\n"+
    62   "j: 3,0\n"+
    63   "j: 4,5\n"+
    64   "j: 5,6\n"+
    65   "j: 6,7\n"+
    66   "j: 7,4\n"+
    67   "j: 0,4\n"+
    68   "j: 1,5\n"+
    69   "j: 2,6\n"+
    70   "j: 3,7", 0xAA0F0F);
     28  Shapes.set("1p_weaponbox","""//0
     29p:-0.5, -0.5, -0.5
     30p: 0.5, -0.5, -0.5
     31p: 0.5, 0.5, -0.5
     32p: -0.5, 0.5, -0.5
     33p:-0.5, -0.5, 0.5
     34p:0.5, -0.5, 0.5
     35p:0.5, 0.5, 0.5
     36p:-0.5, 0.5, 0.5
     37j: 0,1
     38j: 1,2
     39j: 2,3
     40j: 3,0
     41j: 4,5
     42j: 5,6
     43j: 6,7
     44j: 7,4
     45j: 0,4
     46j: 1,5
     47j: 2,6
     48j: 3,7""", 0x0FAA0F);
     49 
     50  Shapes.set("1p_hpbox","""//0
     51p:-0.5, -0.5, -0.5
     52p: 0.5, -0.5, -0.5
     53p: 0.5, 0.5, -0.5
     54p: -0.5, 0.5, -0.5
     55p:-0.5, -0.5, 0.5
     56p:0.5, -0.5, 0.5
     57p:0.5, 0.5, 0.5
     58p:-0.5, 0.5, 0.5
     59j: 0,1
     60j: 1,2
     61j: 2,3
     62j: 3,0
     63j: 4,5
     64j: 5,6
     65j: 6,7
     66j: 7,4
     67j: 0,4
     68j: 1,5
     69j: 2,6
     70j: 3,7""", 0xAA0F0F);
    7171}
    7272
     
    7777 
    7878  //add Food population (group 0)
    79   Population.name = "Food";
    80   Population.nnsim = 0;
    81   Population.enableperf = 0;
    82   Population.death = 1;
    83   Population.energy = 1;
    84   Population.selfmask = 0x20002;
    85   Population.othermask = 0x10002;
     79  var p=Populations[0];
     80  p.name = "Food";
     81  p.nnsim = 0;
     82  p.enableperf = 0;
     83  p.death = 1;
     84  p.energy = 1;
     85  p.selfmask = 0x20002;
     86  p.othermask = 0x10002;
    8687 
    8788  //add Weapon Upgrade population (group 1)
    88   Populations.addGroup("Upgrades");
    89   Population.nnsim = 0;
    90   Population.enableperf = 0;
    91   Population.death = 1;
    92   Population.energy = 1;
    93   Population.selfmask = 0x20002;
    94   Population.othermask = 0x10002;
     89  p=Populations.addGroup("Upgrades");
     90  p.nnsim = 0;
     91  p.enableperf = 0;
     92  p.death = 1;
     93  p.energy = 1;
     94  p.selfmask = 0x20002;
     95  p.othermask = 0x10002;
    9596
    9697  //add Teams populations (group above 2)
    9798  var i = 0;
    9899  teams = ExpParams.teamCount;
    99   if (teams == 1) {
    100         GenePools.group = 0;
    101         teams = GenePool.size;
    102   }
     100  if (teams == 1)
     101        teams = GenePools[0].size;
    103102  for (i = 0; i < teams; i++)
    104103  {
    105     Populations.addGroup("Team "+i);
    106     Population.nnsim = 1;
    107     Population.enableperf = 1;
    108     Population.death = 0;
    109     Population.energy = 1;
    110     Population.selfmask = 0x50001;
    111     Population.othermask = 0x60001;
     104    p=Populations.addGroup("Team "+i);
     105    p.nnsim = 1;
     106    p.enableperf = 1;
     107    p.death = 0;
     108    p.energy = 1;
     109    p.selfmask = 0x50001;
     110    p.othermask = 0x60001;
    112111  }
    113112 
     
    127126function initCreatures()
    128127{
    129   var i = 0;
    130   var j = 0;
    131   GenePools.group = 0;
    132   for (i = 0; i < Populations.size - 2; i++)
    133   {
    134     Populations.group = i + 2;
    135         for (j = 0; j < ExpParams.teamSize; j++)
     128  for (var i = 0; i < Populations.size - 2; i++)
     129  {
     130        for (var j = 0; j < ExpParams.teamSize; j++)
    136131        {
     132          var g; //Genotype object
    137133          if (ExpParams.teamCount != 1)
    138                 GenePools.genotype = Math.random(GenePool.size);
     134            g = GenePools[0].random();
    139135          else
    140             GenePools.genotype = i;
    141           Population.createFromGenotype();
    142           Creature.name = "Member " + j;
     136            g = GenePools[0][i];
     137          Populations[i+2].add(g).name = "Member " + j;
    143138        }
    144139  }
     
    169164 
    170165  var s = "#Time interval; ";
    171   var i = 0;
    172   for (i = 0; i < Populations.size - 2; i++)
     166  for (var i = 0; i < Populations.size - 2; i++)
    173167  {
    174168    s += "Team " + i + "; ";
     
    204198function tryCreateHPBox()
    205199{
    206   Populations.group = 0;
    207  
    208   if (Population.size >= ExpParams.hpBoxTotalCount) return;
     200  if (Populations[0].size >= ExpParams.hpBoxTotalCount) return;
    209201 
    210202  if (Math.rnd01 > ExpParams.hpBoxProbability) return;
    211203 
    212   var food = Populations.createFromString("//0\nm:Vstyle=hpbox\np:");
     204  var food = Populations[0].add("//0\nm:Vstyle=hpbox\np:");
    213205  food.name = "HP Box";
    214206  food.idleen = ExpParams.hpBoxIdleEnergy;
     
    220212function tryCreateUpgradeBox()
    221213{
    222   Populations.group = 1;
    223  
    224   if (Population.size >= ExpParams.upgradeBoxTotalCount) return;
     214  if (Populations[1].size >= ExpParams.upgradeBoxTotalCount) return;
    225215 
    226216  if (Math.rnd01 > ExpParams.upgradeBoxProbability) return;
    227217 
    228   var weapon = Populations.createFromString("//0\nm:Vstyle=weaponbox\np:");
     218  var weapon = Populations[1].add("//0\nm:Vstyle=weaponbox\np:");
    229219  weapon.name = "Weapon Box";
    230220  weapon.idleen = ExpParams.upgradeBoxIdleEnergy;
     
    235225
    236226//handle creature placement in the world
    237 function onBorn()
     227function onBorn(cr)
    238228{
    239229  // place newly born creature
     
    242232  while (retry-- && !placed_ok)
    243233  {
    244     switch (Populations.group)
     234    switch (cr.population.index)
    245235    {
    246236    case 0: //food placement
    247       place_centerhead();
     237      place_centerhead(cr);
    248238      break;
    249239    case 1: //upgrade placement
    250       place_centerhead();
     240      place_centerhead(cr);
    251241      break;
    252242    default:
    253           Creature.user1 = Vector.new();
    254           Creature.user1.add(0.0); //attack cooldown (0)
    255           Creature.user1.add(0.0); //bonus damage (1)
    256           Creature.user2 = Vector.new();
    257           Creature.user2.add(0); //kills (0)
    258           Creature.user2.add(0); //assists (1)
    259           Creature.user2.add(0); //total damage dealt (2)
    260           Creature.user2.add(0); //total damage received (3)
    261           Creature.user2.add(0); //HP boxes collected (4)
    262           Creature.user2.add(0); //Upgrade boxes collected (5)
    263           Creature.user3 = Vector.new(); //who dealt damage to this creature
    264           Creature.energ0 = ExpParams.creatureStartingEnergy;
    265           Creature.energy = Creature.energ0;
    266       place_inTeamSpot();
     243          cr.user1 = [0.0, 0.0]; //attack cooldown (0), bonus damage (1)
     244          cr.user2 = [0,0,0,0,0,0]; //kills (0), assists (1), total damage dealt (2), total damage received (3), HP boxes collected (4), Upgrade boxes collected (5)
     245          cr.user3 = []; //who dealt damage to this creature
     246          cr.energ0 = ExpParams.creatureStartingEnergy;
     247          cr.energy = cr.energ0;
     248      place_inTeamSpot(cr);
    267249      break;
    268250    }
    269251
    270     if (!Populations.creatBBCollisions(0))
    271       placed_ok = 1;
     252    if (!cr.boundingBoxCollisions(0))
     253      {placed_ok=1; break;}
    272254  }
    273255  if (!placed_ok)
     
    276258
    277259//place creature in random spot and make it head center of the map
    278 function place_centerhead()
     260function place_centerhead(cr)
    279261{
    280262  var x, y, z;
    281   x = (World.wrldsiz - Creature.size_x) * Math.rnd01 - Creature.size_x / 2;
    282   y = (World.wrldsiz - Creature.size_y) * Math.rnd01 - Creature.size_y / 2;
     263  x = (World.wrldsiz - cr.size_x) * Math.rnd01 - cr.size_x / 2;
     264  y = (World.wrldsiz - cr.size_y) * Math.rnd01 - cr.size_y / 2;
    283265  z = WorldMap.getHeight(x, y);
    284266
     
    287269  var alpha_rad = vectorsAngle([1.0, 0.0], [hx, hy]);
    288270
    289   Creature.rotate(0, 0, alpha_rad);
    290   Creature.moveAbs(x, y, z - 0.999);
     271  cr.rotate(0, 0, alpha_rad);
     272  cr.moveAbs(x, y, z - 0.999);
    291273 
    292274  print("Creature placed in [" + x +" " + y + " " + z);
     
    297279//Place creature in correct team spot (valid for Team creatures only)
    298280//Creatures are placed in circle with random rotation (commented out: heading center of the map) in their respective team groups
    299 function place_inTeamSpot()
    300 {
    301   var radius = 360.00 * (Populations.group - 1) / teams;
     281function place_inTeamSpot(cr)
     282{
     283  var radius = 360.00 * (cr.population.index - 1) / teams;
    302284
    303285  var x, y, z;
    304   x = (ExpParams.teamSpawningAreaSize) * Math.rnd01 - Creature.size_x / 2 - ExpParams.teamSpawningAreaSize/2;
    305   y = (ExpParams.teamSpawningAreaSize) * Math.rnd01 - Creature.size_y / 2 - ExpParams.teamSpawningAreaSize/2;
     286  x = (ExpParams.teamSpawningAreaSize) * Math.rnd01 - cr.size_x / 2 - ExpParams.teamSpawningAreaSize/2;
     287  y = (ExpParams.teamSpawningAreaSize) * Math.rnd01 - cr.size_y / 2 - ExpParams.teamSpawningAreaSize/2;
    306288 
    307289  //vector of length half the world size minus spawning area size
     
    324306  //var alpha_rad = vectorsAngle([1.0, 0.0], [hx, hy]);
    325307 
    326   Creature.rotate(0, 0, alpha_rad);
     308  cr.rotate(0, 0, alpha_rad);
    327309  //place it mid-air
    328   Creature.moveAbs(x, y, z);
     310  cr.moveAbs(x, y, z);
    329311
    330312  return ;
     
    350332{
    351333  var s = "" + Simulator.time + "; ";
    352   var i = 0;
    353   var j = 0;
    354334  var total = 0.0;
    355   for (i = 0; i < Populations.size - 2; i++)
    356   {
    357     Populations.group = i + 2;
    358         var sum = 0.0;
    359         for (j = 0; j < Population.size; j++)
    360         {
    361           Populations.creature = j;
    362           sum += Creature.energy;
    363         }
     335  for (var i = 2; i < Populations.size; i++)
     336  {
     337    var pop=Populations[i];
     338    var sum = 0.0;
     339    for (var cr in pop)
     340      sum += cr.energy;
    364341    s += "" + sum + "; ";
    365         s += "" + Population.size + "; ";
    366         total += sum;
     342    s += "" + pop.size + "; ";
     343    total += sum;
    367344  }
    368345  if (total < 0) total == 0;
     
    376353function clearDeadCreatures()
    377354{
    378   var i = 0;
    379   var j = 0;
    380   for (i = 0; i < Populations.size - 2; i++)
    381   {
    382     Populations.group = i + 2;
    383         for (j = 0; j < Population.size; j++)
     355  for (var i = 2; i < Populations.size; i++)
     356  {
     357    var pop=Populations[i];
     358    for (var j = 0; j < pop.size; j++)
     359      {
     360      var cr=pop[j];
     361      if (cr.energy <= 0) {pop.kill(cr); j--;}
     362      }
     363  }
     364}
     365
     366function applySuddenDeathModifier()
     367{
     368  if (idleSimulationSteps < ExpParams.stagnationInterval) return;
     369
     370  for (var i = 2; i < Populations.size; i++)
     371    for (var cr in Populations[i])
     372      cr.energy -= ExpParams.stagnationHealthReduce;
     373}
     374
     375function lowerCooldownCounters()
     376{
     377  for (var i = 2; i < Populations.size; i++)
     378  {
     379    var pop=Populations[i];
     380        for (var cr in pop)
    384381        {
    385       Populations.creature = j;
    386       if (Creature.energy <= 0) Populations.killSelected();
    387         }
    388   }
    389 }
    390 
    391 function applySuddenDeathModifier()
    392 {
    393   if (idleSimulationSteps < ExpParams.stagnationInterval) return;
    394 
    395   var i = 0;
    396   var j = 0;
    397   for (i = 0; i < Populations.size - 2; i++)
    398   {
    399     Populations.group = i + 2;
    400         for (j = 0; j < Population.size; j++)
    401         {
    402           Populations.creature = j;
    403           Creature.energy -= ExpParams.stagnationHealthReduce;
    404         }
    405   }
    406 }
    407 function lowerCooldownCounters()
    408 {
    409   var i = 0;
    410   var j = 0;
    411   for (i = 0; i < Populations.size - 2; i++)
    412   {
    413     Populations.group = i + 2;
    414         for (j = 0; j < Population.size; j++)
    415         {
    416           Populations.creature = j;
    417           if (Creature.user1 != null)
     382          if (cr.user1 != null)
    418383          {
    419             if (Creature.user1.get(0) > 0) Creature.user1.set(0, Creature.user1.get(0) - 1);
    420             if (Creature.user1.get(0) < 0) Creature.user1.set(0,0.0);
    421             if (Creature.user1.get(1) > 0) Creature.user1.set(1, Creature.user1.get(1) - ExpParams.upgradeBoxDecay);
    422             if (Creature.user1.get(1) < 0) Creature.user1.set(1,0.0);
     384            if (cr.user1[0] > 0) cr.user1[0]=cr.user1[0] - 1;
     385            if (cr.user1[0] < 0) cr.user1[0]=0.0;
     386            if (cr.user1[1] > 0) cr.user1[1]=cr.user1[1] - ExpParams.upgradeBoxDecay;
     387            if (cr.user1[1] < 0) cr.user1[1]=0.0;
    423388          }
    424389        }
     
    428393function checkGameState()
    429394{
    430   var i = 0;
    431395  var alivePop = 0;
    432   for (i = 0; i < Populations.size - 2; i++)
    433   {
    434     Populations.group = i + 2;
    435         if (Population.size > 0) alivePop += 1;
    436   }
     396  for (var i = 2; i < Populations.size; i++)
     397    if (Populations[i].size > 0) alivePop += 1;
    437398 
    438399  if (alivePop == 0 && Simulator.time <= 1)
     
    444405  if (alivePop <= 1)
    445406  {
    446     for (i = 0; i < Populations.size - 2; i++)
     407    for (var i = 2; i < Populations.size; i++)
    447408    {
    448       Populations.group = i + 2;
    449           if (Population.size > 0)
     409      var pop=Populations[i];
     410          if (pop.size > 0)
    450411          {
    451             Simulator.print("Battle is OVER! The winner is: " + Population.name);
     412            Simulator.print("Battle is OVER! The winner is: " + pop.name);
    452413               
    453414                //write stats of last living creatures
    454415                var f=File.appendDirect("creatures"+battleNumber+".txt","Creature statistics");
    455                 var j = 0;
    456                 for (j = 0; j < Population.size; j++)
     416                for (var cr in pop)
    457417                {
    458                   Populations.creature = j;
    459418                  //f.writeString("Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan");
    460                   if (Creature.user2 != null)
    461                     f.writeString(Creature.name + "; " + Population.name + "; " + Creature.user2.get(0) + "; " + Creature.user2.get(1) + "; " + Creature.user2.get(2) + "; " + Creature.user2.get(3) + "; " + Creature.user2.get(4) + "; " + Creature.user2.get(5) + "; " + Creature.lifespan + "\n");
     419                  if (cr.user2 != null)
     420                    f.writeString(cr.name + "; " + pop.name + "; " + cr.user2[0] + "; " + cr.user2[1] + "; " + cr.user2[2] + "; " + cr.user2[3] + "; " + cr.user2[4] + "; " + cr.user2[5] + "; " + cr.lifespan + "\n");
    462421                }
    463422
     
    502461  }
    503462 
    504   if (c1.group == null || c2.group == null)
     463  if (c1.population == null || c2.population == null)
    505464  {
    506465    //collision of creature without a group
     
    510469 
    511470  //first condition should never occur, but who knows?
    512   if (c1.group.index < 2 || c2.group.index < 2)
     471  if (c1.population.index < 2 || c2.population.index < 2)
    513472  {
    514473    //collision with HP Box and Upgrades are handled separately
     
    524483  var dice2 = 0;
    525484  var changed = 0;
    526   var i = 0;
    527   for (i = 0; i < ExpParams.diceCount; i++)
     485  for (var i = 0; i < ExpParams.diceCount; i++)
    528486  {
    529487    dice1 = dice1 + Math.random(ExpParams.diceSides) + 1;
     
    534492  energy1 += ExpParams.upgradeMultiplier * c1.user1.get(1);
    535493  energy2 += ExpParams.upgradeMultiplier * c2.user1.get(1);
    536   if (c1.group == c2.group)
     494  if (c1.population == c2.population)
    537495  {
    538496    energy1 = ExpParams.friendlyFireDamageMultiplier * energy1;
     
    547505  if (c2.user2 == null) stop("3");
    548506 
    549   if (c2.user1.get(0) <= 0 && energy2 > 0)
     507  if (c2.user1[0] <= 0 && energy2 > 0)
    550508  {
    551509    changed = 1;
     
    553511    c1.energy = c1.energy - energy2;
    554512        if (c1.energy < 0) c1.energy = 0;
    555     print(c2.name + " [" + c2.group.name + "] rolled " + dice2 + " and dealt " + energy2 + " [+" + (ExpParams.upgradeMultiplier * c2.user1.get(1)) +" bonus] damage to " + c1.name + " [" + c1.group.name + "]");
     513    print(c2.name + " [" + c2.population.name + "] rolled " + dice2 + " and dealt " + energy2 + " [+" + (ExpParams.upgradeMultiplier * c2.user1[1]) +" bonus] damage to " + c1.name + " [" + c1.population.name + "]");
    556514        c2.user1.set(0, ExpParams.attackCooldown);
    557         c2.user2.set(2, c2.user2.get(2) + energy1);
    558         c1.user2.set(3, c1.user2.get(3) + energy1);
    559         var vect = Vector.new();
    560         vect.add(c2.uid);
    561         vect.add(c2.name);
     515        c2.user2.set(2, c2.user2[2] + energy1);
     516        c1.user2.set(3, c1.user2[3] + energy1);
     517        var vect = [c2.uid,c2.name];
    562518        var arrindex = arrayContains(c1.user3, 0, c2.uid);
    563519        if (arrindex != -1)
    564520        {
    565           vect.add(energy2 + c1.user3.get(arrindex).get(2));
    566           c1.user3.set(arrindex, vect);
     521          vect.add(energy2 + c1.user3[arrindex][2]);
     522          c1.user3[arrindex]=vect;
    567523        }
    568524        else
     
    572528          c1.user3.add(vect);
    573529          if (c1.energy > 0)
    574           {
    575         c2.user2.set(1, c2.user2.get(1) + 1); //increase assists statistic
    576           }
     530            c2.user2[1] = c2.user2[1] + 1; //increase assists statistic
    577531        }
    578532        if (c1.energy <= 0)
    579533        {
    580           c2.user2.set(0, c2.user2.get(0) + 1); //increase kills statistic
     534          c2.user2[0] = c2.user2[0] + 1; //increase kills statistic
    581535          kill_c1 = 1;
    582536        }
    583537  }
    584538 
    585   if (c1.user1.get(0) <= 0 && energy1 > 0)
     539  if (c1.user1[0] <= 0 && energy1 > 0)
    586540  {
    587541    changed = 1;
     
    589543    c2.energy = c2.energy - energy1;
    590544        if (c2.energy < 0) c2.energy = 0;
    591     print(c1.name + " [" + c1.group.name + "] rolled " + dice1 + " and dealt " + energy1 + " [+" + (ExpParams.upgradeMultiplier * c1.user1.get(1)) +" bonus] damage to " + c2.name + " [" + c2.group.name + "]");
    592     c1.user1.set(0, ExpParams.attackCooldown);
    593         c1.user2.set(2, c1.user2.get(2) + energy1);
    594         c2.user2.set(3, c2.user2.get(3) + energy1);
     545    print(c1.name + " [" + c1.population.name + "] rolled " + dice1 + " and dealt " + energy1 + " [+" + (ExpParams.upgradeMultiplier * c1.user1[1]) +" bonus] damage to " + c2.name + " [" + c2.population.name + "]");
     546    c1.user1[0] = ExpParams.attackCooldown;
     547        c1.user2[2] = c1.user2[2] + energy1;
     548        c2.user2[3] = c2.user2[3] + energy1;
    595549        var vect = Vector.new();
    596550        vect.add(c1.uid);
     
    599553        if (arrindex != -1)
    600554        {
    601           vect.add(energy1 + c2.user3.get(arrindex).get(2));
    602           c2.user3.set(arrindex, vect);
     555          vect.add(energy1 + c2.user3[arrindex][2]);
     556          c2.user3[arrindex] = vect;
    603557        }
    604558        else
     
    609563          if (c2.energy > 0)
    610564          {
    611         c1.user2.set(1, c1.user2.get(1) + 1); //increase assists statistic
     565        c1.user2[1] = c1.user2[1] + 1; //increase assists statistic
    612566          }
    613567        }
    614568        if (c2.energy <= 0)
    615569        {
    616           c1.user2.set(0, c1.user2.get(0) + 1); //increase kills statistic
     570          c1.user2[0] = c1.user2[0] + 1; //increase kills statistic
    617571          kill_c2 = 1;
    618572        }
     
    626580  //resolve kills
    627581  if (kill_c1 == 1)
    628   {
    629     Populations.group = c1.group.index;
    630     Populations.creature = c1.group.findUID(c1.uid);
    631         if (Populations.creature == -1) stop("4");
    632     Populations.killSelected();
    633   }
     582    c1.population.kill(c1);
    634583  if (kill_c2 == 1)
    635   {
    636     Populations.group = c2.group.index;
    637     Populations.creature = c2.group.findUID(c2.uid);
    638         if (Populations.creature == -1) stop("4");
    639     Populations.killSelected();
    640   }
     584    c2.population.kill(c2);
    641585}
    642586
     
    647591
    648592  //collect HP Box (by eating it :D)
    649   print(Collision.Creature2.name + " [" + Collision.Creature2.group.name + "] picked a HP box");
    650   Collision.Creature2.user2.set(4, Collision.Creature2.user2.get(4) + 1);
    651   Collision.Creature1.energy_m = Collision.Creature1.energy_m + Collision.Creature1.energy;
    652   Collision.Creature2.energy_p = Collision.Creature2.energy_p + Collision.Creature1.energy;
     593  print(Collision.Creature2.name + " [" + Collision.Creature2.population.name + "] picked a HP box");
     594  Collision.Creature2.user2[4] = Collision.Creature2.user2[4] + 1;
     595  Collision.Creature1.energy_m += Collision.Creature1.energy;
     596  Collision.Creature2.energy_p += Collision.Creature1.energy;
    653597 
    654598  //kill HP Box
    655   Populations.group = Collision.Creature1.group.index;
    656   Populations.creature = Collision.Creature1.group.findUID(Collision.Creature1.uid);
    657   Populations.killSelected();
     599  Collision.Creature1.population.kill(Collision.Creature1);
    658600 
    659601  writeTeamStatistics();
     
    666608
    667609  //collect Upgrade Box (by eating it :D)
    668   print(Collision.Creature2.name + " [" + Collision.Creature2.group.name + "] picked an upgrade box");
    669   Collision.Creature2.user2.set(5, Collision.Creature2.user2.get(5) + 1);
    670   Collision.Creature1.energy_m = Collision.Creature1.energy_m + Collision.Creature1.energy;
    671   Collision.Creature2.user1.set(1, Collision.Creature2.user1.get(1) + Collision.Creature1.energy);
     610  print(Collision.Creature2.name + " [" + Collision.Creature2.population.name + "] picked an upgrade box");
     611  Collision.Creature2.user2[5] = Collision.Creature2.user2[5] + 1;
     612  Collision.Creature1.energy_m += Collision.Creature1.energy;
     613  Collision.Creature2.user1[1] = Collision.Creature2.user1[1] + Collision.Creature1.energy;
    672614 
    673615  //kill Upgrade Box
    674   Populations.group = Collision.Creature1.group.index;
    675   Populations.creature = Collision.Creature1.group.findUID(Collision.Creature1.uid);
    676   Populations.killSelected();
     616  Collision.Creature1.population.kill(Collision.Creature1);
    677617 
    678618  writeTeamStatistics();
     
    681621//function executed on Creature death
    682622//TODO: implement some statistics for dieing creature
    683 function onDied()
     623function onDied(cr)
    684624{
    685625  //ignore death of hp boxes and upgrades
    686   if (Populations.group < 2)
     626  if (cr.population.index < 2)
    687627   return ;
    688628
    689   print(Creature.name + " was killed");
    690   var i = 0;
    691   for (i = 0; i < Creature.user3.size; i++)
    692   {
    693     print(Creature.user3.get(i).get(1) + " dealt " + Creature.user3.get(i).get(2) + " damage");
    694   }
     629  print(cr.name + " was killed");
     630  for (var dam in cr.user3)
     631    print(dam[1] + " dealt " + dam[2] + " damage");
    695632 
    696633  var f=File.appendDirect("creatures"+battleNumber+".txt","Creature statistics");
    697634  //f.writeString("Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan");
    698   f.writeString(Creature.name + "; " + Population.name + "; " + Creature.user2.get(0) + "; " + Creature.user2.get(1) + "; " + Creature.user2.get(2) + "; " + Creature.user2.get(3) + "; " + Creature.user2.get(4) + "; " + Creature.user2.get(5) + "; " + Creature.lifespan + "\n");
     635  f.writeString(cr.name + "; " + cr.population.name + "; " + cr.user2[0] + "; " + cr.user2[1] + "; " + cr.user2[2] + "; " + cr.user2[3] + "; " + cr.user2[4] + "; " + cr.user2[5] + "; " + cr.lifespan + "\n");
    699636  f.close();
    700637 
Note: See TracChangeset for help on using the changeset viewer.