ScummVM API documentation
kyra_v2.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 KYRA_KYRA_V2_H
23 #define KYRA_KYRA_V2_H
24 
25 #include "kyra/kyra_v1.h"
26 #include "kyra/gui/gui_v1.h"
27 #include "kyra/graphics/wsamovie.h"
28 #include "kyra/engine/item.h"
29 
30 #include "common/list.h"
31 #include "common/hashmap.h"
32 
33 namespace Kyra {
34 
35 struct FrameControl {
36  uint16 index;
37  uint16 delay;
38 };
39 
41  Item itemIndex;
42  uint8 numFrames;
43  const FrameControl *frames;
44 };
45 
47  uint16 currentFrame;
48  uint32 nextFrameTime;
49 };
50 
51 class Screen_v2;
52 
53 class KyraEngine_v2 : public KyraEngine_v1 {
54 friend class Debugger_v2;
55 friend class GUI_v2;
56 public:
57  struct EngineDesc {
58  // Generic shape related
59  int itemShapeStart;
60  const uint8 *characterFrameTable;
61 
62  // Scene script
63  int firstAnimSceneScript;
64 
65  // Animation script specific
66  int animScriptFrameAdd;
67 
68  // Item specific
69  Item maxItemId;
70  };
71 
72  KyraEngine_v2(OSystem *system, const GameFlags &flags, const EngineDesc &desc);
73  ~KyraEngine_v2() override;
74 
75  void pauseEngineIntern(bool pause) override;
76 
77  virtual Screen_v2 *screen_v2() const = 0;
78 
79  void delay(uint32 time, bool update = false, bool isMainLoop = false) override;
80 
81  const EngineDesc &engineDesc() const { return _desc; }
82 protected:
83  EngineDesc _desc;
84 
85  // run
86  uint32 _pauseStart;
87  bool _runFlag;
88  bool _showOutro;
89 
90  virtual void update() = 0;
91  virtual void updateWithText() = 0;
92 
93  // detection
94  int _lang;
95  const int _numLang;
96  int _langIntern;
97 
98  // Input
99  virtual int inputSceneChange(int x, int y, int unk1, int unk2) = 0;
100 
101  // Animator
102  struct AnimObj {
103  uint16 index;
104  uint16 type;
105  bool enabled;
106  uint16 needRefresh;
107  uint16 specialRefresh;
108  uint16 animFlags;
109  uint16 flags;
110  int16 xPos1, yPos1;
111  uint8 *shapePtr;
112  uint16 shapeIndex1;
113  uint16 animNum;
114  uint16 shapeIndex3;
115  uint16 shapeIndex2;
116  int16 xPos2, yPos2;
117  int16 xPos3, yPos3;
118  int16 width, height;
119  int16 width2, height2;
120  uint16 palette;
121  AnimObj *nextObject;
122  };
123 
124  void allocAnimObjects(int actors, int anims, int items);
125  AnimObj *_animObjects;
126 
127  AnimObj *_animActor;
128  AnimObj *_animAnims;
129  AnimObj *_animItems;
130 
131  bool _drawNoShapeFlag;
132  AnimObj *_animList;
133 
134  AnimObj *initAnimList(AnimObj *list, AnimObj *entry);
135  AnimObj *addToAnimListSorted(AnimObj *list, AnimObj *entry);
136  AnimObj *deleteAnimListEntry(AnimObj *list, AnimObj *entry);
137 
138  virtual void refreshAnimObjects(int force) = 0;
139  void refreshAnimObjectsIfNeed();
140 
141  void flagAnimObjsSpecialRefresh();
142  void flagAnimObjsForRefresh();
143 
144  virtual void clearAnimObjects() = 0;
145 
146  virtual void drawAnimObjects() = 0;
147  virtual void drawSceneAnimObject(AnimObj *obj, int x, int y, int drawLayer) = 0;
148  virtual void drawCharacterAnimObject(AnimObj *obj, int x, int y, int drawLayer) = 0;
149 
150  virtual void updateCharacterAnim(int) = 0;
151  virtual void updateSceneAnim(int anim, int newFrame) = 0;
152 
153  void addItemToAnimList(int item);
154  void deleteItemAnimEntry(int item);
155 
156  virtual void animSetupPaletteEntry(AnimObj *){}
157 
158  virtual void setCharacterAnimDim(int w, int h) = 0;
159  virtual void resetCharacterAnimDim() = 0;
160 
161  virtual int getScale(int x, int y) = 0;
162 
163  uint8 *_screenBuffer;
164 
165  // Scene
166  struct SceneDesc {
167  char filename1[10];
168  char filename2[10];
169 
170  uint16 exit1, exit2, exit3, exit4;
171  uint8 flags;
172  uint8 sound;
173  };
174 
175  SceneDesc *_sceneList;
176  int _sceneListSize;
177  uint16 _currentScene;
178 
179  uint16 _sceneExit1, _sceneExit2, _sceneExit3, _sceneExit4;
180  int _sceneEnterX1, _sceneEnterY1, _sceneEnterX2, _sceneEnterY2,
181  _sceneEnterX3, _sceneEnterY3, _sceneEnterX4, _sceneEnterY4;
182  int _specialExitCount;
183  uint16 _specialExitTable[25];
184  bool checkSpecialSceneExit(int num, int x, int y);
185 
186  bool _overwriteSceneFacing;
187 
188  virtual void enterNewScene(uint16 newScene, int facing, int unk1, int unk2, int unk3) = 0;
189 
190  void runSceneScript6();
191 
192  EMCData _sceneScriptData;
193  EMCState _sceneScriptState;
194 
195  virtual int trySceneChange(int *moveTable, int unk1, int unk2) = 0;
196 
197  // Animation
198  virtual void restorePage3() = 0;
199 
200  struct SceneAnim {
201  uint16 flags;
202  int16 x, y;
203  int16 x2, y2;
204  int16 width, height;
205  uint16 specialSize;
206  int16 shapeIndex;
207  uint16 wsaFlag;
208  char filename[14];
209  };
210 
211  SceneAnim _sceneAnims[16];
212  WSAMovie_v2 *_sceneAnimMovie[16];
213 
214  void freeSceneAnims();
215 
216  bool _specialSceneScriptState[10];
217  bool _specialSceneScriptStateBackup[10];
218  EMCState _sceneSpecialScripts[10];
219  uint32 _sceneSpecialScriptsTimer[10];
220  int _lastProcessedSceneScript;
221  bool _specialSceneScriptRunFlag;
222 
223  void updateSpecialSceneScripts();
224 
225  // Sequences
226  EMCData _animationScriptData;
227  EMCState _animationScriptState;
228  Common::Array<const Opcode *> _opcodesAnimation;
229 
230  void runAnimationScript(const char *filename, int allowSkip, int resetChar, int newShapes, int shapeUnload);
231 
232  int o2a_setAnimationShapes(EMCState *script);
233  int o2a_setResetFrame(EMCState *script);
234 
235  char _animShapeFilename[14];
236 
237  uint8 *_animShapeFiledata;
238  int _animShapeCount;
239  int _animShapeLastEntry;
240 
241  int _animNewFrame;
242  int _animDelayTime;
243 
244  int _animResetFrame;
245 
246  int _animShapeWidth, _animShapeHeight;
247  int _animShapeXAdd, _animShapeYAdd;
248 
249  bool _animNeedUpdate;
250 
251  virtual int initAnimationShapes(uint8 *filedata) = 0;
252  void processAnimationScript(int allowSkip, int resetChar);
253  virtual void uninitAnimationShapes(int count, uint8 *filedata) = 0;
254 
255  // Shapes
257  ShapeMap _gameShapes;
258 
259  uint8 *getShapePtr(int index) const;
260  void addShapeToPool(const uint8 *data, int realIndex, int shape);
261  void addShapeToPool(uint8 *shpData, int index);
262  void remShapeFromPool(int idx);
263 
264  int _characterShapeFile;
265  virtual void loadCharacterShapes(int shapes) = 0;
266 
267  // pathfinder
268  int _movFacingTable[600];
269  int _pathfinderFlag;
270  bool _smoothingPath;
271 
272  int findWay(int curX, int curY, int dstX, int dstY, int *moveTable, int moveTableSize) override;
273 
274  bool directLinePassable(int x, int y, int toX, int toY);
275 
276  int pathfinderInitPositionTable(int *moveTable);
277  int pathfinderAddToPositionTable(int index, int v1, int v2);
278  int pathfinderInitPositionIndexTable(int tableLen, int x, int y);
279  int pathfinderAddToPositionIndexTable(int index, int v);
280  void pathfinderFinializePath(int *moveTable, int unk1, int x, int y, int moveTableSize);
281 
282  int _pathfinderPositionTable[400];
283  int _pathfinderPositionIndexTable[200];
284 
285  // items
286  struct ItemDefinition {
287  Item id;
288  uint16 sceneId;
289  int16 x;
290  uint8 y;
291  };
292 
293  void initItemList(int size);
294 
295  Item _hiddenItems[100];
296 
297  ItemDefinition *_itemList;
298  int _itemListSize;
299 
300  int _itemInHand;
301  int _savedMouseState;
302 
303  int findFreeItem();
304  int countAllItems();
305 
306  int findItem(uint16 sceneId, Item id);
307  int findItem(Item item);
308 
309  void resetItemList();
310  void resetItem(int index);
311 
312  virtual void setMouseCursor(Item item) = 0;
313 
314  void setHandItem(Item item) override;
315  void removeHandItem() override;
316 
317  // character
318  struct Character {
319  uint16 sceneId;
320  int16 dlgIndex;
321  uint8 height;
322  uint8 facing;
323  uint16 animFrame;
324  byte walkspeed;
325  Item inventory[20];
326  int16 x1, y1;
327  int16 x2, y2;
328  int16 x3, y3;
329  };
330 
331  Character _mainCharacter;
332  int _mainCharX, _mainCharY;
333  int _charScale;
334 
335  void moveCharacter(int facing, int x, int y);
336  int updateCharPos(int *table, int force = 0);
337  void updateCharPosWithUpdate();
338 
339  uint32 _updateCharPosNextUpdate;
340 
341  virtual int getCharacterWalkspeed() const = 0;
342  virtual void updateCharAnimFrame(int *table) = 0;
343 
344  // chat
345  int _vocHigh;
346 
347  Common::String _chatText;
348  int _chatObject;
349  uint32 _chatEndTime;
350  int _chatVocHigh, _chatVocLow;
351  bool _chatTextEnabled;
352 
353  EMCData _chatScriptData;
354  EMCState _chatScriptState;
355 
356  virtual void setDlgIndex(int dlgIndex) = 0;
357 
358  virtual void randomSceneChat() = 0;
359 
360  // unknown
361  int _unk4, _unk5;
362  bool _unkSceneScreenFlag1;
363  bool _unkHandleSceneChangeFlag;
364 
365  // opcodes
366  int o2_getCharacterX(EMCState *script);
367  int o2_getCharacterY(EMCState *script);
368  int o2_getCharacterFacing(EMCState *script);
369  int o2_getCharacterScene(EMCState *script);
370  int o2_setCharacterFacingOverwrite(EMCState *script);
371  int o2_trySceneChange(EMCState *script);
372  int o2_moveCharacter(EMCState *script);
373  int o2_checkForItem(EMCState *script);
374  int o2_defineItem(EMCState *script);
375  int o2_addSpecialExit(EMCState *script);
376  int o2_delay(EMCState *script);
377  int o2_update(EMCState *script);
378  int o2_getShapeFlag1(EMCState *script);
379  int o2_waitForConfirmationClick(EMCState *script);
380  int o2_randomSceneChat(EMCState *script);
381  int o2_setDlgIndex(EMCState *script);
382  int o2_getDlgIndex(EMCState *script);
383  int o2_defineRoomEntrance(EMCState *script);
384  int o2_runAnimationScript(EMCState *script);
385  int o2_setSpecialSceneScriptRunTime(EMCState *script);
386  int o2_defineScene(EMCState *script);
387  int o2_setSpecialSceneScriptState(EMCState *script);
388  int o2_clearSpecialSceneScriptState(EMCState *script);
389  int o2_querySpecialSceneScriptState(EMCState *script);
390  int o2_setHiddenItemsEntry(EMCState *script);
391  int o2_getHiddenItemsEntry(EMCState *script);
392  int o2_disableTimer(EMCState *script);
393  int o2_enableTimer(EMCState *script);
394  int o2_setTimerCountdown(EMCState *script);
395  int o2_setVocHigh(EMCState *script);
396  int o2_getVocHigh(EMCState *script);
397 };
398 
399 } // End of namespace Kyra
400 
401 #endif
Definition: kyra_v2.h:200
Definition: str.h:59
Definition: kyra_v2.h:57
Definition: kyra_v2.h:286
Definition: kyra_v1.h:126
Definition: kyra_v2.h:35
Definition: script.h:47
Definition: kyra_v2.h:166
Definition: kyra_v2.h:53
Definition: kyra_v2.h:318
Definition: kyra_v2.h:46
Definition: detection.h:38
Definition: kyra_v2.h:102
Definition: gui_v2.h:102
Definition: detection.h:27
Definition: debugger.h:68
Definition: system.h:161
Definition: screen_v2.h:30
Definition: script.h:35
Definition: wsamovie.h:112
Definition: kyra_v2.h:40