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

OpenTTD Source 15.3

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
10#include "../stdafx.h"
11#include "../debug.h"
12#include "newgrf_bytereader.h"
13#include "newgrf_internal.h"
14
15#include "../safeguards.h"
16
25 static ChangeInfoResult CanalChangeInfo(uint first, uint last, int prop, ByteReader &buf)
26{
27 ChangeInfoResult ret = CIR_SUCCESS;
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); }
ByteReader
Class to read from a NewGRF file.
Definition newgrf_bytereader.h:18
ByteReader::ReadByte
uint8_t ReadByte()
Read a single byte (8 bits).
Definition newgrf_bytereader.h:34
EnumBitSet< CanalCallbackMask, uint8_t >
CanalChangeInfo
static ChangeInfoResult CanalChangeInfo(uint first, uint last, int prop, ByteReader &buf)
Define properties for water features.
Definition newgrf_act0_canals.cpp:25
newgrf_bytereader.h
NewGRF buffer reader definition.
newgrf_internal.h
NewGRF internal processing state.
ChangeInfoResult
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
Definition newgrf_internal.h:20
CIR_INVALID_ID
@ CIR_INVALID_ID
Attempt to modify an invalid ID.
Definition newgrf_internal.h:25
CIR_UNKNOWN
@ CIR_UNKNOWN
Variable is unknown.
Definition newgrf_internal.h:24
CIR_UNHANDLED
@ CIR_UNHANDLED
Variable was parsed but unread.
Definition newgrf_internal.h:23
CIR_SUCCESS
@ CIR_SUCCESS
Variable was parsed and read.
Definition newgrf_internal.h:21
CanalProperties
Canal properties local to the NewGRF.
Definition newgrf.h:39
CanalProperties::callback_mask
CanalCallbackMasks callback_mask
Bitmask of canal callbacks that have to be called.
Definition newgrf.h:40
CanalProperties::flags
uint8_t flags
Flags controlling display.
Definition newgrf.h:41
GRFFile::canal_local_properties
std::array< CanalProperties, CF_END > canal_local_properties
Canal properties as set by this NewGRF.
Definition newgrf.h:150
GrfChangeInfoHandler
GRF feature handler.
Definition newgrf_internal.h:30
GrfProcessingState::grffile
GRFFile * grffile
Currently processed GRF file.
Definition newgrf_internal.h:67