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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef KYRA_RPG_H
24 #define KYRA_RPG_H
25 
26 #if defined(ENABLE_EOB) || defined(ENABLE_LOL)
27 
28 #include "kyra/kyra_v1.h"
29 #include "kyra/graphics/screen_eob.h"
30 #include "kyra/gui/gui_eob.h"
31 #include "kyra/text/text_lol.h"
32 
33 namespace Kyra {
34 
35 struct LevelDecorationProperty {
36 	uint16 shapeIndex[10];
37 	uint8 scaleFlag[10];
38 	int16 shapeX[10];
39 	int16 shapeY[10];
40 	int8 next;
41 	uint8 flags;
42 };
43 
44 struct LevelBlockProperty {
45 	uint8 walls[4];
46 	uint16 assignedObjects;
47 	uint16 drawObjects;
48 	uint8 direction;
49 	uint16 flags;
50 };
51 
52 struct OpenDoorState {
53 	uint16 block;
54 	int8 wall;
55 	int8 state;
56 };
57 
58 struct LevelTempData {
59 	uint8 *wallsXorData;
60 	uint16 *flags;
61 	void *monsters;
62 	void *flyingObjects;
63 	void *wallsOfForce;
64 	uint8 monsterDifficulty;
65 };
66 
67 struct EoBFlyingObject {
68 	uint8 enable;
69 	uint8 objectType;
70 	int16 attackerId;
71 	Item item;
72 	uint16 curBlock;
73 	uint16 starting;
74 	uint8 u1;
75 	uint8 direction;
76 	uint8 distance;
77 	int8 callBackIndex;
78 	uint8 curPos;
79 	uint8 flags;
80 	uint8 unused;
81 };
82 
83 struct KyraRpgGUISettings {
84 	struct DialogueButtons {
85 		uint8 labelColor1;
86 		uint8 labelColor2;
87 		uint16 width;
88 		uint16 height;
89 		int waitReserve;
90 		uint16 waitX[2];
91 		uint8 waitY[2];
92 		uint16 waitWidth[2];
93 	} buttons;
94 
95 	struct Colors {
96 		uint8 frame1;
97 		uint8 frame2;
98 		int fill;
99 
100 		uint8 sfill;
101 		uint8 barGraph;
102 
103 		uint8 warningFrame1;
104 		uint8 warningFrame2;
105 		int warningFill;
106 
107 		uint8 extraFrame1;
108 		uint8 extraFrame2;
109 		int extraFill;
110 
111 		uint8 inactiveTabFrame1;
112 		uint8 inactiveTabFrame2;
113 		int inactiveTabFill;
114 
115 		uint8 guiColorWhite;
116 		uint8 guiColorLightRed;
117 		uint8 guiColorDarkRed;
118 		uint8 guiColorLightBlue;
119 		uint8 guiColorBlue;
120 		uint8 guiColorYellow;
121 		uint8 guiColorLightGreen;
122 		uint8 guiColorDarkGreen;
123 		uint8 guiColorBlack;
124 	} colors;
125 };
126 
127 class KyraRpgEngine : public KyraEngine_v1 {
128 friend class TextDisplayer_rpg;
129 public:
130 	KyraRpgEngine(OSystem *system, const GameFlags &flags);
131 	virtual ~KyraRpgEngine();
132 
133 	virtual Screen *screen() = 0;
134 	virtual GUI *gui() const = 0;
135 
136 protected:
137 	// Startup
138 	virtual Common::Error init();
139 	virtual Common::Error go() = 0;
140 
141 	// Init
142 	void initStaticResource();
143 
144 	const uint8 **_itemIconShapes;
145 	const uint8 **_amigaBlueItemIconShapes;
146 
147 	// Main loop
148 	virtual void update() = 0;
149 	void updateEnvironmentalSfx(int soundId);
150 
151 	// timers
152 	virtual void setupTimers() = 0;
153 	virtual void enableSysTimer(int sysTimer);
154 	virtual void disableSysTimer(int sysTimer);
155 	void enableTimer(int id);
156 	virtual uint8 getClock2Timer(int index) = 0;
157 	virtual uint8 getNumClock2Timers() = 0;
158 
159 	void timerProcessDoors(int timerNum);
160 
161 	// mouse
162 	bool posWithinRect(int posX, int posY, int x1, int y1, int x2, int y2);
163 	virtual void setHandItem(Item itemIndex) = 0;
164 
165 	// Characters
166 	int _updateCharNum;
167 	int _updatePortraitSpeechAnimDuration;
168 	bool _fadeText;
169 	int _resetPortraitAfterSpeechAnim;
170 	int _needSceneRestore;
171 
172 	// Items
173 	int _itemInHand;
174 
175 	// Monsters
176 	int getBlockDistance(uint16 block1, uint16 block2);
177 
178 	uint8 **_monsterPalettes;
179 	uint8 **_monsterShapes;
180 
181 	int16 _shpDmX1;
182 	int16 _shpDmX2;
183 
184 	int _monsterStepCounter;
185 	int _monsterStepMode;
186 
187 	// Level
188 	virtual void addLevelItems() = 0;
189 	virtual void loadBlockProperties(const char *file) = 0;
190 
191 	virtual void drawScene(int pageNum) = 0;
192 	virtual void drawSceneShapes(int start) = 0;
193 	virtual void drawDecorations(int index) = 0;
194 
195 	virtual const uint8 *getBlockFileData(int levelIndex) = 0;
196 	void setLevelShapesDim(int index, int16 &x1, int16 &x2, int dim);
197 	void setDoorShapeDim(int index, int16 &y1, int16 &y2, int dim);
198 	void drawLevelModifyScreenDim(int dim, int16 x1, int16 y1, int16 x2, int16 y2);
199 	void generateBlockDrawingBuffer();
200 	void generateVmpTileData(int16 startBlockX, uint8 startBlockY, uint8 wllVmpIndex, int16 vmpOffset, uint8 numBlocksX, uint8 numBlocksY);
201 	void generateVmpTileDataFlipped(int16 startBlockX, uint8 startBlockY, uint8 wllVmpIndex, int16 vmpOffset, uint8 numBlocksX, uint8 numBlocksY);
202 	bool hasWall(int index);
203 	void assignVisibleBlocks(int block, int direction);
204 	bool checkSceneUpdateNeed(int block);
205 	uint16 calcNewBlockPosition(uint16 curBlock, uint16 direction);
206 
207 	void drawVcnBlocks();
208 	void vcnDraw_fw_4bit(uint8 *&dst, const uint8 *&src);
209 	void vcnDraw_bw_4bit(uint8 *&dst, const uint8 *&src);
210 	void vcnDraw_fw_trans_4bit(uint8 *&dst, const uint8 *&src);
211 	void vcnDraw_bw_trans_4bit(uint8 *&dst, const uint8 *&src);
212 	void vcnDraw_fw_hiCol(uint8 *&dst, const uint8 *&src);
213 	void vcnDraw_bw_hiCol(uint8 *&dst, const uint8 *&src);
214 	void vcnDraw_fw_trans_hiCol(uint8 *&dst, const uint8 *&src);
215 	void vcnDraw_bw_trans_hiCol(uint8 *&dst, const uint8 *&src);
216 	void vcnDraw_fw_Amiga(uint8 *&dst, const uint8 *&src);
217 	void vcnDraw_bw_Amiga(uint8 *&dst, const uint8 *&src);
218 	void vcnDraw_fw_trans_Amiga(uint8 *&dst, const uint8 *&src);
219 	void vcnDraw_bw_trans_Amiga(uint8 *&dst, const uint8 *&src);
220 
221 	typedef Common::Functor2Mem<uint8 *&, const uint8 *&, void, KyraRpgEngine> VcnDrawProc;
222 	struct VcnLineDrawingMethods {
VcnLineDrawingMethodsVcnLineDrawingMethods223 		VcnLineDrawingMethods(VcnDrawProc *fw, VcnDrawProc *bw, VcnDrawProc *fw_t, VcnDrawProc *bw_t) : forward(fw), backwards(bw), forward_trans(fw_t), backwards_trans(bw_t) {}
~VcnLineDrawingMethodsVcnLineDrawingMethods224 		~VcnLineDrawingMethods() {
225 			delete forward;
226 			delete backwards;
227 			delete forward_trans;
228 			delete backwards_trans;
229 		}
230 
231 		VcnDrawProc *forward;
232 		VcnDrawProc *backwards;
233 		VcnDrawProc *forward_trans;
234 		VcnDrawProc *backwards_trans;
235 	};
236 	VcnLineDrawingMethods *_vcnDrawLine;
237 
238 	virtual int clickedDoorSwitch(uint16 block, uint16 direction) = 0;
239 	int clickedWallShape(uint16 block, uint16 direction);
240 	int clickedLeverOn(uint16 block, uint16 direction);
241 	int clickedLeverOff(uint16 block, uint16 direction);
242 	int clickedWallOnlyScript(uint16 block);
243 	virtual int clickedNiche(uint16 block, uint16 direction) = 0;
244 
245 	void processDoorSwitch(uint16 block, int openClose);
246 	void openCloseDoor(int block, int openClose);
247 	void completeDoorOperations();
248 
249 	uint8 *_wllVmpMap;
250 	int8 *_wllShapeMap;
251 	uint8 *_specialWallTypes;
252 	uint8 *_wllWallFlags;
253 
254 	int _sceneXoffset;
255 	int _sceneShpDim;
256 
257 	LevelBlockProperty *_levelBlockProperties;
258 	LevelBlockProperty *_visibleBlocks[18];
259 	LevelDecorationProperty *_levelDecorationData;
260 	uint16 _levelDecorationDataSize;
261 	LevelDecorationProperty *_levelDecorationProperties;
262 	uint8 **_levelDecorationShapes;
263 	uint16 _decorationCount;
264 	int16 _mappedDecorationsCount;
265 	uint16 *_vmpPtr;
266 	uint8 *_vcnBlocks;
267 	uint8 *_vcfBlocks;
268 	uint8 *_vcnTransitionMask;
269 	uint8 *_vcnMaskTbl;
270 	uint8 *_vcnShift;
271 	uint8 _vcnShiftVal;
272 	uint8 *_vcnColTable;
273 	uint8 _vcnSrcBitsPerPixel;
274 	uint8 _vcnBpp;
275 	uint16 *_blockDrawingBuffer;
276 	uint8 *_sceneWindowBuffer;
277 	uint8 _blockBrightness;
278 	uint8 _wllVcnOffset;
279 	uint8 _wllVcnOffset2;
280 	uint8 _wllVcnRmdOffset;
281 
282 	uint8 **_doorShapes;
283 
284 	uint8 _currentLevel;
285 	uint16 _currentBlock;
286 	uint16 _currentDirection;
287 	int _sceneDefaultUpdate;
288 	bool _sceneUpdateRequired;
289 
290 	int16 _visibleBlockIndex[18];
291 	int16 *_lvlShapeLeftRight;
292 	int16 *_lvlShapeTop;
293 	int16 *_lvlShapeBottom;
294 
295 	char _lastBlockDataFile[13];
296 	uint32 _hasTempDataFlags;
297 
298 	int16 _sceneDrawVarDown;
299 	int16 _sceneDrawVarRight;
300 	int16 _sceneDrawVarLeft;
301 	int _wllProcessFlag;
302 
303 	OpenDoorState _openDoorState[3];
304 
305 	int _sceneDrawPage1;
306 	int _sceneDrawPage2;
307 
308 	const int8 *_dscShapeIndex;
309 	const uint8 *_dscDimMap;
310 	const int8 *_dscDim1;
311 	const int8 *_dscDim2;
312 	const int16 *_dscShapeX;
313 	const uint8 *_dscDoorScaleOffs;
314 	const uint8 *_dscBlockMap;
315 	const int8 *_dscBlockIndex;
316 	const uint8 *_dscTileIndex;
317 
318 	const uint8 *_dscDoorShpIndex;
319 	int _dscDoorShpIndexSize;
320 	const uint8 *_dscDoorY2;
321 	const uint8 *_dscDoorFrameY1;
322 	const uint8 *_dscDoorFrameY2;
323 	const uint8 *_dscDoorFrameIndex1;
324 	const uint8 *_dscDoorFrameIndex2;
325 
326 	// Script
327 	virtual void runLevelScript(int block, int flags) = 0;
328 
329 	// Gui
330 	void removeInputTop();
331 	void gui_drawBox(int x, int y, int w, int h, int frameColor1, int frameColor2, int fillColor);
332 	virtual void gui_drawHorizontalBarGraph(int x, int y, int w, int h, int32 curVal, int32 maxVal, int col1, int col2);
333 	void gui_initButtonsFromList(const uint8 *list);
334 	virtual void gui_initButton(int index, int x = -1, int y = -1, int val = -1) = 0;
335 	void gui_resetButtonList();
336 	void gui_notifyButtonListChanged();
337 
338 	bool clickedShape(int shapeIndex);
339 
340 	virtual const KyraRpgGUISettings *guiSettings() const = 0;
useMainMenuGUISettings(bool toggle)341 	virtual void useMainMenuGUISettings(bool toggle) {};
342 
343 	int _clickedShapeXOffs;
344 	int _clickedShapeYOffs;
345 
346 	Button *_activeButtons;
347 	Button _activeButtonData[70];
348 	Common::Array<Button::Callback> _buttonCallbacks;
349 	//bool _processingButtons;
350 
351 	uint8 _mouseClick;
352 	bool _preserveEvents;
353 	bool _buttonListChanged;
354 
355 	int _updateFlags;
356 	int _clickedSpecialFlag;
357 
358 	int _compassDirection;
359 
360 	static const uint8 _dropItemDirIndex[];
361 
362 	// text
363 	void drawDialogueButtons();
364 	uint16 processDialogue();
365 
366 	TextDisplayer_rpg *_txt;
txt()367 	virtual TextDisplayer_rpg *txt() { return _txt; }
368 
369 	bool _dialogueField;
370 	bool _dialogueFieldAmiga;
371 
372 	const char *_dialogueButtonString[9];
373 	const uint16 *_dialogueButtonPosX;
374 	const uint8 *_dialogueButtonPosY;
375 	int16 _dialogueButtonYoffs;
376 	uint16 _dialogueButtonWidth;
377 	int _dialogueNumButtons;
378 	int _dialogueHighlightedButton;
379 	int _currentControlMode;
380 	int _specialSceneFlag;
381 	uint8 _dialogueButtonLabelColor1;
382 	uint8 _dialogueButtonLabelColor2;
383 
384 	const char *const *_moreStrings;
385 
386 	// misc
387 	virtual void delay(uint32 millis, bool doUpdate = false, bool isMainLoop = false) = 0;
388 	void delayUntil(uint32 time, bool unused = false, bool doUpdate = false, bool isMainLoop = false);
389 	int rollDice(int times, int pips, int inc = 0);
390 
391 	virtual Common::Error loadGameState(int slot) = 0;
392 	virtual Common::Error saveGameStateIntern(int slot, const char *saveName, const Graphics::Surface *thumbnail) = 0;
393 
394 	void generateTempData();
395 	virtual void restoreBlockTempData(int levelIndex);
396 	void releaseTempData();
397 	virtual void *generateMonsterTempData(LevelTempData *tmp) = 0;
398 	virtual void restoreMonsterTempData(LevelTempData *tmp) = 0;
399 	virtual void releaseMonsterTempData(LevelTempData *tmp) = 0;
400 	void restoreFlyingObjectTempData(LevelTempData *tmp);
401 	void *generateFlyingObjectTempData(LevelTempData *tmp);
402 	void releaseFlyingObjectTempData(LevelTempData *tmp);
generateWallOfForceTempData(LevelTempData * tmp)403 	virtual void *generateWallOfForceTempData(LevelTempData *tmp) { return 0; }
restoreWallOfForceTempData(LevelTempData * tmp)404 	virtual void restoreWallOfForceTempData(LevelTempData *tmp) {}
releaseWallOfForceTempData(LevelTempData * tmp)405 	virtual void releaseWallOfForceTempData(LevelTempData *tmp) {}
406 
407 	LevelTempData *_lvlTempData[29];
408 	const int _numFlyingObjects;
409 	uint32 _flyingObjectStructSize;
410 	void *_flyingObjectsPtr;
411 
412 	// sound
413 	virtual bool snd_processEnvironmentalSoundEffect(int soundId, int block);
snd_stopSpeech(bool)414 	virtual void snd_stopSpeech(bool) {}
snd_updateCharacterSpeech()415 	virtual int snd_updateCharacterSpeech() { return 0; }
stopPortraitSpeechAnim()416 	virtual void stopPortraitSpeechAnim() {}
setupOpcodeTable()417 	virtual void setupOpcodeTable() {}
snd_playVoiceFile(int)418 	virtual void snd_playVoiceFile(int) {}
419 
420 	int _environmentSfx;
421 	int _environmentSfxVol;
422 	int _envSfxDistThreshold;
423 
424 	uint32 _activeVoiceFileTotalTime;
425 
426 	// unused
setWalkspeed(uint8)427 	void setWalkspeed(uint8) {}
removeHandItem()428 	void removeHandItem() {}
lineIsPassable(int,int)429 	bool lineIsPassable(int, int) { return false; }
430 };
431 
432 } // End of namespace Kyra
433 
434 #endif // ENABLE_EOB || ENABLE_LOL
435 
436 #endif
437