HDB: Change init functions to handle errors
This commit is contained in:
parent
23c7dc8ebd
commit
2178770898
16 changed files with 29 additions and 64 deletions
|
@ -1012,7 +1012,7 @@ AI::~AI() {
|
|||
}
|
||||
}
|
||||
|
||||
bool AI::init() {
|
||||
void AI::init() {
|
||||
_debugQMark = g_hdb->_gfx->loadIcon("icon_question_mark");
|
||||
|
||||
// Clear Waypoint list and load Waypoint graphics
|
||||
|
@ -1114,7 +1114,6 @@ bool AI::init() {
|
|||
_weaponSelGfx = NULL;
|
||||
|
||||
restartSystem();
|
||||
return true;
|
||||
}
|
||||
|
||||
void AI::clearPersistent() {
|
||||
|
|
|
@ -300,7 +300,7 @@ void AI::newDelivery(const char *itemTextName, const char *itemGfxName, const ch
|
|||
}
|
||||
|
||||
bool AI::completeDelivery(const char *id) {
|
||||
for (int i = 0; i < _numDeliveries; i++)
|
||||
for (int i = 0; i < _numDeliveries; i++) {
|
||||
if (!scumm_stricmp(_deliveries[i].id, id)) {
|
||||
for (; i < _numDeliveries; i++)
|
||||
memcpy(&_deliveries[i], &_deliveries[i + 1], sizeof(_deliveries[0]));
|
||||
|
@ -311,6 +311,7 @@ bool AI::completeDelivery(const char *id) {
|
|||
g_hdb->_sound->playVoice(GUY_COMPLETED, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -803,7 +803,7 @@ public:
|
|||
AI();
|
||||
~AI();
|
||||
|
||||
bool init();
|
||||
void init();
|
||||
void clearPersistent();
|
||||
void restartSystem();
|
||||
const char *funcLookUp(void(*function)(AIEntity *e));
|
||||
|
|
|
@ -39,33 +39,27 @@ FileMan::~FileMan() {
|
|||
delete _dir[i];
|
||||
}
|
||||
|
||||
bool FileMan::openMPC(const Common::String &filename) {
|
||||
uint32 offset;
|
||||
|
||||
void FileMan::openMPC(const Common::String &filename) {
|
||||
if (!_mpcFile->open(filename)) {
|
||||
error("FileMan::openMPC(): Error reading the MSD/MPC file %s", filename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
_dataHeader.id = _mpcFile->readUint32BE();
|
||||
|
||||
if (_dataHeader.id == MKTAG('M', 'P', 'C', 'C')) {
|
||||
debug("COMPRESSED MPC FILE");
|
||||
return false;
|
||||
error("FileMan::openMPC: Compressed MPC File");
|
||||
} else if (_dataHeader.id == MKTAG('M', 'P', 'C', 'U')) {
|
||||
// we're fine
|
||||
} else if (_dataHeader.id == MKTAG('M', 'S', 'D', 'C')) {
|
||||
// we're fine
|
||||
} else if (_dataHeader.id == MKTAG('M', 'S', 'D', 'U')) {
|
||||
debug("UNCOMPRESSED MSD FILE");
|
||||
return false;
|
||||
error("FileMan::openMPC: Uncompressed MSD File");
|
||||
} else {
|
||||
error("Invalid MPC/MSD File.");
|
||||
return false;
|
||||
error("FileMan::openMPC: Invalid MPC/MSD File.");
|
||||
}
|
||||
|
||||
// read the directory
|
||||
offset = _mpcFile->readUint32LE();
|
||||
uint32 offset = _mpcFile->readUint32LE();
|
||||
_mpcFile->seek((int32)offset);
|
||||
|
||||
// Note: The MPC archive format assumes the offset to be uint32,
|
||||
|
@ -91,8 +85,6 @@ bool FileMan::openMPC(const Common::String &filename) {
|
|||
|
||||
_dir.push_back(dirEntry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileMan::closeMPC() {
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
uint32 dirSize;
|
||||
} _dataHeader;
|
||||
|
||||
bool openMPC(const Common::String &filename);
|
||||
void openMPC(const Common::String &filename);
|
||||
void closeMPC();
|
||||
void seek(int32 offset, int flag);
|
||||
|
||||
|
|
|
@ -85,8 +85,7 @@ Gfx::~Gfx() {
|
|||
delete _skyClouds;
|
||||
}
|
||||
|
||||
bool Gfx::init() {
|
||||
|
||||
void Gfx::init() {
|
||||
// Set the default cursor pos & char clipping
|
||||
setCursor(0, 0);
|
||||
|
||||
|
@ -109,12 +108,12 @@ bool Gfx::init() {
|
|||
|
||||
// Load Game Font
|
||||
if (!loadFont(HDB_FONT))
|
||||
return false;
|
||||
error("Gfx::init: Couldn't load fonts");
|
||||
|
||||
// Read total number of tiles in game
|
||||
_numTiles = g_hdb->_fileMan->getCount("t32_", TYPE_TILE32);
|
||||
if (!_numTiles)
|
||||
return false;
|
||||
error("Gfx::init: No tiles in game");
|
||||
|
||||
// Setup Tile Lookup Array
|
||||
_tLookupArray = new TileLookup[_numTiles];
|
||||
|
@ -199,7 +198,6 @@ bool Gfx::init() {
|
|||
}
|
||||
|
||||
_systemInit = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Gfx::save(Common::OutSaveFile *out) {
|
||||
|
@ -835,7 +833,6 @@ int Gfx::animateTile(int tileIndex) {
|
|||
}
|
||||
|
||||
bool Gfx::loadFont(const char *string) {
|
||||
|
||||
Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(string, TYPE_FONT);
|
||||
if (!stream)
|
||||
return false;
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
|
||||
Graphics::ManagedSurface _globalSurface;
|
||||
|
||||
bool init();
|
||||
void init();
|
||||
void save(Common::OutSaveFile *out);
|
||||
void loadSaveFile(Common::InSaveFile *in);
|
||||
void fillScreen(uint32 color);
|
||||
|
|
|
@ -137,28 +137,14 @@ bool HDBGame::init() {
|
|||
|
||||
// Init fileMan
|
||||
|
||||
if (!_fileMan->openMPC(getGameFile())) {
|
||||
error("FileMan::openMPC: Cannot find the %s data file", getGameFile());
|
||||
}
|
||||
if (!_gfx->init()) {
|
||||
error("Gfx::init: Couldn't initialize Gfx");
|
||||
}
|
||||
if (!_sound->init()) {
|
||||
error("Window::init: Couldn't initialize Sound");
|
||||
}
|
||||
if (!_ai->init()) {
|
||||
error("AI::init: Couldn't initialize AI");
|
||||
}
|
||||
if (!_window->init()) {
|
||||
error("Window::init: Couldn't initialize Window");
|
||||
}
|
||||
if (!_input->init()) {
|
||||
error("Input::init: Couldn't initialize Input");
|
||||
}
|
||||
if (!_lua->init()) {
|
||||
error("LuaScript::init: Couldn't load the GLOBAL.LUA code.");
|
||||
}
|
||||
_fileMan->openMPC(getGameFile());
|
||||
|
||||
_gfx->init();
|
||||
_sound->init();
|
||||
_ai->init();
|
||||
_window->init();
|
||||
_input->init();
|
||||
_lua->init();
|
||||
_menu->init();
|
||||
|
||||
_debugLogo = _gfx->loadIcon("icon_debug_logo");
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
namespace HDB {
|
||||
|
||||
bool Input::init() {
|
||||
void Input::init() {
|
||||
_stylusDown = false;
|
||||
_buttons = 0;
|
||||
|
||||
|
@ -49,8 +49,6 @@ bool Input::init() {
|
|||
_mouseY = g_hdb->_screenHeight / 2;
|
||||
|
||||
_mouseLButton = _mouseMButton = _mouseRButton = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Input::setButtons(uint16 b) {
|
||||
|
|
|
@ -42,7 +42,7 @@ enum Button {
|
|||
class Input {
|
||||
public:
|
||||
|
||||
bool init();
|
||||
void init();
|
||||
|
||||
void setButtons(uint16 b);
|
||||
uint16 getButtons();
|
||||
|
|
|
@ -125,16 +125,13 @@ LuaScript::~LuaScript() {
|
|||
delete _globalLuaStream;
|
||||
}
|
||||
|
||||
bool LuaScript::init() {
|
||||
void LuaScript::init() {
|
||||
// Load Global Lua Code
|
||||
_globalLuaStream = g_hdb->_fileMan->findFirstData("GLOBAL.LUA", TYPE_BINARY);
|
||||
_globalLuaLength = g_hdb->_fileMan->getLength("GLOBAL.LUA", TYPE_BINARY);
|
||||
if (_globalLuaStream == NULL || _globalLuaLength == 0) {
|
||||
error("LuaScript::initScript: 'global code' failed to load");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LuaScript::loadLua(const char *name) {
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
void save(Common::OutSaveFile *out);
|
||||
void loadSaveFile(Common::InSaveFile *in);
|
||||
|
||||
bool init();
|
||||
void init();
|
||||
bool initScript(Common::SeekableReadStream *stream, const char *scriptName, int32 length);
|
||||
|
||||
void pushInt(int value);
|
||||
|
|
|
@ -1418,7 +1418,7 @@ void Sound::test() {
|
|||
#endif
|
||||
}
|
||||
|
||||
bool Sound::init() {
|
||||
void Sound::init() {
|
||||
_song1.playing = _song2.playing = false;
|
||||
|
||||
//
|
||||
|
@ -1448,8 +1448,6 @@ bool Sound::init() {
|
|||
// voices are on by default
|
||||
_voicesOn = 1;
|
||||
memset(&_voicePlayed[0], 0, sizeof(_voicePlayed));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Sound::save(Common::OutSaveFile *out) {
|
||||
|
|
|
@ -1487,7 +1487,7 @@ public:
|
|||
|
||||
void test(); // FIXME. Remove
|
||||
|
||||
bool init();
|
||||
void init();
|
||||
void save(Common::OutSaveFile *out);
|
||||
void loadSaveFile(Common::InSaveFile *in);
|
||||
void setMusicVolume(int value);
|
||||
|
|
|
@ -131,8 +131,7 @@ Window::~Window() {
|
|||
delete _gemGfx;
|
||||
}
|
||||
|
||||
bool Window::init() {
|
||||
|
||||
void Window::init() {
|
||||
_gfxTL = g_hdb->_gfx->loadPic(MENU_BACK_TOPLEFT);
|
||||
_gfxTM = g_hdb->_gfx->loadPic(MENU_BACK_TOP);
|
||||
_gfxTR = g_hdb->_gfx->loadPic(MENU_BACK_TOPRIGHT);
|
||||
|
@ -207,8 +206,6 @@ bool Window::init() {
|
|||
_gemGfx = NULL;
|
||||
|
||||
restartSystem();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::save(Common::OutSaveFile *out) {
|
||||
|
|
|
@ -171,7 +171,7 @@ public:
|
|||
Window();
|
||||
~Window();
|
||||
|
||||
bool init();
|
||||
void init();
|
||||
void save(Common::OutSaveFile *out);
|
||||
void loadSaveFile(Common::InSaveFile *in);
|
||||
void restartSystem();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue