diff options
Diffstat (limited to 'engines/agos')
-rw-r--r-- | engines/agos/game.cpp | 173 |
1 files changed, 8 insertions, 165 deletions
diff --git a/engines/agos/game.cpp b/engines/agos/game.cpp index 55fa425a5a..04860c41b4 100644 --- a/engines/agos/game.cpp +++ b/engines/agos/game.cpp @@ -37,18 +37,12 @@ static DetectedGameList GAME_detectGames(const FSList &fslist); using Common::File; -struct ObsoleteGameID { - const char *from; - const char *to; - Common::Platform platform; -}; - /** * Conversion table mapping old obsolete target names to the * corresponding new target and platform combination. * */ -static const ObsoleteGameID obsoleteGameIDsTable[] = { +static const Common::ADObsoleteGameID obsoleteGameIDsTable[] = { {"simon1acorn", "simon1", Common::kPlatformAcorn}, {"simon1amiga", "simon1", Common::kPlatformAmiga}, {"simon1cd32", "simon1", Common::kPlatformAmiga}, @@ -77,85 +71,13 @@ static const PlainGameDescriptor simonGames[] = { {NULL, NULL} }; -GameList Engine_AGOS_gameIDList() { - GameList games; - const PlainGameDescriptor *g = simonGames; - while (g->gameid) { - games.push_back(*g); - g++; - } +ADVANCED_DETECTOR_GAMEID_LIST(AGOS, simonGames); - return games; -} +ADVANCED_DETECTOR_FIND_GAMEID(AGOS, simonGames, obsoleteGameIDsTable); -GameDescriptor Engine_AGOS_findGameID(const char *gameid) { - // First search the list of supported game IDs. - const PlainGameDescriptor *g = simonGames; - while (g->gameid) { - if (!scumm_stricmp(gameid, g->gameid)) - return *g; - g++; - } - - // If we didn't find the gameid in the main list, check if it - // is an obsolete game id. - GameDescriptor gs; - const ObsoleteGameID *o = obsoleteGameIDsTable; - while (o->from) { - if (0 == scumm_stricmp(gameid, o->from)) { - gs.gameid = gameid; - gs.description = "Obsolete game ID"; - return gs; - } - o++; - } - return gs; -} +ADVANCED_DETECTOR_DETECT_GAMES(AGOS, AGOS::GAME_detectGames); -DetectedGameList Engine_AGOS_detectGames(const FSList &fslist) { - return AGOS::GAME_detectGames(fslist); -} - -PluginError Engine_AGOS_create(OSystem *syst, Engine **engine) { - assert(syst); - assert(engine); - const char *gameid = ConfMan.get("gameid").c_str(); - - for (const ObsoleteGameID *o = obsoleteGameIDsTable; o->from; ++o) { - if (!scumm_stricmp(gameid, o->from)) { - // Match found, perform upgrade - gameid = o->to; - ConfMan.set("gameid", o->to); - - if (o->platform != Common::kPlatformUnknown) - ConfMan.set("platform", Common::getPlatformCode(o->platform)); - - warning("Target upgraded from %s to %s", o->from, o->to); - ConfMan.flushToDisk(); - break; - } - } - - FSList fslist; - FilesystemNode dir(ConfMan.get("path")); - if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { - warning("AGOSEngine: invalid game path '%s'", dir.path().c_str()); - return kInvalidPathError; - } - - // Invoke the detector - DetectedGameList detectedGames = Engine_AGOS_detectGames(fslist); - - for (uint i = 0; i < detectedGames.size(); i++) { - if (detectedGames[i].gameid == gameid) { - *engine = new AGOS::AGOSEngine(syst); - return kNoError; - } - } - - warning("AGOSEngine: Unable to locate game data at path '%s'", dir.path().c_str()); - return kNoGameDataFoundError; -} +ADVANCED_DETECTOR_ENGINE_CREATE(AGOS, AGOS::AGOSEngine, "AGOSEngine", obsoleteGameIDsTable); REGISTER_PLUGIN(AGOS, "AGOS", "AGOS (C) Adventure Soft"); @@ -166,89 +88,10 @@ using Common::ADGameDescription; #include "agosgame.cpp" -DetectedGame toDetectedGame(const ADGameDescription &g) { - const char *title = 0; - - const PlainGameDescriptor *sg = simonGames; - while (sg->gameid) { - if (!scumm_stricmp(g.name, sg->gameid)) - title = sg->description; - sg++; - } - - DetectedGame dg(g.name, title, g.language, g.platform); - dg.updateDesc(g.extra); - return dg; -} - -bool AGOSEngine::initGame() { - int gameNumber = -1; - - DetectedGameList detectedGames; - Common::AdvancedDetector AdvDetector; - Common::ADList matches; - Common::ADGameDescList descList; - - Common::Language language = Common::UNK_LANG; - Common::Platform platform = Common::kPlatformUnknown; - - if (ConfMan.hasKey("language")) - language = Common::parseLanguage(ConfMan.get("language")); - if (ConfMan.hasKey("platform")) - platform = Common::parsePlatform(ConfMan.get("platform")); - - Common::String gameid = ConfMan.get("gameid"); +ADVANCED_DETECTOR_TO_DETECTED_GAME(simonGames); - // At this point, Engine_AGOS_create() has already verified that the - // desired game is in the specified directory. But we've already - // forgotten which particular version it was, so we have to do it all - // over again... +ADVANCED_DETECTOR_DETECT_INIT_GAME(AGOSEngine::initGame, gameDescriptions, _gameDescription, Common::ADTrue); - for (int i = 0; i < ARRAYSIZE(gameDescriptions); i++) - descList.push_back((const ADGameDescription *)&gameDescriptions[i]); - - AdvDetector.registerGameDescriptions(descList); - AdvDetector.setFileMD5Bytes(FILE_MD5_BYTES); - - matches = AdvDetector.detectGame(NULL, language, platform); - - for (uint i = 0; i < matches.size(); i++) { - if (toDetectedGame(gameDescriptions[matches[i]].desc).gameid == gameid) { - gameNumber = matches[i]; - break; - } - } - - if (gameNumber >= ARRAYSIZE(gameDescriptions) || gameNumber == -1) { - error("AGOSEngine::loadGame wrong gameNumber"); - } - - debug(2, "Running %s", toDetectedGame(gameDescriptions[gameNumber].desc).description.c_str()); - - _gameDescription = &gameDescriptions[gameNumber]; - - return true; -} - -DetectedGameList GAME_detectGames(const FSList &fslist) { - DetectedGameList detectedGames; - Common::AdvancedDetector AdvDetector; - Common::ADList matches; - Common::ADGameDescList descList; - - for (int i = 0; i < ARRAYSIZE(gameDescriptions); i++) - descList.push_back((const ADGameDescription *)&gameDescriptions[i]); - - AdvDetector.registerGameDescriptions(descList); - AdvDetector.setFileMD5Bytes(FILE_MD5_BYTES); - - matches = AdvDetector.detectGame(&fslist, Common::UNK_LANG, Common::kPlatformUnknown); - - for (uint i = 0; i < matches.size(); i++) - detectedGames.push_back(toDetectedGame(gameDescriptions[matches[i]].desc)); - - //delete &matches; - return detectedGames; -} +ADVANCED_DETECTOR_DETECT_GAMES_FUNCTION(GAME_detectGames, gameDescriptions); } // End of namespace AGOS |