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
|
/* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "hdb/hdb.h"
namespace HDB {
void aiOmniBotInit(AIEntity *e) {
if (e->value1 == 1)
e->aiAction = aiOmniBotMove;
else if (g_hdb->_ai->findPath(e))
e->aiAction = aiOmniBotAction;
}
void aiOmniBotInit2(AIEntity *e) {
e->standdownGfx[0] = e->movedownGfx[0];
e->standupGfx[0] = e->movedownGfx[0];
e->standleftGfx[0] = e->moveleftGfx[0];
e->standrightGfx[0] = e->moverightGfx[0];
e->standdownFrames = e->standupFrames = e->standleftFrames = e->standrightFrames = 1;
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiOmniBotMove(AIEntity *e) {
if (e->goalX)
g_hdb->_ai->animateEntity(e);
else
g_hdb->_ai->animEntFrames(e);
}
void aiOmniBotAction(AIEntity *e) {
AIEntity *p = g_hdb->_ai->getPlayer();
if (e->goalX) {
if (!e->sequence) {
g_hdb->_ai->animateEntity(e);
// Is the Player collding?
if (hitPlayer(e->x, e->y) && (p->level == e->level)) {
g_hdb->_ai->killPlayer(DEATH_FRIED);
return;
}
// Shoot player ?
if (onEvenTile(e->x, e->y) && g_hdb->getActionMode()) {
int xv = 0, yv = 0, result;
int shoot = 0;
AIEntity *omni;
// FIXME: Is reloading Player required here?
p = g_hdb->_ai->getPlayer();
// On same level/screen?
if ((e->level != p->level) || g_hdb->_ai->playerDead() || !e->onScreen)
return;
// Is Player in Line of Sight?
switch (e->dir) {
case DIR_UP:
if (p->x == e->x && p->y < e->y) {
shoot = 1;
yv = -1;
}
break;
case DIR_DOWN:
if (p->x == e->x && p->y > e->y) {
shoot = 1;
yv = 1;
}
break;
case DIR_LEFT:
if (p->x < e->x && p->y == e->y) {
shoot = 1;
xv = -1;
}
break;
case DIR_RIGHT:
if (p->x > e->x && p->y == e->y) {
shoot = 1;
xv = 1;
}
break;
case DIR_NONE:
warning("aiOmniBotAction: DIR_NONE found");
break;
}
// If shoot = 1, take the shot
// (1) Check we're not shooting into a solid tile
// (2) Check we're not shooting into an Entity unless it's the player
AIEntity *hit = g_hdb->_ai->legalMoveOverWater(e->tileX+xv, e->tileY + yv, e->level, &result);
if (shoot && !hit && result) {
omni = g_hdb->_ai->spawn(AI_OMNIBOT_MISSILE, e->dir, e->tileX + xv, e->tileY + yv, NULL, NULL, NULL, DIR_NONE, e->level, 0, 0, 1);
omni->xVel = xv * kPlayerMoveSpeed * 2;
omni->yVel = yv * kPlayerMoveSpeed * 2;
if (g_hdb->_map->onScreen(e->tileX, e->tileY))
warning("STUB: aiOmniBotAction: Play SND_OMNIBOT_FIRE");
if (!g_hdb->getActionMode()) {
omni->xVel >>= 1;
omni->yVel >>= 1;
}
e->sequence = 16;
}
}
}
} else {
g_hdb->_ai->findPath(e);
if (e->onScreen)
warning("STUB: aiOmniBotAction: Play SND_OMNIBOT_AMBIENT");
}
if (e->sequence)
e->sequence--;
}
void aiOmniBotMissileInit(AIEntity *e) {
e->state = STATE_MOVEDOWN;
e->aiAction = aiOmniBotMissileAction;
}
void aiOmniBotMissileInit2(AIEntity *e) {
for (int i = 0; i < e->movedownFrames; i++)
e->moveleftGfx[i] = e->moverightGfx[i] = e->moveupGfx[i] = e->movedownGfx[i];
e->moveleftFrames = e->moverightFrames = e->moveupFrames = e->movedownFrames;
e->draw = e->movedownGfx[0];
}
void aiOmniBotMissileAction(AIEntity *e) {
AIEntity *p = g_hdb->_ai->getPlayer();
g_hdb->_ai->animEntFrames(e);
e->x += e->xVel;
e->y += e->yVel;
e->tileX = e->x / kTileWidth;
e->tileY = e->y / kTileHeight;
// Did we hit a solid wall?
int result;
AIEntity *hit = g_hdb->_ai->legalMoveOverWaterIgnore(e->tileX, e->tileY, e->level, &result, e);
if (hit || !result) {
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_FAST, false, false, "steam_puff_sit");
g_hdb->_ai->removeEntity(e);
}
// On Even tiles, check for hitting player
if (onEvenTile(e->x, e->y))
if (hitPlayer(e->x, e->y) && (p->level == e->level)) {
g_hdb->_ai->killPlayer(DEATH_NORMAL);
g_hdb->_ai->addAnimateTarget(e->x, e->y, 0, 3, ANIM_FAST, false, false, "steam_puff_sit");
g_hdb->_ai->removeEntity(e);
}
}
void aiTurnBotInit(AIEntity *e) {
e->aiAction = aiTurnBotAction;
}
void aiTurnBotInit2(AIEntity *e) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiTurnBotChoose(AIEntity *e) {
int xvAhead[5] = { 9, 0, 0, -1, 1 }, yvAhead[5] = { 9, -1, 1, 0, 0 };
AIDir turnRight[5] = { DIR_NONE, DIR_RIGHT, DIR_LEFT, DIR_UP, DIR_DOWN };
AIState dirState[5] = { STATE_NONE, STATE_MOVEUP, STATE_MOVEDOWN, STATE_MOVELEFT, STATE_MOVERIGHT };
int xv, yv;
xv = xvAhead[e->dir];
yv = yvAhead[e->dir];
if (g_hdb->_map->getMapBGTileFlags(e->tileX + xv, e->tileY + yv) & (kFlagSolid | kFlagWater)) {
e->xVel = e->yVel = 0;
e->animFrame = 0;
e->animDelay = e->animCycle;
e->dir = turnRight[e->dir];
e->state = dirState[e->dir];
} else {
e->xVel = xv * kPlayerMoveSpeed;
e->yVel = yv * kPlayerMoveSpeed;
if (!g_hdb->getActionMode()) {
e->xVel >>= 1;
e->yVel >>= 1;
}
e->goalX = e->tileX + xv;
e->goalY = e->tileY + yv;
e->state = dirState[e->dir];
if (e->dir == DIR_DOWN)
e->animFrame = 3;
}
}
void aiTurnBotAction(AIEntity *e) {
if (e->goalX)
g_hdb->_ai->animateEntity(e);
else {
aiTurnBotChoose(e);
g_hdb->_ai->animateEntity(e);
if (e->onScreen)
warning("STUB: aiTurnBotAction: Play SND_TURNBOT_TURN");
}
if (e->onScreen && onEvenTile(e->x, e->y) && g_hdb->_ai->checkPlayerCollision(e->x, e->y, 0) && !g_hdb->_ai->playerDead())
g_hdb->_ai->killPlayer(DEATH_NORMAL);
}
void aiShockBotInit(AIEntity *e) {
g_hdb->_ai->findPath(e);
e->aiAction = aiShockBotAction;
e->animCycle = 0;
e->sequence = 0;
e->aiDraw = aiShockBotShock;
}
void aiShockBotInit2(AIEntity *e) {
e->standupFrames = e->standdownFrames = e->standleftFrames = e->standrightFrames =
e->moveupFrames = e->moverightFrames = e->moveleftFrames = e->movedownFrames;
for (int i = 0; i < e->movedownFrames; i++)
e->standupGfx[i] = e->standleftGfx[i] = e->standrightGfx[i] = e->standdownGfx[i] = e->moveupGfx[i] = e->moveleftGfx[i] = e->moverightGfx[i] = e->movedownGfx[i];
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiShockBotAction(AIEntity *e) {
if (e->goalX) {
if (!e->sequence) {
if (hitPlayer(e->x, e->y))
g_hdb->_ai->killPlayer(DEATH_SHOCKED);
g_hdb->_ai->animateEntity(e);
} else
g_hdb->_ai->animEntFrames(e);
} else {
g_hdb->_ai->findPath(e);
e->sequence = 20;
g_hdb->_ai->animEntFrames(e);
if (e->onScreen)
warning("STUB: aiShockBotAction: Play SND_SHOCKBOT_AMBIENT");
}
if (e->sequence)
e->sequence--;
}
void aiShockBotShock(AIEntity *e, int mx, int my) {
int offX[8] = { -1, 0, 1, 1, 1, 0, -1, -1 };
int offY[8] = { -1, -1, -1, 0, 1, 1, 1, 0 };
// Only on a exact tile boundary do we change the shocked tiles
// Start at top left and go around
if (g_hdb->_map->getMapBGTileFlags(e->tileX, e->tileY) & kFlagMetal)
e->special1Gfx[e->animFrame]->drawMasked(e->tileX * kTileWidth - mx, e->tileY * kTileHeight - my);
uint32 flags;
for (int i = 0; i < 8; i++) {
flags = g_hdb->_map->getMapBGTileFlags(e->tileX + offX[i], e->tileY + offY[i]);
if (flags & kFlagMetal) {
// Is the shocking tile onScreen?
if (g_hdb->_map->checkXYOnScreen((e->tileX + offX[i]) * kTileWidth, (e->tileY + offY[i]) * kTileHeight)) {
// Draw shocking tile animation
e->special1Gfx[e->animFrame]->drawMasked((e->tileX + offX[i])*kTileWidth - mx, (e->tileY + offY[i])*kTileHeight - my);
// Did the player get fried?
// Check every 4 frames
if (e->onScreen && !e->animFrame && g_hdb->_ai->checkPlayerTileCollision(e->tileX + offX[i], e->tileY + offY[i]) && !g_hdb->_ai->playerDead()) {
g_hdb->_ai->killPlayer(DEATH_SHOCKED);
return;
}
if (!e->animFrame && g_hdb->_map->boomBarrelExist(e->tileX + offX[i], e->tileY + offY[i])) {
AIEntity *e2 = g_hdb->_ai->findEntityType(AI_BOOMBARREL, e->tileX + offX[i], e->tileY + offY[i]);
aiBarrelExplode(e2);
}
}
}
}
}
void aiRightBotInit(AIEntity *e) {
e->moveSpeed = kPlayerMoveSpeed;
if (!g_hdb->getActionMode())
e->moveSpeed >>= 1;
e->aiAction = aiRightBotAction;
}
void aiRightBotInit2(AIEntity *e) {
switch (e->dir) {
case DIR_UP:
e->draw = e->moveupGfx[0];
e->state = STATE_MOVEUP;
break;
case DIR_DOWN:
e->draw = e->movedownGfx[0];
e->state = STATE_MOVEDOWN;
break;
case DIR_LEFT:
e->draw = e->moveleftGfx[0];
e->state = STATE_MOVELEFT;
break;
case DIR_RIGHT:
e->draw = e->moverightGfx[0];
e->state = STATE_MOVERIGHT;
break;
case DIR_NONE:
warning("aiRightBotInit2: DIR_NONE found");
break;
}
}
void aiRightBotFindGoal(AIEntity *e) {
int xv, yv, xv2, yv2, xv3, yv3;
int bg, bg2, bg3;
AIEntity *e1, *e2, *e3, *p;
int hit, sx, sy, rotate;
int xvAhead[5] = { 9, 0, 0,-1, 1 }, yvAhead[5] = { 9,-1, 1, 0, 0 };
int xvAToR[5] = { 9, 1,-1,-1, 1 }, yvAToR[5] = { 9,-1, 1,-1, 1 };
int xvToR[5] = { 9, 1,-1, 0, 0 }, yvToR[5] = { 9, 0, 0,-1, 1 };
int xvToL[5] = { 9,-1, 1, 0, 0 }, yvToL[5] = { 9, 0, 0, 1,-1 };
p = g_hdb->_ai->getPlayer();
rotate = 0;
do {
xv = xvAhead[e->dir]; // Search Ahead
yv = yvAhead[e->dir];
xv2 = xvAToR[e->dir]; // Search Ahead and to the Right
yv2 = yvAToR[e->dir];
xv3 = xvToR[e->dir]; // Search to the Right
yv3 = yvToR[e->dir];
// Search until we hit a wall...or empty space to our right (and forward)
hit = 0;
sx = e->tileX;
sy = e->tileY;
while (!hit) {
bg = g_hdb->_map->getMapBGTileFlags(sx + xv, sy + yv) & (kFlagSolid | kFlagWater | kFlagSlime | kFlagSpecial);
e1 = g_hdb->_ai->findEntity(sx + xv, sy + yv);
if (e1 && e1 == p)
e1 = NULL;
bg2 = g_hdb->_map->getMapBGTileFlags(sx + xv2, sy + yv2) & (kFlagSolid | kFlagWater | kFlagSlime | kFlagSpecial);
e2 = g_hdb->_ai->findEntity(sx + xv2, sy + yv2);
if (e2 && e2 == p)
e2 = NULL;
bg3 = g_hdb->_map->getMapBGTileFlags(sx + xv3, sy + yv3) & (kFlagSolid | kFlagWater | kFlagSlime | kFlagSpecial);
e3 = g_hdb->_ai->findEntity(sx + xv3, sy + yv3);
if (e3 && e3 == p)
e3 = NULL;
// Okay to move forward?
if ((!bg && !e1) && (bg2 || e2 || bg3 || e3)) {
sx += xv;
sy += yv;
rotate = 0;
} else
hit = 1;
}
// Are we stuck in a corner?
if (sx == e->tileX && sy == e->tileY) {
sx = e->tileX;
sy = e->tileY;
rotate += 1;
// Need to check for turning RIGHT when we're in a corner
xv = xvToL[e->dir];
yv = yvToL[e->dir];
// Check Tile flags to our left and right
bg = g_hdb->_map->getMapBGTileFlags(sx + xv, sy + yv) & (kFlagSolid | kFlagWater | kFlagSlime | kFlagSpecial);
e1 = g_hdb->_ai->findEntity(sx + xv, sy + yv);
bg2 = g_hdb->_map->getMapBGTileFlags(sx + xv3, sy + yv3) & (kFlagSolid | kFlagWater | kFlagSlime | kFlagSpecial);
e2 = g_hdb->_ai->findEntity(sx + xv3, sy + yv3);
if (e1 && e1->type == AI_GUY)
e1 = NULL;
if (e2 && e2->type == AI_GUY)
e2 = NULL;
// Is tile to the right clear?
// Is tile to the left clear?
// If neither, go backwards
if (!bg2 && !e2) {
switch (e->dir) {
case DIR_UP: e->dir = DIR_RIGHT; break;
case DIR_DOWN: e->dir = DIR_LEFT; break;
case DIR_LEFT: e->dir = DIR_UP; break;
case DIR_RIGHT: e->dir = DIR_DOWN; break;
case DIR_NONE:
warning("aiRightBotFindGoal: DIR_NONE found");
}
} else if (!bg && !e1) {
switch (e->dir) {
case DIR_UP: e->dir = DIR_LEFT; break;
case DIR_DOWN: e->dir = DIR_RIGHT; break;
case DIR_LEFT: e->dir = DIR_DOWN; break;
case DIR_RIGHT: e->dir = DIR_UP; break;
case DIR_NONE:
warning("aiRightBotFindGoal: DIR_NONE found");
}
} else {
switch (e->dir) {
case DIR_UP: e->dir = DIR_DOWN; yv = 1; xv = 0; break;
case DIR_DOWN: e->dir = DIR_UP; yv = -1; xv = 0; break;
case DIR_LEFT: e->dir = DIR_RIGHT; yv = 0; xv = 1; break;
case DIR_RIGHT: e->dir = DIR_LEFT; yv = 0; xv = -1; break;
case DIR_NONE:
warning("aiRightBotFindGoal: DIR_NONE found");
}
sx += xv;
sy += yv;
rotate = 4;
}
}
} while (rotate >= 1 && rotate < 4);
switch (e->dir) {
case DIR_UP:
e->state = STATE_MOVEUP;
break;
case DIR_DOWN:
e->state = STATE_MOVEDOWN;
break;
case DIR_LEFT:
e->state = STATE_MOVELEFT;
break;
case DIR_RIGHT:
e->state = STATE_MOVERIGHT;
break;
case DIR_NONE:
warning("aiRightBotFindGoal: DIR_NONE found");
break;
}
e->goalX = sx;
e->goalY = sy;
e->xVel = xv * e->moveSpeed;
e->yVel = yv * e->moveSpeed;
if (e->onScreen)
warning("STUB: aiRightBotFindGoal: Play SND_RIGHTBOT_TURN");
}
void aiRightBotAction(AIEntity *e) {
AIEntity *p = g_hdb->_ai->getPlayer();
if (e->goalX) {
if (e->onScreen && g_hdb->_ai->checkPlayerCollision(e->x, e->y, 0) && p->state != STATE_DEAD && p->level == e->level && !g_hdb->_ai->playerDead())
g_hdb->_ai->killPlayer(DEATH_NORMAL);
g_hdb->_ai->animateEntity(e);
} else {
aiRightBotFindGoal(e);
g_hdb->_ai->animEntFrames(e);
}
}
void aiPushBotInit(AIEntity *e) {
if (e->value1 != 1)
e->aiAction = aiPushBotAction;
}
void aiPushBotInit2(AIEntity *e) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiPushBotAction(AIEntity *e) {
AIState moveState[5] = { STATE_NONE, STATE_MOVEUP, STATE_MOVEDOWN, STATE_MOVELEFT, STATE_MOVERIGHT };
int xvAhead[5] = { 9, 0, 0,-1, 1 }, yvAhead[5] = { 9,-1, 1, 0, 0 };
AIDir oneEighty[5] = { DIR_NONE, DIR_DOWN, DIR_UP, DIR_RIGHT, DIR_LEFT };
uint32 bgFlags, fgFlags;
int nx, ny, nx2, ny2, result;
AIEntity *e1 = NULL, *e2;
if (e->goalX) {
g_hdb->_ai->animateEntity(e);
if (hitPlayer(e->x, e->y))
g_hdb->_ai->killPlayer(DEATH_NORMAL);
} else {
if (hitPlayer(e->x, e->y))
g_hdb->_ai->killPlayer(DEATH_NORMAL);
// Where to go next
nx = e->tileX + xvAhead[e->dir];
ny = e->tileY + yvAhead[e->dir];
e1 = g_hdb->_ai->legalMove(nx, ny, e->level, &result);
// Push something
// Turn Around
// Move Forward
if (e1 && onEvenTile(e1->x, e1->y) && (e1->type == AI_LIGHTBARREL || e1->type == AI_HEAVYBARREL || e1->type == AI_BOOMBARREL || e1->type == AI_CRATE)) {
// Actually going over a floating crate?
if (e1 && (e1->state == STATE_FLOATING || e1->state == STATE_MELTED)) {
e->state = moveState[e->dir];
g_hdb->_ai->setEntityGoal(e, nx, ny);
g_hdb->_ai->animateEntity(e);
return;
}
nx2 = nx + xvAhead[e->dir];
ny2 = ny + yvAhead[e->dir];
bgFlags = g_hdb->_map->getMapBGTileFlags(nx2, ny2);
fgFlags = g_hdb->_map->getMapFGTileFlags(nx2, ny2);
e2 = g_hdb->_ai->findEntity(nx2, ny2);
result = (e->level == 1) ? (bgFlags & kFlagSolid) : !(fgFlags & kFlagGrating) && (bgFlags & kFlagSolid);
// If we're going to push something onto a floating thing, that's ok
if (e2 && (e2->state == STATE_FLOATING || e2->state == STATE_MELTED))
e2 = NULL;
// If no walls in front & no entities
if (!result && !e2 && e1->state != STATE_EXPLODING) {
e->state = moveState[e->dir];
g_hdb->_ai->setEntityGoal(e, nx, ny);
e1->dir = e->dir;
e1->state = e->state;
e1->moveSpeed = e->moveSpeed;
g_hdb->_ai->setEntityGoal(e1, nx2, ny2);
warning("STUB: aiPushBotAction: Switch Case for Sound");
} else {
if (e->onScreen)
warning("STUB: aiPushBotAction: Play SND_PUSHBOT_STRAIN");
e->dir = oneEighty[e->dir];
e->state = moveState[e->dir];
nx = e->tileX + xvAhead[e->dir];
ny = e->tileY + yvAhead[e->dir];
e1 = g_hdb->_ai->legalMove(nx, ny, e->level, &result);
if (!e1 && result)
g_hdb->_ai->setEntityGoal(e, nx, ny);
}
} else if (!result || (e1 && !onEvenTile(e1->x, e1->y))) {
e->dir = oneEighty[e->dir];
e->state = moveState[e->dir];
nx = e->tileX + xvAhead[e->dir];
ny = e->tileY + yvAhead[e->dir];
e1 = g_hdb->_ai->legalMove(nx, ny, e->level, &result);
if (!e1 && result)
g_hdb->_ai->setEntityGoal(e, nx, ny);
} else {
e->state = moveState[e->dir];
g_hdb->_ai->setEntityGoal(e, nx, ny);
}
g_hdb->_ai->animateEntity(e);
}
}
void aiRailRiderInit(AIEntity *e) {
if (e->type == AI_RAILRIDER_ON) {
// On the tracks already - spawn RED arrow
g_hdb->_ai->addToPathList(e->tileX, e->tileY, 0, e->dir);
e->state = STATE_STANDUP;
e->aiAction = aiRailRiderOnAction;
e->aiUse = aiRailRiderOnUse;
} else {
e->state = STATE_STANDDOWN;
e->sequence = 0;
e->aiAction = aiRailRiderAction;
e->aiUse = aiRailRiderUse;
}
e->moveSpeed = kPlayerMoveSpeed;
}
void aiRailRiderInit2(AIEntity *e) {
e->draw = e->standdownGfx[0];
}
// Talking to RailRider off track
void aiRailRiderUse(AIEntity *e) {
e->sequence = 1;
}
void aiRailRiderAction(AIEntity *e) {
switch (e->sequence) {
// Waiting for Dialog to goaway
case 1:
// Dialog gone?
if (!g_hdb->_window->dialogActive()) {
e->sequence = 2;
switch (e->dir) {
case DIR_UP: e->xVel = 0; e->yVel = -1; break;
case DIR_DOWN: e->xVel = 0; e->yVel = 1; break;
case DIR_LEFT: e->xVel = -1; e->yVel = 0; break;
case DIR_RIGHT: e->xVel = 1; e->yVel = 0; break;
case DIR_NONE:
warning("aiRailRiderAction: DIR_NONE found");
break;
}
}
break;
// Walking over to track
case 2:
e->x += e->xVel;
e->y += e->yVel;
if (onEvenTile(e->x, e->y)) {
ArrowPath *arrowPath;
e->tileX = e->x / kTileWidth;
e->tileY = e->y / kTileHeight;
e->sequence = 3; // Wait for use
e->type = AI_RAILRIDER_ON;
e->state = STATE_STANDUP;
e->aiAction = aiRailRiderOnAction;
e->aiUse = aiRailRiderOnUse;
arrowPath = g_hdb->_ai->findArrowPath(e->tileX, e->tileY);
e->dir = arrowPath->dir;
e->value1 = 0; // Not in a tunnel
}
break;
}
// Cycle through animation frames
if (e->animDelay-- > 0)
return;
e->animDelay = e->animCycle;
e->animFrame++;
if (e->animFrame == e->standdownFrames)
e->animFrame = 0;
e->draw = e->standdownGfx[e->animFrame];
}
// Talking to RailRider on track
void aiRailRiderOnUse(AIEntity *e) {
AIEntity *p = g_hdb->_ai->getPlayer();
if (p->tileX == e->tileX) {
if (p->tileY > e->tileY)
g_hdb->_ai->setEntityGoal(p, p->tileX, p->tileY - 1);
else
g_hdb->_ai->setEntityGoal(p, p->tileX, p->tileY + 1);
} else {
if (p->tileX > e->tileX)
g_hdb->_ai->setEntityGoal(p, p->tileX - 1, p->tileY);
else
g_hdb->_ai->setEntityGoal(p, p->tileX + 1, p->tileY);
}
e->sequence = -1; // Waiting for player to board
}
void aiRailRiderOnAction(AIEntity *e) {
int xv[5] = { 9, 0, 0, -1, 1 }, yv[5] = { 9, -1, 1, 0, 0 };
AIEntity*p = g_hdb->_ai->getPlayer();
SingleTele t;
switch (e->sequence) {
// Player is boarding
case -1:
if (!p->goalX)
e->sequence = 1; // Boarded yet?
// Cycle Animation Frames
case 3:
if (e->animDelay-- > 0)
return;
e->animDelay = e->animCycle;
e->animFrame++;
if (e->animFrame == e->standupFrames)
e->animFrame = 0;
e->draw = e->standupGfx[e->animFrame];
break;
// Player is in - lock him
case 1:
g_hdb->_ai->setPlayerInvisible(true);
g_hdb->_ai->setPlayerLock(true);
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
warning("STUB: aiRailRiderOnAction: Play SND_RAILRIDER_TASTE");
e->sequence = 2;
e->value1 = 0;
// New RailRider gfx
// Move the RailRider
case 2:
// Done moving to next spot?
if (!e->goalX) {
ArrowPath *arrowPath = g_hdb->_ai->findArrowPath(e->tileX, e->tileY);
if (arrowPath) {
// Stop Arrow?
if (!arrowPath->type) {
HereT *h;
e->sequence = 4; // Get Player off RailRider - RIGHT SIDE ONLY
p->tileX = e->tileX;
p->tileY = e->tileY;
p->x = e->x;
p->y = e->y;
// Try to find a HERE icon to either side of the track and go there
switch (e->dir) {
case DIR_UP:
h = g_hdb->_ai->findHere(e->tileX - 1, e->tileY);
if (h)
g_hdb->_ai->setEntityGoal(p, e->tileX - 1, e->tileY);
else
g_hdb->_ai->setEntityGoal(p, e->tileX + 1, e->tileY);
break;
case DIR_DOWN:
h = g_hdb->_ai->findHere(e->tileX + 1, e->tileY);
if (h)
g_hdb->_ai->setEntityGoal(p, e->tileX + 1, e->tileY);
else
g_hdb->_ai->setEntityGoal(p, e->tileX - 1, e->tileY);
break;
case DIR_LEFT:
h = g_hdb->_ai->findHere(e->tileX, e->tileY + 1);
if (h)
g_hdb->_ai->setEntityGoal(p, e->tileX, e->tileY + 1);
else
g_hdb->_ai->setEntityGoal(p, e->tileX, e->tileY - 1);
break;
case DIR_RIGHT:
h = g_hdb->_ai->findHere(e->tileX, e->tileY - 1);
if (h)
g_hdb->_ai->setEntityGoal(p, e->tileX, e->tileY - 1);
else
g_hdb->_ai->setEntityGoal(p, e->tileX, e->tileY + 1);
break;
case DIR_NONE:
warning("aiRailRiderOnAction: DIR_NOW found");
break;
}
g_hdb->_ai->setPlayerInvisible(false);
warning("STUB: aiRailRiderOnAction: Play SND_RAILRIDER_EXIT");
} else if (arrowPath->type == 1) {
e->dir = arrowPath->dir;
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
}
} else
g_hdb->_ai->setEntityGoal(e, e->tileX + xv[e->dir], e->tileY + yv[e->dir]);
warning("STUB: aiRailRiderOnAction: Play SND_RAILRIDER_ONTRACK");
}
p->tileX = e->tileX;
p->tileY = e->tileY;
p->x = e->x;
p->y = e->y;
g_hdb->_ai->animateEntity(e);
switch (e->dir) {
case DIR_UP: e->draw = e->moveupGfx[0]; break;
case DIR_DOWN: e->draw = e->movedownGfx[0]; break;
case DIR_LEFT: e->draw = e->moveleftGfx[0]; break;
case DIR_RIGHT: e->draw = e->moverightGfx[0]; break;
default: break; // DIR_NONE
}
g_hdb->_map->centerMapXY(e->x + 16, e->y + 16);
// Did we hit a tunnel entrance?
if (onEvenTile(e->x, e->y) && g_hdb->_ai->findTeleporterDest(e->tileX, e->tileY, &t) && !e->value1 && !e->dir2) {
// Set tunnel destination
e->value1 = t.x;
e->value2 = t.y;
e->dir2 = (AIDir)(t.x + t.y); // Flag for coming out of tunnel
}
// Are we going through a tunnel?
if (e->value1) {
// Reach the End?
// If not, don't draw RailRider
if (onEvenTile(e->x, e->y) && e->tileX == e->value1 && e->tileY == e->value2)
e->value1 = 0;
else
e->draw = NULL;
} else if (e->dir2 && e->dir2 != (AIDir)(e->tileX + e->tileY))
e->dir2 = DIR_NONE;
break;
// Waiting for Player to move to Dest
case 4:
if (!p->goalX) {
g_hdb->_ai->setPlayerLock(false);
e->sequence = 3; // Wait for Use
}
// Cycle Animation frames
if (e->animDelay-- > 0)
return;
e->animDelay = e->animCycle;
e->animFrame++;
if (e->animFrame == e->standupFrames)
e->animFrame = 0;
e->draw = e->standupGfx[e->animFrame];
break;
}
}
void aiMaintBotInit(AIEntity *e) {
// value1 field determines whether the "MMM!" sound plays
// 1 means NO
e->int1 = e->value1;
e->aiAction = aiMaintBotAction;
e->value1 = 0;
g_hdb->_ai->findPath(e);
}
void aiMaintBotInit2(AIEntity *e) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiMaintBotAction(AIEntity *e) {
AIState useState[5] = {STATE_NONE, STATE_USEUP, STATE_USEDOWN, STATE_USELEFT, STATE_USERIGHT};
AIState standState[5] = {STATE_NONE, STATE_STANDUP, STATE_STANDDOWN, STATE_STANDLEFT, STATE_STANDRIGHT};
int xvAhead[5] = {9, 0, 0,-1, 1}, yvAhead[5] = {9,-1, 1, 0, 0};
AIEntity *it;
int nx, ny;
debug(9, "STUB: aiMaintBotAction: Add sounds");
// Waiting at an arrow (or hit by player)?
if (e->sequence) {
e->sequence--;
g_hdb->_ai->animEntFrames(e);
// Use Something here
if (!e->value2)
switch (e->sequence) {
case 50:
if (e->onScreen && !e->int1) {
warning("STUB: aiMaintBotAction: Play SND_MBOT_HMMM or SND_MBOT_HMMM2");
}
break;
// Need to USE the object
case 30:
e->state = useState[e->dir];
nx = e->tileX + xvAhead[e->dir];
ny = e->tileY + yvAhead[e->dir];
it = g_hdb->_ai->findEntity(nx, ny);
if (it) {
if (e->onScreen)
e->value1 = 1;
g_hdb->useEntity(it);
break;
}
// Did the MaintBot use an Action Tile?
if (g_hdb->_ai->checkActionList(e, nx, ny, true)) {
if (e->onScreen)
e->value1 = 1;
break;
}
// Did the MaintBot use an AutoAction Tile?
if (g_hdb->_ai->checkAutoList(e, nx, ny)) {
if (e->onScreen)
e->value1 = 1;
break;
}
// Did the MaintBot use a LUA Tile?
if (g_hdb->_ai->checkLuaList(e, nx, ny)) {
if (e->onScreen)
e->value1 = 1;
break;
}
break;
// Play a sound if we used something
case 25:
e->value1 = 0;
break;
// Change to Standing frames
case 20:
e->state = standState[e->dir];
break;
// All done - find a new path
case 0:
e->dir = e->dir2;
g_hdb->_ai->findPath(e);
g_hdb->_ai->animateEntity(e);
break;
}
// Deciding where to go at 4-way
else {
AIDir lookRight[5] = {DIR_NONE, DIR_RIGHT, DIR_LEFT, DIR_UP, DIR_DOWN};
AIDir lookLeft[5] = {DIR_NONE, DIR_LEFT, DIR_RIGHT, DIR_DOWN, DIR_UP};
AIDir dirList[5] = {DIR_NONE, DIR_UP, DIR_DOWN, DIR_LEFT, DIR_RIGHT};
switch (e->sequence) {
// HMM
case 50:
if (e->onScreen && !e->int1)
warning("STUB: aiMaintBotAction: Play SND_MBOT_HMMM");
break;
// Look Right
case 40:
e->dir = lookRight[e->dir2];
e->state = standState[e->dir];
break;
// Look Left
case 30:
e->dir = lookLeft[e->dir];
e->state = standState[e->dir];
break;
// HMM2
case 25:
if (e->onScreen && !e->int1)
warning("STUB: aiMaintBotAction: Play SND_MBOT_HMM2");
break;
// Decide direction and GO
case 0:
int dir = (g_hdb->_rnd->getRandomNumber(4)) + 1;
e->dir = dirList[dir];
g_hdb->_ai->findPath(e);
if (e->onScreen)
warning("STUB: aiMaintBotAction: Play whistle");
break;
}
}
return;
}
// Moving already, keep going
if (e->goalX) {
g_hdb->_ai->animateEntity(e);
if (hitPlayer(e->x, e->y)) {
g_hdb->_ai->killPlayer(DEATH_GRABBED);
warning("STUB: aiMaintBotAction: Play SND_MBOT_DEATH");
}
} else {
// Check if there's an arrow UNDER the bot, and if its RED
// If so, turn in that direction and use something
ArrowPath *ar = g_hdb->_ai->findArrowPath(e->tileX, e->tileY);
if (ar) {
// STOP Arrow
// GO Arrow
// 4-way Arrow
if (!ar->type) {
e->dir2 = e->dir; // dir2 holds the last direction we were travelling in
e->dir = ar->dir;
e->sequence = 64; // sequence is the timer of events
e->state = standState[e->dir];
e->value2 = 0;
return;
} else if (ar->type == 1) {
g_hdb->_ai->findPath(e);
warning("STUB: aiMaintBotAction: Play whistle");
} else {
e->sequence = 64;
e->dir2 = e->dir;
e->value2 = 1;
return;
}
}
g_hdb->_ai->animateEntity(e);
}
}
void aiFourFirerInit(AIEntity *e) {
e->value1 = 0;
e->aiAction = aiFourFirerAction;
}
void aiFourFirerInit2(AIEntity *e) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiFourFirerAction(AIEntity *e) {
AIEntity *p = g_hdb->_ai->getPlayer(), *fire, *hit;
AIState state[5] = {STATE_NONE, STATE_STANDUP, STATE_STANDDOWN, STATE_STANDLEFT, STATE_STANDRIGHT};
AIDir turn[5] = {DIR_NONE, DIR_RIGHT, DIR_LEFT, DIR_UP, DIR_DOWN};
int shoot, xv, yv, result;
// Time to turn right?
if (!e->value1) {
e->dir = turn[e->dir];
e->state = state[e->dir];
e->value1 = 16;
if (e->onScreen)
warning("STUB: aiFourFirerAction: Play SND_FOURFIRE_TURN");
}
e->value1--;
// Waiting before firing again?
if (e->sequence) {
e->sequence--;
return;
}
g_hdb->_ai->animEntFrames(e);
// Can we see the player on the same level?
if ((e->level != p->level) || g_hdb->_ai->playerDead() || !e->onScreen)
return;
// Check player direction
shoot = xv = yv = 0;
switch (e->dir) {
case DIR_UP: if (p->x == e->x && p->y < e->y) { shoot = 1; yv = -1; } break;
case DIR_DOWN: if (p->x == e->x && p->y > e->y) { shoot = 1; yv = 1; } break;
case DIR_LEFT: if (p->y == e->y && p->x < e->x) { shoot = 1; xv = -1; } break;
case DIR_RIGHT: if (p->y == e->y && p->x > e->x) { shoot = 1; xv = 1; } break;
case DIR_NONE: warning("aiFourFirerAction: DIR_NONE found"); break;
}
// Shoot if needed
// Make sure not shooting into solid tile
// Make sure if shooting at entity it is the player
hit = g_hdb->_ai->legalMoveOverWater(e->tileX + xv, e->tileY + yv, e->level, &result);
if (hit && hit->type == AI_GUY)
hit = NULL;
if (shoot && !hit && result) {
fire = g_hdb->_ai->spawn(AI_OMNIBOT_MISSILE, e->dir, e->tileX + xv, e->tileY + yv, NULL, NULL, NULL, DIR_NONE, e->level, 0, 0, 1);
if (g_hdb->_map->onScreen(e->tileX, e->tileY))
warning("STUB: aiFourFirerAction: Play SND_FOUR_FIRE");
fire->xVel = xv * kPlayerMoveSpeed * 2;
fire->yVel = yv * kPlayerMoveSpeed * 2;
if (!g_hdb->getActionMode()) {
fire->xVel >>= 1;
fire->yVel >>= 1;
}
e->sequence = 16;
if (hitPlayer(fire->tileX*kTileWidth, fire->tileY*kTileHeight))
g_hdb->_ai->killPlayer(DEATH_FRIED);
}
}
void aiDeadEyeInit(AIEntity *e) {
e->sequence = 64;
e->blinkFrames = e->goalX = 0;
if (e->value1 == 1)
e->aiAction = aiDeadEyeWalkInPlace;
else
e->aiAction = aiDeadEyeAction;
}
void aiDeadEyeInit2(AIEntity *e) {
e->draw = g_hdb->_ai->getStandFrameDir(e);
}
void aiDeadEyeWalkInPlace(AIEntity *e) {
AIState state[5] = {STATE_NONE, STATE_MOVEUP, STATE_MOVEDOWN, STATE_MOVELEFT, STATE_MOVERIGHT};
AIDir dir;
AIState s;
e->sequence--;
switch (e->sequence) {
case 50:
case 40:
case 30:
case 20:
case 10:
dir = (AIDir)(g_hdb->_rnd->getRandomNumber(4) + 1);
s = state[dir];
e->dir = dir;
e->state = s;
if (e->onScreen) {
if (e->sequence == 50)
warning("STUB: aiDeadEyeWalkInPlace: Play SND_DEADEYE_AMB01");
else if (e->sequence == 10)
warning("STUB: aiDeadEyeWalkInPlace: Play SND_DEADEYE_AMB02");
}
break;
case 0:
e->sequence = 64;
}
g_hdb->_ai->animEntFrames(e);
}
void aiDeadEyeAction(AIEntity *e) {
AIState state[5] = {STATE_NONE, STATE_MOVEUP, STATE_MOVEDOWN, STATE_MOVELEFT, STATE_MOVERIGHT};
int xvAhead[5] = {9, 0, 0, -1, 1}, yvAhead[5] = {9, -1, 1, 0, 0};
int result;
AIEntity *hit;
AIDir dir;
AIState s;
if (e->sequence) {
e->sequence--;
if (e->blinkFrames) // Between attacks timer
e->blinkFrames--;
// Is player visible to us?
AIEntity *p = g_hdb->_ai->getPlayer();
if (e->onScreen && p->level == e->level && !e->blinkFrames) {
int nuts = 0;
switch (e->dir) {
case DIR_UP: if (p->tileX == e->tileX && p->tileY < e->tileY) nuts = 1; break;
case DIR_DOWN: if (p->tileX == e->tileX && p->tileY > e->tileY) nuts = 1; break;
case DIR_LEFT: if (p->tileY == e->tileY && p->tileX < e->tileX) nuts = 1; break;
case DIR_RIGHT: if (p->tileY == e->tileY && p->tileX > e->tileX) nuts = 1; break;
case DIR_NONE: warning("aiDeadEyeAction: DIR_NONE found"); break;
}
// Did we see the player (and we're done moving)?
if (nuts && e->aiAction != aiDeadEyeWalkInPlace) {
int newX, newY, xv, yv, done, okToMove;
e->sequence = 0;
e->blinkFrames = 20;
xv = xvAhead[e->dir];
yv = yvAhead[e->dir];
newX = e->tileX + xv;
newY = e->tileY + yv;
okToMove = done = 0;
do {
hit = g_hdb->_ai->legalMove(newX, newY, e->level, &result);
if (hit && hit->type == AI_GUY)
hit = NULL;
if (result && !hit) {
okToMove = 1;
newX += xv;
newY += yv;
if (newX == p->tileX && newY == p->tileY)
done = 1;
} else {
newX -= xv;
newY -= yv;
done = 1;
}
} while (!done);
// If we can move in the direction of the player, set our goal at him
if (okToMove) {
e->moveSpeed = kPlayerMoveSpeed << 1;
g_hdb->_ai->setEntityGoal(e, newX, newY);
p->tileX & 1 ? warning("STUB: aiDeadEyeAction: Play SND_DEADEYE_ATTACK01") : warning("STUB: aiDeadEyeAction: Play SND_DEADEYE_ATTACK02");
}
g_hdb->_ai->animateEntity(e);
return;
}
}
switch (e->sequence) {
// Look around
case 50:
case 40:
case 30:
case 20:
case 10:
dir = (AIDir)(g_hdb->_rnd->getRandomNumber(4)+1);
s = state[dir];
e->dir = dir;
e->state = s;
if (e->onScreen) {
if (e->sequence == 50)
warning("STUB: aiDeadEyeAction: Play SND_DEADEYE_AMB01");
else if (e->sequence == 10)
warning("STUB: aiDeadEyeAction: Play SND_DEADEYE_AMB01");
}
break;
case 0:
// Pick a random direction and random number of tiles in that direction
dir = (AIDir)(g_hdb->_rnd->getRandomNumber(4) + 1);
int walk = g_hdb->_rnd->getRandomNumber(5) + 1;
int xv, yv;
e->dir = dir;
e->state = state[dir];
xv = xvAhead[dir] * walk;
if (e->tileX + xv < 1)
xv = 1 - e->tileX;
if (e->tileX + xv > g_hdb->_map->_width)
xv = g_hdb->_map->_width - e->tileX - 1;
yv = yvAhead[dir] * walk;
if (e->tileY + yv < 1)
yv = 1 - e->tileY;
if (e->tileY + yv > g_hdb->_map->_height)
yv = g_hdb->_map->_height - e->tileY - 1;
e->value1 = xvAhead[dir];
e->value2 = yvAhead[dir];
e->moveSpeed = kPlayerMoveSpeed;
hit = g_hdb->_ai->legalMove(e->tileX + xvAhead[e->dir], e->tileY + yvAhead[e->dir], e->level, &result);
if (hit && hit->type == AI_GUY)
hit = NULL;
if (!hit && result)
g_hdb->_ai->setEntityGoal(e, e->tileX + xv, e->tileY + yv);
break;
}
g_hdb->_ai->animEntFrames(e);
return;
}
// In the process of moving around
if (e->goalX) {
// Hit the player
if (hitPlayer(e->x, e->y)) {
g_hdb->_ai->killPlayer(DEATH_GRABBED);
return;
}
// Did we run into a wall, entity, water, slime etc?
// If so, Pick new direction
if (onEvenTile(e->x, e->y)) {
hit = g_hdb->_ai->legalMove(e->tileX + e->value1, e->tileY + e->value2, e->level, &result);
if (hit && hit->type == AI_GUY)
hit = NULL;
if (!result || hit) {
g_hdb->_ai->stopEntity(e);
e->state = STATE_MOVEDOWN;
e->sequence = 64;
return;
}
}
g_hdb->_ai->animateEntity(e);
} else
// If not, start looking around
e->sequence = 64;
}
void aiLaserAction(AIEntity *e) {
warning("STUB: AI: aiLaserAction required");
}
void aiLaserDraw(AIEntity *e, int mx, int my) {
warning("STUB: AI: aiLaserDraw required");
}
void aiDiverterAction(AIEntity *e) {
warning("STUB: AI: aiDiverterAction required");
}
void aiDiverterDraw(AIEntity *e, int mx, int my) {
warning("STUB: AI: aiDiverterDraw required");
}
void aiMeerkatDraw(AIEntity *e, int mx, int my) {
warning("STUB: AI: aiMeerkatDraw required");
}
void aiMeerkatAction(AIEntity *e) {
warning("STUB: AI: aiMeerkatAction required");
}
void aiMeerkatLookAround(AIEntity *e) {
warning("STUB: AI: aiMeerkatLookAround required");
}
void aiFatFrogAction(AIEntity *e) {
warning("STUB: AI: aiFatFrogAction required");
}
void aiFatFrogTongueDraw(AIEntity *e, int mx, int my) {
warning("STUB: AI: aiFatFrogTongueDraw required");
}
void aiGoodFairyAction(AIEntity *e) {
warning("STUB: AI: aiGoodFairyAction required");
}
void aiBadFairyAction(AIEntity *e) {
warning("STUB: AI: aiBadFairyAction required");
}
void aiGatePuddleAction(AIEntity *e) {
warning("STUB: AI: aiGatePuddleAction required");
}
void aiIcePuffSnowballAction(AIEntity *e) {
warning("STUB: AI: aiIcePuffSnowballAction required");
}
void aiIcePuffSnowballDraw(AIEntity *e, int mx, int my) {
warning("STUB: AI: aiIcePuffSnowballDraw required");
}
void aiIcePuffAction(AIEntity *e) {
warning("STUB: AI: aiIcePuffAction required");
}
void aiBuzzflyAction(AIEntity *e) {
warning("STUB: AI: aiBuzzflyAction required");
}
void aiDragonAction(AIEntity *e) {
warning("STUB: AI: aiDragonAction required");
}
void aiDragonDraw(AIEntity *e, int mx, int my) {
warning("STUB: AI: aiDragonDraw required");
}
void aiListenBotInit(AIEntity *e) {
warning("STUB: AI: aiListenBotInit required");
}
void aiListenBotInit2(AIEntity *e) {
warning("STUB: AI: aiListenBotInit2 required");
}
void aiLaserInit(AIEntity *e) {
warning("STUB: AI: aiLaserInit required");
}
void aiLaserInit2(AIEntity *e) {
warning("STUB: AI: aiLaserInit2 required");
}
void aiDiverterInit(AIEntity *e) {
warning("STUB: AI: aiDiverterInit required");
}
void aiDiverterInit2(AIEntity *e) {
warning("STUB: AI: aiDiverterInit2 required");
}
void aiMeerkatInit(AIEntity *e) {
warning("STUB: AI: aiMeerkatInit required");
}
void aiMeerkatInit2(AIEntity *e) {
warning("STUB: AI: aiMeerkatInit2 required");
}
void aiFatFrogInit(AIEntity *e) {
warning("STUB: AI: aiFatFrogInit required");
}
void aiFatFrogInit2(AIEntity *e) {
warning("STUB: AI: aiFatFrogInit2 required");
}
void aiGoodFairyInit(AIEntity *e) {
warning("STUB: AI: aiGoodFairyInit required");
}
void aiGoodFairyInit2(AIEntity *e) {
warning("STUB: AI: aiGoodFairyInit2 required");
}
void aiGoodFairyMoveaway(AIEntity *e) {
warning("STUB: AI: aiGoodFairyMoveaway required");
}
void aiBadFairyInit(AIEntity *e) {
warning("STUB: AI: aiBadFairyInit required");
}
void aiBadFairyInit2(AIEntity *e) {
warning("STUB: AI: aiBadFairyInit2 required");
}
void aiGatePuddleInit(AIEntity *e) {
warning("STUB: AI: aiGatePuddleInit required");
}
void aiGatePuddleInit2(AIEntity *e) {
warning("STUB: AI: aiGatePuddleInit2 required");
}
void aiIcePuffInit(AIEntity *e) {
warning("STUB: AI: aiIcePuffInit required");
}
void aiIcePuffInit2(AIEntity *e) {
warning("STUB: AI: aiIcePuffInit2 required");
}
void aiBuzzflyInit(AIEntity *e) {
warning("STUB: AI: aiBuzzflyInit required");
}
void aiBuzzflyInit2(AIEntity *e) {
warning("STUB: AI: aiBuzzflyInit2 required");
}
void aiDragonInit(AIEntity *e) {
warning("STUB: AI: aiDragonInit required");
}
void aiDragonInit2(AIEntity *e) {
warning("STUB: AI: aiDragonInit2 required");
}
void aiDragonWake(AIEntity *e) {
warning("STUB: AI: aiDragonWake required");
}
void aiDragonUse(AIEntity *e) {
warning("STUB: AI: aiDragonUse required");
}
} // End of Namespace
|