2004-01-06 13:44:17 +00:00
|
|
|
/* Copyright (C) 1994-2004 Revolution Software Ltd
|
2003-07-28 01:44:38 +00:00
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
*/
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-10-17 23:16:53 +00:00
|
|
|
#include "backends/fs/fs.h"
|
2003-09-17 22:41:01 +00:00
|
|
|
#include "base/gameDetector.h"
|
2003-09-18 18:23:53 +00:00
|
|
|
#include "base/plugins.h"
|
2003-10-08 21:59:23 +00:00
|
|
|
#include "common/config-manager.h"
|
2004-06-28 00:06:31 +00:00
|
|
|
#include "common/file.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/console.h"
|
|
|
|
#include "sword2/controls.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/defs.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/logic.h"
|
|
|
|
#include "sword2/maketext.h"
|
|
|
|
#include "sword2/resman.h"
|
|
|
|
#include "sword2/driver/d_draw.h"
|
|
|
|
#include "sword2/driver/d_sound.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
extern bool isSmartphone(void);
|
|
|
|
#endif
|
|
|
|
|
2003-12-13 00:20:01 +00:00
|
|
|
struct Sword2GameSettings {
|
|
|
|
const char *name;
|
|
|
|
const char *description;
|
|
|
|
uint32 features;
|
|
|
|
const char *detectname;
|
|
|
|
GameSettings toGameSettings() const {
|
|
|
|
GameSettings dummy = { name, description, features };
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const Sword2GameSettings sword2_settings[] = {
|
2003-10-04 00:52:27 +00:00
|
|
|
/* Broken Sword 2 */
|
2003-12-13 00:20:01 +00:00
|
|
|
{"sword2", "Broken Sword II", GF_DEFAULT_TO_1X_SCALER, "players.clu" },
|
|
|
|
{"sword2alt", "Broken Sword II (alt)", GF_DEFAULT_TO_1X_SCALER, "r2ctlns.ocx" },
|
|
|
|
{"sword2demo", "Broken Sword II (Demo)", GF_DEFAULT_TO_1X_SCALER | Sword2::GF_DEMO, "players.clu" },
|
|
|
|
{NULL, NULL, 0, NULL}
|
2003-10-04 00:52:27 +00:00
|
|
|
};
|
|
|
|
|
2003-10-17 23:16:53 +00:00
|
|
|
GameList Engine_SWORD2_gameList() {
|
2003-12-13 00:20:01 +00:00
|
|
|
const Sword2GameSettings *g = sword2_settings;
|
2003-10-17 23:16:53 +00:00
|
|
|
GameList games;
|
2003-12-13 00:20:01 +00:00
|
|
|
while (g->name) {
|
|
|
|
games.push_back(g->toGameSettings());
|
|
|
|
g++;
|
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
return games;
|
|
|
|
}
|
|
|
|
|
2003-12-21 15:29:52 +00:00
|
|
|
DetectedGameList Engine_SWORD2_detectGames(const FSList &fslist) {
|
|
|
|
DetectedGameList detectedGames;
|
2003-12-13 00:20:01 +00:00
|
|
|
const Sword2GameSettings *g;
|
2003-11-01 16:39:26 +00:00
|
|
|
|
2003-12-01 07:47:54 +00:00
|
|
|
// TODO: It would be nice if we had code here which distinguishes
|
|
|
|
// between the 'sword2' and 'sword2demo' targets. The current code
|
|
|
|
// can't do that since they use the same detectname.
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2003-12-13 00:20:01 +00:00
|
|
|
for (g = sword2_settings; g->name; ++g) {
|
2003-10-17 23:16:53 +00:00
|
|
|
// Iterate over all files in the given directory
|
2004-02-05 00:19:57 +00:00
|
|
|
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
|
2003-10-17 23:16:53 +00:00
|
|
|
const char *gameName = file->displayName().c_str();
|
|
|
|
|
2003-11-01 16:39:26 +00:00
|
|
|
if (0 == scumm_stricmp(g->detectname, gameName)) {
|
2003-10-17 23:16:53 +00:00
|
|
|
// Match found, add to list of candidates, then abort inner loop.
|
2003-12-13 00:20:01 +00:00
|
|
|
detectedGames.push_back(g->toGameSettings());
|
2003-10-17 23:16:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return detectedGames;
|
2003-10-04 00:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Engine *Engine_SWORD2_create(GameDetector *detector, OSystem *syst) {
|
2003-10-04 01:09:29 +00:00
|
|
|
return new Sword2::Sword2Engine(detector, syst);
|
2003-10-04 00:52:27 +00:00
|
|
|
}
|
|
|
|
|
2003-12-01 10:24:02 +00:00
|
|
|
REGISTER_PLUGIN("Broken Sword II", Engine_SWORD2_gameList, Engine_SWORD2_create, Engine_SWORD2_detectGames)
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
Sword2Engine *g_sword2 = NULL;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
|
2003-11-10 01:04:12 +00:00
|
|
|
: Engine(syst) {
|
2003-10-26 15:42:49 +00:00
|
|
|
|
2004-06-28 00:06:31 +00:00
|
|
|
// Add default file directories
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/CLUSTERS/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/SWORD2/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/VIDEO/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/clusters/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/sword2/");
|
|
|
|
File::addDefaultDirectory(_gameDataPath + "/video/");
|
|
|
|
|
2003-07-30 19:25:31 +00:00
|
|
|
g_sword2 = this;
|
2003-10-26 15:42:49 +00:00
|
|
|
_debugger = NULL;
|
2003-12-01 07:47:54 +00:00
|
|
|
_sound = NULL;
|
|
|
|
_graphics = NULL;
|
2003-07-28 07:00:15 +00:00
|
|
|
_features = detector->_game.features;
|
2003-10-12 19:10:17 +00:00
|
|
|
_targetName = strdup(detector->_targetName.c_str());
|
2003-10-08 21:59:23 +00:00
|
|
|
_bootParam = ConfMan.getInt("boot_param");
|
|
|
|
_saveSlot = ConfMan.getInt("save_slot");
|
2003-08-02 02:31:36 +00:00
|
|
|
|
|
|
|
// Setup mixer
|
2003-12-24 17:42:22 +00:00
|
|
|
if (!_mixer->isReady())
|
2003-08-02 02:31:36 +00:00
|
|
|
warning("Sound initialization failed");
|
|
|
|
|
2003-09-22 14:55:17 +00:00
|
|
|
// We have our own volume settings panel, so don't let ScummVM's mixer
|
|
|
|
// soften the sound in any way.
|
|
|
|
|
|
|
|
_mixer->setVolume(256);
|
|
|
|
_mixer->setMusicVolume(256);
|
2003-08-02 02:31:36 +00:00
|
|
|
|
2004-05-09 13:32:04 +00:00
|
|
|
_keyboardEvent.pending = false;
|
|
|
|
_mouseEvent.pending = false;
|
|
|
|
|
|
|
|
_mouseX = _mouseY = 0;
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
// get some falling RAM and put it in your pocket, never let it slip
|
|
|
|
// away
|
|
|
|
|
2003-12-01 07:47:54 +00:00
|
|
|
_graphics = new Graphics(this, 640, 480);
|
|
|
|
|
|
|
|
// Create the debugger as early as possible (but not before the
|
|
|
|
// graphics object!) so that errors can be displayed in it. In
|
|
|
|
// particular, we want errors about missing files to be clearly
|
|
|
|
// visible to the user.
|
|
|
|
|
|
|
|
_debugger = new Debugger(this);
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
_memory = new MemoryManager(this);
|
|
|
|
_resman = new ResourceManager(this);
|
2003-11-15 09:38:00 +00:00
|
|
|
_logic = new Logic(this);
|
2003-11-16 14:18:29 +00:00
|
|
|
_fontRenderer = new FontRenderer(this);
|
|
|
|
_gui = new Gui(this);
|
|
|
|
_sound = new Sound(this);
|
2003-11-01 16:55:20 +00:00
|
|
|
|
|
|
|
_lastPaletteRes = 0;
|
|
|
|
|
|
|
|
_largestLayerArea = 0;
|
|
|
|
_largestSpriteArea = 0;
|
|
|
|
|
|
|
|
strcpy(_largestLayerInfo, "largest layer: none registered");
|
|
|
|
strcpy(_largestSpriteInfo, "largest sprite: none registered");
|
|
|
|
|
|
|
|
_fps = 0;
|
|
|
|
_cycleTime = 0;
|
|
|
|
_frameCount = 0;
|
2003-11-02 15:58:45 +00:00
|
|
|
|
|
|
|
_wantSfxDebug = false;
|
|
|
|
|
|
|
|
// For the menus
|
|
|
|
|
|
|
|
_totalTemp = 0;
|
|
|
|
memset(_tempList, 0, sizeof(_tempList));
|
|
|
|
|
|
|
|
_totalMasters = 0;
|
|
|
|
memset(_masterMenuList, 0, sizeof(_masterMenuList));
|
2003-11-02 17:17:10 +00:00
|
|
|
|
|
|
|
memset(&_thisScreen, 0, sizeof(_thisScreen));
|
2003-11-02 18:50:09 +00:00
|
|
|
|
|
|
|
memset(_mouseList, 0, sizeof(_mouseList));
|
|
|
|
|
|
|
|
_mouseTouching = 0;
|
|
|
|
_oldMouseTouching = 0;
|
|
|
|
_menuSelectedPos = 0;
|
|
|
|
_examiningMenuIcon = false;
|
|
|
|
_mousePointerRes = 0;
|
|
|
|
_mouseMode = 0;
|
|
|
|
_mouseStatus = false;
|
|
|
|
_mouseModeLocked = false;
|
|
|
|
_currentLuggageResource = 0;
|
|
|
|
_oldButton = 0;
|
|
|
|
_buttonClick = 0;
|
|
|
|
_pointerTextBlocNo = 0;
|
|
|
|
_playerActivityDelay = 0;
|
|
|
|
_realLuggageItem = 0;
|
2003-11-03 07:47:42 +00:00
|
|
|
|
|
|
|
// used to be a define, but now it's flexible
|
|
|
|
_scrollFraction = 16;
|
2003-11-08 15:47:51 +00:00
|
|
|
|
|
|
|
_gamePaused = false;
|
|
|
|
_stepOneCycle = false;
|
|
|
|
_graphicsLevelFudged = false;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-12 14:40:04 +00:00
|
|
|
Sword2Engine::~Sword2Engine() {
|
2003-10-12 19:10:17 +00:00
|
|
|
free(_targetName);
|
2003-10-26 15:42:49 +00:00
|
|
|
delete _debugger;
|
2003-11-11 07:43:02 +00:00
|
|
|
delete _graphics;
|
2003-11-08 15:47:51 +00:00
|
|
|
delete _sound;
|
2003-11-16 14:18:29 +00:00
|
|
|
delete _gui;
|
|
|
|
delete _fontRenderer;
|
2003-11-15 09:38:00 +00:00
|
|
|
delete _logic;
|
2003-11-16 14:18:29 +00:00
|
|
|
delete _resman;
|
|
|
|
delete _memory;
|
2003-10-12 14:40:04 +00:00
|
|
|
}
|
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
void Sword2Engine::errorString(const char *buf1, char *buf2) {
|
2003-07-28 01:44:38 +00:00
|
|
|
strcpy(buf2, buf1);
|
2003-10-26 15:42:49 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
if (isSmartphone())
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2003-12-01 07:47:54 +00:00
|
|
|
// Unless an error -originated- within the debugger, spawn the
|
|
|
|
// debugger. Otherwise exit out normally.
|
Re-enabled the CD swapping code, after rewriting it a bit.
If a cluster file isn't found the resource manager will first check if it's
one of the files that it expects to find on the hard disk. If so, it's
considered a fatal error.
Otherwise it will present the user with an "Insert CD1" or "Insert CD2"
message, just like the original did. Unlike the original, the user will
have to press a button or click the mouse to indicate when he's done. I
don't know if we even can detect the CD automatically in any portable way.
As far as I can see, we'll need at least two separate path settings for
this to actually work: one for the HD install directory, and one or two for
the CDs. The file that are supposed to be found on the HD are only on one
of the CDs, so the amount of CD swapping would probably be unbearable
otherwise.
As a consequence, I haven't actually tried running the game from CD yet.
By the way, the old caching code has been removed completely now. All it
did was to copy the cluster file to HD for faster access. ScummVM never did
that, but so far no one has complained.
svn-id: r11273
2003-11-13 07:59:52 +00:00
|
|
|
if (_debugger && !_debugger->isAttached()) {
|
2003-12-01 07:47:54 +00:00
|
|
|
// (Print it again in case debugger segfaults)
|
|
|
|
printf("%s\n", buf2);
|
2003-10-26 15:42:49 +00:00
|
|
|
_debugger->attach(buf2);
|
|
|
|
_debugger->onFrame();
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-25 09:05:10 +00:00
|
|
|
int32 Sword2Engine::initialiseGame(void) {
|
2004-05-09 13:32:04 +00:00
|
|
|
// During normal gameplay, we care neither about mouse button releases
|
|
|
|
// nor the scroll wheel.
|
|
|
|
setEventFilter(RD_LEFTBUTTONUP | RD_RIGHTBUTTONUP | RD_WHEELUP | RD_WHEELDOWN);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// initialise global script variables
|
|
|
|
// res 1 is the globals list
|
2004-03-17 09:03:15 +00:00
|
|
|
Logic::_scriptVars = (uint32 *) (_resman->openResource(1) + sizeof(StandardHeader));
|
2003-09-27 11:02:58 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// DON'T CLOSE VARIABLES RESOURCE - KEEP IT OPEN AT VERY START OF
|
|
|
|
// MEMORY SO IT CAN'T MOVE!
|
|
|
|
|
|
|
|
// DON'T CLOSE PLAYER OBJECT RESOURCE - KEEP IT OPEN IN MEMORY SO IT
|
|
|
|
// CAN'T MOVE!
|
2003-09-27 11:02:58 +00:00
|
|
|
|
2004-03-17 09:03:15 +00:00
|
|
|
_resman->openResource(8);
|
2003-09-20 18:33:24 +00:00
|
|
|
|
|
|
|
// Set up font resource variables for this language version
|
2003-09-27 11:02:58 +00:00
|
|
|
|
2003-10-11 12:26:53 +00:00
|
|
|
debug(5, "CALLING: initialiseFontResourceFlags");
|
|
|
|
initialiseFontResourceFlags();
|
2003-09-20 18:33:24 +00:00
|
|
|
|
|
|
|
// initialise the sound fx queue
|
2003-09-27 11:02:58 +00:00
|
|
|
|
|
|
|
debug(5, "CALLING: Init_fx_queue");
|
2003-11-03 07:47:42 +00:00
|
|
|
initFxQueue();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-07-28 07:00:15 +00:00
|
|
|
// all demos (not just web)
|
2003-12-29 15:30:10 +00:00
|
|
|
if (_features & GF_DEMO)
|
2004-03-17 09:03:15 +00:00
|
|
|
Logic::_scriptVars[DEMO] = 1;
|
2003-12-29 15:30:10 +00:00
|
|
|
else
|
2004-03-17 09:03:15 +00:00
|
|
|
Logic::_scriptVars[DEMO] = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
return 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
void Sword2Engine::closeGame(void) {
|
2004-01-06 16:49:04 +00:00
|
|
|
_quit = true;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-05-09 13:32:04 +00:00
|
|
|
bool Sword2Engine::checkForMouseEvents(void) {
|
|
|
|
return _mouseEvent.pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseEvent *Sword2Engine::mouseEvent(void) {
|
|
|
|
if (!_mouseEvent.pending)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
_mouseEvent.pending = false;
|
|
|
|
return &_mouseEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyboardEvent *Sword2Engine::keyboardEvent(void) {
|
|
|
|
if (!_keyboardEvent.pending)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
_keyboardEvent.pending = false;
|
|
|
|
return &_keyboardEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 Sword2Engine::setEventFilter(uint32 filter) {
|
|
|
|
uint32 oldFilter = _eventFilter;
|
|
|
|
|
|
|
|
_eventFilter = filter;
|
|
|
|
return oldFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OSystem Event Handler. Full of cross platform goodness and 99% fat free!
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Sword2Engine::parseEvents(void) {
|
|
|
|
OSystem::Event event;
|
|
|
|
|
|
|
|
while (_system->poll_event(&event)) {
|
|
|
|
switch (event.event_code) {
|
|
|
|
case OSystem::EVENT_KEYDOWN:
|
|
|
|
if (!(_eventFilter & RD_KEYDOWN)) {
|
|
|
|
_keyboardEvent.pending = true;
|
|
|
|
_keyboardEvent.ascii = event.kbd.ascii;
|
|
|
|
_keyboardEvent.keycode = event.kbd.keycode;
|
|
|
|
_keyboardEvent.modifiers = event.kbd.flags;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
|
|
|
if (!(_eventFilter & RD_KEYDOWN)) {
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y - RDMENU_MENUDEEP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
|
|
|
if (!(_eventFilter & RD_LEFTBUTTONDOWN)) {
|
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_LEFTBUTTONDOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_RBUTTONDOWN:
|
|
|
|
if (!(_eventFilter & RD_RIGHTBUTTONDOWN)) {
|
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_RIGHTBUTTONDOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONUP:
|
|
|
|
if (!(_eventFilter & RD_LEFTBUTTONUP)) {
|
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_LEFTBUTTONUP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_RBUTTONUP:
|
|
|
|
if (!(_eventFilter & RD_RIGHTBUTTONUP)) {
|
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_RIGHTBUTTONUP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELUP:
|
|
|
|
if (!(_eventFilter & RD_WHEELUP)) {
|
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_WHEELUP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_WHEELDOWN:
|
|
|
|
if (!(_eventFilter & RD_WHEELDOWN)) {
|
|
|
|
_mouseEvent.pending = true;
|
|
|
|
_mouseEvent.buttons = RD_WHEELDOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
closeGame();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
void Sword2Engine::gameCycle(void) {
|
2003-09-20 18:33:24 +00:00
|
|
|
// do one game cycle
|
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// got a screen to run?
|
2003-11-15 09:38:00 +00:00
|
|
|
if (_logic->getRunList()) {
|
2003-12-01 07:47:54 +00:00
|
|
|
// run the logic session UNTIL a full loop has been performed
|
2003-09-20 18:33:24 +00:00
|
|
|
do {
|
2003-12-28 15:08:12 +00:00
|
|
|
// reset the graphic 'BuildUnit' list before a new
|
2003-10-18 08:11:50 +00:00
|
|
|
// logic list (see fnRegisterFrame)
|
2003-11-08 15:47:51 +00:00
|
|
|
resetRenderLists();
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// reset the mouse hot-spot list (see fnRegisterMouse
|
|
|
|
// and fnRegisterFrame)
|
2003-11-08 15:47:51 +00:00
|
|
|
resetMouseList();
|
2003-09-20 18:33:24 +00:00
|
|
|
|
|
|
|
// keep going as long as new lists keep getting put in
|
|
|
|
// - i.e. screen changes
|
2003-11-15 09:38:00 +00:00
|
|
|
} while (_logic->processSession());
|
2003-09-20 18:33:24 +00:00
|
|
|
} else {
|
|
|
|
// start the console and print the start options perhaps?
|
2003-11-08 15:47:51 +00:00
|
|
|
_debugger->attach("AWAITING START COMMAND: (Enter 's 1' then 'q' to start from beginning)");
|
2003-09-20 18:33:24 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// if this screen is wide, recompute the scroll offsets every cycle
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_thisScreen.scroll_flag)
|
|
|
|
setScrolling();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
mouseEngine();
|
|
|
|
processFxQueue();
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
void Sword2Engine::go() {
|
2004-01-08 13:03:50 +00:00
|
|
|
_quit = false;
|
|
|
|
|
2003-10-03 06:54:44 +00:00
|
|
|
debug(5, "CALLING: readOptionSettings");
|
2003-11-16 14:18:29 +00:00
|
|
|
_gui->readOptionSettings();
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-11-25 09:05:10 +00:00
|
|
|
debug(5, "CALLING: initialiseGame");
|
2004-01-06 16:49:04 +00:00
|
|
|
if (initialiseGame())
|
2003-07-28 01:44:38 +00:00
|
|
|
return;
|
|
|
|
|
2003-09-14 21:45:42 +00:00
|
|
|
if (_saveSlot != -1) {
|
2003-11-03 07:47:42 +00:00
|
|
|
if (saveExists(_saveSlot))
|
|
|
|
restoreGame(_saveSlot);
|
2004-03-04 08:03:32 +00:00
|
|
|
else {
|
2003-11-02 18:50:09 +00:00
|
|
|
setMouse(NORMAL_MOUSE_ID);
|
2003-11-16 14:18:29 +00:00
|
|
|
if (!_gui->restoreControl())
|
2003-11-08 15:47:51 +00:00
|
|
|
startGame();
|
2003-09-14 21:45:42 +00:00
|
|
|
}
|
2004-03-28 13:12:10 +00:00
|
|
|
} else if (!_bootParam && saveExists()) {
|
2004-03-04 08:03:32 +00:00
|
|
|
int32 pars[2] = { 221, FX_LOOP };
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
setMouse(NORMAL_MOUSE_ID);
|
|
|
|
_logic->fnPlayMusic(pars);
|
|
|
|
result = _gui->startControl();
|
2004-03-27 12:07:07 +00:00
|
|
|
|
|
|
|
// If the game is started from the beginning, the cutscene
|
|
|
|
// player will kill the music for us. Otherwise, the restore
|
|
|
|
// will either have killed the music, or done a crossfade.
|
2004-03-04 08:03:32 +00:00
|
|
|
|
|
|
|
if (_quit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
startGame();
|
2003-09-14 21:45:42 +00:00
|
|
|
} else
|
2003-11-08 15:47:51 +00:00
|
|
|
startGame();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
debug(5, "CALLING: initialiseRenderCycle");
|
2003-11-11 07:43:02 +00:00
|
|
|
_graphics->initialiseRenderCycle();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 15:58:45 +00:00
|
|
|
_renderSkip = false; // Toggled on 'S' key, to render only
|
|
|
|
// 1 in 4 frames, to speed up game
|
|
|
|
|
|
|
|
_gameCycle = 0;
|
|
|
|
|
2003-09-24 06:40:23 +00:00
|
|
|
while (1) {
|
2003-10-26 15:42:49 +00:00
|
|
|
if (_debugger->isAttached())
|
|
|
|
_debugger->onFrame();
|
|
|
|
|
|
|
|
// the screen is build. Mostly because of first scroll
|
|
|
|
// cycle stuff
|
|
|
|
|
2003-07-30 19:25:31 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-10-26 15:42:49 +00:00
|
|
|
// if we've just stepped forward one cycle while the
|
|
|
|
// game was paused
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_stepOneCycle) {
|
|
|
|
pauseGame();
|
|
|
|
_stepOneCycle = false;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-05-09 13:32:04 +00:00
|
|
|
KeyboardEvent *ke = keyboardEvent();
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2004-05-09 13:32:04 +00:00
|
|
|
if (ke) {
|
|
|
|
if ((ke->modifiers == OSystem::KBD_CTRL && ke->keycode == 'd') || ke->ascii == '#' || ke->ascii == '~') {
|
2003-10-26 15:42:49 +00:00
|
|
|
_debugger->attach();
|
2004-05-09 13:32:04 +00:00
|
|
|
} else if (ke->modifiers == 0 || ke->modifiers == OSystem::KBD_SHIFT) {
|
|
|
|
switch (ke->keycode) {
|
2003-12-10 07:59:45 +00:00
|
|
|
case 'p':
|
|
|
|
if (_gamePaused)
|
|
|
|
unpauseGame();
|
|
|
|
else
|
|
|
|
pauseGame();
|
|
|
|
break;
|
|
|
|
case 'c':
|
2004-03-17 09:03:15 +00:00
|
|
|
if (!Logic::_scriptVars[DEMO] && !_logic->_choosing)
|
2003-12-10 07:59:45 +00:00
|
|
|
_logic->fnPlayCredits(NULL);
|
|
|
|
break;
|
2003-09-20 18:33:24 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-12-10 07:59:45 +00:00
|
|
|
case ' ':
|
|
|
|
if (_gamePaused) {
|
|
|
|
_stepOneCycle = true;
|
|
|
|
unpauseGame();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
_renderSkip = !_renderSkip;
|
|
|
|
break;
|
2003-09-20 18:33:24 +00:00
|
|
|
#endif
|
2003-12-10 07:59:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-10-26 15:42:49 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// skip GameCycle if we're paused
|
2003-11-08 15:47:51 +00:00
|
|
|
if (!_gamePaused) {
|
2003-11-02 15:58:45 +00:00
|
|
|
_gameCycle++;
|
2003-11-08 15:47:51 +00:00
|
|
|
gameCycle();
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-01-06 16:49:04 +00:00
|
|
|
// We can't use this as termination condition for the looop,
|
|
|
|
// because we want the break to happen before updating the
|
|
|
|
// screen again.
|
|
|
|
|
|
|
|
if (_quit)
|
|
|
|
break;
|
|
|
|
|
2003-10-26 15:42:49 +00:00
|
|
|
// creates the debug text blocks
|
2003-11-02 15:58:45 +00:00
|
|
|
_debugger->buildDebugText();
|
2003-10-26 15:42:49 +00:00
|
|
|
|
2003-07-30 19:25:31 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-11-02 15:58:45 +00:00
|
|
|
// if not in console & '_renderSkip' is set, only render
|
2003-09-20 18:33:24 +00:00
|
|
|
// display once every 4 game-cycles
|
|
|
|
|
2003-11-02 15:58:45 +00:00
|
|
|
if (console_status || !_renderSkip || (_gameCycle % 4) == 0)
|
2003-11-08 15:47:51 +00:00
|
|
|
buildDisplay(); // create and flip the screen
|
2003-07-28 01:44:38 +00:00
|
|
|
#else
|
2003-09-20 18:33:24 +00:00
|
|
|
// create and flip the screen
|
2003-11-08 15:47:51 +00:00
|
|
|
buildDisplay();
|
2003-09-20 18:33:24 +00:00
|
|
|
#endif
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-01-06 16:49:04 +00:00
|
|
|
// Stop music instantly!
|
|
|
|
killMusic();
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
void Sword2Engine::startGame(void) {
|
2003-09-20 18:33:24 +00:00
|
|
|
// boot the game straight into a start script
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-07-28 07:00:15 +00:00
|
|
|
int screen_manager_id;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
debug(5, "startGame() STARTING:");
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-07-28 07:00:15 +00:00
|
|
|
// all demos not just web
|
2004-03-17 09:03:15 +00:00
|
|
|
if (Logic::_scriptVars[DEMO])
|
2003-07-28 07:00:15 +00:00
|
|
|
screen_manager_id = 19; // DOCKS SECTION START
|
|
|
|
else
|
|
|
|
screen_manager_id = 949; // INTRO & PARIS START
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-08-22 08:40:27 +00:00
|
|
|
// FIXME this could be validated against startup.inf for valid numbers
|
|
|
|
// to stop people shooting themselves in the foot
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-08-22 08:40:27 +00:00
|
|
|
if (_bootParam != 0)
|
|
|
|
screen_manager_id = _bootParam;
|
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
char *raw_script;
|
|
|
|
char *raw_data_ad;
|
|
|
|
|
|
|
|
// the required start-scripts are both script #1 in the respective
|
|
|
|
// ScreenManager objects
|
|
|
|
|
|
|
|
uint32 null_pc = 1;
|
|
|
|
|
|
|
|
// open george object, ready for start script to reference
|
2003-11-16 14:18:29 +00:00
|
|
|
raw_data_ad = (char *) _resman->openResource(8);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// open the ScreenManager object
|
2003-11-16 14:18:29 +00:00
|
|
|
raw_script = (char *) _resman->openResource(screen_manager_id);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// run the start script now (because no console)
|
2003-11-15 09:38:00 +00:00
|
|
|
_logic->runScript(raw_script, raw_data_ad, &null_pc);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// close the ScreenManager object
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(screen_manager_id);
|
2003-09-20 18:33:24 +00:00
|
|
|
|
|
|
|
// close george
|
2003-11-16 14:18:29 +00:00
|
|
|
_resman->closeResource(8);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
debug(5, "startGame() DONE.");
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-05 15:28:15 +00:00
|
|
|
// FIXME: Move this to some better place?
|
|
|
|
|
2003-11-11 10:30:25 +00:00
|
|
|
void Sword2Engine::sleepUntil(uint32 time) {
|
|
|
|
while (_system->get_msecs() < time) {
|
2004-01-04 15:11:30 +00:00
|
|
|
// Make sure menu animations and fades don't suffer, but don't
|
|
|
|
// redraw the entire scene.
|
2003-11-11 07:43:02 +00:00
|
|
|
_graphics->processMenu();
|
2004-01-04 15:11:30 +00:00
|
|
|
_graphics->updateDisplay(false);
|
2003-11-11 07:43:02 +00:00
|
|
|
_system->delay_msecs(10);
|
2003-10-05 15:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
void Sword2Engine::pauseGame(void) {
|
2003-10-15 06:40:31 +00:00
|
|
|
// don't allow Pause while screen fading or while black
|
2003-11-11 07:43:02 +00:00
|
|
|
if (_graphics->getFadeStatus() != RDFADE_NONE)
|
2003-07-28 01:44:38 +00:00
|
|
|
return;
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
pauseAllSound();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-02 18:50:09 +00:00
|
|
|
// make a normal mouse
|
2003-11-08 15:47:51 +00:00
|
|
|
clearPointerText();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-15 06:40:31 +00:00
|
|
|
// this is the only place allowed to do it this way
|
2003-11-11 07:43:02 +00:00
|
|
|
_graphics->setLuggageAnim(NULL, 0);
|
2003-09-20 18:33:24 +00:00
|
|
|
|
|
|
|
// blank cursor
|
2003-11-08 15:47:51 +00:00
|
|
|
setMouse(0);
|
2003-09-20 18:33:24 +00:00
|
|
|
|
|
|
|
// forces engine to choose a cursor
|
2003-11-08 15:47:51 +00:00
|
|
|
_mouseTouching = 1;
|
2003-09-20 18:33:24 +00:00
|
|
|
|
|
|
|
// if level at max, turn down because palette-matching won't work
|
|
|
|
// when dimmed
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
if (_gui->_currentGraphicsLevel == 3) {
|
|
|
|
_gui->updateGraphicsLevel(2);
|
2003-11-08 15:47:51 +00:00
|
|
|
_graphicsLevelFudged = true;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// don't dim it if we're single-stepping through frames
|
2003-11-03 07:47:42 +00:00
|
|
|
// dim the palette during the pause
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
if (!_stepOneCycle)
|
2003-11-11 07:43:02 +00:00
|
|
|
_graphics->dimPalette();
|
2003-09-20 18:33:24 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_gamePaused = true;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
void Sword2Engine::unpauseGame(void) {
|
2004-03-17 09:03:15 +00:00
|
|
|
if (Logic::_scriptVars[OBJECT_HELD] && _realLuggageItem)
|
2003-11-08 15:47:51 +00:00
|
|
|
setLuggage(_realLuggageItem);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
unpauseAllSound();
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-03-28 13:12:10 +00:00
|
|
|
// put back game screen palette; see build_display.cpp
|
|
|
|
setFullPalette(-1);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// If graphics level at max, turn up again
|
2003-11-08 19:47:20 +00:00
|
|
|
if (_graphicsLevelFudged) {
|
2003-11-16 14:18:29 +00:00
|
|
|
_gui->updateGraphicsLevel(3);
|
2003-11-08 15:47:51 +00:00
|
|
|
_graphicsLevelFudged = false;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-08 15:47:51 +00:00
|
|
|
_gamePaused = false;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-20 18:33:24 +00:00
|
|
|
// if mouse is about or we're in a chooser menu
|
2003-11-15 09:38:00 +00:00
|
|
|
if (!_mouseStatus || _logic->_choosing)
|
2003-11-08 15:47:51 +00:00
|
|
|
setMouse(NORMAL_MOUSE_ID);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|