[231] | 1 | expdef:
|
---|
| 2 | name:Deathmatch
|
---|
| 3 | info:~
|
---|
| 4 | This experiment simulates a team deathmatch. It means that framstick creatures are grouped in teams and the basic rule is: "My team vs WORLD!".
|
---|
| 5 |
|
---|
| 6 | The basic battle rules and collectibles are implemented. Statistics for the battle are saved to text files in CSV format: creatures.txt, teams.txt.
|
---|
| 7 |
|
---|
| 8 | For more information, see http://www.framsticks.com/deathmatch
|
---|
| 9 | ~
|
---|
| 10 | code:~
|
---|
| 11 |
|
---|
| 12 | //Author: Mateusz Cicheñski @ Poznan University of Technology, 2012
|
---|
| 13 |
|
---|
| 14 | @include "deathmatch-utils.inc"
|
---|
| 15 | @include "deathmatch-levels.inc"
|
---|
| 16 |
|
---|
| 17 | global idleSimulationSteps;
|
---|
| 18 | global battleNumber;
|
---|
| 19 | global teams;
|
---|
| 20 |
|
---|
| 21 | function onExpDefLoad()
|
---|
| 22 | {
|
---|
| 23 | idleSimulationSteps = 0;
|
---|
| 24 | battleNumber = 0;
|
---|
| 25 | initLevels();
|
---|
| 26 | initPopulations();
|
---|
| 27 |
|
---|
[233] | 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);
|
---|
[231] | 49 |
|
---|
[233] | 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);
|
---|
[231] | 71 | }
|
---|
| 72 |
|
---|
| 73 | function initPopulations()
|
---|
| 74 | {
|
---|
| 75 | //clear anything in populations
|
---|
| 76 | Populations.clear();
|
---|
| 77 |
|
---|
| 78 | //add Food population (group 0)
|
---|
[233] | 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;
|
---|
[231] | 87 |
|
---|
| 88 | //add Weapon Upgrade population (group 1)
|
---|
[233] | 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;
|
---|
[231] | 96 |
|
---|
| 97 | //add Teams populations (group above 2)
|
---|
| 98 | var i = 0;
|
---|
[480] | 99 | teams = ExpProperties.teamCount;
|
---|
[233] | 100 | if (teams == 1)
|
---|
| 101 | teams = GenePools[0].size;
|
---|
[231] | 102 | for (i = 0; i < teams; i++)
|
---|
| 103 | {
|
---|
[233] | 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;
|
---|
[231] | 111 | }
|
---|
| 112 |
|
---|
| 113 | //Collisions on 32 bit mask:
|
---|
| 114 | // standard - rebound creatures => if lower bits 0xFFFF
|
---|
| 115 | // custom - custom function handler => if higher bits 0xFFFF0000
|
---|
| 116 | //Collisions map:
|
---|
| 117 | // Food vs Food = 0x20002 & 0x10002 = 2 - standard
|
---|
| 118 | // Upgrades vs Upgrades = 0x20002 & 0x10002 = 2 - standard
|
---|
| 119 | // Team X vs Team X = 0x50001 & 0x60001 = 0x40001 - standard + custom
|
---|
| 120 | // Team X vs Team Y = 0x50001 & 0x60001 = 0x40001 - standard + custom
|
---|
| 121 | // Food vs Upgrades = 0x20002 & 0x10002 = 2 - standard
|
---|
| 122 | // Food vs Team X = 0x20002 & 0x60001 = 0x20000 || 0x50001 & 0x10002 = 0x10000 - custom
|
---|
| 123 | // Upgrades vs Team X = 0x20002 & 0x60001 = 0x20000 || 0x50001 & 0x10002 = 0x10000 - custom
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | function initCreatures()
|
---|
| 127 | {
|
---|
[233] | 128 | for (var i = 0; i < Populations.size - 2; i++)
|
---|
[231] | 129 | {
|
---|
[480] | 130 | for (var j = 0; j < ExpProperties.teamSize; j++)
|
---|
[231] | 131 | {
|
---|
[233] | 132 | var g; //Genotype object
|
---|
[480] | 133 | if (ExpProperties.teamCount != 1)
|
---|
[233] | 134 | g = GenePools[0].random();
|
---|
[231] | 135 | else
|
---|
[233] | 136 | g = GenePools[0][i];
|
---|
| 137 | Populations[i+2].add(g).name = "Member " + j;
|
---|
[231] | 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | function onExpInit()
|
---|
| 143 | {
|
---|
| 144 | battleNumber = 0;
|
---|
| 145 | initAll();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | function initAll()
|
---|
| 149 | {
|
---|
| 150 | idleSimulationSteps = 0;
|
---|
| 151 | battleNumber += 1;
|
---|
| 152 | initLevel();
|
---|
| 153 | initPopulations();
|
---|
| 154 | initCreatures();
|
---|
| 155 | initFiles();
|
---|
| 156 | writeTeamStatistics();
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | function initFiles()
|
---|
| 160 | {
|
---|
| 161 | var f=File.createDirect("creatures"+battleNumber+".txt","Creature statistics");
|
---|
| 162 | f.writeString("#Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan\n");
|
---|
| 163 | f.close();
|
---|
| 164 |
|
---|
| 165 | var s = "#Time interval; ";
|
---|
[233] | 166 | for (var i = 0; i < Populations.size - 2; i++)
|
---|
[231] | 167 | {
|
---|
| 168 | s += "Team " + i + "; ";
|
---|
| 169 | s += "Team members; ";
|
---|
| 170 | }
|
---|
| 171 | s += "Total energy\n";
|
---|
| 172 |
|
---|
| 173 | var f=File.createDirect("teams"+battleNumber+".txt","Teams statistics");
|
---|
| 174 | f.writeString(s);
|
---|
| 175 | f.close();
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | function initLevel()
|
---|
| 179 | {
|
---|
| 180 | var levelNumber;
|
---|
[480] | 181 | if (ExpProperties.level == -1)
|
---|
[231] | 182 | levelNumber = Math.random(levels.size);
|
---|
| 183 | else
|
---|
[480] | 184 | levelNumber = ExpProperties.level;
|
---|
[231] | 185 |
|
---|
| 186 | var level = levels.get(levelNumber);
|
---|
| 187 | Simulator.print("Level #" + (levelNumber + 1) + ": " + level[0]);
|
---|
| 188 |
|
---|
| 189 | World.wrldbnd = level[2];
|
---|
| 190 | World.wrldsiz = level[1];
|
---|
| 191 | World.wrldwat = -1;
|
---|
| 192 | World.wrldtyp = level[3];
|
---|
| 193 | World.wrldmap = level[4];
|
---|
| 194 |
|
---|
| 195 | World.wrldchg();
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | function tryCreateHPBox()
|
---|
| 199 | {
|
---|
[480] | 200 | if (Populations[0].size >= ExpProperties.hpBoxTotalCount) return;
|
---|
[231] | 201 |
|
---|
[480] | 202 | if (Math.rnd01 > ExpProperties.hpBoxProbability) return;
|
---|
[231] | 203 |
|
---|
[233] | 204 | var food = Populations[0].add("//0\nm:Vstyle=hpbox\np:");
|
---|
[231] | 205 | food.name = "HP Box";
|
---|
[480] | 206 | food.idleen = ExpProperties.hpBoxIdleEnergy;
|
---|
| 207 | food.energ0 = ExpProperties.hpBoxStartingEnergy;
|
---|
[231] | 208 | food.energy = food.energ0;
|
---|
| 209 | food.nnenabled = 0;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | function tryCreateUpgradeBox()
|
---|
| 213 | {
|
---|
[480] | 214 | if (Populations[1].size >= ExpProperties.upgradeBoxTotalCount) return;
|
---|
[231] | 215 |
|
---|
[480] | 216 | if (Math.rnd01 > ExpProperties.upgradeBoxProbability) return;
|
---|
[231] | 217 |
|
---|
[233] | 218 | var weapon = Populations[1].add("//0\nm:Vstyle=weaponbox\np:");
|
---|
[231] | 219 | weapon.name = "Weapon Box";
|
---|
[480] | 220 | weapon.idleen = ExpProperties.upgradeBoxIdleEnergy;
|
---|
| 221 | weapon.energ0 = ExpProperties.upgradeBoxStartingEnergy;
|
---|
[231] | 222 | weapon.energy = weapon.energ0;
|
---|
| 223 | weapon.nnenabled = 0;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | //handle creature placement in the world
|
---|
[233] | 227 | function onBorn(cr)
|
---|
[231] | 228 | {
|
---|
| 229 | // place newly born creature
|
---|
| 230 | var retry = 20; //try 20 times
|
---|
| 231 | var placed_ok = 0;
|
---|
| 232 | while (retry-- && !placed_ok)
|
---|
| 233 | {
|
---|
[233] | 234 | switch (cr.population.index)
|
---|
[231] | 235 | {
|
---|
| 236 | case 0: //food placement
|
---|
[233] | 237 | place_centerhead(cr);
|
---|
[231] | 238 | break;
|
---|
| 239 | case 1: //upgrade placement
|
---|
[233] | 240 | place_centerhead(cr);
|
---|
[231] | 241 | break;
|
---|
| 242 | default:
|
---|
[233] | 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
|
---|
[480] | 246 | cr.energ0 = ExpProperties.creatureStartingEnergy;
|
---|
[233] | 247 | cr.energy = cr.energ0;
|
---|
| 248 | place_inTeamSpot(cr);
|
---|
[231] | 249 | break;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[233] | 252 | if (!cr.boundingBoxCollisions(0))
|
---|
| 253 | {placed_ok=1; break;}
|
---|
[231] | 254 | }
|
---|
| 255 | if (!placed_ok)
|
---|
| 256 | print("onBorn() could not avoid collisions.");
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | //place creature in random spot and make it head center of the map
|
---|
[233] | 260 | function place_centerhead(cr)
|
---|
[231] | 261 | {
|
---|
| 262 | var x, y, z;
|
---|
[233] | 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;
|
---|
[231] | 265 | z = WorldMap.getHeight(x, y);
|
---|
| 266 |
|
---|
| 267 | var hx = 0.0 + (World.wrldsiz / 2) - x;
|
---|
| 268 | var hy = 0.0 + (World.wrldsiz / 2) - y;
|
---|
| 269 | var alpha_rad = vectorsAngle([1.0, 0.0], [hx, hy]);
|
---|
| 270 |
|
---|
[233] | 271 | cr.rotate(0, 0, alpha_rad);
|
---|
| 272 | cr.moveAbs(x, y, z - 0.999);
|
---|
[231] | 273 |
|
---|
| 274 | print("Creature placed in [" + x +" " + y + " " + z);
|
---|
| 275 |
|
---|
| 276 | return ;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | //Place creature in correct team spot (valid for Team creatures only)
|
---|
| 280 | //Creatures are placed in circle with random rotation (commented out: heading center of the map) in their respective team groups
|
---|
[233] | 281 | function place_inTeamSpot(cr)
|
---|
[231] | 282 | {
|
---|
[233] | 283 | var radius = 360.00 * (cr.population.index - 1) / teams;
|
---|
[231] | 284 |
|
---|
| 285 | var x, y, z;
|
---|
[480] | 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;
|
---|
[231] | 288 |
|
---|
| 289 | //vector of length half the world size minus spawning area size
|
---|
[480] | 290 | var vect = [0.0 + World.wrldsiz/2 - ExpProperties.teamSpawningAreaSize/2 - 1.0, 0.0];
|
---|
[231] | 291 | vect = rotateVector(vect, radius);
|
---|
| 292 |
|
---|
| 293 | //translate creature by given vector
|
---|
| 294 | //then translate by halfworld (as it is the center of the world
|
---|
| 295 | //and the positions were calculated for point [0,0]
|
---|
| 296 | x = x + vect[0] + World.wrldsiz/2;
|
---|
| 297 | y = y + vect[1] + World.wrldsiz/2;
|
---|
| 298 |
|
---|
| 299 | z = WorldMap.getHeight(x, y);
|
---|
| 300 |
|
---|
| 301 | var alpha_rad = 360.0 * Math.rnd01; //random rotation
|
---|
| 302 |
|
---|
| 303 | //this would rotate creatures so that they would face the world center:
|
---|
| 304 | //var hx = 0.0 + (World.wrldsiz / 2) - x;
|
---|
| 305 | //var hy = 0.0 + (World.wrldsiz / 2) - y;
|
---|
| 306 | //var alpha_rad = vectorsAngle([1.0, 0.0], [hx, hy]);
|
---|
| 307 |
|
---|
[233] | 308 | cr.rotate(0, 0, alpha_rad);
|
---|
[231] | 309 | //place it mid-air
|
---|
[233] | 310 | cr.moveAbs(x, y, z);
|
---|
[231] | 311 |
|
---|
| 312 | return ;
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | // ////////////////////////////////
|
---|
| 316 | // Simulation steps
|
---|
| 317 |
|
---|
| 318 | function onStep()
|
---|
| 319 | {
|
---|
| 320 | idleSimulationSteps += 1;
|
---|
| 321 | tryCreateHPBox();
|
---|
| 322 | tryCreateUpgradeBox();
|
---|
| 323 |
|
---|
| 324 | lowerCooldownCounters();
|
---|
| 325 | applySuddenDeathModifier();
|
---|
| 326 |
|
---|
| 327 | clearDeadCreatures();
|
---|
| 328 | checkGameState();
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | function writeTeamStatistics()
|
---|
| 332 | {
|
---|
| 333 | var s = "" + Simulator.time + "; ";
|
---|
| 334 | var total = 0.0;
|
---|
[233] | 335 | for (var i = 2; i < Populations.size; i++)
|
---|
[231] | 336 | {
|
---|
[233] | 337 | var pop=Populations[i];
|
---|
| 338 | var sum = 0.0;
|
---|
| 339 | for (var cr in pop)
|
---|
| 340 | sum += cr.energy;
|
---|
[231] | 341 | s += "" + sum + "; ";
|
---|
[233] | 342 | s += "" + pop.size + "; ";
|
---|
| 343 | total += sum;
|
---|
[231] | 344 | }
|
---|
| 345 | if (total < 0) total == 0;
|
---|
| 346 | s += "" + total + "\n";
|
---|
| 347 |
|
---|
| 348 | var f=File.appendDirect("teams"+battleNumber+".txt","Teams statistics");
|
---|
| 349 | f.writeString(s);
|
---|
| 350 | f.close();
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | function clearDeadCreatures()
|
---|
| 354 | {
|
---|
[233] | 355 | for (var i = 2; i < Populations.size; i++)
|
---|
[231] | 356 | {
|
---|
[233] | 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 | }
|
---|
[231] | 363 | }
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | function applySuddenDeathModifier()
|
---|
| 367 | {
|
---|
[480] | 368 | if (idleSimulationSteps < ExpProperties.stagnationInterval) return;
|
---|
[231] | 369 |
|
---|
[233] | 370 | for (var i = 2; i < Populations.size; i++)
|
---|
| 371 | for (var cr in Populations[i])
|
---|
[480] | 372 | cr.energy -= ExpProperties.stagnationHealthReduce;
|
---|
[231] | 373 | }
|
---|
[233] | 374 |
|
---|
[231] | 375 | function lowerCooldownCounters()
|
---|
| 376 | {
|
---|
[233] | 377 | for (var i = 2; i < Populations.size; i++)
|
---|
[231] | 378 | {
|
---|
[233] | 379 | var pop=Populations[i];
|
---|
| 380 | for (var cr in pop)
|
---|
[231] | 381 | {
|
---|
[233] | 382 | if (cr.user1 != null)
|
---|
[231] | 383 | {
|
---|
[233] | 384 | if (cr.user1[0] > 0) cr.user1[0]=cr.user1[0] - 1;
|
---|
| 385 | if (cr.user1[0] < 0) cr.user1[0]=0.0;
|
---|
[480] | 386 | if (cr.user1[1] > 0) cr.user1[1]=cr.user1[1] - ExpProperties.upgradeBoxDecay;
|
---|
[233] | 387 | if (cr.user1[1] < 0) cr.user1[1]=0.0;
|
---|
[231] | 388 | }
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | function checkGameState()
|
---|
| 394 | {
|
---|
| 395 | var alivePop = 0;
|
---|
[233] | 396 | for (var i = 2; i < Populations.size; i++)
|
---|
| 397 | if (Populations[i].size > 0) alivePop += 1;
|
---|
[231] | 398 |
|
---|
| 399 | if (alivePop == 0 && Simulator.time <= 1)
|
---|
| 400 | {
|
---|
| 401 | onExpInit(); //do initialization for user, because he forgot to do so
|
---|
| 402 | return;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | if (alivePop <= 1)
|
---|
| 406 | {
|
---|
[233] | 407 | for (var i = 2; i < Populations.size; i++)
|
---|
[231] | 408 | {
|
---|
[233] | 409 | var pop=Populations[i];
|
---|
| 410 | if (pop.size > 0)
|
---|
[231] | 411 | {
|
---|
[233] | 412 | Simulator.print("Battle is OVER! The winner is: " + pop.name);
|
---|
[231] | 413 |
|
---|
| 414 | //write stats of last living creatures
|
---|
| 415 | var f=File.appendDirect("creatures"+battleNumber+".txt","Creature statistics");
|
---|
[233] | 416 | for (var cr in pop)
|
---|
[231] | 417 | {
|
---|
| 418 | //f.writeString("Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan");
|
---|
[233] | 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");
|
---|
[231] | 421 | }
|
---|
| 422 |
|
---|
| 423 | f.close();
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | if (alivePop == 0) Simulator.print("Battle is OVER! Total annihilation!");
|
---|
| 427 |
|
---|
| 428 | Simulator.stop();
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | function print(msg)
|
---|
| 433 | {
|
---|
[480] | 434 | if (ExpProperties.debug)
|
---|
[231] | 435 | Simulator.print(msg);
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | function stop(msg)
|
---|
| 439 | {
|
---|
| 440 | Simulator.print(msg);
|
---|
| 441 | Simulator.stop();
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | // ////////////////////////////
|
---|
| 445 | // Collisions
|
---|
| 446 |
|
---|
| 447 | //function executed on any Creature collission
|
---|
| 448 | function onTeam0CrCollision, onTeam1CrCollision, onTeam2CrCollision, onTeam3CrCollision, onTeam4CrCollision, onTeam5CrCollision, onTeam6CrCollision, onTeam7CrCollision, onTeam8CrCollision, onTeam9CrCollision()
|
---|
| 449 | {
|
---|
| 450 | var c1 = CrCollision.Creature1;
|
---|
| 451 | var c2 = CrCollision.Creature2;
|
---|
| 452 |
|
---|
| 453 | if (c1 == null) stop("2");
|
---|
| 454 | if (c2 == null) stop("2");
|
---|
| 455 |
|
---|
| 456 | if (c1.energy <= 0 || c2.energy <= 0)
|
---|
| 457 | {
|
---|
| 458 | //collision with already killed creature (chain resolution)
|
---|
| 459 | print("onCrCollision called with less than 2 Creatures");
|
---|
| 460 | return ;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
[233] | 463 | if (c1.population == null || c2.population == null)
|
---|
[231] | 464 | {
|
---|
| 465 | //collision of creature without a group
|
---|
| 466 | print("onCrCollision called for creature without group, ignoring");
|
---|
| 467 | return ;
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | //first condition should never occur, but who knows?
|
---|
[233] | 471 | if (c1.population.index < 2 || c2.population.index < 2)
|
---|
[231] | 472 | {
|
---|
| 473 | //collision with HP Box and Upgrades are handled separately
|
---|
| 474 | print("onCrCollision called for population 0 or 1, ignoring");
|
---|
| 475 | return ;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | idleSimulationSteps = 0;
|
---|
| 479 |
|
---|
| 480 | var kill_c1 = 0;
|
---|
| 481 | var kill_c2 = 0;
|
---|
| 482 | var dice1 = 0;
|
---|
| 483 | var dice2 = 0;
|
---|
| 484 | var changed = 0;
|
---|
[480] | 485 | for (var i = 0; i < ExpProperties.diceCount; i++)
|
---|
[231] | 486 | {
|
---|
[480] | 487 | dice1 = dice1 + Math.random(ExpProperties.diceSides) + 1;
|
---|
| 488 | dice2 = dice2 + Math.random(ExpProperties.diceSides) + 1;
|
---|
[231] | 489 | }
|
---|
[480] | 490 | var energy1 = 0.0 + ExpProperties.creatureDamage * dice1;
|
---|
| 491 | var energy2 = 0.0 + ExpProperties.creatureDamage * dice2;
|
---|
| 492 | energy1 += ExpProperties.upgradeMultiplier * c1.user1.get(1);
|
---|
| 493 | energy2 += ExpProperties.upgradeMultiplier * c2.user1.get(1);
|
---|
[233] | 494 | if (c1.population == c2.population)
|
---|
[231] | 495 | {
|
---|
[480] | 496 | energy1 = ExpProperties.friendlyFireDamageMultiplier * energy1;
|
---|
| 497 | energy2 = ExpProperties.friendlyFireDamageMultiplier * energy2;
|
---|
[231] | 498 | }
|
---|
| 499 |
|
---|
| 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 |
|
---|
[233] | 507 | if (c2.user1[0] <= 0 && energy2 > 0)
|
---|
[231] | 508 | {
|
---|
| 509 | changed = 1;
|
---|
| 510 |
|
---|
| 511 | c1.energy = c1.energy - energy2;
|
---|
| 512 | if (c1.energy < 0) c1.energy = 0;
|
---|
[480] | 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);
|
---|
[233] | 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];
|
---|
[231] | 518 | var arrindex = arrayContains(c1.user3, 0, c2.uid);
|
---|
| 519 | if (arrindex != -1)
|
---|
| 520 | {
|
---|
[233] | 521 | vect.add(energy2 + c1.user3[arrindex][2]);
|
---|
| 522 | c1.user3[arrindex]=vect;
|
---|
[231] | 523 | }
|
---|
| 524 | else
|
---|
| 525 | {
|
---|
| 526 | vect.add(energy2);
|
---|
| 527 | if (c1.user3 == null) c1.user3 = Vector.new();
|
---|
| 528 | c1.user3.add(vect);
|
---|
| 529 | if (c1.energy > 0)
|
---|
[233] | 530 | c2.user2[1] = c2.user2[1] + 1; //increase assists statistic
|
---|
[231] | 531 | }
|
---|
| 532 | if (c1.energy <= 0)
|
---|
| 533 | {
|
---|
[233] | 534 | c2.user2[0] = c2.user2[0] + 1; //increase kills statistic
|
---|
[231] | 535 | kill_c1 = 1;
|
---|
| 536 | }
|
---|
| 537 | }
|
---|
| 538 |
|
---|
[233] | 539 | if (c1.user1[0] <= 0 && energy1 > 0)
|
---|
[231] | 540 | {
|
---|
| 541 | changed = 1;
|
---|
| 542 |
|
---|
| 543 | c2.energy = c2.energy - energy1;
|
---|
| 544 | if (c2.energy < 0) c2.energy = 0;
|
---|
[480] | 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;
|
---|
[233] | 547 | c1.user2[2] = c1.user2[2] + energy1;
|
---|
| 548 | c2.user2[3] = c2.user2[3] + energy1;
|
---|
[231] | 549 | var vect = Vector.new();
|
---|
| 550 | vect.add(c1.uid);
|
---|
| 551 | vect.add(c1.name);
|
---|
| 552 | var arrindex = arrayContains(c2.user3, 0, c1.uid);
|
---|
| 553 | if (arrindex != -1)
|
---|
| 554 | {
|
---|
[233] | 555 | vect.add(energy1 + c2.user3[arrindex][2]);
|
---|
| 556 | c2.user3[arrindex] = vect;
|
---|
[231] | 557 | }
|
---|
| 558 | else
|
---|
| 559 | {
|
---|
| 560 | vect.add(energy1);
|
---|
| 561 | if (c2.user3 == null) c2.user3 = Vector.new();
|
---|
| 562 | c2.user3.add(vect);
|
---|
| 563 | if (c2.energy > 0)
|
---|
| 564 | {
|
---|
[233] | 565 | c1.user2[1] = c1.user2[1] + 1; //increase assists statistic
|
---|
[231] | 566 | }
|
---|
| 567 | }
|
---|
| 568 | if (c2.energy <= 0)
|
---|
| 569 | {
|
---|
[233] | 570 | c1.user2[0] = c1.user2[0] + 1; //increase kills statistic
|
---|
[231] | 571 | kill_c2 = 1;
|
---|
| 572 | }
|
---|
| 573 | }
|
---|
| 574 |
|
---|
| 575 | if (changed == 1)
|
---|
| 576 | {
|
---|
| 577 | writeTeamStatistics();
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | //resolve kills
|
---|
| 581 | if (kill_c1 == 1)
|
---|
[233] | 582 | c1.population.kill(c1);
|
---|
[231] | 583 | if (kill_c2 == 1)
|
---|
[233] | 584 | c2.population.kill(c2);
|
---|
[231] | 585 | }
|
---|
| 586 |
|
---|
| 587 | //function executed on collision with Food population group
|
---|
| 588 | function onFoodCollision()
|
---|
| 589 | {
|
---|
[480] | 590 | if (ExpProperties.pickupNotStagnation == 1) idleSimulationSteps = 0;
|
---|
[231] | 591 |
|
---|
| 592 | //collect HP Box (by eating it :D)
|
---|
[233] | 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;
|
---|
[231] | 597 |
|
---|
| 598 | //kill HP Box
|
---|
[233] | 599 | Collision.Creature1.population.kill(Collision.Creature1);
|
---|
[231] | 600 |
|
---|
| 601 | writeTeamStatistics();
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | //function executed on collision with Upgrade population group
|
---|
| 605 | function onUpgradesCollision()
|
---|
| 606 | {
|
---|
[480] | 607 | if (ExpProperties.pickupNotStagnation == 1) idleSimulationSteps = 0;
|
---|
[231] | 608 |
|
---|
| 609 | //collect Upgrade Box (by eating it :D)
|
---|
[233] | 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;
|
---|
[231] | 614 |
|
---|
| 615 | //kill Upgrade Box
|
---|
[233] | 616 | Collision.Creature1.population.kill(Collision.Creature1);
|
---|
[231] | 617 |
|
---|
| 618 | writeTeamStatistics();
|
---|
| 619 | }
|
---|
| 620 |
|
---|
| 621 | //function executed on Creature death
|
---|
| 622 | //TODO: implement some statistics for dieing creature
|
---|
[233] | 623 | function onDied(cr)
|
---|
[231] | 624 | {
|
---|
| 625 | //ignore death of hp boxes and upgrades
|
---|
[233] | 626 | if (cr.population.index < 2)
|
---|
[231] | 627 | return ;
|
---|
| 628 |
|
---|
[233] | 629 | print(cr.name + " was killed");
|
---|
| 630 | for (var dam in cr.user3)
|
---|
| 631 | print(dam[1] + " dealt " + dam[2] + " damage");
|
---|
[231] | 632 |
|
---|
| 633 | var f=File.appendDirect("creatures"+battleNumber+".txt","Creature statistics");
|
---|
| 634 | //f.writeString("Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan");
|
---|
[233] | 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");
|
---|
[231] | 636 | f.close();
|
---|
| 637 |
|
---|
| 638 | writeTeamStatistics();
|
---|
| 639 | }
|
---|
| 640 |
|
---|
| 641 | // ////////////////////////////
|
---|
[537] | 642 | // ExpProperties setters
|
---|
[231] | 643 |
|
---|
| 644 | //reinit populations on change
|
---|
[480] | 645 | function ExpProperties_teamCount_set()
|
---|
[231] | 646 | {
|
---|
| 647 | initPopulations();
|
---|
| 648 | }
|
---|
| 649 |
|
---|
[480] | 650 | function ExpProperties_level_set()
|
---|
[231] | 651 | {
|
---|
| 652 | initLevel();
|
---|
| 653 | }
|
---|
| 654 | ~
|
---|
| 655 |
|
---|
| 656 | # ################################
|
---|
| 657 | # Team
|
---|
| 658 |
|
---|
[480] | 659 | property:
|
---|
[231] | 660 | id:teamCount
|
---|
| 661 | name:Number of teams in Deathmatch
|
---|
| 662 | type:d 1 10 1
|
---|
| 663 | group:Team
|
---|
| 664 | help:If set to 1, the number of teams will be equal to the number of genotypes in gene pool.
|
---|
| 665 |
|
---|
[480] | 666 | property:
|
---|
[231] | 667 | id:teamSize
|
---|
| 668 | name:Number of creatures per team
|
---|
| 669 | type:d 1 10 5
|
---|
| 670 | group:Team
|
---|
| 671 |
|
---|
[480] | 672 | property:
|
---|
[231] | 673 | id:teamSpawningAreaSize
|
---|
| 674 | name:Spawning area size for team
|
---|
| 675 | type:f 10 30 20
|
---|
| 676 | group:Team
|
---|
| 677 |
|
---|
[480] | 678 | property:
|
---|
[231] | 679 | id:creatureStartingEnergy
|
---|
| 680 | name:Starting energy of creature
|
---|
| 681 | type:f 0 1000 300
|
---|
| 682 | group:Team
|
---|
| 683 | help:Base starting energy level for each creature in teams
|
---|
| 684 |
|
---|
| 685 | # ################################
|
---|
| 686 | # Attack parameters
|
---|
| 687 |
|
---|
[480] | 688 | property:
|
---|
[231] | 689 | id:diceSides
|
---|
| 690 | name:Number of sides of dices
|
---|
| 691 | type:f 1 10 1
|
---|
| 692 | group:Attack rules
|
---|
| 693 |
|
---|
[480] | 694 | property:
|
---|
[231] | 695 | id:diceCount
|
---|
| 696 | name:Number of dices to roll per attack
|
---|
| 697 | type:f 0 10 5
|
---|
| 698 | group:Attack rules
|
---|
| 699 |
|
---|
[480] | 700 | property:
|
---|
[231] | 701 | id:creatureDamage
|
---|
| 702 | name:Basic damage multiplied by result of dice roll
|
---|
| 703 | type:f 0 100 10
|
---|
| 704 | group:Attack rules
|
---|
| 705 |
|
---|
[480] | 706 | property:
|
---|
[231] | 707 | id:friendlyFireDamageMultiplier
|
---|
| 708 | name:Multiplier of energy taken when Creatures of the same team collide
|
---|
| 709 | type:f 0 1 0.0
|
---|
| 710 | group:Attack rules
|
---|
| 711 | help:Set to 0 for no friendly fire, set to 1 if full damage should be dealt when interacting with team member
|
---|
| 712 |
|
---|
[480] | 713 | property:
|
---|
[231] | 714 | id:attackCooldown
|
---|
| 715 | name:Number of simulation steps between two consecutive attacks of a creature
|
---|
| 716 | type:f 100 10000 1000
|
---|
| 717 | group:Attack rules
|
---|
| 718 | help:Set this to 100 to nearly instantly resolve battles
|
---|
| 719 |
|
---|
| 720 | # ################################
|
---|
| 721 | # Collectibles - HP Boxes & Upgrades
|
---|
| 722 |
|
---|
[480] | 723 | property:
|
---|
[231] | 724 | id:pickupNotStagnation
|
---|
| 725 | name:Collectible pick-up resets stagnation counter?
|
---|
| 726 | type:d 0 1 1
|
---|
| 727 | help:If set to true picking up an item will restart counting towards stagnation, effects in longer battles.
|
---|
| 728 |
|
---|
[480] | 729 | property:
|
---|
[231] | 730 | id:hpBoxStartingEnergy
|
---|
| 731 | name:Starting energy of HP Box
|
---|
| 732 | type:f 0 1000 100
|
---|
| 733 | group:Collectibles
|
---|
| 734 | help:Base starting energy level for HP Box
|
---|
| 735 |
|
---|
[480] | 736 | property:
|
---|
[231] | 737 | id:hpBoxIdleEnergy
|
---|
| 738 | name:Amount of energy lost by HP Box
|
---|
| 739 | type:f 0 10 0.00
|
---|
| 740 | group:Collectibles
|
---|
| 741 | help:How much energy HP Box looses each step (0 - it will not disappear)
|
---|
| 742 |
|
---|
[480] | 743 | property:
|
---|
[231] | 744 | id:hpBoxProbability
|
---|
| 745 | name:Probablity that new HP Box will spawn
|
---|
| 746 | type:f 0 1 0.0005
|
---|
| 747 | group:Collectibles
|
---|
| 748 | help:Probability of HP Box appearing each step of simulation
|
---|
| 749 |
|
---|
[480] | 750 | property:
|
---|
[231] | 751 | id:hpBoxTotalCount
|
---|
| 752 | name:Maximum number of HP Boxes on the field
|
---|
| 753 | type:d 0 20 10
|
---|
| 754 | group:Collectibles
|
---|
| 755 | help:The total number of HP Boxes on the field will never exceed this number
|
---|
| 756 |
|
---|
[480] | 757 | property:
|
---|
[231] | 758 | id:upgradeBoxStartingEnergy
|
---|
| 759 | name:Starting energy of Upgrade Box
|
---|
| 760 | type:f 0 1000 500
|
---|
| 761 | group:Collectibles
|
---|
| 762 | help:Base starting energy level for Upgrade Box
|
---|
| 763 |
|
---|
[480] | 764 | property:
|
---|
[231] | 765 | id:upgradeBoxIdleEnergy
|
---|
| 766 | name:Amount of energy lost by Upgrade Box
|
---|
| 767 | type:f 0 10 0.00
|
---|
| 768 | group:Collectibles
|
---|
| 769 | help:How much energy Upgrade Box looses each step (0 - it will not disappear)
|
---|
| 770 |
|
---|
[480] | 771 | property:
|
---|
[231] | 772 | id:upgradeBoxProbability
|
---|
| 773 | name:Probablity that new Upgrade Box will spawn
|
---|
| 774 | type:f 0 1 0.0005
|
---|
| 775 | group:Collectibles
|
---|
| 776 | help:Probability of Upgrade Box appearing each step of simulation
|
---|
| 777 |
|
---|
[480] | 778 | property:
|
---|
[231] | 779 | id:upgradeBoxTotalCount
|
---|
| 780 | name:Maximum number of Upgrade Boxes on the field
|
---|
| 781 | type:d 0 20 10
|
---|
| 782 | group:Collectibles
|
---|
| 783 | help:The total number of Upgrade Boxes on the field will never exceed this number
|
---|
| 784 |
|
---|
[480] | 785 | property:
|
---|
[231] | 786 | id:upgradeBoxDecay
|
---|
| 787 | name:How fast upgrade boost fades from creature
|
---|
| 788 | type:f 0 10 0.1
|
---|
| 789 | group:Collectibles
|
---|
| 790 | help:Each step creature damage bonus will be decreased by given amount until it reaches 0
|
---|
| 791 |
|
---|
[480] | 792 | property:
|
---|
[231] | 793 | id:upgradeMultiplier
|
---|
| 794 | name:Multiplier of bonus damage
|
---|
| 795 | type:f 0 1 0.1
|
---|
| 796 | group:Collectibles
|
---|
| 797 | help:Value of collected bonus multiplied by this variable is taken as bonus damage
|
---|
| 798 |
|
---|
| 799 | # ################################
|
---|
| 800 | # Other
|
---|
| 801 |
|
---|
[480] | 802 | property:
|
---|
[231] | 803 | id:level
|
---|
| 804 | name:Level
|
---|
| 805 | type:d -1 2 0
|
---|
| 806 | help:Number of a level to battle (-1 is random)
|
---|
| 807 |
|
---|
[480] | 808 | property:
|
---|
[231] | 809 | id:stagnationInterval
|
---|
| 810 | name:Number of idle simulation steps before Sudden Death
|
---|
| 811 | type:d 0 10000 5000
|
---|
| 812 | help:If no combat occurs during given number of steps, the Sudden Death mode is turned on (0 = Sudden Death all the time)
|
---|
| 813 |
|
---|
[480] | 814 | property:
|
---|
[231] | 815 | id:stagnationHealthReduce
|
---|
| 816 | name:Sudden Death health reduce
|
---|
| 817 | type:f 0 100 0.1
|
---|
| 818 | help:If Suddent Death is turned on, creatures will lose given amount of HP each simulation step
|
---|
| 819 |
|
---|
[480] | 820 | property:
|
---|
[231] | 821 | id:debug
|
---|
| 822 | name:Show additional debug messages
|
---|
| 823 | type:d 0 1 0
|
---|
| 824 |
|
---|