Files
@ r28024:510529c5fc82
Branch filter:
Location: cpp/openttd-patchpack/source/src/game/game_scanner.cpp - annotation
r28024:510529c5fc82
3.1 KiB
text/x-c
Change: Use CARGO_LIST to show station cargo acceptance changes. (#11379)
This simplifies construction of the news message and allows for more than
two changes to be show in one line.
This simplifies construction of the news message and allows for more than
two changes to be show in one line.
r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r27307:3787f9679f95 r27307:3787f9679f95 r21383:942c32fb8b0e r21383:942c32fb8b0e r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r27307:3787f9679f95 r18748:5e4b96072e2a r27307:3787f9679f95 r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r27354:7a607c98c943 r18748:5e4b96072e2a r23607:36c15679007d r27354:7a607c98c943 r18748:5e4b96072e2a r27308:abc0eb023c25 r18748:5e4b96072e2a r27308:abc0eb023c25 r27308:abc0eb023c25 r24498:e9114d9ab04a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r27308:abc0eb023c25 r27308:abc0eb023c25 r27308:abc0eb023c25 r24498:e9114d9ab04a r18748:5e4b96072e2a r18748:5e4b96072e2a r24498:e9114d9ab04a r27308:abc0eb023c25 r24498:e9114d9ab04a r18748:5e4b96072e2a r18748:5e4b96072e2a r24500:deda806a71a7 r24500:deda806a71a7 r27308:abc0eb023c25 r27308:abc0eb023c25 r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18748:5e4b96072e2a r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r27307:3787f9679f95 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r27307:3787f9679f95 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r27354:7a607c98c943 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r27308:abc0eb023c25 r18754:42d72cb83fe7 r18754:42d72cb83fe7 r24500:deda806a71a7 r24500:deda806a71a7 r18754:42d72cb83fe7 r24500:deda806a71a7 r18754:42d72cb83fe7 | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file game_scanner.cpp allows scanning Game scripts */
#include "../stdafx.h"
#include "../script/squirrel_class.hpp"
#include "game_info.hpp"
#include "game_scanner.hpp"
#include "../3rdparty/fmt/format.h"
#include "../safeguards.h"
void GameScannerInfo::Initialize()
{
ScriptScanner::Initialize("GSScanner");
}
std::string GameScannerInfo::GetScriptName(ScriptInfo *info)
{
return info->GetName();
}
void GameScannerInfo::RegisterAPI(class Squirrel *engine)
{
GameInfo::RegisterAPI(engine);
}
GameInfo *GameScannerInfo::FindInfo(const std::string &name, int version, bool force_exact_match)
{
if (this->info_list.size() == 0) return nullptr;
if (name.empty()) return nullptr;
if (version == -1) {
/* We want to load the latest version of this Game script; so find it */
auto it = this->info_single_list.find(name);
if (it != this->info_single_list.end()) return static_cast<GameInfo *>(it->second);
return nullptr;
}
if (force_exact_match) {
/* Try to find a direct 'name.version' match */
std::string name_with_version = fmt::format("{}.{}", name, version);
auto it = this->info_list.find(name_with_version);
if (it != this->info_list.end()) return static_cast<GameInfo *>(it->second);
return nullptr;
}
GameInfo *info = nullptr;
int highest_version = -1;
/* See if there is a compatible Game script which goes by that name, with the highest
* version which allows loading the requested version */
for (const auto &item : this->info_list) {
GameInfo *i = static_cast<GameInfo *>(item.second);
if (StrEqualsIgnoreCase(name, i->GetName()) && i->CanLoadFromVersion(version) && (highest_version == -1 || i->GetVersion() > highest_version)) {
highest_version = item.second->GetVersion();
info = i;
}
}
return info;
}
void GameScannerLibrary::Initialize()
{
ScriptScanner::Initialize("GSScanner");
}
std::string GameScannerLibrary::GetScriptName(ScriptInfo *info)
{
GameLibrary *library = static_cast<GameLibrary *>(info);
return fmt::format("{}.{}", library->GetCategory(), library->GetInstanceName());
}
void GameScannerLibrary::RegisterAPI(class Squirrel *engine)
{
GameLibrary::RegisterAPI(engine);
}
GameLibrary *GameScannerLibrary::FindLibrary(const std::string &library, int version)
{
/* Internally we store libraries as 'library.version' */
std::string library_name = fmt::format("{}.{}", library, version);
/* Check if the library + version exists */
ScriptInfoList::iterator it = this->info_list.find(library_name);
if (it == this->info_list.end()) return nullptr;
return static_cast<GameLibrary *>((*it).second);
}
|