diff options
Diffstat (limited to 'engines/hdb')
-rw-r--r-- | engines/hdb/file-manager.cpp | 22 | ||||
-rw-r--r-- | engines/hdb/hdb.cpp | 17 | ||||
-rw-r--r-- | engines/hdb/hdb.h | 2 | ||||
-rw-r--r-- | engines/hdb/lua-script.cpp | 47 | ||||
-rw-r--r-- | engines/hdb/map.cpp | 8 |
5 files changed, 54 insertions, 42 deletions
diff --git a/engines/hdb/file-manager.cpp b/engines/hdb/file-manager.cpp index 66543db4cd..0bc22fbb62 100644 --- a/engines/hdb/file-manager.cpp +++ b/engines/hdb/file-manager.cpp @@ -96,23 +96,29 @@ Common::SeekableReadStream *FileMan::findFirstData(const char *string, DataType Common::String fileString; MPCEntry *file = NULL; - debug(4, "Looking for Data: '%s'", string); + char fname[128]; + strcpy(fname, string); + char *pDest = strrchr(fname, '.'); + if (pDest) + *pDest = '_'; + + debug(4, "Looking for Data: '%s' <- '%s'", fname, string); // Find MPC Entry for (MPCIterator it = _dir.begin(); it != _dir.end(); it++) { fileString = (*it)->filename; - if (fileString.equals(string)) { + if (fileString.equals(fname)) { if ((*it)->type == type) { file = *it; break; } else { - debug(4, "Found Data but type mismatch: '%s', target: %d, found: %d", string, type, (*it)->type); + debug(4, "Found Data but type mismatch: '%s', target: %d, found: %d", fname, type, (*it)->type); } } } if (file == NULL) { - debug(4, "Couldn't find Data: '%s'", string); + debug(4, "Couldn't find Data: '%s'", fname); return NULL; } @@ -130,10 +136,16 @@ int32 FileMan::getLength(const char *string, DataType type) { Common::String fileString; MPCEntry *file = NULL; + char fname[128]; + strcpy(fname, string); + char *pDest = strrchr(fname, '.'); + if (pDest) + *pDest = '_'; + // Find MPC Entry for (MPCIterator it = _dir.begin(); it != _dir.end(); it++) { fileString = (*it)->filename; - if (fileString.contains(string)) { + if (fileString.contains(fname)) { if ((*it)->type == type) { file = *it; break; diff --git a/engines/hdb/hdb.cpp b/engines/hdb/hdb.cpp index 9eaf120813..1f2f58bda2 100644 --- a/engines/hdb/hdb.cpp +++ b/engines/hdb/hdb.cpp @@ -106,7 +106,7 @@ bool HDBGame::init() { error("Input::init: Couldn't initialize Input"); } if (!_lua->init()) { - error("LuaScript::init: Couldn't load the GLOBAL_LUA code."); + error("LuaScript::init: Couldn't load the GLOBAL.LUA code."); } _menu->init(); @@ -192,7 +192,7 @@ bool HDBGame::restartMap() { return true; } -bool HDBGame::startMap(char *name) { +bool HDBGame::startMap(const char *name) { // save last mapname strcpy(_lastMapname, _currentMapname); @@ -503,18 +503,7 @@ Common::Error HDBGame::run() { tile->load(tileStream); #endif - _lua->loadLua("MAP00_LUA"); - - _lua->callFunction("level_loaded", 0); - - Common::SeekableReadStream *mapStream = _fileMan->findFirstData("MAP00_MSM", TYPE_BINARY); - if (mapStream == NULL) { - debug("The MAP00_MSM MPC entry can't be found."); - return Common::kReadingFailed; - } - - _map->load(mapStream); - _ai->initAnimInfo(); + startMap("MAP00"); //_window->openDialog("Sgt. Filibuster", 0, "You address me as 'sarge' or 'sergeant' or get your snappin' teeth kicked in! Got me?", 0, NULL); diff --git a/engines/hdb/hdb.h b/engines/hdb/hdb.h index 33778b37d2..6d7490b914 100644 --- a/engines/hdb/hdb.h +++ b/engines/hdb/hdb.h @@ -150,7 +150,7 @@ public: bool init(); bool restartMap(); - bool startMap(char *name); + bool startMap(const char *name); void changeMap(char *name) { strcpy(_changeMapname, name); diff --git a/engines/hdb/lua-script.cpp b/engines/hdb/lua-script.cpp index 5c273e2a3e..4731136205 100644 --- a/engines/hdb/lua-script.cpp +++ b/engines/hdb/lua-script.cpp @@ -30,22 +30,22 @@ namespace HDB { struct ScriptPatch { - const char* scriptName; - const char* search; - const char* replace; + const char *scriptName; + const char *search; + const char *replace; } scriptPatches[] = { - {"GLOBAL_LUA", "for i,npc in npcs do", "for i,npc in pairs(npcs) do"}, - {"GLOBAL_LUA", "setglobal( npcdef.codename..\"_init\", function() return NPC_Init( %npcdef ) end )", "_G[npcdef.codename .. \"_init\"] = function() return NPC_Init( npcdef ) end"}, - {"GLOBAL_LUA", "setglobal( npcdef.codename..\"_use\", function(x, y, v1, v2) return NPC_Use( %npcdef, x, y, v1, v2 ) end )", "_G[npcdef.codename .. \"_use\"] = function(x, y, v1, v2) return NPC_Use( npcdef, x, y, v1, v2 ) end"}, - {"GLOBAL_LUA", "if( dtable.counter < getn(dtable) ) then", "if( dtable.counter < #dtable ) then"}, - {"GLOBAL_LUA", "if( getglobal( \"map\"..tostring(v1)..\"_complete\" ) ) then", "if( _G[\"map\"..tostring(v1)..\"_complete\"] ) then"}, - {"GLOBAL_LUA", "closefunc = getglobal( npcdef.codename..\"_use\" )", "closefunc = _G[npcdef.codename..\"_use\"]"}, - {"GLOBAL_LUA", "strsub(", "string.sub("}, // line 15 - {"MAP00_LUA", "tempfunc = function() emptybed_use( %x, %y, %v1, %v2 ) end", "tempfunc = function() emptybed_use(x, y, v1, v2) end"}, - {"MAP00_LUA", "if( getn( beds ) == 0 ) then", "if( #beds == 0 ) then"}, - {"MAP01_LUA", "if( covert_index < getn(covert_dialog) ) then", "if( covert_index < #covert_dialog ) then"}, - {"MAP01_LUA", "if( chiste_index < getn( chiste_dialog ) )then", "if( covert_index < #covert_dialog ) then"}, - {"MAP01_LUA", "strsub(", "string.sub("}, // line 23 + {"GLOBAL.LUA", "for i,npc in npcs do", "for i,npc in pairs(npcs) do"}, + {"GLOBAL.LUA", "setglobal( npcdef.codename..\"_init\", function() return NPC_Init( %npcdef ) end )", "_G[npcdef.codename .. \"_init\"] = function() return NPC_Init( npcdef ) end"}, + {"GLOBAL.LUA", "setglobal( npcdef.codename..\"_use\", function(x, y, v1, v2) return NPC_Use( %npcdef, x, y, v1, v2 ) end )", "_G[npcdef.codename .. \"_use\"] = function(x, y, v1, v2) return NPC_Use( npcdef, x, y, v1, v2 ) end"}, + {"GLOBAL.LUA", "if( dtable.counter < getn(dtable) ) then", "if( dtable.counter < #dtable ) then"}, + {"GLOBAL.LUA", "if( getglobal( \"map\"..tostring(v1)..\"_complete\" ) ) then", "if( _G[\"map\"..tostring(v1)..\"_complete\"] ) then"}, + {"GLOBAL.LUA", "closefunc = getglobal( npcdef.codename..\"_use\" )", "closefunc = _G[npcdef.codename..\"_use\"]"}, + {"GLOBAL.LUA", "strsub(", "string.sub("}, // line 15 + {"MAP00.LUA", "tempfunc = function() emptybed_use( %x, %y, %v1, %v2 ) end", "tempfunc = function() emptybed_use(x, y, v1, v2) end"}, + {"MAP00.LUA", "if( getn( beds ) == 0 ) then", "if( #beds == 0 ) then"}, + {"MAP01.LUA", "if( covert_index < getn(covert_dialog) ) then", "if( covert_index < #covert_dialog ) then"}, + {"MAP01.LUA", "if( chiste_index < getn( chiste_dialog ) )then", "if( covert_index < #covert_dialog ) then"}, + {"MAP01.LUA", "strsub(", "string.sub("}, // line 23 {NULL, NULL, NULL}, }; @@ -62,8 +62,8 @@ LuaScript::~LuaScript() { bool LuaScript::init() { // Load Global Lua Code - _globalLuaStream = g_hdb->_fileMan->findFirstData("GLOBAL_LUA", TYPE_BINARY); - _globalLuaLength = g_hdb->_fileMan->getLength("GLOBAL_LUA", TYPE_BINARY); + _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; @@ -1426,9 +1426,9 @@ bool LuaScript::initScript(Common::SeekableReadStream *stream, const char *scrip lua_sethook(_state, debugHook, LUA_MASKCALL | LUA_MASKLINE, 0); } - // Load GLOBAL_LUA and execute it + // Load GLOBAL.LUA and execute it - if (!executeMPC(_globalLuaStream, "global code", "GLOBAL_LUA", _globalLuaLength)) { + if (!executeMPC(_globalLuaStream, "global code", "GLOBAL.LUA", _globalLuaLength)) { error("LuaScript::initScript: 'global code' failed to execute"); return false; } @@ -1640,17 +1640,22 @@ void LuaScript::stripComments(char *chunk) { } } -void LuaScript::addPatches(Common::String &chunk, const char* scriptName) { +void LuaScript::addPatches(Common::String &chunk, const char *scriptName) { ScriptPatch *patch = scriptPatches; + int applied = 0; while (patch->scriptName) { - if (scriptName == patch->scriptName) { + if (!strcmp(scriptName, patch->scriptName)) { Common::String searchString(patch->search); Common::String replaceString(patch->replace); Common::replace(chunk, searchString, replaceString); + applied++; } patch++; } + + if (applied) + debug(1, "Applied %d patches to %s", applied, scriptName); } void LuaScript::checkParameters(const char *func, int params) { diff --git a/engines/hdb/map.cpp b/engines/hdb/map.cpp index c34104c5a1..ec5b57cea0 100644 --- a/engines/hdb/map.cpp +++ b/engines/hdb/map.cpp @@ -73,7 +73,13 @@ void Map::restartSystem() { } bool Map::loadMap(char *name) { - warning("STUB: loadMap(%s)", name); + Common::SeekableReadStream *mapStream = g_hdb->_fileMan->findFirstData(name, TYPE_BINARY); + if (mapStream == NULL) { + warning("The %s MPC entry can't be found", name); + return false; + } + + load(mapStream); return true; } |