ScummVM API documentation
kyra_mr.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_MR_H
23 #define KYRA_KYRA_MR_H
24 
25 #include "kyra/engine/kyra_v2.h"
26 #include "kyra/graphics/screen_mr.h"
27 #include "kyra/script/script.h"
28 #include "kyra/gui/gui_mr.h"
29 
30 #include "common/hashmap.h"
31 #include "common/list.h"
32 
33 namespace Kyra {
34 
35 class SoundDigital_MR;
36 class Screen_MR;
37 class MainMenu;
38 class WSAMovie_v2;
39 class TextDisplayer_MR;
40 struct Button;
41 
42 class KyraEngine_MR : public KyraEngine_v2 {
43 friend class TextDisplayer_MR;
44 friend class GUI_MR;
45 public:
46  KyraEngine_MR(OSystem *system, const GameFlags &flags);
47  ~KyraEngine_MR() override;
48 
49  // Regarding pausing of the engine:
50  // Idle animation time, item animations and album animations should be taken
51  // care of, but since those would just produce minor glitches it's not that
52  // important.
53 
54  Screen *screen() override { return _screen; }
55  Screen_v2 *screen_v2() const override { return _screen; }
56  GUI *gui() const override { return _gui; }
57  SoundDigital_MR *soundDigital() { return _soundDigital; }
58  int language() const { return _lang; }
59  bool heliumMode() const { return _configHelium; }
60 
61  Common::Error go() override;
62 
63  void playVQA(const char *name);
64 
65 private:
66  static const EngineDesc _mrEngineDesc;
67 
68  // config
69  bool _configStudio;
70  bool _configSkip;
71  bool _configHelium;
72  int _configVQAQuality;
73 
74  void registerDefaultSettings() override;
75  void writeSettings() override;
76  void readSettings() override;
77 
78  void initStaticResource();
79 
80  // --
81  Screen_MR *_screen;
82  SoundDigital_MR *_soundDigital;
83 
84  Common::Error init() override;
85 
86  void preinit();
87  void startup();
88  void runStartupScript(int script, int unk1);
89 
90  void setupOpcodeTable() override;
91 
92  // input
93  bool skipFlag() const override;
94  void resetSkipFlag(bool removeEvent = true) override;
95 
96  // run
97  bool _menuDirectlyToLoad;
98 
99  void runLoop();
100  void handleInput(int x, int y);
101  int inputSceneChange(int x, int y, int unk1, int unk2) override;
102 
103  void update() override;
104  void updateWithText() override;
105  void updateMouse();
106 
107  // sound specific
108 private:
109  void playMenuAudioFile();
110 
111  int _musicSoundChannel;
112  int _fadeOutMusicChannel;
113  const char *_menuAudioFile;
114 
115  const char *const *_soundList;
116  int _soundListSize;
117 
118  void snd_playWanderScoreViaMap(int track, int force) override;
119  void stopMusicTrack();
120 
121  void fadeOutMusic(int ticks);
122 
123  void snd_playSoundEffect(int item, int volume) override;
124 
125  const uint8 *_sfxFileMap;
126  int _sfxFileMapSize;
127  const char *const *_sfxFileList;
128  int _sfxFileListSize;
129 
130  int _voiceSoundChannel;
131 
132  void playVoice(int high, int low);
133  void snd_playVoiceFile(int file) override;
134  bool snd_voiceIsPlaying() override;
135  void snd_stopVoice() override;
136 
137  int _curStudioSFX;
138  void playStudioSFX(const char *str);
139 
140  // gui
141  GUI_MR *_gui;
142 
143  Button *_mainButtonData;
144  Button *_mainButtonList;
145  bool _mainButtonListInitialized;
146  void initMainButtonList(bool disable);
147 
148  bool _enableInventory;
149  int buttonInventory(Button *button);
150  int buttonMoodChange(Button *button);
151  int buttonShowScore(Button *button);
152  int buttonJesterStaff(Button *button);
153 
154  void loadButtonShapes();
155  int callbackButton1(Button *button);
156  int callbackButton2(Button *button);
157  int callbackButton3(Button *button);
158 
159  // -> main menu
160  void initMainMenu();
161  void uninitMainMenu();
162 
163  MainMenu *_menu;
164  WSAMovie_v2 *_menuAnim;
165 
166  // timer
167  void setupTimers() override;
168 
169  void setWalkspeed(uint8) override;
170  void setCommandLineRestoreTimer(int secs);
171 
172  void timerRestoreCommandLine(int arg);
173  void timerRunSceneScript7(int arg);
174  void timerFleaDeath(int arg);
175 
176  uint32 _nextIdleAnim;
177  void setNextIdleAnimTimer();
178 
179  // pathfinder
180  bool lineIsPassable(int x, int y) override;
181 
182 private:
183  // main menu
184  const char *const *_mainMenuStrings;
185  int _mainMenuStringsSize;
186 
187  // animator
188  uint8 *_gamePlayBuffer;
189  void restorePage3() override;
190 
191  void clearAnimObjects() override;
192 
193  void animSetupPaletteEntry(AnimObj *anim) override;
194 
195  void drawAnimObjects() override;
196  void drawSceneAnimObject(AnimObj *obj, int x, int y, int drawLayer) override;
197  void drawCharacterAnimObject(AnimObj *obj, int x, int y, int drawLayer) override;
198 
199  void refreshAnimObjects(int force) override;
200 
201  bool _loadingState;
202  void updateItemAnimations();
203  void updateCharacterAnim(int charId) override;
204 
205  void updateSceneAnim(int anim, int newFrame) override;
206  void setupSceneAnimObject(int anim, uint16 flags, int x, int y, int x2, int y2, int w, int h, int unk10, int specialSize, int unk14, int shape, const char *filename);
207  void removeSceneAnimObject(int anim, int refresh);
208 
209  int _charBackUpWidth2, _charBackUpHeight2;
210  int _charBackUpWidth, _charBackUpHeight;
211 
212  void setCharacterAnimDim(int w, int h) override;
213  void resetCharacterAnimDim() override;
214 
215  bool _nextIdleType;
216  void showIdleAnim();
217 
218  const ItemAnimDefinition *_itemAnimDefinition;
219  ActiveItemAnim _activeItemAnim[10];
220  int _nextAnimItem;
221 
222  // interface
223  uint8 *_interface;
224  uint32 _interfaceSize;
225  uint16 _interfaceH;
226  uint8 *_interfaceCommandLine;
227  uint32 _interfaceCommandLineSize;
228  uint16 _interfaceCommandLineY1;
229  uint16 _interfaceCommandLineY2;
230  uint16 _interfaceCommandLineH;
231 
232  void loadInterfaceShapes();
233  void loadInterface();
234 
235  void showMessage(const char *string, uint8 c0, uint8 c1);
236  void showMessageFromCCode(int string, uint8 c0, int);
237  void updateItemCommand(Item item, int str, uint8 c0);
238 
239  void updateCommandLine();
240  void restoreCommandLine();
241  void updateCLState();
242 
243  int _commandLineY;
244  const char *_shownMessage;
245  bool _restoreCommandLine;
246  bool _inventoryState;
247  int _inventoryScrollSpeed;
248 
249  void showInventory();
250  void hideInventory();
251 
252  void drawMalcolmsMoodText();
253  void drawMalcolmsMoodPointer(int frame, int page);
254  void drawJestersStaff(int type, int page);
255 
256  void drawScore(int page, int x, int y);
257  void drawScoreCounting(int oldScore, int newScore, int drawOld, const int x);
258  int getScoreX(const char *str);
259 
260  static const uint8 _inventoryX[];
261  static const uint8 _inventoryY[];
262  void redrawInventory(int page);
263  void clearInventorySlot(int slot, int page);
264  void drawInventorySlot(int page, Item item, int slot);
265 
266  WSAMovie_v2 *_invWsa;
267  int _invWsaFrame;
268 
269  // localization
270  uint8 *_scoreFile;
271  uint8 *_cCodeFile;
272  uint8 *_scenesFile;
273  uint8 *_itemFile;
274  uint8 *_optionsFile;
275  uint8 *_actorFile;
276  uint32 _actorFileSize;
277  uint8 *_sceneStrings;
278 
279  uint8 *getTableEntry(uint8 *buffer, int id);
280  void getTableEntry(Common::SeekableReadStream *stream, int id, char *dst);
281 
282  // items
283  int8 *_itemBuffer1;
284  int8 *_itemBuffer2;
285 
286  static const Item _trashItemList[];
287  void removeTrashItems();
288 
289  void initItems();
290 
291  int checkItemCollision(int x, int y);
292 
293  bool dropItem(int unk1, Item item, int x, int y, int unk2);
294  bool processItemDrop(uint16 sceneId, Item item, int x, int y, int unk1, int unk2);
295  void itemDropDown(int startX, int startY, int dstX, int dstY, int itemSlot, Item item, int remove);
296  void exchangeMouseItem(int itemPos, int runScript);
297  bool pickUpItem(int x, int y, int runScript);
298 
299  bool isDropable(int x, int y);
300 
301  const uint8 *_itemMagicTable;
302  bool itemListMagic(Item handItem, int itemSlot);
303  bool itemInventoryMagic(Item handItem, int invSlot);
304 
305  const uint8 *_itemStringMap;
306  int _itemStringMapSize;
307  static const uint8 _itemStringPickUp[];
308  static const uint8 _itemStringDrop[];
309  static const uint8 _itemStringInv[];
310 
311  int getItemCommandStringPickUp(uint16 item);
312  int getItemCommandStringDrop(uint16 item);
313  int getItemCommandStringInv(uint16 item);
314 
315  // -> hand item
316  void setItemMouseCursor();
317  void setMouseCursor(Item item) override;
318 
319  // shapes
320  void initMouseShapes();
321 
322  void loadCharacterShapes(int newShapes) override;
323  void updateMalcolmShapes();
324 
325  int _malcolmShapeXOffset, _malcolmShapeYOffset;
326 
327  struct ShapeDesc {
328  uint8 width, height;
329  int8 xOffset, yOffset;
330  };
331  static const ShapeDesc _shapeDescs[];
332  static const int _shapeDescsSize;
333 
334  // scene animation
335  uint8 *_sceneShapes[20];
336 
337  void freeSceneShapes();
338 
339  // voice
340  int _currentTalkFile;
341  void openTalkFile(int file);
342 
343  // scene
344  bool _noScriptEnter;
345  void enterNewScene(uint16 scene, int facing, int unk1, int unk2, int unk3) override;
346  void enterNewSceneUnk1(int facing, int unk1, int unk2);
347  void enterNewSceneUnk2(int unk1);
348  int _enterNewSceneLock;
349 
350  void unloadScene();
351 
352  void loadScenePal();
353  void loadSceneMsc();
354  void initSceneScript(int unk1);
355  void initSceneAnims(int unk1);
356  void initSceneScreen(int unk1);
357 
358  int runSceneScript1(int x, int y);
359  int runSceneScript2();
360  bool _noStartupChat;
361  void runSceneScript4(int unk1);
362  void runSceneScript8();
363 
364  int _sceneMinX, _sceneMaxX;
365  int _maskPageMinY, _maskPageMaxY;
366 
367  int trySceneChange(int *moveTable, int unk1, int unk2) override;
368  int checkSceneChange();
369 
370  int8 _sceneDatPalette[45];
371  int8 _sceneDatLayerTable[15];
372  struct SceneShapeDesc {
373  // the original saves those variables, we don't, since
374  // they are just needed on scene load
375  /*int x, y;
376  int w, h;*/
377  int drawX, drawY;
378  };
379  SceneShapeDesc _sceneShapeDescs[20];
380 
381  int getDrawLayer(int x, int y);
382 
383  int getScale(int x, int y) override;
384  int _scaleTable[15];
385 
386  // character
387  int getCharacterWalkspeed() const override;
388  void updateCharAnimFrame(int *table) override;
389  int8 _characterAnimTable[2];
390  static const uint8 _characterFrameTable[];
391 
392  void updateCharPal(int unk1);
393  int _lastCharPalLayer;
394  bool _charPalUpdate;
395 
396  bool checkCharCollision(int x, int y);
397 
398  int _malcolmsMood;
399 
400  void makeCharFacingMouse();
401 
402  int findFreeInventorySlot();
403 
404  // talk object
405  struct TalkObject {
406  char filename[13];
407  int8 sceneAnim;
408  int8 sceneScript;
409  int16 x, y;
410  uint8 color;
411  uint8 sceneId;
412  };
413 
414  TalkObject *_talkObjectList;
415 
416  bool talkObjectsInCurScene();
417 
418  // chat
419  int chatGetType(const char *text);
420  int chatCalcDuration(const char *text);
421 
422  void objectChat(const char *text, int object, int vocHigh, int vocLow);
423  void objectChatInit(const char *text, int object, int vocHigh, int vocLow);
424  void objectChatPrintText(const Common::String &text, int object);
425  void objectChatProcess(const char *script);
426  void objectChatWaitToFinish();
427 
428  void badConscienceChat(const char *str, int vocHigh, int vocLow);
429  void badConscienceChatWaitToFinish();
430 
431  void goodConscienceChat(const char *str, int vocHigh, int vocLow);
432  void goodConscienceChatWaitToFinish();
433 
434  bool _albumChatActive;
435  void albumChat(const char *str, int vocHigh, int vocLow);
436  void albumChatInit(const char *str, int object, int vocHigh, int vocLow);
437  void albumChatWaitToFinish();
438 
439  void malcolmSceneStartupChat();
440 
441  byte _newSceneDlgState[40];
442  int8 _conversationState[30][30];
443  bool _chatAltFlag;
444  void setDlgIndex(int index) override;
445  void updateDlgIndex();
446 
447  Common::SeekableReadStream *_cnvFile;
448  Common::SeekableReadStream *_dlgBuffer;
449  int _curDlgChapter, _curDlgIndex, _curDlgLang;
450  void updateDlgBuffer();
451  void loadDlgHeader(int &vocHighBase, int &vocHighIndex, int &index1, int &index2);
452 
453  static const uint8 _vocHighTable[];
454  bool _isStartupDialog;
455  void processDialog(int vocHighIndex, int vocHighBase, int funcNum);
456 
457  EMCData _dialogScriptData;
458  EMCState _dialogScriptState;
459  int _dialogSceneAnim;
460  int _dialogSceneScript;
461  int _dialogScriptFuncStart, _dialogScriptFuncProc, _dialogScriptFuncEnd;
462 
463  void dialogStartScript(int object, int funcNum);
464  void dialogEndScript(int object);
465 
466  void npcChatSequence(const char *str, int object, int vocHigh, int vocLow);
467 
468  Common::Array<const Opcode *> _opcodesDialog;
469 
470  int o3d_updateAnim(EMCState *script);
471  int o3d_delay(EMCState *script);
472 
473  void randomSceneChat() override;
474  void doDialog(int dlgIndex, int funcNum);
475 
476  // conscience
477  bool _badConscienceShown;
478  int _badConscienceAnim;
479  bool _badConsciencePosition;
480 
481  static const uint8 _badConscienceFrameTable[];
482 
483  void showBadConscience();
484  void hideBadConscience();
485 
486  bool _goodConscienceShown;
487  int _goodConscienceAnim;
488  bool _goodConsciencePosition;
489 
490  static const uint8 _goodConscienceFrameTable[];
491 
492  void showGoodConscience();
493  void hideGoodConscience();
494 
495  // special script code
496  bool _useFrameTable;
497 
498  int o3a_setCharacterFrame(EMCState *script);
499  int o3a_playSoundEffect(EMCState *script);
500 
501  // special shape code
502  int initAnimationShapes(uint8 *filedata) override;
503  void uninitAnimationShapes(int count, uint8 *filedata) override;
504 
505  // unk
506  uint8 *_costPalBuffer;
507  uint8 *_paletteOverlay;
508  bool _useActorBuffer;
509 
510  int _currentChapter;
511  void changeChapter(int newChapter, int sceneId, int malcolmShapes, int facing);
512 
513  static const uint8 _chapterLowestScene[];
514 
515  void loadCostPal();
516  void loadShadowShape();
517  void loadExtrasShapes();
518 
519  uint8 *_gfxBackUpRect;
520  void backUpGfxRect32x32(int x, int y);
521  void restoreGfxRect32x32(int x, int y);
522 
523  char *_stringBuffer;
524 
525  int _score;
526  int _scoreMax;
527 
528  const uint8 *_scoreTable;
529  int _scoreTableSize;
530 
531  int8 _scoreFlagTable[26];
532  bool updateScore(int scoreId, int strId);
533  void scoreIncrease(int count, const char *str);
534 
535  void eelScript();
536 
537  // Album
538  struct Album {
539  uint8 *backUpPage;
540  uint8 *file;
541  WSAMovie_v2 *wsa;
542  uint8 *backUpRect;
543 
544  struct PageMovie {
545  WSAMovie_v2 *wsa;
546  int curFrame;
547  int maxFrame;
548  uint32 timer;
549  };
550 
551  PageMovie leftPage, rightPage;
552 
553  int curPage, nextPage;
554  bool running;
555  bool isPage14;
556  } _album;
557 
558  static const int8 _albumWSAX[];
559  static const int8 _albumWSAY[];
560 
561  void showAlbum();
562 
563  void loadAlbumPage();
564  void loadAlbumPageWSA();
565 
566  void printAlbumPageText();
567  void printAlbumText(int page, const char *str, int x, int y, uint8 c0);
568 
569  void processAlbum();
570 
571  void albumNewPage();
572  void albumUpdateAnims();
573  void albumAnim1();
574  void albumAnim2();
575 
576  void albumBackUpRect();
577  void albumRestoreRect();
578  void albumUpdateRect();
579 
580  void albumSwitchPages(int oldPage, int newPage, int srcPage);
581 
582  int albumNextPage(Button *caller);
583  int albumPrevPage(Button *caller);
584  int albumClose(Button *caller);
585 
586  // save/load
587  Common::Error saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumbnail) override;
588  Common::Error loadGameState(int slot) override;
589 
590  // opcodes
591  int o3_getMalcolmShapes(EMCState *script);
592  int o3_setCharacterPos(EMCState *script);
593  int o3_defineObject(EMCState *script);
594  int o3_refreshCharacter(EMCState *script);
595  int o3_getMalcolmsMood(EMCState *script);
596  int o3_getCharacterFrameFromFacing(EMCState *script);
597  int o3_setCharacterFacing(EMCState *script);
598  int o3_showSceneFileMessage(EMCState *script);
599  int o3_setCharacterAnimFrameFromFacing(EMCState *script);
600  int o3_showBadConscience(EMCState *script);
601  int o3_hideBadConscience(EMCState *script);
602  int o3_showAlbum(EMCState *script);
603  int o3_setInventorySlot(EMCState *script);
604  int o3_getInventorySlot(EMCState *script);
605  int o3_addItemToInventory(EMCState *script);
606  int o3_addItemToCurScene(EMCState *script);
607  int o3_objectChat(EMCState *script);
608  int o3_resetInventory(EMCState *script);
609  int o3_removeInventoryItemInstances(EMCState *script);
610  int o3_countInventoryItemInstances(EMCState *script);
611  int o3_npcChatSequence(EMCState *script);
612  int o3_badConscienceChat(EMCState *script);
613  int o3_wipeDownMouseItem(EMCState *script);
614  int o3_setMalcolmsMood(EMCState *script);
615  int o3_updateScore(EMCState *script);
616  int o3_makeSecondChanceSave(EMCState *script);
617  int o3_setSceneFilename(EMCState *script);
618  int o3_removeItemsFromScene(EMCState *script);
619  int o3_disguiseMalcolm(EMCState *script);
620  int o3_drawSceneShape(EMCState *script);
621  int o3_drawSceneShapeOnPage(EMCState *script);
622  int o3_checkInRect(EMCState *script);
623  int o3_updateConversations(EMCState *script);
624  int o3_removeItemSlot(EMCState *script);
625  int o3_setSceneDim(EMCState *script);
626  int o3_setSceneAnimPosAndFrame(EMCState *script);
627  int o3_removeItemInstances(EMCState *script);
628  int o3_disableInventory(EMCState *script);
629  int o3_enableInventory(EMCState *script);
630  int o3_enterNewScene(EMCState *script);
631  int o3_switchScene(EMCState *script);
632  int o3_setMalcolmPos(EMCState *script);
633  int o3_stopMusic(EMCState *script);
634  int o3_playSoundEffect(EMCState *script);
635  int o3_getScore(EMCState *script);
636  int o3_daggerWarning(EMCState *script);
637  int o3_blockOutWalkableRegion(EMCState *script);
638  int o3_showSceneStringsMessage(EMCState *script);
639  int o3_showGoodConscience(EMCState *script);
640  int o3_goodConscienceChat(EMCState *script);
641  int o3_hideGoodConscience(EMCState *script);
642  int o3_defineSceneAnim(EMCState *script);
643  int o3_updateSceneAnim(EMCState *script);
644  int o3_runActorScript(EMCState *script);
645  int o3_doDialog(EMCState *script);
646  int o3_setConversationState(EMCState *script);
647  int o3_getConversationState(EMCState *script);
648  int o3_changeChapter(EMCState *script);
649  int o3_countItemInstances(EMCState *script);
650  int o3_dialogStartScript(EMCState *script);
651  int o3_dialogEndScript(EMCState *script);
652  int o3_customChat(EMCState *script);
653  int o3_customChatFinish(EMCState *script);
654  int o3_setupSceneAnimObject(EMCState *script);
655  int o3_removeSceneAnimObject(EMCState *script);
656  int o3_dummy(EMCState *script);
657 
658  // misc
659  TextDisplayer_MR *_text;
660  bool _wasPlayingVQA;
661 
662  // resource specific
663 private:
664  static const char *const _languageExtension[];
665  static const int _languageExtensionSize;
666 
667  int loadLanguageFile(const char *file, uint8 *&buffer);
668 };
669 
670 } // End of namespace Kyra
671 
672 #endif
Definition: gui_mr.h:32
Definition: str.h:59
Definition: surface.h:66
Definition: text_mr.h:31
Definition: kyra_v2.h:57
Definition: error.h:84
Definition: kyra_mr.h:42
Definition: sound_digital_mr.h:46
Definition: screen.h:565
Definition: stream.h:745
Definition: system.h:45
Definition: script.h:47
Definition: kyra_v2.h:53
Definition: screen_mr.h:31
Definition: kyra_v2.h:46
Definition: kyra_mr.h:544
Definition: detection.h:38
Definition: kyra_v2.h:102
Definition: detection.h:27
Definition: gui.h:38
Definition: system.h:167
Definition: screen_v2.h:30
Definition: script.h:35
Definition: input.h:69
Definition: wsamovie.h:112
Definition: gui_v1.h:149
Definition: kyra_v2.h:40