ScummVM API documentation
dm.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/*
23 * Based on the Reverse Engineering work of Christophe Fontanel,
24 * maintainer of the Dungeon Master Encyclopaedia (http://dmweb.free.fr/)
25 */
26
27#ifndef DM_DM_H
28#define DM_DM_H
29
30#include "engines/engine.h"
31#include "engines/savestate.h"
32
33#include "common/random.h"
34#include "common/savefile.h"
35#include "common/str.h"
36#include "common/memstream.h"
37
38#include "advancedDetector.h"
39
40#include "dm/console.h"
41#include "dm/detection.h"
42
43namespace DM {
44
45class DisplayMan;
46class DungeonMan;
47class EventManager;
48class MenuMan;
49class ChampionMan;
50class ObjectMan;
51class InventoryMan;
52class TextMan;
53class MovesensMan;
54class GroupMan;
55class Timeline;
56class ProjExpl;
57class DialogMan;
58class SoundMan;
59
60enum DMActions {
61 kActionNone,
62 kActionToggleInventoryChampion0,
63 kActionToggleInventoryChampion1,
64 kActionToggleInventoryChampion2,
65 kActionToggleInventoryChampion3,
66 kActionSave,
67 kActionFreezeGame,
68 kActionTurnLeft,
69 kActionMoveForward,
70 kActionTurnRight,
71 kActionMoveLeft,
72 kActionMoveBackward,
73 kActionMoveRight,
74 kActionWakeUp,
75 kActionSelectChoice,
76};
77
78enum Direction {
79 kDMDirNorth = 0,
80 kDMDirEast = 1,
81 kDMDirSouth = 2,
82 kDMDirWest = 3
83};
84
85enum ThingType {
86 kDMThingTypeParty = -1, // @ CM1_THING_TYPE_PARTY
87 kDMThingTypeDoor = 0, // @ C00_THING_TYPE_DOOR
88 kDMThingTypeTeleporter = 1, // @ C01_THING_TYPE_TELEPORTER
89 kDMstringTypeText = 2, // @ C02_THING_TYPE_TEXTSTRING
90 kDMThingTypeSensor = 3, // @ C03_THING_TYPE_SENSOR
91 kDMThingTypeGroup = 4, // @ C04_THING_TYPE_GROUP
92 kDMThingTypeWeapon = 5, // @ C05_THING_TYPE_WEAPON
93 kDMThingTypeArmour = 6, // @ C06_THING_TYPE_ARMOUR
94 kDMThingTypeScroll = 7, // @ C07_THING_TYPE_SCROLL
95 kDMThingTypePotion = 8, // @ C08_THING_TYPE_POTION
96 kDMThingTypeContainer = 9, // @ C09_THING_TYPE_CONTAINER
97 kDMThingTypeJunk = 10, // @ C10_THING_TYPE_JUNK
98 kDMThingTypeProjectile = 14, // @ C14_THING_TYPE_PROJECTILE
99 kDMThingTypeExplosion = 15, // @ C15_THING_TYPE_EXPLOSION
100 kDMThingTypeTotal = 16 // +1 than the last (explosionThingType)
101}; // @ C[00..15]_THING_TYPE_...
102
103enum Cell {
104 kDMCellAny = -1, // @ CM1_CELL_ANY
105 kDMCellNorthWest = 0, // @ C00_CELL_NORTHWEST
106 kDMCellNorthEast = 1, // @ C01_CELL_NORTHEAST
107 kDMCellSouthEast = 2, // @ C02_CELL_SOUTHEAST
108 kDMCellSouthWest = 3 // @ C03_CELL_SOUTHWEST
109};
110
111enum GameMode {
112 kDMModeLoadSavedGame = 0, // @ C000_MODE_LOAD_SAVED_GAME
113 kDMModeLoadDungeon = 1, // @ C001_MODE_LOAD_DUNGEON
114 kDMModeWaitingOnEntrance = 99, // @ C099_MODE_WAITING_ON_ENTRANCE
115 kDMModeEntranceDrawCredits = 202 // @ C202_MODE_ENTRANCE_DRAW_CREDITS
116};
117
118enum LoadgameResult {
119 kDMLoadgameFailure = -1, // @ CM1_LOAD_GAME_FAILURE
120 kDMLoadgameSuccess = 1// @ C01_LOAD_GAME_SUCCESS
121};
122
123enum MapIndice {
124 kDMMapIndexNone = -1, // @ CM1_MAP_INDEX_NONE
125 kDMMapIndexEntrance = 255 // @ C255_MAP_INDEX_ENTRANCE
126};
127
128#define kDMMaskDecodeEvenIfInvisible 0x8000 // @ MASK0x8000_DECODE_EVEN_IF_INVISIBLE
129#define kDMMaskMergeCycles 0x8000 // @ MASK0x8000_MERGE_CYCLES
130
131#define kDMSlotBoxInventoryFirstSlot 8 // @ C08_SLOT_BOX_INVENTORY_FIRST_SLOT
132#define kDMSlotBoxInventoryActionHand 9 // @ C09_SLOT_BOX_INVENTORY_ACTION_HAND
133#define kDMSlotBoxChestFirstSlot 38 // @ C38_SLOT_BOX_CHEST_FIRST_SLOT
134
135class Thing {
136public:
137 uint16 _data;
138
139 Thing() : _data(0xFFFF) {}
140 explicit Thing(uint16 d) { set(d); }
141
142 void set(uint16 d) {
143 _data = d;
144 }
145
146 byte getCell() const { return _data >> 14; }
147 ThingType getType() const { return (ThingType)((_data >> 10) & 0xF); }
148 uint16 getIndex() const { return _data & 0x3FF; }
149
150 void setCell(uint16 cell) { _data = (_data & ~(0x3 << 14)) | ((cell & 0x3) << 14); }
151 void setType(uint16 type) { _data = (_data & ~(0xF << 10)) | ((type & 0xF) << 10); }
152 void setIndex(uint16 index) { _data = (_data & ~0x3FF) | (index & 0x3FF); }
153
154 uint16 getTypeAndIndex() { return _data & 0x3FFF; }
155 uint16 toUint16() const { return _data; } // I don't like 'em cast operators
156 bool operator==(const Thing &rhs) const { return _data == rhs._data; }
157 bool operator!=(const Thing &rhs) const { return _data != rhs._data; }
158}; // @ THING
159
160#define setFlag(val, mask) ((val) |= (mask))
161#define getFlag(val, mask) ((val) & (mask))
162#define clearFlag(val, mask) ((val) &= (~(mask))) // @ M09_CLEAR
163
164// Note: F0026_MAIN_GetBoundedValue<T> has been replaced by CLIP<T>
165
166#define CALL_MEMBER_FN(object, ptrToMember) ((object).*(ptrToMember))
167
168
169class DMEngine : public Engine {
170private:
171 void startGame(); // @ F0462_START_StartGame_CPSF
172 void processNewPartyMap(uint16 mapIndex); // @ F0003_MAIN_ProcessNewPartyMap_CPSE
173 void initializeGame(); // @ F0463_START_InitializeGame_CPSADEF
174 void initMemoryManager(); // @ F0448_STARTUP1_InitializeMemoryManager_CPSADEF
175 void gameloop(); // @ F0002_MAIN_GameLoop_CPSDF
176 void initConstants();
177 Common::String getSavefileName(uint16 slot);
178 Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
179 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
180 Common::Error writeCompleteSaveFile(Common::WriteStream *file);
181 void drawEntrance(); // @ F0439_STARTEND_DrawEntrance
182 void fuseSequenceUpdate(); // @ F0445_STARTEND_FuseSequenceUpdate
183 void processEntrance(); // @ F0441_STARTEND_ProcessEntrance
184 void openEntranceDoors(); // @ F0438_STARTEND_OpenEntranceDoors
185 void drawTittle(); // @ F0437_STARTEND_DrawTitle
186
187public:
188 explicit DMEngine(OSystem *syst, const DMADGameDescription *gameDesc);
189 ~DMEngine() override;
190 bool hasFeature(EngineFeature f) const override;
191
192 Common::Error loadGameState(int slot) override;
193 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
194 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
195 Common::String getSaveStateName(int slot) const override;
196
197 bool isDemo() const;
198
199 void delay(uint16 verticalBlank); // @ F0022_MAIN_Delay
200 uint16 getScaledProduct(uint16 val, uint16 scale, uint16 vale2); // @ F0030_MAIN_GetScaledProduct
201 uint16 getRandomNumber(uint32 max) { return _rnd->getRandomNumber(max - 1); }
202 int16 ordinalToIndex(int16 val); // @ M01_ORDINAL_TO_INDEX
203 int16 indexToOrdinal(int16 val); // @ M00_INDEX_TO_ORDINAL
204 Common::Error run() override; // @ main
205 void saveGame(); // @ F0433_STARTEND_ProcessCommand140_SaveGame_CPSCDF
206 LoadgameResult loadgame(int16 slot); // @ F0435_STARTEND_LoadGame_CPSF
207 void endGame(bool doNotDrawCreditsOnly); // @ F0444_STARTEND_Endgame
208
209 void entranceDrawCredits();
210 void fuseSequence(); // @ F0446_STARTEND_FuseSequence
211 Common::Language getGameLanguage();
212 Common::Platform getPlatform() const { return _gameVersion->_desc.platform; }
213
214 Direction turnDirRight(int16 dir); // @ M17_NEXT
215 Direction turnDirLeft(int16 dir); // @ M19_PREVIOUS
216 Direction returnOppositeDir(int16 dir); // @ M18_OPPOSITE
217 bool isOrientedWestEast(int16 dir); // @ M16_IS_ORIENTED_WEST_EAST
218 uint16 normalizeModulo4(int16 dir); // @ M21_NORMALIZE
219
220 int32 filterTime(int32 mapTime); // @ M30_TIME
221 int32 setMapAndTime(uint32 map, uint32 time); // @ M33_SET_MAP_AND_TIME
222 uint16 getMap(int32 mapTime); // @ M29_MAP
223 Thing thingWithNewCell(Thing thing, int16 cell); // @ M15_THING_WITH_NEW_CELL
224 int16 getDistance(int16 mapx1, int16 mapy1, int16 mapx2, int16 mapy2); // @ M38_DISTANCE
225 int32 setMap(int32 &mapTime, uint32 map); // @ M31_setMap
226
227
228private:
229 uint16 _dungeonId; // @ G0526_ui_DungeonID
230 byte *_interfaceCredits; // @ G0564_puc_Graphic5_InterfaceCredits
232
233 byte *_savedScreenForOpenEntranceDoors; // ad-hoc HACK
234 const DMADGameDescription *_gameVersion;
235 bool _canLoadFromGMM;
236public:
237 byte *_entranceDoorAnimSteps[10]; // @ G0562_apuc_Bitmap_EntranceDoorAnimationSteps
238 Console *_console;
239 DisplayMan *_displayMan;
240 DungeonMan *_dungeonMan;
241 EventManager *_eventMan;
242 MenuMan *_menuMan;
243 ChampionMan *_championMan;
244 ObjectMan *_objectMan;
245 InventoryMan *_inventoryMan;
246 TextMan *_textMan;
247 MovesensMan *_moveSens;
248 GroupMan *_groupMan;
249 Timeline *_timeline;
250 ProjExpl *_projexpl;
251 DialogMan *_dialog;
252 SoundMan *_sound;
253
254 Common::MemoryWriteStreamDynamic *_saveThumbnail;
255
256 bool _engineShouldQuit;
257 int _loadSaveSlotAtRuntime;
258
259 GameMode _gameMode; // @ G0298_B_NewGame
260 bool _restartGameRequest; // @ G0523_B_RestartGameRequested
261
262 bool _stopWaitingForPlayerInput; // @ G0321_B_StopWaitingForPlayerInput
263 bool _gameTimeTicking; // @ G0301_B_GameTimeTicking
264 bool _restartGameAllowed; // @ G0524_B_RestartGameAllowed
265 bool _pressingEye; // @ G0331_B_PressingEye
266 bool _stopPressingEye; // @ G0332_B_StopPressingEye
267 bool _pressingMouth; // @ G0333_B_PressingMouth
268 bool _stopPressingMouth; // @ G0334_B_StopPressingMouth
269 bool _highlightBoxInversionRequested; // @ G0340_B_HighlightBoxInversionRequested
270 int16 _projectileDisableMovementTicks; // @ G0311_i_ProjectileDisabledMovementTicks
271 int16 _lastProjectileDisabledMovementDirection; // @ G0312_i_LastProjectileDisabledMovementDirection
272 bool _gameWon; // @ G0302_B_GameWon
273 int16 _newPartyMapIndex; // @ G0327_i_NewPartyMapIndex
274 bool _setMousePointerToObjectInMainLoop; // @ G0325_B_SetMousePointerToObjectInMainLoop
275 int16 _disabledMovementTicks; // @ G0310_i_DisabledMovementTicks
276
277 int8 _dirIntoStepCountEast[4]; // @ G0233_ai_Graphic559_DirectionToStepEastCount
278 int8 _dirIntoStepCountNorth[4]; // @ G0234_ai_Graphic559_DirectionToStepNorthCount
279 int32 _gameTime; // @ G0313_ul_GameTime
280 char _stringBuildBuffer[128]; // @ G0353_ac_StringBuildBuffer
281 int16 _waitForInputMaxVerticalBlankCount; // @ G0318_i_WaitForInputMaximumVerticalBlankCount
282
283 Thing _thingNone; // @ C0xFFFF_THING_NONE
284 Thing _thingEndOfList; // @ C0xFFFE_THING_ENDOFLIST
285 Thing _thingFirstExplosion; // @ C0xFF80_THING_FIRST_EXPLOSION
286 Thing _thingExplFireBall; // @ C0xFF80_THING_EXPLOSION_FIREBALL
287 Thing _thingExplSlime; // @ C0xFF81_THING_EXPLOSION_SLIME
288 Thing _thingExplLightningBolt; // @ C0xFF82_THING_EXPLOSION_LIGHTNING_BOLT
289 Thing _thingExplHarmNonMaterial; // @ C0xFF83_THING_EXPLOSION_HARM_NON_MATERIAL
290 Thing _thingExplOpenDoor; // @ C0xFF84_THING_EXPLOSION_OPEN_DOOR
291 Thing _thingExplPoisonBolt; // @ C0xFF86_THING_EXPLOSION_POISON_BOLT
292 Thing _thingExplPoisonCloud; // @ C0xFF87_THING_EXPLOSION_POISON_CLOUD
293 Thing _thingExplSmoke; // @ C0xFFA8_THING_EXPLOSION_SMOKE
294 Thing _thingExplFluxcage; // @ C0xFFB2_THING_EXPLOSION_FLUXCAGE
295 Thing _thingExplRebirthStep1; // @ C0xFFE4_THING_EXPLOSION_REBIRTH_STEP1
296 Thing _thingExplRebirthStep2; // @ C0xFFE5_THING_EXPLOSION_REBIRTH_STEP2
297 Thing _thingParty; // @ C0xFFFF_THING_PARTY
298};
299
300
301} // End of namespace DM
302
303#endif
Definition: error.h:81
Definition: memstream.h:194
Definition: random.h:44
uint getRandomNumber(uint max)
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: champion.h:491
Definition: console.h:36
Definition: dm.h:169
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Common::Error loadGameState(int slot) override
bool hasFeature(EngineFeature f) const override
Common::String getSaveStateName(int slot) const override
Common::Error run() override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: dialog.h:48
Definition: gfx.h:758
Definition: dungeonman.h:609
Definition: eventman.h:199
Definition: group.h:151
Definition: inventory.h:53
Definition: menus.h:77
Definition: movesens.h:45
Definition: objectman.h:48
Definition: projexpl.h:43
Definition: sounds.h:109
Definition: text.h:42
Definition: dm.h:135
Definition: timeline.h:151
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
Definition: system.h:166
Language
Definition: language.h:45
Platform
Definition: platform.h:93
Common::Platform platform
Definition: advancedDetector.h:199
Definition: detection.h:70