scummvm/engines/sludge/sludger.cpp

309 lines
8.2 KiB
C++
Raw Normal View History

/* 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.
*
*/
#include "common/config-manager.h"
2017-05-26 19:25:11 +00:00
#include "common/debug.h"
2017-06-05 17:10:47 +00:00
#include "sludge/allfiles.h"
#include "sludge/backdrop.h"
2017-07-19 22:41:13 +00:00
#include "sludge/builtin.h"
2017-06-05 17:10:47 +00:00
#include "sludge/cursors.h"
#include "sludge/event.h"
2017-07-19 22:41:13 +00:00
#include "sludge/fonttext.h"
#include "sludge/freeze.h"
#include "sludge/floor.h"
#include "sludge/fileset.h"
#include "sludge/function.h"
2017-07-19 22:41:13 +00:00
#include "sludge/graphics.h"
#include "sludge/imgloader.h"
#include "sludge/language.h"
#include "sludge/moreio.h"
#include "sludge/newfatal.h"
2017-06-05 17:10:47 +00:00
#include "sludge/objtypes.h"
2017-07-19 22:41:13 +00:00
#include "sludge/people.h"
2017-06-05 17:10:47 +00:00
#include "sludge/region.h"
#include "sludge/savedata.h"
2017-07-19 22:41:13 +00:00
#include "sludge/sludge.h"
#include "sludge/sludger.h"
#include "sludge/sound.h"
2017-12-19 20:24:31 +00:00
#include "sludge/speech.h"
#include "sludge/sprites.h"
#include "sludge/sprbanks.h"
#include "sludge/statusba.h"
2017-06-05 17:10:47 +00:00
#include "sludge/variable.h"
#include "sludge/version.h"
2017-07-19 22:41:13 +00:00
#include "sludge/zbuffer.h"
2017-05-26 19:25:11 +00:00
namespace Sludge {
extern int numBIFNames;
extern Common::String *allBIFNames;
extern int numUserFunc;
extern Common::String *allUserFunc;
int selectedLanguage = 0;
int gameVersion;
FILETIME fileTime;
int numGlobals = 0;
extern Variable *launchResult;
extern Variable *globalVars;
extern VariableStack *noStack;
extern bool allowAnyFilename;
Common::File *openAndVerify(const Common::String &filename, char extra1, char extra2,
2017-05-29 06:02:59 +00:00
const char *er, int &fileVersion) {
Common::File *fp = new Common::File();
if (!fp->open(filename)) {
fatal("Can't open file", filename);
return NULL;
}
bool headerBad = false;
if (fp->readByte() != 'S')
2017-05-29 06:02:59 +00:00
headerBad = true;
if (fp->readByte() != 'L')
2017-05-29 06:02:59 +00:00
headerBad = true;
if (fp->readByte() != 'U')
2017-05-29 06:02:59 +00:00
headerBad = true;
if (fp->readByte() != 'D')
2017-05-29 06:02:59 +00:00
headerBad = true;
if (fp->readByte() != extra1)
2017-05-29 06:02:59 +00:00
headerBad = true;
if (fp->readByte() != extra2)
2017-05-29 06:02:59 +00:00
headerBad = true;
if (headerBad) {
fatal(er, filename);
return NULL;
}
char c;
c = fp->readByte();
2017-08-02 14:35:09 +00:00
while ((c = fp->readByte()))
;
int majVersion = fp->readByte();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "majVersion %i", majVersion);
int minVersion = fp->readByte();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "minVersion %i", minVersion);
fileVersion = majVersion * 256 + minVersion;
Common::String txtVer = "";
if (fileVersion > WHOLE_VERSION) {
txtVer = Common::String::format(ERROR_VERSION_TOO_LOW_2, majVersion, minVersion);
fatal(ERROR_VERSION_TOO_LOW_1, txtVer);
return NULL;
} else if (fileVersion < MINIM_VERSION) {
txtVer = Common::String::format(ERROR_VERSION_TOO_HIGH_2, majVersion, minVersion);
fatal(ERROR_VERSION_TOO_HIGH_1, txtVer);
return NULL;
}
return fp;
}
void initSludge() {
g_sludge->_timer.reset();
g_sludge->_languageMan->init();
g_sludge->_gfxMan->init();
g_sludge->_resMan->init();
2018-04-15 19:10:02 +00:00
g_sludge->_peopleMan->init();
2018-05-01 16:41:34 +00:00
g_sludge->_floorMan->init();
g_sludge->_objMan->init();
2017-12-19 20:24:31 +00:00
g_sludge->_speechMan->init();
initStatusBar();
g_sludge->_evtMan->init();
g_sludge->_txtMan->init();
g_sludge->_cursorMan->init();
g_sludge->_soundMan->init();
if (!ConfMan.hasKey("mute") || !ConfMan.getBool("mute")) {
g_sludge->_soundMan->initSoundStuff();
}
CustomSaveHelper::_saveEncoding = false;
// global variables
numGlobals = 0;
launchResult = nullptr;
allowAnyFilename = true;
noStack = nullptr;
numBIFNames = numUserFunc = 0;
allUserFunc = allBIFNames = nullptr;
}
void killSludge() {
killAllFunctions();
2018-04-15 19:10:02 +00:00
g_sludge->_peopleMan->kill();
g_sludge->_regionMan->kill();
2018-05-01 16:41:34 +00:00
g_sludge->_floorMan->kill();
2017-12-19 20:24:31 +00:00
g_sludge->_speechMan->kill();
g_sludge->_languageMan->kill();
g_sludge->_gfxMan->kill();
g_sludge->_resMan->kill();
g_sludge->_objMan->kill();
g_sludge->_soundMan->killSoundStuff();
g_sludge->_evtMan->kill();
g_sludge->_txtMan->kill();
g_sludge->_cursorMan->kill();
// global variables
numBIFNames = numUserFunc = 0;
delete []allUserFunc;
delete []allBIFNames;
}
bool initSludge(const Common::String &filename) {
initSludge();
Common::File *fp = openAndVerify(filename, 'G', 'E', ERROR_BAD_HEADER, gameVersion);
2017-05-29 06:02:59 +00:00
if (!fp)
return false;
char c = fp->readByte();
if (c) {
numBIFNames = fp->readUint16BE();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "numBIFNames %i", numBIFNames);
allBIFNames = new Common::String[numBIFNames];
2017-05-29 06:02:59 +00:00
if (!checkNew(allBIFNames))
return false;
2017-05-29 06:02:59 +00:00
for (int fn = 0; fn < numBIFNames; fn++) {
allBIFNames[fn].clear();
allBIFNames[fn] = readString(fp);
}
numUserFunc = fp->readUint16BE();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "numUserFunc %i", numUserFunc);
allUserFunc = new Common::String[numUserFunc];
2017-05-29 06:02:59 +00:00
if (!checkNew(allUserFunc))
return false;
2017-05-29 06:02:59 +00:00
for (int fn = 0; fn < numUserFunc; fn++) {
allUserFunc[fn].clear();
allUserFunc[fn] = readString(fp);
}
if (gameVersion >= VERSION(1, 3)) {
g_sludge->_resMan->readResourceNames(fp);
}
}
2017-07-19 22:41:13 +00:00
int winWidth = fp->readUint16BE();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "winWidth : %i", winWidth);
2017-07-19 22:41:13 +00:00
int winHeight = fp->readUint16BE();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "winHeight : %i", winHeight);
2017-07-19 22:41:13 +00:00
g_sludge->_gfxMan->setWindowSize(winWidth, winHeight);
2017-07-18 14:17:39 +00:00
int specialSettings = fp->readByte();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "specialSettings : %i", specialSettings);
g_sludge->_timer.setDesiredFPS(1000 / fp->readByte());
readString(fp); // Unused - was used for registration purposes.
uint bytes_read = fp->read(&fileTime, sizeof(FILETIME));
if (bytes_read != sizeof(FILETIME) && fp->err()) {
2017-08-02 14:35:09 +00:00
debug(0, "Reading error in initSludge.");
}
Common::String dataFol = (gameVersion >= VERSION(1, 3)) ? readString(fp) : "";
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "dataFol : %s", dataFol.c_str());
g_sludge->_languageMan->createTable(fp);
if (gameVersion >= VERSION(1, 6)) {
fp->readByte();
// aaLoad
fp->readByte();
fp->readFloatLE();
fp->readFloatLE();
}
Common::String checker = readString(fp);
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "checker : %s", checker.c_str());
if (checker != "okSoFar")
2017-05-29 06:02:59 +00:00
return fatal(ERROR_BAD_HEADER, filename);
byte customIconLogo = fp->readByte();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "Game icon type: %i", customIconLogo);
if (customIconLogo & 1) {
// There is an icon - read it!
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "There is an icon - read it!");
2017-07-16 10:18:30 +00:00
// read game icon
Graphics::Surface gameIcon;
if (!ImgLoader::loadImage(fp, &gameIcon, false))
return false;
}
if (customIconLogo & 2) {
// There is an logo - read it!
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "There is an logo - read it!");
2017-07-16 10:18:30 +00:00
// read game logo
Graphics::Surface gameLogo;
if (!ImgLoader::loadImage(fp, &gameLogo))
return false;
}
numGlobals = fp->readUint16BE();
2017-08-02 14:35:09 +00:00
debugC(2, kSludgeDebugDataLoad, "numGlobals : %i", numGlobals);
globalVars = new Variable[numGlobals];
2017-05-29 06:02:59 +00:00
if (!checkNew(globalVars))
return false;
// Get language selected by user
2017-07-18 17:03:45 +00:00
g_sludge->_resMan->setData(fp);
2017-07-18 15:25:00 +00:00
g_sludge->_languageMan->setLanguageID(g_sludge->getLanguageID());
if (!dataFol.empty()) {
Common::String dataFolder = encodeFilename(dataFol);
}
positionStatus(10, winHeight - 15);
return true;
}
void displayBase() {
g_sludge->_gfxMan->clear(); // Clear screen
g_sludge->_gfxMan->drawBackDrop();// Draw Backdrop
2017-07-19 22:41:13 +00:00
g_sludge->_gfxMan->drawZBuffer(g_sludge->_gfxMan->getCamX(), g_sludge->_gfxMan->getCamY(), false);
2018-04-15 19:10:02 +00:00
g_sludge->_peopleMan->drawPeople();// Then add any moving characters...
2017-07-19 22:41:13 +00:00
g_sludge->_gfxMan->displaySpriteLayers();
}
void sludgeDisplay() {
displayBase();
2017-12-19 20:24:31 +00:00
g_sludge->_speechMan->display();
drawStatusBar();
2017-07-21 06:16:17 +00:00
g_sludge->_cursorMan->displayCursor();
2017-07-19 22:41:13 +00:00
g_sludge->_gfxMan->display();
}
2017-05-26 19:25:11 +00:00
} // End of namespace Sludge