OpenTTD Source 20250331-master-g3c15e0c889
newgrf_acte.cpp
Go to the documentation of this file.
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 */
7
10#include "../stdafx.h"
11#include "../debug.h"
12#include "newgrf_bytereader.h"
13#include "newgrf_internal.h"
14
15#include "table/strings.h"
16
17#include "../safeguards.h"
18
19/* Action 0x0E (GLS_SAFETYSCAN) */
20static void SafeGRFInhibit(ByteReader &buf)
21{
22 /* <0E> <num> <grfids...>
23 *
24 * B num Number of GRFIDs that follow
25 * D grfids GRFIDs of the files to deactivate */
26
27 uint8_t num = buf.ReadByte();
28
29 for (uint i = 0; i < num; i++) {
30 uint32_t grfid = buf.ReadDWord();
31
32 /* GRF is unsafe it if tries to deactivate other GRFs */
33 if (grfid != _cur.grfconfig->ident.grfid) {
34 GRFUnsafe(buf);
35 return;
36 }
37 }
38}
39
40/* Action 0x0E */
41static void GRFInhibit(ByteReader &buf)
42{
43 /* <0E> <num> <grfids...>
44 *
45 * B num Number of GRFIDs that follow
46 * D grfids GRFIDs of the files to deactivate */
47
48 uint8_t num = buf.ReadByte();
49
50 for (uint i = 0; i < num; i++) {
51 uint32_t grfid = buf.ReadDWord();
52 GRFConfig *file = GetGRFConfig(grfid);
53
54 /* Unset activation flag */
55 if (file != nullptr && file != _cur.grfconfig) {
56 GrfMsg(2, "GRFInhibit: Deactivating file '{}'", file->filename);
57 GRFError *error = DisableGrf(STR_NEWGRF_ERROR_FORCEFULLY_DISABLED, file);
58 error->data = _cur.grfconfig->GetName();
59 }
60 }
61}
62
63template <> void GrfActionHandler<0x0E>::FileScan(ByteReader &) { }
64template <> void GrfActionHandler<0x0E>::SafetyScan(ByteReader &buf) { SafeGRFInhibit(buf); }
66template <> void GrfActionHandler<0x0E>::Init(ByteReader &buf) { GRFInhibit(buf); }
67template <> void GrfActionHandler<0x0E>::Reserve(ByteReader &buf) { GRFInhibit(buf); }
68template <> void GrfActionHandler<0x0E>::Activation(ByteReader &buf) { GRFInhibit(buf); }
Class to read from a NewGRF file.
uint32_t ReadDWord()
Read a single DWord (32 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
void GRFUnsafe(ByteReader &)
Set the current NewGRF as unsafe for static use.
Definition newgrf.cpp:365
GRFError * DisableGrf(StringID message, GRFConfig *config)
Disable a GRF.
Definition newgrf.cpp:131
NewGRF buffer reader definition.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
NewGRF internal processing state.
Information about GRF, used in the game and (part of it) in savegames.
std::string filename
Filename - either with or without full path.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
std::string GetName() const
Get the name of this grf.
Information about why GRF had problems during initialisation.
std::string data
Additional data for message and custom_message.
uint32_t grfid
GRF ID (defined by Action 0x08)
GRF action handler.
GRFConfig * grfconfig
Config of the currently processed GRF file.