-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.h
562 lines (507 loc) · 14.2 KB
/
game.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
/*
* Bermuda Syndrome engine rewrite
* Copyright (C) 2007-2011 Gregory Montoir
*/
#ifndef GAME_H__
#define GAME_H__
#include "intern.h"
#include "random.h"
#include "fs.h"
struct SceneBitmap {
uint16_t w; // x2
uint16_t h; // y2
uint16_t pitch;
uint8_t *bits;
};
struct SceneAnimation {
char name[20];
int16_t firstMotionIndex;
int16_t motionsCount;
int16_t firstObjectIndex;
int16_t objectsCount;
int16_t firstSoundBufferIndex;
int16_t soundBuffersCount;
uint8_t *scriptData;
uint16_t scriptSize;
int16_t unk26;
};
struct SceneObject {
int16_t xInit;
int16_t yInit;
int16_t x;
int16_t y;
int16_t xPrev;
int16_t yPrev;
int16_t zInit;
int16_t zPrev;
int16_t z;
int16_t frameNum;
int16_t frameNumPrev;
int16_t flipInit;
int16_t flip;
int16_t flipPrev;
int16_t motionNum; // motionStart
int16_t motionInit;
int16_t motionNum1; // motionNumPrev
int16_t motionNum2; // motionNum
int16_t motionFrameNum; // motionIdle ?
int16_t mode;
int16_t modeRndMul;
int16_t statePrev;
int16_t state;
char name[20];
char className[20];
int16_t varsTable[10];
};
struct SoundBuffer {
char filename[40];
// uint8_t *buffer; // original preload the sound
};
struct SceneObjectMotion {
int16_t firstFrameIndex;
int16_t count;
int16_t animNum;
};
struct Box {
int16_t x1;
int16_t x2;
int16_t y1;
int16_t y2;
uint8_t state;
int16_t z;
int16_t startColor;
int16_t endColor;
};
struct SceneObjectFrameHeader {
int16_t num; // 0
int16_t w; // 2
int16_t h; // 4
int16_t xPos; // 6
int16_t yPos; // 8
};
struct SceneObjectFrame {
uint8_t *data;
SceneObjectFrameHeader hdr;
};
struct BagObject {
char name[20];
uint8_t *data;
uint32_t dataSize; // not in the original
};
struct NextScene {
int16_t num;
char name[20];
};
struct SceneObjectStatus {
int16_t x;
int16_t y;
int16_t z;
int16_t motionNum;
int16_t frameNum;
int16_t flip;
};
struct Script {
uint8_t *data;
int dataOffset;
int testDataOffset;
int currentObjectNum;
bool objectFound;
int testObjectNum;
int nextScene;
int statementNum;
int16_t fetchNextWord() {
int16_t word = READ_LE_UINT16(data + dataOffset);
dataOffset += 2;
return word;
}
const char *fetchNextString() {
int len = fetchNextWord();
assert(len >= 1);
const char *str = (const char *)(data + dataOffset);
dataOffset += len;
assert(len >= 1 && str[len - 1] == '\0');
return str;
}
const char *getString() {
return (const char *)(data + dataOffset);
}
};
struct DialogueChoice {
char *id;
bool gotoFlag;
char *nextId;
char *speechSoundFile;
char *text;
};
struct Game;
struct GameConditionOpcode {
int num;
bool (Game::*pf)();
};
struct GameOperatorOpcode {
int num;
void (Game::*pf)();
};
enum {
kActionTake = 0,
kActionTalk = 1,
kActionGirl = 2,
kActionUseObject = 3,
};
enum {
kObjectFlipY = 1,
kObjectFlipX = 2
};
enum {
kVarHasSword = 1,
kVarHasGun = 2,
kVarAmmo = 3
};
enum {
kLeftMouseButton = 1 << 0,
kRightMouseButton = 1 << 1
};
enum {
kStateInit,
kStateGame,
kStateBag,
kStateDialogue,
kStateBitmapSequence,
};
enum {
kCycleDelay = 50,
kGameScreenWidth = 640,
kGameScreenHeight = 480,
kOffsetBitmapInfo = 0,
kOffsetBitmapPalette = kOffsetBitmapInfo + 40,
kOffsetBitmapBits = kOffsetBitmapPalette + 256 * 4,
kBitmapBufferDefaultSize = 40 + 256 * 4 + 640 * 480 + 256 * 4
};
static inline int getBitmapWidth(const uint8_t *p) {
return READ_LE_UINT16(p) + 1;
}
static inline int getBitmapHeight(const uint8_t *p) {
return READ_LE_UINT16(p + 2) + 1;
}
static inline int getBitmapSize(const uint8_t *p) {
int sz = 4 + getBitmapWidth(p) * getBitmapHeight(p);
return sz;
}
static inline const uint8_t *getBitmapData(const uint8_t *p) {
return p + 4;
}
static inline bool boxInRect(Box *box, int rect_x1, int rect_x2, int rect_y1, int rect_y2) {
assert(box->x1 <= box->x2 && box->y1 <= box->y2);
const int xmin = MIN(rect_x1, rect_x2);
const int xmax = MAX(rect_x1, rect_x2);
const int ymin = MIN(rect_y1, rect_y2);
const int ymax = MAX(rect_y1, rect_y2);
return box->x1 <= xmax && box->x2 >= xmin && box->y1 <= ymax && box->y2 >= ymin;
}
struct Mixer;
struct SystemStub;
struct Game {
enum {
NUM_VARS = 310,
NUM_BOXES = 20,
NUM_SCENE_OBJECT_FRAMES = 3000,
NUM_SCENE_MOTIONS = 300,
NUM_SOUND_BUFFERS = 80,
NUM_SCENE_OBJECTS = 50,
NUM_SCENE_ANIMATIONS = 50,
NUM_BAG_OBJECTS = 20,
NUM_NEXT_SCENES = 20,
NUM_SCENE_OBJECT_STATUS = 200,
NUM_DIALOG_CHOICES = 10,
NUM_DIALOG_ENTRIES = 40
};
Game(SystemStub *stub, const char *dataPath, const char *savePath, const char *musicPath);
~Game();
SceneObject *derefSceneObject(int i) {
assert(i >= 0 && i < _sceneObjectsCount);
return &_sceneObjectsTable[i];
}
Box *derefBox(int i, int j) {
assert(i >= 0 && i < NUM_BOXES && j >= 0 && j < 10);
return &_boxesTable[i][j];
}
SceneObjectStatus *derefSceneObjectStatus(int i) {
assert(i >= 0 && i < NUM_SCENE_OBJECT_STATUS);
return &_sceneObjectStatusTable[i];
}
SceneObjectFrame *derefSceneObjectFrame(int i) {
assert(i >= 0 && i < _sceneObjectFramesCount);
return &_sceneObjectFramesTable[i];
}
// bag.cpp
void handleBagMenu();
void drawBagMenu(int xPosWnd, int yPosWnd);
// dialogue.cpp
void unloadDialogueData();
void setupDialog(const char *code);
void loadDialogueSprite(int spr);
void loadDialogueData(const char *filename);
void redrawDialogueSprite(int num);
void redrawDialogueBackground();
void redrawDialogueTexts();
void initDialogue();
void finiDialogue();
void handleDialogue();
// game.cpp
void detectVersion();
void restart();
void init();
void fini();
void mainLoop();
void updateMouseButtonsPressed();
void updateKeysPressedTable();
void setupScreenPalette(const uint8_t *src);
void clearSceneData(int anim);
void reinitializeObject(int object);
void updateObjects();
void runObjectsScript();
int findBagObjectByName(const char *objectName) const;
int getObjectTranslateXPos(int object, int dx1, int div, int dx2);
int getObjectTranslateYPos(int object, int dy1, int div, int dy2);
int findObjectByName(int currentObjectNum, int defaultObjectNum, bool *objectFlag);
void sortObjects();
void copyBufferToBuffer(int x, int y, int w, int h, SceneBitmap *src, SceneBitmap *dst);
void drawBox(int x, int y, int w, int h, SceneBitmap *src, SceneBitmap *dst, int startColor, int endColor);
void drawObject(int x, int y, const uint8_t *src, SceneBitmap *dst);
void drawObjectVerticalFlip(int x, int y, const uint8_t *src, SceneBitmap *dst);
void redrawObjectBoxes(int previousObject, int currentObject);
void redrawObjects();
void playVideo(const char *name);
void drawBitmapSequenceDemo(int num);
void stopMusic();
void playMusic(const char *name);
void changeObjectMotionFrame(int object, int object2, int useObject2, int count1, int count2, int useDx, int dx, int useDy, int dy);
int16_t getObjectTransformXPos(int object);
int16_t getObjectTransformYPos(int object);
bool comparePrevObjectTransformXPos(int object, bool fetchCmp = true, int cmpX = -1);
bool compareObjectTransformXPos(int object, bool fetchCmp = true, int cmpX = -1);
bool comparePrevObjectTransformYPos(int object, bool fetchCmp = true, int cmpY = -1);
bool compareObjectTransformYPos(int object, bool fetchCmp = true, int cmpY = -1);
void setupObjectPos(int object, int object2, int useObject2, int useData, int type1, int type2);
bool intersectsBox(int num, int index, int x1, int y1, int x2, int y2);
// opcodes.cpp
const GameConditionOpcode *findConditionOpcode(int num) const;
const GameOperatorOpcode *findOperatorOpcode(int num) const;
void evalExpr(int16_t *val);
bool testExpr(int16_t val);
bool cop_true();
bool cop_isInRandomRange();
bool cop_isKeyPressed();
bool cop_isKeyNotPressed();
bool cop_testMouseButtons();
bool cop_isObjectInScene();
bool cop_testObjectPrevState();
bool cop_testObjectState();
bool cop_isObjectInRect();
bool cop_testPrevObjectTransformXPos();
bool cop_testObjectTransformXPos();
bool cop_testPrevObjectTransformYPos();
bool cop_testObjectTransformYPos();
bool cop_testObjectPrevFlip();
bool cop_testObjectFlip();
bool cop_testObjectPrevFrameNum();
bool cop_testObjectFrameNum();
bool cop_testPrevMotionNum();
bool cop_testMotionNum();
bool cop_testObjectVar();
bool cop_testObjectAndObjectXPos();
bool cop_testObjectAndObjectYPos();
bool cop_testObjectMotionYPos();
bool cop_testVar();
bool cop_isCurrentBagAction();
bool cop_isObjectInBox();
bool cop_isObjectNotInBox();
bool cop_isObjectNotIntersectingBox();
bool cop_isCurrentBagObject();
bool cop_isLifeBarDisplayed();
bool cop_isLifeBarNotDisplayed();
bool cop_testLastDialogue();
bool cop_isNextScene();
void oop_initializeObject();
void oop_evalCurrentObjectX();
void oop_evalCurrentObjectY();
void oop_evalObjectX();
void oop_evalObjectY();
void oop_evalObjectZ();
void oop_setObjectFlip();
void oop_adjustObjectPos_vv0000();
void oop_adjustObjectPos_vv1v00();
void oop_adjustObjectPos_vv1v1v();
void oop_setupObjectPos_121();
void oop_setupObjectPos_122();
void oop_setupObjectPos_123();
void oop_adjustObjectPos_1v0000();
void oop_adjustObjectPos_1v1v1v();
void oop_setupObjectPos_021();
void oop_setupObjectPos_022();
void oop_setupObjectPos_023();
void oop_evalObjectVar();
void oop_translateObjectXPos();
void oop_translateObjectYPos();
void oop_setObjectMode();
void oop_setObjectInitPos();
void oop_setObjectTransformInitPos();
void oop_evalObjectXInit();
void oop_evalObjectYInit();
void oop_evalObjectZInit();
void oop_setObjectFlipInit();
void oop_setObjectCel();
void oop_resetObjectCel();
void oop_evalVar();
void oop_getSceneNumberInVar();
void oop_disableBox();
void oop_enableBox();
void oop_evalBoxesXPos();
void oop_evalBoxesYPos();
void oop_setBoxToObject();
void oop_clipBoxes();
void oop_saveObjectStatus();
void oop_addObjectToBag();
void oop_removeObjectFromBag();
void oop_playSoundLowerEqualPriority();
void oop_playSoundLowerPriority();
void oop_startDialogue();
void oop_switchSceneClearBoxes();
void oop_switchSceneCopyBoxes();
// parser_scn.cpp
void parseSCN(const char *fileName);
// parser_dlg.cpp
void parseDLG();
// resource.cpp
void allocateTables();
void deallocateTables();
void loadCommonSprites();
void unloadCommonSprites();
uint8_t *loadFile(const char *fileName, uint8_t *dst = 0, uint32_t *dstSize = 0);
void loadWGP(const char *fileName);
void loadSPR(const char *fileName, SceneAnimation *sa);
void loadMOV(const char *fileName);
// saveload.cpp
void saveState(int slot);
void loadState(int slot, bool switchScene);
// win16.cpp (temporary helpers)
int win16_sndPlaySound(int op, void *data = 0);
void win16_stretchBits(SceneBitmap *bits, int srcHeight, int srcWidth, int srcY, int srcX, int dstHeight, int dstWidth, int dstY, int dstX);
int _nextState, _state;
bool _isDemo;
const char *_startupScene;
FileSystem _fs;
RandomGenerator _rnd;
SystemStub *_stub;
Mixer *_mixer;
const char *_dataPath;
const char *_savePath;
const char *_musicPath;
int _stateSlot;
int _mixerSoundId;
int _mixerMusicId;
uint32_t _lastFrameTimeStamp;
int _bitmapSequence;
uint8_t *_bitmapBuffer0;
SceneBitmap _bitmapBuffer1;
uint8_t *_bitmapBuffer2;
SceneBitmap _bitmapBuffer3;
uint8_t *_bermudaOvrData;
uint8_t *_tempDecodeBuffer;
SceneBitmap _bagBackgroundImage;
uint8_t *_bermudaSprData;
uint8_t *_bermudaSprDataTable[3];
// inventory
uint8_t *_lifeBarImageTable[11][12];
uint8_t *_weaponIconImageTable[14];
uint8_t *_ammoIconImageTable[2][5];
uint8_t *_swordIconImage;
uint8_t *_iconBackgroundImage;
uint8_t *_lifeBarImage;
uint8_t *_bagObjectAreaBlinkImageTable[10];
int _bagObjectAreaBlinkCounter;
uint8_t *_bagWeaponAreaBlinkImageTable[10];
int _bagWeaponAreaBlinkCounter;
int _lifeBarCurrentFrame;
int _bagObjectW, _bagObjectH;
// dialogue
int _lastDialogueEndedId;
int _dialogueEndedFlag;
int _dialogueSpriteIndex;
int _dialogueSpriteFrameCountTable[3];
int _dialogueSpriteCurrentFrameTable[3];
int _dialogueChoiceSelected;
uint8_t *_dialogueSpriteDataTable[3][105];
int _dialogueSpeechIndex;
int _loadDialogueDataState;
int _dialogueDescriptionSize;
char *_dialogueDescriptionBuffer;
DialogueChoice _dialogueChoiceData[NUM_DIALOG_ENTRIES];
int _dialogueChoiceSize;
bool _dialogueChoiceGotoFlag[NUM_DIALOG_CHOICES];
char *_dialogueChoiceText[NUM_DIALOG_CHOICES];
char *_dialogueChoiceSpeechSoundFile[NUM_DIALOG_CHOICES];
char *_dialogueChoiceNextId[NUM_DIALOG_CHOICES];
int _dialogueChoiceCounter;
uint8_t *_dialogueFrameSpriteData;
Rect _dialogueTextRect;
// logic
int _sceneDescriptionSize;
char *_sceneDescriptionBuffer;
Script _objectScript;
int16_t _defaultVarsTable[NUM_VARS];
int16_t _varsTable[NUM_VARS];
const char *_scriptDialogId;
const char *_scriptDialogFileName;
const char *_scriptDialogSprite1;
const char *_scriptDialogSprite2;
bool _switchScene;
bool _startDialogue;
bool _loadState;
bool _clearSceneData;
bool _gameOver;
int _loadDataState;
int _currentBagAction;
int _previousBagAction;
int _currentBagObject;
int _previousBagObject;
bool _workaroundRaftFlySceneBug;
int _currentPlayingSoundPriority;
bool _lifeBarDisplayed;
bool _lifeBarDisplayed2;
uint8_t _keysPressed[128];
int _mouseButtonsPressed;
int _musicTrack; // useless, always equal to 0
char _musicName[40];
int _sceneNumber;
char _currentSceneWgp[128];
char _tempTextBuffer[128];
char _currentSceneScn[128];
int _bagPosX, _bagPosY;
SceneObject *_sortedSceneObjectsTable[NUM_SCENE_OBJECTS];
SceneObject _sceneObjectsTable[NUM_SCENE_OBJECTS];
int _sceneObjectsCount;
SceneAnimation _animationsTable[NUM_SCENE_ANIMATIONS];
int _animationsCount;
SoundBuffer _soundBuffersTable[NUM_SOUND_BUFFERS];
int _soundBuffersCount;
Box _boxesTable[NUM_BOXES][10];
int _boxesCountTable[NUM_BOXES];
SceneObjectFrame _sceneObjectFramesTable[NUM_SCENE_OBJECT_FRAMES];
int _sceneObjectFramesCount;
BagObject _bagObjectsTable[NUM_BAG_OBJECTS];
int _bagObjectsCount;
SceneObjectMotion _sceneObjectMotionsTable[NUM_SCENE_MOTIONS];
int _sceneObjectMotionsCount;
NextScene _nextScenesTable[NUM_NEXT_SCENES];
int _sceneConditionsCount;
SceneObjectStatus _sceneObjectStatusTable[NUM_SCENE_OBJECT_STATUS];
int _sceneObjectStatusCount;
static const GameConditionOpcode _conditionOpTable[];
static const int _conditionOpCount;
static const GameOperatorOpcode _operatorOpTable[];
static const int _operatorOpCount;
static const uint16_t _fontData[];
static const uint8_t _fontCharWidth[];
};
#endif // GAME_H__