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 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/random.h"
#include "hdb/hdb.h"
#include "hdb/ai.h"
#include "hdb/ai-player.h"
#include "hdb/file-manager.h"
#include "hdb/gfx.h"
#include "hdb/sound.h"
#include "hdb/menu.h"
#include "hdb/lua-script.h"
#include "hdb/map.h"
#include "hdb/mpc.h"
#include "hdb/window.h"
namespace HDB {
void aiPlayerInit(AIEntity *e, int mx, int my) {
g_hdb->_ai->clearInventory();
e->aiAction = aiPlayerAction;
e->draw = g_hdb->_ai->getStandFrameDir(e);
switch (e->dir) {
case DIR_UP:
e->state = STATE_STANDUP;
break;
case DIR_DOWN:
e->state = STATE_STANDDOWN;
break;
case DIR_LEFT:
e->state = STATE_STANDLEFT;
break;
case DIR_RIGHT:
e->state = STATE_STANDRIGHT;
break;
case DIR_NONE:
default:
break;
}
e->moveSpeed = kPlayerMoveSpeed;
Common::strlcpy(e->entityName, "player", 32);
g_hdb->_ai->assignPlayer(e);
}
void aiPlayerInit2(AIEntity *e, int mx, int my) {
if (!g_hdb->_ai->_clubUpGfx[0]) {
g_hdb->_ai->_weaponSelGfx = g_hdb->_gfx->loadTile(TILE_WEAPON_EQUIPPED);
g_hdb->_ai->_clubUpGfx[0] = g_hdb->_gfx->getPicGfx(CLUBUP1, -1);
g_hdb->_ai->_clubUpGfx[1] = g_hdb->_gfx->getPicGfx(CLUBUP2, -1);
g_hdb->_ai->_clubUpGfx[2] = g_hdb->_gfx->getPicGfx(CLUBUP3, -1);
g_hdb->_ai->_clubUpGfx[3] = g_hdb->_gfx->getPicGfx(CLUBUP3, -1);
g_hdb->_ai->_clubDownGfx[0] = g_hdb->_gfx->getPicGfx(CLUBDOWN1, -1);
g_hdb->_ai->_clubDownGfx[1] = g_hdb->_gfx->getPicGfx(CLUBDOWN2, -1);
g_hdb->_ai->_clubDownGfx[2] = g_hdb->_gfx->getPicGfx(CLUBDOWN3, -1);
g_hdb->_ai->_clubDownGfx[3] = g_hdb->_gfx->getPicGfx(CLUBDOWN3, -1);
g_hdb->_ai->_clubLeftGfx[0] = g_hdb->_gfx->getPicGfx(CLUBLEFT1, -1);
g_hdb->_ai->_clubLeftGfx[1] = g_hdb->_gfx->getPicGfx(CLUBLEFT2, -1);
g_hdb->_ai->_clubLeftGfx[2] = g_hdb->_gfx->getPicGfx(CLUBLEFT3, -1);
g_hdb->_ai->_clubLeftGfx[3] = g_hdb->_gfx->getPicGfx(CLUBLEFT3, -1);
g_hdb->_ai->_clubRightGfx[0] = g_hdb->_gfx->getPicGfx(CLUBRIGHT1, -1);
g_hdb->_ai->_clubRightGfx[1] = g_hdb->_gfx->getPicGfx(CLUBRIGHT2, -1);
g_hdb->_ai->_clubRightGfx[2] = g_hdb->_gfx->getPicGfx(CLUBRIGHT3, -1);
g_hdb->_ai->_clubRightGfx[3] = g_hdb->_gfx->getPicGfx(CLUBRIGHT3, -1);
g_hdb->_ai->_clubUpFrames = g_hdb->_ai->_clubDownFrames =
g_hdb->_ai->_clubLeftFrames = g_hdb->_ai->_clubRightFrames = 4;
g_hdb->_ai->_slugAttackGfx[0] = g_hdb->_gfx->loadPic(SLUG_SHOT1);
g_hdb->_ai->_slugAttackGfx[1] = g_hdb->_gfx->loadPic(SLUG_SHOT2);
g_hdb->_ai->_slugAttackGfx[2] = g_hdb->_gfx->loadPic(SLUG_SHOT3);
g_hdb->_ai->_slugAttackGfx[3] = g_hdb->_gfx->loadPic(SLUG_SHOT4);
int32 size = g_hdb->_fileMan->getLength("shock_spark_sit01", TYPE_TILE32);
g_hdb->_ai->_stunLightningGfx[0] = g_hdb->_gfx->getTileGfx("shock_spark_sit01", size);
size = g_hdb->_fileMan->getLength("shock_spark_sit02", TYPE_TILE32);
g_hdb->_ai->_stunLightningGfx[1] = g_hdb->_gfx->getTileGfx("shock_spark_sit02", size);
size = g_hdb->_fileMan->getLength("shock_spark_sit03", TYPE_TILE32);
g_hdb->_ai->_stunLightningGfx[2] = g_hdb->_gfx->getTileGfx("shock_spark_sit03", size);
size = g_hdb->_fileMan->getLength("shock_spark_sit04", TYPE_TILE32);
g_hdb->_ai->_stunLightningGfx[3] = g_hdb->_gfx->getTileGfx("shock_spark_sit04", size);
size = g_hdb->_fileMan->getLength("starstun_sit01", TYPE_TILE32);
g_hdb->_ai->_stunnedGfx[0] = g_hdb->_gfx->getTileGfx("starstun_sit01", size);
size = g_hdb->_fileMan->getLength("starstun_sit02", TYPE_TILE32);
g_hdb->_ai->_stunnedGfx[1] = g_hdb->_gfx->getTileGfx("starstun_sit02", size);
size = g_hdb->_fileMan->getLength("starstun_sit03", TYPE_TILE32);
g_hdb->_ai->_stunnedGfx[2] = g_hdb->_gfx->getTileGfx("starstun_sit03", size);
size = g_hdb->_fileMan->getLength("starstun_sit04", TYPE_TILE32);
g_hdb->_ai->_stunnedGfx[3] = g_hdb->_gfx->getTileGfx("starstun_sit04", size);
}
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiPlayerAction(AIEntity *e, int mx, int my) {
static const AIState stand[5] = {STATE_NONE, STATE_STANDUP, STATE_STANDDOWN, STATE_STANDLEFT, STATE_STANDRIGHT};
static const int xvAhead[5] = {9, 0, 0, -1, 1};
static const int yvAhead[5] = {9, -1, 1, 0, 0};
AIEntity *hit = nullptr;
// Draw the STUN lightning if it exists
if (e->sequence) {
e->aiDraw = aiPlayerDraw;
g_hdb->_sound->playSound(SND_STUNNER_FIRE);
hit = g_hdb->_ai->findEntity(e->tileX + xvAhead[e->dir], e->tileY + yvAhead[e->dir]);
if (hit)
switch (hit->type) {
case AI_MEERKAT:
if (hit->sequence > 2)
g_hdb->_ai->stunEnemy(hit, 8);
break;
case AI_ICEPUFF:
if (hit->state == STATE_ICEP_APPEAR || hit->state == STATE_ICEP_THROWDOWN || hit->state == STATE_ICEP_THROWLEFT || hit->state == STATE_ICEP_THROWRIGHT) {
g_hdb->_ai->addAnimateTarget(hit->x, hit->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->stunEnemy(hit, 8);
}
break;
case AI_BADFAIRY:
case AI_GOODFAIRY:
case AI_CHICKEN:
case AI_OMNIBOT:
case AI_TURNBOT:
case AI_PUSHBOT:
case AI_DEADEYE:
case AI_FATFROG:
case AI_BUZZFLY:
case AI_MAINTBOT:
case AI_RIGHTBOT:
case AI_GATEPUDDLE:
g_hdb->_ai->stunEnemy(hit, 8);
break;
default:
break;
}
hit = g_hdb->_ai->findEntity(e->tileX + (xvAhead[e->dir] << 1), e->tileY + (yvAhead[e->dir] << 1));
if (hit)
switch (hit->type) {
case AI_MEERKAT:
if (hit->sequence > 2)
g_hdb->_ai->stunEnemy(hit, 8);
break;
case AI_ICEPUFF:
if (hit->state == STATE_ICEP_APPEAR || hit->state == STATE_ICEP_THROWDOWN || hit->state == STATE_ICEP_THROWLEFT || hit->state == STATE_ICEP_THROWRIGHT) {
g_hdb->_ai->addAnimateTarget(hit->x, hit->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->stunEnemy(hit, 8);
}
break;
case AI_BADFAIRY:
case AI_GOODFAIRY:
case AI_CHICKEN:
case AI_OMNIBOT:
case AI_TURNBOT:
case AI_PUSHBOT:
case AI_DEADEYE:
case AI_FATFROG:
case AI_BUZZFLY:
case AI_MAINTBOT:
case AI_RIGHTBOT:
case AI_GATEPUDDLE:
g_hdb->_ai->stunEnemy(hit, 8);
break;
default:
break;
}
}
int xOff[] = {0, 0, -8,-16};
int yOff[] = {-8,-24,-16,-16};
// If the player is supposed to animate for abit, check for it here
switch (e->state) {
case STATE_GRABUP:
case STATE_GRABDOWN:
case STATE_GRABLEFT:
case STATE_GRABRIGHT:
if (!e->animFrame--) {
// Done with the Grabbing Animation, switch to standing
switch (e->state) {
case STATE_GRABUP:
e->draw = e->standupGfx[0];
e->state = STATE_STANDUP;
break;
case STATE_GRABDOWN:
e->draw = e->standdownGfx[0];
e->state = STATE_STANDDOWN;
break;
case STATE_GRABLEFT:
e->draw = e->standleftGfx[0];
e->state = STATE_STANDLEFT;
break;
case STATE_GRABRIGHT:
e->draw = e->standrightGfx[0];
e->state = STATE_STANDRIGHT;
break;
default:
break;
}
e->animDelay = 1;
e->animCycle = 1;
}
break;
case STATE_ATK_CLUB_UP:
case STATE_ATK_CLUB_DOWN:
case STATE_ATK_CLUB_LEFT:
case STATE_ATK_CLUB_RIGHT:
g_hdb->_ai->setPlayerInvisible(true);
e->aiDraw = aiPlayerDraw;
e->drawXOff = xOff[e->state - STATE_ATK_CLUB_UP];
e->drawYOff = yOff[e->state - STATE_ATK_CLUB_UP];
switch (e->state) {
case STATE_ATK_CLUB_UP:
cycleFrames(e, g_hdb->_ai->_clubUpFrames);
break;
case STATE_ATK_CLUB_DOWN:
cycleFrames(e, g_hdb->_ai->_clubDownFrames);
break;
case STATE_ATK_CLUB_LEFT:
cycleFrames(e, g_hdb->_ai->_clubLeftFrames);
break;
case STATE_ATK_CLUB_RIGHT:
cycleFrames(e, g_hdb->_ai->_clubRightFrames);
break;
default:
break;
}
// Whack!
if ((e->animFrame >= 1) && (e->animDelay == e->animCycle)) {
switch (e->dir) {
case DIR_UP:
hit = g_hdb->_ai->playerCollision(32, 0, 16, 16);
break;
case DIR_DOWN:
hit = g_hdb->_ai->playerCollision(0, 32, 16, 16);
break;
case DIR_LEFT:
hit = g_hdb->_ai->playerCollision(16, 16, 32, 0);
break;
case DIR_RIGHT:
hit = g_hdb->_ai->playerCollision(16, 16, 0, 32);
break;
default:
break;
}
if (hit && hit->level == e->level && !hit->stunnedWait) {
switch (hit->type) {
case AI_MEERKAT:
if (hit->sequence > 2) // out of the ground?
g_hdb->_ai->stunEnemy(hit, 2);
break;
case AI_ICEPUFF:
if (hit->state == STATE_ICEP_APPEAR ||
hit->state == STATE_ICEP_THROWDOWN ||
hit->state == STATE_ICEP_THROWLEFT ||
hit->state == STATE_ICEP_THROWRIGHT)
g_hdb->_ai->stunEnemy(hit, 2);
break;
case AI_CHICKEN:
g_hdb->_ai->addAnimateTarget(hit->x, hit->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->removeEntity(hit);
break;
case AI_BADFAIRY:
case AI_GOODFAIRY:
case AI_OMNIBOT:
case AI_TURNBOT:
case AI_PUSHBOT:
case AI_DEADEYE:
case AI_FATFROG:
case AI_BUZZFLY:
case AI_MAINTBOT:
case AI_RIGHTBOT:
case AI_SHOCKBOT:
case AI_GATEPUDDLE:
g_hdb->_ai->stunEnemy(hit, 2);
g_hdb->_sound->playSound(g_hdb->_ai->metalOrFleshSND(hit));
break;
default:
break;
}
}
}
if ((!e->animFrame) && (e->animDelay == e->animCycle)) {
e->state = stand[e->dir];
e->aiDraw = nullptr;
switch (e->state) {
case STATE_ATK_CLUB_UP:
e->draw = e->standupGfx[0];
break;
case STATE_ATK_CLUB_DOWN:
e->draw = e->standdownGfx[0];
break;
case STATE_ATK_CLUB_LEFT:
e->draw = e->standleftGfx[0];
break;
case STATE_ATK_CLUB_RIGHT:
e->draw = e->standrightGfx[0];
break;
default:
break;
}
g_hdb->_ai->setPlayerInvisible(false);
e->drawXOff = e->drawYOff = 0;
}
return;
case STATE_ATK_STUN_UP:
e->draw = g_hdb->_ai->_stunUpGfx[e->animFrame];
cycleFrames(e, g_hdb->_ai->_stunUpFrames);
if (!e->animFrame && e->animDelay == e->animCycle) {
e->state = stand[e->dir];
e->aiDraw = nullptr;
e->sequence = 0;
}
return;
case STATE_ATK_STUN_DOWN:
e->draw = g_hdb->_ai->_stunDownGfx[e->animFrame];
cycleFrames(e, g_hdb->_ai->_stunDownFrames);
if (!e->animFrame && e->animDelay == e->animCycle) {
e->state = stand[e->dir];
e->aiDraw = nullptr;
e->sequence = 0;
}
return;
case STATE_ATK_STUN_LEFT:
e->draw = g_hdb->_ai->_stunLeftGfx[e->animFrame];
cycleFrames(e, g_hdb->_ai->_stunLeftFrames);
if (!e->animFrame && e->animDelay == e->animCycle) {
e->state = stand[e->dir];
e->aiDraw = nullptr;
e->sequence = 0;
}
return;
case STATE_ATK_STUN_RIGHT:
e->draw = g_hdb->_ai->_stunRightGfx[e->animFrame];
cycleFrames(e, g_hdb->_ai->_stunRightFrames);
if (!e->animFrame && e->animDelay == e->animCycle) {
e->state = stand[e->dir];
e->aiDraw = nullptr;
e->sequence = 0;
}
return;
case STATE_ATK_SLUG_UP:
e->draw = g_hdb->_ai->_slugUpGfx[e->animFrame];
cycleFrames(e, g_hdb->_ai->_slugUpFrames);
if (!e->animFrame && e->animDelay == e->animCycle) {
e->state = stand[e->dir];
e->sequence = 0;
}
return;
case STATE_ATK_SLUG_DOWN:
e->draw = g_hdb->_ai->_slugDownGfx[e->animFrame];
cycleFrames(e, g_hdb->_ai->_slugDownFrames);
if (!e->animFrame && e->animDelay == e->animCycle) {
e->state = stand[e->dir];
e->sequence = 0;
}
return;
case STATE_ATK_SLUG_LEFT:
e->draw = g_hdb->_ai->_slugLeftGfx[e->animFrame];
cycleFrames(e, g_hdb->_ai->_slugLeftFrames);
if (!e->animFrame && e->animDelay == e->animCycle) {
e->state = stand[e->dir];
e->sequence = 0;
}
return;
case STATE_ATK_SLUG_RIGHT:
e->draw = g_hdb->_ai->_slugRightGfx[e->animFrame];
cycleFrames(e, g_hdb->_ai->_slugRightFrames);
if (!e->animFrame && e->animDelay == e->animCycle) {
e->state = stand[e->dir];
e->sequence = 0;
}
return;
default:
break;
}
// If the touchplate wait is on, keep it timing
if (e->touchpWait) {
e->touchpWait--;
if (!e->touchpWait)
e->touchpTile = -e->touchpTile;
} else if (e->touchpTile < 0 && (e->touchpX != e->tileX || e->touchpY != e->tileY)) {
g_hdb->_ai->checkActionList(e, e->touchpX, e->touchpY, false);
g_hdb->_map->setMapBGTileIndex(e->touchpX, e->touchpY, -e->touchpTile);
e->touchpX = e->touchpY = e->touchpTile = 0;
}
// If the player is moving somewhere, animate him
int bgFlags, fgFlags;
if (e->goalX) {
if (onEvenTile(e->x, e->y)) {
g_hdb->_ai->playerOnIce() ? g_hdb->_sound->playSound(SND_STEPS_ICE) : g_hdb->_sound->playSound(SND_FOOTSTEPS);
// Did we just fall down a PLUMMET?
bgFlags = g_hdb->_map->getMapBGTileFlags(e->tileX, e->tileY);
fgFlags = g_hdb->_map->getMapFGTileFlags(e->tileX, e->tileY);
if ((bgFlags & kFlagPlummet) && !(fgFlags & kFlagGrating) && !g_hdb->_ai->playerDead()) {
g_hdb->_ai->killPlayer(DEATH_PLUMMET);
g_hdb->_ai->animEntFrames(e);
return;
}
}
g_hdb->_ai->animateEntity(e);
} else {
// Sometimes the fading stays black
if (!g_hdb->_ai->cinematicsActive() && g_hdb->_gfx->isFadeStaying())
g_hdb->_gfx->turnOffFade();
// Did we just fall down a PLUMMET?
bgFlags = g_hdb->_map->getMapBGTileFlags(e->tileX, e->tileY);
fgFlags = g_hdb->_map->getMapFGTileFlags(e->tileX, e->tileY);
if ((bgFlags & kFlagPlummet) && !(fgFlags & kFlagGrating) && !g_hdb->_ai->playerDead()) {
g_hdb->_ai->killPlayer(DEATH_PLUMMET);
g_hdb->_ai->animEntFrames(e);
return;
}
// Standing on a TouchPlate will activate something WHILE standing on it
int bgTile = g_hdb->_ai->checkForTouchplate(e->tileX, e->tileY);
if (bgTile && !e->touchpWait && !e->touchpTile) {
if (g_hdb->_ai->checkActionList(e, e->tileX, e->tileY, false)) {
e->touchpTile = bgTile;
e->touchpX = e->tileX;
e->touchpY = e->tileY;
e->touchpWait = kPlayerTouchPWait;
g_hdb->_ai->stopEntity(e);
}
}
g_hdb->_ai->animEntFrames(e);
}
}
void aiPlayerDraw(AIEntity *e, int mx, int my) {
switch (e->state) {
case STATE_ATK_CLUB_UP:
g_hdb->_ai->_clubUpGfx[e->animFrame]->drawMasked(e->x + e->drawXOff - mx, e->y + e->drawYOff - my);
break;
case STATE_ATK_CLUB_DOWN:
g_hdb->_ai->_clubDownGfx[e->animFrame]->drawMasked(e->x + e->drawXOff - mx, e->y + e->drawYOff - my);
break;
case STATE_ATK_CLUB_LEFT:
g_hdb->_ai->_clubLeftGfx[e->animFrame]->drawMasked(e->x + e->drawXOff - mx, e->y + e->drawYOff - my);
break;
case STATE_ATK_CLUB_RIGHT:
g_hdb->_ai->_clubRightGfx[e->animFrame]->drawMasked(e->x + e->drawXOff - mx, e->y + e->drawYOff - my);
break;
default:
break;
}
if (e->sequence) {
static int frame = 0;
switch (e->dir) {
case DIR_UP:
g_hdb->_ai->_stunLightningGfx[frame]->drawMasked(e->x - mx, e->y - 32 - my);
g_hdb->_ai->_stunLightningGfx[frame]->drawMasked(e->x - mx, e->y - 64 - my);
break;
case DIR_DOWN:
g_hdb->_ai->_stunLightningGfx[frame]->drawMasked(e->x - mx, e->y + 32 - my);
g_hdb->_ai->_stunLightningGfx[frame]->drawMasked(e->x - mx, e->y + 64 - my);
break;
case DIR_LEFT:
g_hdb->_ai->_stunLightningGfx[frame]->drawMasked(e->x - 32 - mx, e->y - my);
g_hdb->_ai->_stunLightningGfx[frame]->drawMasked(e->x - 64 - mx, e->y - my);
break;
case DIR_RIGHT:
g_hdb->_ai->_stunLightningGfx[frame]->drawMasked(e->x + 32 - mx, e->y - my);
g_hdb->_ai->_stunLightningGfx[frame]->drawMasked(e->x + 64 - mx, e->y - my);
break;
case DIR_NONE:
default:
break;
}
frame = (frame + 1) & 3;
}
}
void aiGemAttackInit(AIEntity *e, int mx, int my) {
static const int xv[5] = {9, 0, 0, -1, 1};
static const int yv[5] = {9, -1, 1, 0, 0};
e->moveSpeed = kPlayerMoveSpeed << 1;
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
e->state = STATE_MOVEDOWN; // so it will draw & animate
e->sequence = 0; // flying out at something
e->aiAction = aiGemAttackAction;
e->draw = e->movedownGfx[0];
g_hdb->_sound->playSound(SND_GEM_THROW);
}
void aiGemAttackAction(AIEntity *e, int mx, int my) {
static const int xv[5] = {9, 0, 0, -1, 1};
static const int yv[5] = {9, -1, 1, 0, 0};
switch (e->sequence) {
// flying out at something
case 0:
if (e->goalX)
g_hdb->_ai->animateEntity(e);
else {
g_hdb->_ai->checkActionList(e, e->tileX, e->tileY, false);
g_hdb->_ai->checkAutoList(e, e->tileX, e->tileY);
AIEntity *hit = g_hdb->_ai->findEntityIgnore(e->tileX, e->tileY, e);
uint32 bgFlags = g_hdb->_map->getMapBGTileFlags(e->tileX, e->tileY);
uint32 fgFlags = g_hdb->_map->getMapFGTileFlags(e->tileX, e->tileY);
int result = (e->level == 1 ? (bgFlags & (kFlagSolid)) : !(fgFlags & kFlagGrating) && (bgFlags & (kFlagSolid)));
if (hit) {
switch (hit->type) {
case AI_CHICKEN:
g_hdb->_ai->addAnimateTarget(hit->x, hit->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->removeEntity(hit);
g_hdb->_sound->playSound(SND_CHICKEN_BAGAWK);
break;
case AI_BADFAIRY:
g_hdb->_ai->stunEnemy(hit, 2);
g_hdb->_ai->addAnimateTarget(hit->x, hit->y, 0, 3, ANIM_NORMAL, false, false, GEM_FLASH);
break;
case AI_NONE:
if (hit->value1 == (int)AI_DRAGON) {
// pull dragon's coords out of "lua_func_use" string.
char num1[4], num2[4];
memset(num1, 0, 4);
memset(num2, 0, 4);
memcpy(num1, hit->luaFuncUse, 3);
memcpy(num2, hit->luaFuncUse + 3, 3);
g_hdb->_sound->playSound(SND_CLUB_HIT_FLESH);
AIEntity *found = g_hdb->_ai->findEntity(atoi(num1), atoi(num2));
if (found)
aiDragonWake(found, 0, 0);
}
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_NORMAL, false, false, GEM_FLASH);
g_hdb->_sound->playSound(SND_INV_SELECT);
break;
case AI_DRAGON:
g_hdb->_sound->playSound(SND_CLUB_HIT_FLESH);
aiDragonWake(hit, 0, 0);
// fallthrough
default:
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_NORMAL, false, false, GEM_FLASH);
g_hdb->_sound->playSound(SND_CLUB_HIT_FLESH);
}
if (e->value1)
e->sequence = 1;
else
g_hdb->_ai->removeEntity(e); // bye bye!
return;
} else if (result) { // hit a wall
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_NORMAL, false, false, GEM_FLASH);
g_hdb->_sound->playSound(SND_INV_SELECT);
// come back to daddy?
if (e->value1)
e->sequence = 1;
else {
g_hdb->_ai->removeEntity(e);
return;
}
} else {
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
e->state = STATE_MOVEDOWN; // so it will draw & animate
}
g_hdb->_ai->animateEntity(e);
}
break;
// coming back to daddy?
case 1:
{
AIEntity *p = g_hdb->_ai->getPlayer();
if (e->x < p->x)
e->x++;
else
e->x--;
if (e->y < p->y)
e->y++;
else
e->y--;
if (abs(e->x - p->x) < 4 && abs(e->y - p->y) < 4)
{
int amt = g_hdb->_ai->getGemAmount();
g_hdb->_ai->setGemAmount(amt + 1);
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_NORMAL, false, false, GEM_FLASH);
g_hdb->_ai->removeEntity(e);
g_hdb->_sound->playSound(SND_GET_GEM);
}
}
break;
default:
break;
}
}
void aiChickenAction(AIEntity *e, int mx, int my) {
static int delay = 64;
if (g_hdb->_map->checkEntOnScreen(e) && !delay) {
g_hdb->_sound->playSound(SND_CHICKEN_AMBIENT);
delay = g_hdb->_rnd->getRandomNumber(127) + 160;
aiChickenUse(e, 0, 0);
}
if (delay)
delay--;
if (e->goalX)
g_hdb->_ai->animateEntity(e);
else
g_hdb->_ai->animEntFrames(e);
}
void aiChickenUse(AIEntity *e, int mx, int my) {
g_hdb->_sound->playSound(SND_CHICKEN_BAGAWK);
}
void aiChickenInit(AIEntity *e, int mx, int my) {
e->aiUse = aiChickenUse;
e->aiAction = aiChickenAction;
}
void aiChickenInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiDollyInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPlayerMoveSpeed >> 1;
e->aiAction = aiGenericAction;
}
void aiDollyInit2(AIEntity *e, int mx, int my) {
e->draw = e->movedownGfx[0];
}
void aiSergeantInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPlayerMoveSpeed >> 1;
if (e->value1)
e->aiAction = aiSergeantAction;
}
void aiSergeantInit2(AIEntity *e, int mx, int my) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiSergeantAction(AIEntity *e, int mx, int my) {
if (e->goalX) {
g_hdb->_sound->playSound(SND_FOOTSTEPS);
g_hdb->_ai->animateEntity(e);
} else
g_hdb->_ai->animEntFrames(e);
}
void aiSpacedudeInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPlayerMoveSpeed >> 1;
if (e->value1)
e->aiAction = aiGenericAction;
}
void aiSpacedudeInit2(AIEntity *e, int mx, int my) {
e->standdownFrames = 1;
e->standdownGfx[0] = e->movedownGfx[0];
e->standupFrames = 1;
e->standupGfx[0] = e->moveupGfx[0];
e->standleftFrames = 1;
e->standleftGfx[0] = e->moveleftGfx[0];
e->standrightFrames = 1;
e->standrightGfx[0] = e->moverightGfx[0];
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiCrateAction(AIEntity *e, int mx, int my) {
// if crate isn't moving somewhere, don't move it
if (!e->goalX) {
// crate is stopped in the water... should it continue downstream?
// not if it's marked by the Number of the Beast!
if (e->state == STATE_FLOATING) {
if (e->value1 != 0x666) {
int flags = g_hdb->_map->getMapBGTileFlags(e->tileX, e->tileY);
if (flags & (kFlagPushRight | kFlagPushLeft | kFlagPushUp | kFlagPushDown)) {
g_hdb->_ai->setEntityGoal(e, e->tileX, e->tileY);
g_hdb->_ai->animateEntity(e);
} else
g_hdb->_ai->animEntFrames(e);
} else
g_hdb->_ai->animEntFrames(e);
}
return;
}
g_hdb->_ai->animateEntity(e);
}
void aiCrateInit2(AIEntity *e, int mx, int my) {
// point all crate move frames to the standing one
e->movedownFrames =
e->moveleftFrames =
e->moverightFrames =
e->moveupFrames = 1;
e->movedownGfx[0] =
e->moveupGfx[0] =
e->moveleftGfx[0] =
e->moverightGfx[0] = e->standdownGfx[0];
e->draw = e->standdownGfx[0]; // standing frame - doesn't move
}
void aiCrateInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPushMoveSpeed;
e->aiAction = aiCrateAction;
e->value1 = 0;
}
void aiBarrelLightAction(AIEntity *e, int mx, int my) {
if (!e->goalX) {
if (e->state == STATE_FLOATING)
g_hdb->_ai->animEntFrames(e);
return;
}
g_hdb->_ai->animateEntity(e);
}
void aiBarrelLightInit2(AIEntity *e, int mx, int my) {
// point all light barrel move frames to the standing one
e->movedownFrames =
e->moveleftFrames =
e->moverightFrames =
e->moveupFrames = 1;
e->movedownGfx[0] =
e->moveupGfx[0] =
e->moveleftGfx[0] =
e->moverightGfx[0] = e->standdownGfx[0];
e->draw = e->standdownGfx[0]; // standing frame - doesn't move
}
void aiBarrelLightInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPushMoveSpeed;
e->aiAction = aiBarrelLightAction;
}
void aiBarrelHeavyAction(AIEntity *e, int mx, int my) {
if (!e->goalX) {
if (e->state == STATE_FLOATING)
g_hdb->_ai->animEntFrames(e);
return;
}
g_hdb->_ai->animateEntity(e);
}
void aiBarrelHeavyInit2(AIEntity *e, int mx, int my) {
// point all heavy barrel move frames to the standing one
e->movedownFrames =
e->moveleftFrames =
e->moverightFrames =
e->moveupFrames = 1;
e->movedownGfx[0] =
e->moveupGfx[0] =
e->moveleftGfx[0] =
e->moverightGfx[0] = e->standdownGfx[0];
e->draw = e->standdownGfx[0]; // standing frame - doesn't move
}
void aiBarrelHeavyInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPushMoveSpeed;
e->aiAction = aiBarrelHeavyAction;
}
void aiBarrelExplode(AIEntity *e, int mx, int my) {
e->state = STATE_EXPLODING;
e->animDelay = e->animCycle;
e->animFrame = 0;
if (!g_hdb->isDemo())
g_hdb->_sound->playSound(SND_BARREL_EXPLODE);
g_hdb->_map->setBoomBarrel(e->tileX, e->tileY, 0);
}
void aiBarrelExplodeInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPushMoveSpeed;
e->aiAction = aiBarrelExplodeAction;
g_hdb->_map->setBoomBarrel(e->tileX, e->tileY, 1);
}
void aiBarrelExplodeInit2(AIEntity *e, int mx, int my) {
// point all exploding barrel MOVE frames to the standing one
e->blinkFrames =
e->movedownFrames =
e->moveleftFrames =
e->moverightFrames =
e->moveupFrames = 1;
e->blinkGfx[0] =
e->movedownGfx[0] =
e->moveupGfx[0] =
e->moveleftGfx[0] =
e->moverightGfx[0] = e->standdownGfx[0];
e->draw = e->standdownGfx[0]; // standing frame - doesn't move
}
void aiBarrelExplodeAction(AIEntity *e, int mx, int my) {
if (e->goalX)
g_hdb->_ai->animateEntity(e);
else if (e->state == STATE_EXPLODING)
g_hdb->_ai->animEntFrames(e);
}
void aiBarrelExplodeSpread(AIEntity *e, int mx, int my) {
static const int xv1[4] = {-1, 1, -1, 0};
static const int yv1[4] = {-1, -1, 0, -1};
static const int xv2[4] = {1, 0, 1, -1};
static const int yv2[4] = {0, 1, 1, 1};
int x = e->tileX;
int y = e->tileY;
int index = e->animFrame;
// are we just starting an explosion ring?
if (e->animDelay != e->animCycle)
return;
// the animation frame is the index into which set of 2 explosions to spawn
int xv = xv1[index];
int yv = yv1[index];
// explosion 1: check to see if we can explode (non-solid tile)
// if so, spawn it and mark it in the explosion matrix
if (!(g_hdb->_map->getMapBGTileFlags(x + xv, y + yv) & kFlagSolid) && !g_hdb->_map->explosionExist(x + xv, y + yv)) {
aiBarrelBlowup(e, x + xv, y + yv);
// are we blowing up on another BOOMBARREL? if so, start it exploding.
AIEntity *e2 = g_hdb->_ai->findEntity(x + xv, y + yv);
if (e2 && e2->state != STATE_EXPLODING) {
switch (e2->type) {
case AI_GUY:
g_hdb->_ai->killPlayer(DEATH_FRIED);
break;
case AI_BOOMBARREL:
aiBarrelExplode(e2, 0, 0);
break;
case AI_OMNIBOT:
case AI_TURNBOT:
case AI_SHOCKBOT:
case AI_RIGHTBOT:
case AI_PUSHBOT:
case AI_RAILRIDER:
case AI_MAINTBOT:
case AI_DEADEYE:
case AI_FATFROG:
case AI_ICEPUFF:
case AI_MEERKAT:
case AI_BUZZFLY:
case AI_GOODFAIRY:
case AI_GATEPUDDLE:
case AI_BADFAIRY:
g_hdb->_ai->addAnimateTarget(x * kTileWidth,
y * kTileHeight, 0, 3, ANIM_NORMAL, false, false, GROUP_EXPLOSION_BOOM_SIT);
if (e2->type != AI_LASERBEAM)
g_hdb->_ai->removeEntity(e2);
break;
default:
break;
}
}
}
xv = xv2[index];
yv = yv2[index];
// explosion 2: check to see if we can explode (non-solid tile)
// if so, spawn it and mark it in the explosion matrix
if (!(g_hdb->_map->getMapBGTileFlags(x + xv, y + yv) & kFlagSolid) && !g_hdb->_map->explosionExist(x + xv, y + yv)) {
aiBarrelBlowup(e, x + xv, y + yv);
// are we blowing up on another BOOMBARREL? if so, start it exploding.
AIEntity *e2 = g_hdb->_ai->findEntity(x + xv, y + yv);
if (e2 && e2->state != STATE_EXPLODING) {
switch (e2->type) {
case AI_GUY:
g_hdb->_ai->killPlayer(DEATH_FRIED);
break;
case AI_BOOMBARREL:
aiBarrelExplode(e2, 0, 0);
break;
case AI_OMNIBOT:
case AI_TURNBOT:
case AI_SHOCKBOT:
case AI_RIGHTBOT:
case AI_PUSHBOT:
case AI_RAILRIDER:
case AI_MAINTBOT:
case AI_DEADEYE:
case AI_FATFROG:
case AI_ICEPUFF:
case AI_MEERKAT:
case AI_BUZZFLY:
case AI_GOODFAIRY:
case AI_GATEPUDDLE:
case AI_BADFAIRY:
g_hdb->_ai->addAnimateTarget(x * kTileWidth,
y * kTileHeight, 0, 3, ANIM_NORMAL, false, false, GROUP_EXPLOSION_BOOM_SIT);
if (e2->type != AI_LASERBEAM)
g_hdb->_ai->removeEntity(e2);
break;
default:
break;
}
}
}
}
void callbackAiBarrelExplosionEnd(int x, int y) {
g_hdb->_map->setExplosion(x, y, 0);
}
void aiBarrelBlowup(AIEntity *e, int x, int y) {
g_hdb->_ai->addAnimateTarget(x * kTileWidth,
y * kTileHeight, 0, 3, ANIM_NORMAL, false, false, GROUP_EXPLOSION_BOOM_SIT);
g_hdb->_map->setExplosion(x, y, 1);
g_hdb->_ai->addCallback(AI_BARREL_EXPLOSION_END, x, y, e->animCycle * 4);
}
void aiScientistInit(AIEntity *e, int x, int y) {
e->moveSpeed = kPlayerMoveSpeed >> 1;
if (g_hdb->_ai->findPath(e))
e->aiAction = aiGenericAction;
else if (e->value1)
e->aiAction = aiGenericAction;
}
void aiScientistInit2(AIEntity *e, int x, int y) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiSlugAttackAction(AIEntity *e, int x, int y) {
static const int xv[5] = {9, 0, 0, -1, 1};
static const int yv[5] = {9, -1, 1, 0, 0};
if (e->goalX)
g_hdb->_ai->animateEntity(e);
g_hdb->_ai->checkActionList(e, e->tileX, e->tileY, false);
g_hdb->_ai->checkAutoList(e, e->tileX, e->tileY);
AIEntity *hit = g_hdb->_ai->findEntityIgnore(e->tileX, e->tileY, e);
if (hit && hit->type == AI_GUY)
hit = nullptr;
// don't hit anything you can walk through...
if (hit && true == g_hdb->_ai->getTableEnt(hit->type))
hit = nullptr;
// don't hit floating stuff
if (hit && hit->state == STATE_FLOATING)
hit = nullptr;
uint32 bg_flags = g_hdb->_map->getMapBGTileFlags(e->tileX, e->tileY);
uint32 fg_flags = g_hdb->_map->getMapFGTileFlags(e->tileX, e->tileY);
int result = (e->level == 1 ? (bg_flags & (kFlagSolid)) : !(fg_flags & kFlagGrating) && (bg_flags & (kFlagSolid)));
if (hit) {
g_hdb->_sound->playSound(SND_SLUG_HIT);
g_hdb->_sound->playSound(g_hdb->_ai->metalOrFleshSND(hit));
switch (hit->type) {
case AI_MEERKAT:
if (hit->sequence > 2) { // out of the ground?
g_hdb->_ai->addAnimateTarget(hit->x, hit->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->stunEnemy(hit, 8);
} else {
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
e->state = STATE_MOVEDOWN; // so it will draw & animate
g_hdb->_ai->animateEntity(e);
return;
}
break;
case AI_ICEPUFF:
if (hit->state == STATE_ICEP_APPEAR ||
hit->state == STATE_ICEP_THROWDOWN ||
hit->state == STATE_ICEP_THROWLEFT ||
hit->state == STATE_ICEP_THROWRIGHT) {
g_hdb->_ai->addAnimateTarget(hit->x, hit->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->stunEnemy(hit, 8);
} else {
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
e->state = STATE_MOVEDOWN; // so it will draw & animate
g_hdb->_ai->animateEntity(e);
return;
}
break;
case AI_OMNIBOT:
case AI_TURNBOT:
case AI_SHOCKBOT:
case AI_RIGHTBOT:
case AI_PUSHBOT:
case AI_LISTENBOT:
case AI_MAINTBOT:
case AI_FATFROG:
case AI_BADFAIRY:
case AI_BUZZFLY:
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->stunEnemy(hit, 8);
break;
case AI_CHICKEN:
g_hdb->_ai->addAnimateTarget(hit->x, hit->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->removeEntity(hit);
break;
case AI_BOOMBARREL:
g_hdb->_sound->playSound(SND_CLUB_HIT_METAL);
aiBarrelExplode(hit, 0, 0);
aiBarrelBlowup(hit, hit->tileX, hit->tileY);
break;
// ACTION MODE entities go away - except the FOURFIRER
case AI_GATEPUDDLE:
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 7, ANIM_NORMAL, false, false, TELEPORT_FLASH);
g_hdb->_ai->removeEntity(hit);
g_hdb->_sound->playSound(SND_TELEPORT);
break;
case AI_DEADEYE:
g_hdb->_ai->addAnimateTarget(e->tileX * kTileWidth,
e->tileY * kTileHeight, 0, 3, ANIM_NORMAL, false, false, GROUP_EXPLOSION_BOOM_SIT);
g_hdb->_ai->removeEntity(hit);
g_hdb->_sound->playSound(SND_BARREL_EXPLODE);
break;
case AI_NONE:
if (hit->value1 == (int)AI_DRAGON) {
// pull dragon's coords out of "lua_func_use" string.
char num1[4], num2[4];
memset(num1, 0, 4);
memset(num2, 0, 4);
memcpy(num1, hit->luaFuncUse, 3);
memcpy(num2, hit->luaFuncUse + 3, 3);
g_hdb->_sound->playSound(SND_CLUB_HIT_FLESH);
AIEntity *found = g_hdb->_ai->findEntity(atoi(num1), atoi(num2));
if (found)
aiDragonWake(found, 0, 0);
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_NORMAL, false, false, GEM_FLASH);
}
break;
case AI_DRAGON:
aiDragonWake(hit, 0, 0);
break;
default:
break;
}
g_hdb->_ai->removeEntity(e); // bye bye!
return;
} else if (result) { // hit a wall
g_hdb->_sound->playSound(SND_SLUG_HIT);
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_NORMAL, false, false, GROUP_STEAM_PUFF_SIT);
g_hdb->_ai->removeEntity(e);
} else {
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
e->state = STATE_MOVEDOWN; // so it will draw & animate
g_hdb->_ai->animateEntity(e);
}
}
void aiSlugAttackDraw(AIEntity *e, int mx, int my) {
g_hdb->_ai->_slugAttackGfx[e->animFrame]->drawMasked(e->x - mx + 8, e->y - my + 8);
}
void aiSlugAttackInit(AIEntity *e, int mx, int my) {
static const int xv[5] = {9, 0, 0, -1, 1};
static const int yv[5] = {9, -1, 1, 0, 0};
if (g_hdb->isDemo())
return;
e->moveSpeed = kPlayerMoveSpeed << 1;
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
e->draw = nullptr; // use custom draw function
e->aiDraw = aiSlugAttackDraw;
e->state = STATE_MOVEDOWN; // so it will draw & animate
e->aiAction = aiSlugAttackAction;
g_hdb->_sound->playSound(SND_SLUG_FIRE);
}
void aiSlugAttackInit2(AIEntity *e, int mx, int my) {
e->movedownFrames = 4;
}
void aiDeadWorkerInit(AIEntity *e, int mx, int my) {
}
void aiDeadWorkerInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiWorkerInit(AIEntity *e, int mx, int my) {
if (e->value1)
e->aiAction = aiGenericAction;
e->moveSpeed = kPlayerMoveSpeed >> 1;
}
void aiWorkerInit2(AIEntity *e, int mx, int my) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiAccountantInit(AIEntity *e, int mx, int my) {
}
void aiAccountantInit2(AIEntity *e, int mx, int my) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiFrogStatueInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPushMoveSpeed;
e->aiAction = aiFrogStatueAction;
}
void aiFrogStatueInit2(AIEntity *e, int mx, int my) {
// point all frog statue MOVE frames to the standing one
e->blinkFrames =
e->movedownFrames =
e->moveleftFrames =
e->moverightFrames =
e->moveupFrames = 1;
e->blinkGfx[0] =
e->movedownGfx[0] =
e->moveupGfx[0] =
e->moveleftGfx[0] =
e->moverightGfx[0] = e->standdownGfx[0];
e->draw = e->standdownGfx[0]; // standing frame - doesn't move
}
void aiFrogStatueAction(AIEntity *e, int mx, int my) {
// if frog statue isn't moving somewhere, don't move it
if (!e->goalX)
return;
g_hdb->_ai->animateEntity(e);
}
void aiRoboStunnerAction(AIEntity *e, int mx, int my) {
aiAnimateStanddown(e, 1);
aiGetItemAction(e, 0, 0);
}
void aiRoboStunnerInit(AIEntity *e, int mx, int my) {
e->aiAction = aiRoboStunnerAction;
Common::strlcpy(e->printedName, "Robostunner", 32);
}
void aiRoboStunnerInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiClubInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Creature Clubber", 32);
e->aiAction = aiGetItemAction;
}
void aiClubInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiSlugSlingerInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Slugslinger", 32);
e->aiAction = aiGetItemAction;
}
void aiSlugSlingerInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiEnvelopeGreenInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Green envelope", 32);
e->aiAction = aiGetItemAction;
}
void aiEnvelopeGreenInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiGemBlueInit(AIEntity *e, int mx, int my) {
e->aiAction = aiGemAction;
}
void aiGemBlueInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiGemRedInit(AIEntity *e, int mx, int my) {
e->aiAction = aiGemAction;
}
void aiGemRedInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiGemGreenInit(AIEntity *e, int mx, int my) {
e->aiAction = aiGemAction;
}
void aiGemGreenInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiTeaCupInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Teacup", 32);
e->aiAction = aiGetItemAction;
}
void aiTeaCupInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiCookieInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Cookie", 32);
e->aiAction = aiGetItemAction;
}
void aiCookieInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiBurgerInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Burger", 32);
e->aiAction = aiGetItemAction;
}
void aiBurgerInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiBookInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Book", 32);
e->aiAction = aiGetItemAction;
}
void aiBookInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiClipboardInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Clipboard", 32);
e->aiAction = aiGetItemAction;
}
void aiClipboardInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiNoteInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Note", 32);
e->aiAction = aiGetItemAction;
}
void aiNoteInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiKeycardWhiteInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a White keycard", 32);
e->aiAction = aiGetItemAction;
}
void aiKeycardWhiteInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiKeycardBlueInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Blue keycard", 32);
e->aiAction = aiGetItemAction;
}
void aiKeycardBlueInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiKeycardRedInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Red keycard", 32);
e->aiAction = aiGetItemAction;
}
void aiKeycardRedInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiKeycardGreenInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Green keycard", 32);
e->aiAction = aiGetItemAction;
}
void aiKeycardGreenInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiKeycardPurpleInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Purple keycard", 32);
e->aiAction = aiGetItemAction;
}
void aiKeycardPurpleInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiKeycardBlackInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Black keycard", 32);
e->aiAction = aiGetItemAction;
}
void aiKeycardBlackInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiSeedInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "some Henscratch", 32);
e->aiAction = aiGetItemAction;
}
void aiSeedInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiSodaInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Dr. Frostee", 32);
e->aiAction = aiGetItemAction;
}
void aiSodaInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiDollyTool1Init(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Dolly's Wrench", 32);
e->aiAction = aiGetItemAction;
}
void aiDollyTool1Init2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiDollyTool2Init(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Dolly's Torch", 32);
e->aiAction = aiGetItemAction;
}
void aiDollyTool2Init2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiDollyTool3Init(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Dolly's EMF Resonator", 32);
e->aiAction = aiGetItemAction;
}
void aiDollyTool3Init2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiDollyTool4Init(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Dolly's Toolbox", 32);
e->aiAction = aiGetItemAction;
}
void aiDollyTool4Init2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiRouterInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Computer Router", 32);
e->aiAction = aiGetItemAction;
}
void aiRouterInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiSlicerInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Pizza Slicer", 32);
e->aiAction = aiGetItemAction;
}
void aiSlicerInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiPackageInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Package", 32);
e->aiAction = aiGetItemAction;
}
void aiPackageInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiMagicEggAction(AIEntity *e, int mx, int my) {
// if magic egg isn't moving somewhere, don't move it
if (!e->goalX)
return;
g_hdb->_ai->animateEntity(e);
}
void aiMagicEggInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPushMoveSpeed;
e->aiAction = aiMagicEggAction;
}
void aiMagicEggInit2(AIEntity *e, int mx, int my) {
// point all magic egg move frames to the standing one
e->movedownFrames =
e->moveleftFrames =
e->moverightFrames =
e->moveupFrames = 1;
e->movedownGfx[0] =
e->moveupGfx[0] =
e->moveleftGfx[0] =
e->moverightGfx[0] = e->standdownGfx[0];
e->draw = e->standdownGfx[0]; // standing frame - doesn't move
}
void aiMagicEggUse(AIEntity *e, int mx, int my) {
if (!scumm_strnicmp(e->luaFuncAction, "ai_", 3) || !scumm_strnicmp(e->luaFuncAction, "item_", 5)) {
AIEntity *spawned = nullptr;
for (int i = 0; aiEntList[i].type != END_AI_TYPES; ++i) {
if (!scumm_stricmp(aiEntList[i].luaName, e->luaFuncAction)) {
spawned = g_hdb->_ai->spawn(aiEntList[i].type, e->dir, e->tileX, e->tileY, nullptr, nullptr, nullptr, DIR_NONE, e->level, 0, 0, 1);
break;
}
}
if (spawned) {
g_hdb->_ai->addAnimateTarget(e->tileX * kTileWidth,
e->tileY * kTileHeight, 0, 3, ANIM_NORMAL, false, false, GROUP_EXPLOSION_BOOM_SIT);
if (!g_hdb->isDemo())
g_hdb->_sound->playSound(SND_BARREL_EXPLODE);
g_hdb->_ai->removeEntity(e);
}
}
}
void aiIceBlockAction(AIEntity *e, int mx, int my) {
// if ice block isn't moving somewhere, don't move it
if (!e->goalX)
return;
g_hdb->_ai->animateEntity(e);
}
void aiIceBlockInit(AIEntity *e, int mx, int my) {
e->moveSpeed = kPushMoveSpeed;
e->aiAction = aiIceBlockAction;
}
void aiIceBlockInit2(AIEntity *e, int mx, int my) {
// point all ice block move frames to the standing one
e->movedownFrames =
e->moveleftFrames =
e->moverightFrames =
e->moveupFrames = 1;
e->movedownGfx[0] =
e->moveupGfx[0] =
e->moveleftGfx[0] =
e->moverightGfx[0] = e->standdownGfx[0];
e->draw = e->standdownGfx[0]; // standing frame - doesn't move
}
void aiCabKeyInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a Cabinet key", 32);
}
void aiCabKeyInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiItemChickenInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Cooper's chicken", 32);
}
void aiItemChickenInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiPdaInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "a P.D.A.", 32);
e->aiAction = aiGetItemAction;
}
void aiPdaInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
#if 0
void aiCellUse(AIEntity *e, int mx, int my) {
g_hdb->_window->openMessageBar("You got the Energy Cell!", kMsgDelay);
}
#endif
void aiCellInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiCellInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Energy Cell", 32);
e->aiAction = aiGetItemAction;
}
void aiEnvelopeWhiteInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "White envelope", 32);
e->aiAction = aiGetItemAction;
}
void aiEnvelopeWhiteInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiEnvelopeBlueInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Blue envelope", 32);
e->aiAction = aiGetItemAction;
}
void aiEnvelopeBlueInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiEnvelopeRedInit(AIEntity *e, int mx, int my) {
Common::strlcpy(e->printedName, "Red envelope", 32);
e->aiAction = aiGetItemAction;
}
void aiEnvelopeRedInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiTransceiverInit(AIEntity *e, int mx, int my) {
e->aiAction = aiTransceiverAction;
Common::strlcpy(e->printedName, "Transceiver", 32);
}
void aiTransceiverInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiTransceiverAction(AIEntity *e, int mx, int my) {
aiAnimateStanddown(e, 5);
if (e->onScreen)
aiGetItemAction(e, 0, 0);
}
#if 0
void aiTransceiverUse(AIEntity *e, int mx, int my) {
g_hdb->_window->openMessageBar("You got the Transceiver!", kMsgDelay);
}
#endif
void aiMonkeystoneInit(AIEntity *e, int mx, int my) {
e->aiUse = aiMonkeystoneUse;
e->aiAction = aiMonkeystoneAction;
}
void aiMonkeystoneAction(AIEntity *e, int mx, int my) {
if (!e->onScreen)
return;
AIEntity *p = g_hdb->_ai->getPlayer();
if (abs(p->x - e->x) < 16 && abs(p->y - e->y) < 16 && e->level == p->level) {
if (e->luaFuncUse[0])
g_hdb->_lua->callFunction(e->luaFuncUse, 0);
g_hdb->_ai->addToInventory(e);
aiMonkeystoneUse(nullptr, 0, 0);
}
}
void aiMonkeystoneInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiMonkeystoneUse(AIEntity *e, int mx, int my) {
int val = g_hdb->_ai->getMonkeystoneAmount();
Common::String monkString = Common::String::format("You have %d Monkeystone%s!", val, (val > 1) ? "s" : "");
g_hdb->_sound->playSound(SND_GET_MONKEYSTONE);
g_hdb->_window->openMessageBar(monkString.c_str(), kMsgDelay);
// have we unlocked a secret star(tm)???
if (val == 7) {
g_hdb->_window->openMessageBar("Red Star is Ready!", kMsgDelay * 2);
g_hdb->setStarsMonkeystone7(STARS_MONKEYSTONE_7);
g_hdb->_menu->writeConfig();
g_hdb->_gfx->turnOnBonusStars(0);
}
if (val == 14) {
g_hdb->_window->openMessageBar("Green Star is GO!", kMsgDelay * 2);
g_hdb->setStarsMonkeystone14(STARS_MONKEYSTONE_14);
g_hdb->_menu->writeConfig();
g_hdb->_gfx->turnOnBonusStars(1);
}
if (val == 21) {
g_hdb->_window->openMessageBar("Blue Star is Born!", kMsgDelay * 2);
g_hdb->setStarsMonkeystone21(STARS_MONKEYSTONE_21);
g_hdb->_menu->writeConfig();
g_hdb->_gfx->turnOnBonusStars(2);
}
}
void aiGemAction(AIEntity *e, int mx, int my) {
e->animFrame++;
if (e->animFrame >= e->standdownFrames) {
e->animFrame = 0;
// every 4th frame, check for player collision &
// add to inventory if it happens
AIEntity *p = g_hdb->_ai->getPlayer();
int tolerance = 16;
if (g_hdb->_ai->playerRunning())
tolerance = 24;
if (e->onScreen && abs(p->x - e->x) < tolerance && abs(p->y - e->y) < tolerance && e->level == p->level) {
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_NORMAL, false, false, GEM_FLASH);
g_hdb->_ai->addToInventory(e);
g_hdb->_sound->playSound(SND_GET_GEM);
return;
}
}
e->draw = e->standdownGfx[e->animFrame];
}
void aiGemWhiteInit(AIEntity *e, int mx, int my) {
e->aiAction = aiGemAction;
}
void aiGemWhiteInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiGooCupUse(AIEntity *e, int mx, int my) {
g_hdb->_window->openMessageBar("Got a... cup of goo.", kMsgDelay);
}
void aiGooCupInit(AIEntity *e, int mx, int my) {
e->aiUse = aiGooCupUse;
e->aiAction = aiGetItemAction;
}
void aiGooCupInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiVortexianAction(AIEntity *e, int mx, int my) {
// anim the alpha blending : down to 32, up to 180, back down...
e->value2 += e->value1;
if ((e->value2 & 0xff) > 128) {
e->value2 = (e->value2 & 0xff00) | 128;
e->value1 = -e->value1;
} else if ((e->value2 & 0xff) < 32) {
e->value2 = (e->value2 & 0xff00) | 32;
e->value1 = -e->value1;
}
// anim the shape
e->animFrame++;
if (e->animFrame >= e->standdownFrames) {
e->animFrame = 0;
// every 4th frame, check for player collision &
// do an autosave
AIEntity *p = g_hdb->_ai->getPlayer();
if (abs(p->x - e->x) < 4 && abs(p->y - e->y) < 4) {
if (!(e->value2 & 0xff00)) {
// let's make sure we don't autosave every frikken second!
e->value2 |= 0xff00;
g_hdb->saveWhenReady(kAutoSaveSlot);
g_hdb->_window->openMessageBar("Saving progress at Vortexian...", 1);
}
} else
e->value2 &= 0x00ff;
}
e->draw = e->standdownGfx[e->animFrame];
}
void aiVortexianUse(AIEntity *e, int mx, int my) {
}
void aiVortexianInit(AIEntity *e, int mx, int my) {
e->aiUse = aiVortexianUse;
e->aiAction = aiVortexianAction;
e->value1 = 5;
e->value2 = 128;
}
void aiVortexianInit2(AIEntity *e, int mx, int my) {
e->draw = e->standdownGfx[0];
}
void aiNoneInit(AIEntity *e, int mx, int my) {
}
// Utility Functions
void aiAnimateStanddown(AIEntity *e, int speed) {
if (e->value2-- > 0)
return;
e->value2 = speed;
if (e->type == AI_GUY && e->animFrame > 0)
e->value2 = 0;
e->draw = e->standdownGfx[e->animFrame];
e->animFrame++;
if (e->animFrame >= e->standdownFrames)
e->animFrame = 0;
}
void aiGenericAction(AIEntity *e, int mx, int my) {
if (!e->goalX)
g_hdb->_ai->findPath(e);
else if (onEvenTile(e->x, e->y))
g_hdb->_sound->playSound(SND_FOOTSTEPS);
g_hdb->_ai->animateEntity(e);
}
void aiGetItemAction(AIEntity *e, int mx, int my) {
if (!e->onScreen)
return;
AIEntity *p = g_hdb->_ai->getPlayer();
if (abs(p->x - e->x) < 16 && abs(p->y - e->y) < 16 && e->level == p->level) {
if (e->aiUse)
e->aiUse(e, 0, 0);
if (e->luaFuncUse[0])
g_hdb->_lua->callFunction(e->luaFuncUse, 0);
g_hdb->_ai->getItemSound(e->type);
g_hdb->_ai->addToInventory(e);
}
}
} // End of Namespace
|