1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* Based on the Reverse Engineering work of Christophe Fontanel,
* maintainer of the Dungeon Master Encyclopaedia (http://dmweb.free.fr/)
*/
#include "common/scummsys.h"
#include "common/system.h"
#include "common/debug.h"
#include "common/debug-channels.h"
#include "common/error.h"
#include "engines/util.h"
#include "engines/engine.h"
#include "graphics/palette.h"
#include "common/file.h"
#include "common/events.h"
#include "dm/dm.h"
#include "gfx.h"
#include "dungeonman.h"
#include "eventman.h"
#include "menus.h"
#include "champion.h"
#include "loadsave.h"
#include "objectman.h"
#include "inventory.h"
#include "text.h"
#include "movesens.h"
#include "group.h"
#include "timeline.h"
namespace DM {
void turnDirRight(direction &dir) { dir = (direction)((dir + 1) & 3); }
void turnDirLeft(direction &dir) { dir = (direction)((dir - 1) & 3); }
direction returnOppositeDir(direction dir) { return (direction)((dir + 2) & 3); }
uint16 returnPrevVal(uint16 val) {
return (direction)((val + 3) & 3);
}
uint16 returnNextVal(uint16 val) {
return (val + 1) & 0x3;
}
bool isOrientedWestEast(direction dir) { return dir & 1; }
uint16 getFlag(uint16 val, uint16 mask) {
return val & mask;
}
void setFlag(uint16 &val, uint16 mask) {
val |= mask;
}
void clearFlag(uint16 &val, uint16 mask) {
val &= ~mask;
}
DMEngine::DMEngine(OSystem *syst) : Engine(syst), _console(nullptr) {
// Do not load data files
// Do not initialize graphics here
// Do not initialize audio devices here
// Do these from run
//Specify all default directories
//const Common::FSNode gameDataDir(ConfMan.get("example"));
//SearchMan.addSubDirectoryMatching(gameDataDir, "example2");
DebugMan.addDebugChannel(kDMDebugExample, "example", "example desc");
// register random source
_rnd = new Common::RandomSource("quux");
_dungeonMan = nullptr;
_displayMan = nullptr;
_eventMan = nullptr;
_menuMan = nullptr;
_championMan = nullptr;
_loadsaveMan = nullptr;
_objectMan = nullptr;
_inventoryMan = nullptr;
_textMan = nullptr;
_movsens = nullptr;
_groupMan = nullptr;
_timeline = nullptr;
_g321_stopWaitingForPlayerInput = false;
_g301_gameTimeTicking = false;
_g524_restartGameAllowed = false;
_g331_pressingEye = false;
_g333_pressingMouth = false;
_g332_stopPressingEye = false;
_g334_stopPressingMouth = false;
_g340_highlightBoxInversionRequested = false;
debug("DMEngine::DMEngine");
}
DMEngine::~DMEngine() {
debug("DMEngine::~DMEngine");
// dispose of resources
delete _rnd;
delete _console;
delete _displayMan;
delete _dungeonMan;
delete _eventMan;
delete _menuMan;
delete _championMan;
delete _loadsaveMan;
delete _objectMan;
delete _inventoryMan;
delete _textMan;
delete _movsens;
delete _groupMan;
delete _timeline;
// clear debug channels
DebugMan.clearAllDebugChannels();
}
void DMEngine::initializeGame() {
_displayMan->loadGraphics();
// DUMMY CODE: next line
_displayMan->loadPalette(g19_PalCredits);
_eventMan->initMouse();
while (_loadsaveMan->loadgame() != kLoadgameSuccess) {
warning("TODO: F0441_STARTEND_ProcessEntrance");
}
_displayMan->loadFloorSet(k0_FloorSetStone);
_displayMan->loadWallSet(k0_WallSetStone);
_objectMan->loadObjectNames();
startGame();
warning("MISSING CODE: F0267_MOVE_GetMoveResult_CPSCE (if newGame)");
_eventMan->showMouse(true);
warning("MISSING CODE: F0357_COMMAND_DiscardAllInput");
}
void DMEngine::startGame() {
_g331_pressingEye = false;
_g332_stopPressingEye = false;
_g333_pressingMouth = false;
_g334_stopPressingMouth = false;
_g340_highlightBoxInversionRequested = false;
_eventMan->_highlightBoxEnabled = false;
_championMan->_g300_partyIsSleeping = false;
_championMan->_g506_actingChampionOrdinal = indexToOrdinal(kM1_ChampionNone);
_menuMan->_actionAreaContainsIcons = true;
_eventMan->_useChampionIconOrdinalAsMousePointerBitmap = indexToOrdinal(kM1_ChampionNone);
_eventMan->_primaryMouseInput = gPrimaryMouseInput_Interface;
_eventMan->_secondaryMouseInput = gSecondaryMouseInput_Movement;
warning("MISSING CODE: set primary/secondary keyboard input");
processNewPartyMap(_dungeonMan->_currMap._g309_currPartyMapIndex);
if (!_dungeonMan->_messages._g298_newGame) {
warning("TODO: loading game");
} else {
_displayMan->_g578_useByteBoxCoordinates = false;
warning("TODO: clear screen");
}
warning("TODO: build copper");
_menuMan->drawMovementArrows();
_championMan->resetDataToStartGame();
_g301_gameTimeTicking = true;
}
void DMEngine::processNewPartyMap(uint16 mapIndex) {
warning("MISSING CODE: F0194_GROUP_RemoveAllActiveGroups");
_dungeonMan->setCurrentMapAndPartyMap(mapIndex);
_displayMan->loadCurrentMapGraphics();
warning("MISSING CODE: F0195_GROUP_AddAllActiveGroups");
warning("MISSING CODE: F0337_INVENTORY_SetDungeonViewPalette");
}
Common::Error DMEngine::run() {
initArrays();
// scummvm/engine specific
initGraphics(320, 200, false);
_console = new Console(this);
_displayMan = new DisplayMan(this);
_dungeonMan = new DungeonMan(this);
_eventMan = new EventManager(this);
_menuMan = new MenuMan(this);
_championMan = new ChampionMan(this);
_loadsaveMan = new LoadsaveMan(this);
_objectMan = new ObjectMan(this);
_inventoryMan = new InventoryMan(this);
_textMan = new TextMan(this);
_movsens = new MovesensMan(this);
_groupMan = new GroupMan(this);
_timeline = new Timeline(this);
_displayMan->setUpScreens(320, 200);
initializeGame(); // @ F0463_START_InitializeGame_CPSADEF
while (true) {
gameloop();
warning("TODO: F0444_STARTEND_Endgame(G0303_B_PartyDead);");
}
return Common::kNoError;
}
void DMEngine::gameloop() {
warning("DUMMY CODE SETTING PARTY POS AND DIRECTION");
_dungeonMan->_currMap._g306_partyPosX = 10;
_dungeonMan->_currMap._g307_partyPosY = 4;
_dungeonMan->_currMap._g308_partyDir = kDirNorth;
warning("DUMMY CODE: setting InventoryMan::_inventoryChampionOrdinal to zero");
_inventoryMan->_inventoryChampionOrdinal = 0;
warning("DUMMY CODE: clearing screen to black"); // in loop below
while (true) {
_g321_stopWaitingForPlayerInput = false;
_menuMan->refreshActionAreaAndSetChampDirMaxDamageReceived();
//do {
_eventMan->processInput();
_eventMan->processCommandQueue();
//} while (!_g321_stopWaitingForPlayerInput || !_g301_gameTimeTicking);
if (!_inventoryMan->_inventoryChampionOrdinal && !_championMan->_g300_partyIsSleeping) {
Box box(0, 224, 0, 126);
_displayMan->clearScreenBox(k0_ColorBlack, box, g296_DungeonViewport); // dummy code
_displayMan->drawDungeon(_dungeonMan->_currMap._g308_partyDir, _dungeonMan->_currMap._g306_partyPosX, _dungeonMan->_currMap._g307_partyPosY);
}
// DUMMY CODE: next line
_menuMan->drawMovementArrows();
_displayMan->updateScreen();
_system->delayMillis(10);
}
}
int16 DMEngine::ordinalToIndex(int16 val) {
return val - 1;
}
int16 DMEngine::indexToOrdinal(int16 val) {
return val + 1;
}
} // End of namespace DM
|