ScummVM API documentation
kyra_rpg.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_RPG_H
23#define KYRA_RPG_H
24
25#if defined(ENABLE_EOB) || defined(ENABLE_LOL)
26
27#include "kyra/kyra_v1.h"
28#include "kyra/graphics/screen_eob.h"
29#include "kyra/gui/gui_eob.h"
30#include "kyra/text/text_lol.h"
31
32#include "common/keyboard.h"
33#include "backends/keymapper/action.h"
34
35namespace {
36 class Action;
37}
38
39namespace Kyra {
40
41struct LevelDecorationProperty {
42 uint16 shapeIndex[10];
43 uint8 scaleFlag[10];
44 int16 shapeX[10];
45 int16 shapeY[10];
46 int8 next;
47 uint8 flags;
48};
49
50struct LevelBlockProperty {
51 uint8 walls[4];
52 uint16 assignedObjects;
53 uint16 drawObjects;
54 uint8 direction;
55 uint16 flags;
56};
57
58struct OpenDoorState {
59 uint16 block;
60 int8 wall;
61 int8 state;
62};
63
64struct LevelTempData {
65 const uint8 *wallsXorData;
66 const uint16 *flags;
67 const void *monsters;
68 const void *flyingObjects;
69 const void *wallsOfForce;
70 uint8 monsterDifficulty;
71 // ScummVM extra feature for EOBI/II
72 const void *automapExploreState;
73};
74
75struct EoBFlyingObject {
76 uint8 enable;
77 uint8 objectType;
78 int16 attackerId;
79 Item item;
80 uint16 curBlock;
81 uint16 starting;
82 uint8 u1;
83 uint8 direction;
84 uint8 distance;
85 int8 callBackIndex;
86 uint8 curPos;
87 uint8 flags;
88 Item projectileWeapon;
89};
90
91struct KyraRpgGUISettings {
92 struct DialogueButtons {
93 const uint16 *posX;
94 const uint8 *posY;
95 uint8 labelColor1;
96 uint8 labelColor2;
97 bool labelShadow;
98 uint16 width;
99 uint16 height;
100 int16 txtOffsY;
101 int waitReserve;
102 uint16 waitX[2];
103 uint8 waitY[2];
104 uint16 waitWidth[2];
105 } buttons;
106
107 struct Colors {
108 uint8 frame1;
109 uint8 frame2;
110 int fill;
111
112 uint8 sfill;
113 uint8 barGraph;
114
115 uint8 warningFrame1;
116 uint8 warningFrame2;
117 int warningFill;
118
119 uint8 extraFrame1;
120 uint8 extraFrame2;
121 int extraFill;
122
123 uint8 inactiveTabFrame1;
124 uint8 inactiveTabFrame2;
125 int inactiveTabFill;
126
127 uint8 guiColorWhite;
128 uint8 guiColorLightRed;
129 uint8 guiColorDarkRed;
130 uint8 guiColorLightBlue;
131 uint8 guiColorBlue;
132 uint8 guiColorDarkBlue;
133 uint8 guiColorYellow;
134 uint8 guiColorLightGreen;
135 uint8 guiColorDarkGreen;
136 uint8 guiColorPurple;
137 uint8 guiColorBrown;
138 uint8 guiColorBlack;
139 } colors;
140
141 struct CharacterBoxCoords {
142 int16 boxX[3];
143 int16 boxY[3];
144 uint8 boxWidth;
145 uint8 boxHeight;
146 int16 facePosX_1[3];
147 int16 facePosY_1[3];
148 int16 facePosX_2[3];
149 int16 facePosY_2[3];
150 int16 weaponSlotX[3];
151 int16 weaponSlotY[6];
152 int16 hpBarX_1[3];
153 int16 hpBarY_1[3];
154 uint8 hpBarWidth_1;
155 uint8 hpBarHeight_1;
156 int16 hpFoodBarX_2[3];
157 int16 hpFoodBarY_2[3];
158 uint8 hpFoodBarWidth_2[2];
159 uint8 hpFoodBarHeight_2;
160 int16 nameLabelOffsetX;
161 int16 nameLabelOffsetY;
162 int16 exchangeLabelOffsetX;
163 int16 exchangeLabelOffsetY;
164 int16 redSplatOffsetX;
165 int16 redSplatOffsetY;
166 } charBoxCoords;
167
168 struct StatsPageCoords {
169 int16 headlineX;
170 int16 headlineY;
171 int16 descStartX;
172 int16 descStartY;
173 uint8 descYInc;
174 int16 statsGroup1StringsX;
175 int16 statsGroup1StringsY;
176 int16 statsGroup2StringsX;
177 int16 statsGroup2StringsY;
178 uint8 statsStringsYInc;
179 int16 statsGroup1StatsX;
180 int16 statsGroup1StatsY;
181 int16 statsGroup2StatsX;
182 int16 statsGroup2StatsY;
183 uint8 statsStatsYInc;
184 int16 acStringX;
185 int16 acStringY;
186 int16 acStatsX;
187 int16 acStatsY;
188 int16 expStringX;
189 int16 expStringY;
190 int16 expStatsX;
191 int16 expStatsY;
192 uint8 expStatsXInc;
193 uint8 expStatsYInc;
194 int16 lvlStringX;
195 int16 lvlStringY;
196 int16 lvlStatsX;
197 int16 lvlStatsY;
198 uint8 lvlStatsXInc;
199 uint8 lvlStatsYInc;
200 int16 classStringsX;
201 int16 classStringsY;
202 uint8 classStringsXInc;
203 uint8 classStringsYInc;
204 } statsPageCoords;
205
206 struct StatsPageColors {
207 uint8 headLine;
208 uint8 cls[3];
209 uint8 alignment;
210 uint8 race;
211 uint8 acString;
212 uint8 statsStrings;
213 uint8 statsValues;
214 uint8 expLvl[3];
215 } statsPageColors;
216
217 struct SpellbookCoords {
218 uint8 totalHeight;
219 uint8 numTabs;
220 uint8 tabStartX;
221 uint8 tabStartY;
222 uint8 tabWidth;
223 uint8 tabHeight;
224 uint8 tabStrOffsX;
225 uint8 tabStrOffsY;
226 uint8 listSize;
227 uint8 listStartX;
228 uint8 listStartY;
229 uint8 listTotalH;
230 uint8 abortBtnX;
231 uint8 abortBtnY;
232 uint8 abortBtnW;
233 uint8 abortBtnH;
234 uint8 abortStrX;
235 uint8 abortStrY;
236 uint8 scrollButtonY;
237 uint8 gridCoordsX[4];
238 uint8 gridCoordsY[3];
239 } spellbookCoords;
240};
241
242class KyraRpgEngine : public KyraEngine_v1 {
243friend class TextDisplayer_rpg;
244public:
245 KyraRpgEngine(OSystem *system, const GameFlags &flags);
246 ~KyraRpgEngine() override;
247
248 Screen *screen() override = 0;
249 GUI *gui() const override = 0;
250
251protected:
252 // Startup
253 Common::Error init() override;
254 Common::Error go() override = 0;
255
256 // Init
257 void initStaticResource();
258
259 static void addKeymapAction(Common::Keymap *const keyMap, const char *actionId, const Common::U32String &actionDesc, const Common::Functor0Mem<void, Common::Action>::FuncType setEventProc, const Common::String &mapping1, const Common::String &mapping2);
260 static void addKeymapAction(Common::Keymap *const keyMap, const char *actionId, const Common::U32String &actionDesc, Common::KeyState eventKeyState, const Common::String &mapping1, const Common::String &mapping2);
261
262 const uint8 **_itemIconShapes;
263
264 // Main loop
265 virtual void update() = 0;
266 void snd_updateEnvironmentalSfx(int soundId);
267
268 // timers
269 void setupTimers() override = 0;
270 virtual void enableSysTimer(int sysTimer);
271 virtual void disableSysTimer(int sysTimer);
272 void enableTimer(int id);
273 virtual uint8 getClock2Timer(int index) = 0;
274 virtual uint8 getNumClock2Timers() = 0;
275
276 void timerProcessDoors(int timerNum);
277
278 // mouse
279 bool posWithinRect(int posX, int posY, int x1, int y1, int x2, int y2);
280 void setHandItem(Item itemIndex) override = 0;
281
282 // Characters
283 int _updateCharNum;
284 int _updatePortraitSpeechAnimDuration;
285 bool _fadeText;
286 int _resetPortraitAfterSpeechAnim;
287 int _needSceneRestore;
288
289 // Items
290 int _itemInHand;
291
292 // Monsters
293 int getBlockDistance(uint16 block1, uint16 block2);
294
295 uint8 **_monsterPalettes;
296 uint8 **_monsterShapes;
297
298 int16 _shpDmX1;
299 int16 _shpDmX2;
300
301 int _monsterStepCounter;
302 int _monsterStepMode;
303
304 // Level
305 virtual void addLevelItems() = 0;
306 virtual void loadBlockProperties(const char *file) = 0;
307
308 virtual const uint8 *getBlockFileData(int levelIndex) = 0;
309 void setLevelShapesDim(int index, int16 &x1, int16 &x2, int dim);
310 void setDoorShapeDim(int index, int16 &y1, int16 &y2, int dim);
311 void drawLevelModifyScreenDim(int dim, int16 x1, int16 y1, int16 x2, int16 y2);
312 void generateBlockDrawingBuffer();
313 void generateVmpTileData(int16 startBlockX, uint8 startBlockY, uint8 wllVmpIndex, int16 vmpOffset, uint8 numBlocksX, uint8 numBlocksY);
314 void generateVmpTileDataFlipped(int16 startBlockX, uint8 startBlockY, uint8 wllVmpIndex, int16 vmpOffset, uint8 numBlocksX, uint8 numBlocksY);
315 bool hasWall(int index);
316 void assignVisibleBlocks(int block, int direction);
317 bool checkSceneUpdateNeed(int block);
318 uint16 calcNewBlockPosition(uint16 curBlock, uint16 direction);
319
320 void setVcnFormat(int outputBPP, Common::RenderMode renderMode);
321 void drawVcnBlocks();
322 void vcnDraw_fw_4bit(uint8 *&dst, const uint8 *&src);
323 void vcnDraw_bw_4bit(uint8 *&dst, const uint8 *&src);
324 template<bool cga> void vcnDraw_fw_trans_4bit(uint8 *&dst, const uint8 *&src);
325 template<bool cga> void vcnDraw_bw_trans_4bit(uint8 *&dst, const uint8 *&src);
326 template<typename T> void vcnDraw_fw_hiCol(uint8 *&dst, const uint8 *&src);
327 template<typename T> void vcnDraw_bw_hiCol(uint8 *&dst, const uint8 *&src);
328 template<typename T> void vcnDraw_fw_trans_hiCol(uint8 *&dst, const uint8 *&src);
329 template<typename T> void vcnDraw_bw_trans_hiCol(uint8 *&dst, const uint8 *&src);
330 void vcnDraw_fw_planar(uint8 *&dst, const uint8 *&src);
331 void vcnDraw_bw_planar(uint8 *&dst, const uint8 *&src);
332 void vcnDraw_fw_trans_planar(uint8 *&dst, const uint8 *&src);
333 void vcnDraw_bw_trans_planar(uint8 *&dst, const uint8 *&src);
334
336 struct VcnLineDrawingMethods {
337 VcnLineDrawingMethods(VcnDrawProc *fw, VcnDrawProc *bw, VcnDrawProc *fw_t, VcnDrawProc *bw_t) : forward(fw), backwards(bw), forward_trans(fw_t), backwards_trans(bw_t) {}
338 ~VcnLineDrawingMethods() {
339 delete forward;
340 delete backwards;
341 delete forward_trans;
342 delete backwards_trans;
343 }
344
345 VcnDrawProc *forward;
346 VcnDrawProc *backwards;
347 VcnDrawProc *forward_trans;
348 VcnDrawProc *backwards_trans;
349 };
350 VcnLineDrawingMethods *_vcnDrawLine;
351
352 virtual int clickedDoorSwitch(uint16 block, uint16 direction) = 0;
353 int clickedWallShape(uint16 block, uint16 direction);
354 int clickedLeverOn(uint16 block, uint16 direction);
355 int clickedLeverOff(uint16 block, uint16 direction);
356 int clickedWallOnlyScript(uint16 block);
357 virtual int clickedNiche(uint16 block, uint16 direction) = 0;
358
359 void processDoorSwitch(uint16 block, int openClose);
360 void openCloseDoor(int block, int openClose);
361 void completeDoorOperations();
362 bool isSpecialDoor(int block);
363
364 uint8 *_wllVmpMap;
365 int8 *_wllShapeMap;
366 uint8 *_specialWallTypes;
367 uint8 *_wllWallFlags;
368
369 int _sceneXoffset;
370 int _sceneShpDim;
371
372 LevelBlockProperty *_levelBlockProperties;
373 LevelBlockProperty *_visibleBlocks[18];
374 LevelDecorationProperty *_levelDecorationData;
375 uint16 _levelDecorationDataSize;
376 LevelDecorationProperty *_levelDecorationProperties;
377 const uint8 **_levelDecorationShapes;
378 uint16 _decorationCount;
379 int16 _mappedDecorationsCount;
380 uint16 *_vmpPtr;
381 uint8 *_vcnBlocks;
382 uint8 *_vcfBlocks;
383 uint8 *_vcnTransitionMask;
384 uint8 *_vcnMaskTbl;
385 uint8 *_vcnShift;
386 uint8 _vcnShiftVal;
387 uint8 *_vcnColTable;
388 const void *_vcnHiColorPalette;
389 uint8 _vcnSrcBitsPerPixel;
390 uint8 _vcnBpp;
391 uint16 *_blockDrawingBuffer;
392 uint8 *_sceneWindowBuffer;
393 uint8 _blockBrightness;
394 uint8 _wllVcnOffset;
395 uint8 _wllVcnOffset2;
396 uint8 _wllVcnRmdOffset;
397
398 uint8 **_doorShapes;
399
400 uint8 _currentLevel;
401 uint16 _currentBlock;
402 uint16 _currentDirection;
403 int _sceneDefaultUpdate;
404 bool _sceneUpdateRequired;
405
406 int16 _visibleBlockIndex[18];
407 int16 *_lvlShapeLeftRight;
408 int16 *_lvlShapeTop;
409 int16 *_lvlShapeBottom;
410
411 Common::String _lastBlockDataFile;
412 uint32 _hasTempDataFlags;
413
414 int16 _sceneDrawVarDown;
415 int16 _sceneDrawVarRight;
416 int16 _sceneDrawVarLeft;
417 int _wllProcessFlag;
418
419 OpenDoorState _openDoorState[3];
420
421 int _sceneDrawPage1;
422 int _sceneDrawPage2;
423
424 const int8 *_dscShapeIndex;
425 const uint8 *_dscDimMap;
426 const int8 *_dscDim1;
427 const int8 *_dscDim2;
428 const int16 *_dscShapeX;
429 const uint8 *_dscDoorScaleOffs;
430 const uint8 *_dscBlockMap;
431 const int8 *_dscBlockIndex;
432 const uint8 *_dscTileIndex;
433
434 const uint8 *_dscDoorShpIndex;
435 int _dscDoorShpIndexSize;
436 const uint8 *_dscDoorY2;
437 const uint8 *_dscDoorFrameY1;
438 const uint8 *_dscDoorFrameY2;
439 const uint8 *_dscDoorFrameIndex1;
440 const uint8 *_dscDoorFrameIndex2;
441
442 const uint16 *_vmpVisOffs;
443 static const uint16 _vmpOffsetsDefault[9];
444 static const uint16 _vmpOffsetsSegaCD[9];
445
446 // Script
447 virtual void runLevelScript(int block, int flags) = 0;
448
449 // Gui
450 void removeInputTop();
451 void gui_drawBox(int x, int y, int w, int h, int frameColor1, int frameColor2, int fillColor);
452 virtual void gui_drawHorizontalBarGraph(int x, int y, int w, int h, int32 curVal, int32 maxVal, int col1, int col2);
453 void gui_initButtonsFromList(const uint8 *list);
454 virtual void gui_initButton(int index, int x = -1, int y = -1, int val = -1) = 0;
455 void gui_resetButtonList();
456 void gui_notifyButtonListChanged();
457
458 bool clickedShape(int shapeIndex);
459
460 virtual const KyraRpgGUISettings *guiSettings() const = 0;
461 virtual void useMainMenuGUISettings(bool toggle) {};
462
463 int _clickedShapeXOffs;
464 int _clickedShapeYOffs;
465
466 Button *_activeButtons;
467 Button _activeButtonData[70];
468 Common::Array<Button::Callback> _buttonCallbacks;
469 //bool _processingButtons;
470
471 uint8 _mouseClick;
472 bool _preserveEvents;
473 bool _buttonListChanged;
474
475 int _updateFlags;
476 int _clickedSpecialFlag;
477
478 int _compassDirection;
479
480 static const uint8 _dropItemDirIndex[];
481
482 // text
483 virtual void drawDialogueButtons();
484 uint16 processDialogue();
485
486 TextDisplayer_rpg *_txt;
487 virtual TextDisplayer_rpg *txt() { return _txt; }
488
489 bool _dialogueField;
490 bool _dialogueFieldAmiga;
491 Screen::FontId _buttonFont;
492
493 const char *_dialogueButtonString[9];
494 const uint16 *_dialogueButtonPosX;
495 const uint8 *_dialogueButtonPosY;
496 int16 _dialogueButtonXoffs;
497 int16 _dialogueButtonYoffs;
498 uint16 _dialogueButtonWidth;
499 int _dialogueNumButtons;
500 int _dialogueHighlightedButton;
501 int _currentControlMode;
502 int _specialSceneFlag;
503 uint8 _dialogueButtonLabelColor1;
504 uint8 _dialogueButtonLabelColor2;
505
506 const char *const *_moreStrings;
507
508 static const uint16 _dlgButtonPosX_Def[14];
509 static const uint8 _dlgButtonPosY_Def[14];
510
511 // misc
512 void delay(uint32 millis, bool doUpdate = false, bool isMainLoop = false) override = 0;
513 void delayUntil(uint32 time, bool unused = false, bool doUpdate = false, bool isMainLoop = false) override;
514 int rollDice(int times, int pips, int inc = 0);
515
516 Common::Error loadGameState(int slot) override = 0;
517 Common::Error saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumbnail) override = 0;
518
519 void generateTempData();
520 virtual void restoreBlockTempData(int levelIndex);
521 void releaseTempData();
522 virtual const void *generateMonsterTempData(uint8 &monsterDifficulty) const = 0;
523 virtual void restoreMonsterTempData(LevelTempData *tmp) = 0;
524 virtual void releaseMonsterTempData(LevelTempData *tmp) = 0;
525 void restoreFlyingObjectTempData(LevelTempData *tmp);
526 const void *generateFlyingObjectTempData() const;
527 void releaseFlyingObjectTempData(LevelTempData *tmp);
528 virtual const void *generateWallOfForceTempData() const { return nullptr; }
529 virtual void restoreWallOfForceTempData(LevelTempData *tmp) {}
530 virtual void releaseWallOfForceTempData(LevelTempData *tmp) {}
531 virtual const void *generateAutoMapTempData() { return nullptr; }
532 virtual void restoreAutoMapTempData(LevelTempData *tmp) {}
533 virtual void releaseAutoMapTempData(LevelTempData *tmp) {}
534
535 LevelTempData *_lvlTempData[29];
536 const int _numFlyingObjects;
537 uint32 _flyingObjectStructSize;
538 void *_flyingObjectsPtr;
539
540 Common::String _versionString;
541
542 // sound
543 virtual bool snd_processEnvironmentalSoundEffect(int soundId, int block);
544 virtual void snd_stopSpeech(bool) {}
545 virtual int snd_updateCharacterSpeech() { return 0; }
546 virtual void stopPortraitSpeechAnim() {}
547 void setupOpcodeTable() override {}
548 void snd_playVoiceFile(int) override {}
549
550 int _environmentSfx;
551 int _environmentSfxVol;
552 int _envSfxDistThreshold;
553
554 uint32 _activeVoiceFileTotalTime;
555
556 // unused
557 void setWalkspeed(uint8) override {}
558 void removeHandItem() override {}
559 bool lineIsPassable(int, int) override { return false; }
560};
561
562} // End of namespace Kyra
563
564#endif // ENABLE_EOB || ENABLE_LOL
565
566#endif
Definition: input.h:69
Definition: array.h:52
Definition: error.h:81
Definition: func.h:389
Definition: func.h:508
Definition: keymap.h:66
Definition: str.h:59
Definition: ustr.h:57
Definition: system.h:166
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
RenderMode
Definition: rendermode.h:48
Definition: detection.h:27
Definition: keyboard.h:294
Definition: surface.h:67
Definition: atari-screen.h:58