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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2003 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#include "stdafx.h"
#include "sword1.h"
#include "backends/fs/fs.h"
#include "base/plugins.h"
#include "common/config-manager.h"
#include "common/file.h"
#include "common/timer.h"
#include "memman.h"
#include "resman.h"
#include "objectman.h"
#include "mouse.h"
#include "logic.h"
#include "sound.h"
#include "screen.h"
#include "swordres.h"
#include "menu.h"
#include "music.h"
/* Broken Sword 1 */
static const GameSettings sword1_setting =
{"sword1", "Broken Sword I", GF_DEFAULT_TO_1X_SCALER};
GameList Engine_SWORD1_gameList() {
GameList games;
games.push_back(sword1_setting);
return games;
}
GameList Engine_SWORD1_detectGames(const FSList &fslist) {
GameList detectedGames;
// Iterate over all files in the given directory
for (FSList::ConstIterator file = fslist.begin(); file != fslist.end(); ++file) {
const char *gameName = file->displayName().c_str();
if (0 == scumm_stricmp("swordres.rif", gameName)) {
// Match found, add to list of candidates, then abort inner loop.
detectedGames.push_back(sword1_setting);
break;
}
}
return detectedGames;
}
Engine *Engine_SWORD1_create(GameDetector *detector, OSystem *syst) {
return new SwordEngine(detector, syst);
}
REGISTER_PLUGIN("Broken Sword", Engine_SWORD1_gameList, Engine_SWORD1_create, Engine_SWORD1_detectGames)
SystemVars SwordEngine::_systemVars;
void SwordEngine::errorString(const char *buf1, char *buf2) {
strcpy(buf2, buf1);
}
extern uint16 _debugLevel;
SwordEngine::SwordEngine(GameDetector *detector, OSystem *syst)
: Engine(syst) {
_detector = detector;
_system = syst;
_debugLevel = ConfMan.getInt("debuglevel");
if (!_mixer->bindToSystem(syst))
warning("Sound initialization failed");
}
SwordEngine::~SwordEngine() {
}
void SwordEngine::initialize(void) {
_system->init_size(640, 480);
debug(5, "Starting memory manager");
_memMan = new MemMan();
debug(5, "Starting resource manager");
_resMan = new ResMan("swordres.rif", _memMan);
debug(5, "Starting object manager");
_objectMan = new ObjectMan(_resMan);
_mixer->setVolume(255);
_mouse = new SwordMouse(_system, _resMan, _objectMan);
_screen = new SwordScreen(_system, _resMan, _objectMan);
_music = new SwordMusic(_system, _mixer);
_sound = new SwordSound("", _mixer, _resMan);
_menu = new SwordMenu(_screen, _mouse);
_logic = new SwordLogic(_objectMan, _resMan, _screen, _mouse, _sound, _music, _menu);
_mouse->useLogic(_logic);
_systemVars.justRestoredGame = _systemVars.currentCD =
_systemVars.gamePaused = _systemVars.saveGameFlag =
_systemVars.deathScreenFlag = _systemVars.currentMusic = 0;
_systemVars.snrStatus = 0;
_systemVars.rate = 8;
switch (Common::parseLanguage(ConfMan.get("language"))) {
case Common::DE_DEU:
_systemVars.language = BS1_GERMAN;
break;
case Common::FR_FRA:
_systemVars.language = BS1_FRENCH;
break;
case Common::IT_ITA:
_systemVars.language = BS1_ITALIAN;
break;
case Common::ES_ESP:
_systemVars.language = BS1_SPANISH;
break;
case Common::PT_BRA:
_systemVars.language = BS1_PORT;
break;
// TODO add czech option
default:
_systemVars.language = BS1_ENGLISH;
}
_systemVars.playSpeech = 1;
//- start.c:
// todo: move these to somewhere else
SwordLogic::_scriptVars[GEORGE_CDT_FLAG] = GEO_TLK_TABLE;
SwordLogic::_scriptVars[CHANGE_X] = 481;
SwordLogic::_scriptVars[CHANGE_Y] = 413;
SwordLogic::_scriptVars[CHANGE_DIR] = DOWN;
SwordLogic::_scriptVars[CHANGE_PLACE] = FLOOR_1;
SwordLogic::_scriptVars[NEW_SCREEN] = 1;
_objectMan->fetchObject(PLAYER)->o_screen = 1;
_objectMan->megaEntering(1);
SwordLogic::_scriptVars[CHANGE_STANCE] = STAND;
_mouseState = 0;
}
void SwordEngine::go(void) {
initialize();
// check if we have savegames. if we do, show control panel, else start intro.
do {
mainLoop();
// mainLoop was left, show control panel
} while (true);
}
void SwordEngine::mainLoop(void) {
uint32 newTime, frameTime;
do {
// do we need the section45-hack from sword.c here?
// todo: ensure right cd is inserted
_screen->newScreen(SwordLogic::_scriptVars[NEW_SCREEN]);
_logic->newScreen(SwordLogic::_scriptVars[NEW_SCREEN]);
SwordLogic::_scriptVars[SCREEN] = SwordLogic::_scriptVars[NEW_SCREEN];
// let swordSound start room sfx
do {
_music->stream();
frameTime = _system->get_msecs();
_systemVars.saveGameFlag = 0;
debug(5, "\n\nNext logic cycle");
_logic->engine();
_logic->updateScreenParams(); // sets scrolling
_screen->recreate();
_screen->spritesAndParallax();
_mouse->animate();
newTime = _system->get_msecs();
/*if ((newTime - frameTime < 50) && (!SwordLogic::_scriptVars[NEW_PALETTE])) {
RenderScreenGDK();
BlitMenusGDK();
BlitMousePm();
if (newTime - frameTime < 40)
_system->delay_msecs(40 - (newTime - frameTime));
FlipScreens();
}*/
_sound->engine();
_screen->updateScreen();
//-
_menu->refresh(MENU_TOP);
_menu->refresh(MENU_BOT);
newTime = _system->get_msecs();
if (newTime - frameTime < 80)
delay(80 - (newTime - frameTime));
else
delay(0);
/*FlipScreens(); this is done in SwordScreen::updateScreen() now.
if (SwordLogic::_scriptVars[NEW_PALETTE]) {
SwordLogic::_scriptVars[NEW_PALETTE] = 0;
startFadePaletteUp();
}*/
_mouse->engine( _mouseX, _mouseY, _mouseState);
_mouseState = 0;
// do something smart here to implement pausing the game. If we even want that, that is.
} while ((SwordLogic::_scriptVars[SCREEN] == SwordLogic::_scriptVars[NEW_SCREEN]) &&
(_systemVars.saveGameFlag < 2)); // change screen
if (SwordLogic::_scriptVars[SCREEN] != 53) // don't fade down after syria pan
_screen->fadeDownPalette();
while (_screen->stillFading()) {
_screen->updateScreen();
delay(1000/12);
// todo: fade sfx?
}
_screen->quitScreen(); // close graphic resources
_objectMan->closeSection(SwordLogic::_scriptVars[SCREEN]); // close the section that PLAYER has just left, if it's empty now
// todo: stop sfx, clear sfx queue, free sfx memory
} while (_systemVars.saveGameFlag < 2);
}
void SwordEngine::delay(uint amount) { //copied and mutilated from sky.cpp
OSystem::Event event;
uint32 start = _system->get_msecs();
uint32 cur = start;
uint16 _key_pressed = 0; //reset
do {
while (_system->poll_event(&event)) {
switch (event.event_code) {
case OSystem::EVENT_KEYDOWN:
// Make sure backspace works right (this fixes a small issue on OS X)
if (event.kbd.keycode == 8)
_key_pressed = 8;
else
_key_pressed = (byte)event.kbd.ascii;
break;
case OSystem::EVENT_MOUSEMOVE:
_mouseX = event.mouse.x;
_mouseY = event.mouse.y;
break;
case OSystem::EVENT_LBUTTONDOWN:
_mouseState |= BS1L_BUTTON_DOWN;
#ifdef _WIN32_WCE
_mouseX = event.mouse.x;
_mouseY = event.mouse.y;
#endif
break;
case OSystem::EVENT_RBUTTONDOWN:
_mouseState |= BS1R_BUTTON_DOWN;
break;
case OSystem::EVENT_QUIT:
_system->quit();
break;
default:
break;
}
}
if (amount == 0)
break;
{
uint this_delay = 20; // 1?
#ifdef _WIN32_WCE
this_delay = 10;
#endif
if (this_delay > amount)
this_delay = amount;
_system->delay_msecs(this_delay);
}
cur = _system->get_msecs();
} while (cur < start + amount);
}
|