ScummVM API documentation
lilliput.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef LILLIPUT_LILLIPUT_H
23 #define LILLIPUT_LILLIPUT_H
24 
25 #include "lilliput/console.h"
26 #include "lilliput/script.h"
27 #include "lilliput/sound.h"
28 #include "lilliput/stream.h"
29 #include "lilliput/detection.h"
30 
31 #include "common/file.h"
32 #include "common/rect.h"
33 #include "common/events.h"
34 
35 #include "engines/engine.h"
36 #include "graphics/surface.h"
37 
38 namespace Common {
39 class RandomSource;
40 }
41 
52 namespace Lilliput {
53 
54 static const int kSavegameVersion = 1;
55 
56 enum LilliputDebugChannels {
57  kDebugEngine = 1 << 0,
58  kDebugScript = 1 << 1,
59  kDebugSound = 1 << 2,
60  kDebugEngineTBC = 1 << 3,
61  kDebugScriptTBC = 1 << 4
62 };
63 
64 enum InterfaceHotspotStatus {
65  kHotspotOff = 0,
66  kHotspotDisabled = 1,
67  kHotspotEnabled = 2,
68  kHotspotSelected = 3
69 };
70 
71 #define kSeqNone 0
72 #define kSeqNoInc 1 << 0
73 #define kSeqRepeat 1 << 1
74 
75 struct LilliputGameDescription;
76 
77 struct SmallAnim {
78  bool _active;
79  Common::Point _pos;
80  int16 _frameIndex[8];
81 };
82 
83 class LilliputEngine : public Engine {
84 public:
86  ~LilliputEngine() override;
87 
88  OSystem *_system;
89 
91  LilliputScript *_scriptHandler;
92  LilliputSound *_soundHandler;
93  Graphics::Surface *_mainSurface;
94 
95  SmallAnim _smallAnims[4];
96  int _smallAnimsFrameIndex;
97 
98  byte _handleOpcodeReturnCode;
99  byte _keyDelay;
100  byte _lastAnimationTick;
101  byte _animationTick;
102  Common::Point _nextDisplayCharacterPos;
103  byte _int8Timer;
104  Common::Event _lastKeyPressed;
105  Common::EventType _lastEventType;
106  byte _keyboard_nextIndex;
107  byte _keyboard_oldIndex;
108  Common::Event _keyboard_buffer[8];
109  byte _byte12A05;
110  bool _refreshScreenFlag;
111  byte _byte16552;
112  int8 _lastInterfaceHotspotIndex;
113  byte _lastInterfaceHotspotButton; // Unused: set by 2 functions, but never used elsewhere
114  byte _debugFlag; // Mostly useless, as the associated functions are empty
115  byte _debugFlag2; // Unused byte, set by an opcode
116 
117  byte _codeEntered[3];
118  char _homeInDirLikelyhood[4];
119  byte *_bufferIsoMap;
120  byte *_bufferCubegfx;
121  byte *_bufferMen;
122  byte *_bufferMen2;
123  byte *_bufferIsoChars;
124  byte *_bufferIdeogram;
125  byte *_normalCursor;
126  byte *_greenCursor;
127  byte _curPalette[768];
128  byte _displayStringBuf[160];
129 
130  bool _saveFlag;
131  bool _displayMap;
132 
133  int _word10800_ERULES;
134  byte _numCharacters;
135  Common::Point _currentScriptCharacterPos;
136  int _nextCharacterIndex;
137  int8 _waitingSignal;
138  int8 _waitingSignalCharacterId;
139  uint16 _newModesEvaluatedNumber;
140  Common::Point _savedSurfaceUnderMousePos;
141  bool _displayGreenHand;
142  bool _isCursorGreenHand;
143  int _currentDisplayCharacter;
144  int _displayStringIndex;
145  int _signalTimer;
146  Common::Point _curCharacterTilePos;
147 
148  int16 _mapSavedPixelIndex[40];
149  byte _mapSavedPixel[40];
150  int16 _characterSignals[40];
151  int16 _signalArr[40];
152  int16 _signalArray[30];
153 
154  byte *_sequencesArr;
155  int16 _currentScriptCharacter;
156  Common::Point _characterPos[40];
157  int8 _characterPosAltitude[40];
158  int16 _characterFrameArray[40];
159  int8 _characterCarried[40];
160  int8 _characterBehindDist[40];
161  byte _characterAboveDist[40];
162  byte _spriteSizeArray[40];
163  byte _characterDirectionArray[40];
164  byte _characterMobility[40];
165  byte _characterTypes[40];
166  byte _characterBehaviour[40];
167  Common::Point _characterHomePos[40];
168  byte _characterVariables[1400 + 3120];
169  byte *_currentCharacterAttributes;
170  byte _poseArray[40 * 32];
171  int *_packedStringIndex;
172  int _packedStringNumb;
173  char *_packedStrings;
174  byte *_initScript;
175  int _initScriptSize;
176  byte *_menuScript;
177  int _menuScriptSize;
178  int *_arrayGameScriptIndex;
179  int _gameScriptIndexSize;
180  byte *_arrayGameScripts;
181  byte _cubeFlags[60];
182  byte _listNumb;
183  int16 *_listIndex;
184  byte *_listArr;
185  int16 _rectNumb;
186  Common::Rect _enclosureRect[40];
187  Common::Point _keyPos[40];
188  Common::Point _portalPos[40];
189  int _interfaceHotspotNumb;
190  byte _interfaceTwoStepAction[20];
191  Common::Point _interfaceHotspots[20];
192  Common::KeyCode _keyboardMapping[20];
193  Common::Point _characterTargetPos[40];
194  byte _savedSurfaceUnderMouse[16 * 16];
195  byte _charactersToDisplay[40];
196  Common::Point _characterRelativePos[40];
197  Common::Point _characterDisplay[40];
198  int8 _characterMagicPuffFrame[40];
199  Common::Point _characterSubTargetPos[40];
200  byte _specialCubes[40];
201  byte _doorEntranceMask[4];
202  byte _doorExitMask[4];
203  byte _savedSurfaceGameArea1[176 * 256]; // 45056
204  byte _savedSurfaceGameArea2[176 * 256]; // 45056
205  byte _savedSurfaceGameArea3[176 * 256]; // 45056
206  byte _savedSurfaceSpeech[16 * 252];
207 
208  const LilliputGameDescription *_gameDescription;
209  uint32 getFeatures() const;
210  const char *getGameId() const;
211 
212  void newInt8();
213  void update();
214 
215  void display16x16IndexedBuf(byte *buf, int index, Common::Point pos, bool transparent = true, bool updateScreen = true);
216  void display16x16Buf(byte *buf, Common::Point pos, bool transparent = true, bool updateScreen = true);
217  void fill16x16Rect(byte col, Common::Point pos);
218  void saveSurfaceGameArea();
219  void saveSurfaceSpeech();
220  void displayInterfaceHotspots();
221  void displayLandscape();
222  void displaySpeechBubble();
223  void displaySpeech(byte *buf);
224  void initGameAreaDisplay();
225  void displayIsometricBlock(byte *buf, int var1, int posX, int posY, int var3);
226  void displayGameArea();
227  void prepareGameArea();
228  void displayRefreshScreen();
229  void restoreSurfaceSpeech();
230  void displayCharacterStatBar(int8 type, int16 averagePosX, int8 score, int16 posY);
231  void displayCharacter(int index, Common::Point pos, int flags);
232  void displayString(byte *buf, Common::Point pos);
233  void displayChar(int index, int var1);
234  void displaySmallAnims();
235  void displaySmallIndexedAnim(byte index, byte subIndex);
236 
237  void unselectInterfaceHotspots();
238  void startNavigateFromMap();
239  void resetSmallAnims();
240  void paletteFadeOut();
241  void paletteFadeIn();
242 
243  void sortCharacters();
244  void scrollToViewportCharacterTarget();
245  void viewportScrollTo(Common::Point goalPos);
246  void checkSpeechClosing();
247  void updateCharPosSequence();
248  void evaluateDirections(int index);
249  byte homeInAvoidDeadEnds(int indexb, int indexs);
250  void signalDispatcher(byte type, byte index, int var4);
251  void sendMessageToCharacter(byte index, int var4);
252  int16 checkEnclosure(Common::Point pos);
253  int16 checkOuterEnclosure(Common::Point pos);
254  byte sequenceSetMobility(int index, Common::Point var1);
255  byte sequenceEnd(int index);
256  void homeInPathFinding(int index);
257 
258  void renderCharacters(byte *buf, Common::Point pos);
259 
260  void checkNumericCode();
261  void keyboard_handleInterfaceShortcuts(bool &forceReturnFl);
262  byte sequenceCharacterHomeIn(int index, Common::Point param1);
263  byte getDirection(Common::Point param1, Common::Point param2);
264  void addCharToBuf(byte character);
265  void numberToString(int param1);
266  void handleCharacterTimers();
267  byte sequenceMoveCharacter(int idx, int moveType, int poseType);
268  void setCharacterPose(int idx, int poseIdx);
269  void checkSpecialCubes();
270  void checkInteractions();
271  byte sequenceSetCharacterDirection(int index, int direction, int poseType);
272  void handleSignals();
273  void checkInterfaceActivationDelay();
274  int16 checkObstacle(int x1, int y1, int x2, int y2);
275  void displayCharactersOnMap();
276  void restoreMapPoints();
277  void displayHeroismIndicator();
278  void handleGameMouseClick();
279  void handleInterfaceHotspot(byte index, byte button);
280  void checkInterfaceHotspots(bool &forceReturnFl);
281  bool isMouseOverHotspot(Common::Point mousePos, Common::Point hotspotPos);
282  void checkClickOnCharacter(Common::Point pos, bool &forceReturnFl);
283  void checkClickOnGameArea(Common::Point pos);
284  void displaySpeechBubbleTail(Common::Point displayPos);
285  void displaySpeechBubbleTailLine(Common::Point pos, int var2);
286  void displaySpeechLine(int vgaIndex, byte *srcBuf, int &bufIndex);
287  void checkMapClosing(bool &forceReturnFl);
288  void turnCharacter1(int index);
289  void turnCharacter2(int index);
290  void moveCharacterUp1(int index);
291  void moveCharacterUp2(int index);
292  void moveCharacterDown1(int index);
293  void moveCharacterDown2(int index);
294  void moveCharacterSpeed2(int index);
295  void moveCharacterSpeed4(int index);
296  void moveCharacterBack2(int index);
297  void moveCharacterSpeed3(int index);
298  void moveCharacterForward(int index, int16 speed);
299  void checkCollision(int index, Common::Point pos, int direction);
300  byte sequenceSeekMovingCharacter(int index, Common::Point var1);
301  byte sequenceSound(int index, Common::Point var1);
302  byte sequenceRepeat(int index, Common::Point var1, int tmpVal);
303  void homeInChooseDirection(int index);
304 
305  void initGame(const LilliputGameDescription *gd);
306  byte *loadVGA(const Common::Path &filename, int fileSize, bool loadPal);
307  byte *loadRaw(const Common::Path &filename, int filesize);
308  void loadRules();
309 
310  void displayVGAFile(const Common::Path &fileName);
311  void initPalette();
312  void fixPaletteEntries(uint8 *palette, int num);
313 
314  GameType getGameType() const;
315  Common::Platform getPlatform() const;
316 
317  bool hasFeature(EngineFeature f) const override;
318  const char *getCopyrightString() const;
319 
320  Common::String getSavegameFilename(int slot);
321  void syncSoundSettings() override;
322 
323  Common::Point _mousePos;
324  Common::Point _oldMousePos;
325  Common::Point _mouseDisplayPos;
326  int _mouseButton;
327  bool _mouseClicked;
328  Common::EventType _mousePreviousEventType;
329  Common::Point _savedMousePosDivided;
330  int _skipDisplayFlag1;
331  int _skipDisplayFlag2;
332 
333  byte _actionType;
334  bool _delayedReactivationAction;
335  int8 _selectedCharacterId;
336  byte _numCharactersToDisplay;
337  int16 _host;
338  bool _shouldQuit;
339 
340  void pollEvent();
341  void setCurrentCharacter(int index);
342  void unselectInterfaceButton();
343  void moveCharacters();
344  void setNextDisplayCharacter(int var1);
345  void handleGameScripts();
346 
347  // Added by Strangerke
348  byte *getCharacterAttributesPtr(int16 index);
349 
350  // Temporary stubs
351  Common::Event _keyboard_getch();
352  bool _keyboard_checkKeyboard();
353  void _keyboard_resetKeyboardBuffer();
354 
355 protected:
356  Common::EventManager *_eventMan;
357  int _lastTime;
358 
359  // Engine APIs
360  Common::Error run() override;
361  void handleMenu();
362 
363 private:
364  static LilliputEngine *s_Engine;
365 
366  GameType _gameType;
367  Common::Platform _platform;
368 
369  void initialize();
370 };
371 
372 } // End of namespace Lilliput
373 
374 #endif
Definition: str.h:59
Definition: console.h:27
Definition: surface.h:66
EngineFeature
Definition: engine.h:250
Definition: error.h:84
EventType
Definition: events.h:48
Definition: random.h:44
Definition: rect.h:144
Definition: path.h:52
Definition: sound.h:36
Definition: lilliput.h:77
Definition: events.h:198
Definition: algorithm.h:29
Definition: rect.h:45
Definition: lilliput.h:83
Definition: script.h:70
Definition: system.h:167
Definition: events.h:471
Definition: engine.h:143
Platform
Definition: platform.h:46
Definition: detection.h:35