Changeset 233 for experiments/frams
- Timestamp:
- 04/29/14 18:26:49 (11 years ago)
- Location:
- experiments/frams
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
experiments/frams/capture-the-flag/data/scripts/capture-the-flag.expdef
r232 r233 54 54 } 55 55 56 function onBorn( )57 { 58 Creature.energ0 = 100;59 Creature.energy = Creature.energ0;60 } 61 62 function onDied( )56 function onBorn(cr) 57 { 58 cr.energ0 = 100; 59 cr.energy = cr.energ0; 60 } 61 62 function onDied(cr) 63 63 { 64 64 … … 87 87 //Create GenePool and Population for each team 88 88 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); 93 94 94 95 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; 104 106 105 107 var i = 2; 106 108 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;"; 112 114 } 113 115 114 116 //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")); 122 124 } 123 125 … … 127 129 128 130 //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 = []; 136 138 137 139 //Init global vectors … … 201 203 Populations[team].delete(0); 202 204 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; 205 213 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 217 214 var crX, crY; 218 215 219 216 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]); 222 219 crX = Math.random(30) - 15; 223 220 if (crX >=0 && crX < 5) … … 230 227 else if (crY > -5 && crY < 0) 231 228 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; 236 233 } 237 234 } … … 245 242 GenePools[team].delete(0); 246 243 if (team != 1) 247 GenePools[team].add Geno(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")); 248 245 else if (team == 1) 249 GenePools[team].add Geno(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")); 250 247 } 251 248 } … … 257 254 //Update flags position if taken and cooldown if recently retrieved 258 255 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; 263 260 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); 268 265 } 269 266 } … … 286 283 287 284 function 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); 289 286 } 290 287 … … 295 292 296 293 //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; 298 295 flag.user1 = 1; 299 296 flag.user2 = creature; … … 307 304 308 305 //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; 311 308 312 309 } … … 314 311 function retrieveFlag(flag, creature){ 315 312 //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; 317 314 flag.user1 = 0; 318 315 … … 333 330 334 331 //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; 337 334 } 338 335 339 336 function scoreFlag(flag, creature){ 340 337 //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; 342 339 creature.user2.user1 = 0; 343 340 creature.user2.user2 = 0; … … 354 351 355 352 //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; 358 355 } 359 356 … … 385 382 if (colFlag == 1){ 386 383 //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){ 388 385 retrieveFlag(flag, creature); 389 386 } //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){ 391 388 scoreFlag(flag, creature); 392 389 } //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){ 394 391 takeFlag(flag, creature); 395 392 } … … 398 395 else { 399 396 //Players of different teams 400 if (c1. group.index != c2.group.index){397 if (c1.population.index != c2.population.index){ 401 398 //If player 1 has a flag ... 402 399 if (c1.user1 == 1){ 403 400 // ... 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){ 405 402 //... retrieve it 406 403 retrieveFlag(c1.user2, c2); … … 410 407 if (c2.user1 == 1){ 411 408 // ... 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){ 413 410 //... retrieve it 414 411 retrieveFlag(c2.user2, c1); -
experiments/frams/deathmatch/data/scripts/deathmatch.expdef
r231 r233 26 26 initPopulations(); 27 27 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 29 p:-0.5, -0.5, -0.5 30 p: 0.5, -0.5, -0.5 31 p: 0.5, 0.5, -0.5 32 p: -0.5, 0.5, -0.5 33 p:-0.5, -0.5, 0.5 34 p:0.5, -0.5, 0.5 35 p:0.5, 0.5, 0.5 36 p:-0.5, 0.5, 0.5 37 j: 0,1 38 j: 1,2 39 j: 2,3 40 j: 3,0 41 j: 4,5 42 j: 5,6 43 j: 6,7 44 j: 7,4 45 j: 0,4 46 j: 1,5 47 j: 2,6 48 j: 3,7""", 0x0FAA0F); 49 50 Shapes.set("1p_hpbox","""//0 51 p:-0.5, -0.5, -0.5 52 p: 0.5, -0.5, -0.5 53 p: 0.5, 0.5, -0.5 54 p: -0.5, 0.5, -0.5 55 p:-0.5, -0.5, 0.5 56 p:0.5, -0.5, 0.5 57 p:0.5, 0.5, 0.5 58 p:-0.5, 0.5, 0.5 59 j: 0,1 60 j: 1,2 61 j: 2,3 62 j: 3,0 63 j: 4,5 64 j: 5,6 65 j: 6,7 66 j: 7,4 67 j: 0,4 68 j: 1,5 69 j: 2,6 70 j: 3,7""", 0xAA0F0F); 71 71 } 72 72 … … 77 77 78 78 //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; 86 87 87 88 //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; 95 96 96 97 //add Teams populations (group above 2) 97 98 var i = 0; 98 99 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; 103 102 for (i = 0; i < teams; i++) 104 103 { 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; 112 111 } 113 112 … … 127 126 function initCreatures() 128 127 { 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++) 136 131 { 132 var g; //Genotype object 137 133 if (ExpParams.teamCount != 1) 138 GenePools.genotype = Math.random(GenePool.size);134 g = GenePools[0].random(); 139 135 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; 143 138 } 144 139 } … … 169 164 170 165 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++) 173 167 { 174 168 s += "Team " + i + "; "; … … 204 198 function tryCreateHPBox() 205 199 { 206 Populations.group = 0; 207 208 if (Population.size >= ExpParams.hpBoxTotalCount) return; 200 if (Populations[0].size >= ExpParams.hpBoxTotalCount) return; 209 201 210 202 if (Math.rnd01 > ExpParams.hpBoxProbability) return; 211 203 212 var food = Populations .createFromString("//0\nm:Vstyle=hpbox\np:");204 var food = Populations[0].add("//0\nm:Vstyle=hpbox\np:"); 213 205 food.name = "HP Box"; 214 206 food.idleen = ExpParams.hpBoxIdleEnergy; … … 220 212 function tryCreateUpgradeBox() 221 213 { 222 Populations.group = 1; 223 224 if (Population.size >= ExpParams.upgradeBoxTotalCount) return; 214 if (Populations[1].size >= ExpParams.upgradeBoxTotalCount) return; 225 215 226 216 if (Math.rnd01 > ExpParams.upgradeBoxProbability) return; 227 217 228 var weapon = Populations .createFromString("//0\nm:Vstyle=weaponbox\np:");218 var weapon = Populations[1].add("//0\nm:Vstyle=weaponbox\np:"); 229 219 weapon.name = "Weapon Box"; 230 220 weapon.idleen = ExpParams.upgradeBoxIdleEnergy; … … 235 225 236 226 //handle creature placement in the world 237 function onBorn( )227 function onBorn(cr) 238 228 { 239 229 // place newly born creature … … 242 232 while (retry-- && !placed_ok) 243 233 { 244 switch ( Populations.group)234 switch (cr.population.index) 245 235 { 246 236 case 0: //food placement 247 place_centerhead( );237 place_centerhead(cr); 248 238 break; 249 239 case 1: //upgrade placement 250 place_centerhead( );240 place_centerhead(cr); 251 241 break; 252 242 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); 267 249 break; 268 250 } 269 251 270 if (! Populations.creatBBCollisions(0))271 placed_ok = 1;252 if (!cr.boundingBoxCollisions(0)) 253 {placed_ok=1; break;} 272 254 } 273 255 if (!placed_ok) … … 276 258 277 259 //place creature in random spot and make it head center of the map 278 function place_centerhead( )260 function place_centerhead(cr) 279 261 { 280 262 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; 283 265 z = WorldMap.getHeight(x, y); 284 266 … … 287 269 var alpha_rad = vectorsAngle([1.0, 0.0], [hx, hy]); 288 270 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); 291 273 292 274 print("Creature placed in [" + x +" " + y + " " + z); … … 297 279 //Place creature in correct team spot (valid for Team creatures only) 298 280 //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;281 function place_inTeamSpot(cr) 282 { 283 var radius = 360.00 * (cr.population.index - 1) / teams; 302 284 303 285 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; 306 288 307 289 //vector of length half the world size minus spawning area size … … 324 306 //var alpha_rad = vectorsAngle([1.0, 0.0], [hx, hy]); 325 307 326 Creature.rotate(0, 0, alpha_rad);308 cr.rotate(0, 0, alpha_rad); 327 309 //place it mid-air 328 Creature.moveAbs(x, y, z);310 cr.moveAbs(x, y, z); 329 311 330 312 return ; … … 350 332 { 351 333 var s = "" + Simulator.time + "; "; 352 var i = 0;353 var j = 0;354 334 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; 364 341 s += "" + sum + "; "; 365 s += "" + Population.size + "; ";366 342 s += "" + pop.size + "; "; 343 total += sum; 367 344 } 368 345 if (total < 0) total == 0; … … 376 353 function clearDeadCreatures() 377 354 { 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 366 function 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 375 function lowerCooldownCounters() 376 { 377 for (var i = 2; i < Populations.size; i++) 378 { 379 var pop=Populations[i]; 380 for (var cr in pop) 384 381 { 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) 418 383 { 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; 423 388 } 424 389 } … … 428 393 function checkGameState() 429 394 { 430 var i = 0;431 395 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; 437 398 438 399 if (alivePop == 0 && Simulator.time <= 1) … … 444 405 if (alivePop <= 1) 445 406 { 446 for ( i = 0; i < Populations.size - 2; i++)407 for (var i = 2; i < Populations.size; i++) 447 408 { 448 Populations.group = i + 2;449 if ( Population.size > 0)409 var pop=Populations[i]; 410 if (pop.size > 0) 450 411 { 451 Simulator.print("Battle is OVER! The winner is: " + Population.name);412 Simulator.print("Battle is OVER! The winner is: " + pop.name); 452 413 453 414 //write stats of last living creatures 454 415 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) 457 417 { 458 Populations.creature = j;459 418 //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"); 462 421 } 463 422 … … 502 461 } 503 462 504 if (c1. group == null || c2.group== null)463 if (c1.population == null || c2.population == null) 505 464 { 506 465 //collision of creature without a group … … 510 469 511 470 //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) 513 472 { 514 473 //collision with HP Box and Upgrades are handled separately … … 524 483 var dice2 = 0; 525 484 var changed = 0; 526 var i = 0; 527 for (i = 0; i < ExpParams.diceCount; i++) 485 for (var i = 0; i < ExpParams.diceCount; i++) 528 486 { 529 487 dice1 = dice1 + Math.random(ExpParams.diceSides) + 1; … … 534 492 energy1 += ExpParams.upgradeMultiplier * c1.user1.get(1); 535 493 energy2 += ExpParams.upgradeMultiplier * c2.user1.get(1); 536 if (c1. group == c2.group)494 if (c1.population == c2.population) 537 495 { 538 496 energy1 = ExpParams.friendlyFireDamageMultiplier * energy1; … … 547 505 if (c2.user2 == null) stop("3"); 548 506 549 if (c2.user1 .get(0)<= 0 && energy2 > 0)507 if (c2.user1[0] <= 0 && energy2 > 0) 550 508 { 551 509 changed = 1; … … 553 511 c1.energy = c1.energy - energy2; 554 512 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 + "]"); 556 514 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]; 562 518 var arrindex = arrayContains(c1.user3, 0, c2.uid); 563 519 if (arrindex != -1) 564 520 { 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; 567 523 } 568 524 else … … 572 528 c1.user3.add(vect); 573 529 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 577 531 } 578 532 if (c1.energy <= 0) 579 533 { 580 c2.user2 .set(0, c2.user2.get(0) + 1); //increase kills statistic534 c2.user2[0] = c2.user2[0] + 1; //increase kills statistic 581 535 kill_c1 = 1; 582 536 } 583 537 } 584 538 585 if (c1.user1 .get(0)<= 0 && energy1 > 0)539 if (c1.user1[0] <= 0 && energy1 > 0) 586 540 { 587 541 changed = 1; … … 589 543 c2.energy = c2.energy - energy1; 590 544 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; 595 549 var vect = Vector.new(); 596 550 vect.add(c1.uid); … … 599 553 if (arrindex != -1) 600 554 { 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; 603 557 } 604 558 else … … 609 563 if (c2.energy > 0) 610 564 { 611 c1.user2 .set(1, c1.user2.get(1) + 1); //increase assists statistic565 c1.user2[1] = c1.user2[1] + 1; //increase assists statistic 612 566 } 613 567 } 614 568 if (c2.energy <= 0) 615 569 { 616 c1.user2 .set(0, c1.user2.get(0) + 1); //increase kills statistic570 c1.user2[0] = c1.user2[0] + 1; //increase kills statistic 617 571 kill_c2 = 1; 618 572 } … … 626 580 //resolve kills 627 581 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); 634 583 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); 641 585 } 642 586 … … 647 591 648 592 //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; 653 597 654 598 //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); 658 600 659 601 writeTeamStatistics(); … … 666 608 667 609 //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; 672 614 673 615 //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); 677 617 678 618 writeTeamStatistics(); … … 681 621 //function executed on Creature death 682 622 //TODO: implement some statistics for dieing creature 683 function onDied( )623 function onDied(cr) 684 624 { 685 625 //ignore death of hp boxes and upgrades 686 if ( Populations.group< 2)626 if (cr.population.index < 2) 687 627 return ; 688 628 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"); 695 632 696 633 var f=File.appendDirect("creatures"+battleNumber+".txt","Creature statistics"); 697 634 //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"); 699 636 f.close(); 700 637
Note: See TracChangeset
for help on using the changeset viewer.