Changeset 485


Ignore:
Timestamp:
03/26/16 02:33:51 (8 years ago)
Author:
sz
Message:

capture-the-flag using data->fields:

  • creature.user1/user2/user3 >>> creature.data->holding / creature.data->flag / creature.data->score
  • flag.user1/user2/user3 >>> flag.data->taken / flag.data->owner / flag.data->cooldown
File:
1 edited

Legend:

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

    r480 r485  
    8989        var pool=GenePools[0];
    9090        pool.name = "Team1";
    91         pool.fitness = "return this.user3;";
     91        pool.fitness = "return 0;";
    9292        while (pool.size > 0)
    9393                pool.delete(0);
     
    111111        pop.othermask = 0x60001;
    112112                pool=GenePools.addGroup("Team"+i);
    113                 pool.fitness = "return this.user3;";   
     113                pool.fitness = "return 0;";
    114114        }
    115115       
     
    208208                cr.signals[0].flavor = team;
    209209                cr.signals[0].power=1000;
    210                 cr.user1 = 0;
    211                 cr.user2 = 0;
    212                 cr.user3 = 0;
     210                cr.data->taken = 0;
     211                cr.data->owner = 0;
     212                cr.data->cooldown = 0;
    213213               
    214214                var crX, crY;
     
    228228                                crY = -5;
    229229                        cr.moveAbs(flagsX[team] + crX, flagsY[team] + crY, 0);
    230                         cr.user1 = 0;
    231                         cr.user2 = 0;
    232                         cr.user3 = 0;
     230                        cr.data->holding = 0;
     231                        cr.data->flag = 0;
     232                        cr.data->score = 0;
    233233                }
    234234        }
     
    256256                var pop=Populations[team];
    257257
    258                 if (pop[0].user3 > 0)
    259                         pop[0].user3 -= 1;
     258                if (pop[0].data->cooldown > 0)
     259                        pop[0].data->cooldown -= 1;
    260260               
    261261                for (player = 1; player < pop.size; player++){
    262262                        var cr=pop[player];
    263                         if (cr.user1 == 1){
    264                                 cr.user2.moveAbs(cr.pos_x, cr.pos_y, cr.size_z + 1);
     263                        if (cr.data->holding == 1){
     264                                cr.data->flag.moveAbs(cr.pos_x, cr.pos_y, cr.size_z + 1);
    265265                        }
    266266                }
     
    288288function takeFlag(flag, creature){
    289289        //If the cooldown is on - do nothing
    290         if (flag.user3 > 0)
     290        if (flag.data->cooldown > 0)
    291291                return;
    292292       
    293293        //Take flag by changing its flavour and setting flag in player and player in flag fields
    294294        flag.signals[0].flavor = flag.population.index + 100;
    295         flag.user1 = 1;
    296         flag.user2 = creature;
    297         creature.user1 = 1;
    298         creature.user2 = flag;
     295        flag.data->taken = 1;
     296        flag.data->owner = creature;
     297        creature.data->holding = 1;
     298        creature.data->flag = flag;
    299299       
    300300        //Score points for taking a flag
    301         creature.user3 += ExpProperties.pointsCapture;
     301        creature.data->score += ExpProperties.pointsCapture;
    302302       
    303303//      Simulator.print("Flag "+(flag.group.index+1)+" taken by team "+(creature.group.index+1));
     
    312312        //Retrieve flag by changing its flavour and deleting it from player and player from flag
    313313        flag.signals[0].flavor = flag.population.index;
    314         flag.user1 = 0;
    315        
    316         flag.user2.user1 = 0;
    317         flag.user2.user2 = 0;
    318        
    319         flag.user2 = 0;
     314        flag.data->taken = 0;
     315       
     316        flag.data->owner.data->holding = 0;
     317        flag.data->owner.data->flag = 0;
     318       
     319        flag.data->owner = 0;
    320320       
    321321        //Set cooldown for taking a flag
    322         flag.user3 = 1000;
     322        flag.data->cooldown = 1000;
    323323       
    324324        placeFlag(flag);
    325325
    326326        //Score points for retrieving a flag
    327         creature.user3 += ExpProperties.pointsRetrieve;
     327        creature.data->score += ExpProperties.pointsRetrieve;
    328328       
    329329//      Simulator.print("Flag "+ (flag.group.index+1) +" retrieved");
     
    336336function scoreFlag(flag, creature){
    337337        //Put the flag back on its spot and delete references between player and flag
    338         creature.user2.signals[0].flavor = creature.user2.population.index;
    339         creature.user2.user1 = 0;
    340         creature.user2.user2 = 0;
    341        
    342         placeFlag(creature.user2);
    343        
    344         creature.user1 = 0;
    345         creature.user2 = 0;
     338        creature.data->flag.signals[0].flavor = creature.data->flag.population.index;
     339        creature.data->flag.data->taken = 0;
     340        creature.data->flag.data->owner = 0;
     341       
     342        placeFlag(creature.data->flag);
     343       
     344        creature.data->holding = 0;
     345        creature.data->flag = 0;
    346346       
    347347        //Score points for scoring a flag
    348         creature.user3 += ExpProperties.pointsScoring;
     348        creature.data->score += ExpProperties.pointsScoring;
    349349       
    350350//      Simulator.print("Team "+ (creature.group.index + 1) +" scored");
     
    382382        if (colFlag == 1){
    383383                //Collision with my flag which is taken
    384                 if (flag.population.index == creature.population.index && flag.user1 == 1){
     384                if (flag.population.index == creature.population.index && flag.data->taken == 1){
    385385                        retrieveFlag(flag, creature);
    386386                } //Collision with my flag which is not taken while carrying another team's flag
    387                 else if (flag.population.index == creature.population.index && flag.user1 == 0 && creature.user1 == 1 && flag.user3 != 1){
     387                else if (flag.population.index == creature.population.index && flag.data->taken == 0 && creature.data->holding == 1 && flag.data->cooldown != 1){
    388388                        scoreFlag(flag, creature);
    389389                } //Collision with another team's flag which is not taken while not carrying any flag
    390                 else if (flag.population.index != creature.population.index && flag.user1 == 0 && creature.user1 == 0 && flag.user3 != 1){
     390                else if (flag.population.index != creature.population.index && flag.data->taken == 0 && creature.data->holding == 0 && flag.data->cooldown != 1){
    391391                        takeFlag(flag, creature);
    392392                }
     
    397397                if (c1.population.index != c2.population.index){
    398398                        //If player 1 has a flag ...
    399                         if (c1.user1 == 1){
     399                        if (c1.data->holding == 1){
    400400                                // ... and the flag is of my team ...
    401                                 if (c2.population.index == c1.user2.population.index){
     401                                if (c2.population.index == c1.data->flag.population.index){
    402402                                        //... retrieve it
    403                                         retrieveFlag(c1.user2, c2);
     403                                        retrieveFlag(c1.data->flag, c2);
    404404                                }
    405405                        }
    406406                        //If player 2 has a flag ...
    407                         if (c2.user1 == 1){
     407                        if (c2.data->holding == 1){
    408408                                // ... and the flag is of my team ...
    409                                  if (c1.population.index == c2.user2.population.index){
     409                                 if (c1.population.index == c2.data->flag.population.index){
    410410                                        //... retrieve it
    411                                         retrieveFlag(c2.user2, c1);
     411                                        retrieveFlag(c2.data->flag, c1);
    412412                                }
    413413                        }
Note: See TracChangeset for help on using the changeset viewer.