forked from scummvm/scummvm
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathai.h
1408 lines (1201 loc) · 33.1 KB
/
ai.h
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
/* 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.
*
*/
#ifndef HDB_AI_H
#define HDB_AI_H
#define STARS_MONKEYSTONE_7 0xfe257d // magic value in the config file for the unlocking of the Monkeystone secret #7
#define STARS_MONKEYSTONE_7_FAKE 0x11887e // fake value that means it hasn't been unlocked
#define STARS_MONKEYSTONE_14 0x3341fe // <same> for the Monkeystone #14
#define STARS_MONKEYSTONE_14_FAKE 0x1cefd0 // fake value that means it hasn't been unlocked
#define STARS_MONKEYSTONE_21 0x77ace3 // <same> for the Monkeystone #21
#define STARS_MONKEYSTONE_21_FAKE 0x3548fe // fake value that means it hasn't been unlocked
namespace HDB {
enum {
kMaxAnimFrames = 8,
kMaxAnimTFrames = 16,
kMaxDeathFrames = 12,
kMaxLevel2Ents = 60,
kMaxInventory = 10,
kMaxDeliveries = 5,
kMaxWaypoints = 10,
kMaxActions = 20,
kMaxTeleporters = 20,
kMaxAutoActions = 30,
kMaxLuaEnts = 50,
kMaxCallbacks = 20,
kMaxFairystones = 5,
kMaxGatePuddles = 8,
kMaxBridges = 10,
kDelay5Seconds = 5 * kGameFPS,
kPlayerMoveSpeed = 4,
kEnemyMoveSpeed = 2,
kPushMoveSpeed = (kPlayerMoveSpeed >> 1),
kPlayerTouchPWait = 16,
kMaxCineGfx = 10,
kRunToggleDelay = 2,
kMsgDelay = 3,
kYouGotX = -1,
kNumSaveSlots = 8,
kAutoSaveSlot = 0
};
enum AIType {
AI_NONE,
AI_GUY,
AI_DOLLY,
AI_SPACEDUDE,
AI_SERGEANT,
AI_SCIENTIST,
AI_WORKER,
AI_DEADWORKER,
AI_ACCOUNTANT,
AI_RAILRIDER,
AI_RAILRIDER_ON,
AI_VORTEXIAN,
AI_CHICKEN,
AI_GEM_ATTACK,
AI_SLUG_ATTACK,
AI_LASER,
AI_LASERBEAM,
AI_DIVERTER,
AI_FOURFIRER,
AI_OMNIBOT,
AI_TURNBOT,
AI_SHOCKBOT,
AI_RIGHTBOT,
AI_PUSHBOT,
AI_LISTENBOT,
AI_MAINTBOT,
AI_OMNIBOT_MISSILE,
AI_DEADEYE,
AI_MEERKAT,
AI_FATFROG,
AI_GOODFAIRY,
AI_BADFAIRY,
AI_ICEPUFF,
AI_BUZZFLY,
AI_DRAGON,
AI_GATEPUDDLE,
AI_CRATE,
AI_LIGHTBARREL,
AI_HEAVYBARREL,
AI_BOOMBARREL,
AI_FROGSTATUE,
AI_MAGIC_EGG,
AI_ICE_BLOCK,
ITEM_CELL,
ITEM_ENV_WHITE,
ITEM_ENV_RED,
ITEM_ENV_BLUE,
ITEM_ENV_GREEN,
ITEM_TRANSCEIVER,
ITEM_CLUB,
ITEM_ROBOSTUNNER,
ITEM_SLUGSLINGER,
ITEM_MONKEYSTONE,
ITEM_GEM_WHITE,
ITEM_GEM_BLUE,
ITEM_GEM_RED,
ITEM_GEM_GREEN,
ITEM_GOO_CUP,
ITEM_TEACUP,
ITEM_COOKIE,
ITEM_BURGER,
ITEM_PDA,
ITEM_BOOK,
ITEM_CLIPBOARD,
ITEM_NOTE,
ITEM_KEYCARD_WHITE,
ITEM_KEYCARD_BLUE,
ITEM_KEYCARD_RED,
ITEM_KEYCARD_GREEN,
ITEM_KEYCARD_PURPLE,
ITEM_KEYCARD_BLACK,
ITEM_CABKEY,
ITEM_DOLLYTOOL1,
ITEM_DOLLYTOOL2,
ITEM_DOLLYTOOL3,
ITEM_DOLLYTOOL4,
ITEM_SEED,
ITEM_SODA,
ITEM_ROUTER,
ITEM_SLICER,
ITEM_CHICKEN,
ITEM_PACKAGE,
INFO_FAIRY_SRC,
INFO_FAIRY_SRC2,
INFO_FAIRY_SRC3,
INFO_FAIRY_SRC4,
INFO_FAIRY_SRC5,
INFO_FAIRY_DEST,
INFO_FAIRY_DEST2,
INFO_FAIRY_DEST3,
INFO_FAIRY_DEST4,
INFO_FAIRY_DEST5,
INFO_TRIGGER,
INFO_SET_MUSIC,
INFO_PROMOTE,
INFO_DEMOTE,
INFO_LUA,
INFO_HERE,
INFO_ARROW_TURN,
INFO_ARROW_STOP,
INFO_ARROW_4WAY,
INFO_TELEPORTER1,
INFO_TELEPORTER2,
INFO_TELEPORTER3,
INFO_TELEPORTER4,
INFO_TELEPORTER5,
INFO_TELEPORTER6,
INFO_TELEPORTER7,
INFO_TELEPORTER8,
INFO_TELEPORTER9,
INFO_TELEPORTER10,
INFO_TELEPORTER11,
INFO_TELEPORTER12,
INFO_TELEPORTER13,
INFO_TELEPORTER14,
INFO_TELEPORTER15,
INFO_TELEPORTER16,
INFO_TELEPORTER17,
INFO_TELEPORTER18,
INFO_TELEPORTER19,
INFO_TELEPORTER20,
INFO_LEVELEXIT,
INFO_ACTION1,
INFO_ACTION2,
INFO_ACTION3,
INFO_ACTION4,
INFO_ACTION5,
INFO_ACTION6,
INFO_ACTION7,
INFO_ACTION8,
INFO_ACTION9,
INFO_ACTION10,
INFO_ACTION11,
INFO_ACTION12,
INFO_ACTION13,
INFO_ACTION14,
INFO_ACTION15,
INFO_ACTION16,
INFO_ACTION17,
INFO_ACTION18,
INFO_ACTION19,
INFO_ACTION20,
INFO_ACTION_AUTO,
INFO_QMARK,
INFO_DEBUG,
END_AI_TYPES
};
enum AIDir {
DIR_NONE,
DIR_UP,
DIR_DOWN,
DIR_LEFT,
DIR_RIGHT
};
enum Death {
DEATH_NORMAL,
DEATH_FRIED,
DEATH_DROWNED,
DEATH_GRABBED,
DEATH_SHOCKED,
DEATH_PANICZONE,
DEATH_PLUMMET
};
enum AIState {
STATE_NONE,
STATE_STANDDOWN,
STATE_STANDUP,
STATE_STANDLEFT,
STATE_STANDRIGHT,
STATE_BLINK,
STATE_MOVEUP,
STATE_MOVEDOWN,
STATE_MOVELEFT,
STATE_MOVERIGHT,
STATE_DYING,
STATE_DEAD,
STATE_HORRIBLE1,
STATE_HORRIBLE2,
STATE_HORRIBLE3,
STATE_HORRIBLE4,
STATE_GOODJOB,
STATE_PLUMMET,
STATE_PUSHUP, // these are only used for the player
STATE_PUSHDOWN,
STATE_PUSHLEFT,
STATE_PUSHRIGHT,
STATE_GRABUP, // player grabbing something
STATE_GRABDOWN,
STATE_GRABLEFT,
STATE_GRABRIGHT,
STATE_ATK_CLUB_UP, // player attacking frames
STATE_ATK_CLUB_DOWN,
STATE_ATK_CLUB_LEFT,
STATE_ATK_CLUB_RIGHT,
STATE_ATK_STUN_DOWN,
STATE_ATK_STUN_UP,
STATE_ATK_STUN_LEFT,
STATE_ATK_STUN_RIGHT,
STATE_ATK_SLUG_DOWN,
STATE_ATK_SLUG_UP,
STATE_ATK_SLUG_LEFT,
STATE_ATK_SLUG_RIGHT,
STATE_FLOATING, // floating in stuff (can walk on)
STATE_FLOATDOWN,
STATE_FLOATUP,
STATE_FLOATLEFT,
STATE_FLOATRIGHT,
STATE_MELTED, // melted into slag (can walk on)
STATE_SLIDING, // sliding across a floor
STATE_SHOCKING, // for Shockbot floor-shock anim
STATE_EXPLODING, // boom barrel explosion!
STATE_USEDOWN, // crazy maintenance bot!
STATE_USEUP,
STATE_USELEFT,
STATE_USERIGHT,
STATE_MEER_MOVE, // for the Meerkat
STATE_MEER_APPEAR,
STATE_MEER_BITE,
STATE_MEER_DISAPPEAR,
STATE_MEER_LOOK,
STATE_ICEP_PEEK, // for the Icepuff
STATE_ICEP_APPEAR,
STATE_ICEP_THROWDOWN,
STATE_ICEP_THROWRIGHT,
STATE_ICEP_THROWLEFT,
STATE_ICEP_DISAPPEAR,
STATE_LICKDOWN, // for the Fatfrog
STATE_LICKLEFT,
STATE_LICKRIGHT,
STATE_DIVERTER_BL, // for Diverters
STATE_DIVERTER_BR,
STATE_DIVERTER_TL,
STATE_DIVERTER_TR,
STATE_KISSRIGHT, // for Dolly
STATE_KISSLEFT,
STATE_ANGRY,
STATE_PANIC,
STATE_LAUGH,
STATE_DOLLYUSERIGHT,
STATE_YELL, // for Sarge
STATE_ENDSTATES
};
enum AnimSpeed {
ANIM_SLOW,
ANIM_NORMAL,
ANIM_FAST
};
enum CineType {
C_NO_COMMAND,
C_STOPCINE,
C_LOCKPLAYER,
C_UNLOCKPLAYER,
C_SETCAMERA,
C_MOVECAMERA,
C_WAIT,
C_WAITUNTILDONE,
C_MOVEENTITY,
C_DIALOG,
C_ANIMENTITY,
C_RESETCAMERA,
C_SETENTITY,
C_STARTMAP,
C_MOVEPIC,
C_MOVEMASKEDPIC,
C_DRAWPIC,
C_DRAWMASKEDPIC,
C_FADEIN,
C_FADEOUT,
C_SPAWNENTITY,
C_PLAYSOUND,
C_CLEAR_FG,
C_SET_FG,
C_SET_BG,
C_FUNCTION,
C_ENTITYFACE,
C_USEENTITY,
C_REMOVEENTITY,
C_SETANIMFRAME,
C_TEXTOUT,
C_CENTERTEXTOUT,
C_PLAYVOICE,
C_ENDLIST
};
enum CallbackType {
NO_FUNCTION,
AI_BARREL_EXPLOSION_END,
CALLBACK_DOOR_OPEN_CLOSE,
CALLBACK_AUTODOOR_OPEN_CLOSE,
CALLBACK_END
};
struct AIStateDef {
AIState state;
const char *name;
};
struct AIEntity {
AIType type;
AIState state;
AIDir dir;
Tile *draw; // Current frame to draw
void (*aiInit)(AIEntity *e); // func ptr to init routine
void (*aiInit2)(AIEntity *e); // func ptr to init2 routine - graphic init only (this for LoadGame functionality)
void (*aiAction)(AIEntity *e); // func ptr to action routine
void (*aiUse)(AIEntity *e); // func ptr to use routine
void (*aiDraw)(AIEntity *e, int x, int y); // func ptr to extra drawing routine (only for special stuff) - pass in mapx, mapy
char luaFuncInit[32]; // Lua function for Init (always called after entity's init). These are ptrs into the map header.
char luaFuncAction[32]; // Lua function for Action
char luaFuncUse[32]; // Lua function for Use
int16 level; // which floor level we're on
int16 value1, value2; // extra values we might need
AIDir dir2; // this is from TED
int16 x, y;
int16 drawXOff, drawYOff; // might need a drawing offset
int16 onScreen; // FLAG: is this entity onscreen?
int16 moveSpeed; // movement speed of this entity
int16 xVel, yVel; // movement values
int16 tileX, tileY;
int16 goalX, goalY; // where we're trying to go - TILE COORDS
int16 touchpX, touchpY, touchpTile, touchpWait; // ACTION index a touchplate is using, which you're on
int32 stunnedWait; // if we're stunned, this is the delay before being normal again
int16 sequence; // to use for specially-coded sequences
char entityName[32]; // the name of the entity, as registered by the Lua init function for the entity
char printedName[32]; // the name of the entity/item, the way it should be printed
int16 animFrame; // which frame we're on
int16 animDelay; // changes every frame; based on anim_cycle at start
int16 animCycle; // delay between frame animations
union {
uint16 blinkFrames;
int16 int1;
};
Tile *blinkGfx[kMaxAnimFrames];
union {
uint16 special1Frames;
int16 int2;
};
Tile *special1Gfx[kMaxAnimFrames];
int16 standdownFrames;
Tile *standdownGfx[kMaxAnimFrames];
int16 standupFrames;
Tile *standupGfx[kMaxAnimFrames];
int16 standleftFrames;
Tile *standleftGfx[kMaxAnimFrames];
int16 standrightFrames;
Tile *standrightGfx[kMaxAnimFrames];
int16 moveupFrames;
Tile *moveupGfx[kMaxAnimFrames];
int16 movedownFrames;
Tile *movedownGfx[kMaxAnimFrames];
int16 moveleftFrames;
Tile *moveleftGfx[kMaxAnimFrames];
int16 moverightFrames;
Tile *moverightGfx[kMaxAnimFrames];
void reset() {
luaFuncInit[0] = 0;
luaFuncAction[0] = 0;
luaFuncUse[0] = 0;
entityName[0] = 0;
printedName[0] = 0;
type = AI_NONE;
state = STATE_NONE;
dir = DIR_NONE;
draw = NULL;
aiInit = aiInit2 = NULL;
aiAction = NULL;
aiUse = NULL;
aiDraw = NULL;
level = 0;
value1 = value2 = 0;
dir2 = DIR_NONE;
x = y = 0;
drawXOff = drawYOff = 0;
onScreen = 0;
moveSpeed = 0;
xVel = yVel = 0;
tileX = tileY = 0;
goalX = goalY = 0;
touchpX = touchpY = touchpTile = touchpWait = 0;
stunnedWait = 0;
sequence = 0;
animCycle = 0;
animDelay = 0;
animFrame = 0;
blinkFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
blinkGfx[i] = NULL;
}
special1Frames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
special1Gfx[i] = NULL;
}
standdownFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
standdownGfx[i] = NULL;
}
standupFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
standupGfx[i] = NULL;
}
standleftFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
standleftGfx[i] = NULL;
}
standrightFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
standrightGfx[i] = NULL;
}
movedownFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
movedownGfx[i] = NULL;
}
moveupFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
moveupGfx[i] = NULL;
}
moveleftFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
moveleftGfx[i] = NULL;
}
moverightFrames = 0;
for (int i = 0; i < kMaxAnimFrames; i++) {
moverightGfx[i] = NULL;
}
}
AIEntity() {
reset();
}
~AIEntity() {
}
void save(Common::OutSaveFile *out);
void load(Common::InSaveFile *in);
};
// Structs for Function Table Lookup for SaveGames
typedef void(*FuncPtr)(AIEntity *);
typedef void(*EntFuncPtr)(AIEntity *, int, int);
struct AIEntTypeInfo {
AIType type;
const char *luaName;
AIStateDef *stateDef;
void (*initFunc)(AIEntity *e);
void (*initFunc2)(AIEntity *e);
};
struct FuncLookUp {
void(*function)(AIEntity *e);
const char *funcName;
};
extern AIEntTypeInfo aiEntList[];
extern FuncLookUp aiFuncList[];
struct AIEntLevel2 {
uint16 x;
uint16 y;
Tile *draw;
AIEntity *e;
void(*aiDraw)(AIEntity *e, int x, int y);
uint32 stunnedWait;
AIEntLevel2() : x(0), y(0), draw(NULL), e(NULL), aiDraw(NULL), stunnedWait(0) {}
};
struct AnimTarget {
uint16 x, y;
uint16 start, end;
int16 vel;
uint16 animCycle;
uint16 animFrame;
bool killAuto; // Keep it alive if its an Auto?
bool inMap;
Tile *gfxList[kMaxAnimTFrames];
AnimTarget() : x(0), y(0), start(0), end(0), vel(0), animCycle(0), animFrame(0), killAuto(false), inMap(false) {
for (int i = 0; i < kMaxAnimTFrames; i++) {
gfxList[i] = NULL;
}
}
};
struct InvEnt {
uint16 keep;
AIEntity ent;
void reset() {
keep = 0;
ent.reset();
}
InvEnt() {
reset();
}
};
struct DlvEnt {
char itemTextName[32];
char itemGfxName[32];
Tile *itemGfx;
char destTextName[32];
char destGfxName[32];
Tile *destGfx;
char id[32];
DlvEnt() : itemGfx(NULL), destGfx(NULL) {
itemTextName[0] = 0;
itemGfxName[0] = 0;
destTextName[0] = 0;
destGfxName[0] = 0;
}
~DlvEnt() {
itemGfx = NULL;
destGfx = NULL;
}
};
struct Waypoint {
int x, y, level;
void reset() {
x = 0;
y = 0;
level = 0;
}
Waypoint() {
reset();
}
};
struct LuaT {
uint16 x, y;
uint16 value1, value2;
char luaFuncInit[32];
char luaFuncAction[32];
char luaFuncUse[32];
LuaT() : x(0), y(0), value1(0), value2(0) {
luaFuncInit[0] = 0;
luaFuncAction[0] = 0;
luaFuncUse[0] = 0;
}
};
struct ActionInfo {
uint16 x1, y1;
uint16 x2, y2;
char luaFuncInit[32];
char luaFuncUse[32];
char entityName[32];
ActionInfo() : x1(0), y1(0), x2(0), y2(0) {
luaFuncInit[0] = 0;
luaFuncUse[0] = 0;
entityName[0] = 0;
}
};
struct TeleInfo {
uint16 x1, y1;
uint16 x2, y2;
AIDir dir1;
AIDir dir2;
uint16 level1, level2;
uint16 usable1, usable2;
uint16 anim1, anim2;
char luaFuncUse1[32];
char luaFuncUse2[32];
TeleInfo() : x1(0), y1(0), x2(0), y2(0), dir1(DIR_NONE), dir2(DIR_NONE), level1(0), level2(0), usable1(0), usable2(0), anim1(0), anim2(0) {
luaFuncUse1[0] = 0;
luaFuncUse2[0] = 0;
}
};
struct SingleTele {
uint16 x, y, level, usable, anim;
AIDir dir;
SingleTele() : x(0), y(0), level(0), usable(0), anim(0), dir(DIR_NONE) {}
};
struct AutoAction {
uint16 x, y;
bool activated;
char luaFuncInit[32];
char luaFuncUse[32];
char entityName[32];
AutoAction() : x(0), y(0), activated(false) {
luaFuncInit[0] = 0;
luaFuncUse[0] = 0;
entityName[0] = 0;
}
};
struct ArrowPath {
uint16 type;
AIDir dir;
uint16 tileX, tileY;
ArrowPath() : type(0), dir(DIR_NONE), tileX(0), tileY(0) {}
};
struct HereT {
uint16 x, y;
char entName[32];
};
struct Trigger {
char id[32];
uint16 x, y;
uint16 value1, value2;
char luaFuncInit[32];
char luaFuncUse[32];
Trigger() : x(0), y(0), value1(0), value2(0) {
id[0] = 0;
luaFuncInit[0] = 0;
luaFuncUse[0] = 0;
}
};
struct CallbackDef {
CallbackType type;
void(*function)(int x, int y);
};
struct Callback {
CallbackType type;
uint16 x, y;
uint16 delay;
Callback() : type(NO_FUNCTION), x(0), y(0), delay(0) {}
};
struct Fairystone {
uint16 srcX, srcY;
uint16 destX, destY;
Fairystone() : srcX(0), srcY(0), destX(0), destY(0) {}
};
struct Bridge {
uint16 x, y;
AIDir dir;
uint16 delay;
uint16 anim;
void reset() {
x = 0;
y = 0;
dir = DIR_NONE;
delay = 0;
anim = 0;
}
Bridge() {
reset();
}
};
struct CineCommand {
CineType cmdType;
double x, y;
double x2, y2;
double xv, yv;
int start, end;
uint32 delay;
int speed;
const char *title;
const char *string;
const char *id;
AIEntity *e;
Picture *pic;
CineCommand() : cmdType(C_NO_COMMAND), x(0.0), y(0.0), x2(0.0), y2(0.0), xv(0.0), yv(0.0),
start(0), end(0), delay(0), speed(0), title(NULL), string(NULL), id(NULL), e(NULL), pic(NULL) {}
};
struct CineBlit {
double x, y;
Picture *pic;
const char *name;
const char *id;
bool masked;
CineBlit() : x(0), y(0), pic(NULL), name(NULL), id(NULL), masked(false) {}
};
#define onEvenTile(x, y) ( !(x & 31) && !(y & 31) )
#define hitPlayer(x, y) ( e->onScreen && g_hdb->_ai->checkPlayerCollision( x, y, 4 ) && !g_hdb->_ai->playerDead() )
#define cycleFrames( e, max ) \
{ \
if ( e->animDelay-- < 1 ) \
{ \
e->animDelay = e->animCycle; \
e->animFrame++; \
if ( e->animFrame >= max ) \
e->animFrame = 0; \
} \
}
#define spawnBlocking(x, y, level) g_hdb->_ai->spawn(AI_NONE, DIR_NONE, x, y, NULL, NULL, NULL, DIR_NONE, level, 0, 0, 0)
class AI {
public:
AI();
~AI();
void init();
void clearPersistent();
void restartSystem();
const char *funcLookUp(void(*function)(AIEntity *e));
FuncPtr funcLookUp(const char *function);
void save(Common::OutSaveFile *out);
void loadSaveFile(Common::InSaveFile *in);
void initAnimInfo();
// Entity Functions
AIEntity *spawn(AIType type, AIDir dir, int x, int y, const char *funcInit, const char *funcAction, const char *funcUse, AIDir dir2, int level, int value1, int value2, int callInit);
bool cacheEntGfx(AIEntity *e, bool init);
void stopEntity(AIEntity *e);
AIEntity *locateEntity(const char *luaName);
AIEntity *findEntity(int x, int y);
AIEntity *findEntityIgnore(int x, int y, AIEntity *ignore);
AIEntity *findEntityType(AIType type, int x, int y);
void getEntityXY(const char *entName, int *x, int *y);
bool useLuaEntity(const char *initName);
void removeLuaEntity(const char *initName);
void animLuaEntity(const char *initName, AIState st);
void setLuaAnimFrame(const char *initName, AIState st, int frame);
int checkForTouchplate(int x, int y);
void removeEntity(AIEntity *e);
void setEntityGoal(AIEntity *e, int x, int y);
void initAllEnts();
void killPlayer(Death method);
void stunEnemy(AIEntity *e, int time);
int metalOrFleshSND(AIEntity *e);
int tileDistance(AIEntity *e1, AIEntity *e2) {
return abs(e1->tileX - e2->tileX) + abs(e1->tileY - e2->tileY);
}
void animateEntity(AIEntity *e);
void animEntFrames(AIEntity *e);
void drawEnts(int x, int y, int w, int h);
void drawLevel2Ents();
void animGrabbing();
void entityFace(const char *luaName, int dir);
void moveEnts();
bool findPath(AIEntity *e);
AIEntity *legalMove(int tileX, int tileY, int level, int *result);
AIEntity *legalMoveOverWater(int tileX, int tileY, int level, int *result);
AIEntity *legalMoveOverWaterIgnore(int tileX, int tileY, int level, int *result, AIEntity *ignore);
void addAnimateTarget(int x, int y, int start, int end, AnimSpeed speed, bool killAuto, bool inMap, const char *tileName);
void animateTargets();
void addBridgeExtend(int x, int y, int bridgeType);
void animateBridges();
void addToFairystones(int index, int tileX, int tileY, int sourceOrDest);
int checkFairystones(int tileX, int tileY);
void getFairystonesSrc(int index, int *tileX, int *tileY) {
*tileX = _fairystones[index].srcX;
*tileY = _fairystones[index].srcY;
}
AIEntity *playerCollision(int topBorder, int bottomBorder, int leftBorder, int rightBorder);
bool checkPlayerTileCollision(int x, int y);
bool checkPlayerCollision(int x, int y, int border);
void clearDiverters();
void laserScan();
// List functions
void addToActionList(int actionIndex, int x, int y, char *funcLuaInit, char *funcLuaUse);
bool checkActionList(AIEntity *e, int x, int y, bool lookAndGrab);
void addToHereList(const char *entName, int x, int y);
HereT *findHere(int x, int y);
void addToAutoList(int x, int y, const char *luaFuncInit, const char *luaFuncUse);
void autoDeactivate(int x, int y);
bool activateAction(AIEntity *e, int x, int y, int targetX, int targetY);
bool checkAutoList(AIEntity *e, int x, int y);
bool autoActive(int x, int y);
void addCallback(CallbackType type, int x, int y, int delay);
void processCallbackList();
void addToLuaList(int x, int y, int value1, int value2, char *luaFuncInit, char *luaFuncAction, char *luaFuncUse);
bool checkLuaList(AIEntity *e, int x, int y);
bool luaExistAtXY(int x, int y);
void addToTeleportList(int teleIndex, int x, int y, int dir, int level, int anim, int usable, const char *luaFuncUse);
bool checkTeleportList(AIEntity *e, int x, int y);
bool findTeleporterDest(int tileX, int tileY, SingleTele *info);
void addToPathList(int x, int y, int type, AIDir dir);
ArrowPath *findArrowPath(int x, int y);
void addToTriggerList(char *luaFuncInit, char *luaFuncUse, int x, int y, int value1, int value2, char *id);
bool checkTriggerList(char *entName, int x, int y);
void killTrigger(const char *id);
void floatEntity(AIEntity *e, AIState state);
bool checkFloating(int x, int y);
bool getTableEnt(AIType type);
bool walkThroughEnt(AIType type);
void getItemSound(AIType type);
void lookAtEntity(AIEntity *e);
// Player Functions
void movePlayer(uint16 buttons);
void playerUse();
void setPlayerWeapon(AIType w, Tile *gfx) {
_weaponSelected = w;
_weaponGfx = gfx;
}
AIType getPlayerWeapon() {
return _weaponSelected;
}
Tile *getPlayerWeaponGfx() {
return _weaponGfx;
}
Tile *getPlayerWeaponSelGfx() {
return _weaponSelGfx;
}
AIEntity *getPlayer() {
if (!_player)
return &_dummyPlayer;
return _player;
}
void getPlayerXY(int *x, int *y) {
if (_player) {
*x = _player->x;
*y = _player->y;
} else {
*x = *y = 0;
}
}
void setPlayerXY(int x, int y) {
if (_player) {
_player->x = x;
_player->tileX = x / kTileWidth;
_player->y = y;
_player->tileY = y / kTileHeight;
_player->xVel = _player->yVel = 0;
}
}
void assignPlayer(AIEntity *p) {
_player = p;
}
bool playerDead() {
return _playerDead;
}
bool playerOnIce() {
return _playerOnIce;
}
bool playerLocked() {
return _playerLock;
}
void setPlayerLock(bool status) {
_playerLock = status;
}
void setPlayerInvisible(bool status) {
_playerInvisible = status;
}
bool playerRunning() {