[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 |
|
---|
[634] | 28 | WireframeAppearance.set("1p_weaponbox","""//0
|
---|
[233] | 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 |
|
---|
[634] | 50 | WireframeAppearance.set("1p_hpbox","""//0
|
---|
[233] | 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 |
|
---|
[631] | 186 | var level = levels[levelNumber];
|
---|
[231] | 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;
|
---|
[631] | 207 | food.energy0 = ExpProperties.hpBoxStartingEnergy;
|
---|
| 208 | food.energy = food.energy0;
|
---|
[231] | 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;
|
---|
[631] | 221 | weapon.energy0 = ExpProperties.upgradeBoxStartingEnergy;
|
---|
| 222 | weapon.energy = weapon.energy0;
|
---|
[231] | 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:
|
---|
[631] | 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;
|
---|
[233] | 254 | place_inTeamSpot(cr);
|
---|
[231] | 255 | break;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
[233] | 258 | if (!cr.boundingBoxCollisions(0))
|
---|
| 259 | {placed_ok=1; break;}
|
---|
[231] | 260 | }
|
---|
| 261 | if (!placed_ok)
|
---|
| 262 | print("onBorn() could not avoid collisions.");
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | //place creature in random spot and make it head center of the map
|
---|
[233] | 266 | function place_centerhead(cr)
|
---|
[231] | 267 | {
|
---|
| 268 | var x, y, z;
|
---|
[631] | 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;
|
---|
[231] | 272 | z = WorldMap.getHeight(x, y);
|
---|
| 273 |
|
---|
| 274 | var hx = 0.0 + (World.wrldsiz / 2) - x;
|
---|
| 275 | var hy = 0.0 + (World.wrldsiz / 2) - y;
|
---|
| 276 | var alpha_rad = vectorsAngle([1.0, 0.0], [hx, hy]);
|
---|
| 277 |
|
---|
[233] | 278 | cr.rotate(0, 0, alpha_rad);
|
---|
[631] | 279 | cr.locationSetBboxLow(x, y, z - 0.999);
|
---|
[231] | 280 |
|
---|
| 281 | print("Creature placed in [" + x +" " + y + " " + z);
|
---|
| 282 |
|
---|
| 283 | return ;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | //Place creature in correct team spot (valid for Team creatures only)
|
---|
| 287 | //Creatures are placed in circle with random rotation (commented out: heading center of the map) in their respective team groups
|
---|
[233] | 288 | function place_inTeamSpot(cr)
|
---|
[231] | 289 | {
|
---|
[233] | 290 | var radius = 360.00 * (cr.population.index - 1) / teams;
|
---|
[231] | 291 |
|
---|
| 292 | var x, y, z;
|
---|
[631] | 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;
|
---|
[231] | 295 |
|
---|
| 296 | //vector of length half the world size minus spawning area size
|
---|
[480] | 297 | var vect = [0.0 + World.wrldsiz/2 - ExpProperties.teamSpawningAreaSize/2 - 1.0, 0.0];
|
---|
[231] | 298 | vect = rotateVector(vect, radius);
|
---|
| 299 |
|
---|
| 300 | //translate creature by given vector
|
---|
| 301 | //then translate by halfworld (as it is the center of the world
|
---|
| 302 | //and the positions were calculated for point [0,0]
|
---|
| 303 | x = x + vect[0] + World.wrldsiz/2;
|
---|
| 304 | y = y + vect[1] + World.wrldsiz/2;
|
---|
| 305 |
|
---|
| 306 | z = WorldMap.getHeight(x, y);
|
---|
| 307 |
|
---|
| 308 | var alpha_rad = 360.0 * Math.rnd01; //random rotation
|
---|
| 309 |
|
---|
| 310 | //this would rotate creatures so that they would face the world center:
|
---|
| 311 | //var hx = 0.0 + (World.wrldsiz / 2) - x;
|
---|
| 312 | //var hy = 0.0 + (World.wrldsiz / 2) - y;
|
---|
| 313 | //var alpha_rad = vectorsAngle([1.0, 0.0], [hx, hy]);
|
---|
| 314 |
|
---|
[233] | 315 | cr.rotate(0, 0, alpha_rad);
|
---|
[231] | 316 | //place it mid-air
|
---|
[631] | 317 | cr.locationSetBboxLow(x, y, z);
|
---|
[231] | 318 |
|
---|
| 319 | return ;
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | // ////////////////////////////////
|
---|
| 323 | // Simulation steps
|
---|
| 324 |
|
---|
| 325 | function onStep()
|
---|
| 326 | {
|
---|
| 327 | idleSimulationSteps += 1;
|
---|
| 328 | tryCreateHPBox();
|
---|
| 329 | tryCreateUpgradeBox();
|
---|
| 330 |
|
---|
| 331 | lowerCooldownCounters();
|
---|
| 332 | applySuddenDeathModifier();
|
---|
| 333 |
|
---|
| 334 | clearDeadCreatures();
|
---|
| 335 | checkGameState();
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | function writeTeamStatistics()
|
---|
| 339 | {
|
---|
[631] | 340 | var s = string(Simulator.stepNumber) + "; ";
|
---|
[231] | 341 | var total = 0.0;
|
---|
[233] | 342 | for (var i = 2; i < Populations.size; i++)
|
---|
[231] | 343 | {
|
---|
[233] | 344 | var pop=Populations[i];
|
---|
| 345 | var sum = 0.0;
|
---|
| 346 | for (var cr in pop)
|
---|
| 347 | sum += cr.energy;
|
---|
[231] | 348 | s += "" + sum + "; ";
|
---|
[233] | 349 | s += "" + pop.size + "; ";
|
---|
| 350 | total += sum;
|
---|
[231] | 351 | }
|
---|
| 352 | if (total < 0) total == 0;
|
---|
| 353 | s += "" + total + "\n";
|
---|
| 354 |
|
---|
| 355 | var f=File.appendDirect("teams"+battleNumber+".txt","Teams statistics");
|
---|
| 356 | f.writeString(s);
|
---|
| 357 | f.close();
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | function clearDeadCreatures()
|
---|
| 361 | {
|
---|
[233] | 362 | for (var i = 2; i < Populations.size; i++)
|
---|
[231] | 363 | {
|
---|
[233] | 364 | var pop=Populations[i];
|
---|
| 365 | for (var j = 0; j < pop.size; j++)
|
---|
| 366 | {
|
---|
| 367 | var cr=pop[j];
|
---|
| 368 | if (cr.energy <= 0) {pop.kill(cr); j--;}
|
---|
| 369 | }
|
---|
[231] | 370 | }
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | function applySuddenDeathModifier()
|
---|
| 374 | {
|
---|
[480] | 375 | if (idleSimulationSteps < ExpProperties.stagnationInterval) return;
|
---|
[231] | 376 |
|
---|
[233] | 377 | for (var i = 2; i < Populations.size; i++)
|
---|
| 378 | for (var cr in Populations[i])
|
---|
[480] | 379 | cr.energy -= ExpProperties.stagnationHealthReduce;
|
---|
[231] | 380 | }
|
---|
[233] | 381 |
|
---|
[231] | 382 | function lowerCooldownCounters()
|
---|
| 383 | {
|
---|
[233] | 384 | for (var i = 2; i < Populations.size; i++)
|
---|
[231] | 385 | {
|
---|
[233] | 386 | var pop=Populations[i];
|
---|
| 387 | for (var cr in pop)
|
---|
[231] | 388 | {
|
---|
[631] | 389 | if (cr.data->cooldown != null)
|
---|
[231] | 390 | {
|
---|
[631] | 391 | if (cr.data->cooldown > 0) cr.data->cooldown-=1;
|
---|
| 392 | if (cr.data->cooldown < 0) cr.data->cooldown=0.0;
|
---|
[231] | 393 | }
|
---|
[631] | 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;
|
---|
| 398 | }
|
---|
[231] | 399 | }
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | function checkGameState()
|
---|
| 404 | {
|
---|
| 405 | var alivePop = 0;
|
---|
[233] | 406 | for (var i = 2; i < Populations.size; i++)
|
---|
| 407 | if (Populations[i].size > 0) alivePop += 1;
|
---|
[231] | 408 |
|
---|
[631] | 409 | if (alivePop == 0 && Simulator.stepNumber <= 1)
|
---|
[231] | 410 | {
|
---|
| 411 | onExpInit(); //do initialization for user, because he forgot to do so
|
---|
| 412 | return;
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | if (alivePop <= 1)
|
---|
| 416 | {
|
---|
[233] | 417 | for (var i = 2; i < Populations.size; i++)
|
---|
[231] | 418 | {
|
---|
[233] | 419 | var pop=Populations[i];
|
---|
| 420 | if (pop.size > 0)
|
---|
[231] | 421 | {
|
---|
[233] | 422 | Simulator.print("Battle is OVER! The winner is: " + pop.name);
|
---|
[231] | 423 |
|
---|
| 424 | //write stats of last living creatures
|
---|
| 425 | var f=File.appendDirect("creatures"+battleNumber+".txt","Creature statistics");
|
---|
[233] | 426 | for (var cr in pop)
|
---|
[231] | 427 | {
|
---|
| 428 | //f.writeString("Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan");
|
---|
[631] | 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");
|
---|
[231] | 431 | }
|
---|
| 432 |
|
---|
| 433 | f.close();
|
---|
| 434 | }
|
---|
| 435 | }
|
---|
| 436 | if (alivePop == 0) Simulator.print("Battle is OVER! Total annihilation!");
|
---|
| 437 |
|
---|
| 438 | Simulator.stop();
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | function print(msg)
|
---|
| 443 | {
|
---|
[480] | 444 | if (ExpProperties.debug)
|
---|
[231] | 445 | Simulator.print(msg);
|
---|
| 446 | }
|
---|
| 447 |
|
---|
| 448 | function stop(msg)
|
---|
| 449 | {
|
---|
| 450 | Simulator.print(msg);
|
---|
| 451 | Simulator.stop();
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | // ////////////////////////////
|
---|
| 455 | // Collisions
|
---|
| 456 |
|
---|
| 457 | //function executed on any Creature collission
|
---|
| 458 | function onTeam0CrCollision, onTeam1CrCollision, onTeam2CrCollision, onTeam3CrCollision, onTeam4CrCollision, onTeam5CrCollision, onTeam6CrCollision, onTeam7CrCollision, onTeam8CrCollision, onTeam9CrCollision()
|
---|
| 459 | {
|
---|
| 460 | var c1 = CrCollision.Creature1;
|
---|
| 461 | var c2 = CrCollision.Creature2;
|
---|
| 462 |
|
---|
| 463 | if (c1 == null) stop("2");
|
---|
| 464 | if (c2 == null) stop("2");
|
---|
| 465 |
|
---|
| 466 | if (c1.energy <= 0 || c2.energy <= 0)
|
---|
| 467 | {
|
---|
| 468 | //collision with already killed creature (chain resolution)
|
---|
| 469 | print("onCrCollision called with less than 2 Creatures");
|
---|
| 470 | return ;
|
---|
| 471 | }
|
---|
| 472 |
|
---|
[233] | 473 | if (c1.population == null || c2.population == null)
|
---|
[231] | 474 | {
|
---|
| 475 | //collision of creature without a group
|
---|
| 476 | print("onCrCollision called for creature without group, ignoring");
|
---|
| 477 | return ;
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | //first condition should never occur, but who knows?
|
---|
[233] | 481 | if (c1.population.index < 2 || c2.population.index < 2)
|
---|
[231] | 482 | {
|
---|
| 483 | //collision with HP Box and Upgrades are handled separately
|
---|
| 484 | print("onCrCollision called for population 0 or 1, ignoring");
|
---|
| 485 | return ;
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 | idleSimulationSteps = 0;
|
---|
| 489 |
|
---|
| 490 | var kill_c1 = 0;
|
---|
| 491 | var kill_c2 = 0;
|
---|
| 492 | var dice1 = 0;
|
---|
| 493 | var dice2 = 0;
|
---|
| 494 | var changed = 0;
|
---|
[480] | 495 | for (var i = 0; i < ExpProperties.diceCount; i++)
|
---|
[231] | 496 | {
|
---|
[480] | 497 | dice1 = dice1 + Math.random(ExpProperties.diceSides) + 1;
|
---|
| 498 | dice2 = dice2 + Math.random(ExpProperties.diceSides) + 1;
|
---|
[231] | 499 | }
|
---|
[480] | 500 | var energy1 = 0.0 + ExpProperties.creatureDamage * dice1;
|
---|
| 501 | var energy2 = 0.0 + ExpProperties.creatureDamage * dice2;
|
---|
[631] | 502 | energy1 += ExpProperties.upgradeMultiplier * c1.data->bonusdamage;
|
---|
| 503 | energy2 += ExpProperties.upgradeMultiplier * c2.data->bonusdamage;
|
---|
[233] | 504 | if (c1.population == c2.population)
|
---|
[231] | 505 | {
|
---|
[480] | 506 | energy1 = ExpProperties.friendlyFireDamageMultiplier * energy1;
|
---|
| 507 | energy2 = ExpProperties.friendlyFireDamageMultiplier * energy2;
|
---|
[231] | 508 | }
|
---|
| 509 |
|
---|
[631] | 510 | if (c1.data->cooldown == null) stop("3");
|
---|
| 511 | if (c2.data->cooldown == null) stop("3");
|
---|
[231] | 512 |
|
---|
[631] | 513 | if (c2.data->cooldown <= 0 && energy2 > 0)
|
---|
[231] | 514 | {
|
---|
| 515 | changed = 1;
|
---|
| 516 |
|
---|
| 517 | c1.energy = c1.energy - energy2;
|
---|
| 518 | if (c1.energy < 0) c1.energy = 0;
|
---|
[631] | 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;
|
---|
[233] | 523 | var vect = [c2.uid,c2.name];
|
---|
[631] | 524 | var arrindex = arrayContains(c1.data->damagefrom, 0, c2.uid);
|
---|
[231] | 525 | if (arrindex != -1)
|
---|
| 526 | {
|
---|
[631] | 527 | vect.add(energy2 + c1.data->damagefrom[arrindex][2]);
|
---|
| 528 | c1.data->damagefrom[arrindex]=vect;
|
---|
[231] | 529 | }
|
---|
| 530 | else
|
---|
| 531 | {
|
---|
| 532 | vect.add(energy2);
|
---|
[631] | 533 | if (c1.data->damagefrom == null) c1.data->damagefrom = [];
|
---|
| 534 | c1.data->damagefrom.add(vect);
|
---|
[231] | 535 | if (c1.energy > 0)
|
---|
[631] | 536 | c2.data->assists += 1; //increase assists statistic
|
---|
[231] | 537 | }
|
---|
| 538 | if (c1.energy <= 0)
|
---|
| 539 | {
|
---|
[631] | 540 | c2.data->kills += 1; //increase kills statistic
|
---|
[231] | 541 | kill_c1 = 1;
|
---|
| 542 | }
|
---|
| 543 | }
|
---|
| 544 |
|
---|
[631] | 545 | if (c1.data->cooldown <= 0 && energy1 > 0)
|
---|
[231] | 546 | {
|
---|
| 547 | changed = 1;
|
---|
| 548 |
|
---|
| 549 | c2.energy = c2.energy - energy1;
|
---|
| 550 | if (c2.energy < 0) c2.energy = 0;
|
---|
[631] | 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;
|
---|
[231] | 555 | var vect = Vector.new();
|
---|
| 556 | vect.add(c1.uid);
|
---|
| 557 | vect.add(c1.name);
|
---|
[631] | 558 | var arrindex = arrayContains(c2.data->damagefrom, 0, c1.uid);
|
---|
[231] | 559 | if (arrindex != -1)
|
---|
| 560 | {
|
---|
[631] | 561 | vect.add(energy1 + c2.data->damagefrom[arrindex][2]);
|
---|
| 562 | c2.data->damagefrom[arrindex] = vect;
|
---|
[231] | 563 | }
|
---|
| 564 | else
|
---|
| 565 | {
|
---|
| 566 | vect.add(energy1);
|
---|
[631] | 567 | if (c2.data->damagefrom == null) c2.data->damagefrom = [];
|
---|
| 568 | c2.data->damagefrom.add(vect);
|
---|
[231] | 569 | if (c2.energy > 0)
|
---|
| 570 | {
|
---|
[631] | 571 | c1.data->assists += 1; //increase assists statistic
|
---|
[231] | 572 | }
|
---|
| 573 | }
|
---|
| 574 | if (c2.energy <= 0)
|
---|
| 575 | {
|
---|
[631] | 576 | c1.data->kills += 1; //increase kills statistic
|
---|
[231] | 577 | kill_c2 = 1;
|
---|
| 578 | }
|
---|
| 579 | }
|
---|
| 580 |
|
---|
| 581 | if (changed == 1)
|
---|
| 582 | {
|
---|
| 583 | writeTeamStatistics();
|
---|
| 584 | }
|
---|
| 585 |
|
---|
| 586 | //resolve kills
|
---|
| 587 | if (kill_c1 == 1)
|
---|
[233] | 588 | c1.population.kill(c1);
|
---|
[231] | 589 | if (kill_c2 == 1)
|
---|
[233] | 590 | c2.population.kill(c2);
|
---|
[231] | 591 | }
|
---|
| 592 |
|
---|
| 593 | //function executed on collision with Food population group
|
---|
| 594 | function onFoodCollision()
|
---|
| 595 | {
|
---|
[480] | 596 | if (ExpProperties.pickupNotStagnation == 1) idleSimulationSteps = 0;
|
---|
[231] | 597 |
|
---|
| 598 | //collect HP Box (by eating it :D)
|
---|
[233] | 599 | print(Collision.Creature2.name + " [" + Collision.Creature2.population.name + "] picked a HP box");
|
---|
[631] | 600 | Collision.Creature2.data->hpcollected += 1;
|
---|
| 601 | Collision.Creature1.transferEnergyTo(Collision.Creature2,Collision.Creature1.energy);
|
---|
[231] | 602 |
|
---|
| 603 | //kill HP Box
|
---|
[233] | 604 | Collision.Creature1.population.kill(Collision.Creature1);
|
---|
[231] | 605 |
|
---|
| 606 | writeTeamStatistics();
|
---|
| 607 | }
|
---|
| 608 |
|
---|
| 609 | //function executed on collision with Upgrade population group
|
---|
| 610 | function onUpgradesCollision()
|
---|
| 611 | {
|
---|
[480] | 612 | if (ExpProperties.pickupNotStagnation == 1) idleSimulationSteps = 0;
|
---|
[231] | 613 |
|
---|
| 614 | //collect Upgrade Box (by eating it :D)
|
---|
[233] | 615 | print(Collision.Creature2.name + " [" + Collision.Creature2.population.name + "] picked an upgrade box");
|
---|
[631] | 616 | Collision.Creature2.data->upgradecollected += 1;
|
---|
| 617 | Collision.Creature2.data->bonusdamage += Collision.Creature1.energy;
|
---|
| 618 | Collision.Creature1.energy = 0;
|
---|
[231] | 619 |
|
---|
| 620 | //kill Upgrade Box
|
---|
[233] | 621 | Collision.Creature1.population.kill(Collision.Creature1);
|
---|
[231] | 622 |
|
---|
| 623 | writeTeamStatistics();
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | //function executed on Creature death
|
---|
| 627 | //TODO: implement some statistics for dieing creature
|
---|
[233] | 628 | function onDied(cr)
|
---|
[231] | 629 | {
|
---|
| 630 | //ignore death of hp boxes and upgrades
|
---|
[233] | 631 | if (cr.population.index < 2)
|
---|
[231] | 632 | return ;
|
---|
| 633 |
|
---|
[233] | 634 | print(cr.name + " was killed");
|
---|
[631] | 635 | for (var dam in cr.data->damagefrom)
|
---|
[233] | 636 | print(dam[1] + " dealt " + dam[2] + " damage");
|
---|
[231] | 637 |
|
---|
| 638 | var f=File.appendDirect("creatures"+battleNumber+".txt","Creature statistics");
|
---|
| 639 | //f.writeString("Creature name; Team; Kills; Assists; Total damage dealt; Total damage received; HP boxes collected; Upgrade boxes collected; Lifespan");
|
---|
[631] | 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");
|
---|
[231] | 641 | f.close();
|
---|
| 642 |
|
---|
| 643 | writeTeamStatistics();
|
---|
| 644 | }
|
---|
| 645 |
|
---|
| 646 | // ////////////////////////////
|
---|
[537] | 647 | // ExpProperties setters
|
---|
[231] | 648 |
|
---|
| 649 | //reinit populations on change
|
---|
[480] | 650 | function ExpProperties_teamCount_set()
|
---|
[231] | 651 | {
|
---|
| 652 | initPopulations();
|
---|
| 653 | }
|
---|
| 654 |
|
---|
[480] | 655 | function ExpProperties_level_set()
|
---|
[231] | 656 | {
|
---|
| 657 | initLevel();
|
---|
| 658 | }
|
---|
| 659 | ~
|
---|
| 660 |
|
---|
| 661 | # ################################
|
---|
| 662 | # Team
|
---|
| 663 |
|
---|
[480] | 664 | property:
|
---|
[231] | 665 | id:teamCount
|
---|
| 666 | name:Number of teams in Deathmatch
|
---|
| 667 | type:d 1 10 1
|
---|
| 668 | group:Team
|
---|
| 669 | help:If set to 1, the number of teams will be equal to the number of genotypes in gene pool.
|
---|
| 670 |
|
---|
[480] | 671 | property:
|
---|
[231] | 672 | id:teamSize
|
---|
| 673 | name:Number of creatures per team
|
---|
| 674 | type:d 1 10 5
|
---|
| 675 | group:Team
|
---|
| 676 |
|
---|
[480] | 677 | property:
|
---|
[231] | 678 | id:teamSpawningAreaSize
|
---|
| 679 | name:Spawning area size for team
|
---|
| 680 | type:f 10 30 20
|
---|
| 681 | group:Team
|
---|
| 682 |
|
---|
[480] | 683 | property:
|
---|
[231] | 684 | id:creatureStartingEnergy
|
---|
| 685 | name:Starting energy of creature
|
---|
| 686 | type:f 0 1000 300
|
---|
| 687 | group:Team
|
---|
| 688 | help:Base starting energy level for each creature in teams
|
---|
| 689 |
|
---|
| 690 | # ################################
|
---|
| 691 | # Attack parameters
|
---|
| 692 |
|
---|
[480] | 693 | property:
|
---|
[231] | 694 | id:diceSides
|
---|
| 695 | name:Number of sides of dices
|
---|
| 696 | type:f 1 10 1
|
---|
| 697 | group:Attack rules
|
---|
| 698 |
|
---|
[480] | 699 | property:
|
---|
[231] | 700 | id:diceCount
|
---|
| 701 | name:Number of dices to roll per attack
|
---|
| 702 | type:f 0 10 5
|
---|
| 703 | group:Attack rules
|
---|
| 704 |
|
---|
[480] | 705 | property:
|
---|
[231] | 706 | id:creatureDamage
|
---|
| 707 | name:Basic damage multiplied by result of dice roll
|
---|
| 708 | type:f 0 100 10
|
---|
| 709 | group:Attack rules
|
---|
| 710 |
|
---|
[480] | 711 | property:
|
---|
[231] | 712 | id:friendlyFireDamageMultiplier
|
---|
| 713 | name:Multiplier of energy taken when Creatures of the same team collide
|
---|
| 714 | type:f 0 1 0.0
|
---|
| 715 | group:Attack rules
|
---|
| 716 | help:Set to 0 for no friendly fire, set to 1 if full damage should be dealt when interacting with team member
|
---|
| 717 |
|
---|
[480] | 718 | property:
|
---|
[231] | 719 | id:attackCooldown
|
---|
| 720 | name:Number of simulation steps between two consecutive attacks of a creature
|
---|
| 721 | type:f 100 10000 1000
|
---|
| 722 | group:Attack rules
|
---|
| 723 | help:Set this to 100 to nearly instantly resolve battles
|
---|
| 724 |
|
---|
| 725 | # ################################
|
---|
| 726 | # Collectibles - HP Boxes & Upgrades
|
---|
| 727 |
|
---|
[480] | 728 | property:
|
---|
[231] | 729 | id:pickupNotStagnation
|
---|
| 730 | name:Collectible pick-up resets stagnation counter?
|
---|
| 731 | type:d 0 1 1
|
---|
| 732 | help:If set to true picking up an item will restart counting towards stagnation, effects in longer battles.
|
---|
| 733 |
|
---|
[480] | 734 | property:
|
---|
[231] | 735 | id:hpBoxStartingEnergy
|
---|
| 736 | name:Starting energy of HP Box
|
---|
| 737 | type:f 0 1000 100
|
---|
| 738 | group:Collectibles
|
---|
| 739 | help:Base starting energy level for HP Box
|
---|
| 740 |
|
---|
[480] | 741 | property:
|
---|
[231] | 742 | id:hpBoxIdleEnergy
|
---|
| 743 | name:Amount of energy lost by HP Box
|
---|
| 744 | type:f 0 10 0.00
|
---|
| 745 | group:Collectibles
|
---|
| 746 | help:How much energy HP Box looses each step (0 - it will not disappear)
|
---|
| 747 |
|
---|
[480] | 748 | property:
|
---|
[231] | 749 | id:hpBoxProbability
|
---|
| 750 | name:Probablity that new HP Box will spawn
|
---|
| 751 | type:f 0 1 0.0005
|
---|
| 752 | group:Collectibles
|
---|
| 753 | help:Probability of HP Box appearing each step of simulation
|
---|
| 754 |
|
---|
[480] | 755 | property:
|
---|
[231] | 756 | id:hpBoxTotalCount
|
---|
| 757 | name:Maximum number of HP Boxes on the field
|
---|
| 758 | type:d 0 20 10
|
---|
| 759 | group:Collectibles
|
---|
| 760 | help:The total number of HP Boxes on the field will never exceed this number
|
---|
| 761 |
|
---|
[480] | 762 | property:
|
---|
[231] | 763 | id:upgradeBoxStartingEnergy
|
---|
| 764 | name:Starting energy of Upgrade Box
|
---|
| 765 | type:f 0 1000 500
|
---|
| 766 | group:Collectibles
|
---|
| 767 | help:Base starting energy level for Upgrade Box
|
---|
| 768 |
|
---|
[480] | 769 | property:
|
---|
[231] | 770 | id:upgradeBoxIdleEnergy
|
---|
| 771 | name:Amount of energy lost by Upgrade Box
|
---|
| 772 | type:f 0 10 0.00
|
---|
| 773 | group:Collectibles
|
---|
| 774 | help:How much energy Upgrade Box looses each step (0 - it will not disappear)
|
---|
| 775 |
|
---|
[480] | 776 | property:
|
---|
[231] | 777 | id:upgradeBoxProbability
|
---|
| 778 | name:Probablity that new Upgrade Box will spawn
|
---|
| 779 | type:f 0 1 0.0005
|
---|
| 780 | group:Collectibles
|
---|
| 781 | help:Probability of Upgrade Box appearing each step of simulation
|
---|
| 782 |
|
---|
[480] | 783 | property:
|
---|
[231] | 784 | id:upgradeBoxTotalCount
|
---|
| 785 | name:Maximum number of Upgrade Boxes on the field
|
---|
| 786 | type:d 0 20 10
|
---|
| 787 | group:Collectibles
|
---|
| 788 | help:The total number of Upgrade Boxes on the field will never exceed this number
|
---|
| 789 |
|
---|
[480] | 790 | property:
|
---|
[231] | 791 | id:upgradeBoxDecay
|
---|
| 792 | name:How fast upgrade boost fades from creature
|
---|
| 793 | type:f 0 10 0.1
|
---|
| 794 | group:Collectibles
|
---|
| 795 | help:Each step creature damage bonus will be decreased by given amount until it reaches 0
|
---|
| 796 |
|
---|
[480] | 797 | property:
|
---|
[231] | 798 | id:upgradeMultiplier
|
---|
| 799 | name:Multiplier of bonus damage
|
---|
| 800 | type:f 0 1 0.1
|
---|
| 801 | group:Collectibles
|
---|
| 802 | help:Value of collected bonus multiplied by this variable is taken as bonus damage
|
---|
| 803 |
|
---|
| 804 | # ################################
|
---|
| 805 | # Other
|
---|
| 806 |
|
---|
[480] | 807 | property:
|
---|
[231] | 808 | id:level
|
---|
| 809 | name:Level
|
---|
| 810 | type:d -1 2 0
|
---|
| 811 | help:Number of a level to battle (-1 is random)
|
---|
| 812 |
|
---|
[480] | 813 | property:
|
---|
[231] | 814 | id:stagnationInterval
|
---|
| 815 | name:Number of idle simulation steps before Sudden Death
|
---|
| 816 | type:d 0 10000 5000
|
---|
| 817 | help:If no combat occurs during given number of steps, the Sudden Death mode is turned on (0 = Sudden Death all the time)
|
---|
| 818 |
|
---|
[480] | 819 | property:
|
---|
[231] | 820 | id:stagnationHealthReduce
|
---|
| 821 | name:Sudden Death health reduce
|
---|
| 822 | type:f 0 100 0.1
|
---|
| 823 | help:If Suddent Death is turned on, creatures will lose given amount of HP each simulation step
|
---|
| 824 |
|
---|
[480] | 825 | property:
|
---|
[231] | 826 | id:debug
|
---|
| 827 | name:Show additional debug messages
|
---|
| 828 | type:d 0 1 0
|
---|
| 829 |
|
---|