Ignore:
Timestamp:
11/09/16 04:29:53 (8 years ago)
Author:
sz
Message:

Updated the script to use more modern framscript features, most notably creature.data dictionary instead of creature->user1/2/3
Creature properties mapping: old --- new
user1[0] --- data->cooldown
user1[1] --- data->bonusdamage
user2[0] --- data->kills
user2[1] --- data->assists
user2[2] --- data->damagedealt
user2[3] --- data->damagereceived
user2[4] --- data->hpcollected
user2[5] --- data->upgradecollected
user3 --- data->damagefrom

Location:
experiments/frams/deathmatch/data/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • experiments/frams/deathmatch/data/scripts/deathmatch-utils.inc

    r231 r631  
    5656  for (i = 0; i < array.size; i++)
    5757  {
    58     if (array.get(i) != null)
    59       if (array.get(i).get(column) == value) return i;
     58    if (array[i] != null)
     59      if (array[i][column] == value) return i;
    6060  }
    6161  return -1;
  • experiments/frams/deathmatch/data/scripts/deathmatch.expdef

    r537 r631  
    184184    levelNumber = ExpProperties.level;
    185185
    186   var level = levels.get(levelNumber);
     186  var level = levels[levelNumber];
    187187  Simulator.print("Level #" + (levelNumber + 1) + ": " + level[0]);
    188188
     
    205205  food.name = "HP Box";
    206206  food.idleen = ExpProperties.hpBoxIdleEnergy;
    207   food.energ0 = ExpProperties.hpBoxStartingEnergy;
    208   food.energy = food.energ0;
     207  food.energy0 = ExpProperties.hpBoxStartingEnergy;
     208  food.energy = food.energy0;
    209209  food.nnenabled = 0;
    210210}
     
    219219  weapon.name = "Weapon Box";
    220220  weapon.idleen = ExpProperties.upgradeBoxIdleEnergy;
    221   weapon.energ0 = ExpProperties.upgradeBoxStartingEnergy;
    222   weapon.energy = weapon.energ0;
     221  weapon.energy0 = ExpProperties.upgradeBoxStartingEnergy;
     222  weapon.energy = weapon.energy0;
    223223  weapon.nnenabled = 0;
    224224}
     
    241241      break;
    242242    default:
    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 = ExpProperties.creatureStartingEnergy;
    247           cr.energy = cr.energ0;
     243      cr.data->cooldown=0.0;
     244      cr.data->bonusdamage=0.0;
     245      cr.data->kills=0;
     246      cr.data->assists=0;
     247      cr.data->damagedealt=0;
     248      cr.data->damagereceived=0;
     249      cr.data->hpcollected=0;
     250      cr.data->upgradecollected=0;
     251      cr.data->damagefrom=[]; //who dealt damage to this creature
     252      cr.energy0 = ExpProperties.creatureStartingEnergy;
     253      cr.energy = cr.energy0;
    248254      place_inTeamSpot(cr);
    249255      break;
     
    261267{
    262268  var x, y, z;
    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;
     269  var size=cr.bboxSize;
     270  x = (World.wrldsiz - size.x) * Math.rnd01 - size.x / 2;
     271  y = (World.wrldsiz - size.y) * Math.rnd01 - size.y / 2;
    265272  z = WorldMap.getHeight(x, y);
    266273
     
    270277
    271278  cr.rotate(0, 0, alpha_rad);
    272   cr.moveAbs(x, y, z - 0.999);
     279  cr.locationSetBboxLow(x, y, z - 0.999);
    273280 
    274281  print("Creature placed in [" + x +" " + y + " " + z);
     
    284291
    285292  var x, y, z;
    286   x = (ExpProperties.teamSpawningAreaSize) * Math.rnd01 - cr.size_x / 2 - ExpProperties.teamSpawningAreaSize/2;
    287   y = (ExpProperties.teamSpawningAreaSize) * Math.rnd01 - cr.size_y / 2 - ExpProperties.teamSpawningAreaSize/2;
     293  x = (ExpProperties.teamSpawningAreaSize) * Math.rnd01 - cr.bboxSize.x / 2 - ExpProperties.teamSpawningAreaSize/2;
     294  y = (ExpProperties.teamSpawningAreaSize) * Math.rnd01 - cr.bboxSize.y / 2 - ExpProperties.teamSpawningAreaSize/2;
    288295 
    289296  //vector of length half the world size minus spawning area size
     
    308315  cr.rotate(0, 0, alpha_rad);
    309316  //place it mid-air
    310   cr.moveAbs(x, y, z);
     317  cr.locationSetBboxLow(x, y, z);
    311318
    312319  return ;
     
    331338function writeTeamStatistics()
    332339{
    333   var s = "" + Simulator.time + "; ";
     340  var s = string(Simulator.stepNumber) + "; ";
    334341  var total = 0.0;
    335342  for (var i = 2; i < Populations.size; i++)
     
    380387        for (var cr in pop)
    381388        {
    382           if (cr.user1 != null)
     389          if (cr.data->cooldown != null)
    383390          {
    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] - ExpProperties.upgradeBoxDecay;
    387             if (cr.user1[1] < 0) cr.user1[1]=0.0;
     391            if (cr.data->cooldown > 0) cr.data->cooldown-=1;
     392            if (cr.data->cooldown < 0) cr.data->cooldown=0.0;
     393          }
     394          if (cr.data->bonusdamage != null)
     395          {
     396            if (cr.data->bonusdamage > 0) cr.data->bonusdamage-=ExpProperties.upgradeBoxDecay;
     397            if (cr.data->bonusdamage < 0) cr.data->bonusdamage=0.0;
    388398          }
    389399        }
     
    397407    if (Populations[i].size > 0) alivePop += 1;
    398408 
    399   if (alivePop == 0 && Simulator.time <= 1)
     409  if (alivePop == 0 && Simulator.stepNumber <= 1)
    400410  {
    401411    onExpInit(); //do initialization for user, because he forgot to do so
     
    417427                {
    418428                  //f.writeString("Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan");
    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");
     429                  if (cr.data->kills != null)
     430                    f.writeString(cr.name + "; " + pop.name + "; " + cr.data->kills + "; " + cr.data->assists + "; " + cr.data->damagedealt + "; " + cr.data->damagereceived + "; " + cr.data->hpcollected + "; " + cr.data->upgradecollected + "; " + cr.lifespan + "\n");
    421431                }
    422432
     
    490500  var energy1 = 0.0 + ExpProperties.creatureDamage * dice1;
    491501  var energy2 = 0.0 + ExpProperties.creatureDamage * dice2;
    492   energy1 += ExpProperties.upgradeMultiplier * c1.user1.get(1);
    493   energy2 += ExpProperties.upgradeMultiplier * c2.user1.get(1);
     502  energy1 += ExpProperties.upgradeMultiplier * c1.data->bonusdamage;
     503  energy2 += ExpProperties.upgradeMultiplier * c2.data->bonusdamage;
    494504  if (c1.population == c2.population)
    495505  {
     
    498508  }
    499509 
    500   if (c1.user1 == null) stop("3");
    501   if (c1.user2 == null) stop("3");
    502   if (c1.user3 == null) stop("3");
    503   if (c2.user1 == null) stop("3");
    504   if (c2.user2 == null) stop("3");
    505   if (c2.user2 == null) stop("3");
    506  
    507   if (c2.user1[0] <= 0 && energy2 > 0)
     510  if (c1.data->cooldown == null) stop("3");
     511  if (c2.data->cooldown == null) stop("3");
     512 
     513  if (c2.data->cooldown <= 0 && energy2 > 0)
    508514  {
    509515    changed = 1;
     
    511517    c1.energy = c1.energy - energy2;
    512518        if (c1.energy < 0) c1.energy = 0;
    513     print(c2.name + " [" + c2.population.name + "] rolled " + dice2 + " and dealt " + energy2 + " [+" + (ExpProperties.upgradeMultiplier * c2.user1[1]) +" bonus] damage to " + c1.name + " [" + c1.population.name + "]");
    514         c2.user1.set(0, ExpProperties.attackCooldown);
    515         c2.user2.set(2, c2.user2[2] + energy1);
    516         c1.user2.set(3, c1.user2[3] + energy1);
     519    print(c2.name + " [" + c2.population.name + "] rolled " + dice2 + " and dealt " + energy2 + " [+" + (ExpProperties.upgradeMultiplier * c2.data->bonusdamage) +" bonus] damage to " + c1.name + " [" + c1.population.name + "]");
     520        c2.data->cooldown = ExpProperties.attackCooldown;
     521        c2.data->damagedealt += energy1;
     522        c1.data->damagereceived += energy1;
    517523        var vect = [c2.uid,c2.name];
    518         var arrindex = arrayContains(c1.user3, 0, c2.uid);
     524        var arrindex = arrayContains(c1.data->damagefrom, 0, c2.uid);
    519525        if (arrindex != -1)
    520526        {
    521           vect.add(energy2 + c1.user3[arrindex][2]);
    522           c1.user3[arrindex]=vect;
     527          vect.add(energy2 + c1.data->damagefrom[arrindex][2]);
     528          c1.data->damagefrom[arrindex]=vect;
    523529        }
    524530        else
    525531        {
    526532          vect.add(energy2);
    527           if (c1.user3 == null) c1.user3 = Vector.new();
    528           c1.user3.add(vect);
     533          if (c1.data->damagefrom == null) c1.data->damagefrom = [];
     534          c1.data->damagefrom.add(vect);
    529535          if (c1.energy > 0)
    530             c2.user2[1] = c2.user2[1] + 1; //increase assists statistic
     536            c2.data->assists += 1; //increase assists statistic
    531537        }
    532538        if (c1.energy <= 0)
    533539        {
    534           c2.user2[0] = c2.user2[0] + 1; //increase kills statistic
     540          c2.data->kills += 1; //increase kills statistic
    535541          kill_c1 = 1;
    536542        }
    537543  }
    538544 
    539   if (c1.user1[0] <= 0 && energy1 > 0)
     545  if (c1.data->cooldown <= 0 && energy1 > 0)
    540546  {
    541547    changed = 1;
     
    543549    c2.energy = c2.energy - energy1;
    544550        if (c2.energy < 0) c2.energy = 0;
    545     print(c1.name + " [" + c1.population.name + "] rolled " + dice1 + " and dealt " + energy1 + " [+" + (ExpProperties.upgradeMultiplier * c1.user1[1]) +" bonus] damage to " + c2.name + " [" + c2.population.name + "]");
    546     c1.user1[0] = ExpProperties.attackCooldown;
    547         c1.user2[2] = c1.user2[2] + energy1;
    548         c2.user2[3] = c2.user2[3] + energy1;
     551    print(c1.name + " [" + c1.population.name + "] rolled " + dice1 + " and dealt " + energy1 + " [+" + (ExpProperties.upgradeMultiplier * c1.data->bonusdamage) +" bonus] damage to " + c2.name + " [" + c2.population.name + "]");
     552    c1.data->cooldown = ExpProperties.attackCooldown;
     553        c1.data->damagedealt += energy1;
     554        c2.data->damagereceived += energy1;
    549555        var vect = Vector.new();
    550556        vect.add(c1.uid);
    551557        vect.add(c1.name);
    552         var arrindex = arrayContains(c2.user3, 0, c1.uid);
     558        var arrindex = arrayContains(c2.data->damagefrom, 0, c1.uid);
    553559        if (arrindex != -1)
    554560        {
    555           vect.add(energy1 + c2.user3[arrindex][2]);
    556           c2.user3[arrindex] = vect;
     561          vect.add(energy1 + c2.data->damagefrom[arrindex][2]);
     562          c2.data->damagefrom[arrindex] = vect;
    557563        }
    558564        else
    559565        {
    560566          vect.add(energy1);
    561           if (c2.user3 == null) c2.user3 = Vector.new();
    562           c2.user3.add(vect);
     567          if (c2.data->damagefrom == null) c2.data->damagefrom = [];
     568          c2.data->damagefrom.add(vect);
    563569          if (c2.energy > 0)
    564570          {
    565         c1.user2[1] = c1.user2[1] + 1; //increase assists statistic
     571        c1.data->assists += 1; //increase assists statistic
    566572          }
    567573        }
    568574        if (c2.energy <= 0)
    569575        {
    570           c1.user2[0] = c1.user2[0] + 1; //increase kills statistic
     576          c1.data->kills += 1; //increase kills statistic
    571577          kill_c2 = 1;
    572578        }
     
    592598  //collect HP Box (by eating it :D)
    593599  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;
     600  Collision.Creature2.data->hpcollected += 1;
     601  Collision.Creature1.transferEnergyTo(Collision.Creature2,Collision.Creature1.energy);
    597602 
    598603  //kill HP Box
     
    609614  //collect Upgrade Box (by eating it :D)
    610615  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;
     616  Collision.Creature2.data->upgradecollected += 1;
     617  Collision.Creature2.data->bonusdamage += Collision.Creature1.energy;
     618  Collision.Creature1.energy = 0;
    614619 
    615620  //kill Upgrade Box
     
    628633
    629634  print(cr.name + " was killed");
    630   for (var dam in cr.user3)
     635  for (var dam in cr.data->damagefrom)
    631636    print(dam[1] + " dealt " + dam[2] + " damage");
    632637 
    633638  var f=File.appendDirect("creatures"+battleNumber+".txt","Creature statistics");
    634639  //f.writeString("Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan");
    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");
     640  f.writeString(cr.name + "; " + cr.population.name + "; " + cr.data->kills + "; " + cr.data->assists + "; " + cr.data->damagedealt + "; " + cr.data->damagereceived + "; " + cr.data->hpcollected + "; " + cr.data->upgradecollected + "; " + cr.lifespan + "\n");
    636641  f.close();
    637642 
Note: See TracChangeset for help on using the changeset viewer.