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/>.
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
) {
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
) {
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
) {