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 DetectedGame::DetectedGame() :
00053         engineName(nullptr),
00054         hasUnknownFiles(false),
00055         canBeAdded(true),
00056         language(Common::UNK_LANG),
00057         platform(Common::kPlatformUnknown),
00058         gameSupportLevel(kStableGame) {
00059 }
00060 
00061 DetectedGame::DetectedGame(const PlainGameDescriptor &pgd) :
00062         engineName(nullptr),
00063         hasUnknownFiles(false),
00064         canBeAdded(true),
00065         language(Common::UNK_LANG),
00066         platform(Common::kPlatformUnknown),
00067         gameSupportLevel(kStableGame) {
00068 
00069     gameId = pgd.gameId;
00070     preferredTarget = pgd.gameId;
00071     description = pgd.description;
00072 }
00073 
00074 DetectedGame::DetectedGame(const Common::String &id, const Common::String &d, Common::Language l, Common::Platform p, const Common::String &ex) :
00075         engineName(nullptr),
00076         hasUnknownFiles(false),
00077         canBeAdded(true),
00078         gameSupportLevel(kStableGame) {
00079 
00080     gameId = id;
00081     preferredTarget = id;
00082     description = d;
00083     language = l;
00084     platform = p;
00085     extra = ex;
00086 
00087     // Append additional information, if set, to the description.
00088     description += updateDesc();
00089 }
00090 
00091 void DetectedGame::setGUIOptions(const Common::String &guioptions) {
00092     _guiOptions = Common::getGameGUIOptionsDescription(guioptions);
00093 }
00094 
00095 void DetectedGame::appendGUIOptions(const Common::String &str) {
00096     if (!_guiOptions.empty())
00097         _guiOptions += " ";
00098 
00099     _guiOptions += str;
00100 }
00101 
00102 Common::String DetectedGame::updateDesc() const {
00103     const bool hasCustomLanguage = (language != Common::UNK_LANG);
00104     const bool hasCustomPlatform = (platform != Common::kPlatformUnknown);
00105     const bool hasExtraDesc = !extra.empty();
00106 
00107     // Adapt the description string if custom platform/language is set.
00108     Common::String descr;
00109     if (!hasCustomLanguage && !hasCustomPlatform && !hasExtraDesc)
00110         return descr;
00111 
00112     descr += " (";
00113 
00114     if (hasExtraDesc)
00115         descr += extra;
00116     if (hasCustomPlatform) {
00117         if (hasExtraDesc)
00118             descr += "/";
00119         descr += Common::getPlatformDescription(platform);
00120     }
00121     if (hasCustomLanguage) {
00122         if (hasExtraDesc || hasCustomPlatform)
00123             descr += "/";
00124         descr += Common::getLanguageDescription(language);
00125     }
00126 
00127     descr += ")";
00128 
00129     return descr;
00130 }
00131 
00132 DetectionResults::DetectionResults(const DetectedGames &detectedGames) :
00133         _detectedGames(detectedGames) {
00134 }
00135 
00136 bool DetectionResults::foundUnknownGames() const {
00137     for (uint i = 0; i < _detectedGames.size(); i++) {
00138         if (_detectedGames[i].hasUnknownFiles) {
00139             return true;
00140         }
00141     }
00142     return false;
00143 }
00144 
00145 DetectedGames DetectionResults::listRecognizedGames() const {
00146     DetectedGames candidates;
00147     for (uint i = 0; i < _detectedGames.size(); i++) {
00148         if (_detectedGames[i].canBeAdded) {
00149             candidates.push_back(_detectedGames[i]);
00150         }
00151     }
00152     return candidates;
00153 }
00154 
00155 DetectedGames DetectionResults::listDetectedGames() const {
00156     return _detectedGames;
00157 }
00158 
00159 Common::String DetectionResults::generateUnknownGameReport(bool translate, uint32 wordwrapAt) const {
00160     return ::generateUnknownGameReport(_detectedGames, translate, false, wordwrapAt);
00161 }
00162 
00163 Common::String generateUnknownGameReport(const DetectedGames &detectedGames, bool translate, bool fullPath, uint32 wordwrapAt) {
00164     assert(!detectedGames.empty());
00165 
00166     const char *reportStart = _s("The game in '%s' seems to be an unknown game variant.\n\n"
00167                                  "Please report the following data to the ResidualVM team at %s "
00168                                  "along with the name of the game you tried to add and "
00169                                  "its version, language, etc.:");
00170     const char *reportEngineHeader = _s("Matched game IDs for the %s engine:");
00171 
00172     Common::String report = Common::String::format(
00173             translate ? _(reportStart) : reportStart,
00174             fullPath ? detectedGames[0].path.c_str() : detectedGames[0].shortPath.c_str(),
00175             "https://github.com/residualvm/residualvm/issues"
00176     );
00177     report += "\n";
00178 
00179     FilePropertiesMap matchedFiles;
00180 
00181     const char *currentEngineName = nullptr;
00182     for (uint i = 0; i < detectedGames.size(); i++) {
00183         const DetectedGame &game = detectedGames[i];
00184 
00185         if (!game.hasUnknownFiles) continue;
00186 
00187         if (!currentEngineName || strcmp(currentEngineName, game.engineName) != 0) {
00188             currentEngineName = game.engineName;
00189 
00190             // If the engine is not the same as for the previous entry, print an engine line header
00191             report += "\n";
00192             report += Common::String::format(
00193                     translate ? _(reportEngineHeader) : reportEngineHeader,
00194                     game.engineName
00195             );
00196             report += " ";
00197 
00198         } else {
00199             report += ", ";
00200         }
00201 
00202         // Add the gameId to the list of matched games for the engine
00203         // TODO: Use the gameId here instead of the preferred target.
00204         // This is currently impossible due to the AD singleId feature losing the information.
00205         report += game.preferredTarget;
00206 
00207         // Consolidate matched files across all engines and detection entries
00208         for (FilePropertiesMap::const_iterator it = game.matchedFiles.begin(); it != game.matchedFiles.end(); it++) {
00209             matchedFiles.setVal(it->_key, it->_value);
00210         }
00211     }
00212 
00213     if (wordwrapAt) {
00214         report.wordWrap(wordwrapAt);
00215     }
00216 
00217     report += "\n\n";
00218 
00219     for (FilePropertiesMap::const_iterator file = matchedFiles.begin(); file != matchedFiles.end(); ++file)
00220         report += Common::String::format("  {\"%s\", 0, \"%s\", %d},\n", file->_key.c_str(), file->_value.md5.c_str(), file->_value.size);
00221 
00222     report += "\n";
00223 
00224     return report;
00225 }
00226 
00227 Common::String generateUnknownGameReport(const DetectedGame &detectedGame, bool translate, bool fullPath, uint32 wordwrapAt) {
00228     DetectedGames detectedGames;
00229     detectedGames.push_back(detectedGame);
00230 
00231     return generateUnknownGameReport(detectedGames, translate, fullPath, wordwrapAt);
00232 }


Generated on Sat Aug 17 2019 05:00:36 for ResidualVM by doxygen 1.7.1
curved edge   curved edge