This repository has been archived by the owner on Mar 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathengine.cpp
240 lines (223 loc) · 5.5 KB
/
engine.cpp
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
/*
* Another World engine rewrite
* Copyright (C) 2004-2005 Gregory Montoir (cyx@users.sourceforge.net)
*/
#include "engine.h"
#include "file.h"
#include "graphics.h"
#include "resource_nth.h"
#include "systemstub.h"
#include "util.h"
Engine::Engine(const char *dataDir, int partNum)
: _graphics(0), _stub(0), _script(&_mix, &_res, &_ply, &_vid), _mix(&_ply), _res(&_vid, dataDir),
_ply(&_res), _vid(&_res), _partNum(partNum) {
_res.detectVersion();
}
static const int _restartPos[36 * 2] = {
16008, 0, 16001, 0, 16002, 10, 16002, 12, 16002, 14,
16003, 20, 16003, 24, 16003, 26, 16004, 30, 16004, 31,
16004, 32, 16004, 33, 16004, 34, 16004, 35, 16004, 36,
16004, 37, 16004, 38, 16004, 39, 16004, 40, 16004, 41,
16004, 42, 16004, 43, 16004, 44, 16004, 45, 16004, 46,
16004, 47, 16004, 48, 16004, 49, 16006, 64, 16006, 65,
16006, 66, 16006, 67, 16006, 68, 16005, 50, 16006, 60,
16007, 0
};
void Engine::setSystemStub(SystemStub *stub, Graphics *graphics) {
_stub = stub;
_script._stub = stub;
_graphics = graphics;
}
void Engine::run() {
switch (_state) {
case kStateLogo3DO:
doThreeScreens();
scrollText(0, 380, Video::_noteText3DO);
playCinepak("Logo.Cine");
playCinepak("Spintitle.Cine");
break;
case kStateTitle3DO:
titlePage();
break;
case kStateEnd3DO:
doEndCredits();
break;
case kStateGame:
_script.setupTasks();
_script.updateInput();
processInput();
_script.runTasks();
_mix.update();
if (_res.getDataType() == Resource::DT_3DO) {
switch (_res._nextPart) {
case 16009:
_state = kStateEnd3DO;
break;
case 16000:
_state = kStateTitle3DO;
break;
}
}
break;
}
}
void Engine::setup(Language lang, int graphicsType, const char *scalerName, int scalerFactor) {
_vid._graphics = _graphics;
int w = GFX_W * scalerFactor;
int h = GFX_H * scalerFactor;
if (_res.getDataType() != Resource::DT_3DO) {
_vid._graphics->_fixUpPalette = FIXUP_PALETTE_REDRAW;
}
_vid.init();
if (scalerFactor > 1) {
_vid.setScaler(scalerName, scalerFactor);
}
_res._lang = lang;
_res.allocMemBlock();
_res.readEntries();
_res.dumpEntries();
const bool isNth = !Graphics::_is1991 && (_res.getDataType() == Resource::DT_15TH_EDITION || _res.getDataType() == Resource::DT_20TH_EDITION);
if (isNth) {
// get HD background bitmaps resolution
_res._nth->getBitmapSize(&w, &h);
}
_graphics->init(w, h);
if (isNth) {
_res.loadFont();
_res.loadHeads();
} else {
_vid.setDefaultFont();
}
_script.init();
MixerType mixerType = kMixerTypeRaw;
switch (_res.getDataType()) {
case Resource::DT_DOS:
case Resource::DT_AMIGA:
case Resource::DT_ATARI:
case Resource::DT_ATARI_DEMO:
mixerType = kMixerTypeRaw;
switch (lang) {
case LANG_FR:
_vid._stringsTable = Video::_stringsTableFr;
break;
case LANG_US:
default:
_vid._stringsTable = Video::_stringsTableEng;
break;
}
break;
case Resource::DT_WIN31:
case Resource::DT_15TH_EDITION:
case Resource::DT_20TH_EDITION:
mixerType = kMixerTypeWav;
break;
case Resource::DT_3DO:
mixerType = kMixerTypeAiff;
break;
}
_mix.init(mixerType);
#ifndef BYPASS_PROTECTION
switch (_res.getDataType()) {
case Resource::DT_DOS:
if (!_res._hasPasswordScreen) {
break;
}
/* fall-through */
case Resource::DT_AMIGA:
case Resource::DT_ATARI:
case Resource::DT_WIN31:
_partNum = kPartCopyProtection;
break;
default:
break;
}
#endif
if (_res.getDataType() == Resource::DT_3DO && _partNum == kPartIntro) {
_state = kStateLogo3DO;
} else {
_state = kStateGame;
const int num = _partNum;
if (num < 36) {
_script.restartAt(_restartPos[num * 2], _restartPos[num * 2 + 1]);
} else {
_script.restartAt(num);
}
}
}
void Engine::finish() {
_graphics->fini();
_ply.stop();
_mix.quit();
_res.freeMemBlock();
}
void Engine::processInput() {
if (_stub->_pi.fastMode) {
_script._fastMode = !_script._fastMode;
_stub->_pi.fastMode = false;
}
if (_stub->_pi.screenshot) {
_vid.captureDisplay();
_stub->_pi.screenshot = false;
}
}
void Engine::doThreeScreens() {
_script.snd_playMusic(1, 0, 0);
static const int bitmaps[] = { 67, 68, 69, -1 };
for (int i = 0; bitmaps[i] != -1 && !_stub->_pi.quit; ++i) {
_res.loadBmp(bitmaps[i]);
_vid.updateDisplay(0, _stub);
while (!_stub->_pi.quit) {
_stub->processEvents();
if (_stub->_pi.action) {
_stub->_pi.action = false;
break;
}
_stub->sleep(50);
}
}
_state = kStateTitle3DO;
}
void Engine::doEndCredits() {
scrollText(0, 380, Video::_endText3DO);
_script.snd_playMusic(0, 0, 0);
playCinepak("ootw2.cine");
_state = kStateTitle3DO;
}
void Engine::playCinepak(const char *name) {
}
void Engine::scrollText(int a, int b, const char *text) {
}
void Engine::titlePage() {
_res.loadBmp(70);
static const int kCursorColor = 0;
_vid.setPaletteColor(kCursorColor, 255, 0, 0);
static const int yPos[] = { 97, 123, 149 };
int y = 0;
while (!_stub->_pi.quit) {
_vid.copyPage(0, 1, 0);
_vid.drawRect(1, kCursorColor, 97, yPos[y], 210, yPos[y + 1]);
_stub->processEvents();
if (_stub->_pi.dirMask & PlayerInput::DIR_DOWN) {
_stub->_pi.dirMask &= ~PlayerInput::DIR_DOWN;
_partNum = kPartPassword;
y = 1;
}
if (_stub->_pi.dirMask & PlayerInput::DIR_UP) {
_stub->_pi.dirMask &= ~PlayerInput::DIR_UP;
_partNum = kPartIntro;
y = 0;
}
if (_stub->_pi.action) {
_stub->_pi.action = false;
_script.restartAt(_partNum);
break;
}
_vid.updateDisplay(1, _stub);
_stub->sleep(50);
}
_state = kStateGame;
}
void Engine::saveGameState(uint8_t slot, const char *desc) {
}
void Engine::loadGameState(uint8_t slot) {
}