OpenTTD Source 20260721-master-g25ec12c62d
newgrf_act0_roadstops.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_engine.h"
13#include "../newgrf_roadstop.h"
14#include "newgrf_bytereader.h"
15#include "newgrf_internal.h"
17
18#include "../safeguards.h"
19
27{
29
30 switch (prop) {
31 case 0x09:
32 case 0x0C:
33 case 0x0F:
34 case 0x11:
35 buf.ReadByte();
36 break;
37
38 case 0x0A:
39 case 0x0B:
40 case 0x0E:
41 case 0x10:
42 case 0x15:
43 buf.ReadWord();
44 break;
45
46 case 0x08:
47 case 0x0D:
48 case 0x12:
49 buf.ReadDWord();
50 break;
51
52 case 0x13:
53 case 0x14:
54 buf.Skip(buf.ReadExtendedByte());
55 break;
56
57 case 0x16: // Badge list
58 SkipBadgeList(buf);
59 break;
60
61 default:
63 break;
64 }
65
66 return ret;
67}
68
69static ChangeInfoResult RoadStopChangeInfo(uint first, uint last, int prop, ByteReader &buf)
70{
72
73 if (last > NUM_ROADSTOPS_PER_GRF) {
74 GrfMsg(1, "RoadStopChangeInfo: RoadStop {} is invalid, max {}, ignoring", last, NUM_ROADSTOPS_PER_GRF);
76 }
77
78 if (_cur_gps.grffile->roadstops.size() < last) _cur_gps.grffile->roadstops.resize(last);
79
80 for (uint id = first; id < last; ++id) {
81 auto &rs = _cur_gps.grffile->roadstops[id];
82
83 if (rs == nullptr && prop != 0x08) {
84 GrfMsg(1, "RoadStopChangeInfo: Attempt to modify undefined road stop {}, ignoring", id);
86 if (cir > ret) ret = cir;
87 continue;
88 }
89
90 switch (prop) {
91 case 0x08: // Road Stop Class ID
92 if (rs == nullptr) {
93 rs = std::make_unique<RoadStopSpec>();
94 }
95
97 break;
98
99 case 0x09: // Road stop type
100 rs->stop_type = (RoadStopAvailabilityType)buf.ReadByte();
101 break;
102
103 case 0x0A: // Road Stop Name
104 AddStringForMapping(GRFStringID{buf.ReadWord()}, &rs->name);
105 break;
106
107 case 0x0B: // Road Stop Class name
108 AddStringForMapping(GRFStringID{buf.ReadWord()}, [rs = rs.get()](StringID str) { RoadStopClass::Get(rs->class_index)->name = str; });
109 break;
110
111 case 0x0C: // The draw modes
112 rs->draw_mode = static_cast<RoadStopDrawModes>(buf.ReadByte());
113 break;
114
115 case 0x0D: // Cargo types for random triggers
116 rs->cargo_triggers = TranslateRefitMask(buf.ReadDWord());
117 break;
118
119 case 0x0E: // Animation info
120 rs->animation.frames = buf.ReadByte();
121 rs->animation.status = static_cast<AnimationStatus>(buf.ReadByte());
122 break;
123
124 case 0x0F: // Animation speed
125 rs->animation.speed = buf.ReadByte();
126 break;
127
128 case 0x10: // Animation triggers
129 rs->animation.triggers = static_cast<StationAnimationTriggers>(buf.ReadWord());
130 break;
131
132 case 0x11: // Callback mask
133 rs->callback_mask = static_cast<RoadStopCallbackMasks>(buf.ReadByte());
134 break;
135
136 case 0x12: // General flags
137 rs->flags = static_cast<RoadStopSpecFlags>(buf.ReadDWord()); // Future-proofing, size this as 4 bytes, but we only need two byte's worth of flags at present
138 break;
139
140 case 0x13: { // Minimum bridge height for each of the roadstop's tile layouts.
141 uint16_t tiles = buf.ReadExtendedByte();
142 for (uint j = 0; j != tiles; ++j) {
143 if (j < std::size(rs->bridgeable_info)) {
144 rs->bridgeable_info[j].height = buf.ReadByte();
145 } else {
146 buf.ReadByte();
147 }
148 }
149 break;
150 }
151
152 case 0x14: { // Disallowed pillars for each of the roadstop's tile layouts.
153 uint16_t tiles = buf.ReadExtendedByte();
154 for (uint j = 0; j != tiles; ++j) {
155 if (j < std::size(rs->bridgeable_info)) {
156 rs->bridgeable_info[j].disallowed_pillars = BridgePillarFlags{buf.ReadByte()};
157 } else {
158 buf.ReadByte();
159 }
160 }
161 break;
162 }
163
164 case 0x15: // Cost multipliers
165 rs->build_cost_multiplier = buf.ReadByte();
166 rs->clear_cost_multiplier = buf.ReadByte();
167 break;
168
169 case 0x16: // Badge list
170 rs->badges = ReadBadgeList(buf, GrfSpecFeature::RoadStops);
171 break;
172
173 default:
175 break;
176 }
177 }
178
179 return ret;
180}
181
185template <> ChangeInfoResult GrfChangeInfoHandler<GrfSpecFeature::RoadStops>::Activation(uint first, uint last, int prop, ByteReader &buf) { return RoadStopChangeInfo(first, last, prop, buf); }
EnumBitSet< BridgePillarFlag, uint8_t > BridgePillarFlags
Bitset of BridgePillarFlag elements.
Definition bridge_type.h:53
Class to read from a NewGRF file.
uint32_t ReadDWord()
Read a single DWord (32 bits).
uint16_t ReadWord()
Read a single Word (16 bits).
T ReadLabel()
Read a label.
uint16_t ReadExtendedByte()
Read a single Extended Byte (8 or 16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
static NewGRFClass * Get(RoadStopClassID class_index)
StringID name
Name of this class.
Label< NewGRFClass< RoadStopSpec, RoadStopClassID > > GlobalID
static RoadStopClassID Allocate(GlobalID global_id)
Functions related to debugging.
CargoTypes TranslateRefitMask(uint32_t refit_mask)
Translate the refit mask.
Definition newgrf.cpp:322
@ RoadStops
Road stops feature.
Definition newgrf.h:99
std::vector< BadgeID > ReadBadgeList(ByteReader &buf, GrfSpecFeature feature)
Read a list of badges.
void SkipBadgeList(ByteReader &buf)
Skip a list of badges.
static ChangeInfoResult IgnoreRoadStopProperty(uint prop, ByteReader &buf)
Ignore properties for roadstops.
AnimationStatus
Statuses of animation within NewGRFs.
NewGRF buffer reader definition.
EnumBitSet< RoadStopCallbackMask, uint8_t > RoadStopCallbackMasks
Bitset of RoadStopCallbackMask elements.
Functions for NewGRF engines.
NewGRF internal processing state.
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
@ Success
Variable was parsed and read.
@ Unhandled
Variable was parsed but unread.
@ Unknown
Variable is unknown.
@ InvalidId
Attempt to modify an invalid ID.
NewGRF definitions and structures for road stops.
EnumBitSet< RoadStopSpecFlag, uint8_t > RoadStopSpecFlags
Bitset of RoadStopSpecFlag elements.
EnumBitSet< RoadStopDrawMode, uint8_t > RoadStopDrawModes
Bitset of RoadStopDrawMode elements.
RoadStopAvailabilityType
Various different options for availability, restricting the roadstop to be only for busses or for tru...
static const int NUM_ROADSTOPS_PER_GRF
The maximum amount of roadstops a single GRF is allowed to add.
void AddStringForMapping(GRFStringID source, std::function< void(StringID)> &&func)
Record a static StringID for getting translated later.
NewGRF string mapping definition.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
A number of safeguards to prevent using unsafe methods.
EnumBitSet< StationAnimationTrigger, uint16_t > StationAnimationTriggers
Bitset of StationAnimationTrigger elements.
Definition of base types and functions in a cross-platform compatible way.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static ChangeInfoResult Reserve(uint first, uint last, int prop, ByteReader &buf)
Implementation of the GrfLoadingStage::Reserve stage of this feature.
static ChangeInfoResult Activation(uint first, uint last, int prop, ByteReader &buf)
Implementation of the GrfLoadingStage::Activation stage of this feature.