Changeset 233


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)

Location:
experiments/frams
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • experiments/frams/capture-the-flag/data/scripts/capture-the-flag.expdef

    r232 r233  
    5454}
    5555
    56 function onBorn()
    57 {
    58   Creature.energ0 = 100;
    59   Creature.energy = Creature.energ0;
    60 }
    61 
    62 function onDied()
     56function onBorn(cr)
     57{
     58  cr.energ0 = 100;
     59  cr.energy = cr.energ0;
     60}
     61
     62function onDied(cr)
    6363{
    6464 
     
    8787        //Create GenePool and Population for each team
    8888        GenePools.clear();
    89         GenePool.name = "Team1";
    90         GenePool.fitness = "return this.user3;";
    91         while (GenePools[0].size > 0)
    92                 GenePools[0].delete(0);
     89        var pool=GenePools[0];
     90        pool.name = "Team1";
     91        pool.fitness = "return this.user3;";
     92        while (pool.size > 0)
     93                pool.delete(0);
    9394       
    9495        Populations.clear();
    95         Population.name = "Team1";
    96        
    97         while (Population.size > 0)
    98                         Population.delete(0);
    99        
    100        
    101        
    102         Population.selfmask = 0x50001;
    103     Population.othermask = 0x60001;
     96        var pop=Populations[0];
     97        pop.name = "Team1";
     98       
     99        while (pop.size > 0)
     100                        pop.delete(0);
     101       
     102       
     103       
     104        pop.selfmask = 0x50001;
     105    pop.othermask = 0x60001;
    104106       
    105107        var i = 2;
    106108        for (i = 2; i <= ExpParams.teamsno; i++){
    107                 Populations.addGroup("Team"+i);
    108                 Population.selfmask = 0x50001;
    109         Population.othermask = 0x60001;
    110                 GenePools.addGroup("Team"+i);
    111                 GenePool.fitness = "return this.user3;";       
     109                pop=Populations.addGroup("Team"+i);
     110                pop.selfmask = 0x50001;
     111        pop.othermask = 0x60001;
     112                pool=GenePools.addGroup("Team"+i);
     113                pool.fitness = "return this.user3;";   
    112114        }
    113115       
    114116        //Create GenePool for flags and fill it
    115         GenePools.addGroup("Flags");
    116        
    117         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag0\np:",48,"Flag","Single flag object"));
    118         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag1\np:",48,"Flag","Single flag object"));
    119         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag2\np:",48,"Flag","Single flag object"));
    120         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag3\np:",48,"Flag","Single flag object"));
    121         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag4\np:",48,"Flag","Single flag object"));
     117        pool=GenePools.addGroup("Flags");
     118       
     119        pool.add(Geno.newFrom("m:Vstyle=flag0\np:",48,"Flag","Single flag object"));
     120        pool.add(Geno.newFrom("m:Vstyle=flag1\np:",48,"Flag","Single flag object"));
     121        pool.add(Geno.newFrom("m:Vstyle=flag2\np:",48,"Flag","Single flag object"));
     122        pool.add(Geno.newFrom("m:Vstyle=flag3\np:",48,"Flag","Single flag object"));
     123        pool.add(Geno.newFrom("m:Vstyle=flag4\np:",48,"Flag","Single flag object"));
    122124}
    123125
     
    127129       
    128130        //Reset all global points vectors
    129         flagsX = Vector.new();
    130         flagsY = Vector.new();
    131        
    132         points = Vector.new();
    133         scored = Vector.new();
    134         taken = Vector.new();
    135         retrieved = Vector.new();
     131        flagsX = [];
     132        flagsY = [];
     133       
     134        points = [];
     135        scored = [];
     136        taken = [];
     137        retrieved = [];
    136138       
    137139        //Init global vectors
     
    201203                        Populations[team].delete(0);
    202204               
    203                 GenePools.group = ExpParams.teamsno;
    204                 GenePools.genotype = team;
     205                var cr = Populations[team].add(GenePools[ExpParams.teamsno][team]);
     206                placeFlag(cr);
     207                cr.signals.add("Flag");
     208                cr.signals[0].flavor = team;
     209                cr.signals[0].power=1000;
     210                cr.user1 = 0;
     211                cr.user2 = 0;
     212                cr.user3 = 0;
    205213               
    206                 Populations[team].createFromGenotype();
    207                 placeFlag(Populations[team][0]);
    208                 Creature.signals.add("Flag");
    209                 Creature.signals[0].flavor = team;
    210                 Creature.signals[0].power=1000;
    211                 Creature.user1 = 0;
    212                 Creature.user2 = 0;
    213                 Creature.user3 = 0;
    214                
    215                 GenePools.group = team;
    216 
    217214                var crX, crY;
    218215               
    219216                for (player = 0; player < ExpParams.memberssno; player++){
    220                         GenePools.genotype = player % GenePool.size;
    221                         Populations[team].createFromGenotype();
     217                        var pool=GenePools[team];
     218                        cr = Populations[team].add(pool[player % pool.size]);
    222219                        crX = Math.random(30) - 15;
    223220                        if (crX >=0 && crX < 5)
     
    230227                        else if (crY > -5 && crY < 0)
    231228                                crY = -5;
    232                         Creature.moveAbs(flagsX[team] + crX, flagsY[team] + crY, 0);
    233                         Creature.user1 = 0;
    234                         Creature.user2 = 0;
    235                         Creature.user3 = 0;
     229                        cr.moveAbs(flagsX[team] + crX, flagsY[team] + crY, 0);
     230                        cr.user1 = 0;
     231                        cr.user2 = 0;
     232                        cr.user3 = 0;
    236233                }
    237234        }
     
    245242                        GenePools[team].delete(0);
    246243                if (team != 1)
    247                         GenePools[team].addGeno(Geno.newFrom("lllfffX[0:2.420, 2:-2, 1:-1][-1:1, 0:1, 0:-1][-1:1](RRlllfffMMMX[|-1:-10]lllFFFMMMX[|-2:-1], fffIXlllfffMMMsX[|6:10, 3:-10](RRlllfffMMMIX[|-4:-10]lllFFFMMMIX[|-5:-1][*], , RRlllfffMMMIX[|-7:10]lllFFFMMMIX[|-8:-1][*]), RRlllfffMMMX[|-10:10]lllFFFMMMX[|-11:-1.784])", 49, "Player", "Player"));
     244                        GenePools[team].add(Geno.newFrom("lllfffX[0:2.420, 2:-2, 1:-1][-1:1, 0:1, 0:-1][-1:1](RRlllfffMMMX[|-1:-10]lllFFFMMMX[|-2:-1], fffIXlllfffMMMsX[|6:10, 3:-10](RRlllfffMMMIX[|-4:-10]lllFFFMMMIX[|-5:-1][*], , RRlllfffMMMIX[|-7:10]lllFFFMMMIX[|-8:-1][*]), RRlllfffMMMX[|-10:10]lllFFFMMMX[|-11:-1.784])", 49, "Player", "Player"));
    248245                else if (team == 1)
    249                         GenePools[team].addGeno(Geno.newFrom("lllfffX[0:2.420, 2:-2, 1:-1][-1:1, 0:1, 0:-1][-1:1](RRlllfffMMMX[|-1:-10]lllFFFMMMX[|-2:-1], fffIXlllfffMMMsX[|1:1][Thr2,lo:-0.75,hi:0.75,t:0.75,3:-10,6:10](RRlllfffMMMIX[|-4:-10]lllFFFMMMIX[|-5:-1][FlagDef,opp:0,my:1], , RRlllfffMMMIX[|-7:10]lllFFFMMMIX[|-8:-1][FlagDef,opp:0,my:1]), RRlllfffMMMX[|-10:10]lllFFFMMMX[|-11:-1.784])", 49, "Inteligent Player", "Inteligent Player"));
     246                        GenePools[team].add(Geno.newFrom("lllfffX[0:2.420, 2:-2, 1:-1][-1:1, 0:1, 0:-1][-1:1](RRlllfffMMMX[|-1:-10]lllFFFMMMX[|-2:-1], fffIXlllfffMMMsX[|1:1][Thr2,lo:-0.75,hi:0.75,t:0.75,3:-10,6:10](RRlllfffMMMIX[|-4:-10]lllFFFMMMIX[|-5:-1][FlagDef,opp:0,my:1], , RRlllfffMMMIX[|-7:10]lllFFFMMMIX[|-8:-1][FlagDef,opp:0,my:1]), RRlllfffMMMX[|-10:10]lllFFFMMMX[|-11:-1.784])", 49, "Inteligent Player", "Inteligent Player"));
    250247        }
    251248}
     
    257254        //Update flags position if taken and cooldown if recently retrieved
    258255        for (team = 0; team < Populations.size; team++){
    259                 Populations.group = team;
    260                 Populations.creature = 0;
    261                 if (Creature.user3 > 0)
    262                         Creature.user3 -= 1;
     256                var pop=Populations[team];
     257
     258                if (pop[0].user3 > 0)
     259                        pop[0].user3 -= 1;
    263260               
    264                 for (player = 1; player < Population.size; player++){
    265                         Populations.creature = player;
    266                         if (Creature.user1 == 1){
    267                                 Creature.user2.moveAbs(Creature.pos_x, Creature.pos_y, Creature.size_z + 1);
     261                for (player = 1; player < pop.size; player++){
     262                        var cr=pop[player];
     263                        if (cr.user1 == 1){
     264                                cr.user2.moveAbs(cr.pos_x, cr.pos_y, cr.size_z + 1);
    268265                        }
    269266                }
     
    286283
    287284function placeFlag(flag){
    288         flag.moveAbs(flagsX[flag.group.index], flagsY[flag.group.index], 0);
     285        flag.moveAbs(flagsX[flag.population.index], flagsY[flag.population.index], 0);
    289286}
    290287
     
    295292       
    296293        //Take flag by changing its flavour and setting flag in player and player in flag fields
    297         flag.signals[0].flavor = flag.group.index + 100;
     294        flag.signals[0].flavor = flag.population.index + 100;
    298295        flag.user1 = 1;
    299296        flag.user2 = creature;
     
    307304       
    308305        //Update team points and events
    309         points.set(creature.group.index, points[creature.group.index] + ExpParams.pointsCapture);
    310         taken.set(creature.group.index, taken[creature.group.index] + 1);
     306        points[creature.population.index] = points[creature.population.index] + ExpParams.pointsCapture;
     307        taken[creature.population.index] = taken[creature.population.index] + 1;
    311308
    312309}
     
    314311function retrieveFlag(flag, creature){
    315312        //Retrieve flag by changing its flavour and deleting it from player and player from flag
    316         flag.signals[0].flavor = flag.group.index;
     313        flag.signals[0].flavor = flag.population.index;
    317314        flag.user1 = 0;
    318315       
     
    333330       
    334331        //Update team scores
    335         points.set(creature.group.index, points[creature.group.index] + ExpParams.pointsRetrieve);
    336         retrieved.set(creature.group.index, retrieved[creature.group.index] + 1);
     332        points[creature.population.index] = points[creature.population.index] + ExpParams.pointsRetrieve;
     333        retrieved[creature.population.index] = retrieved[creature.population.index] + 1;
    337334}
    338335
    339336function scoreFlag(flag, creature){
    340337        //Put the flag back on its spot and delete references between player and flag
    341         creature.user2.signals[0].flavor = creature.user2.group.index;
     338        creature.user2.signals[0].flavor = creature.user2.population.index;
    342339        creature.user2.user1 = 0;
    343340        creature.user2.user2 = 0;
     
    354351       
    355352        //Update team points
    356         points.set(creature.group.index, points[creature.group.index] + ExpParams.pointsScoring);
    357         scored.set(creature.group.index, scored[creature.group.index] + 1);
     353        points[creature.population.index] = points[creature.population.index] + ExpParams.pointsScoring;
     354        scored[creature.population.index] = scored[creature.population.index] + 1;
    358355}
    359356
     
    385382        if (colFlag == 1){
    386383                //Collision with my flag which is taken
    387                 if (flag.group.index == creature.group.index && flag.user1 == 1){
     384                if (flag.population.index == creature.population.index && flag.user1 == 1){
    388385                        retrieveFlag(flag, creature);
    389386                } //Collision with my flag which is not taken while carrying another team's flag
    390                 else if (flag.group.index == creature.group.index && flag.user1 == 0 && creature.user1 == 1 && flag.user3 != 1){
     387                else if (flag.population.index == creature.population.index && flag.user1 == 0 && creature.user1 == 1 && flag.user3 != 1){
    391388                        scoreFlag(flag, creature);
    392389                } //Collision with another team's flag which is not taken while not carrying any flag
    393                 else if (flag.group.index != creature.group.index && flag.user1 == 0 && creature.user1 == 0 && flag.user3 != 1){
     390                else if (flag.population.index != creature.population.index && flag.user1 == 0 && creature.user1 == 0 && flag.user3 != 1){
    394391                        takeFlag(flag, creature);
    395392                }
     
    398395        else {
    399396                //Players of different teams
    400                 if (c1.group.index != c2.group.index){
     397                if (c1.population.index != c2.population.index){
    401398                        //If player 1 has a flag ...
    402399                        if (c1.user1 == 1){
    403400                                // ... and the flag is of my team ...
    404                                 if (c2.group.index == c1.user2.group.index){
     401                                if (c2.population.index == c1.user2.population.index){
    405402                                        //... retrieve it
    406403                                        retrieveFlag(c1.user2, c2);
     
    410407                        if (c2.user1 == 1){
    411408                                // ... and the flag is of my team ...
    412                                  if (c1.group.index == c2.user2.group.index){
     409                                 if (c1.population.index == c2.user2.population.index){
    413410                                        //... retrieve it
    414411                                        retrieveFlag(c2.user2, c1);
  • 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.