OpenTTD Source: src/newgrf/newgrf_acte.cpp Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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_gps.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_gps.grfconfig) {
56 GrfMsg(2, "GRFInhibit: Deactivating file '{}'", file->filename);
57 GRFError *error = DisableGrf(STR_NEWGRF_ERROR_FORCEFULLY_DISABLED, file);
58 error->data = _cur_gps.grfconfig->GetName();
59 }
60 }
61}
62
63template <> void GrfActionHandler<0x0E>::FileScan(ByteReader &) { }
64template <> void GrfActionHandler<0x0E>::SafetyScan(ByteReader &buf) { SafeGRFInhibit(buf); }
65template <> void GrfActionHandler<0x0E>::LabelScan(ByteReader &) { }
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); }
ByteReader
Class to read from a NewGRF file.
Definition newgrf_bytereader.h:18
ByteReader::ReadDWord
uint32_t ReadDWord()
Read a single DWord (32 bits).
Definition newgrf_bytereader.h:66
ByteReader::ReadByte
uint8_t ReadByte()
Read a single byte (8 bits).
Definition newgrf_bytereader.h:34
GRFUnsafe
void GRFUnsafe(ByteReader &)
Set the current NewGRF as unsafe for static use.
Definition newgrf.cpp:373
DisableGrf
GRFError * DisableGrf(StringID message, GRFConfig *config)
Disable a GRF.
Definition newgrf.cpp:135
newgrf_bytereader.h
NewGRF buffer reader definition.
GetGRFConfig
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Definition newgrf_config.cpp:622
newgrf_internal.h
NewGRF internal processing state.
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition newgrf_config.h:158
GRFConfig::filename
std::string filename
Filename - either with or without full path.
Definition newgrf_config.h:170
GRFConfig::ident
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Definition newgrf_config.h:168
GRFConfig::GetName
std::string GetName() const
Get the name of this grf.
Definition newgrf_config.cpp:85
GRFError
Information about why GRF had problems during initialisation.
Definition newgrf_config.h:109
GRFError::data
std::string data
Additional data for message and custom_message.
Definition newgrf_config.h:114
GRFIdentifier::grfid
uint32_t grfid
GRF ID (defined by Action 0x08)
Definition newgrf_config.h:84
GrfActionHandler
GRF action handler.
Definition newgrf_internal.h:37
GrfProcessingState::grfconfig
GRFConfig * grfconfig
Config of the currently processed GRF file.
Definition newgrf_internal.h:68