OpenTTD Source 15.0-beta3
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 <http://www.gnu.org/licenses/>.
6 */
7
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.ReadWord();
55 buf.ReadWord();
56 buf.ReadWord();
57 break;
58
59 case 0x16: // Badge list
60 SkipBadgeList(buf);
61 break;
62
63 default:
64 ret = CIR_UNKNOWN;
65 break;
66 }
67
68 return ret;
69}
70
71static ChangeInfoResult RoadStopChangeInfo(uint first, uint last, int prop, ByteReader &buf)
72{
74
75 if (last > NUM_ROADSTOPS_PER_GRF) {
76 GrfMsg(1, "RoadStopChangeInfo: RoadStop {} is invalid, max {}, ignoring", last, NUM_ROADSTOPS_PER_GRF);
77 return CIR_INVALID_ID;
78 }
79
80 if (_cur_gps.grffile->roadstops.size() < last) _cur_gps.grffile->roadstops.resize(last);
81
82 for (uint id = first; id < last; ++id) {
83 auto &rs = _cur_gps.grffile->roadstops[id];
84
85 if (rs == nullptr && prop != 0x08) {
86 GrfMsg(1, "RoadStopChangeInfo: Attempt to modify undefined road stop {}, ignoring", id);
88 if (cir > ret) ret = cir;
89 continue;
90 }
91
92 switch (prop) {
93 case 0x08: { // Road Stop Class ID
94 if (rs == nullptr) {
95 rs = std::make_unique<RoadStopSpec>();
96 }
97
98 uint32_t classid = buf.ReadDWord();
99 rs->class_index = RoadStopClass::Allocate(std::byteswap(classid));
100 break;
101 }
102
103 case 0x09: // Road stop type
104 rs->stop_type = (RoadStopAvailabilityType)buf.ReadByte();
105 break;
106
107 case 0x0A: // Road Stop Name
108 AddStringForMapping(GRFStringID{buf.ReadWord()}, &rs->name);
109 break;
110
111 case 0x0B: // Road Stop Class name
112 AddStringForMapping(GRFStringID{buf.ReadWord()}, [rs = rs.get()](StringID str) { RoadStopClass::Get(rs->class_index)->name = str; });
113 break;
114
115 case 0x0C: // The draw modes
116 rs->draw_mode = static_cast<RoadStopDrawModes>(buf.ReadByte());
117 break;
118
119 case 0x0D: // Cargo types for random triggers
120 rs->cargo_triggers = TranslateRefitMask(buf.ReadDWord());
121 break;
122
123 case 0x0E: // Animation info
124 rs->animation.frames = buf.ReadByte();
125 rs->animation.status = static_cast<AnimationStatus>(buf.ReadByte());
126 break;
127
128 case 0x0F: // Animation speed
129 rs->animation.speed = buf.ReadByte();
130 break;
131
132 case 0x10: // Animation triggers
133 rs->animation.triggers = static_cast<StationAnimationTriggers>(buf.ReadWord());
134 break;
135
136 case 0x11: // Callback mask
137 rs->callback_mask = static_cast<RoadStopCallbackMasks>(buf.ReadByte());
138 break;
139
140 case 0x12: // General flags
141 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
142 break;
143
144 case 0x13: { // Minimum bridge height for each of the roadstop's tile layouts.
145 uint16_t tiles = buf.ReadExtendedByte();
146 for (uint j = 0; j != tiles; ++j) {
147 if (j < std::size(rs->bridgeable_info)) {
148 rs->bridgeable_info[j].height = buf.ReadByte();
149 } else {
150 buf.ReadByte();
151 }
152 }
153 break;
154 }
155
156 case 0x14: { // Disallowed pillars for each of the roadstop's tile layouts.
157 uint16_t tiles = buf.ReadExtendedByte();
158 for (uint j = 0; j != tiles; ++j) {
159 if (j < std::size(rs->bridgeable_info)) {
160 rs->bridgeable_info[j].disallowed_pillars = BridgePillarFlags{buf.ReadByte()};
161 } else {
162 buf.ReadByte();
163 }
164 }
165 break;
166 }
167
168 case 0x15: // Cost multipliers
169 rs->build_cost_multiplier = buf.ReadByte();
170 rs->clear_cost_multiplier = buf.ReadByte();
171 break;
172
173 case 0x16: // Badge list
174 rs->badges = ReadBadgeList(buf, GSF_ROADSTOPS);
175 break;
176
177 default:
178 ret = CIR_UNKNOWN;
179 break;
180 }
181 }
182
183 return ret;
184}
185
187template <> ChangeInfoResult GrfChangeInfoHandler<GSF_ROADSTOPS>::Activation(uint first, uint last, int prop, ByteReader &buf) { return RoadStopChangeInfo(first, last, prop, buf); }
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).
uint16_t ReadExtendedByte()
Read a single Extended Byte (8 or 16 bits).
uint8_t ReadByte()
Read a single byte (8 bits).
StringID name
Name of this class.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
static Tindex Allocate(uint32_t global_id)
Allocate a class with a given global class ID.
CargoTypes TranslateRefitMask(uint32_t refit_mask)
Translate the refit mask.
Definition newgrf.cpp:311
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.
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.
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.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
GRF feature handler.
GRFFile * grffile
Currently processed GRF file.