OpenTTD Source: src/newgrf_station.cpp Source File

OpenTTD Source 15.0-RC2

newgrf_station.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 "station_base.h"
13#include "waypoint_base.h"
14#include "roadstop_base.h"
15#include "newgrf_badge.h"
16#include "newgrf_cargo.h"
17#include "newgrf_station.h"
18#include "newgrf_spritegroup.h"
19#include "newgrf_sound.h"
20#include "newgrf_railtype.h"
21#include "town.h"
22#include "newgrf_town.h"
23#include "company_func.h"
24#include "tunnelbridge_map.h"
25#include "newgrf_animation_base.h"
26#include "timer/timer_game_calendar.h"
27
28#include "table/strings.h"
29
30#include "newgrf_class_func.h"
31
32#include "safeguards.h"
33
34
35template <>
36/* static */ void StationClass::InsertDefaults()
37{
38 /* Set up initial data */
39 StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_DEFAULT))->name = STR_STATION_CLASS_DFLT;
40 StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_DEFAULT))->Insert(nullptr);
41 StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_WAYPOINT))->name = STR_STATION_CLASS_WAYP;
42 StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_WAYPOINT))->Insert(nullptr);
43}
44
45template <>
46bool StationClass::IsUIAvailable(uint) const
47{
48 return true;
49}
50
51/* Instantiate StationClass. */
52template class NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX>;
53
54 static const uint NUM_STATIONSSPECS_PER_STATION = 255;
55
60uint8_t GoodsEntry::ConvertState() const
61{
62 uint8_t res = 0;
63 if (this->status.Test(GoodsEntry::State::EverAccepted)) SetBit(res, 0);
64 if (this->status.Test(GoodsEntry::State::LastMonth)) SetBit(res, 1);
65 if (this->status.Test(GoodsEntry::State::CurrentMonth)) SetBit(res, 2);
66 if (this->status.Test(GoodsEntry::State::AcceptedBigtick)) SetBit(res, 3);
67 return res;
68}
69
70enum TriggerArea : uint8_t {
71 TA_TILE,
72 TA_PLATFORM,
73 TA_WHOLE,
74};
75
83 TileArea GetRailTileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
84{
85 switch (ta) {
86 default: NOT_REACHED();
87
88 case TA_TILE:
89 return {tile, 1, 1};
90
91 case TA_PLATFORM: {
92 TileIndex start, end;
93 Axis axis = GetRailStationAxis(tile);
94 TileIndexDiff delta = TileOffsByAxis(axis);
95
96 for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(end + delta, tile); end += delta) { /* Nothing */ }
97 for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(start - delta, tile); start -= delta) { /* Nothing */ }
98
99 return TileArea(start, TileX(end) - TileX(start) + 1, TileY(end) - TileY(start) + 1);
100 }
101
102 case TA_WHOLE:
103 return st->GetTileArea(Station::IsExpected(st) ? StationType::Rail : StationType::RailWaypoint);
104 }
105}
106
107
120uint32_t GetPlatformInfo(Axis axis, uint8_t tile, int platforms, int length, int x, int y, bool centred)
121{
122 uint32_t retval = 0;
123
124 if (axis == AXIS_X) {
125 std::swap(platforms, length);
126 std::swap(x, y);
127 }
128
129 if (centred) {
130 x -= platforms / 2;
131 y -= length / 2;
132 x = Clamp(x, -8, 7);
133 y = Clamp(y, -8, 7);
134 SB(retval, 0, 4, y & 0xF);
135 SB(retval, 4, 4, x & 0xF);
136 } else {
137 SB(retval, 0, 4, std::min(15, y));
138 SB(retval, 4, 4, std::min(15, length - y - 1));
139 SB(retval, 8, 4, std::min(15, x));
140 SB(retval, 12, 4, std::min(15, platforms - x - 1));
141 }
142 SB(retval, 16, 4, std::min(15, length));
143 SB(retval, 20, 4, std::min(15, platforms));
144 SB(retval, 24, 8, tile);
145
146 return retval;
147}
148
149
158 static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
159{
160 uint8_t orig_type = 0;
161 Axis orig_axis = AXIS_X;
162 StationID sid = GetStationIndex(tile);
163
164 if (check_type) orig_type = GetCustomStationSpecIndex(tile);
165 if (check_axis) orig_axis = GetRailStationAxis(tile);
166
167 for (;;) {
168 TileIndex new_tile = TileAdd(tile, delta);
169
170 if (!IsTileType(new_tile, MP_STATION) || GetStationIndex(new_tile) != sid) break;
171 if (!HasStationRail(new_tile)) break;
172 if (check_type && GetCustomStationSpecIndex(new_tile) != orig_type) break;
173 if (check_axis && GetRailStationAxis(new_tile) != orig_axis) break;
174
175 tile = new_tile;
176 }
177 return tile;
178}
179
180
181static uint32_t GetPlatformInfoHelper(TileIndex tile, bool check_type, bool check_axis, bool centred)
182{
183 int tx = TileX(tile);
184 int ty = TileY(tile);
185 int sx = TileX(FindRailStationEnd(tile, TileDiffXY(-1, 0), check_type, check_axis));
186 int sy = TileY(FindRailStationEnd(tile, TileDiffXY( 0, -1), check_type, check_axis));
187 int ex = TileX(FindRailStationEnd(tile, TileDiffXY( 1, 0), check_type, check_axis)) + 1;
188 int ey = TileY(FindRailStationEnd(tile, TileDiffXY( 0, 1), check_type, check_axis)) + 1;
189
190 tx -= sx; ex -= sx;
191 ty -= sy; ey -= sy;
192
193 return GetPlatformInfo(GetRailStationAxis(tile), GetStationGfx(tile), ex, ey, tx, ty, centred);
194}
195
196
197static uint32_t GetRailContinuationInfo(TileIndex tile)
198{
199 /* Tile offsets and exit dirs for X axis */
200 static const Direction x_dir[8] = { DIR_SW, DIR_NE, DIR_SE, DIR_NW, DIR_S, DIR_E, DIR_W, DIR_N };
201 static const DiagDirection x_exits[8] = { DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SW, DIAGDIR_NE };
202
203 /* Tile offsets and exit dirs for Y axis */
204 static const Direction y_dir[8] = { DIR_SE, DIR_NW, DIR_SW, DIR_NE, DIR_S, DIR_W, DIR_E, DIR_N };
205 static const DiagDirection y_exits[8] = { DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_NW };
206
207 Axis axis = GetRailStationAxis(tile);
208
209 /* Choose appropriate lookup table to use */
210 const Direction *dir = axis == AXIS_X ? x_dir : y_dir;
211 const DiagDirection *diagdir = axis == AXIS_X ? x_exits : y_exits;
212
213 uint32_t res = 0;
214 uint i;
215
216 for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) {
217 TileIndex neighbour_tile = tile + TileOffsByDir(*dir);
218 TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(neighbour_tile, TRANSPORT_RAIL, 0));
219 if (trackbits != TRACK_BIT_NONE) {
220 /* If there is any track on the tile, set the bit in the second byte */
221 SetBit(res, i + 8);
222
223 /* With tunnels and bridges the tile has tracks, but they are not necessarily connected
224 * with the next tile because the ramp is not going in the right direction. */
225 if (IsTileType(neighbour_tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(neighbour_tile) != *diagdir) {
226 continue;
227 }
228
229 /* If any track reaches our exit direction, set the bit in the lower byte */
230 if (trackbits & DiagdirReachesTracks(*diagdir)) SetBit(res, i);
231 }
232 }
233
234 return res;
235}
236
237
238/* Station Resolver Functions */
239/* virtual */ uint32_t StationScopeResolver::GetRandomBits() const
240{
241 return (this->st == nullptr ? 0 : this->st->random_bits) | (this->tile == INVALID_TILE ? 0 : GetStationTileRandomBits(this->tile) << 16);
242}
243
244
245/* virtual */ uint32_t StationScopeResolver::GetRandomTriggers() const
246{
247 return this->st == nullptr ? 0 : this->st->waiting_random_triggers.base();
248}
249
250
256 TownScopeResolver *StationResolverObject::GetTown()
257{
258 if (!this->town_scope.has_value()) {
259 Town *t = nullptr;
260 if (this->station_scope.st != nullptr) {
261 t = this->station_scope.st->town;
262 } else if (this->station_scope.tile != INVALID_TILE) {
263 t = ClosestTownFromTile(this->station_scope.tile, UINT_MAX);
264 }
265 if (t == nullptr) return nullptr;
266 this->town_scope.emplace(*this, t, this->station_scope.st == nullptr);
267 }
268 return &*this->town_scope;
269}
270
271/* virtual */ uint32_t StationScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
272{
273 if (this->st == nullptr) {
274 /* Station does not exist, so we're in a purchase list or the land slope check callback. */
275 switch (variable) {
276 case 0x40:
277 case 0x41:
278 case 0x46:
279 case 0x47:
280 case 0x49: return 0x2110000; // Platforms, tracks & position
281 case 0x42: return 0; // Rail type (XXX Get current type from GUI?)
282 case 0x43: return GetCompanyInfo(_current_company); // Station owner
283 case 0x44: return 2; // PBS status
284 case 0x67: // Land info of nearby tile
285 if (this->axis != INVALID_AXIS && this->tile != INVALID_TILE) {
286 TileIndex tile = this->tile;
287 if (parameter != 0) tile = GetNearbyTile(parameter, tile, true, this->axis); // only perform if it is required
288
289 Slope tileh = GetTileSlope(tile);
290 bool swap = (this->axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
291
292 return GetNearbyTileInformation(tile, this->ro.grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
293 }
294 break;
295
296 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter);
297
298 case 0xFA: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value
299 }
300
301 available = false;
302 return UINT_MAX;
303 }
304
305 switch (variable) {
306 /* Calculated station variables */
307 case 0x40:
308 if (!this->cache.v40.has_value()) this->cache.v40 = GetPlatformInfoHelper(this->tile, false, false, false);
309 return *this->cache.v40;
310
311 case 0x41:
312 if (!this->cache.v41.has_value()) this->cache.v41 = GetPlatformInfoHelper(this->tile, true, false, false);
313 return *this->cache.v41;
314
315 case 0x42: return GetTerrainType(this->tile) | (GetReverseRailTypeTranslation(GetRailType(this->tile), this->statspec->grf_prop.grffile) << 8);
316 case 0x43: return GetCompanyInfo(this->st->owner); // Station owner
317 case 0x44: return HasStationReservation(this->tile) ? 7 : 4; // PBS status
318 case 0x45:
319 if (!this->cache.v45.has_value()) this->cache.v45 = GetRailContinuationInfo(this->tile);
320 return *this->cache.v45;
321
322 case 0x46:
323 if (!this->cache.v46.has_value()) this->cache.v46 = GetPlatformInfoHelper(this->tile, false, false, true);
324 return *this->cache.v46;
325
326 case 0x47:
327 if (!this->cache.v47.has_value()) this->cache.v47 = GetPlatformInfoHelper(this->tile, true, false, true);
328 return *this->cache.v47;
329
330 case 0x49:
331 if (!this->cache.v49.has_value()) this->cache.v49 = GetPlatformInfoHelper(this->tile, false, true, false);
332 return *this->cache.v49;
333
334 case 0x4A: // Animation frame of tile
335 return GetAnimationFrame(this->tile);
336
337 /* Variables which use the parameter */
338 /* Variables 0x60 to 0x65 and 0x69 are handled separately below */
339 case 0x66: { // Animation frame of nearby tile
340 TileIndex tile = this->tile;
341 if (parameter != 0) tile = GetNearbyTile(parameter, tile);
342 return this->st->TileBelongsToRailStation(tile) ? GetAnimationFrame(tile) : UINT_MAX;
343 }
344
345 case 0x67: { // Land info of nearby tile
346 Axis axis = GetRailStationAxis(this->tile);
347 TileIndex tile = this->tile;
348 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
349
350 Slope tileh = GetTileSlope(tile);
351 bool swap = (axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
352
353 return GetNearbyTileInformation(tile, this->ro.grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
354 }
355
356 case 0x68: { // Station info of nearby tiles
357 TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
358
359 if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
360
361 uint32_t grfid = this->st->speclist[GetCustomStationSpecIndex(this->tile)].grfid;
362 bool perpendicular = GetRailStationAxis(this->tile) != GetRailStationAxis(nearby_tile);
363 bool same_station = this->st->TileBelongsToRailStation(nearby_tile);
364 uint32_t res = GB(GetStationGfx(nearby_tile), 1, 2) << 12 | !!perpendicular << 11 | !!same_station << 10;
365
366 if (IsCustomStationSpecIndex(nearby_tile)) {
367 const auto &sm = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
368 res |= 1 << (sm.grfid != grfid ? 9 : 8) | ClampTo<uint8_t>(sm.localidx);
369 }
370 return res;
371 }
372
373 case 0x6A: { // GRFID of nearby station tiles
374 TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
375
376 if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
377 if (!IsCustomStationSpecIndex(nearby_tile)) return 0;
378
379 const auto &sm = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
380 return sm.grfid;
381 }
382
383 case 0x6B: { // 16 bit Station ID of nearby tiles
384 TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
385
386 if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
387 if (!IsCustomStationSpecIndex(nearby_tile)) return 0xFFFE;
388
389 uint32_t grfid = this->st->speclist[GetCustomStationSpecIndex(this->tile)].grfid;
390
391 const auto &sm = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
392 if (sm.grfid == grfid) {
393 return sm.localidx;
394 }
395
396 return 0xFFFE;
397 }
398
399 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->statspec->badges, parameter);
400
401 /* General station variables */
402 case 0x82: return 50;
403 case 0x84: return this->st->string_id;
404 case 0x86: return 0;
405 case 0xF0: return this->st->facilities.base();
406 case 0xFA: return ClampTo<uint16_t>(this->st->build_date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR);
407 }
408
409 return this->st->GetNewGRFVariable(this->ro, variable, parameter, available);
410}
411
412uint32_t Station::GetNewGRFVariable(const ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const
413{
414 switch (variable) {
415 case 0x48: { // Accepted cargo types
416 uint32_t value = GetAcceptanceMask(this);
417 return value;
418 }
419
420 case 0x8A: return this->had_vehicle_of_type;
421 case 0xF1: return (this->airport.tile != INVALID_TILE) ? this->airport.GetSpec()->ttd_airport_type : ATP_TTDP_LARGE;
422 case 0xF2: return (this->truck_stops != nullptr) ? this->truck_stops->status.base() : 0;
423 case 0xF3: return (this->bus_stops != nullptr) ? this->bus_stops->status.base() : 0;
424 case 0xF6: return this->airport.blocks.base();
425 case 0xF7: return GB(this->airport.blocks.base(), 8, 8);
426 }
427
428 /* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */
429 if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) {
430 CargoType cargo = GetCargoTranslation(parameter, object.grffile);
431
432 if (!IsValidCargoType(cargo)) {
433 switch (variable) {
434 case 0x62: return 0xFFFFFFFF;
435 case 0x64: return 0xFF00;
436 default: return 0;
437 }
438 }
439 const GoodsEntry *ge = &this->goods[cargo];
440
441 switch (variable) {
442 case 0x60: return ge->HasData() ? std::min(ge->GetData().cargo.TotalCount(), 4095u) : 0;
443 case 0x61: return ge->HasVehicleEverTriedLoading() ? ge->time_since_pickup : 0;
444 case 0x62: return ge->HasRating() ? ge->rating : 0xFFFFFFFF;
445 case 0x63: return ge->HasData() ? ge->GetData().cargo.PeriodsInTransit() : 0;
446 case 0x64: return ge->HasVehicleEverTriedLoading() ? ge->last_speed | (ge->last_age << 8) : 0xFF00;
447 case 0x65: return ge->status.Test(GoodsEntry::State::Acceptance) ? (1U << 3) : 0;
448 case 0x69: return ge->ConvertState();
449 }
450 }
451
452 /* Handle cargo variables (deprecated) */
453 if (variable >= 0x8C && variable <= 0xEC) {
454 const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)];
455 switch (GB(variable - 0x8C, 0, 3)) {
456 case 0: return g->HasData() ? g->GetData().cargo.TotalCount() : 0;
457 case 1: return GB(g->HasData() ? std::min(g->GetData().cargo.TotalCount(), 4095u) : 0, 0, 4) | (g->status.Test(GoodsEntry::State::Acceptance) ? (1U << 7) : 0);
458 case 2: return g->time_since_pickup;
459 case 3: return g->rating;
460 case 4: return (g->HasData() ? g->GetData().cargo.GetFirstStation() : StationID::Invalid()).base();
461 case 5: return g->HasData() ? g->GetData().cargo.PeriodsInTransit() : 0;
462 case 6: return g->last_speed;
463 case 7: return g->last_age;
464 }
465 }
466
467 Debug(grf, 1, "Unhandled station variable 0x{:X}", variable);
468
469 available = false;
470 return UINT_MAX;
471}
472
473uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, uint8_t variable, [[maybe_unused]] uint8_t parameter, bool &available) const
474{
475 switch (variable) {
476 case 0x48: return 0; // Accepted cargo types
477 case 0x8A: return HVOT_WAYPOINT;
478 case 0xF1: return 0; // airport type
479 case 0xF2: return 0; // truck stop status
480 case 0xF3: return 0; // bus stop status
481 case 0xF6: return 0; // airport flags
482 case 0xF7: return 0; // airport flags cont.
483 }
484
485 /* Handle cargo variables with parameter, 0x60 to 0x65 */
486 if (variable >= 0x60 && variable <= 0x65) {
487 return 0;
488 }
489
490 /* Handle cargo variables (deprecated) */
491 if (variable >= 0x8C && variable <= 0xEC) {
492 switch (GB(variable - 0x8C, 0, 3)) {
493 case 3: return INITIAL_STATION_RATING;
494 case 4: return StationID::Invalid().base();
495 default: return 0;
496 }
497 }
498
499 Debug(grf, 1, "Unhandled station variable 0x{:X}", variable);
500
501 available = false;
502 return UINT_MAX;
503}
504
505/* virtual */ const SpriteGroup *StationResolverObject::ResolveReal(const RealSpriteGroup &group) const
506{
507 if (this->station_scope.st == nullptr || !Station::IsExpected(this->station_scope.st)) {
508 if (!group.loading.empty()) return group.loading[0];
509 return nullptr;
510 }
511
512 uint cargo = 0;
513 const Station *st = Station::From(this->station_scope.st);
514
515 switch (this->station_scope.cargo_type) {
516 case INVALID_CARGO:
517 case CargoGRFFileProps::SG_DEFAULT_NA:
518 case CargoGRFFileProps::SG_PURCHASE:
519 cargo = 0;
520 break;
521
522 case CargoGRFFileProps::SG_DEFAULT:
523 for (const GoodsEntry &ge : st->goods) {
524 if (!ge.HasData()) continue;
525 cargo += ge.GetData().cargo.TotalCount();
526 }
527 break;
528
529 default: {
530 const GoodsEntry &ge = st->goods[this->station_scope.cargo_type];
531 cargo = ge.HasData() ? ge.GetData().cargo.TotalCount() : 0;
532 break;
533 }
534 }
535
536 if (this->station_scope.statspec->flags.Test(StationSpecFlag::DivByStationSize)) cargo /= (st->train_station.w + st->train_station.h);
537 cargo = std::min(0xfffu, cargo);
538
539 if (cargo > this->station_scope.statspec->cargo_threshold) {
540 if (!group.loading.empty()) {
541 uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * static_cast<uint>(group.loading.size())) / (4096 - this->station_scope.statspec->cargo_threshold);
542 return group.loading[set];
543 }
544 } else {
545 if (!group.loaded.empty()) {
546 uint set = (cargo * static_cast<uint>(group.loaded.size())) / (this->station_scope.statspec->cargo_threshold + 1);
547 return group.loaded[set];
548 }
549 }
550
551 if (!group.loading.empty()) return group.loading[0];
552 return nullptr;
553}
554
555 GrfSpecFeature StationResolverObject::GetFeature() const
556{
557 return GSF_STATIONS;
558}
559
560uint32_t StationResolverObject::GetDebugID() const
561{
562 return this->station_scope.statspec->grf_prop.local_id;
563}
564
574StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseStation *base_station, TileIndex tile,
575 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
576 : SpecializedResolverObject<StationRandomTriggers>(statspec->grf_prop.grffile, callback, callback_param1, callback_param2),
577 station_scope(*this, statspec, base_station, tile)
578{
579 CargoType ctype = CargoGRFFileProps::SG_DEFAULT_NA;
580
581 if (this->station_scope.st == nullptr) {
582 /* No station, so we are in a purchase list */
583 ctype = CargoGRFFileProps::SG_PURCHASE;
584 } else if (Station::IsExpected(this->station_scope.st)) {
585 const Station *st = Station::From(this->station_scope.st);
586 /* Pick the first cargo that we have waiting */
587 for (const auto &[cargo, spritegroup] : statspec->grf_prop.spritegroups) {
588 if (cargo < NUM_CARGO && st->goods[cargo].HasData() && st->goods[cargo].GetData().cargo.TotalCount() > 0) {
589 ctype = cargo;
590 break;
591 }
592 }
593 }
594
595 this->root_spritegroup = this->station_scope.statspec->grf_prop.GetSpriteGroup(ctype);
596 if (this->root_spritegroup == nullptr) {
597 ctype = CargoGRFFileProps::SG_DEFAULT;
598 this->root_spritegroup = this->station_scope.statspec->grf_prop.GetSpriteGroup(ctype);
599 }
600
601 /* Remember the cargo type we've picked */
602 this->station_scope.cargo_type = ctype;
603}
604
613 SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10)
614{
615 StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, var10);
616 const auto *group = object.Resolve<ResultSpriteGroup>();
617
618 /* A zero-length ResultSpriteGroup is valid because the output value is an offset, not a sprite ID within the ResultSpriteGroup. */
619 if (group == nullptr) return 0;
620 return group->sprite - SPR_RAIL_PLATFORM_Y_FRONT;
621}
622
623void GetCustomStationRelocation(SpriteLayoutProcessor &processor, const StationSpec *statspec, BaseStation *st, TileIndex tile)
624{
625 StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK);
626 for (uint8_t var10 : processor.Var10Values()) {
627 object.callback_param1 = var10;
628 const auto *group = object.Resolve<ResultSpriteGroup>();
629
630 /* ProcessRegisters must be called no matter the type of the sprite resolve result or whether it is valid.
631 * The sprite offset is only used for layouts with the SPRITE_MODIFIER_CUSTOM_SPRITE flag, however other aspects of layouts
632 * such as register operations must still be processed even if this flag is not set and the sprite offset is never used.
633 * A zero-length ResultSpriteGroup is valid because the output value is an offset, not a sprite ID within the ResultSpriteGroup. */
634 processor.ProcessRegisters(object, var10, group != nullptr ? group->sprite - SPR_RAIL_PLATFORM_Y_FRONT : 0);
635 }
636}
637
647 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
648{
649 /* callback_param1 == 2 means we are resolving the foundation sprites. */
650 StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 2, layout | (edge_info << 16));
651
652 const auto *group = object.Resolve<ResultSpriteGroup>();
653 /* Note: SpriteGroup::Resolve zeroes all registers, so register 0x100 is initialised to 0. (compatibility) */
654 uint32_t offset = static_cast<uint32_t>(object.GetRegister(0x100));
655 if (group == nullptr || group->num_sprites <= offset) return 0;
656
657 return group->sprite + offset;
658}
659
660
661uint16_t GetStationCallback(CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, std::span<int32_t> regs100)
662{
663 StationResolverObject object(statspec, st, tile, callback, param1, param2);
664 return object.ResolveCallback(regs100);
665}
666
677 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, uint8_t plat_len, uint8_t numtracks)
678{
679 TileIndex diff = cur_tile - north_tile;
680 Slope slope = GetTileSlope(cur_tile);
681
682 StationResolverObject object(statspec, nullptr, cur_tile, CBID_STATION_LAND_SLOPE_CHECK,
683 (slope << 4) | (slope ^ (axis == AXIS_Y && HasBit(slope, CORNER_W) != HasBit(slope, CORNER_E) ? SLOPE_EW : 0)),
684 (numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff)));
685 object.station_scope.axis = axis;
686
687 std::array<int32_t, 16> regs100;
688 uint16_t cb_res = object.ResolveCallback(regs100);
689
690 /* Failed callback means success. */
691 if (cb_res == CALLBACK_FAILED) return CommandCost();
692
693 /* The meaning of bit 10 is inverted for a grf version < 8. */
694 if (statspec->grf_prop.grffile->grf_version < 8) ToggleBit(cb_res, 10);
695 return GetErrorMessageFromLocationCallbackResult(cb_res, regs100, statspec->grf_prop.grffile, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
696}
697
698
705std::optional<uint8_t> AllocateSpecToStation(const StationSpec *spec, BaseStation *st)
706{
707 uint i;
708
709 if (spec == nullptr) return 0;
710
711 /* If station doesn't exist yet then the first slot is available. */
712 if (st == nullptr) return 1;
713
714 for (i = 1; i < st->speclist.size() && i < NUM_STATIONSSPECS_PER_STATION; i++) {
715 if (st->speclist[i].spec == nullptr && st->speclist[i].grfid == 0) break;
716 }
717
718 if (i == NUM_STATIONSSPECS_PER_STATION) {
719 /* As final effort when the spec list is already full...
720 * try to find the same spec and return that one. This might
721 * result in slightly "wrong" (as per specs) looking stations,
722 * but it's fairly unlikely that one reaches the limit anyways.
723 */
724 for (i = 1; i < st->speclist.size() && i < NUM_STATIONSSPECS_PER_STATION; i++) {
725 if (st->speclist[i].spec == spec) return i;
726 }
727
728 return std::nullopt;
729 }
730
731 return i;
732}
733
740 void AssignSpecToStation(const StationSpec *spec, BaseStation *st, uint8_t specindex)
741{
742 if (specindex == 0) return;
743 if (specindex >= st->speclist.size()) st->speclist.resize(specindex + 1);
744
745 st->speclist[specindex].spec = spec;
746 st->speclist[specindex].grfid = spec->grf_prop.grfid;
747 st->speclist[specindex].localidx = spec->grf_prop.local_id;
748
749 StationUpdateCachedTriggers(st);
750}
751
757 void DeallocateSpecFromStation(BaseStation *st, uint8_t specindex)
758{
759 /* specindex of 0 (default) is never freeable */
760 if (specindex == 0) return;
761
762 /* Check all tiles over the station to check if the specindex is still in use */
763 for (TileIndex tile : GetRailTileArea(st, INVALID_TILE, TA_WHOLE)) {
764 if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
765 return;
766 }
767 }
768
769 /* This specindex is no longer in use, so deallocate it */
770 st->speclist[specindex].spec = nullptr;
771 st->speclist[specindex].grfid = 0;
772 st->speclist[specindex].localidx = 0;
773
774 /* If this was the highest spec index, reallocate */
775 if (specindex == st->speclist.size() - 1) {
776 size_t num_specs;
777 for (num_specs = st->speclist.size() - 1; num_specs > 0; num_specs--) {
778 if (st->speclist[num_specs].grfid != 0) break;
779 }
780
781 if (num_specs > 0) {
782 st->speclist.resize(num_specs + 1);
783 } else {
784 st->speclist.clear();
785 st->cached_anim_triggers = {};
786 st->cached_cargo_triggers = 0;
787 return;
788 }
789 }
790
791 StationUpdateCachedTriggers(st);
792}
793
804 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
805{
806 const DrawTileSprites *sprites = nullptr;
807 const RailTypeInfo *rti = GetRailTypeInfo(railtype);
808 PaletteID palette = GetCompanyPalette(_local_company);
809 uint tile = 2;
810
811 const StationSpec *statspec = StationClass::Get(sclass)->GetSpec(station);
812 if (statspec == nullptr) return false;
813
814 if (statspec->callback_mask.Test(StationCallbackMask::DrawTileLayout)) {
815 uint16_t callback = GetStationCallback(CBID_STATION_DRAW_TILE_LAYOUT, 0, 0, statspec, nullptr, INVALID_TILE);
816 if (callback != CALLBACK_FAILED) tile = callback & ~1;
817 }
818
819 uint32_t total_offset = rti->GetRailtypeSpriteOffset();
820 uint32_t relocation = 0;
821 uint32_t ground_relocation = 0;
822 const NewGRFSpriteLayout *layout = nullptr;
823 SpriteLayoutProcessor processor; // owns heap, borrowed by tmp_rail_layout and sprites
824 DrawTileSpriteSpan tmp_rail_layout;
825
826 if (statspec->renderdata.empty()) {
827 sprites = GetStationTileLayout(StationType::Rail, tile + axis);
828 } else {
829 layout = &statspec->renderdata[(tile < statspec->renderdata.size()) ? tile + axis : (uint)axis];
830 if (!layout->NeedsPreprocessing()) {
831 sprites = layout;
832 layout = nullptr;
833 }
834 }
835
836 if (layout != nullptr) {
837 /* Sprite layout which needs preprocessing */
838 bool separate_ground = statspec->flags.Test(StationSpecFlag::SeparateGround);
839 processor = SpriteLayoutProcessor(*layout, total_offset, rti->fallback_railtype, 0, 0, separate_ground);
840 GetCustomStationRelocation(processor, statspec, nullptr, INVALID_TILE);
841 tmp_rail_layout = processor.GetLayout();
842 sprites = &tmp_rail_layout;
843 total_offset = 0;
844 } else {
845 /* Simple sprite layout */
846 ground_relocation = relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, 0);
847 if (HasBit(sprites->ground.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
848 ground_relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, 1);
849 }
850 ground_relocation += rti->fallback_railtype;
851 }
852
853 SpriteID image = sprites->ground.sprite;
854 PaletteID pal = sprites->ground.pal;
855 RailTrackOffset overlay_offset;
856 if (rti->UsesOverlay() && SplitGroundSpriteForOverlay(nullptr, &image, &overlay_offset)) {
857 SpriteID ground = GetCustomRailSprite(rti, INVALID_TILE, RTSG_GROUND);
858 DrawSprite(image, PAL_NONE, x, y);
859 DrawSprite(ground + overlay_offset, PAL_NONE, x, y);
860 } else {
861 image += HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? ground_relocation : total_offset;
862 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += ground_relocation;
863 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
864 }
865
866 DrawRailTileSeqInGUI(x, y, sprites, total_offset, relocation, palette);
867
868 return true;
869}
870
871
872const StationSpec *GetStationSpec(TileIndex t)
873{
874 if (!IsCustomStationSpecIndex(t)) return nullptr;
875
876 const BaseStation *st = BaseStation::GetByTile(t);
877 uint specindex = GetCustomStationSpecIndex(t);
878 return specindex < st->speclist.size() ? st->speclist[specindex].spec : nullptr;
879}
880
882uint16_t GetAnimStationCallback(CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, int)
883{
884 return GetStationCallback(callback, param1, param2, statspec, st, tile);
885}
886
888 struct StationAnimationBase : public AnimationBase<StationAnimationBase, StationSpec, BaseStation, int, GetAnimStationCallback, TileAnimationFrameAnimationHelper<BaseStation> > {
889 static constexpr CallbackID cb_animation_speed = CBID_STATION_ANIMATION_SPEED;
890 static constexpr CallbackID cb_animation_next_frame = CBID_STATION_ANIMATION_NEXT_FRAME;
891
892 static constexpr StationCallbackMask cbm_animation_speed = StationCallbackMask::AnimationSpeed;
893 static constexpr StationCallbackMask cbm_animation_next_frame = StationCallbackMask::AnimationNextFrame;
894};
895
896void AnimateStationTile(TileIndex tile)
897{
898 const StationSpec *ss = GetStationSpec(tile);
899 if (ss == nullptr) return;
900
901 StationAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, ss->flags.Test(StationSpecFlag::Cb141RandomBits));
902}
903
904void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoType cargo_type)
905{
906 /* List of coverage areas for each animation trigger */
907 static const TriggerArea tas[] = {
908 TA_TILE, // Built
909 TA_WHOLE, // NewCargo
910 TA_WHOLE, // CargoTaken
911 TA_PLATFORM, // VehicleArrives
912 TA_PLATFORM, // VehicleDeparts
913 TA_PLATFORM, // VehicleLoads
914 TA_WHOLE, // AcceptanceTick
915 TA_TILE, // TileLoop
916 TA_PLATFORM, // PathReservation
917 };
918 static_assert(std::size(tas) == static_cast<size_t>(StationAnimationTrigger::End));
919
920 assert(st != nullptr);
921
922 /* Check the cached animation trigger bitmask to see if we need
923 * to bother with any further processing. */
924 if (!st->cached_anim_triggers.Test(trigger)) return;
925
926 uint16_t random_bits = Random();
927
928 /* Check all tiles over the station to check if the specindex is still in use */
929 for (TileIndex tile : GetRailTileArea(st, trigger_tile, tas[static_cast<size_t>(trigger)])) {
930 if (st->TileBelongsToRailStation(tile)) {
931 const StationSpec *ss = GetStationSpec(tile);
932 if (ss != nullptr && ss->animation.triggers.Test(trigger)) {
933 uint8_t var18_extra = 0;
934 if (IsValidCargoType(cargo_type)) {
935 var18_extra |= ss->grf_prop.grffile->cargo_map[cargo_type] << 8;
936 }
937 StationAnimationBase::ChangeAnimationFrame(CBID_STATION_ANIMATION_TRIGGER, ss, st, tile, (random_bits << 16) | GB(Random(), 0, 16), to_underlying(trigger) | var18_extra);
938 }
939 }
940 }
941}
942
950 void TriggerStationRandomisation(BaseStation *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoType cargo_type)
951{
952 /* List of coverage areas for each animation trigger */
953 static const TriggerArea tas[] = {
954 TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM
955 };
956
957 assert(st != nullptr);
958
959 /* Check the cached cargo trigger bitmask to see if we need
960 * to bother with any further processing.
961 * Note: cached_cargo_triggers must be non-zero even for cargo-independent triggers. */
962 if (st->cached_cargo_triggers == 0) return;
963 if (IsValidCargoType(cargo_type) && !HasBit(st->cached_cargo_triggers, cargo_type)) return;
964
965 uint32_t whole_reseed = 0;
966
967 /* Bitmask of completely empty cargo types to be matched. */
968 CargoTypes empty_mask{};
969 if (trigger == StationRandomTrigger::CargoTaken) {
970 empty_mask = GetEmptyMask(Station::From(st));
971 }
972
973 /* Store triggers now for var 5F */
974 st->waiting_random_triggers.Set(trigger);
975 StationRandomTriggers used_random_triggers;
976
977 /* Check all tiles over the station to check if the specindex is still in use */
978 for (TileIndex tile : GetRailTileArea(st, trigger_tile, tas[static_cast<size_t>(trigger)])) {
979 if (st->TileBelongsToRailStation(tile)) {
980 const StationSpec *ss = GetStationSpec(tile);
981 if (ss == nullptr) continue;
982
983 /* Cargo taken "will only be triggered if all of those
984 * cargo types have no more cargo waiting." */
985 if (trigger == StationRandomTrigger::CargoTaken) {
986 if ((ss->cargo_triggers & ~empty_mask) != 0) continue;
987 }
988
989 if (!IsValidCargoType(cargo_type) || HasBit(ss->cargo_triggers, cargo_type)) {
990 StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
991 object.SetWaitingRandomTriggers(st->waiting_random_triggers);
992
993 object.ResolveRerandomisation();
994
995 used_random_triggers.Set(object.GetUsedRandomTriggers());
996
997 uint32_t reseed = object.GetReseedSum();
998 if (reseed != 0) {
999 whole_reseed |= reseed;
1000 reseed >>= 16;
1001
1002 /* Set individual tile random bits */
1003 uint8_t random_bits = GetStationTileRandomBits(tile);
1004 random_bits &= ~reseed;
1005 random_bits |= Random() & reseed;
1006 SetStationTileRandomBits(tile, random_bits);
1007
1008 MarkTileDirtyByTile(tile);
1009 }
1010 }
1011 }
1012 }
1013
1014 /* Update whole station random bits */
1015 st->waiting_random_triggers.Reset(used_random_triggers);
1016 if ((whole_reseed & 0xFFFF) != 0) {
1017 st->random_bits &= ~whole_reseed;
1018 st->random_bits |= Random() & whole_reseed;
1019 }
1020}
1021
1026 void StationUpdateCachedTriggers(BaseStation *st)
1027{
1028 st->cached_anim_triggers = {};
1029 st->cached_cargo_triggers = 0;
1030
1031 /* Combine animation trigger bitmask for all station specs
1032 * of this station. */
1033 for (const auto &sm : GetStationSpecList<StationSpec>(st)) {
1034 if (sm.spec == nullptr) continue;
1035 st->cached_anim_triggers.Set(sm.spec->animation.triggers);
1036 st->cached_cargo_triggers |= sm.spec->cargo_triggers;
1037 }
1038}
1039
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition bitmath_func.hpp:58
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition bitmath_func.hpp:157
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::base
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
Definition base_bitset_type.hpp:219
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
CargoList::PeriodsInTransit
uint PeriodsInTransit() const
Returns average number of cargo aging periods in transit for a cargo entity.
Definition cargopacket.h:329
CommandCost
Common return value for all commands.
Definition command_type.h:24
EnumBitSet< StationRandomTrigger, uint8_t >
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition newgrf_class.h:26
NewGRFClass::name
StringID name
Name of this class.
Definition newgrf_class.h:49
NewGRFClass::IsUIAvailable
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
Definition newgrf_airport.cpp:40
NewGRFClass::Insert
void Insert(Tspec *spec)
Insert a spec into the class, and update its index.
Definition newgrf_class_func.h:55
NewGRFClass::Get
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
Definition newgrf_class_func.h:82
NewGRFClass::Allocate
static Tindex Allocate(uint32_t global_id)
Allocate a class with a given global class ID.
Definition newgrf_class_func.h:32
NewGRFClass::InsertDefaults
static void InsertDefaults()
Initialise the defaults.
Definition newgrf_airport.cpp:31
NewGRFClass::GetSpec
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Definition newgrf_class_func.h:114
RailTypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition rail.h:115
RailTypeInfo::fallback_railtype
uint8_t fallback_railtype
Original railtype number to use when drawing non-newgrf railtypes, or when drawing stations.
Definition rail.h:190
RailTypeInfo::GetRailtypeSpriteOffset
uint GetRailtypeSpriteOffset() const
Offset between the current railtype and normal rail.
Definition rail.h:286
SpriteLayoutProcessor
Add dynamic register values to a sprite layout.
Definition newgrf_commons.h:142
SpriteLayoutProcessor::GetLayout
DrawTileSpriteSpan GetLayout() const
Returns the result spritelayout after preprocessing.
Definition newgrf_commons.h:167
SpriteLayoutProcessor::ProcessRegisters
void ProcessRegisters(const struct ResolverObject &object, uint8_t resolved_var10, uint32_t resolved_sprite)
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
Definition newgrf_commons.cpp:665
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition cargopacket.h:597
StationCargoList::GetFirstStation
StationID GetFirstStation() const
Returns first station of the first cargo packet in this list.
Definition cargopacket.h:568
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition timer_game_calendar.h:33
TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
Definition timer_game_common.h:184
GetCompanyPalette
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
Definition company_cmd.cpp:164
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
debug.h
Functions related to debugging.
Debug
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
DIR_SW
@ DIR_SW
Southwest.
Definition direction_type.h:31
DIR_NW
@ DIR_NW
Northwest.
Definition direction_type.h:33
DIR_N
@ DIR_N
North.
Definition direction_type.h:26
DIR_SE
@ DIR_SE
Southeast.
Definition direction_type.h:29
DIR_S
@ DIR_S
South.
Definition direction_type.h:30
DIR_NE
@ DIR_NE
Northeast.
Definition direction_type.h:27
DIR_W
@ DIR_W
West.
Definition direction_type.h:32
DIR_E
@ DIR_E
East.
Definition direction_type.h:28
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition direction_type.h:127
AXIS_X
@ AXIS_X
The X axis.
Definition direction_type.h:124
AXIS_Y
@ AXIS_Y
The y axis.
Definition direction_type.h:125
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition direction_type.h:80
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition direction_type.h:83
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition direction_type.h:81
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition direction_type.h:82
to_underlying
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition gfx.cpp:1031
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition viewport.cpp:2128
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition landscape.cpp:559
BorderFlag::Random
@ Random
Randomise borders.
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:401
TileOffsByAxis
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
Definition map_func.h:567
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:437
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:427
TileAdd
constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
Adds a given offset to a tile.
Definition map_func.h:469
TileOffsByDir
TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Definition map_func.h:596
TileIndexDiff
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
ATP_TTDP_LARGE
@ ATP_TTDP_LARGE
Same as AT_LARGE.
Definition newgrf_airport.h:89
newgrf_animation_base.h
Function implementations related to NewGRF animation.
GetBadgeVariableResult
uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
Test for a matching badge in a list of badges, returning the number of matching bits.
Definition newgrf_badge.cpp:225
newgrf_badge.h
Functions related to NewGRF badges.
StationCallbackMask
StationCallbackMask
Callback masks for stations.
Definition newgrf_callbacks.h:319
StationCallbackMask::DrawTileLayout
@ DrawTileLayout
Use callback to select a tile layout to use when drawing.
StationCallbackMask::AnimationNextFrame
@ AnimationNextFrame
Use a custom next frame callback.
StationCallbackMask::AnimationSpeed
@ AnimationSpeed
Customize the animation speed of the station.
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:22
CBID_STATION_ANIMATION_TRIGGER
@ CBID_STATION_ANIMATION_TRIGGER
Called for periodically starting or stopping the animation.
Definition newgrf_callbacks.h:187
CBID_STATION_DRAW_TILE_LAYOUT
@ CBID_STATION_DRAW_TILE_LAYOUT
Choose a tile layout to draw, instead of the standard range.
Definition newgrf_callbacks.h:44
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition newgrf_callbacks.h:24
CBID_STATION_ANIMATION_NEXT_FRAME
@ CBID_STATION_ANIMATION_NEXT_FRAME
Called to determine station tile next animation frame.
Definition newgrf_callbacks.h:190
CBID_STATION_ANIMATION_SPEED
@ CBID_STATION_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Definition newgrf_callbacks.h:193
CBID_RANDOM_TRIGGER
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
Definition newgrf_callbacks.h:27
CBID_STATION_LAND_SLOPE_CHECK
@ CBID_STATION_LAND_SLOPE_CHECK
Callback done for each tile of a station to check the slope.
Definition newgrf_callbacks.h:214
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
GetCargoTranslation
CargoType GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoType.
Definition newgrf_cargo.cpp:80
newgrf_cargo.h
Cargo support for NewGRFs.
newgrf_class_func.h
Implementation of the NewGRF class' functions.
GetErrorMessageFromLocationCallbackResult
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, std::span< const int32_t > textstack, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Definition newgrf_commons.cpp:471
GetCompanyInfo
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
Definition newgrf_commons.cpp:457
GetNearbyTileInformation
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
Definition newgrf_commons.cpp:434
GetTerrainType
uint32_t GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
Definition newgrf_commons.cpp:336
GetNearbyTile
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition newgrf_commons.cpp:411
Invalid
@ Invalid
GRF is unusable with this version of OpenTTD.
Definition newgrf_config.h:28
GetReverseRailTypeTranslation
uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
Definition newgrf_railtype.cpp:173
GetCustomRailSprite
SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
Definition newgrf_railtype.cpp:106
newgrf_railtype.h
NewGRF handling of rail types.
newgrf_sound.h
Functions related to NewGRF provided sounds.
newgrf_spritegroup.h
Action 2 handling.
GetPlatformInfo
uint32_t GetPlatformInfo(Axis axis, uint8_t tile, int platforms, int length, int x, int y, bool centred)
Evaluate a tile's position within a station, and return the result in a bit-stuffed format.
Definition newgrf_station.cpp:120
FindRailStationEnd
static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
Find the end of a railway station, from the tile, in the direction of delta.
Definition newgrf_station.cpp:158
GetCustomStationRelocation
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10)
Resolve sprites for drawing a station tile.
Definition newgrf_station.cpp:613
GetCustomStationFoundationRelocation
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
Resolve the sprites for custom station foundations.
Definition newgrf_station.cpp:647
StationUpdateCachedTriggers
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
Definition newgrf_station.cpp:1026
DrawStationTile
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
Draw representation of a station tile for GUI purposes.
Definition newgrf_station.cpp:804
AssignSpecToStation
void AssignSpecToStation(const StationSpec *spec, BaseStation *st, uint8_t specindex)
Assign a previously allocated StationSpec specindex to a Station.
Definition newgrf_station.cpp:740
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, uint8_t specindex)
Deallocate a StationSpec from a Station.
Definition newgrf_station.cpp:757
GetRailTileArea
TileArea GetRailTileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
Get the tile area of a rail station with trigger area type.
Definition newgrf_station.cpp:83
TriggerStationRandomisation
void TriggerStationRandomisation(BaseStation *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoType cargo_type)
Trigger station randomisation.
Definition newgrf_station.cpp:950
NUM_STATIONSSPECS_PER_STATION
static const uint NUM_STATIONSSPECS_PER_STATION
Maximum number of parts per station.
Definition newgrf_station.cpp:54
PerformStationTileSlopeCheck
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, uint8_t plat_len, uint8_t numtracks)
Check the slope of a tile of a new station.
Definition newgrf_station.cpp:677
GetAnimStationCallback
uint16_t GetAnimStationCallback(CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, int)
Wrapper for animation control, see GetStationCallback.
Definition newgrf_station.cpp:882
AllocateSpecToStation
std::optional< uint8_t > AllocateSpecToStation(const StationSpec *spec, BaseStation *st)
Allocate a StationSpec to a Station.
Definition newgrf_station.cpp:705
newgrf_station.h
Header file for NewGRF stations.
StationSpecFlag::Cb141RandomBits
@ Cb141RandomBits
Callback 141 needs random bits.
StationSpecFlag::SeparateGround
@ SeparateGround
Use different sprite set for ground sprites.
StationSpecFlag::DivByStationSize
@ DivByStationSize
Divide cargo amount by station size.
StationClassID
StationClassID
Definition newgrf_station.h:103
newgrf_town.h
Functions to handle the town part of NewGRF towns.
NewsType::Acceptance
@ Acceptance
A type of cargo is (no longer) accepted.
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:300
RTSG_GROUND
@ RTSG_GROUND
Main group of ground images.
Definition rail.h:43
RailTrackOffset
RailTrackOffset
Offsets for sprites within an overlay/underlay set.
Definition rail.h:61
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
RailType
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
roadstop_base.h
Base class for roadstops.
safeguards.h
A number of safeguards to prevent using unsafe methods.
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
SLOPE_EW
@ SLOPE_EW
east and west corner are raised
Definition slope_type.h:59
DrawRailTileSeqInGUI
void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence in GUI with railroad specifics.
Definition sprite.h:105
GroundSpritePaletteTransform
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:174
SPRITE_MODIFIER_CUSTOM_SPRITE
static constexpr uint8_t SPRITE_MODIFIER_CUSTOM_SPRITE
these masks change the colours of the palette for a sprite.
Definition sprites.h:1559
station_base.h
Base classes/functions for stations.
GetEmptyMask
CargoTypes GetEmptyMask(const Station *st)
Get a mask of the cargo types that are empty at the station.
Definition station_cmd.cpp:504
GetStationTileLayout
const DrawTileSprites * GetStationTileLayout(StationType st, uint8_t gfx)
Get station tile layout for a station type and its station gfx.
Definition station_cmd.cpp:3101
GetAcceptanceMask
CargoTypes GetAcceptanceMask(const Station *st)
Get a mask of the cargo types that the station accepts.
Definition station_cmd.cpp:489
SplitGroundSpriteForOverlay
bool SplitGroundSpriteForOverlay(const TileInfo *ti, SpriteID *ground, RailTrackOffset *overlay_offset)
Check whether a sprite is a track sprite, which can be replaced by a non-track ground sprite and a ra...
Definition station_cmd.cpp:3117
GetStationGfx
StationGfx GetStationGfx(Tile t)
Get the station graphics of this tile.
Definition station_map.h:68
IsCompatibleTrainStationTile
bool IsCompatibleTrainStationTile(Tile test_tile, Tile station_tile)
Check if a tile is a valid continuation to a railstation tile.
Definition station_map.h:544
GetStationTileRandomBits
uint8_t GetStationTileRandomBits(Tile t)
Get the random bits of a station tile.
Definition station_map.h:702
IsRailStationTile
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
Definition station_map.h:102
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
HasStationTileRail
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition station_map.h:146
GetCustomStationSpecIndex
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
Definition station_map.h:642
SetStationTileRandomBits
void SetStationTileRandomBits(Tile t, uint8_t random_bits)
Set the random bits for a station tile.
Definition station_map.h:690
GetRailStationAxis
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Definition station_map.h:503
IsCustomStationSpecIndex
bool IsCustomStationSpecIndex(Tile t)
Is there a custom rail station spec on this tile?
Definition station_map.h:618
HasStationRail
bool HasStationRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition station_map.h:135
HasStationReservation
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
Definition station_map.h:559
HVOT_WAYPOINT
@ HVOT_WAYPOINT
Station is a waypoint (NewGRF only!)
Definition station_type.h:72
StationRandomTrigger
StationRandomTrigger
Randomisation triggers for stations and roadstops.
Definition station_type.h:77
StationRandomTrigger::CargoTaken
@ CargoTaken
Trigger station when cargo is completely taken.
StationAnimationTrigger
StationAnimationTrigger
Animation triggers for stations and roadstops.
Definition station_type.h:88
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:271
AirportSpec::ttd_airport_type
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
Definition newgrf_airport.h:120
Airport::blocks
AirportBlocks blocks
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition station_base.h:354
Airport::GetSpec
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition station_base.h:366
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition newgrf_animation_base.h:43
AnimationBase< StationAnimationBase, StationSpec, BaseStation, int, GetAnimStationCallback, TileAnimationFrameAnimationHelper< BaseStation > >::AnimateTile
static void AnimateTile(const StationSpec *spec, BaseStation *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
Definition newgrf_animation_base.h:52
AnimationBase< StationAnimationBase, StationSpec, BaseStation, int, GetAnimStationCallback, TileAnimationFrameAnimationHelper< BaseStation > >::ChangeAnimationFrame
static void ChangeAnimationFrame(CallbackID cb, const StationSpec *spec, BaseStation *obj, TileIndex tile, uint32_t random_bits, uint32_t trigger, int extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
Definition newgrf_animation_base.h:131
BaseStation
Base class for all station-ish types.
Definition base_station_base.h:58
BaseStation::GetNewGRFVariable
virtual uint32_t GetNewGRFVariable(const struct ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const =0
Helper function to get a NewGRF variable that isn't implemented by the base class.
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition base_station_base.h:64
BaseStation::speclist
std::vector< SpecMapping< StationSpec > > speclist
List of rail station specs of this station.
Definition base_station_base.h:71
BaseStation::GetTileArea
virtual TileArea GetTileArea(StationType type) const =0
Get the tile area for a given station type.
BaseStation::facilities
StationFacilities facilities
The facilities that this station has.
Definition base_station_base.h:69
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition base_station_base.h:83
BaseStation::cached_anim_triggers
StationAnimationTriggers cached_anim_triggers
NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
Definition base_station_base.h:78
BaseStation::owner
Owner owner
The owner of this station.
Definition base_station_base.h:68
BaseStation::town
Town * town
The town this station is associated with.
Definition base_station_base.h:67
BaseStation::GetByTile
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
Definition base_station_base.h:160
BaseStation::TileBelongsToRailStation
virtual bool TileBelongsToRailStation(TileIndex tile) const =0
Check whether a specific tile belongs to this station.
BaseStation::random_bits
uint16_t random_bits
Random bits assigned to this station.
Definition base_station_base.h:76
BaseStation::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition base_station_base.h:74
BaseStation::waiting_random_triggers
StationRandomTriggers waiting_random_triggers
Waiting triggers (NewGRF), shared by all station parts/tiles, road stops, ... essentially useless and...
Definition base_station_base.h:77
BaseStation::cached_cargo_triggers
CargoTypes cached_cargo_triggers
NOSAVE: Combined cargo trigger bitmask.
Definition base_station_base.h:80
CargoGRFFileProps::SG_PURCHASE
static constexpr CargoType SG_PURCHASE
Used in purchase lists before an item exists.
Definition newgrf_commons.h:457
CargoGRFFileProps::SG_DEFAULT
static constexpr CargoType SG_DEFAULT
Default type used when no more-specific cargo matches.
Definition newgrf_commons.h:456
CargoGRFFileProps::SG_DEFAULT_NA
static constexpr CargoType SG_DEFAULT_NA
Used only by stations and roads when no more-specific cargo matches.
Definition newgrf_commons.h:458
DrawTileSpriteSpan
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:67
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:52
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:318
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition newgrf_commons.h:316
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:317
GRFFile::cargo_map
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoType -> local ID)
Definition newgrf.h:136
GoodsEntry::GoodsEntryData::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition station_base.h:213
GoodsEntry
Stores station stats for a single cargo.
Definition station_base.h:167
GoodsEntry::HasRating
bool HasRating() const
Does this cargo have a rating at this station?
Definition station_base.h:267
GoodsEntry::last_speed
uint8_t last_speed
Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
Definition station_base.h:246
GoodsEntry::last_age
uint8_t last_age
Age in years (up to 255) of the last vehicle that tried to load this cargo.
Definition station_base.h:252
GoodsEntry::time_since_pickup
uint8_t time_since_pickup
Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.
Definition station_base.h:233
GoodsEntry::status
States status
Status of this cargo, see State.
Definition station_base.h:226
GoodsEntry::State::LastMonth
@ LastMonth
Set when cargo was delivered for final delivery last month.
GoodsEntry::State::Acceptance
@ Acceptance
Set when the station accepts the cargo currently for final deliveries.
GoodsEntry::State::EverAccepted
@ EverAccepted
Set when a vehicle ever delivered cargo to the station for final delivery.
GoodsEntry::State::AcceptedBigtick
@ AcceptedBigtick
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval.
GoodsEntry::State::CurrentMonth
@ CurrentMonth
Set when cargo was delivered for final delivery this month.
GoodsEntry::GetData
const GoodsEntryData & GetData() const
Get optional cargo packet/flow data.
Definition station_base.h:317
GoodsEntry::HasVehicleEverTriedLoading
bool HasVehicleEverTriedLoading() const
Reports whether a vehicle has ever tried to load the cargo at this station.
Definition station_base.h:261
GoodsEntry::rating
uint8_t rating
Station rating for this cargo.
Definition station_base.h:235
GoodsEntry::HasData
bool HasData() const
Test if this goods entry has optional cargo packet/flow data.
Definition station_base.h:305
GoodsEntry::ConvertState
uint8_t ConvertState() const
Convert GoodsEntry status to the form required for NewGRF variables.
Definition newgrf_station.cpp:60
NewGRFSpriteLayout
NewGRF supplied spritelayout.
Definition newgrf_commons.h:113
NewGRFSpriteLayout::NeedsPreprocessing
bool NeedsPreprocessing() const
Tests whether this spritelayout needs preprocessing by SpriteLayoutProcessor, or whether it can be us...
Definition newgrf_commons.h:131
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition tilearea_type.h:20
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition tilearea_type.h:19
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition tilearea_type.h:21
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
PoolID< uint16_t, struct StationIDTag, 64000, 0xFFFF >
RealSpriteGroup
Definition newgrf_spritegroup.h:64
RealSpriteGroup::loaded
std::vector< const SpriteGroup * > loaded
List of loaded groups (can be SpriteIDs or Callback results)
Definition newgrf_spritegroup.h:74
RealSpriteGroup::loading
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results)
Definition newgrf_spritegroup.h:75
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition newgrf_spritegroup.h:352
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition newgrf_spritegroup.h:353
ResultSpriteGroup
Definition newgrf_spritegroup.h:217
RoadStop::status
RoadStopStatusFlags status
Current status of the Stop. Access using *Bay and *Busy functions.
Definition roadstop_base.h:69
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition newgrf_spritegroup.h:270
SpecializedResolverObject
Specialization of ResolverObject with type-safe access to RandomTriggers.
Definition newgrf_spritegroup.h:450
SpecializedStation< Station, false >::IsExpected
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
Definition base_station_base.h:229
SpecializedStation< Station, false >::From
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
Definition base_station_base.h:277
SpriteGroup
Definition newgrf_spritegroup.h:47
StationAnimationBase
Helper class for animation control.
Definition newgrf_station.cpp:888
StationResolverObject
Station resolver.
Definition newgrf_station.h:68
StationResolverObject::station_scope
StationScopeResolver station_scope
The station scope resolver.
Definition newgrf_station.h:69
StationResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_station.cpp:560
StationResolverObject::GetTown
TownScopeResolver * GetTown()
Get the town scope associated with a station, if it exists.
Definition newgrf_station.cpp:256
StationResolverObject::town_scope
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
Definition newgrf_station.h:70
StationResolverObject::StationResolverObject
StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Resolver for stations.
Definition newgrf_station.cpp:574
StationResolverObject::ResolveReal
const SpriteGroup * ResolveReal(const RealSpriteGroup &group) const override
Get the real sprites of the grf.
Definition newgrf_station.cpp:505
StationResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_station.cpp:555
StationScopeResolver::cargo_type
CargoType cargo_type
Type of cargo of the station.
Definition newgrf_station.h:31
StationScopeResolver::st
struct BaseStation * st
Instance of the station.
Definition newgrf_station.h:29
StationScopeResolver::GetRandomTriggers
uint32_t GetRandomTriggers() const override
Get the triggers.
Definition newgrf_station.cpp:245
StationScopeResolver::GetVariable
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
Definition newgrf_station.cpp:271
StationScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_station.cpp:239
StationScopeResolver::statspec
const struct StationSpec * statspec
Station (type) specification.
Definition newgrf_station.h:30
StationScopeResolver::axis
Axis axis
Station axis, used only for the slope check callback.
Definition newgrf_station.h:32
StationScopeResolver::tile
TileIndex tile
Tile of the station.
Definition newgrf_station.h:28
StationSpec
Station specification.
Definition newgrf_station.h:123
StationSpec::cargo_threshold
uint16_t cargo_threshold
Cargo threshold for choosing between little and lots of cargo.
Definition newgrf_station.h:158
StationSpec::grf_prop
CargoGRFFileProps grf_prop
Link to NewGRF.
Definition newgrf_station.h:130
StationSpec::cargo_triggers
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
Definition newgrf_station.h:160
StationSpec::renderdata
std::vector< NewGRFSpriteLayout > renderdata
Number of tile layouts.
Definition newgrf_station.h:152
StationSpec::callback_mask
StationCallbackMasks callback_mask
Bitmask of station callbacks that have to be called.
Definition newgrf_station.h:162
StationSpec::flags
StationSpecFlags flags
Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size.
Definition newgrf_station.h:164
Station
Station data structure.
Definition station_base.h:500
Station::bus_stops
RoadStop * bus_stops
All the road stops.
Definition station_base.h:509
Station::goods
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
Definition station_base.h:529
Station::airport
Airport airport
Tile area the airport covers.
Definition station_base.h:514
Station::truck_stops
RoadStop * truck_stops
All the truck stops.
Definition station_base.h:511
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TownScopeResolver
Scope resolver for a town.
Definition newgrf_town.h:22
Town
Town data structure.
Definition town.h:63
VariableGRFFileProps::spritegroups
std::vector< ValueType > spritegroups
pointers to the different sprite groups of the entity
Definition newgrf_commons.h:408
VariableGRFFileProps::GetSpriteGroup
const SpriteGroup * GetSpriteGroup(Tkey index) const
Get the SpriteGroup at the specified index.
Definition newgrf_commons.h:415
Waypoint::GetNewGRFVariable
uint32_t GetNewGRFVariable(const struct ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const override
Helper function to get a NewGRF variable that isn't implemented by the base class.
Definition newgrf_station.cpp:473
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
GetAnimationFrame
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
Definition tile_map.h:250
GetTileSlope
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition tilearea_type.h:102
timer_game_calendar.h
Definition of the game-calendar-timer.
town.h
Base of the town class.
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition town_cmd.cpp:3952
DiagdirReachesTracks
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
Definition track_func.h:573
TrackStatusToTrackBits
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition track_func.h:363
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition track_type.h:36
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition transport_type.h:25
tunnelbridge_map.h
Functions that have tunnels and bridges in common.
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition tunnelbridge_map.h:26
waypoint_base.h
Base of waypoints.