aboutsummaryrefslogtreecommitdiff
path: root/engines/dm/dm.cpp
blob: 94f9f30420d31a874c0debdf5cbd6a1bdfc12e30 (plain)
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
#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"

namespace DM {

int8 dirIntoStepCountEast[4] = {0 /* North */, 1 /* East */, 0 /* West */, -1 /* South */};
int8 dirIntoStepCountNorth[4] = {-1 /* North */, 0 /* East */, 1 /* West */, 0 /* South */};

void turnDirRight(direction &dir) { dir = (direction)((dir + 1) & 3); }
void turnDirLeft(direction &dir) { dir = (direction)((dir - 1) & 3); }
bool isOrientedWestEast(direction dir) { return dir & 1; }


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;
	_stopWaitingForPlayerInput = false;
	_gameTimeTicking = 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;

	// clear debug channels
	DebugMan.clearAllDebugChannels();
}

void DMEngine::initializeGame() {
	_displayMan->loadGraphics();
	// DUMMY CODE: next line
	_displayMan->loadPalette(gPalCredits);

	_eventMan->initMouse();

	while (_loadsaveMan->loadgame() != kLoadgameSuccess) {
		// MISSING CODE: F0441_STARTEND_ProcessEntrance
	}

	_displayMan->loadFloorSet(kFloorSetStone);
	_displayMan->loadWallSet(kWallSetStone);

	startGame();
	warning("MISSING CODE: F0267_MOVE_GetMoveResult_CPSCE (if newGame)");
	_eventMan->showMouse(true);
	warning("MISSING CODE: F0357_COMMAND_DiscardAllInput");
}


void DMEngine::startGame() {
	_eventMan->_primaryMouseInput = gPrimaryMouseInput_Interface;
	_eventMan->_secondaryMouseInput = gSecondaryMouseInput_Movement;
	// TODO:(next 2 lines) move to F0003_MAIN_ProcessNewPartyMap_CPSE
	_dungeonMan->setCurrentMapAndPartyMap(0);
	_displayMan->loadCurrentMapGraphics();


	_menuMan->drawMovementArrows();
	_gameTimeTicking = true;

	// MISSING CODE: Lot of stuff
}

Common::Error DMEngine::run() {
	// 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);
	_displayMan->setUpScreens(320, 200);

	initializeGame(); // @ F0463_START_InitializeGame_CPSADEF
	while (true) {
		gameloop();
		// MISSING CODE: F0444_STARTEND_Endgame(G0303_B_PartyDead);
	}

	return Common::kNoError;
}

void DMEngine::gameloop() {
	while (true) {
		_stopWaitingForPlayerInput = false;
		//do {
		_eventMan->processInput();
		_eventMan->processCommandQueue();
		//} while (!_stopWaitingForPlayerInput || !_gameTimeTicking);

		_displayMan->clearScreen(kColorBlack);
		_displayMan->drawDungeon(_dungeonMan->_currMap.partyDir, _dungeonMan->_currMap.partyPosX, _dungeonMan->_currMap.partyPosY);
		// DUMMY CODE: next line
		_menuMan->drawMovementArrows();
		_displayMan->updateScreen();
		_system->delayMillis(10);
	}
}

} // End of namespace DM