ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

game.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/game.h"
00024 #include "common/gui_options.h"
00025 #include "common/translation.h"
00026 
00027 
00028 const PlainGameDescriptor *findPlainGameDescriptor(const char *gameid, const PlainGameDescriptor *list) {
00029     const PlainGameDescriptor *g = list;
00030     while (g->gameId) {
00031         if (0 == scumm_stricmp(gameid, g->gameId))
00032             return g;
00033         g++;
00034     }
00035     return 0;
00036 }
00037 
00038 PlainGameDescriptor PlainGameDescriptor::empty() {
00039     PlainGameDescriptor pgd;
00040     pgd.gameId = nullptr;
00041     pgd.description = nullptr;
00042     return pgd;
00043 }
00044 
00045 PlainGameDescriptor PlainGameDescriptor::of(const char *gameId, const char *description) {
00046     PlainGameDescriptor pgd;
00047     pgd.gameId = gameId;
00048     pgd.description = description;
00049     return pgd;
00050 }
00051 
00052 QualifiedGameDescriptor::QualifiedGameDescriptor(const char *engine, const PlainGameDescriptor &pgd) :
00053         engineId(engine),
00054         gameId(pgd.gameId),
00055         description(pgd.description) {
00056 }
00057 
00058 DetectedGame::DetectedGame() :
00059         hasUnknownFiles(false),
00060         canBeAdded(true),
00061         language(Common::UNK_LANG),
00062         platform(Common::kPlatformUnknown),
00063         gameSupportLevel(kStableGame) {
00064 }
00065 
00066 DetectedGame::DetectedGame(const Common::String &engine, const PlainGameDescriptor &pgd) :
00067         engineId(engine),
00068         hasUnknownFiles(false),
00069         canBeAdded(true),
00070         language(Common::UNK_LANG),
00071         platform(Common::kPlatformUnknown),
00072         gameSupportLevel(kStableGame) {
00073 
00074     gameId = pgd.gameId;
00075     preferredTarget = pgd.gameId;
00076     description = pgd.description;
00077 }
00078 
00079 DetectedGame::DetectedGame(const Common::String &engine, const Common::String &id, const Common::String &d, Common::Language l, Common::Platform p, const Common::String &ex) :
00080         engineId(engine),
00081         hasUnknownFiles(false),
00082         canBeAdded(true),
00083         gameSupportLevel(kStableGame) {
00084 
00085     gameId = id;
00086     preferredTarget = id;
00087     description = d;
00088     language = l;
00089     platform = p;
00090     extra = ex;
00091 
00092     // Append additional information, if set, to the description.
00093     description += updateDesc();
00094 }
00095 
00096 void DetectedGame::setGUIOptions(const Common::String &guioptions) {
00097     _guiOptions = Common::getGameGUIOptionsDescription(guioptions);
00098 }
00099 
00100 void DetectedGame::appendGUIOptions(const Common::String &str) {
00101     if (!_guiOptions.empty())
00102         _guiOptions += " ";
00103 
00104     _guiOptions += str;
00105 }
00106 
00107 Common::String DetectedGame::updateDesc() const {
00108     const bool hasCustomLanguage = (language != Common::UNK_LANG);
00109     const bool hasCustomPlatform = (platform != Common::kPlatformUnknown);
00110     const bool hasExtraDesc = !extra.empty();
00111 
00112     // Adapt the description string if custom platform/language is set.
00113     Common::String descr;
00114     if (!hasCustomLanguage && !hasCustomPlatform && !hasExtraDesc)
00115         return descr;
00116 
00117     descr += " (";
00118 
00119     if (hasExtraDesc)
00120         descr += extra;
00121     if (hasCustomPlatform) {
00122         if (hasExtraDesc)
00123             descr += "/";
00124         descr += Common::getPlatformDescription(platform);
00125     }
00126     if (hasCustomLanguage) {
00127         if (hasExtraDesc || hasCustomPlatform)
00128             descr += "/";
00129         descr += Common::getLanguageDescription(language);
00130     }
00131 
00132     descr += ")";
00133 
00134     return descr;
00135 }
00136 
00137 DetectionResults::DetectionResults(const DetectedGames &detectedGames) :
00138         _detectedGames(detectedGames) {
00139 }
00140 
00141 bool DetectionResults::foundUnknownGames() const {
00142     for (uint i = 0; i < _detectedGames.size(); i++) {
00143         if (_detectedGames[i].hasUnknownFiles) {
00144             return true;
00145         }
00146     }
00147     return false;
00148 }
00149 
00150 DetectedGames DetectionResults::listRecognizedGames() const {
00151     DetectedGames candidates;
00152     for (uint i = 0; i < _detectedGames.size(); i++) {
00153         if (_detectedGames[i].canBeAdded) {
00154             candidates.push_back(_detectedGames[i]);
00155         }
00156     }
00157     return candidates;
00158 }
00159 
00160 DetectedGames DetectionResults::listDetectedGames() const {
00161     return _detectedGames;
00162 }
00163 
00164 Common::U32String DetectionResults::generateUnknownGameReport(bool translate, uint32 wordwrapAt) const {
00165     return ::generateUnknownGameReport(_detectedGames, translate, false, wordwrapAt);
00166 }
00167 
00168 Common::U32String generateUnknownGameReport(const DetectedGames &detectedGames, bool translate, bool fullPath, uint32 wordwrapAt) {
00169     assert(!detectedGames.empty());
00170 
00171     const char *reportStart = _s("The game in '%s' seems to be an unknown game variant.\n\n"
00172                                  "Please report the following data to the ResidualVM team at %s "
00173                                  "along with the name of the game you tried to add and "
00174                                  "its version, language, etc.:");
00175     const char *reportEngineHeader = _s("Matched game IDs for the %s engine:");
00176 
00177     Common::U32String report = Common::U32String::format(
00178             translate ? _(reportStart) : Common::U32String(reportStart),
00179             fullPath ? detectedGames[0].path.c_str() : detectedGames[0].shortPath.c_str(),
00180             "https://github.com/residualvm/residualvm/issues"
00181     );
00182     report += Common::U32String("\n");
00183 
00184     FilePropertiesMap matchedFiles;
00185 
00186     Common::String currentEngineId;
00187     for (uint i = 0; i < detectedGames.size(); i++) {
00188         const DetectedGame &game = detectedGames[i];
00189 
00190         if (!game.hasUnknownFiles) continue;
00191 
00192         if (currentEngineId.empty() || currentEngineId != game.engineId) {
00193             currentEngineId = game.engineId;
00194 
00195             // If the engine is not the same as for the previous entry, print an engine line header
00196             report += Common::U32String("\n");
00197             report += Common::U32String::format(
00198                     translate ? _(reportEngineHeader) : Common::U32String(reportEngineHeader),
00199                     game.engineId.c_str()
00200             );
00201             report += Common::U32String(" ");
00202 
00203         } else {
00204             report += Common::U32String(", ");
00205         }
00206 
00207         // Add the gameId to the list of matched games for the engine
00208         // TODO: Use the gameId here instead of the preferred target.
00209         // This is currently impossible due to the AD singleId feature losing the information.
00210         report += game.preferredTarget;
00211 
00212         // Consolidate matched files across all engines and detection entries
00213         for (FilePropertiesMap::const_iterator it = game.matchedFiles.begin(); it != game.matchedFiles.end(); it++) {
00214             matchedFiles.setVal(it->_key, it->_value);
00215         }
00216     }
00217 
00218     if (wordwrapAt) {
00219         report.wordWrap(wordwrapAt);
00220     }
00221 
00222     report += Common::U32String("\n\n");
00223 
00224     for (FilePropertiesMap::const_iterator file = matchedFiles.begin(); file != matchedFiles.end(); ++file)
00225         report += Common::String::format("  {\"%s\", 0, \"%s\", %d},\n", file->_key.c_str(), file->_value.md5.c_str(), file->_value.size);
00226 
00227     report += Common::U32String("\n");
00228 
00229     return report;
00230 }
00231 
00232 Common::U32String generateUnknownGameReport(const DetectedGame &detectedGame, bool translate, bool fullPath, uint32 wordwrapAt) {
00233     DetectedGames detectedGames;
00234     detectedGames.push_back(detectedGame);
00235 
00236     return generateUnknownGameReport(detectedGames, translate, fullPath, wordwrapAt);
00237 }


Generated on Sat Sep 12 2020 05:01:02 for ResidualVM by doxygen 1.7.1
curved edge   curved edge