Выкладываю php код, по просьбе Blagtoof. Забавно, что это кому то может быть нужно. :) А мне не жалко. Забросил по понятным причинам саму игру.
Скачать как файл (download php code as text file).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
<? $dragons = array( '-- Нет --' => array(), 'Great Dragon' => array( '4' => array('melee' => 459, 'ranged' => 459, 'def' => 459, 'hp' => 45947, 'speed' => 750, 'range' => 1500), '5' => array('melee' => 747, 'ranged' => 747, 'def' => 747, 'hp' => 74743, 'speed' => 750, 'range' => 1500), '6' => array('melee' => 1055, 'ranged' => 1055, 'def' => 1055, 'hp' => 105560, 'speed' => 750, 'range' => 1500), '7' => array('melee' => 1379, 'ranged' => 1379, 'def' => 1379, 'hp' => 137972, 'speed' => 750, 'range' => 1500), '8' => array('melee' => 1717, 'ranged' => 1717, 'def' => 1717, 'hp' => 171716, 'speed' => 750, 'range' => 1500), '9' => array('melee' => 2066, 'ranged' => 2066, 'def' => 2066, 'hp' => 206608, 'speed' => 750, 'range' => 1500), '10' => array('melee' => 2425, 'ranged' => 2425, 'def' => 2425, 'hp' => 242514, 'speed' => 750, 'range' => 1500)), 'Stone Dragon' => array( '4' => array('melee' => 1836, 'ranged' => 1378, 'def' => 2754, 'hp' => 183788, 'speed' => 650, 'range' => 1700), '5' => array('melee' => 2988, 'ranged' => 2242, 'def' => 4482, 'hp' => 298972, 'speed' => 650, 'range' => 1700), '6' => array('melee' => 4220, 'ranged' => 3164, 'def' => 6330, 'hp' => 422240, 'speed' => 650, 'range' => 1700), '7' => array('melee' => 5516, 'ranged' => 4138, 'def' => 8274, 'hp' => 551888, 'speed' => 650, 'range' => 1700), '8' => array('melee' => 6868, 'ranged' => 5152, 'def' => 10302, 'hp' => 686864, 'speed' => 650, 'range' => 1700), '9' => array('melee' => 8264, 'ranged' => 6198, 'def' => 12396, 'hp' => 826432, 'speed' => 650, 'range' => 1700), '10' => array('melee' => 9700, 'ranged' => 7276, 'def' => 14550, 'hp' => 970056, 'speed' => 650, 'range' => 1700)), ); $bs = array( 1 => array('melee' => 1, 'ranged' => 0, 'def' => 10, 'hp' => 45, 'speed' => 100, 'range' => 0, 'name' => 'Porter'), 2 => array('melee' => 10, 'ranged' => 0, 'def' => 10, 'hp' => 75, 'speed' => 200, 'range' => 0, 'name' => 'Conscript'), 3 => array('melee' => 5, 'ranged' => 0, 'def' => 5, 'hp' => 10, 'speed' => 3000, 'range' => 0, 'name' => 'Spy'), 4 => array('melee' => 40, 'ranged' => 0, 'def' => 40, 'hp' => 150, 'speed' => 300, 'range' => 0, 'name' => 'Halberdsmen'), 5 => array('melee' => 70, 'ranged' => 0, 'def' => 45, 'hp' => 225, 'speed' => 275, 'range' => 0, 'name' => 'Minotaur'), 6 => array('melee' => 5, 'ranged' => 80, 'def' => 30, 'hp' => 75, 'speed' => 250, 'range' => 1200, 'name' => 'Longbowmen'), 7 => array('melee' => 150, 'ranged' => 0, 'def' => 60, 'hp' => 300, 'speed' => 1000, 'range' => 0, 'name' => 'Swift strike dragon'), 8 => array('melee' => 300, 'ranged' => 0, 'def' => 300, 'hp' => 1500, 'speed' => 750, 'range' => 0, 'name' => 'Battle dragon'), 9 => array('melee' => 5, 'ranged' => 0, 'def' => 200, 'hp' => 750, 'speed' => 150, 'range' => 0, 'name' => 'Armored transport'), 10 => array('melee' => 1000, 'ranged' => 0, 'def' => 400, 'hp' => 4000, 'speed' => 120, 'range' => 0, 'name' => 'Giant'), 11 => array('melee' => 20, 'ranged' => 1200, 'def' => 30, 'hp' => 1500, 'speed' => 50, 'range' => 1500, 'name' => 'Fire Mirror'), 12 => array('melee' => 150, 'ranged' => 0, 'def' => 400, 'hp' => 850, 'speed' => 1000, 'range' => 0, 'name' => 'Pack Dragon'), 13 => array('melee' => 1600, 'ranged' => 800, 'def' => 300, 'hp' => 3000, 'speed' => 500, 'range' => 600, 'name' => 'Fangtooth'), 14 => array('melee' => 650, 'ranged' => 0, 'def' => 900, 'hp' => 15000, 'speed' => 350, 'range' => 0, 'name' => 'Granite Ogre'), 15 => array('melee' => 500, 'ranged' => 2000, 'def' => 150, 'hp' => 1000, 'speed' => 400, 'range' => 1600, 'name' => 'Lava Jaw'), 16 => array('melee' => 700, 'ranged' => 0, 'def' => 200, 'hp' => 2850, 'speed' => 1350, 'range' => 0, 'name' => 'Banshee'), 17 => array('melee' => 1000, 'ranged' => 0, 'def' => 500, 'hp' => 3000, 'speed' => 450, 'range' => 0, 'name' => 'Soul Reaper'), 18 => array('melee' => 900, 'ranged' => 800, 'def' => 225, 'hp' => 3500, 'speed' => 300, 'range' => 700, 'name' => 'Venom Dweller'), 19 => array('melee' => 1500, 'ranged' => 0, 'def' => 200, 'hp' => 5500, 'speed' => 200, 'range' => 0, 'name' => 'Frost Giant'), 20 => array('melee' => 5000, 'ranged' => 0, 'def' => 1500, 'hp' => 7500, 'speed' => 50, 'range' => 0, 'name' => 'Petrified Titan'), 21 => array('melee' => 600, 'ranged' => 400, 'def' => 600, 'hp' => 2000, 'speed' => 1000, 'range' => 1200, 'name' => 'Sand Strider'), ); $wall_koef = 1.05; ?> <style> #atlantis-form .num { width: 50px; text-align: right; } #atlantis-form select { width: auto; } .dead { color: #990000; text-decoration:line-through; } .wounded { color: #990000; } </style> <form method="POST" action="?#calced" name="atlantis-form" id="atlantis-form"> <table> <tr> <td><h2>Нападающая сторона (attacker)</h2></td> <td><h2>Сторона обороны (defender)</h2></td> </tr> <tr> <td colspan="2" align="left"><h3>Дракон (Dragon)</h3></td> </tr> <tr align="left"> <td><select name="da"> <? foreach ($dragons as $k => $v) { if ($_POST['da'] == $k) echo "<option value=\"$k\" selected>$k</option>\n"; else echo "<option value=\"$k\">$k</option>\n"; } ?> </select> Уровень: <select name="da_lev"> <? for($k = 4; $k < 11; $k++) { if ($_POST['da_lev'] == $k) echo "<option value=\"$k\" selected>$k</option>\n"; else echo "<option value=\"$k\">$k</option>\n"; } ?> </select> </td> <td><select name="dd"> <? foreach ($dragons as $k => $v) { if ($_POST['dd'] == $k) echo "<option value=\"$k\" selected>$k</option>\n"; else echo "<option value=\"$k\">$k</option>\n"; } ?> </select> Уровень: <select name="dd_lev"> <? for($k = 4; $k < 11; $k++) { if ($_POST['dd_lev'] == $k) echo "<option value=\"$k\" selected>$k</option>\n"; else echo "<option value=\"$k\">$k</option>\n"; } ?> </select> </td> </tr> <tr> <td colspan="2" align="left"><h3>Войска (Battle units)</h3></td> </tr> <tr align="left"> <td> <table> <tr> <td>Porter<br > <input type="text" name="p1" value="<?=$_POST['p1'] + 0?>"></td> <td>Conscript<br > <input type="text" name="p2" value="<?=$_POST['p2'] + 0?>"></td> <td>Spy<br > <input type="text" name="p3" value="<?=$_POST['p3'] + 0?>"></td> </tr> <tr> <td>Halbersman<br > <input type="text" name="p4" value="<?=$_POST['p4'] + 0?>"></td> <td>Minotaur<br > <input type="text" name="p5" value="<?=$_POST['p5'] + 0?>"></td> <td>Longbowman<br > <input type="text" name="p6" value="<?=$_POST['p6'] + 0?>"></td> </tr> <tr> <td>Swift Dragon<br > <input type="text" name="p7" value="<?=$_POST['p7'] + 0?>"></td> <td>Battle Dragon<br > <input type="text" name="p8" value="<?=$_POST['p8'] + 0?>"></td> <td>Armored Tr.<br > <input type="text" name="p9" value="<?=$_POST['p9'] + 0?>"></td> </tr> <tr> <td>Giant<br > <input type="text" name="p10" value="<?=$_POST['p10'] + 0?>"></td> <td>Fire Mirror<br > <input type="text" name="p11" value="<?=$_POST['p11'] + 0?>"></td> <td>Pack Dragon<br > <input type="text" name="p12" value="<?=$_POST['p12'] + 0?>"></td> </tr> <tr> <td>FangTooth<br > <input type="text" name="p13" value="<?=$_POST['p13'] + 0?>"></td> <td>Granite Ogre<br > <input type="text" name="p14" value="<?=$_POST['p14'] + 0?>"></td> <td>Lava Jaw<br > <input type="text" name="p15" value="<?=$_POST['p15'] + 0?>"></td> </tr> <tr> <td>Banshee<br > <input type="text" name="p16" value="<?=$_POST['p16'] + 0?>"></td> <td>Soul Reaper<br > <input type="text" name="p17" value="<?=$_POST['p17'] + 0?>"></td> <td>Venom Dweller<br > <input type="text" name="p18" value="<?=$_POST['p18'] + 0?>"></td> </tr> <tr> <td>Frost Giant<br > <input type="text" name="p19" value="<?=$_POST['p19'] + 0?>"></td> <td>Petrified Titan<br > <input type="text" name="p20" value="<?=$_POST['p20'] + 0?>"></td> <td>Sand Strider<br > <input type="text" name="p21" value="<?=$_POST['p21'] + 0?>"></td> </tr> </table> </td> <td> <table> <tr> <td>Porter<br > <input type="text" name="r1" value="<?=$_POST['r1'] + 0?>"></td> <td>Conscript<br > <input type="text" name="r2" value="<?=$_POST['r2'] + 0?>"></td> <td>Spy<br > <input type="text" name="r3" value="<?=$_POST['r3'] + 0?>"></td> </tr> <tr> <td>Halbersman<br > <input type="text" name="r4" value="<?=$_POST['r4'] + 0?>"></td> <td>Minotaur<br > <input type="text" name="r5" value="<?=$_POST['r5'] + 0?>"></td> <td>Longbowman<br > <input type="text" name="r6" value="<?=$_POST['r6'] + 0?>"></td> </tr> <tr> <td>Swift Dragon<br > <input type="text" name="r7" value="<?=$_POST['r7'] + 0?>"></td> <td>Battle Dragon<br > <input type="text" name="r8" value="<?=$_POST['r8'] + 0?>"></td> <td>Armored Tr.<br > <input type="text" name="r9" value="<?=$_POST['r9'] + 0?>"></td> </tr> <tr> <td>Giant<br > <input type="text" name="r10" value="<?=$_POST['r10'] + 0?>"></td> <td>Fire Mirror<br > <input type="text" name="r11" value="<?=$_POST['r11'] + 0?>"></td> <td>Pack Dragon<br > <input type="text" name="r12" value="<?=$_POST['r12'] + 0?>"></td> </tr> <tr> <td>FangTooth<br > <input type="text" name="r13" value="<?=$_POST['r13'] + 0?>"></td> <td>Granite Ogre<br > <input type="text" name="r14" value="<?=$_POST['r14'] + 0?>"></td> <td>Lava Jaw<br > <input type="text" name="r15" value="<?=$_POST['r15'] + 0?>"></td> </tr> <tr> <td>Banshee<br > <input type="text" name="r16" value="<?=$_POST['r16'] + 0?>"></td> <td>Soul Reaper<br > <input type="text" name="r17" value="<?=$_POST['r17'] + 0?>"></td> <td>Venom Dweller<br > <input type="text" name="r18" value="<?=$_POST['r18'] + 0?>"></td> </tr> <tr> <td>Frost Giant<br > <input type="text" name="r19" value="<?=$_POST['r19'] + 0?>"></td> <td>Petrified Titan<br > <input type="text" name="r20" value="<?=$_POST['r20'] + 0?>"></td> <td>Sand Strider<br > <input type="text" name="r21" value="<?=$_POST['r21'] + 0?>"></td> </tr> </table> </td> </tr> <tr> <td colspan="2" align="left"><h3>Технологии (Technologies)</h3></td> </tr> <tr> <td> <table> <tr> <td><a title="Weapon calibration">WC</a><br > <input type="text" name="s1" value="<?=$_POST['s1'] + 0?>"></td> <td><a title="Metallurgy">MET</a><br > <input type="text" name="s2" value="<?=$_POST['s2'] + 0?>"></td> <td><a title="Medicine">MED</a><br > <input type="text" name="s3" value="<?=$_POST['s3'] + 0?>"></td> </tr> <tr> <td><a title="Dragonry">DRG</a><br > <input type="text" name="s4" value="<?=$_POST['s4'] + 0?>"></td> <td><a title="Rapid Deployment">RD</a><br > <input type="text" name="s5" value="<?=$_POST['s5'] + 0?>"></td> <td></td> </tr> <tr> <td><a title="Warrior Revival">WR</a><br > <input type="text" name="s6" value="<?=$_POST['s6'] + 0?>"></td> <td><a title="Guardian Revival">GR</a><br > <input type="text" name="s7" value="<?=$_POST['s7'] + 0?>"></td> <td></td> </tr> </table> </td> <td> <table> <tr> <td><a title="Weapon calibration">WC</a><br > <input type="text" name="sc1" value="<?=$_POST['sc1'] + 0?>"></td> <td><a title="Metallurgy">MET</a><br > <input type="text" name="sc2" value="<?=$_POST['sc2'] + 0?>"></td> <td><a title="Medicine">MED</a><br > <input type="text" name="sc3" value="<?=$_POST['sc3'] + 0?>"></td> </tr> <tr> <td><a title="Dragonry">DRG</a><br > <input type="text" name="sc4" value="<?=$_POST['sc4'] + 0?>"></td> <td><a title="Rapid Deployment">RD</a><br > <input type="text" name="sc5" value="<?=$_POST['sc5'] + 0?>"></td> <td></td> </tr> <tr> <td><a title="Warrior Revival">WR</a><br > <input type="text" name="sc6" value="<?=$_POST['sc6'] + 0?>"></td> <td><a title="Guardian Revival">GR</a><br > <input type="text" name="sc7" value="<?=$_POST['sc7'] + 0?>"></td> <td></td> </tr> </table> </td> <tr align="left"> <td></td> <td>Уровень стены (city wall level) <br > <input type="text" name="wall" value="<?=$_POST['wall'] + 0?>"> </td> </tr> <tr align="right"> <td colspan="2"> <input type="submit" name="sbm" value="Посчитать"> <input type="hidden" name="action" value="calc"> </td> </tr> </tr> </table> </form> <? if ($_POST['action'] == 'calc') { //чтение данных $att = array( 'f' => array(), 's' => array(), ); $def = array( 'f' => array(), 's' => array(), 'w' => 0 ); //научка for($k = 1; $k < 7; $k ++) { if (!empty($_POST['s' . $k])) { $value = _num_read('s' . $k); $att['s'][$k] = $value; } if (!empty($_POST['sc' . $k])) { $value = _num_read('sc' . $k); $def['s'][$k] = $value; } } //стена $def['w'] = _num_read('wall') * $wall_koef; //модификатор защиты стенки $maxRange = 0; //драконы if ($_POST['da'] != '-- Нет --' && isset($dragons[$_POST['da']]) && $_POST['da_lev'] + 0 >= 8 && $_POST['da_lev'] + 0 <= 10) { $att['f'][0] = $dragons[$_POST['da']][$_POST['da_lev'] + 0]; $att['f'][0]['amount'] = 1; $att['f'][0]['name'] = $_POST['da']; $maxRange = $att['f'][0]['range']; } if ($_POST['dd'] != '-- Нет --' && isset($dragons[$_POST['dd']]) && $_POST['dd_lev'] + 0 >= 8 && $_POST['dd_lev'] + 0 <= 10) { $def['f'][0] = $dragons[$_POST['dd']][$_POST['dd_lev'] + 0]; $def['f'][0]['amount'] = 1; $def['f'][0]['name'] = $_POST['dd']; // $maxRange = max($def['f'][0]['range'], $maxRange); } //отряды for($k = 1; $k < 22; $k ++) { if (!empty($_POST['p' . $k])) { $value = _num_read('p' . $k); if ($value > 0) { $att['f'][$k] = $bs[$k]; $att['f'][$k]['amount'] = $value; $att['f'][$k]['range'] *= 1 + $att['s'][1] * 0.05; //WC $att['f'][$k]['ranged'] *= 1 + $att['s'][2] * 0.05; //MET $att['f'][$k]['melee'] *= 1 + $att['s'][2] * 0.05; //MET $att['f'][$k]['def'] *= 1 + $att['s'][2] * 0.05; //MET $att['f'][$k]['hp'] *= 1 + $att['s'][3] * 0.05; //MED $att['f'][$k]['speed'] *= 1 + $att['s'][5] * 0.05 //RD + ($k == 7 || $k == 8 ? $att['s'][4] * 0.05 : 0); //DRAG if ($maxRange < $att['f'][$k]['range']) $maxRange = $att['f'][$k]['range']; } } if (!empty($_POST['r' . $k])) { $value = _num_read('r' . $k); if ($value > 0) { $def['f'][$k] = $bs[$k]; $def['f'][$k]['amount'] = $value; $def['f'][$k]['range'] *= 1 + $def['s'][1] * 0.05; //WC $def['f'][$k]['ranged'] *= 1 + $def['s'][2] * 0.05; //MET $def['f'][$k]['melee'] *= 1 + $def['s'][2] * 0.05; //MET $def['f'][$k]['def'] *= 1 + $def['s'][2] * 0.05; //MET $def['f'][$k]['hp'] *= 1 + $def['s'][3] * 0.05; //MED $def['f'][$k]['speed'] *= 1 + $def['s'][5] * 0.05 //RD + ($k == 7 || $k == 8 ? $def['s'][4] * 0.05 : 0); //DRAG // if ($maxRange < $def['f'][$k]['range']) $maxRange = $def['f'][$k]['range']; } } } $len = rand(350, 500) + $maxRange; //вообще то от 325 до 550 //расчет раундов и вывод информации по итерациям $DOA = new DAO_calc($att, $def, $len); echo "<a name='calced'></a><p>Обратите внимание, что некоторые детали боя зависят от <b>случайных факторов</b> (от генератора случаных чисел - RNG). Потому стоит несколько раз прогонять одни и те же данные через расчет, чтобы поглядеть возможные варианты исхода боя.</p> <h3>Перед боем (Before fight)</h3>"; echo $DOA->show(); while ($DOA -> iteration()) { echo "<h3>Раунд (Round) № " . $DOA->n_inter . '</h3>'; echo $DOA->show(); } } function _num_read($name) { if (!empty($_POST[$name])) { return floor(abs($_POST[$name] + 0)); } return 0; } /* класс для расчета раундов боя */ class DAO_calc { var $att, $def; var $n_inter = 0; function DAO_calc($att, $def, $range) { uasort($att['f'], 'DAO_calc::speed_buble'); $this->att = $att; uasort($def['f'], 'DAO_calc::speed_buble'); $this->def = $def; foreach($this->att['f'] as $k => $v) { $this->att['f'][$k]['pos'] = 0; //общее число хитов и брони $this->att['f'][$k]['hp-amount'] = $v['amount'] * $v['hp']; $this->att['f'][$k]['arm-amount'] = $v['amount'] * $v['def']; } foreach($this->def['f'] as $k => $v) { $this->def['f'][$k]['pos'] = $range; //общее число хитов и брони $this->def['f'][$k]['hp-amount'] = $v['amount'] * $v['hp']; $this->def['f'][$k]['arm-amount'] = $v['amount'] * $v['def']; } } //расстояние и описание группы войск - рассчитаем потенц. опасность function danger_rating($distance, $bg) { if ($distance > 0 && $bg['ranged'] > 0) { return $bg['ranged'] * $bg['amount']; } else { return $bg['melee'] * $bg['amount']; } } /* выбрать ближайшего врага со строны защиты */ function select_def($att_ind) { $z = &$this->att[$att_ind]; $pos = 1000000; $danger = 0; $t = -1; foreach($this->def['f'] as $ek => $ev) { $new_danger = $this->danger_rating($ev['pos'] - $z['pos'], $ev); if ($pos > $ev['pos'] || ($pos == $ev['pos'] && $new_danger > $danger) ) { $pos = $ev['pos']; $danger = $new_danger; $t = $ek; } } return $t; } /* выбрать ближайшего врага со строны атаккера */ function select_att($def_ind) { $z = &$this->def[$def_ind]; $pos = -100; $danger = 0; $t = -1; foreach($this->att['f'] as $ek => $ev) { $new_danger = $this->danger_rating($z['pos'] - $ev['pos'], $ev); if ($pos < $ev['pos'] || ($pos == $ev['pos'] && $new_danger > $danger) ) { $pos = $ev['pos']; $danger = $new_danger; $t = $ek; } } return $t; } /* вывод таблицы раунда */ function show() { $as = '<table> <tr><td></td><th>ATTeff</th><th>HP</th><th>DEF</th><th>Amount</th><th>Pos</th></tr>'; foreach ($this->att['f'] as $k => $v) { if (!$v['amount']) { $as .= "<tr><th class=\"dead\">{$v['name']}</th><td colspan=4></td><td>" . floor($v['pos']) . "</td></tr>"; unset($this->att['f'][$k]); } else { if ($v['f']) { $class = 'wounded'; $this->att['f'][$k]['f'] = 0; } else $class = ''; $as .= "<tr class='$class'><th>{$v['name']}</th><td>" . round($v['attack'], 2) . "</td><td>" . floor($v['hp-amount'] / $v['amount']) . "</td><td>" . floor($v['arm-amount'] / $v['amount']). "</td><td>" . floor($v['amount']) . "</td><td>" . floor($v['pos']) . "</td></tr>"; } } $as .= '</table>'; $ds = '<table> <tr><td></td><th>ATTeff</th><th>HP</th><th>DEF</th><th>Amount</th><th>Pos</th></tr>'; foreach ($this->def['f'] as $k => $v) { if (!$v['amount']) { $ds .= "<tr><th class=\"dead\">{$v['name']}</th><td colspan=4></td><td>" . floor($v['pos']) . "</td></tr>"; unset($this->def['f'][$k]); } else { if ($v['f']) { $class = 'wounded'; $this->def['f'][$k]['f'] = 0; } else $class = ''; $ds .= "<tr class='$class'><th>{$v['name']}</th><td>" . round($v['attack'] ,2) . "</td><td>" . floor($v['hp-amount'] / $v['amount']) . "</td><td>" . floor($v['arm-amount'] / $v['amount']). "</td><td>" . floor($v['amount']) . "</td><td>" . floor($v['pos']) . "</td></tr>"; } } $ds .= '</table>'; return "<table width=\"85%\"> <tr valign=\"top\" style=\"font-size: 10px;\"> <td width=\"50%\">$as</td> <td>$ds</td></tr> </table>"; } function iteration() { //остались ли ещё воины $n = 0; foreach($this->att['f'] as $k => $v) { $n += $this->att['f'][$k]['amount']; } if (!$n) return false; $n = 0; foreach($this->def['f'] as $k => $v) { $n += $this->def['f'][$k]['amount']; } if (!$n) return false; $this->n_inter ++; if ($this->n_inter > 50) return false; //ограничение по числу расчетных раундов //ход атакующего foreach($this->att['f'] as $k => $v) { //ближайший враг $t = $this->select_def($k); $defer = &$this->def['f'][$t]; if ($t == -1) return true; //враг не обнаружен - но итерация полноценная, поэтому вернем true $pos = $defer['pos']; //движение if ($pos > $v['pos'] + $v['range']) { $new_pos = min($v['pos'] + $v['speed'], $pos - $v['range']); if ($new_pos > $v['pos']) { $this->att['f'][$k]['pos'] = $new_pos; $v['pos'] = $new_pos; } } if ($v['pos'] < $pos && $v['pos'] + $v['range'] >= $pos) { //атака ranged $attack = $v['ranged']; } else if ($v['pos'] == $pos) { //атака melee $attack = $v['melee']; } else continue; $attack -= $this->def['w']; $this->att['f'][$k]['attack'] = $attack; if ($attack <= 0) continue; $dem = $attack * $v['amount']; $defer['f'] = 1; $amount = $defer['amount']; $arm = $defer['arm-amount']; $hp = $defer['hp-amount']; //коэф неопред $min = 0.5; $max = $attack / ($attack + $defer['def']); $dem = $dem * 0.5 + $dem * $max * mt_rand() / mt_getrandmax(); //особенности if ($k == 18 && $t == 14) $dem *= 2; //venom dveller атакует granite ogre с удвоенным уроном if ($k == 19 && $t == 15) $dem /= 2; //lava jaw получает в два раза меньший урон от frost giant //варианты стычки if ($dem >= $arm + $hp) { $defer['amount'] = 0; //сдохли } else if ($dem <= $arm) { // $this->def['f'][$t]['def'] = ($arm - $dem) / $amount; //ослабление брони (чисто для индикации) $defer['arm-amount'] -= $dem; } else { // $this->def['f'][$t]['def'] = 0 $dem -= $defer['arm-amount']; $defer['arm-amount'] = 0; //броня выбита $defer['hp-amount'] -= $dem; $defer['amount'] = ceil($defer['hp-amount'] / $defer['hp']); } } //ход обороняющегося foreach($this->def['f'] as $k => $v) { if (!$v['amount']) continue; //ближайший враг $t = $this->select_att($k); $ataker = &$this->att['f'][$t]; if ($t == -1) return true; //враг не обнаружен - но итерация полноценная, поэтому вернем true $pos = $ataker['pos']; //движение if ($pos < $v['pos'] - $v['range']) { $new_pos = max($v['pos'] - $v['speed'], $pos + $v['range']); if ($new_pos < $v['pos']) { $this->def['f'][$k]['pos'] = $new_pos; $v['pos'] = $new_pos; } } if ($v['pos'] > $pos && $v['pos'] - $v['range'] <= $pos) { //атака ranged $attack = $v['ranged']; } else if ($v['pos'] == $pos) { //атака melee $attack = $v['melee']; } else continue; $this->def['f'][$k]['attack'] = $attack; $dem = $attack * $v['amount']; $ataker['f'] = 1; $amount = $ataker['amount']; $arm = $ataker['arm-amount']; $hp = $ataker['hp-amount']; //коэф неопред $min = 0.5; $max = $attack / ($attack + $ataker['def']); $dem = $dem * 0.5 + $dem * $max * mt_rand() / mt_getrandmax(); //особенности if ($k == 18 && $t == 14) $dem *= 2; //venom dveller атакует granite ogre с удвоенным уроном if ($k == 19 && $t == 15) $dem /= 2; //lava jaw получает в два раза меньший урон от frost giant //варианты стычки if ($dem >= $arm + $hp) { $ataker['amount'] = 0; //сдохли } else if ($dem <= $arm) { // $this->att['f'][$t]['def'] = ($arm - $dem) / $amount; //ослабление брони $ataker['arm-amount'] -= $dem; } else { // $this->att['f'][$t]['def'] = 0 $dem -= $ataker['arm-amount']; $ataker['arm-amount'] = 0; //броня выбита $ataker['hp-amount'] -= $dem; $ataker['amount'] = ceil($ataker['hp-amount'] / $ataker['hp']); } } return true; } static function speed_buble($a, $b) { if ($a['speed'] == $b['speed']) { return 0; } return ($a['speed'] > $b['speed']) ? -1 : 1; //с большей скоротью объекты всплвывают вверх } } |
Thanks a lot!
thankkk yyooouuuuu