2011-06-10 05:45:18 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This code is based on original Soltys source code
|
|
|
|
* Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
|
|
|
|
*/
|
|
|
|
|
2011-06-29 11:17:07 +00:00
|
|
|
#include "common/scummsys.h"
|
2011-07-05 10:26:34 +00:00
|
|
|
#include "common/memstream.h"
|
2011-07-09 23:44:46 +00:00
|
|
|
#include "common/savefile.h"
|
2011-07-05 10:26:34 +00:00
|
|
|
#include "common/serializer.h"
|
2011-07-13 11:04:44 +00:00
|
|
|
#include "common/str.h"
|
2011-07-16 08:33:20 +00:00
|
|
|
#include "graphics/palette.h"
|
|
|
|
#include "graphics/scaler.h"
|
|
|
|
#include "graphics/thumbnail.h"
|
2011-06-28 22:35:21 +00:00
|
|
|
#include "cge/general.h"
|
|
|
|
#include "cge/sound.h"
|
|
|
|
#include "cge/config.h"
|
|
|
|
#include "cge/vga13h.h"
|
|
|
|
#include "cge/snail.h"
|
|
|
|
#include "cge/text.h"
|
|
|
|
#include "cge/game.h"
|
2011-07-02 06:19:36 +00:00
|
|
|
#include "cge/events.h"
|
2011-06-28 22:35:21 +00:00
|
|
|
#include "cge/cfile.h"
|
|
|
|
#include "cge/vol.h"
|
|
|
|
#include "cge/talk.h"
|
|
|
|
#include "cge/vmenu.h"
|
|
|
|
#include "cge/gettext.h"
|
|
|
|
#include "cge/mixer.h"
|
|
|
|
#include "cge/cge_main.h"
|
|
|
|
#include "cge/cge.h"
|
2011-07-13 11:04:44 +00:00
|
|
|
#include "cge/walk.h"
|
2011-07-29 08:02:32 +00:00
|
|
|
#include "cge/sound.h"
|
2011-06-11 20:35:21 +00:00
|
|
|
|
2011-06-10 20:57:09 +00:00
|
|
|
namespace CGE {
|
|
|
|
|
2011-07-19 06:24:06 +00:00
|
|
|
#define STACK_SIZ 2048
|
2011-07-02 16:20:41 +00:00
|
|
|
#define SVGCHKSUM (1956 + _now + _oldLev + _game + _music + _demoText)
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-20 23:56:40 +00:00
|
|
|
#define SVG0NAME ("{{INIT}}" kSvgExt)
|
2011-06-28 22:35:21 +00:00
|
|
|
#define SVG0FILE INI_FILE
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 04:55:49 +00:00
|
|
|
uint16 _stklen = (STACK_SIZ * 2);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
Vga *_vga;
|
2011-07-04 06:15:56 +00:00
|
|
|
System *_sys;
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *_pocLight;
|
2011-07-02 08:38:25 +00:00
|
|
|
EventManager *_eventManager;
|
2011-07-02 06:46:31 +00:00
|
|
|
Keyboard *_keyboard;
|
2011-07-08 06:21:35 +00:00
|
|
|
Mouse *_mouse;
|
2011-07-20 23:56:40 +00:00
|
|
|
Sprite *_pocket[kPocketNX];
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *_sprite;
|
|
|
|
Sprite *_miniCave;
|
|
|
|
Sprite *_shadow;
|
2011-07-09 23:57:19 +00:00
|
|
|
HorizLine *_horzLine;
|
2011-07-03 09:28:22 +00:00
|
|
|
InfoLine *_infoLine;
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *_cavLight;
|
2011-07-03 09:28:22 +00:00
|
|
|
InfoLine *_debugLine;
|
2011-06-21 17:38:16 +00:00
|
|
|
|
2011-07-02 16:20:41 +00:00
|
|
|
Snail *_snail;
|
|
|
|
Snail *_snail_;
|
2011-06-22 06:11:18 +00:00
|
|
|
|
2011-07-29 08:02:32 +00:00
|
|
|
Fx *_fx;
|
|
|
|
Sound *_sound;
|
2011-06-09 06:20:53 +00:00
|
|
|
// 0.75 - 17II95 - full sound support
|
|
|
|
// 0.76 - 18II95 - small MiniEMS in DEMO,
|
|
|
|
// unhide CavLight in SNLEVEL
|
|
|
|
// keyclick suppress in startup
|
|
|
|
// keyclick on key service in: SYSTEM, GET_TEXT
|
|
|
|
// 1.01 - 17VII95 - default savegame with sound ON
|
|
|
|
// coditionals EVA for 2-month evaluation version
|
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
const char *SAVEGAME_STR = "SCUMMVM_CGE";
|
|
|
|
#define SAVEGAME_STR_SIZE 11
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
static bool _finis = false;
|
|
|
|
int _offUseCount;
|
|
|
|
uint16 *_intStackPtr = false;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-02 16:20:41 +00:00
|
|
|
extern Dac _stdPal[58];
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-09 23:44:46 +00:00
|
|
|
void CGEEngine::syncHeader(Common::Serializer &s) {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::syncHeader(s)");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
int i;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-05 10:26:34 +00:00
|
|
|
s.syncAsUint16LE(_now);
|
|
|
|
s.syncAsUint16LE(_oldLev);
|
|
|
|
s.syncAsUint16LE(_demoText);
|
2011-07-30 22:52:35 +00:00
|
|
|
for (i = 0; i < 5; i++)
|
2011-07-05 10:26:34 +00:00
|
|
|
s.syncAsUint16LE(_game);
|
|
|
|
s.syncAsSint16LE(i); // unused VGA::Mono variable
|
|
|
|
s.syncAsUint16LE(_music);
|
|
|
|
s.syncBytes(_volume, 2);
|
2011-07-30 22:52:35 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
2011-07-05 10:26:34 +00:00
|
|
|
s.syncAsUint16LE(_flag[i]);
|
|
|
|
|
2011-07-30 13:43:49 +00:00
|
|
|
initCaveValues();
|
|
|
|
if (s.isLoading()) {
|
|
|
|
//TODO: Fix the memory leak when the game is already running
|
2011-07-30 22:52:35 +00:00
|
|
|
_heroXY = (Hxy *) malloc (sizeof(Hxy) * _caveMax);
|
|
|
|
_barriers = (Bar *) malloc (sizeof(Bar) * (1 + _caveMax));
|
2011-07-30 13:43:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
for (i = 0; i < _caveMax; i++) {
|
2011-07-05 10:26:34 +00:00
|
|
|
s.syncAsSint16LE(_heroXY[i]._x);
|
|
|
|
s.syncAsUint16LE(_heroXY[i]._y);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-07-30 22:52:35 +00:00
|
|
|
for (i = 0; i < 1 + _caveMax; i++) {
|
2011-07-05 10:26:34 +00:00
|
|
|
s.syncAsByte(_barriers[i]._horz);
|
|
|
|
s.syncAsByte(_barriers[i]._vert);
|
|
|
|
}
|
2011-07-30 22:52:35 +00:00
|
|
|
for (i = 0; i < kPocketNX; i++)
|
2011-07-05 10:26:34 +00:00
|
|
|
s.syncAsUint16LE(_pocref[i]);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-09 23:44:46 +00:00
|
|
|
if (s.isSaving()) {
|
|
|
|
// Write checksum
|
|
|
|
int checksum = SVGCHKSUM;
|
|
|
|
s.syncAsUint16LE(checksum);
|
|
|
|
} else {
|
|
|
|
// Read checksum and validate it
|
|
|
|
uint16 checksum;
|
|
|
|
s.syncAsUint16LE(checksum);
|
|
|
|
if (checksum != SVGCHKSUM)
|
2011-07-22 09:54:46 +00:00
|
|
|
error("%s", _text->getText(kBadSVG));
|
2011-07-09 23:44:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) {
|
2011-07-30 13:43:49 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::loadgame(%d, header, %s)", slotNumber, tiny ? "true" : "false");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
Common::MemoryReadStream *readStream;
|
|
|
|
SavegameHeader saveHeader;
|
2011-07-09 23:44:46 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
if (slotNumber == -1) {
|
|
|
|
// Loading the data for the initial game state
|
|
|
|
SVG0FILE file = SVG0FILE(SVG0NAME);
|
|
|
|
int size = file.size();
|
|
|
|
byte *dataBuffer = (byte *)malloc(size);
|
|
|
|
file.read(dataBuffer, size);
|
|
|
|
readStream = new Common::MemoryReadStream(dataBuffer, size, DisposeAfterUse::YES);
|
2011-07-09 23:44:46 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
} else {
|
|
|
|
// Open up the savgame file
|
|
|
|
Common::String slotName = generateSaveName(slotNumber);
|
|
|
|
Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(slotName);
|
|
|
|
|
|
|
|
// Read the data into a data buffer
|
|
|
|
int size = saveFile->size();
|
|
|
|
byte *dataBuffer = (byte *)malloc(size);
|
|
|
|
saveFile->read(dataBuffer, size);
|
|
|
|
readStream = new Common::MemoryReadStream(dataBuffer, size, DisposeAfterUse::YES);
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
// Check to see if it's a ScummVM savegame or not
|
|
|
|
char buffer[SAVEGAME_STR_SIZE + 1];
|
|
|
|
readStream->read(buffer, SAVEGAME_STR_SIZE + 1);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
if (strncmp(buffer, SAVEGAME_STR, SAVEGAME_STR_SIZE + 1) != 0) {
|
|
|
|
// It's not, so rewind back to the start
|
|
|
|
readStream->seek(0);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
if (header)
|
|
|
|
// Header wanted where none exists, so return false
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Found header
|
|
|
|
if (!readSavegameHeader(readStream, saveHeader)) {
|
|
|
|
delete readStream;
|
|
|
|
return false;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
if (header) {
|
|
|
|
*header = saveHeader;
|
|
|
|
delete readStream;
|
|
|
|
return true;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-07-16 08:33:20 +00:00
|
|
|
|
|
|
|
// Delete the thumbnail
|
|
|
|
delete saveHeader.thumbnail;
|
|
|
|
|
|
|
|
// If we're loading the auto-save slot, load the name
|
|
|
|
if (slotNumber == 0)
|
|
|
|
strncpy(_usrFnam, saveHeader.saveName.c_str(), 8);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-07-28 13:35:12 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
// Get in the savegame
|
|
|
|
syncGame(readStream, NULL, tiny);
|
|
|
|
|
|
|
|
delete readStream;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if a given savegame exists
|
|
|
|
*/
|
|
|
|
bool CGEEngine::savegameExists(int slotNumber) {
|
|
|
|
Common::String slotName = generateSaveName(slotNumber);
|
|
|
|
|
|
|
|
Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(slotName);
|
|
|
|
bool result = saveFile != NULL;
|
|
|
|
delete saveFile;
|
|
|
|
return result;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
/**
|
|
|
|
* Support method that generates a savegame name
|
|
|
|
* @param slot Slot number
|
|
|
|
*/
|
|
|
|
Common::String CGEEngine::generateSaveName(int slot) {
|
|
|
|
return Common::String::format("%s.%03d", _targetName.c_str(), slot);
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-16 11:12:19 +00:00
|
|
|
Common::Error CGEEngine::loadGameState(int slot) {
|
|
|
|
// Clear current game activity
|
|
|
|
caveDown();
|
|
|
|
|
|
|
|
// Load the game
|
|
|
|
loadGame(slot, NULL, true);
|
|
|
|
caveUp();
|
|
|
|
loadGame(slot, NULL);
|
|
|
|
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error CGEEngine::saveGameState(int slot, const Common::String &desc) {
|
|
|
|
saveGame(slot, desc);
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::saveSound() {
|
2011-07-16 08:33:20 +00:00
|
|
|
warning("STUB: CGEEngine::saveSound");
|
|
|
|
/* Convert to saving any such needed data in ScummVM configuration file
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
CFile cfg(usrPath(progName(CFG_EXT)), WRI);
|
2011-07-01 06:37:40 +00:00
|
|
|
if (!cfg._error)
|
2011-07-03 09:28:22 +00:00
|
|
|
cfg.write(&_sndDrvInfo, sizeof(_sndDrvInfo) - sizeof(_sndDrvInfo.Vol2));
|
2011-07-16 08:33:20 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGEEngine::saveGame(int slotNumber, const Common::String &desc) {
|
|
|
|
// Set up the serializer
|
|
|
|
Common::String slotName = generateSaveName(slotNumber);
|
|
|
|
Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(slotName);
|
|
|
|
|
|
|
|
// Write out the ScummVM savegame header
|
|
|
|
SavegameHeader header;
|
|
|
|
header.saveName = desc;
|
|
|
|
header.version = CGE_SAVEGAME_VERSION;
|
|
|
|
writeSavegameHeader(saveFile, header);
|
|
|
|
|
|
|
|
// Write out the data of the savegame
|
|
|
|
syncGame(NULL, saveFile);
|
|
|
|
|
|
|
|
// Finish writing out game data
|
|
|
|
saveFile->finalize();
|
|
|
|
delete saveFile;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
void CGEEngine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header) {
|
|
|
|
// Write out a savegame header
|
|
|
|
out->write(SAVEGAME_STR, SAVEGAME_STR_SIZE + 1);
|
|
|
|
|
|
|
|
out->writeByte(CGE_SAVEGAME_VERSION);
|
|
|
|
|
|
|
|
// Write savegame name
|
|
|
|
out->write(header.saveName.c_str(), header.saveName.size() + 1);
|
|
|
|
|
|
|
|
// Get the active palette
|
|
|
|
uint8 thumbPalette[256 * 3];
|
|
|
|
g_system->getPaletteManager()->grabPalette(thumbPalette, 0, 256);
|
|
|
|
|
|
|
|
// Create a thumbnail and save it
|
|
|
|
Graphics::Surface *thumb = new Graphics::Surface();
|
2011-07-16 11:12:19 +00:00
|
|
|
Graphics::Surface *s = _vga->_page[0];
|
2011-07-20 23:56:40 +00:00
|
|
|
::createThumbnail(thumb, (const byte *)s->pixels, kScrWidth, kScrHeight, thumbPalette);
|
2011-07-16 08:33:20 +00:00
|
|
|
Graphics::saveThumbnail(*out, *thumb);
|
|
|
|
delete thumb;
|
|
|
|
|
|
|
|
// Write out the save date/time
|
|
|
|
TimeDate td;
|
|
|
|
g_system->getTimeAndDate(td);
|
|
|
|
out->writeSint16LE(td.tm_year + 1900);
|
|
|
|
out->writeSint16LE(td.tm_mon + 1);
|
|
|
|
out->writeSint16LE(td.tm_mday);
|
|
|
|
out->writeSint16LE(td.tm_hour);
|
|
|
|
out->writeSint16LE(td.tm_min);
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream, bool tiny) {
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *spr;
|
2011-06-13 09:57:24 +00:00
|
|
|
int i;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
Common::Serializer s(readStream, writeStream);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
if (s.isSaving()) {
|
2011-07-20 23:56:40 +00:00
|
|
|
for (i = 0; i < kPocketNX; i++) {
|
2011-07-16 08:33:20 +00:00
|
|
|
register Sprite *s = _pocket[i];
|
|
|
|
_pocref[i] = (s) ? s->_ref : -1;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-24 21:42:03 +00:00
|
|
|
warning("STUB: CGEEngine::syncGame Digital and Midi volume");
|
|
|
|
// _volume[0] = _sndDrvInfo.Vol2._d;
|
|
|
|
// _volume[1] = _sndDrvInfo.Vol2._m;
|
|
|
|
_volume[0] = 0;
|
|
|
|
_volume[1] = 0;
|
2011-07-16 08:33:20 +00:00
|
|
|
}
|
2011-07-09 23:44:46 +00:00
|
|
|
|
|
|
|
// Synchronise header data
|
|
|
|
syncHeader(s);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
if (s.isSaving()) {
|
|
|
|
// Loop through saving the sprite data
|
|
|
|
for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) {
|
|
|
|
if ((spr->_ref >= 1000) && !s.err())
|
|
|
|
spr->sync(s);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Loading game
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_soundOk == 1 && _mode == 0) {
|
2011-07-24 21:42:03 +00:00
|
|
|
// _sndDrvInfo.Vol2._d = _volume[0];
|
|
|
|
// _sndDrvInfo.Vol2._m = _volume[1];
|
|
|
|
warning("STUB: CGEEngine::syncGame Digital and Midi volume");
|
2011-07-16 08:33:20 +00:00
|
|
|
sndSetVolume();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! tiny) { // load sprites & pocket
|
|
|
|
while (readStream->pos() < readStream->size()) {
|
|
|
|
Sprite S(this, NULL);
|
|
|
|
S.sync(s);
|
|
|
|
|
|
|
|
S._prev = S._next = NULL;
|
|
|
|
spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL)
|
|
|
|
: new Sprite(this, NULL);
|
2011-07-25 14:04:45 +00:00
|
|
|
assert(spr != NULL);
|
2011-07-16 08:33:20 +00:00
|
|
|
*spr = S;
|
|
|
|
_vga->_spareQ->append(spr);
|
|
|
|
}
|
|
|
|
|
2011-07-20 23:56:40 +00:00
|
|
|
for (i = 0; i < kPocketNX; i++) {
|
2011-07-16 08:33:20 +00:00
|
|
|
register int r = _pocref[i];
|
|
|
|
delete _pocket[i];
|
|
|
|
_pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r);
|
|
|
|
}
|
|
|
|
}
|
2011-07-09 23:44:46 +00:00
|
|
|
}
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::saveSound()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-16 08:33:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header) {
|
|
|
|
header.thumbnail = NULL;
|
|
|
|
|
|
|
|
// Get the savegame version
|
|
|
|
header.version = in->readByte();
|
|
|
|
if (header.version > CGE_SAVEGAME_VERSION)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Read in the string
|
|
|
|
header.saveName.clear();
|
|
|
|
char ch;
|
|
|
|
while ((ch = (char)in->readByte()) != '\0') header.saveName += ch;
|
|
|
|
|
|
|
|
// Get the thumbnail
|
|
|
|
header.thumbnail = new Graphics::Surface();
|
|
|
|
if (!Graphics::loadThumbnail(*in, *header.thumbnail)) {
|
|
|
|
delete header.thumbnail;
|
|
|
|
header.thumbnail = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read in save date/time
|
|
|
|
header.saveYear = in->readSint16LE();
|
|
|
|
header.saveMonth = in->readSint16LE();
|
|
|
|
header.saveDay = in->readSint16LE();
|
|
|
|
header.saveHour = in->readSint16LE();
|
|
|
|
header.saveMinutes = in->readSint16LE();
|
|
|
|
|
|
|
|
return true;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::heroCover(int cvr) {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::heroCover(%d)", cvr);
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnCover, 1, cvr, NULL);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
void CGEEngine::trouble(int seq, int text) {
|
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::trouble(%d, %d)", seq, text);
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
_hero->park();
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnWait, -1, -1, _hero);
|
|
|
|
_snail->addCom(kSnSeq, -1, seq, _hero);
|
|
|
|
_snail->addCom(kSnSound, -1, 2, _hero);
|
|
|
|
_snail->addCom(kSnWait, -1, -1, _hero);
|
2011-07-30 22:52:35 +00:00
|
|
|
_snail->addCom(kSnSay, 1, text, _hero);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::offUse() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::offUse()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-22 09:54:46 +00:00
|
|
|
trouble(kSeqOffUse, kOffUse + new_random(_offUseCount));
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::tooFar() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::tooFar()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-22 09:54:46 +00:00
|
|
|
trouble(kSeqTooFar, kTooFar);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::loadHeroXY() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::loadHeroXY()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-01 23:02:14 +00:00
|
|
|
INI_FILE cf(progName(".HXY"));
|
2011-07-02 16:20:41 +00:00
|
|
|
memset(_heroXY, 0, sizeof(_heroXY));
|
2011-07-01 06:37:40 +00:00
|
|
|
if (!cf._error)
|
2011-07-19 11:24:09 +00:00
|
|
|
cf.read((uint8 *)(&_heroXY),sizeof(*(&_heroXY)));
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-05 21:13:12 +00:00
|
|
|
void CGEEngine::loadMapping() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
if (_now <= _caveMax) {
|
2011-07-01 23:02:14 +00:00
|
|
|
INI_FILE cf(progName(".TAB"));
|
2011-07-01 06:37:40 +00:00
|
|
|
if (!cf._error) {
|
|
|
|
memset(Cluster::_map, 0, sizeof(Cluster::_map));
|
2011-07-02 16:20:41 +00:00
|
|
|
cf.seek((_now - 1) * sizeof(Cluster::_map));
|
2011-07-01 06:37:40 +00:00
|
|
|
cf.read((uint8 *) Cluster::_map, sizeof(Cluster::_map));
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 12:27:36 +00:00
|
|
|
Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) {
|
2011-06-29 14:13:17 +00:00
|
|
|
_flags._kill = true;
|
|
|
|
_flags._bDel = false;
|
2011-07-09 23:51:18 +00:00
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
BitmapPtr *MB = new BitmapPtr[2];
|
2011-07-09 23:51:18 +00:00
|
|
|
MB[0] = new Bitmap("BRICK", true);
|
|
|
|
MB[1] = NULL;
|
|
|
|
setShapeList(MB);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-20 12:27:36 +00:00
|
|
|
void Square::touch(uint16 mask, int x, int y) {
|
2011-07-01 23:02:14 +00:00
|
|
|
Sprite::touch(mask, x, y);
|
2011-06-13 09:57:24 +00:00
|
|
|
if (mask & L_UP) {
|
2011-07-01 06:37:40 +00:00
|
|
|
XZ(_x + x, _y + y).cell() = 0;
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnKill, -1, 0, this);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::setMapBrick(int x, int z) {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::setMapBrick(%d, %d)", x, z);
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-20 12:27:36 +00:00
|
|
|
Square *s = new Square(this);
|
2011-06-13 09:57:24 +00:00
|
|
|
if (s) {
|
|
|
|
static char n[] = "00:00";
|
2011-07-30 22:52:35 +00:00
|
|
|
s->gotoxy(x * kMapGridX, kMapTop + z * kMapGridZ);
|
2011-06-13 09:57:24 +00:00
|
|
|
wtom(x, n + 0, 10, 2);
|
|
|
|
wtom(z, n + 3, 10, 2);
|
2011-07-01 06:37:40 +00:00
|
|
|
Cluster::_map[z][x] = 1;
|
2011-07-01 23:02:14 +00:00
|
|
|
s->setName(n);
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(s, _vga->_showQ->first());
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::keyClick() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::keyClick()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSound, -1, 5, NULL);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::resetQSwitch() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::resetQSwitch()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSeq, 123, 0, NULL);
|
2011-07-07 06:11:29 +00:00
|
|
|
keyClick();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::quit() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::quit()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-28 13:35:12 +00:00
|
|
|
static Choice QuitMenu[] = {
|
2011-07-01 06:37:40 +00:00
|
|
|
{ NULL, &CGEEngine::startCountDown },
|
|
|
|
{ NULL, &CGEEngine::resetQSwitch },
|
2011-06-26 23:03:47 +00:00
|
|
|
{ NULL, &CGEEngine::dummy }
|
2011-06-13 09:57:24 +00:00
|
|
|
};
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
if (_snail->idle() && !_hero->_flags._hide) {
|
|
|
|
if (Vmenu::_addr) {
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnKill, -1, 0, Vmenu::_addr);
|
2011-07-01 06:37:40 +00:00
|
|
|
resetQSwitch();
|
2011-06-13 09:57:24 +00:00
|
|
|
} else {
|
2011-07-22 09:54:46 +00:00
|
|
|
QuitMenu[0]._text = _text->getText(kQuit);
|
|
|
|
QuitMenu[1]._text = _text->getText(kNoQuit);
|
|
|
|
(new Vmenu(this, QuitMenu, -1, -1))->setName(_text->getText(kQuitTitle));
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSeq, 123, 1, NULL);
|
2011-07-07 06:11:29 +00:00
|
|
|
keyClick();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-18 16:05:57 +00:00
|
|
|
void CGEEngine::AltCtrlDel() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::AltCtrlDel()");
|
2011-07-18 16:05:57 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSay, -1, kAltCtrlDel, _hero);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-12 22:28:17 +00:00
|
|
|
void CGEEngine::miniStep(int stp) {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::miniStep(%d)", stp);
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
if (stp < 0)
|
2011-06-29 14:13:17 +00:00
|
|
|
_miniCave->_flags._hide = true;
|
2011-06-13 09:57:24 +00:00
|
|
|
else {
|
2011-07-03 09:28:22 +00:00
|
|
|
*_miniShp[0] = *_miniShpList[stp];
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_fx->_current)
|
|
|
|
&*(_fx->_current->addr());
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
_miniCave->_flags._hide = false;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-18 21:09:57 +00:00
|
|
|
void CGEEngine::postMiniStep(int step) {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(6, kCGEDebugEngine, "CGEEngine::postMiniStep(%d)", step);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-18 21:09:57 +00:00
|
|
|
if (_miniCave && step != _recentStep)
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom2(kSnExec, -1, _recentStep = step, kMiniStep);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-18 21:14:22 +00:00
|
|
|
void CGEEngine::showBak(int ref) {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::showBack(%d)", ref);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
Sprite *spr = _vga->_spareQ->locate(ref);
|
2011-06-13 09:57:24 +00:00
|
|
|
if (spr) {
|
2011-07-03 14:22:26 +00:00
|
|
|
Bitmap::_pal = Vga::_sysPal;
|
2011-07-01 23:02:14 +00:00
|
|
|
spr->expand();
|
2011-06-30 06:30:23 +00:00
|
|
|
Bitmap::_pal = NULL;
|
2011-07-01 23:02:14 +00:00
|
|
|
spr->show(2);
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->copyPage(1, 2);
|
2011-07-04 06:15:56 +00:00
|
|
|
_sys->setPal();
|
2011-07-01 23:02:14 +00:00
|
|
|
spr->contract();
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-04 06:15:56 +00:00
|
|
|
void CGEEngine::caveUp() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::caveUp()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-02 16:20:41 +00:00
|
|
|
int BakRef = 1000 * _now;
|
|
|
|
if (_music)
|
2011-07-04 06:15:56 +00:00
|
|
|
loadMidi(_now);
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-18 21:14:22 +00:00
|
|
|
showBak(BakRef);
|
2011-07-03 09:28:22 +00:00
|
|
|
loadMapping();
|
|
|
|
_text->preload(BakRef, BakRef + 1000);
|
2011-07-03 14:22:26 +00:00
|
|
|
Sprite *spr = _vga->_spareQ->first();
|
2011-06-13 09:57:24 +00:00
|
|
|
while (spr) {
|
2011-06-29 14:13:17 +00:00
|
|
|
Sprite *n = spr->_next;
|
2011-07-02 16:20:41 +00:00
|
|
|
if (spr->_cave == _now || spr->_cave == 0)
|
2011-06-28 22:35:21 +00:00
|
|
|
if (spr->_ref != BakRef) {
|
2011-06-29 14:13:17 +00:00
|
|
|
if (spr->_flags._back)
|
2011-07-01 23:02:14 +00:00
|
|
|
spr->backShow();
|
2011-06-13 09:57:24 +00:00
|
|
|
else
|
2011-07-05 21:13:12 +00:00
|
|
|
expandSprite(spr);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
spr = n;
|
|
|
|
}
|
2011-07-24 21:42:03 +00:00
|
|
|
|
2011-07-29 08:02:32 +00:00
|
|
|
_sound->stop();
|
|
|
|
_fx->clear();
|
|
|
|
_fx->preload(0);
|
|
|
|
_fx->preload(BakRef);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
if (_hero) {
|
|
|
|
_hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y);
|
2011-06-13 09:57:24 +00:00
|
|
|
// following 2 lines trims Hero's Z position!
|
2011-07-03 14:22:26 +00:00
|
|
|
_hero->tick();
|
|
|
|
_hero->_time = 1;
|
|
|
|
_hero->_flags._hide = false;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-02 16:20:41 +00:00
|
|
|
if (!_dark)
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->sunset();
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->copyPage(0, 1);
|
2011-07-02 16:20:41 +00:00
|
|
|
selectPocket(-1);
|
2011-07-03 14:22:26 +00:00
|
|
|
if (_hero)
|
|
|
|
_vga->_showQ->insert(_vga->_showQ->remove(_hero));
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
if (_shadow) {
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->remove(_shadow);
|
|
|
|
_shadow->makeXlat(glass(Vga::_sysPal, 204, 204, 204));
|
|
|
|
_vga->_showQ->insert(_shadow, _hero);
|
|
|
|
_shadow->_z = _hero->_z;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-07-13 06:44:58 +00:00
|
|
|
feedSnail(_vga->_showQ->locate(BakRef + 999), kTake);
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->show();
|
|
|
|
_vga->copyPage(1, 0);
|
|
|
|
_vga->show();
|
|
|
|
_vga->sunrise(Vga::_sysPal);
|
2011-07-02 16:20:41 +00:00
|
|
|
_dark = false;
|
2011-07-04 06:15:56 +00:00
|
|
|
if (!_startupMode)
|
2011-07-08 06:21:35 +00:00
|
|
|
_mouse->on();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::caveDown() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::caveDown()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *spr;
|
2011-06-29 14:13:17 +00:00
|
|
|
if (!_horzLine->_flags._hide)
|
2011-07-01 06:37:40 +00:00
|
|
|
switchMapping();
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
for (spr = _vga->_showQ->first(); spr;) {
|
2011-06-29 14:13:17 +00:00
|
|
|
Sprite *n = spr->_next;
|
2011-06-28 22:35:21 +00:00
|
|
|
if (spr->_ref >= 1000 /*&& spr->_cave*/) {
|
|
|
|
if (spr->_ref % 1000 == 999)
|
2011-07-13 06:44:58 +00:00
|
|
|
feedSnail(spr, kTake);
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_spareQ->append(_vga->_showQ->remove(spr));
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-18 06:54:22 +00:00
|
|
|
spr = n;
|
|
|
|
}
|
2011-07-03 09:28:22 +00:00
|
|
|
_text->clear(1000);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::xCave() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(6, kCGEDebugEngine, "CGEEngine::xCave()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
caveDown();
|
|
|
|
caveUp();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::qGame() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::qGame()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
caveDown();
|
2011-07-02 16:20:41 +00:00
|
|
|
_oldLev = _lev;
|
2011-07-07 06:11:29 +00:00
|
|
|
saveSound();
|
2011-07-09 23:44:46 +00:00
|
|
|
|
|
|
|
// Write out the user's progress
|
2011-07-16 08:33:20 +00:00
|
|
|
saveGame(0, _usrFnam);
|
2011-07-09 23:44:46 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->sunset();
|
2011-07-03 09:28:22 +00:00
|
|
|
_finis = true;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::switchCave(int cav) {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::switchCave(%d)", cav);
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-02 16:20:41 +00:00
|
|
|
if (cav != _now) {
|
2011-06-13 09:57:24 +00:00
|
|
|
if (cav < 0) {
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint
|
|
|
|
_snail->addCom2(kSnExec, -1, 0, kQGame); // switch cave
|
2011-06-13 09:57:24 +00:00
|
|
|
} else {
|
2011-07-02 16:20:41 +00:00
|
|
|
_now = cav;
|
2011-07-08 06:21:35 +00:00
|
|
|
_mouse->off();
|
2011-07-03 14:22:26 +00:00
|
|
|
if (_hero) {
|
|
|
|
_hero->park();
|
|
|
|
_hero->step(0);
|
2011-06-26 23:03:47 +00:00
|
|
|
if (!_isDemo)
|
2011-07-28 09:08:56 +00:00
|
|
|
_vga->_spareQ->_show = 0;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-07-30 22:52:35 +00:00
|
|
|
_cavLight->gotoxy(CAVE_X + ((_now - 1) % _caveNx) * _caveDx + CAVE_SX,
|
|
|
|
CAVE_Y + ((_now - 1) / _caveNx) * _caveDy + CAVE_SY);
|
2011-07-03 09:28:22 +00:00
|
|
|
killText();
|
2011-07-04 06:15:56 +00:00
|
|
|
if (!_startupMode)
|
2011-07-07 06:11:29 +00:00
|
|
|
keyClick();
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint
|
|
|
|
_snail->addCom2(kSnExec, 0, 0, kXCave); // switch cave
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-04 06:15:56 +00:00
|
|
|
System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) {
|
2011-07-20 23:56:40 +00:00
|
|
|
_funDel = kHeroFun0;
|
2011-07-04 06:15:56 +00:00
|
|
|
setPal();
|
|
|
|
tick();
|
2011-06-20 21:40:22 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-18 21:09:57 +00:00
|
|
|
void System::setPal() {
|
|
|
|
uint i;
|
|
|
|
Dac *p = Vga::_sysPal + 256 - ArrayCount(_stdPal);
|
|
|
|
for (i = 0; i < ArrayCount(_stdPal); i++) {
|
|
|
|
p[i]._r = _stdPal[i]._r >> 2;
|
|
|
|
p[i]._g = _stdPal[i]._g >> 2;
|
|
|
|
p[i]._b = _stdPal[i]._b >> 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void System::funTouch() {
|
2011-07-20 23:56:40 +00:00
|
|
|
uint16 n = (PAIN) ? kHeroFun1 : kHeroFun0;
|
2011-07-18 21:09:57 +00:00
|
|
|
if (_talk == NULL || n > _funDel)
|
|
|
|
_funDel = n;
|
|
|
|
}
|
|
|
|
|
2011-07-04 06:15:56 +00:00
|
|
|
void System::touch(uint16 mask, int x, int y) {
|
2011-06-13 09:57:24 +00:00
|
|
|
static int pp = 0;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-04 06:15:56 +00:00
|
|
|
funTouch();
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
if (mask & KEYB) {
|
|
|
|
int pp0;
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->keyClick();
|
2011-07-03 09:28:22 +00:00
|
|
|
killText();
|
2011-07-04 06:15:56 +00:00
|
|
|
if (_vm->_startupMode == 1) {
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnClear, -1, 0, NULL);
|
2011-06-13 09:57:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
pp0 = pp;
|
|
|
|
switch (x) {
|
|
|
|
case Del:
|
2011-07-31 17:56:14 +00:00
|
|
|
if (_keyboard->_key[kKeyAlt] && _keyboard->_key[kKeyCtrl])
|
2011-07-18 16:05:57 +00:00
|
|
|
_vm->AltCtrlDel();
|
2011-07-28 13:35:12 +00:00
|
|
|
else
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->killSprite();
|
2011-06-18 06:54:22 +00:00
|
|
|
break;
|
2011-06-13 09:57:24 +00:00
|
|
|
case 'F':
|
2011-07-31 17:56:14 +00:00
|
|
|
if (_keyboard->_key[kKeyAlt]) {
|
2011-07-03 14:22:26 +00:00
|
|
|
Sprite *m = _vga->_showQ->locate(17001);
|
2011-06-13 09:57:24 +00:00
|
|
|
if (m) {
|
2011-07-01 23:02:14 +00:00
|
|
|
m->step(1);
|
2011-06-29 14:13:17 +00:00
|
|
|
m->_time = 216; // 3s
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PgUp:
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->pushSprite();
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case PgDn:
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->pullSprite();
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case '+':
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->nextStep();
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case '`':
|
2011-07-31 17:56:14 +00:00
|
|
|
if (_keyboard->_key[kKeyAlt])
|
2011-07-05 21:13:12 +00:00
|
|
|
_vm->saveMapping();
|
2011-06-13 09:57:24 +00:00
|
|
|
else
|
2011-07-01 06:37:40 +00:00
|
|
|
_vm->switchMapping();
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F1:
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->switchDebug();
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F3:
|
2011-07-22 09:54:46 +00:00
|
|
|
_hero->step(kTSeq + 4);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F4:
|
2011-07-22 09:54:46 +00:00
|
|
|
_hero->step(kTSeq + 5);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F5:
|
2011-07-22 09:54:46 +00:00
|
|
|
_hero->step(kTSeq + 0);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F6:
|
2011-07-22 09:54:46 +00:00
|
|
|
_hero->step(kTSeq + 1);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F7:
|
2011-07-22 09:54:46 +00:00
|
|
|
_hero->step(kTSeq + 2);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F8:
|
2011-07-22 09:54:46 +00:00
|
|
|
_hero->step(kTSeq + 3);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F9:
|
2011-07-04 06:15:56 +00:00
|
|
|
_sys->_funDel = 1;
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case 'X':
|
2011-07-31 17:56:14 +00:00
|
|
|
if (_keyboard->_key[kKeyAlt])
|
2011-07-03 09:28:22 +00:00
|
|
|
_finis = true;
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
2011-07-31 17:56:14 +00:00
|
|
|
if (_keyboard->_key[kKeyAlt]) {
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnLevel, -1, x - '0', NULL);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
case '8':
|
|
|
|
case '9':
|
2011-06-28 22:35:21 +00:00
|
|
|
if (_sprite)
|
2011-07-01 23:02:14 +00:00
|
|
|
_sprite->step(x - '0');
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case F10 :
|
2011-07-03 14:22:26 +00:00
|
|
|
if (_snail->idle() && !_hero->_flags._hide)
|
2011-07-01 06:37:40 +00:00
|
|
|
_vm->startCountDown();
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case 'J':
|
|
|
|
if (pp == 0)
|
2011-07-03 14:22:26 +00:00
|
|
|
pp++;
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
if (pp == 1)
|
2011-07-03 14:22:26 +00:00
|
|
|
pp++;
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
if (pp == 2)
|
2011-07-04 06:15:56 +00:00
|
|
|
_vm->_jbw = !_vm->_jbw;
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pp == pp0)
|
|
|
|
pp = 0;
|
|
|
|
} else {
|
2011-07-04 06:15:56 +00:00
|
|
|
if (_vm->_startupMode)
|
2011-06-13 09:57:24 +00:00
|
|
|
return;
|
2011-06-13 11:44:52 +00:00
|
|
|
int cav = 0;
|
2011-07-03 09:28:22 +00:00
|
|
|
_infoLine->update(NULL);
|
2011-07-20 23:56:40 +00:00
|
|
|
if (y >= kWorldHeight ) {
|
|
|
|
if (x < kButtonX) { // select cave?
|
2011-07-30 22:52:35 +00:00
|
|
|
if (y >= CAVE_Y && y < CAVE_Y + _vm->_caveNy * _vm->_caveDy &&
|
|
|
|
x >= CAVE_X && x < CAVE_X + _vm->_caveNx * _vm->_caveDx && !_vm->_game) {
|
|
|
|
cav = ((y - CAVE_Y) / _vm->_caveDy) * _vm->_caveNx + (x - CAVE_X) / _vm->_caveDx + 1;
|
2011-07-05 21:13:12 +00:00
|
|
|
if (cav > _vm->_maxCave)
|
2011-06-13 09:57:24 +00:00
|
|
|
cav = 0;
|
|
|
|
} else {
|
|
|
|
cav = 0;
|
|
|
|
}
|
|
|
|
} else if (mask & L_UP) {
|
2011-07-20 23:56:40 +00:00
|
|
|
if (y >= kPocketY && y < kPocketY + kPocketNY * kPocketDY &&
|
|
|
|
x >= kPocketX && x < kPocketX + kPocketNX * kPocketDX) {
|
|
|
|
int n = ((y - kPocketY) / kPocketDY) * kPocketNX + (x - kPocketX) / kPocketDX;
|
2011-07-04 06:15:56 +00:00
|
|
|
_vm->selectPocket(n);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-18 21:09:57 +00:00
|
|
|
_vm->postMiniStep(cav - 1);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
if (mask & L_UP) {
|
2011-07-03 14:22:26 +00:00
|
|
|
if (cav && _snail->idle() && _hero->_tracePtr < 0)
|
2011-07-01 06:37:40 +00:00
|
|
|
_vm->switchCave(cav);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
if (!_horzLine->_flags._hide) {
|
2011-07-30 22:52:35 +00:00
|
|
|
if (y >= kMapTop && y < kMapTop + kMapHig) {
|
2011-06-13 11:44:52 +00:00
|
|
|
int8 x1, z1;
|
2011-07-01 06:37:40 +00:00
|
|
|
XZ(x, y).split(x1, z1);
|
|
|
|
Cluster::_map[z1][x1] = 1;
|
|
|
|
_vm->setMapBrick(x1, z1);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-07-18 21:09:57 +00:00
|
|
|
} else {
|
2011-07-03 14:22:26 +00:00
|
|
|
if (!_talk && _snail->idle() && _hero
|
2011-07-30 22:52:35 +00:00
|
|
|
&& y >= kMapTop && y < kMapTop + kMapHig && !_vm->_game) {
|
2011-07-03 14:22:26 +00:00
|
|
|
_hero->findWay(XZ(x, y));
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-04 06:15:56 +00:00
|
|
|
void System::tick() {
|
|
|
|
if (!_vm->_startupMode)
|
|
|
|
if (--_funDel == 0) {
|
2011-07-03 09:28:22 +00:00
|
|
|
killText();
|
2011-07-02 16:20:41 +00:00
|
|
|
if (_snail->idle()) {
|
2011-06-13 09:57:24 +00:00
|
|
|
if (PAIN)
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->heroCover(9);
|
2011-07-25 17:09:12 +00:00
|
|
|
else { // CHECKME: Before, was: if (Startup::_core >= CORE_MID) {
|
2011-06-13 09:57:24 +00:00
|
|
|
int n = new_random(100);
|
|
|
|
if (n > 96)
|
2011-07-20 23:56:40 +00:00
|
|
|
_vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < kScrWidth / 2));
|
2011-06-13 09:57:24 +00:00
|
|
|
else {
|
|
|
|
if (n > 90)
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->heroCover(5);
|
2011-06-13 09:57:24 +00:00
|
|
|
else {
|
|
|
|
if (n > 60)
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->heroCover(4);
|
2011-06-13 09:57:24 +00:00
|
|
|
else
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->heroCover(3);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-04 06:15:56 +00:00
|
|
|
funTouch();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-07-20 23:56:40 +00:00
|
|
|
_time = kSystemRate;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::switchColorMode() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::switchColorMode()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSeq, 121, _vga->_mono = !_vga->_mono, NULL);
|
2011-07-07 06:11:29 +00:00
|
|
|
keyClick();
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->setColors(Vga::_sysPal, 64);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-04 06:15:56 +00:00
|
|
|
void CGEEngine::switchMusic() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::switchMusic()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-31 17:56:14 +00:00
|
|
|
if (_keyboard->_key[kKeyAlt]) {
|
2011-07-03 14:22:26 +00:00
|
|
|
if (Vmenu::_addr)
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnKill, -1, 0, Vmenu::_addr);
|
2011-06-13 09:57:24 +00:00
|
|
|
else {
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSeq, 122, (_music = false), NULL);
|
|
|
|
_snail->addCom2(kSnExec, -1, 0, kSelectSound);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-07-25 17:09:12 +00:00
|
|
|
_snail_->addCom(kSnSeq, 122, (_music = !_music), NULL);
|
|
|
|
keyClick();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-07-02 16:20:41 +00:00
|
|
|
if (_music)
|
2011-07-04 06:15:56 +00:00
|
|
|
loadMidi(_now);
|
2011-06-13 09:57:24 +00:00
|
|
|
else
|
2011-07-04 06:15:56 +00:00
|
|
|
killMidi();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::startCountDown() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::startCountDown()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
//SNPOST(SNSEQ, 123, 0, NULL);
|
2011-07-01 06:37:40 +00:00
|
|
|
switchCave(-1);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::takeName() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::takeName()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-01 23:02:14 +00:00
|
|
|
if (GetText::_ptr)
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnKill, -1, 0, GetText::_ptr);
|
2011-06-13 09:57:24 +00:00
|
|
|
else {
|
2011-07-16 08:33:20 +00:00
|
|
|
memset(_usrFnam, 0, 15);
|
2011-07-22 09:54:46 +00:00
|
|
|
GetText *tn = new GetText(this, _text->getText(kGetNamePrompt), _usrFnam, 8);
|
2011-06-13 09:57:24 +00:00
|
|
|
if (tn) {
|
2011-07-22 09:54:46 +00:00
|
|
|
tn->setName(_text->getText(kGetNameTitle));
|
2011-07-01 23:02:14 +00:00
|
|
|
tn->center();
|
|
|
|
tn->gotoxy(tn->_x, tn->_y - 10);
|
2011-06-29 14:13:17 +00:00
|
|
|
tn->_z = 126;
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(tn);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::switchMapping() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::switchMapping()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
if (_horzLine->_flags._hide) {
|
2011-06-13 09:57:24 +00:00
|
|
|
int i;
|
2011-07-30 22:52:35 +00:00
|
|
|
for (i = 0; i < kMapZCnt; i++) {
|
2011-06-13 09:57:24 +00:00
|
|
|
int j;
|
2011-07-30 22:52:35 +00:00
|
|
|
for (j = 0; j < kMapXCnt; j++) {
|
2011-07-01 06:37:40 +00:00
|
|
|
if (Cluster::_map[i][j])
|
|
|
|
setMapBrick(j, i);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *s;
|
2011-07-03 14:22:26 +00:00
|
|
|
for (s = _vga->_showQ->first(); s; s = s->_next)
|
2011-07-30 22:52:35 +00:00
|
|
|
if (s->_w == kMapGridX && s->_h == kMapGridZ)
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnKill, -1, 0, s);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-29 14:13:17 +00:00
|
|
|
_horzLine->_flags._hide = !_horzLine->_flags._hide;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::killSprite() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::killSprite()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
_sprite->_flags._kill = true;
|
|
|
|
_sprite->_flags._bDel = true;
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnKill, -1, 0, _sprite);
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = NULL;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::pushSprite() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::pushSprite()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
Sprite *spr = _sprite->_prev;
|
2011-06-13 09:57:24 +00:00
|
|
|
if (spr) {
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr);
|
2011-06-29 14:13:17 +00:00
|
|
|
while (_sprite->_z > _sprite->_next->_z)
|
|
|
|
_sprite->_z--;
|
2011-06-13 09:57:24 +00:00
|
|
|
} else
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSound, -1, 2, NULL);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::pullSprite() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::pullSprite()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
bool ok = false;
|
2011-06-29 14:13:17 +00:00
|
|
|
Sprite *spr = _sprite->_next;
|
2011-06-13 09:57:24 +00:00
|
|
|
if (spr) {
|
2011-06-29 14:13:17 +00:00
|
|
|
spr = spr->_next;
|
2011-06-13 09:57:24 +00:00
|
|
|
if (spr)
|
2011-06-29 14:13:17 +00:00
|
|
|
ok = (!spr->_flags._slav);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
if (ok) {
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr);
|
2011-06-29 14:13:17 +00:00
|
|
|
if (_sprite->_prev)
|
|
|
|
while (_sprite->_z < _sprite->_prev->_z)
|
|
|
|
_sprite->_z++;
|
2011-06-13 09:57:24 +00:00
|
|
|
} else
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSound, -1, 2, NULL);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::nextStep() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::nextStep()");
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnStep, 0, 0, _sprite);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-05 21:13:12 +00:00
|
|
|
void CGEEngine::saveMapping() {
|
2011-07-20 12:22:56 +00:00
|
|
|
debugC(1, kCGEDebugEngine, "CGEEngine::saveMapping()");
|
2011-07-18 21:14:22 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
IoHand cfTab(progName(".TAB"), kModeUpdate);
|
2011-07-18 21:09:57 +00:00
|
|
|
if (!cfTab._error) {
|
|
|
|
cfTab.seek((_now - 1) * sizeof(Cluster::_map));
|
|
|
|
cfTab.write((uint8 *) Cluster::_map, sizeof(Cluster::_map));
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-07-18 21:09:57 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
IoHand cfHxy(progName(".HXY"), kModeWrite);
|
2011-07-18 21:09:57 +00:00
|
|
|
if (!cfHxy._error) {
|
|
|
|
_heroXY[_now - 1]._x = _hero->_x;
|
|
|
|
_heroXY[_now - 1]._y = _hero->_y;
|
|
|
|
cfHxy.write((uint8 *) _heroXY, sizeof(_heroXY));
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-18 21:09:57 +00:00
|
|
|
// 1111111111222222222233333333334444444444555555555566666666667777777777
|
|
|
|
// 01234567890123456789012345678901234567890123456789012345678901234567890123456789
|
|
|
|
static char DebugText[] = " X=000 Y=000 S=00:00 000:000:000 000:000 00";
|
|
|
|
|
|
|
|
#define ABSX (DebugText + 3)
|
|
|
|
#define ABSY (DebugText + 9)
|
|
|
|
#define SP_N (DebugText + 15)
|
|
|
|
#define SP_S (DebugText + 18)
|
|
|
|
#define SP_X (DebugText + 21)
|
|
|
|
#define SP_Y (DebugText + 25)
|
|
|
|
#define SP_Z (DebugText + 29)
|
|
|
|
#define SP_W (DebugText + 33)
|
|
|
|
#define SP_H (DebugText + 37)
|
|
|
|
#define SP_F (DebugText + 41)
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::sayDebug() {
|
2011-07-03 09:28:22 +00:00
|
|
|
if (!_debugLine->_flags._hide) {
|
2011-07-02 06:46:31 +00:00
|
|
|
dwtom(_mouse->_x, ABSX, 10, 3);
|
|
|
|
dwtom(_mouse->_y, ABSY, 10, 3);
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
// sprite queue size
|
|
|
|
uint16 n = 0;
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite *spr;
|
2011-07-03 14:22:26 +00:00
|
|
|
for (spr = _vga->_showQ->first(); spr; spr = spr->_next) {
|
2011-07-25 14:04:45 +00:00
|
|
|
n++;
|
2011-06-28 22:35:21 +00:00
|
|
|
if (spr == _sprite) {
|
2011-06-13 09:57:24 +00:00
|
|
|
dwtom(n, SP_N, 10, 2);
|
2011-06-29 14:13:17 +00:00
|
|
|
dwtom(_sprite->_x, SP_X, 10, 3);
|
|
|
|
dwtom(_sprite->_y, SP_Y, 10, 3);
|
|
|
|
dwtom(_sprite->_z, SP_Z, 10, 3);
|
|
|
|
dwtom(_sprite->_w, SP_W, 10, 3);
|
|
|
|
dwtom(_sprite->_h, SP_H, 10, 3);
|
|
|
|
dwtom(*(uint16 *)(&_sprite->_flags), SP_F, 16, 2);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dwtom(n, SP_S, 10, 2);
|
2011-07-03 09:28:22 +00:00
|
|
|
_debugLine->update(DebugText);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-07 06:11:29 +00:00
|
|
|
void CGEEngine::switchDebug() {
|
2011-07-03 09:28:22 +00:00
|
|
|
_debugLine->_flags._hide = !_debugLine->_flags._hide;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::optionTouch(int opt, uint16 mask) {
|
2011-06-13 09:57:24 +00:00
|
|
|
switch (opt) {
|
|
|
|
case 1 :
|
|
|
|
if (mask & L_UP)
|
2011-07-07 06:11:29 +00:00
|
|
|
switchColorMode();
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case 2 :
|
|
|
|
if (mask & L_UP)
|
2011-07-04 06:15:56 +00:00
|
|
|
switchMusic();
|
2011-06-13 09:57:24 +00:00
|
|
|
else if (mask & R_UP)
|
2011-07-01 23:02:14 +00:00
|
|
|
if (!Mixer::_appear) {
|
|
|
|
Mixer::_appear = true;
|
2011-07-20 23:56:40 +00:00
|
|
|
new Mixer(this, kButtonX, kButtonY);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3 :
|
|
|
|
if (mask & L_UP)
|
2011-07-01 06:37:40 +00:00
|
|
|
quit();
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
#pragma argsused
|
2011-07-01 23:02:14 +00:00
|
|
|
void Sprite::touch(uint16 mask, int x, int y) {
|
2011-07-04 06:15:56 +00:00
|
|
|
_sys->funTouch();
|
2011-06-13 09:57:24 +00:00
|
|
|
if ((mask & ATTN) == 0) {
|
2011-07-03 09:28:22 +00:00
|
|
|
_infoLine->update(name());
|
2011-06-13 09:57:24 +00:00
|
|
|
if (mask & (R_DN | L_DN))
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = this;
|
|
|
|
if (_ref / 10 == 12) {
|
2011-07-01 06:37:40 +00:00
|
|
|
_vm->optionTouch(_ref % 10, mask);
|
2011-06-13 09:57:24 +00:00
|
|
|
return;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-29 14:13:17 +00:00
|
|
|
if (_flags._syst)
|
2011-06-13 09:57:24 +00:00
|
|
|
return; // cannot access system sprites
|
2011-07-05 21:13:12 +00:00
|
|
|
if (_vm->_game) if (mask & L_UP) {
|
2011-06-13 09:57:24 +00:00
|
|
|
mask &= ~L_UP;
|
|
|
|
mask |= R_UP;
|
|
|
|
}
|
2011-07-02 16:20:41 +00:00
|
|
|
if ((mask & R_UP) && _snail->idle()) {
|
2011-07-04 06:15:56 +00:00
|
|
|
Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL;
|
2011-06-13 09:57:24 +00:00
|
|
|
if (ps) {
|
2011-07-20 23:56:40 +00:00
|
|
|
if (_flags._kept || _hero->distance(this) < kDistMax) {
|
2011-07-01 23:02:14 +00:00
|
|
|
if (works(ps)) {
|
2011-07-13 06:44:58 +00:00
|
|
|
_vm->feedSnail(ps, kTake);
|
2011-06-13 11:07:45 +00:00
|
|
|
} else
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->offUse();
|
2011-07-04 06:15:56 +00:00
|
|
|
_vm->selectPocket(-1);
|
2011-06-13 11:07:45 +00:00
|
|
|
} else
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->tooFar();
|
2011-06-13 09:57:24 +00:00
|
|
|
} else {
|
2011-06-29 14:13:17 +00:00
|
|
|
if (_flags._kept)
|
2011-06-13 09:57:24 +00:00
|
|
|
mask |= L_UP;
|
|
|
|
else {
|
2011-07-20 23:56:40 +00:00
|
|
|
if (_hero->distance(this) < kDistMax) {
|
2011-06-13 09:57:24 +00:00
|
|
|
///
|
2011-06-29 14:13:17 +00:00
|
|
|
if (_flags._port) {
|
2011-07-05 21:13:12 +00:00
|
|
|
if (_vm->findPocket(NULL) < 0)
|
|
|
|
_vm->pocFul();
|
2011-06-13 09:57:24 +00:00
|
|
|
else {
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnReach, -1, -1, this);
|
|
|
|
_snail->addCom(kSnKeep, -1, -1, this);
|
2011-06-29 14:13:17 +00:00
|
|
|
_flags._port = false;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-07-01 23:02:14 +00:00
|
|
|
if (_takePtr != NO_PTR) {
|
2011-07-23 12:31:39 +00:00
|
|
|
if (snList(kTake)[_takePtr]._com == kSnNext)
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->offUse();
|
2011-06-13 11:07:45 +00:00
|
|
|
else
|
2011-07-13 06:44:58 +00:00
|
|
|
_vm->feedSnail(this, kTake);
|
2011-06-13 11:07:45 +00:00
|
|
|
} else
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->offUse();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}///
|
2011-06-13 11:07:45 +00:00
|
|
|
else
|
2011-07-07 06:11:29 +00:00
|
|
|
_vm->tooFar();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-07-02 16:20:41 +00:00
|
|
|
if ((mask & L_UP) && _snail->idle()) {
|
2011-06-29 14:13:17 +00:00
|
|
|
if (_flags._kept) {
|
2011-06-13 09:57:24 +00:00
|
|
|
int n;
|
2011-07-20 23:56:40 +00:00
|
|
|
for (n = 0; n < kPocketNX; n++) {
|
2011-06-28 22:35:21 +00:00
|
|
|
if (_pocket[n] == this) {
|
2011-07-04 06:15:56 +00:00
|
|
|
_vm->selectPocket(n);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-13 11:07:45 +00:00
|
|
|
} else
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnWalk, -1, -1, this); // Hero->FindWay(this);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) {
|
2011-06-13 09:57:24 +00:00
|
|
|
static const char *Comd[] = { "Name", "Type", "Phase", "East",
|
|
|
|
"Left", "Right", "Top", "Bottom",
|
|
|
|
"Seq", "Near", "Take",
|
|
|
|
"Portable", "Transparent",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const char *Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS",
|
|
|
|
"FLY", NULL
|
|
|
|
};
|
2011-07-20 23:56:40 +00:00
|
|
|
char line[kLineMax];
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
int shpcnt = 0;
|
|
|
|
int type = 0; // DEAD
|
|
|
|
bool east = false;
|
|
|
|
bool port = false;
|
|
|
|
bool tran = false;
|
|
|
|
int i, lcnt = 0;
|
|
|
|
uint16 len;
|
|
|
|
|
2011-07-01 23:02:14 +00:00
|
|
|
mergeExt(line, fname, SPR_EXT);
|
2011-06-30 06:30:23 +00:00
|
|
|
if (INI_FILE::exist(line)) { // sprite description file exist
|
2011-06-13 09:57:24 +00:00
|
|
|
INI_FILE sprf(line);
|
2011-07-01 06:37:40 +00:00
|
|
|
if (sprf._error)
|
2011-06-13 09:57:24 +00:00
|
|
|
error("Bad SPR [%s]", line);
|
|
|
|
|
2011-06-30 06:30:23 +00:00
|
|
|
while ((len = sprf.read((uint8 *)line)) != 0) {
|
2011-07-25 14:04:45 +00:00
|
|
|
lcnt++;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (len && line[len - 1] == '\n')
|
2011-07-25 14:04:45 +00:00
|
|
|
line[--len] = '\0';
|
2011-06-13 11:07:45 +00:00
|
|
|
if (len == 0 || *line == '.')
|
2011-06-13 09:57:24 +00:00
|
|
|
continue;
|
|
|
|
|
2011-07-01 23:02:14 +00:00
|
|
|
if ((i = takeEnum(Comd, strtok(line, " =\t"))) < 0)
|
2011-07-02 18:25:39 +00:00
|
|
|
error("Bad line %d [%s]", lcnt, fname);
|
2011-06-13 09:57:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 0 : // Name - will be taken in Expand routine
|
|
|
|
break;
|
|
|
|
case 1 : // Type
|
2011-07-01 23:02:14 +00:00
|
|
|
if ((type = takeEnum(Type, strtok(NULL, " \t,;/"))) < 0)
|
2011-07-02 18:25:39 +00:00
|
|
|
error("Bad line %d [%s]", lcnt, fname);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case 2 : // Phase
|
2011-07-25 14:04:45 +00:00
|
|
|
shpcnt++;
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
case 3 : // East
|
|
|
|
east = (atoi(strtok(NULL, " \t,;/")) != 0);
|
|
|
|
break;
|
|
|
|
case 11 : // Portable
|
|
|
|
port = (atoi(strtok(NULL, " \t,;/")) != 0);
|
|
|
|
break;
|
|
|
|
case 12 : // Transparent
|
|
|
|
tran = (atoi(strtok(NULL, " \t,;/")) != 0);
|
|
|
|
break;
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
if (! shpcnt)
|
|
|
|
error("No shapes [%s]", fname);
|
|
|
|
} else { // no sprite description: mono-shaped sprite with only .BMP file
|
|
|
|
++shpcnt;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
// make sprite of choosen type
|
|
|
|
switch (type) {
|
|
|
|
case 1 : { // AUTO
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = new Sprite(this, NULL);
|
|
|
|
if (_sprite) {
|
2011-07-01 23:02:14 +00:00
|
|
|
_sprite->gotoxy(col, row);
|
2011-06-13 09:57:24 +00:00
|
|
|
//Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$
|
|
|
|
}
|
|
|
|
break;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
case 2 : { // WALK
|
2011-07-24 21:42:03 +00:00
|
|
|
Walk *w = new Walk(this, NULL);
|
2011-06-13 09:57:24 +00:00
|
|
|
if (w && ref == 1) {
|
2011-07-01 23:02:14 +00:00
|
|
|
w->gotoxy(col, row);
|
2011-07-03 14:22:26 +00:00
|
|
|
if (_hero)
|
2011-06-13 09:57:24 +00:00
|
|
|
error("2nd HERO [%s]", fname);
|
2011-07-03 14:22:26 +00:00
|
|
|
_hero = w;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = w;
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
/*
|
|
|
|
case 3 : // NEWTON
|
|
|
|
NEWTON * n = new NEWTON(NULL);
|
|
|
|
if (n)
|
2011-06-09 06:20:53 +00:00
|
|
|
{
|
2011-06-13 09:57:24 +00:00
|
|
|
n->Ay = (bottom-n->H);
|
|
|
|
n->By = 90;
|
|
|
|
n->Cy = 3;
|
|
|
|
n->Bx = 99;
|
|
|
|
n->Cx = 3;
|
|
|
|
n->Goto(col, row);
|
|
|
|
}
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = n;
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
*/
|
|
|
|
case 4 : { // LISSAJOUS
|
|
|
|
error("Bad type [%s]", fname);
|
|
|
|
/*
|
|
|
|
LISSAJOUS * l = new LISSAJOUS(NULL);
|
|
|
|
if (l)
|
|
|
|
{
|
|
|
|
l->Ax = SCR_WID/2;
|
|
|
|
l->Ay = SCR_HIG/2;
|
|
|
|
l->Bx = 7;
|
|
|
|
l->By = 13;
|
|
|
|
l->Cx = 300;
|
|
|
|
l->Cy = 500;
|
2011-06-26 10:07:42 +00:00
|
|
|
*(long *) &l->Dx = 0; // movex * cnt
|
2011-06-13 09:57:24 +00:00
|
|
|
l->Goto(col, row);
|
|
|
|
}
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = l;
|
2011-06-13 09:57:24 +00:00
|
|
|
*/
|
|
|
|
break;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
case 5 : { // FLY
|
2011-07-01 06:37:40 +00:00
|
|
|
Fly *f = new Fly(this, NULL);
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = f;
|
2011-06-13 09:57:24 +00:00
|
|
|
//////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$
|
|
|
|
break;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
default: { // DEAD
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = new Sprite(this, NULL);
|
|
|
|
if (_sprite)
|
2011-07-01 23:02:14 +00:00
|
|
|
_sprite->gotoxy(col, row);
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-28 22:35:21 +00:00
|
|
|
if (_sprite) {
|
|
|
|
_sprite->_ref = ref;
|
|
|
|
_sprite->_cave = cav;
|
2011-06-29 14:13:17 +00:00
|
|
|
_sprite->_z = pos;
|
|
|
|
_sprite->_flags._east = east;
|
|
|
|
_sprite->_flags._port = port;
|
|
|
|
_sprite->_flags._tran = tran;
|
|
|
|
_sprite->_flags._kill = true;
|
|
|
|
_sprite->_flags._bDel = true;
|
2011-06-29 11:17:07 +00:00
|
|
|
|
|
|
|
// Extract the filename, without the extension
|
2011-07-01 23:02:14 +00:00
|
|
|
strcpy(_sprite->_file, fname);
|
|
|
|
char *p = strchr(_sprite->_file, '.');
|
2011-06-29 11:17:07 +00:00
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
_sprite->_shpCnt = shpcnt;
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_spareQ->append(_sprite);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::loadScript(const char *fname) {
|
2011-07-20 23:56:40 +00:00
|
|
|
char line[kLineMax];
|
2011-06-13 09:57:24 +00:00
|
|
|
char *SpN;
|
|
|
|
int SpI, SpA, SpX, SpY, SpZ;
|
|
|
|
bool BkG = false;
|
|
|
|
INI_FILE scrf(fname);
|
|
|
|
int lcnt = 0;
|
|
|
|
bool ok = true;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
if (scrf._error)
|
2011-06-13 09:57:24 +00:00
|
|
|
return;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-30 06:30:23 +00:00
|
|
|
while (scrf.read((uint8 *)line) != 0) {
|
2011-06-13 09:57:24 +00:00
|
|
|
char *p;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
lcnt++;
|
2011-06-13 11:07:45 +00:00
|
|
|
if (*line == 0 || *line == '\n' || *line == '.')
|
2011-06-13 09:57:24 +00:00
|
|
|
continue;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
ok = false; // not OK if break
|
|
|
|
// sprite ident number
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((p = strtok(line, " \t\n")) == NULL)
|
2011-06-09 06:20:53 +00:00
|
|
|
break;
|
2011-06-13 09:57:24 +00:00
|
|
|
SpI = atoi(p);
|
|
|
|
// sprite file name
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL)
|
2011-06-09 06:20:53 +00:00
|
|
|
break;
|
2011-06-13 09:57:24 +00:00
|
|
|
// sprite cave
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((p = strtok(NULL, " ,;/\t\n")) == NULL)
|
2011-06-09 06:20:53 +00:00
|
|
|
break;
|
2011-06-13 09:57:24 +00:00
|
|
|
SpA = atoi(p);
|
|
|
|
// sprite column
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((p = strtok(NULL, " ,;/\t\n")) == NULL)
|
2011-06-09 06:20:53 +00:00
|
|
|
break;
|
2011-06-13 09:57:24 +00:00
|
|
|
SpX = atoi(p);
|
|
|
|
// sprite row
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((p = strtok(NULL, " ,;/\t\n")) == NULL)
|
2011-06-09 06:20:53 +00:00
|
|
|
break;
|
2011-06-13 09:57:24 +00:00
|
|
|
SpY = atoi(p);
|
|
|
|
// sprite Z pos
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((p = strtok(NULL, " ,;/\t\n")) == NULL)
|
2011-06-09 06:20:53 +00:00
|
|
|
break;
|
2011-06-13 09:57:24 +00:00
|
|
|
SpZ = atoi(p);
|
|
|
|
// sprite life
|
2011-06-13 11:07:45 +00:00
|
|
|
if ((p = strtok(NULL, " ,;/\t\n")) == NULL)
|
2011-06-13 09:57:24 +00:00
|
|
|
break;
|
|
|
|
BkG = atoi(p) == 0;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-13 09:57:24 +00:00
|
|
|
ok = true; // no break: OK
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
_sprite = NULL;
|
2011-07-01 06:37:40 +00:00
|
|
|
loadSprite(SpN, SpI, SpA, SpX, SpY, SpZ);
|
2011-06-28 22:35:21 +00:00
|
|
|
if (_sprite && BkG)
|
2011-06-29 14:13:17 +00:00
|
|
|
_sprite->_flags._back = true;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
if (! ok)
|
2011-07-02 18:25:39 +00:00
|
|
|
error("Bad INI line %d [%s]", lcnt, fname);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-02 08:38:25 +00:00
|
|
|
#define GAME_FRAME_DELAY (1000 / 50)
|
2011-07-16 12:28:49 +00:00
|
|
|
#define GAME_TICK_DELAY (1000 / 62)
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::mainLoop() {
|
2011-07-03 09:28:22 +00:00
|
|
|
sayDebug();
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-06-26 23:03:47 +00:00
|
|
|
if (_isDemo) {
|
2011-06-29 07:57:16 +00:00
|
|
|
// static uint32 tc = 0;
|
2011-07-03 09:28:22 +00:00
|
|
|
if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ _talk == NULL && _snail->idle()) {
|
|
|
|
if (_text->getText(_demoText)) {
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnSound, -1, 4, NULL); // drumla
|
|
|
|
_snail->addCom(kSnInf, -1, _demoText, NULL);
|
|
|
|
_snail->addCom(kSnLabel, -1, -1, NULL);
|
2011-07-03 09:28:22 +00:00
|
|
|
if (_text->getText(++_demoText) == NULL)
|
2011-07-22 09:54:46 +00:00
|
|
|
_demoText = kDemo + 1;
|
2011-06-26 23:03:47 +00:00
|
|
|
}
|
|
|
|
//FIXME: tc = TimerCount;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->show();
|
2011-07-02 16:20:41 +00:00
|
|
|
_snail_->runCom();
|
|
|
|
_snail->runCom();
|
2011-06-29 11:17:07 +00:00
|
|
|
|
2011-07-16 12:28:49 +00:00
|
|
|
// Handle a delay between game frames
|
|
|
|
handleFrame();
|
|
|
|
|
|
|
|
// Handle any pending events
|
|
|
|
_eventManager->poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGEEngine::handleFrame() {
|
2011-07-02 08:38:25 +00:00
|
|
|
// Game frame delay
|
|
|
|
uint32 millis = g_system->getMillis();
|
|
|
|
while (!_eventManager->_quitFlag && (millis < (_lastFrame + GAME_FRAME_DELAY))) {
|
|
|
|
// Handle any pending events
|
|
|
|
_eventManager->poll();
|
|
|
|
|
2011-07-16 12:28:49 +00:00
|
|
|
if (millis >= (_lastTick + GAME_TICK_DELAY)) {
|
|
|
|
// Dispatch the tick to any active objects
|
|
|
|
tick();
|
|
|
|
_lastTick = millis;
|
|
|
|
}
|
|
|
|
|
2011-07-02 08:38:25 +00:00
|
|
|
// Slight delay
|
|
|
|
g_system->delayMillis(10);
|
|
|
|
millis = g_system->getMillis();
|
|
|
|
}
|
|
|
|
_lastFrame = millis;
|
2011-07-03 10:20:01 +00:00
|
|
|
|
2011-07-16 12:28:49 +00:00
|
|
|
if (millis >= (_lastTick + GAME_TICK_DELAY)) {
|
|
|
|
// Dispatch the tick to any active objects
|
|
|
|
tick();
|
|
|
|
_lastTick = millis;
|
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 10:20:01 +00:00
|
|
|
void CGEEngine::tick() {
|
2011-07-03 14:22:26 +00:00
|
|
|
for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) {
|
2011-07-03 10:20:01 +00:00
|
|
|
if (spr->_time) {
|
|
|
|
if (!spr->_flags._hide) {
|
|
|
|
if (--spr->_time == 0)
|
|
|
|
spr->tick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::loadUser() {
|
2011-06-13 09:57:24 +00:00
|
|
|
// set scene
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_mode == 0) {
|
2011-07-16 08:33:20 +00:00
|
|
|
// user .SVG file found - load it from slot 0
|
|
|
|
loadGame(0, NULL);
|
2011-07-29 08:02:32 +00:00
|
|
|
} else if (_mode == 1) {
|
2011-07-16 11:12:19 +00:00
|
|
|
// Load either initial game state savegame or launcher specified savegame
|
|
|
|
loadGame(_startGameSlot, NULL);
|
2011-07-29 08:02:32 +00:00
|
|
|
} else {
|
2011-07-16 08:33:20 +00:00
|
|
|
error("Creating setup savegames not supported");
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-07-20 23:56:40 +00:00
|
|
|
loadScript(progName(kIn0Ext));
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::runGame() {
|
2011-07-02 08:38:25 +00:00
|
|
|
if (_eventManager->_quitFlag)
|
|
|
|
return;
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
_text->clear();
|
|
|
|
_text->preload(100, 1000);
|
|
|
|
loadHeroXY();
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
_cavLight->_flags._tran = true;
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->append(_cavLight);
|
2011-06-29 14:13:17 +00:00
|
|
|
_cavLight->_flags._hide = true;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-12 22:28:17 +00:00
|
|
|
const Seq pocSeq[] = {
|
|
|
|
{ 0, 0, 0, 0, 20 },
|
2011-06-13 09:57:24 +00:00
|
|
|
{ 1, 2, 0, 0, 4 },
|
|
|
|
{ 2, 3, 0, 0, 4 },
|
|
|
|
{ 3, 4, 0, 0, 16 },
|
|
|
|
{ 2, 5, 0, 0, 4 },
|
|
|
|
{ 1, 6, 0, 0, 4 },
|
|
|
|
{ 0, 1, 0, 0, 16 },
|
|
|
|
};
|
2011-07-12 11:16:23 +00:00
|
|
|
Seq *seq = (Seq *)malloc(7 * sizeof(Seq));
|
|
|
|
Common::copy(pocSeq, pocSeq + 7, seq);
|
|
|
|
_pocLight->setSeq(seq);
|
|
|
|
|
2011-06-29 14:13:17 +00:00
|
|
|
_pocLight->_flags._tran = true;
|
|
|
|
_pocLight->_time = 1;
|
|
|
|
_pocLight->_z = 120;
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->append(_pocLight);
|
2011-07-02 16:20:41 +00:00
|
|
|
selectPocket(-1);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-10 11:07:57 +00:00
|
|
|
_vga->_showQ->append(_mouse);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
|
|
|
// ___________
|
2011-07-01 06:37:40 +00:00
|
|
|
loadUser();
|
2011-06-09 06:20:53 +00:00
|
|
|
// ~~~~~~~~~~~
|
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
if ((_sprite = _vga->_spareQ->locate(121)) != NULL)
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSeq, -1, _vga->_mono, _sprite);
|
2011-07-03 14:22:26 +00:00
|
|
|
if ((_sprite = _vga->_spareQ->locate(122)) != NULL)
|
2011-07-02 16:20:41 +00:00
|
|
|
_sprite->step(_music);
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail_->addCom(kSnSeq, -1, _music, _sprite);
|
2011-07-02 16:20:41 +00:00
|
|
|
if (!_music)
|
2011-07-04 06:15:56 +00:00
|
|
|
killMidi();
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
if (_mini && INI_FILE::exist("MINI.SPR")) {
|
2011-07-30 22:52:35 +00:00
|
|
|
_miniShp = new BitmapPtr[2];
|
2011-07-16 05:17:18 +00:00
|
|
|
_miniShp[0] = _miniShp[1] = NULL;
|
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
uint8 *ptr = (uint8 *) &*_mini;
|
2011-06-13 09:57:24 +00:00
|
|
|
if (ptr != NULL) {
|
2011-07-20 23:56:40 +00:00
|
|
|
loadSprite("MINI", -1, 0, kMiniX, kMiniY);
|
2011-07-05 21:13:12 +00:00
|
|
|
expandSprite(_miniCave = _sprite); // NULL is ok
|
2011-06-28 22:35:21 +00:00
|
|
|
if (_miniCave) {
|
2011-07-16 05:17:18 +00:00
|
|
|
_miniCave->_flags._kill = false;
|
2011-06-29 14:13:17 +00:00
|
|
|
_miniCave->_flags._hide = true;
|
2011-07-01 23:02:14 +00:00
|
|
|
_miniCave->moveShapes(ptr);
|
2011-07-03 09:28:22 +00:00
|
|
|
_miniShp[0] = new Bitmap(*_miniCave->shp());
|
|
|
|
_miniShpList = _miniCave->setShapeList(_miniShp);
|
2011-07-04 06:15:56 +00:00
|
|
|
postMiniStep(-1);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
if (_hero) {
|
2011-07-05 21:13:12 +00:00
|
|
|
expandSprite(_hero);
|
2011-07-03 14:22:26 +00:00
|
|
|
_hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y);
|
2011-06-30 06:30:23 +00:00
|
|
|
if (INI_FILE::exist("00SHADOW.SPR")) {
|
2011-07-03 14:22:26 +00:00
|
|
|
loadSprite("00SHADOW", -1, 0, _hero->_x + 14, _hero->_y + 51);
|
2011-07-12 11:53:07 +00:00
|
|
|
delete _shadow;
|
2011-06-28 22:35:21 +00:00
|
|
|
if ((_shadow = _sprite) != NULL) {
|
|
|
|
_shadow->_ref = 2;
|
2011-06-29 14:13:17 +00:00
|
|
|
_shadow->_flags._tran = true;
|
2011-07-13 09:18:23 +00:00
|
|
|
_shadow->_flags._kill = false;
|
2011-07-03 14:22:26 +00:00
|
|
|
_hero->_flags._shad = true;
|
|
|
|
_vga->_showQ->insert(_vga->_spareQ->remove(_shadow), _hero);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-20 23:56:40 +00:00
|
|
|
_infoLine->gotoxy(kInfoX, kInfoY);
|
2011-07-03 09:28:22 +00:00
|
|
|
_infoLine->_flags._tran = true;
|
|
|
|
_infoLine->update(NULL);
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(_infoLine);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
_debugLine->_z = 126;
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(_debugLine);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
_horzLine->_y = kMapTop - (kMapTop > 0);
|
2011-06-29 14:13:17 +00:00
|
|
|
_horzLine->_z = 126;
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->insert(_horzLine);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-20 23:56:40 +00:00
|
|
|
_mouse->_busy = _vga->_spareQ->locate(kBusyRef);
|
2011-07-08 06:21:35 +00:00
|
|
|
if (_mouse->_busy)
|
|
|
|
expandSprite(_mouse->_busy);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-04 06:15:56 +00:00
|
|
|
_startupMode = 0;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnLevel, -1, _oldLev, &_cavLight);
|
2011-07-30 22:52:35 +00:00
|
|
|
_cavLight->gotoxy(CAVE_X + ((_now - 1) % _caveNx) * _caveDx + CAVE_SX,
|
|
|
|
CAVE_Y + ((_now - 1) / _caveNx) * _caveDy + CAVE_SY);
|
2011-07-01 06:37:40 +00:00
|
|
|
caveUp();
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
_keyboard->setClient(_sys);
|
2011-06-13 09:57:24 +00:00
|
|
|
// main loop
|
2011-07-03 09:28:22 +00:00
|
|
|
while (!_finis && !_eventManager->_quitFlag) {
|
2011-07-12 22:28:17 +00:00
|
|
|
if (_finis)
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom2(kSnExec, -1, 0, kQGame);
|
2011-07-01 06:37:40 +00:00
|
|
|
mainLoop();
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-02 06:46:31 +00:00
|
|
|
_keyboard->setClient(NULL);
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnClear, -1, 0, NULL);
|
|
|
|
_snail_->addCom(kSnClear, -1, 0, NULL);
|
2011-07-08 06:21:35 +00:00
|
|
|
_mouse->off();
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->clear();
|
|
|
|
_vga->_spareQ->clear();
|
|
|
|
_hero = NULL;
|
2011-06-28 22:35:21 +00:00
|
|
|
_shadow = NULL;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
void CGEEngine::movie(const char *ext) {
|
2011-07-02 08:38:25 +00:00
|
|
|
if (_eventManager->_quitFlag)
|
|
|
|
return;
|
|
|
|
|
2011-07-01 23:02:14 +00:00
|
|
|
const char *fn = progName(ext);
|
2011-06-30 06:30:23 +00:00
|
|
|
if (INI_FILE::exist(fn)) {
|
2011-07-01 06:37:40 +00:00
|
|
|
loadScript(fn);
|
2011-07-05 21:13:12 +00:00
|
|
|
expandSprite(_vga->_spareQ->locate(999));
|
2011-07-13 06:44:58 +00:00
|
|
|
feedSnail(_vga->_showQ->locate(999), kTake);
|
2011-07-12 12:44:04 +00:00
|
|
|
_vga->_showQ->append(_mouse);
|
2011-07-03 14:22:26 +00:00
|
|
|
_keyboard->setClient(_sys);
|
2011-07-02 16:20:41 +00:00
|
|
|
while (!_snail->idle() && !_eventManager->_quitFlag)
|
2011-07-01 06:37:40 +00:00
|
|
|
mainLoop();
|
2011-06-22 06:11:18 +00:00
|
|
|
|
2011-07-02 06:46:31 +00:00
|
|
|
_keyboard->setClient(NULL);
|
2011-07-23 12:31:39 +00:00
|
|
|
_snail->addCom(kSnClear, -1, 0, NULL);
|
|
|
|
_snail_->addCom(kSnClear, -1, 0, NULL);
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->clear();
|
|
|
|
_vga->_spareQ->clear();
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-01 06:37:40 +00:00
|
|
|
bool CGEEngine::showTitle(const char *name) {
|
2011-07-02 08:38:25 +00:00
|
|
|
if (_eventManager->_quitFlag)
|
|
|
|
return false;
|
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
Bitmap::_pal = Vga::_sysPal;
|
2011-07-30 22:52:35 +00:00
|
|
|
BitmapPtr *LB = new BitmapPtr[2];
|
2011-07-10 04:51:22 +00:00
|
|
|
LB[0] = new Bitmap(name, true);
|
|
|
|
LB[1] = NULL;
|
2011-06-30 06:30:23 +00:00
|
|
|
Bitmap::_pal = NULL;
|
2011-07-30 22:52:35 +00:00
|
|
|
bool userOk = false;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-28 22:35:21 +00:00
|
|
|
Sprite D(this, LB);
|
2011-06-29 14:13:17 +00:00
|
|
|
D._flags._kill = true;
|
|
|
|
D._flags._bDel = true;
|
2011-07-01 23:02:14 +00:00
|
|
|
D.center();
|
|
|
|
D.show(2);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_mode == 2) {
|
2011-07-01 06:37:40 +00:00
|
|
|
inf(SVG0NAME);
|
2011-07-03 09:28:22 +00:00
|
|
|
_talk->show(2);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->sunset();
|
|
|
|
_vga->copyPage(1, 2);
|
|
|
|
_vga->copyPage(0, 1);
|
2011-07-02 16:20:41 +00:00
|
|
|
selectPocket(-1);
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->sunrise(Vga::_sysPal);
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_mode < 2 && !_soundOk) {
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->copyPage(1, 2);
|
|
|
|
_vga->copyPage(0, 1);
|
|
|
|
_vga->_showQ->append(_mouse);
|
2011-07-08 06:21:35 +00:00
|
|
|
_mouse->on();
|
2011-07-18 19:47:57 +00:00
|
|
|
for (; !_snail->idle() || Vmenu::_addr;) {
|
2011-07-01 06:37:40 +00:00
|
|
|
mainLoop();
|
2011-07-02 08:38:25 +00:00
|
|
|
if (_eventManager->_quitFlag)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-08 06:21:35 +00:00
|
|
|
_mouse->off();
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->clear();
|
|
|
|
_vga->copyPage(0, 2);
|
2011-07-29 08:02:32 +00:00
|
|
|
_soundOk = 2;
|
2011-07-02 16:20:41 +00:00
|
|
|
if (_music)
|
2011-07-04 06:15:56 +00:00
|
|
|
loadMidi(0);
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_mode < 2) {
|
2011-06-26 23:03:47 +00:00
|
|
|
if (_isDemo) {
|
2011-07-20 23:56:40 +00:00
|
|
|
strcpy(_usrFnam, progName(kSvgExt));
|
2011-07-30 22:52:35 +00:00
|
|
|
userOk = true;
|
2011-06-26 23:03:47 +00:00
|
|
|
} else {
|
2011-06-13 09:57:24 +00:00
|
|
|
#ifndef EVA
|
2011-07-28 09:08:56 +00:00
|
|
|
// At this point the game originally set the protection variables
|
|
|
|
// used by the copy protection check
|
2011-07-01 06:37:40 +00:00
|
|
|
movie("X00"); // paylist
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->copyPage(1, 2);
|
|
|
|
_vga->copyPage(0, 1);
|
|
|
|
_vga->_showQ->append(_mouse);
|
2011-06-26 23:03:47 +00:00
|
|
|
//Mouse.On();
|
2011-07-16 08:33:20 +00:00
|
|
|
|
|
|
|
// For ScummVM, skip prompting for name if a savegame in slot 0 already exists
|
2011-07-16 11:12:19 +00:00
|
|
|
if ((_startGameSlot == -1) && savegameExists(0)) {
|
2011-07-16 08:33:20 +00:00
|
|
|
strcpy(_usrFnam, "User");
|
2011-07-30 22:52:35 +00:00
|
|
|
userOk = true;
|
2011-07-16 08:33:20 +00:00
|
|
|
} else {
|
|
|
|
for (takeName(); GetText::_ptr;) {
|
|
|
|
mainLoop();
|
|
|
|
if (_eventManager->_quitFlag)
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-01 07:53:15 +00:00
|
|
|
if (_keyboard->lastKey() == Enter && *_usrFnam)
|
2011-07-30 22:52:35 +00:00
|
|
|
userOk = true;
|
2011-07-16 08:33:20 +00:00
|
|
|
}
|
2011-06-26 23:03:47 +00:00
|
|
|
//Mouse.Off();
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->_showQ->clear();
|
|
|
|
_vga->copyPage(0, 2);
|
2011-06-13 09:57:24 +00:00
|
|
|
#endif
|
2011-06-26 23:03:47 +00:00
|
|
|
}
|
|
|
|
|
2011-07-30 22:52:35 +00:00
|
|
|
if (userOk && _mode == 0) {
|
2011-07-16 08:33:20 +00:00
|
|
|
if (savegameExists(0)) {
|
|
|
|
// Load the savegame
|
|
|
|
loadGame(0, NULL, true); // only system vars
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->setColors(Vga::_sysPal, 64);
|
|
|
|
_vga->update();
|
2011-07-05 21:13:12 +00:00
|
|
|
if (_flag[3]) { //flag FINIS
|
2011-07-29 08:02:32 +00:00
|
|
|
_mode++;
|
2011-07-05 21:13:12 +00:00
|
|
|
_flag[3] = false;
|
2011-06-13 09:57:24 +00:00
|
|
|
}
|
2011-06-13 11:07:45 +00:00
|
|
|
} else
|
2011-07-29 08:02:32 +00:00
|
|
|
_mode++;
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_mode < 2)
|
2011-07-01 06:37:40 +00:00
|
|
|
movie("X01"); // wink
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-03 14:22:26 +00:00
|
|
|
_vga->copyPage(0, 2);
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-06-26 23:03:47 +00:00
|
|
|
if (_isDemo)
|
|
|
|
return true;
|
|
|
|
else
|
2011-07-30 22:52:35 +00:00
|
|
|
return (_mode == 2 || userOk);
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-05 21:13:12 +00:00
|
|
|
void CGEEngine::cge_main() {
|
2011-06-13 09:57:24 +00:00
|
|
|
uint16 intStack[STACK_SIZ / 2];
|
2011-07-03 09:28:22 +00:00
|
|
|
_intStackPtr = intStack;
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-02 16:20:41 +00:00
|
|
|
memset(_barriers, 0xFF, sizeof(_barriers));
|
2011-06-09 06:20:53 +00:00
|
|
|
|
2011-07-08 06:21:35 +00:00
|
|
|
if (!_mouse->_exist)
|
2011-07-03 09:28:22 +00:00
|
|
|
error("%s", _text->getText(NO_MOUSE_TEXT));
|
2011-06-28 22:35:21 +00:00
|
|
|
|
2011-06-30 06:30:23 +00:00
|
|
|
if (!SVG0FILE::exist(SVG0NAME))
|
2011-07-29 08:02:32 +00:00
|
|
|
_mode = 2;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-03 09:28:22 +00:00
|
|
|
_debugLine->_flags._hide = true;
|
2011-06-29 14:13:17 +00:00
|
|
|
_horzLine->_flags._hide = true;
|
2011-06-13 09:57:24 +00:00
|
|
|
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_music && _soundOk)
|
2011-07-04 06:15:56 +00:00
|
|
|
loadMidi(0);
|
2011-07-02 08:38:25 +00:00
|
|
|
|
2011-07-16 11:12:19 +00:00
|
|
|
if (_startGameSlot != -1) {
|
|
|
|
// Starting up a savegame from the launcher
|
2011-07-29 08:02:32 +00:00
|
|
|
_mode++;
|
2011-07-01 06:37:40 +00:00
|
|
|
runGame();
|
2011-07-16 11:12:19 +00:00
|
|
|
|
2011-07-04 06:15:56 +00:00
|
|
|
_startupMode = 2;
|
2011-07-05 21:13:12 +00:00
|
|
|
if (_flag[3]) // Flag FINIS
|
2011-07-01 06:37:40 +00:00
|
|
|
movie("X03");
|
2011-07-16 11:12:19 +00:00
|
|
|
} else {
|
2011-07-29 08:02:32 +00:00
|
|
|
if (_mode < 2)
|
2011-07-20 23:56:40 +00:00
|
|
|
movie(kLgoExt);
|
2011-07-16 11:12:19 +00:00
|
|
|
|
|
|
|
if (showTitle("WELCOME")) {
|
2011-07-29 08:02:32 +00:00
|
|
|
if ((!_isDemo) && (_mode == 1))
|
2011-07-16 11:12:19 +00:00
|
|
|
movie("X02"); // intro
|
|
|
|
runGame();
|
|
|
|
_startupMode = 2;
|
|
|
|
if (_flag[3]) // Flag FINIS
|
|
|
|
movie("X03");
|
|
|
|
} else
|
|
|
|
_vga->sunset();
|
|
|
|
}
|
2011-06-09 06:20:53 +00:00
|
|
|
}
|
2011-06-10 20:57:09 +00:00
|
|
|
|
|
|
|
} // End of namespace CGE
|