Codechange: Optimize FlowsDown (#13262)
[openttd-github.git] / src / script / api / script_newgrf.cpp
blob884918c54994f7e2e8b7120fc455feeb94209a98
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file script_newgrf.cpp Implementation of ScriptNewGRF and friends. */
10 #include "../../stdafx.h"
11 #include "script_newgrf.hpp"
12 #include "../../core/bitmath_func.hpp"
13 #include "../../newgrf_config.h"
14 #include "../../string_func.h"
16 #include "../../safeguards.h"
18 ScriptNewGRFList::ScriptNewGRFList()
20 for (auto c = _grfconfig; c != nullptr; c = c->next) {
21 if (!HasBit(c->flags, GCF_STATIC)) {
22 this->AddItem(BSWAP32(c->ident.grfid));
27 /* static */ bool ScriptNewGRF::IsLoaded(SQInteger grfid)
29 grfid = BSWAP32(GB(grfid, 0, 32)); // Match people's expectations.
31 for (auto c = _grfconfig; c != nullptr; c = c->next) {
32 if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
33 return true;
37 return false;
40 /* static */ SQInteger ScriptNewGRF::GetVersion(SQInteger grfid)
42 grfid = BSWAP32(GB(grfid, 0, 32)); // Match people's expectations.
44 for (auto c = _grfconfig; c != nullptr; c = c->next) {
45 if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
46 return c->version;
50 return 0;
53 /* static */ std::optional<std::string> ScriptNewGRF::GetName(SQInteger grfid)
55 grfid = BSWAP32(GB(grfid, 0, 32)); // Match people's expectations.
57 for (auto c = _grfconfig; c != nullptr; c = c->next) {
58 if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
59 return c->GetName();
63 return std::nullopt;