OpenTTD Source 20260208-master-g43af8e94d0
newgrf_act0_canals.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
9
10#include "../stdafx.h"
11#include "../debug.h"
12#include "newgrf_bytereader.h"
13#include "newgrf_internal.h"
14
15#include "../safeguards.h"
16
25static ChangeInfoResult CanalChangeInfo(uint first, uint last, int prop, ByteReader &buf)
26{
28
29 if (last > CF_END) {
30 GrfMsg(1, "CanalChangeInfo: Canal feature 0x{:02X} is invalid, max {}, ignoring", last, CF_END);
31 return CIR_INVALID_ID;
32 }
33
34 for (uint id = first; id < last; ++id) {
35 CanalProperties *cp = &_cur_gps.grffile->canal_local_properties[id];
36
37 switch (prop) {
38 case 0x08:
39 cp->callback_mask = static_cast<CanalCallbackMasks>(buf.ReadByte());
40 break;
41
42 case 0x09:
43 cp->flags = buf.ReadByte();
44 break;
45
46 default:
47 ret = CIR_UNKNOWN;
48 break;
49 }
50 }
51
52 return ret;
53}
54
55template <> ChangeInfoResult GrfChangeInfoHandler<GSF_CANALS>::Reserve(uint, uint, int, ByteReader &) { return CIR_UNHANDLED; }
56template <> ChangeInfoResult GrfChangeInfoHandler<GSF_CANALS>::Activation(uint first, uint last, int prop, ByteReader &buf) { return CanalChangeInfo(first, last, prop, buf); }
Class to read from a NewGRF file.
uint8_t ReadByte()
Read a single byte (8 bits).
Functions related to debugging.
static ChangeInfoResult CanalChangeInfo(uint first, uint last, int prop, ByteReader &buf)
Define properties for water features.
NewGRF buffer reader definition.
NewGRF internal processing state.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ CIR_INVALID_ID
Attempt to modify an invalid ID.
@ CIR_UNKNOWN
Variable is unknown.
@ CIR_UNHANDLED
Variable was parsed but unread.
@ CIR_SUCCESS
Variable was parsed and read.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
Canal properties local to the NewGRF.
Definition newgrf.h:41
CanalCallbackMasks callback_mask
Bitmask of canal callbacks that have to be called.
Definition newgrf.h:42
uint8_t flags
Flags controlling display.
Definition newgrf.h:43