2007-05-30 21:56:52 +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.
|
2005-04-05 15:53:16 +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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-04-05 15:53:16 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2005-04-09 19:19:54 +00:00
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-04-05 15:53:16 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-03-29 15:59:37 +00:00
|
|
|
|
|
|
|
#include "common/endian.h"
|
2010-10-15 13:54:23 +00:00
|
|
|
#include "common/str.h"
|
2006-03-29 15:59:37 +00:00
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/gob.h"
|
|
|
|
#include "gob/game.h"
|
2007-03-20 14:51:57 +00:00
|
|
|
#include "gob/global.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/dataio.h"
|
2009-06-25 10:55:01 +00:00
|
|
|
#include "gob/variables.h"
|
2009-06-22 10:13:37 +00:00
|
|
|
#include "gob/script.h"
|
2009-06-24 21:49:37 +00:00
|
|
|
#include "gob/resources.h"
|
2009-07-05 11:27:54 +00:00
|
|
|
#include "gob/hotspots.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/inter.h"
|
|
|
|
#include "gob/draw.h"
|
|
|
|
#include "gob/mult.h"
|
2009-07-05 11:29:30 +00:00
|
|
|
#include "gob/scenery.h"
|
2008-12-03 22:14:47 +00:00
|
|
|
#include "gob/videoplayer.h"
|
2008-05-08 00:47:23 +00:00
|
|
|
#include "gob/sound/sound.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
Environments::Environments(GobEngine *vm) : _vm(vm) {
|
|
|
|
for (uint i = 0; i < kEnvironmentCount; i++) {
|
|
|
|
Environment &e = _environments[i];
|
2011-01-27 13:27:58 +00:00
|
|
|
Media &m = _media[i];
|
2009-06-25 15:29:19 +00:00
|
|
|
|
|
|
|
e.cursorHotspotX = 0;
|
|
|
|
e.cursorHotspotY = 0;
|
|
|
|
e.variables = 0;
|
|
|
|
e.script = 0;
|
|
|
|
e.resources = 0;
|
2011-01-27 13:27:58 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < 17; j++)
|
|
|
|
m.fonts[j] = 0;
|
2009-06-25 15:29:19 +00:00
|
|
|
}
|
2009-06-25 10:55:01 +00:00
|
|
|
}
|
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
Environments::~Environments() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Environments::clear() {
|
|
|
|
// Deleting unique variables, script and resources
|
|
|
|
|
|
|
|
for (uint i = 0; i < kEnvironmentCount; i++) {
|
|
|
|
if (_environments[i].variables == _vm->_inter->_variables)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!has(_environments[i].variables, i + 1))
|
|
|
|
delete _environments[i].variables;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint i = 0; i < kEnvironmentCount; i++) {
|
|
|
|
if (_environments[i].script == _vm->_game->_script)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!has(_environments[i].script, i + 1))
|
|
|
|
delete _environments[i].script;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint i = 0; i < kEnvironmentCount; i++) {
|
|
|
|
if (_environments[i].resources == _vm->_game->_resources)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!has(_environments[i].resources, i + 1))
|
|
|
|
delete _environments[i].resources;
|
|
|
|
}
|
2011-01-27 13:27:58 +00:00
|
|
|
|
|
|
|
for (uint i = 0; i < kEnvironmentCount; i++)
|
|
|
|
clearMedia(i);
|
2009-06-25 10:55:01 +00:00
|
|
|
}
|
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
void Environments::set(uint8 env) {
|
|
|
|
if (env >= kEnvironmentCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Environment &e = _environments[env];
|
|
|
|
|
|
|
|
// If it already has a unique script or resource assigned, delete them
|
|
|
|
if ((e.script != _vm->_game->_script) && !has(e.script, 0, env))
|
|
|
|
delete e.script;
|
|
|
|
if ((e.resources != _vm->_game->_resources) && !has(e.resources, 0, env))
|
|
|
|
delete e.resources;
|
|
|
|
|
|
|
|
e.cursorHotspotX = _vm->_draw->_cursorHotspotXVar;
|
|
|
|
e.cursorHotspotY = _vm->_draw->_cursorHotspotYVar;
|
|
|
|
e.script = _vm->_game->_script;
|
|
|
|
e.resources = _vm->_game->_resources;
|
|
|
|
e.variables = _vm->_inter->_variables;
|
2011-01-29 22:45:15 +00:00
|
|
|
e.totFile = _vm->_game->_curTotFile;
|
2009-06-25 10:55:01 +00:00
|
|
|
}
|
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
void Environments::get(uint8 env) const {
|
|
|
|
if (env >= kEnvironmentCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const Environment &e = _environments[env];
|
|
|
|
|
|
|
|
_vm->_draw->_cursorHotspotXVar = e.cursorHotspotX;
|
|
|
|
_vm->_draw->_cursorHotspotYVar = e.cursorHotspotY;
|
|
|
|
_vm->_game->_script = e.script;
|
|
|
|
_vm->_game->_resources = e.resources;
|
|
|
|
_vm->_inter->_variables = e.variables;
|
2011-01-29 22:45:15 +00:00
|
|
|
_vm->_game->_curTotFile = e.totFile;
|
2009-06-25 10:55:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
const Common::String &Environments::getTotFile(uint8 env) const {
|
|
|
|
assert(env < kEnvironmentCount);
|
2009-06-25 15:29:19 +00:00
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
return _environments[env].totFile;
|
2009-06-25 15:29:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Environments::has(Variables *variables, uint8 startEnv, int16 except) const {
|
|
|
|
for (uint i = startEnv; i < kEnvironmentCount; i++) {
|
|
|
|
if ((except >= 0) && (((uint16) except) == i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (_environments[i].variables == variables)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Environments::has(Script *script, uint8 startEnv, int16 except) const {
|
|
|
|
for (uint i = startEnv; i < kEnvironmentCount; i++) {
|
|
|
|
if ((except >= 0) && (((uint16) except) == i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (_environments[i].script == script)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Environments::has(Resources *resources, uint8 startEnv, int16 except) const {
|
|
|
|
for (uint i = startEnv; i < kEnvironmentCount; i++) {
|
|
|
|
if ((except >= 0) && (((uint16) except) == i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (_environments[i].resources == resources)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-06-25 10:55:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-27 13:27:58 +00:00
|
|
|
bool Environments::clearMedia(uint8 env) {
|
|
|
|
if (env >= kEnvironmentCount)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Media &m = _media[env];
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
m.sprites[i].reset();
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
m.sounds[i].free();
|
|
|
|
|
|
|
|
for (int i = 0; i < 17; i++) {
|
|
|
|
delete m.fonts[i];
|
|
|
|
m.fonts[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Environments::setMedia(uint8 env) {
|
|
|
|
if (env >= kEnvironmentCount)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
clearMedia(env);
|
|
|
|
|
|
|
|
Media &m = _media[env];
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
m.sprites[i] = _vm->_draw->_spritesArray[i];
|
|
|
|
_vm->_draw->_spritesArray[i].reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
SoundDesc *sound = _vm->_sound->sampleGetBySlot(i);
|
|
|
|
if (sound)
|
|
|
|
m.sounds[i].swap(*sound);
|
|
|
|
}
|
|
|
|
|
|
|
|
int n = MIN(Draw::kFontCount, 17);
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
m.fonts[i] = _vm->_draw->_fonts[i];
|
|
|
|
_vm->_draw->_fonts[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Environments::getMedia(uint8 env) {
|
|
|
|
if (env >= kEnvironmentCount)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Media &m = _media[env];
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
_vm->_draw->_spritesArray[i] = m.sprites[i];
|
|
|
|
m.sprites[i].reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
SoundDesc *sound = _vm->_sound->sampleGetBySlot(i);
|
|
|
|
if (sound)
|
|
|
|
m.sounds[i].swap(*sound);
|
|
|
|
m.sounds[i].free();
|
|
|
|
}
|
|
|
|
|
|
|
|
int n = MIN(Draw::kFontCount, 17);
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
delete _vm->_draw->_fonts[i];
|
|
|
|
_vm->_draw->_fonts[i] = m.fonts[i];
|
|
|
|
m.fonts[i]= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-25 10:55:01 +00:00
|
|
|
|
2011-01-29 22:50:41 +00:00
|
|
|
TotFunctions::TotFunctions(GobEngine *vm) : _vm(vm) {
|
|
|
|
for (uint8 i = 0; i < kTotCount; i++) {
|
|
|
|
_tots[i].script = 0;
|
|
|
|
_tots[i].resources = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TotFunctions::~TotFunctions() {
|
|
|
|
for (uint8 i = 0; i < kTotCount; i++)
|
|
|
|
freeTot(_tots[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TotFunctions::loadTot(Tot &tot, const Common::String &file) {
|
|
|
|
tot.script = new Script(_vm);
|
|
|
|
tot.resources = new Resources(_vm);
|
|
|
|
|
|
|
|
if (!tot.script->load(file) || !tot.resources->load(file)) {
|
|
|
|
freeTot(tot);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TotFunctions::freeTot(Tot &tot) {
|
|
|
|
delete tot.script;
|
|
|
|
delete tot.resources;
|
|
|
|
|
|
|
|
tot.script = 0;
|
|
|
|
tot.resources = 0;
|
|
|
|
|
|
|
|
tot.file.clear();
|
|
|
|
tot.functions.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TotFunctions::loadIDE(Tot &tot) {
|
|
|
|
// Mapping file of function names -> function numbers/offsets
|
|
|
|
Common::String ideFile = Util::setExtension(tot.file, ".IDE");
|
|
|
|
Common::SeekableReadStream *ide = _vm->_dataIO->getFile(ideFile);
|
|
|
|
if (!ide)
|
|
|
|
// No mapping file => No named functions
|
|
|
|
return true;
|
|
|
|
|
|
|
|
char buffer[17];
|
|
|
|
|
|
|
|
uint32 count = ide->readUint16LE();
|
|
|
|
for (uint32 i = 0; i < count; i++) {
|
|
|
|
Function function;
|
|
|
|
|
|
|
|
function.type = ide->readByte();
|
|
|
|
|
|
|
|
ide->read(buffer, 17);
|
|
|
|
buffer[16] = '\0';
|
|
|
|
|
|
|
|
function.name = buffer;
|
|
|
|
|
|
|
|
ide->skip(2); // Unknown;
|
|
|
|
function.offset = ide->readUint16LE();
|
|
|
|
ide->skip(2); // Unknown;
|
|
|
|
|
|
|
|
if ((function.type != 0x47) && (function.type != 0x67))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tot.script->seek(function.offset);
|
|
|
|
|
|
|
|
if (tot.script->readByte() != 1) {
|
|
|
|
warning("TotFunctions::loadIDE(): IDE corrupt");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(5, kDebugGameFlow, "Function 0x%02X: \"%s\"", function.type,
|
|
|
|
function.name.c_str());
|
|
|
|
tot.functions.push_back(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
tot.script->seek(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TotFunctions::find(const Common::String &totFile) const {
|
|
|
|
for (int i = 0; i < kTotCount; i++)
|
|
|
|
if (_tots[i].file.equalsIgnoreCase(totFile))
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TotFunctions::findFree() const {
|
|
|
|
for (int i = 0; i < kTotCount; i++)
|
|
|
|
if (_tots[i].file.empty())
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TotFunctions::load(const Common::String &totFile) {
|
|
|
|
if (find(totFile) >= 0) {
|
|
|
|
warning("TotFunctions::load(): \"%s\" already loaded", totFile.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = findFree();
|
|
|
|
if (index < 0) {
|
|
|
|
warning("TotFunctions::load(): No free space for \"%s\"", totFile.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tot &tot = _tots[index];
|
|
|
|
if (!loadTot(tot, totFile))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tot.file = totFile;
|
|
|
|
|
|
|
|
if (!loadIDE(tot)) {
|
|
|
|
freeTot(tot);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TotFunctions::unload(const Common::String &totFile) {
|
|
|
|
int index = find(totFile);
|
|
|
|
if (index < 0) {
|
|
|
|
warning("TotFunctions::unload(): \"%s\" not loaded", totFile.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tot &tot = _tots[index];
|
|
|
|
|
|
|
|
if (_vm->_game->_script == tot.script)
|
|
|
|
_vm->_game->_script = 0;
|
|
|
|
if (_vm->_game->_resources == tot.resources)
|
|
|
|
_vm->_game->_resources = 0;
|
|
|
|
|
|
|
|
freeTot(tot);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TotFunctions::call(const Common::String &totFile,
|
|
|
|
const Common::String &function) const {
|
|
|
|
|
|
|
|
int index = find(totFile);
|
|
|
|
if (index < 0) {
|
|
|
|
warning("TotFunctions::call(): No such TOT \"%s\"", totFile.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Tot &tot = _tots[index];
|
|
|
|
|
|
|
|
uint16 offset = 0;
|
|
|
|
Common::List<Function>::const_iterator it;
|
|
|
|
for (it = tot.functions.begin(); it != tot.functions.end(); ++it) {
|
|
|
|
if (it->name.equalsIgnoreCase(function)) {
|
|
|
|
offset = it->offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset == 0) {
|
|
|
|
warning("TotFunctions::call(): No such function \"%s\" in \"%s\"",
|
|
|
|
function.c_str(), totFile.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return call(tot, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TotFunctions::call(const Common::String &totFile, uint16 offset) const {
|
|
|
|
int index = find(totFile);
|
|
|
|
if (index < 0) {
|
|
|
|
warning("TotFunctions::call(): No such TOT \"%s\"", totFile.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return call(_tots[index], offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TotFunctions::call(const Tot &tot, uint16 offset) const {
|
|
|
|
Script *script = _vm->_game->_script;
|
|
|
|
Resources *resources = _vm->_game->_resources;
|
|
|
|
Common::String curtotFile = _vm->_game->_curTotFile;
|
|
|
|
|
|
|
|
_vm->_game->_script = tot.script;
|
|
|
|
_vm->_game->_resources = tot.resources;
|
|
|
|
_vm->_game->_curTotFile = tot.file;
|
|
|
|
|
|
|
|
_vm->_game->playTot(offset);
|
|
|
|
|
|
|
|
_vm->_game->_script = script;
|
|
|
|
_vm->_game->_resources = resources;
|
|
|
|
_vm->_game->_curTotFile = curtotFile;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Game::Game(GobEngine *vm) : _vm(vm), _environments(_vm), _totFunctions(_vm) {
|
2007-03-20 14:51:57 +00:00
|
|
|
_captureCount = 0;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_startTimeKey = 0;
|
2009-07-05 11:26:23 +00:00
|
|
|
_mouseButtons = kMouseButtonsNone;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_handleMouse = 0;
|
|
|
|
_forceHandleMouse = 0;
|
2007-04-16 05:04:41 +00:00
|
|
|
_noScroll = true;
|
2007-05-30 10:20:21 +00:00
|
|
|
_preventScroll = false;
|
2009-08-08 21:43:07 +00:00
|
|
|
|
|
|
|
_wantScroll = false;
|
|
|
|
_wantScrollX = 0;
|
|
|
|
_wantScrollY = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_tempStr[0] = 0;
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2009-06-25 10:55:01 +00:00
|
|
|
_numEnvironments = 0;
|
|
|
|
_curEnvironment = 0;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2011-01-29 22:48:44 +00:00
|
|
|
_script = new Script(_vm);
|
|
|
|
_resources = new Resources(_vm);
|
|
|
|
_hotspots = new Hotspots(_vm);
|
2006-01-03 23:14:39 +00:00
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-05-31 08:44:14 +00:00
|
|
|
Game::~Game() {
|
2009-06-22 10:13:37 +00:00
|
|
|
delete _script;
|
2009-06-24 21:49:37 +00:00
|
|
|
delete _resources;
|
2009-07-05 11:27:54 +00:00
|
|
|
delete _hotspots;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-05 11:28:57 +00:00
|
|
|
void Game::prepareStart() {
|
|
|
|
_vm->_global->_pPaletteDesc->unused2 = _vm->_draw->_unusedPalette2;
|
|
|
|
_vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1;
|
|
|
|
_vm->_global->_pPaletteDesc->vgaPal = _vm->_draw->_vgaPalette;
|
|
|
|
|
|
|
|
_vm->_video->setFullPalette(_vm->_global->_pPaletteDesc);
|
|
|
|
|
|
|
|
_vm->_draw->initScreen();
|
2010-09-30 13:02:16 +00:00
|
|
|
_vm->_draw->_frontSurface->fillRect(0, 0,
|
2010-08-21 18:16:04 +00:00
|
|
|
_vm->_video->_surfWidth - 1, _vm->_video->_surfHeight - 1, 1);
|
2009-07-05 11:28:57 +00:00
|
|
|
|
|
|
|
_vm->_util->setMousePos(152, 92);
|
|
|
|
_vm->_draw->_cursorX = _vm->_global->_inter_mouseX = 152;
|
|
|
|
_vm->_draw->_cursorY = _vm->_global->_inter_mouseY = 92;
|
|
|
|
|
|
|
|
_vm->_draw->_invalidatedCount = 0;
|
|
|
|
_vm->_draw->_noInvalidated = true;
|
|
|
|
_vm->_draw->_applyPal = false;
|
|
|
|
_vm->_draw->_paletteCleared = false;
|
|
|
|
_vm->_draw->_cursorWidth = 16;
|
|
|
|
_vm->_draw->_cursorHeight = 16;
|
|
|
|
_vm->_draw->_transparentCursor = 1;
|
|
|
|
|
|
|
|
for (int i = 0; i < 40; i++) {
|
|
|
|
_vm->_draw->_cursorAnimLow[i] = -1;
|
|
|
|
_vm->_draw->_cursorAnimDelays[i] = 0;
|
|
|
|
_vm->_draw->_cursorAnimHigh[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_draw->_renderFlags = 0;
|
|
|
|
_vm->_draw->_backDeltaX = 0;
|
|
|
|
_vm->_draw->_backDeltaY = 0;
|
|
|
|
|
|
|
|
_startTimeKey = _vm->_util->getTimeKey();
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:44:36 +00:00
|
|
|
void Game::playTot(int16 function) {
|
2011-01-29 22:45:15 +00:00
|
|
|
int16 *oldNestLevel = _vm->_inter->_nestLevel;
|
|
|
|
int16 *oldBreakFrom = _vm->_inter->_breakFromLevel;
|
|
|
|
int16 *oldCaptureCounter = _vm->_scenery->_pCaptureCounter;
|
2009-07-05 11:29:30 +00:00
|
|
|
|
|
|
|
_script->push();
|
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
int16 captureCounter = 0;
|
|
|
|
int16 breakFrom;
|
|
|
|
int16 nestLevel;
|
|
|
|
_vm->_inter->_nestLevel = &nestLevel;
|
|
|
|
_vm->_inter->_breakFromLevel = &breakFrom;
|
2010-10-15 13:55:46 +00:00
|
|
|
_vm->_scenery->_pCaptureCounter = &captureCounter;
|
2011-01-29 22:45:15 +00:00
|
|
|
|
|
|
|
Common::String oldTotFile;
|
2009-07-05 11:29:30 +00:00
|
|
|
|
2011-01-29 22:44:36 +00:00
|
|
|
if (function <= 0) {
|
2009-07-05 11:29:30 +00:00
|
|
|
while (!_vm->shouldQuit()) {
|
|
|
|
if (_vm->_inter->_variables)
|
|
|
|
_vm->_draw->animateCursor(4);
|
|
|
|
|
2011-01-29 22:44:36 +00:00
|
|
|
if (function != -1) {
|
2009-07-05 11:29:30 +00:00
|
|
|
_vm->_inter->initControlVars(1);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
_vm->_draw->_fontToSprite[i].sprite = -1;
|
|
|
|
_vm->_draw->_fontToSprite[i].base = -1;
|
|
|
|
_vm->_draw->_fontToSprite[i].width = -1;
|
|
|
|
_vm->_draw->_fontToSprite[i].height = -1;
|
|
|
|
}
|
|
|
|
|
2009-07-21 11:58:58 +00:00
|
|
|
// Gobliiins music stopping
|
|
|
|
if (_vm->getGameType() == kGameTypeGob1) {
|
|
|
|
_vm->_sound->adlibStop();
|
|
|
|
_vm->_sound->cdStop();
|
|
|
|
}
|
|
|
|
|
2009-07-05 11:29:30 +00:00
|
|
|
_vm->_mult->initAll();
|
|
|
|
_vm->_mult->zeroMultData();
|
|
|
|
|
2010-08-08 00:35:18 +00:00
|
|
|
_vm->_draw->_spritesArray[Draw::kFrontSurface] = _vm->_draw->_frontSurface;
|
|
|
|
_vm->_draw->_spritesArray[Draw::kBackSurface ] = _vm->_draw->_backSurface;
|
2009-07-05 11:29:30 +00:00
|
|
|
_vm->_draw->_cursorSpritesBack = _vm->_draw->_cursorSprites;
|
|
|
|
} else
|
|
|
|
_vm->_inter->initControlVars(0);
|
|
|
|
|
|
|
|
_vm->_draw->_cursorHotspotXVar = -1;
|
2011-01-29 22:45:15 +00:00
|
|
|
_totToLoad.clear();
|
2009-07-05 11:29:30 +00:00
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
if ((_curTotFile.empty()) && (!_script->isLoaded()))
|
2009-07-05 11:29:30 +00:00
|
|
|
break;
|
|
|
|
|
2011-01-29 22:44:36 +00:00
|
|
|
if (function == -2) {
|
2010-08-08 00:48:51 +00:00
|
|
|
_vm->_vidPlayer->closeVideo();
|
2011-01-29 22:44:36 +00:00
|
|
|
function = 0;
|
2009-07-05 11:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_script->load(_curTotFile)) {
|
|
|
|
_vm->_draw->blitCursor();
|
|
|
|
_vm->_inter->_terminate = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_resources->load(_curTotFile);
|
|
|
|
|
|
|
|
_vm->_global->_inter_animDataSize = _script->getAnimDataSize();
|
|
|
|
if (!_vm->_inter->_variables)
|
|
|
|
_vm->_inter->allocateVars(_script->getVariablesCount() & 0xFFFF);
|
|
|
|
|
|
|
|
_script->seek(_script->getFunctionOffset(TOTFile::kFunctionStart));
|
|
|
|
|
|
|
|
_vm->_inter->renewTimeInVars();
|
|
|
|
|
2010-10-15 04:37:44 +00:00
|
|
|
if (_vm->_inter->_variables) {
|
|
|
|
WRITE_VAR(13, _vm->_global->_useMouse);
|
|
|
|
WRITE_VAR(14, _vm->_global->_soundFlags);
|
|
|
|
WRITE_VAR(15, _vm->_global->_fakeVideoMode);
|
|
|
|
WRITE_VAR(16, _vm->_global->_language);
|
2011-01-18 11:51:45 +00:00
|
|
|
|
|
|
|
// WORKAROUND: Inca2 seems to depend on that variable to be cleared
|
|
|
|
if (_vm->getGameType() == kGameTypeInca2)
|
|
|
|
WRITE_VAR(59, 0);
|
2010-10-15 04:37:44 +00:00
|
|
|
}
|
2009-07-05 11:29:30 +00:00
|
|
|
|
|
|
|
_vm->_inter->callSub(2);
|
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
if (!_totToLoad.empty())
|
2009-07-05 11:29:30 +00:00
|
|
|
_vm->_inter->_terminate = 0;
|
|
|
|
|
|
|
|
_vm->_draw->blitInvalidated();
|
|
|
|
|
|
|
|
_script->unload();
|
|
|
|
|
|
|
|
_resources->unload();
|
|
|
|
|
2010-10-15 13:55:46 +00:00
|
|
|
for (int i = 0; i < *_vm->_scenery->_pCaptureCounter; i++)
|
|
|
|
capturePop(0);
|
2009-07-05 11:29:30 +00:00
|
|
|
|
2011-01-29 22:44:36 +00:00
|
|
|
if (function != -1) {
|
2009-07-05 11:29:30 +00:00
|
|
|
_vm->_goblin->freeObjects();
|
|
|
|
|
|
|
|
_vm->_sound->blasterStop(0);
|
|
|
|
|
|
|
|
for (int i = 0; i < Sound::kSoundsCount; i++) {
|
|
|
|
SoundDesc *sound = _vm->_sound->sampleGetBySlot(i);
|
|
|
|
|
|
|
|
if (sound &&
|
|
|
|
((sound->getType() == SOUND_SND) || (sound->getType() == SOUND_WAV)))
|
|
|
|
_vm->_sound->sampleFree(sound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-21 18:16:04 +00:00
|
|
|
_vm->_draw->closeAllWin();
|
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
if (_totToLoad.empty())
|
2009-07-05 11:29:30 +00:00
|
|
|
break;
|
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
_curTotFile = _totToLoad;
|
2010-10-15 04:37:44 +00:00
|
|
|
|
2009-07-05 11:29:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_vm->_inter->initControlVars(0);
|
|
|
|
_vm->_scenery->_pCaptureCounter = oldCaptureCounter;
|
2011-01-26 19:02:39 +00:00
|
|
|
|
2011-01-29 22:50:41 +00:00
|
|
|
if (function > 13)
|
|
|
|
_script->seek(function);
|
|
|
|
else
|
2011-01-29 22:44:36 +00:00
|
|
|
_script->seek(_script->getFunctionOffset(function + 1));
|
2009-07-05 11:29:30 +00:00
|
|
|
|
|
|
|
_vm->_inter->callSub(2);
|
|
|
|
|
|
|
|
if (_vm->_inter->_terminate != 0)
|
|
|
|
_vm->_inter->_terminate = 2;
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
_curTotFile = oldTotFile;
|
2009-07-05 11:29:30 +00:00
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
_vm->_inter->_nestLevel = oldNestLevel;
|
|
|
|
_vm->_inter->_breakFromLevel = oldBreakFrom;
|
2009-07-05 11:29:30 +00:00
|
|
|
_vm->_scenery->_pCaptureCounter = oldCaptureCounter;
|
|
|
|
|
|
|
|
_script->pop();
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Game::capturePush(int16 left, int16 top, int16 width, int16 height) {
|
2005-04-05 15:07:40 +00:00
|
|
|
int16 right;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
if (_captureCount == 20)
|
2009-05-31 10:02:16 +00:00
|
|
|
error("Game::capturePush(): Capture stack overflow");
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_captureStack[_captureCount].left = left;
|
|
|
|
_captureStack[_captureCount].top = top;
|
|
|
|
_captureStack[_captureCount].right = left + width;
|
|
|
|
_captureStack[_captureCount].bottom = top + height;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_draw->_spriteTop = top;
|
|
|
|
_vm->_draw->_spriteBottom = height;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
right = left + width - 1;
|
2007-03-20 14:51:57 +00:00
|
|
|
left &= 0xFFF0;
|
|
|
|
right |= 0xF;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2010-08-08 00:35:18 +00:00
|
|
|
_vm->_draw->initSpriteSurf(Draw::kCaptureSurface + _captureCount, right - left + 1, height, 0);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2010-08-08 00:35:18 +00:00
|
|
|
_vm->_draw->_sourceSurface = Draw::kBackSurface;
|
|
|
|
_vm->_draw->_destSurface = Draw::kCaptureSurface + _captureCount;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_draw->_spriteLeft = left;
|
|
|
|
_vm->_draw->_spriteRight = right - left + 1;
|
|
|
|
_vm->_draw->_destSpriteX = 0;
|
|
|
|
_vm->_draw->_destSpriteY = 0;
|
|
|
|
_vm->_draw->_transparency = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_draw->spriteOperation(0);
|
2006-01-07 22:28:54 +00:00
|
|
|
_captureCount++;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Game::capturePop(char doDraw) {
|
2006-01-07 22:28:54 +00:00
|
|
|
if (_captureCount <= 0)
|
2005-04-05 15:07:40 +00:00
|
|
|
return;
|
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_captureCount--;
|
2005-04-05 15:07:40 +00:00
|
|
|
if (doDraw) {
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_draw->_destSpriteX = _captureStack[_captureCount].left;
|
|
|
|
_vm->_draw->_destSpriteY = _captureStack[_captureCount].top;
|
|
|
|
_vm->_draw->_spriteRight =
|
|
|
|
_captureStack[_captureCount].width();
|
|
|
|
_vm->_draw->_spriteBottom =
|
|
|
|
_captureStack[_captureCount].height();
|
|
|
|
|
|
|
|
_vm->_draw->_transparency = 0;
|
2010-08-08 00:35:18 +00:00
|
|
|
_vm->_draw->_sourceSurface = Draw::kCaptureSurface + _captureCount;
|
|
|
|
_vm->_draw->_destSurface = Draw::kBackSurface;
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_draw->_spriteLeft = _vm->_draw->_destSpriteX & 0xF;
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_draw->_spriteTop = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_draw->spriteOperation(0);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
2010-08-08 00:35:18 +00:00
|
|
|
_vm->_draw->freeSprite(Draw::kCaptureSurface + _captureCount);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void Game::freeSoundSlot(int16 slot) {
|
2005-04-05 15:07:40 +00:00
|
|
|
if (slot == -1)
|
2009-06-24 21:49:37 +00:00
|
|
|
slot = _vm->_game->_script->readValExpr();
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2008-05-08 00:47:23 +00:00
|
|
|
_vm->_sound->sampleFree(_vm->_sound->sampleGetBySlot(slot));
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 21:43:07 +00:00
|
|
|
void Game::wantScroll(int16 x, int16 y) {
|
|
|
|
_wantScroll = true;
|
|
|
|
_wantScrollX = x;
|
|
|
|
_wantScrollY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::evaluateScroll() {
|
|
|
|
if (_noScroll || _preventScroll || !_wantScroll)
|
2007-04-13 07:48:26 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-08 21:43:07 +00:00
|
|
|
if ((_vm->_global->_videoMode != 0x14) && (_vm->_global->_videoMode != 0x18))
|
2007-04-13 07:48:26 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-08 21:43:07 +00:00
|
|
|
if ((_wantScrollX == 0) && (_vm->_draw->_scrollOffsetX > 0)) {
|
2007-04-13 07:48:26 +00:00
|
|
|
uint16 off;
|
|
|
|
|
|
|
|
off = MIN(_vm->_draw->_cursorWidth, _vm->_draw->_scrollOffsetX);
|
|
|
|
off = MAX(off / 2, 1);
|
|
|
|
_vm->_draw->_scrollOffsetX -= off;
|
2008-12-04 18:38:55 +00:00
|
|
|
_vm->_video->dirtyRectsAll();
|
2009-08-08 21:43:07 +00:00
|
|
|
} else if ((_wantScrollY == 0) && (_vm->_draw->_scrollOffsetY > 0)) {
|
2007-04-19 13:51:57 +00:00
|
|
|
uint16 off;
|
|
|
|
|
|
|
|
off = MIN(_vm->_draw->_cursorHeight, _vm->_draw->_scrollOffsetY);
|
|
|
|
off = MAX(off / 2, 1);
|
|
|
|
_vm->_draw->_scrollOffsetY -= off;
|
2008-12-04 18:38:55 +00:00
|
|
|
_vm->_video->dirtyRectsAll();
|
2007-04-13 07:48:26 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 21:43:07 +00:00
|
|
|
int16 cursorRight = _wantScrollX + _vm->_draw->_cursorWidth;
|
|
|
|
int16 screenRight = _vm->_draw->_scrollOffsetX + _vm->_width;
|
|
|
|
int16 cursorBottom = _wantScrollY + _vm->_draw->_cursorHeight;
|
2007-07-24 23:24:40 +00:00
|
|
|
int16 screenBottom = _vm->_draw->_scrollOffsetY + _vm->_height;
|
2007-04-13 07:48:26 +00:00
|
|
|
|
2007-07-24 23:24:40 +00:00
|
|
|
if ((cursorRight >= _vm->_width) &&
|
|
|
|
(screenRight < _vm->_video->_surfWidth)) {
|
2007-04-13 07:48:26 +00:00
|
|
|
uint16 off;
|
|
|
|
|
|
|
|
off = MIN(_vm->_draw->_cursorWidth,
|
|
|
|
(int16) (_vm->_video->_surfWidth - screenRight));
|
|
|
|
off = MAX(off / 2, 1);
|
|
|
|
|
|
|
|
_vm->_draw->_scrollOffsetX += off;
|
2008-12-04 18:38:55 +00:00
|
|
|
_vm->_video->dirtyRectsAll();
|
2007-04-13 07:48:26 +00:00
|
|
|
|
2009-08-08 21:43:07 +00:00
|
|
|
_vm->_util->setMousePos(_vm->_width - _vm->_draw->_cursorWidth, _wantScrollY);
|
2007-07-24 23:24:40 +00:00
|
|
|
} else if ((cursorBottom >= (_vm->_height - _vm->_video->_splitHeight2)) &&
|
2007-04-19 13:51:57 +00:00
|
|
|
(screenBottom < _vm->_video->_surfHeight)) {
|
|
|
|
uint16 off;
|
|
|
|
|
|
|
|
off = MIN(_vm->_draw->_cursorHeight,
|
|
|
|
(int16) (_vm->_video->_surfHeight - screenBottom));
|
|
|
|
off = MAX(off / 2, 1);
|
|
|
|
|
|
|
|
_vm->_draw->_scrollOffsetY += off;
|
2008-12-04 18:38:55 +00:00
|
|
|
_vm->_video->dirtyRectsAll();
|
2007-04-19 13:51:57 +00:00
|
|
|
|
2009-08-08 21:43:07 +00:00
|
|
|
_vm->_util->setMousePos(_wantScrollX,
|
|
|
|
_vm->_height - _vm->_video->_splitHeight2 - _vm->_draw->_cursorHeight);
|
2007-04-13 07:48:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_util->setScrollOffset();
|
2009-08-08 21:43:07 +00:00
|
|
|
|
|
|
|
_wantScroll = false;
|
2007-04-13 07:48:26 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
int16 Game::checkKeys(int16 *pMouseX, int16 *pMouseY,
|
2009-07-05 11:26:23 +00:00
|
|
|
MouseButtons *pButtons, char handleMouse) {
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2007-04-13 07:48:26 +00:00
|
|
|
_vm->_util->processInput(true);
|
2007-02-05 14:08:50 +00:00
|
|
|
|
2008-05-28 21:15:11 +00:00
|
|
|
if (_vm->_mult->_multData && _vm->_inter->_variables &&
|
2007-02-05 14:08:50 +00:00
|
|
|
(VAR(58) != 0)) {
|
2007-03-20 14:51:57 +00:00
|
|
|
if (_vm->_mult->_multData->frameStart != (int) VAR(58) - 1)
|
2007-02-05 14:08:50 +00:00
|
|
|
_vm->_mult->_multData->frameStart++;
|
|
|
|
else
|
|
|
|
_vm->_mult->_multData->frameStart = 0;
|
|
|
|
|
|
|
|
_vm->_mult->playMult(_vm->_mult->_multData->frameStart + VAR(57),
|
|
|
|
_vm->_mult->_multData->frameStart + VAR(57), 1, handleMouse);
|
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
if ((_vm->_inter->_soundEndTimeKey != 0) &&
|
|
|
|
(_vm->_util->getTimeKey() >= _vm->_inter->_soundEndTimeKey)) {
|
2008-05-08 00:47:23 +00:00
|
|
|
_vm->_sound->blasterStop(_vm->_inter->_soundStopVal);
|
2007-02-05 14:08:50 +00:00
|
|
|
_vm->_inter->_soundEndTimeKey = 0;
|
|
|
|
}
|
|
|
|
|
2007-07-30 15:53:38 +00:00
|
|
|
if (pMouseX && pMouseY && pButtons) {
|
|
|
|
_vm->_util->getMouseState(pMouseX, pMouseY, pButtons);
|
2007-02-05 14:08:50 +00:00
|
|
|
|
2009-07-05 11:26:23 +00:00
|
|
|
if (*pButtons == kMouseButtonsBoth)
|
|
|
|
*pButtons = kMouseButtonsNone;
|
2007-07-30 15:53:38 +00:00
|
|
|
}
|
2007-02-05 14:08:50 +00:00
|
|
|
|
|
|
|
return _vm->_util->checkKey();
|
|
|
|
}
|
|
|
|
|
2009-07-05 11:29:30 +00:00
|
|
|
void Game::start() {
|
2006-01-03 23:14:39 +00:00
|
|
|
prepareStart();
|
2006-06-29 12:55:57 +00:00
|
|
|
playTot(-2);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-11-20 13:03:30 +00:00
|
|
|
_vm->_draw->closeScreen();
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2011-02-02 16:49:20 +00:00
|
|
|
for (int i = 0; i < Draw::kSpriteCount; i++)
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_draw->freeSprite(i);
|
2009-06-06 20:03:13 +00:00
|
|
|
_vm->_draw->_scummvmCursor.reset();
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:44:36 +00:00
|
|
|
// flagbits: 0 = freeInterVariables, 1 = function -1
|
2011-01-29 22:45:15 +00:00
|
|
|
void Game::totSub(int8 flags, const Common::String &totFile) {
|
2006-04-13 20:56:22 +00:00
|
|
|
int8 curBackupPos;
|
|
|
|
|
2011-01-27 13:26:34 +00:00
|
|
|
if ((flags == 16) || (flags == 17)) {
|
|
|
|
// Prefetch tot data + delete prefetched data
|
|
|
|
return;
|
|
|
|
}
|
2009-07-05 11:29:13 +00:00
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
if (_numEnvironments >= Environments::kEnvironmentCount)
|
2011-01-26 19:02:20 +00:00
|
|
|
error("Game::totSub(): Environments overflow");
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2011-01-29 22:48:44 +00:00
|
|
|
_environments.set(_numEnvironments);
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2011-01-27 13:27:58 +00:00
|
|
|
if (flags == 18) {
|
|
|
|
warning("Backuping media to %d", _numEnvironments);
|
2011-01-29 22:48:44 +00:00
|
|
|
_environments.setMedia(_numEnvironments);
|
2011-01-27 13:27:58 +00:00
|
|
|
}
|
2011-01-27 13:26:34 +00:00
|
|
|
|
2009-06-25 10:55:01 +00:00
|
|
|
curBackupPos = _curEnvironment;
|
|
|
|
_numEnvironments++;
|
|
|
|
_curEnvironment = _numEnvironments;
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2009-06-22 10:13:37 +00:00
|
|
|
_script = new Script(_vm);
|
2009-06-24 21:49:37 +00:00
|
|
|
_resources = new Resources(_vm);
|
2009-07-05 11:29:13 +00:00
|
|
|
|
|
|
|
if (flags & 0x80)
|
2011-01-27 13:26:34 +00:00
|
|
|
warning("Addy Stub: Game::totSub(), flags & 0x80");
|
2009-07-05 11:29:13 +00:00
|
|
|
|
2011-01-27 13:26:34 +00:00
|
|
|
if (flags & 5)
|
2008-05-28 21:15:11 +00:00
|
|
|
_vm->_inter->_variables = 0;
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2011-01-29 22:45:15 +00:00
|
|
|
_curTotFile = totFile + ".TOT";
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
if (_vm->_inter->_terminate != 0) {
|
|
|
|
clearUnusedEnvironment();
|
2006-04-13 20:56:22 +00:00
|
|
|
return;
|
2009-06-25 15:29:19 +00:00
|
|
|
}
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2011-01-27 13:26:34 +00:00
|
|
|
if (!(flags & 0x20))
|
|
|
|
_hotspots->push(0, true);
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2011-01-27 13:26:34 +00:00
|
|
|
if ((flags == 18) || (flags & 0x06))
|
2006-04-13 20:56:22 +00:00
|
|
|
playTot(-1);
|
|
|
|
else
|
|
|
|
playTot(0);
|
|
|
|
|
|
|
|
if (_vm->_inter->_terminate != 2)
|
|
|
|
_vm->_inter->_terminate = 0;
|
|
|
|
|
2011-01-27 13:26:34 +00:00
|
|
|
if (!(flags & 0x20)) {
|
|
|
|
_hotspots->clear();
|
|
|
|
_hotspots->pop();
|
|
|
|
}
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2011-01-27 13:26:34 +00:00
|
|
|
if ((flags & 5) && _vm->_inter->_variables)
|
2008-05-28 21:15:11 +00:00
|
|
|
_vm->_inter->delocateVars();
|
2006-04-13 20:56:22 +00:00
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
clearUnusedEnvironment();
|
|
|
|
|
2009-06-25 10:55:01 +00:00
|
|
|
_numEnvironments--;
|
|
|
|
_curEnvironment = curBackupPos;
|
2011-01-29 22:48:44 +00:00
|
|
|
_environments.get(_numEnvironments);
|
2011-01-27 13:26:34 +00:00
|
|
|
|
2011-01-27 13:27:58 +00:00
|
|
|
if (flags == 18) {
|
|
|
|
warning("Restoring media from %d", _numEnvironments);
|
2011-01-29 22:48:44 +00:00
|
|
|
_environments.getMedia(_numEnvironments);
|
2011-01-27 13:27:58 +00:00
|
|
|
}
|
|
|
|
|
2011-01-27 13:26:34 +00:00
|
|
|
_vm->_global->_inter_animDataSize = _script->getAnimDataSize();
|
2006-04-13 20:56:22 +00:00
|
|
|
}
|
|
|
|
|
2011-01-29 22:44:36 +00:00
|
|
|
void Game::switchTotSub(int16 index, int16 function) {
|
2006-05-11 19:43:30 +00:00
|
|
|
int16 backupedCount;
|
|
|
|
int16 curBackupPos;
|
|
|
|
|
2009-06-25 10:55:01 +00:00
|
|
|
if ((_numEnvironments - index) < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int16 newPos = _curEnvironment - index - ((index >= 0) ? 1 : 0);
|
2009-06-25 15:29:19 +00:00
|
|
|
if (newPos >= Environments::kEnvironmentCount)
|
2006-05-11 19:43:30 +00:00
|
|
|
return;
|
|
|
|
|
2007-05-30 10:20:21 +00:00
|
|
|
// WORKAROUND: Some versions don't make the MOVEMENT menu item unselectable
|
|
|
|
// in the dreamland screen, resulting in a crash when it's clicked.
|
2011-01-29 22:44:36 +00:00
|
|
|
if ((_vm->getGameType() == kGameTypeGob2) && (index == -1) && (function == 7) &&
|
2011-01-29 22:48:44 +00:00
|
|
|
_environments.getTotFile(newPos).equalsIgnoreCase("gob06.tot"))
|
2007-05-30 10:20:21 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-25 10:55:01 +00:00
|
|
|
curBackupPos = _curEnvironment;
|
|
|
|
backupedCount = _numEnvironments;
|
2009-06-25 15:29:19 +00:00
|
|
|
if (_curEnvironment == _numEnvironments)
|
2011-01-29 22:48:44 +00:00
|
|
|
_environments.set(_numEnvironments++);
|
2009-06-25 15:29:19 +00:00
|
|
|
|
2009-06-25 10:55:01 +00:00
|
|
|
_curEnvironment -= index;
|
2006-05-11 19:43:30 +00:00
|
|
|
if (index >= 0)
|
2009-06-25 10:55:01 +00:00
|
|
|
_curEnvironment--;
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
clearUnusedEnvironment();
|
|
|
|
|
2011-01-29 22:48:44 +00:00
|
|
|
_environments.get(_curEnvironment);
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
if (_vm->_inter->_terminate != 0) {
|
|
|
|
clearUnusedEnvironment();
|
2006-05-11 19:43:30 +00:00
|
|
|
return;
|
2009-06-25 15:29:19 +00:00
|
|
|
}
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2009-07-05 11:27:54 +00:00
|
|
|
_hotspots->push(0, true);
|
2011-01-29 22:44:36 +00:00
|
|
|
playTot(function);
|
2006-05-11 19:43:30 +00:00
|
|
|
|
|
|
|
if (_vm->_inter->_terminate != 2)
|
|
|
|
_vm->_inter->_terminate = 0;
|
|
|
|
|
2009-07-05 11:27:54 +00:00
|
|
|
_hotspots->pop();
|
2006-05-11 19:43:30 +00:00
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
clearUnusedEnvironment();
|
|
|
|
|
2009-06-25 10:55:01 +00:00
|
|
|
_curEnvironment = curBackupPos;
|
|
|
|
_numEnvironments = backupedCount;
|
2011-01-29 22:48:44 +00:00
|
|
|
_environments.get(_curEnvironment);
|
2006-04-18 09:59:18 +00:00
|
|
|
}
|
|
|
|
|
2009-06-25 15:29:19 +00:00
|
|
|
void Game::clearUnusedEnvironment() {
|
2011-01-29 22:48:44 +00:00
|
|
|
if (!_environments.has(_script)) {
|
2009-06-25 15:29:19 +00:00
|
|
|
delete _script;
|
|
|
|
_script = 0;
|
|
|
|
}
|
2011-01-29 22:48:44 +00:00
|
|
|
if (!_environments.has(_resources)) {
|
2009-06-25 15:29:19 +00:00
|
|
|
delete _resources;
|
|
|
|
_resources = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 22:50:41 +00:00
|
|
|
bool Game::loadFunctions(const Common::String &tot, uint16 flags) {
|
|
|
|
if ((flags & 0xFFFE) != 0) {
|
|
|
|
warning("Game::loadFunctions(): Unknown flags 0x%04X", flags);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool unload = (flags & 0x1) != 0;
|
|
|
|
|
|
|
|
if (unload) {
|
|
|
|
debugC(4, kDebugGameFlow, "Unloading function for \"%s\"", tot.c_str());
|
|
|
|
return _totFunctions.unload(tot);
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(4, kDebugGameFlow, "Loading function for \"%s\"", tot.c_str());
|
|
|
|
return _totFunctions.load(tot);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Game::callFunction(const Common::String &tot, const Common::String &function,
|
|
|
|
int16 param) {
|
|
|
|
|
|
|
|
if (param != 0) {
|
|
|
|
warning("Game::callFunction(): param != 0 (%d)", param);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(4, kDebugGameFlow, "Calling function \"%s\":\"%s\"",
|
|
|
|
tot.c_str(), function.c_str());
|
|
|
|
|
|
|
|
uint16 offset = atoi(function.c_str());
|
|
|
|
if (offset != 0)
|
|
|
|
return _totFunctions.call(tot, offset);
|
|
|
|
|
|
|
|
if (function.size() > 16)
|
|
|
|
return _totFunctions.call(tot, Common::String(function.c_str(), 16));
|
|
|
|
|
|
|
|
return _totFunctions.call(tot, function);
|
|
|
|
}
|
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
} // End of namespace Gob
|