OpenTTD Source 20250311-master-g40ddc03423
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 <http://www.gnu.org/licenses/>.
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"
26#include "newgrf_class_func.h"
28
29#include "safeguards.h"
30
31
32template <>
33/* static */ void StationClass::InsertDefaults()
34{
35 /* Set up initial data */
36 StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_DEFAULT))->name = STR_STATION_CLASS_DFLT;
37 StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_DEFAULT))->Insert(nullptr);
38 StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_WAYPOINT))->name = STR_STATION_CLASS_WAYP;
39 StationClass::Get(StationClass::Allocate(STATION_CLASS_LABEL_WAYPOINT))->Insert(nullptr);
40}
41
42template <>
43bool StationClass::IsUIAvailable(uint) const
44{
45 return true;
46}
47
48/* Instantiate StationClass. */
50
51static const uint NUM_STATIONSSPECS_PER_STATION = 255;
52
53enum TriggerArea : uint8_t {
54 TA_TILE,
55 TA_PLATFORM,
56 TA_WHOLE,
57};
58
60 ETileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
61 {
62 switch (ta) {
63 default: NOT_REACHED();
64
65 case TA_TILE:
66 this->tile = tile;
67 this->w = 1;
68 this->h = 1;
69 break;
70
71 case TA_PLATFORM: {
72 TileIndex start, end;
73 Axis axis = GetRailStationAxis(tile);
74 TileIndexDiff delta = TileOffsByAxis(axis);
75
76 for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(end + delta, tile); end += delta) { /* Nothing */ }
77 for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(start - delta, tile); start -= delta) { /* Nothing */ }
78
79 this->tile = start;
80 this->w = TileX(end) - TileX(start) + 1;
81 this->h = TileY(end) - TileY(start) + 1;
82 break;
83 }
84
85 case TA_WHOLE:
86 st->GetTileArea(this, Station::IsExpected(st) ? StationType::Rail : StationType::RailWaypoint);
87 break;
88 }
89 }
90};
91
92
105uint32_t GetPlatformInfo(Axis axis, uint8_t tile, int platforms, int length, int x, int y, bool centred)
106{
107 uint32_t retval = 0;
108
109 if (axis == AXIS_X) {
110 Swap(platforms, length);
111 Swap(x, y);
112 }
113
114 if (centred) {
115 x -= platforms / 2;
116 y -= length / 2;
117 x = Clamp(x, -8, 7);
118 y = Clamp(y, -8, 7);
119 SB(retval, 0, 4, y & 0xF);
120 SB(retval, 4, 4, x & 0xF);
121 } else {
122 SB(retval, 0, 4, std::min(15, y));
123 SB(retval, 4, 4, std::min(15, length - y - 1));
124 SB(retval, 8, 4, std::min(15, x));
125 SB(retval, 12, 4, std::min(15, platforms - x - 1));
126 }
127 SB(retval, 16, 4, std::min(15, length));
128 SB(retval, 20, 4, std::min(15, platforms));
129 SB(retval, 24, 8, tile);
130
131 return retval;
132}
133
134
143static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
144{
145 uint8_t orig_type = 0;
146 Axis orig_axis = AXIS_X;
147 StationID sid = GetStationIndex(tile);
148
149 if (check_type) orig_type = GetCustomStationSpecIndex(tile);
150 if (check_axis) orig_axis = GetRailStationAxis(tile);
151
152 for (;;) {
153 TileIndex new_tile = TileAdd(tile, delta);
154
155 if (!IsTileType(new_tile, MP_STATION) || GetStationIndex(new_tile) != sid) break;
156 if (!HasStationRail(new_tile)) break;
157 if (check_type && GetCustomStationSpecIndex(new_tile) != orig_type) break;
158 if (check_axis && GetRailStationAxis(new_tile) != orig_axis) break;
159
160 tile = new_tile;
161 }
162 return tile;
163}
164
165
166static uint32_t GetPlatformInfoHelper(TileIndex tile, bool check_type, bool check_axis, bool centred)
167{
168 int tx = TileX(tile);
169 int ty = TileY(tile);
170 int sx = TileX(FindRailStationEnd(tile, TileDiffXY(-1, 0), check_type, check_axis));
171 int sy = TileY(FindRailStationEnd(tile, TileDiffXY( 0, -1), check_type, check_axis));
172 int ex = TileX(FindRailStationEnd(tile, TileDiffXY( 1, 0), check_type, check_axis)) + 1;
173 int ey = TileY(FindRailStationEnd(tile, TileDiffXY( 0, 1), check_type, check_axis)) + 1;
174
175 tx -= sx; ex -= sx;
176 ty -= sy; ey -= sy;
177
178 return GetPlatformInfo(GetRailStationAxis(tile), GetStationGfx(tile), ex, ey, tx, ty, centred);
179}
180
181
182static uint32_t GetRailContinuationInfo(TileIndex tile)
183{
184 /* Tile offsets and exit dirs for X axis */
185 static const Direction x_dir[8] = { DIR_SW, DIR_NE, DIR_SE, DIR_NW, DIR_S, DIR_E, DIR_W, DIR_N };
187
188 /* Tile offsets and exit dirs for Y axis */
189 static const Direction y_dir[8] = { DIR_SE, DIR_NW, DIR_SW, DIR_NE, DIR_S, DIR_W, DIR_E, DIR_N };
191
192 Axis axis = GetRailStationAxis(tile);
193
194 /* Choose appropriate lookup table to use */
195 const Direction *dir = axis == AXIS_X ? x_dir : y_dir;
196 const DiagDirection *diagdir = axis == AXIS_X ? x_exits : y_exits;
197
198 uint32_t res = 0;
199 uint i;
200
201 for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) {
202 TileIndex neighbour_tile = tile + TileOffsByDir(*dir);
203 TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(neighbour_tile, TRANSPORT_RAIL, 0));
204 if (trackbits != TRACK_BIT_NONE) {
205 /* If there is any track on the tile, set the bit in the second byte */
206 SetBit(res, i + 8);
207
208 /* With tunnels and bridges the tile has tracks, but they are not necessarily connected
209 * with the next tile because the ramp is not going in the right direction. */
210 if (IsTileType(neighbour_tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(neighbour_tile) != *diagdir) {
211 continue;
212 }
213
214 /* If any track reaches our exit direction, set the bit in the lower byte */
215 if (trackbits & DiagdirReachesTracks(*diagdir)) SetBit(res, i);
216 }
217 }
218
219 return res;
220}
221
222
223/* Station Resolver Functions */
224/* virtual */ uint32_t StationScopeResolver::GetRandomBits() const
225{
226 return (this->st == nullptr ? 0 : this->st->random_bits) | (this->tile == INVALID_TILE ? 0 : GetStationTileRandomBits(this->tile) << 16);
227}
228
229
230/* virtual */ uint32_t StationScopeResolver::GetTriggers() const
231{
232 return this->st == nullptr ? 0 : this->st->waiting_triggers;
233}
234
235
241static struct {
242 uint32_t v40;
243 uint32_t v41;
244 uint32_t v45;
245 uint32_t v46;
246 uint32_t v47;
247 uint32_t v49;
248 uint8_t valid;
250
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 (!HasBit(_svc.valid, 0)) { _svc.v40 = GetPlatformInfoHelper(this->tile, false, false, false); SetBit(_svc.valid, 0); }
309 return _svc.v40;
310
311 case 0x41:
312 if (!HasBit(_svc.valid, 1)) { _svc.v41 = GetPlatformInfoHelper(this->tile, true, false, false); SetBit(_svc.valid, 1); }
313 return _svc.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 (!HasBit(_svc.valid, 2)) { _svc.v45 = GetRailContinuationInfo(this->tile); SetBit(_svc.valid, 2); }
320 return _svc.v45;
321
322 case 0x46:
323 if (!HasBit(_svc.valid, 3)) { _svc.v46 = GetPlatformInfoHelper(this->tile, false, false, true); SetBit(_svc.valid, 3); }
324 return _svc.v46;
325
326 case 0x47:
327 if (!HasBit(_svc.valid, 4)) { _svc.v47 = GetPlatformInfoHelper(this->tile, true, false, true); SetBit(_svc.valid, 4); }
328 return _svc.v47;
329
330 case 0x49:
331 if (!HasBit(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(this->tile, false, true, false); SetBit(_svc.valid, 5); }
332 return _svc.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 : 0;
423 case 0xF3: return (this->bus_stops != nullptr) ? this->bus_stops->status : 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 c = GetCargoTranslation(parameter, object.grffile);
431
432 if (!IsValidCargoType(c)) {
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[c];
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 GB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1) << 3;
448 case 0x69: {
449 static_assert((int)GoodsEntry::GES_EVER_ACCEPTED + 1 == (int)GoodsEntry::GES_LAST_MONTH);
450 static_assert((int)GoodsEntry::GES_EVER_ACCEPTED + 2 == (int)GoodsEntry::GES_CURRENT_MONTH);
453 }
454 }
455 }
456
457 /* Handle cargo variables (deprecated) */
458 if (variable >= 0x8C && variable <= 0xEC) {
459 const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)];
460 switch (GB(variable - 0x8C, 0, 3)) {
461 case 0: return g->HasData() ? g->GetData().cargo.TotalCount() : 0;
462 case 1: return GB(g->HasData() ? std::min(g->GetData().cargo.TotalCount(), 4095u) : 0, 0, 4) | (GB(g->status, GoodsEntry::GES_ACCEPTANCE, 1) << 7);
463 case 2: return g->time_since_pickup;
464 case 3: return g->rating;
465 case 4: return (g->HasData() ? g->GetData().cargo.GetFirstStation() : StationID::Invalid()).base();
466 case 5: return g->HasData() ? g->GetData().cargo.PeriodsInTransit() : 0;
467 case 6: return g->last_speed;
468 case 7: return g->last_age;
469 }
470 }
471
472 Debug(grf, 1, "Unhandled station variable 0x{:X}", variable);
473
474 available = false;
475 return UINT_MAX;
476}
477
478uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, uint8_t variable, [[maybe_unused]] uint8_t parameter, bool &available) const
479{
480 switch (variable) {
481 case 0x48: return 0; // Accepted cargo types
482 case 0x8A: return HVOT_WAYPOINT;
483 case 0xF1: return 0; // airport type
484 case 0xF2: return 0; // truck stop status
485 case 0xF3: return 0; // bus stop status
486 case 0xF6: return 0; // airport flags
487 case 0xF7: return 0; // airport flags cont.
488 }
489
490 /* Handle cargo variables with parameter, 0x60 to 0x65 */
491 if (variable >= 0x60 && variable <= 0x65) {
492 return 0;
493 }
494
495 /* Handle cargo variables (deprecated) */
496 if (variable >= 0x8C && variable <= 0xEC) {
497 switch (GB(variable - 0x8C, 0, 3)) {
498 case 3: return INITIAL_STATION_RATING;
499 case 4: return StationID::Invalid().base();
500 default: return 0;
501 }
502 }
503
504 Debug(grf, 1, "Unhandled station variable 0x{:X}", variable);
505
506 available = false;
507 return UINT_MAX;
508}
509
510/* virtual */ const SpriteGroup *StationResolverObject::ResolveReal(const RealSpriteGroup *group) const
511{
512 if (this->station_scope.st == nullptr || !Station::IsExpected(this->station_scope.st)) {
513 return group->loading[0];
514 }
515
516 uint cargo = 0;
517 const Station *st = Station::From(this->station_scope.st);
518
519 switch (this->station_scope.cargo_type) {
520 case INVALID_CARGO:
523 cargo = 0;
524 break;
525
527 for (const GoodsEntry &ge : st->goods) {
528 if (!ge.HasData()) continue;
529 cargo += ge.GetData().cargo.TotalCount();
530 }
531 break;
532
533 default: {
534 const GoodsEntry &ge = st->goods[this->station_scope.cargo_type];
535 cargo = ge.HasData() ? ge.GetData().cargo.TotalCount() : 0;
536 break;
537 }
538 }
539
541 cargo = std::min(0xfffu, cargo);
542
543 if (cargo > this->station_scope.statspec->cargo_threshold) {
544 if (!group->loading.empty()) {
545 uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * (uint)group->loading.size()) / (4096 - this->station_scope.statspec->cargo_threshold);
546 return group->loading[set];
547 }
548 } else {
549 if (!group->loaded.empty()) {
550 uint set = (cargo * (uint)group->loaded.size()) / (this->station_scope.statspec->cargo_threshold + 1);
551 return group->loaded[set];
552 }
553 }
554
555 return group->loading[0];
556}
557
559{
560 return GSF_STATIONS;
561}
562
564{
566}
567
578 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
579 : ResolverObject(statspec->grf_prop.grffile, callback, callback_param1, callback_param2),
580 station_scope(*this, statspec, base_station, tile)
581{
582 /* Invalidate all cached vars */
583 _svc.valid = 0;
584
586
587 if (this->station_scope.st == nullptr) {
588 /* No station, so we are in a purchase list */
590 this->root_spritegroup = statspec->grf_prop.GetSpriteGroup(ctype);
591 } else if (Station::IsExpected(this->station_scope.st)) {
592 const Station *st = Station::From(this->station_scope.st);
593 /* Pick the first cargo that we have waiting */
594 for (const auto &[cargo, spritegroup] : statspec->grf_prop.spritegroups) {
595 if (cargo < NUM_CARGO && st->goods[cargo].HasData() && st->goods[cargo].GetData().cargo.TotalCount() > 0) {
596 ctype = cargo;
597 this->root_spritegroup = spritegroup;
598 break;
599 }
600 }
601
602 if (this->root_spritegroup == nullptr) {
604 this->root_spritegroup = statspec->grf_prop.GetSpriteGroup(ctype);
605 }
606 }
607
608
609 if (this->root_spritegroup == nullptr) {
611 this->root_spritegroup = statspec->grf_prop.GetSpriteGroup(ctype);
612 }
613
614 /* Remember the cargo type we've picked */
615 this->station_scope.cargo_type = ctype;
616}
617
626SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10)
627{
628 StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, var10);
629 const SpriteGroup *group = object.Resolve();
630 if (group == nullptr || group->type != SGT_RESULT) return 0;
631 return group->GetResult() - 0x42D;
632}
633
643SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
644{
645 /* callback_param1 == 2 means we are resolving the foundation sprites. */
646 StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 2, layout | (edge_info << 16));
647
648 const SpriteGroup *group = object.Resolve();
649 if (group == nullptr || group->type != SGT_RESULT) return 0;
650
651 /* Note: SpriteGroup::Resolve zeroes all registers, so register 0x100 is initialised to 0. (compatibility) */
652 return group->GetResult() + GetRegister(0x100);
653}
654
655
656uint16_t GetStationCallback(CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile)
657{
658 StationResolverObject object(statspec, st, tile, callback, param1, param2);
659 return object.ResolveCallback();
660}
661
672CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, uint8_t plat_len, uint8_t numtracks)
673{
674 TileIndex diff = cur_tile - north_tile;
675 Slope slope = GetTileSlope(cur_tile);
676
677 StationResolverObject object(statspec, nullptr, cur_tile, CBID_STATION_LAND_SLOPE_CHECK,
678 (slope << 4) | (slope ^ (axis == AXIS_Y && HasBit(slope, CORNER_W) != HasBit(slope, CORNER_E) ? SLOPE_EW : 0)),
679 (numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff)));
680 object.station_scope.axis = axis;
681
682 uint16_t cb_res = object.ResolveCallback();
683
684 /* Failed callback means success. */
685 if (cb_res == CALLBACK_FAILED) return CommandCost();
686
687 /* The meaning of bit 10 is inverted for a grf version < 8. */
688 if (statspec->grf_prop.grffile->grf_version < 8) ToggleBit(cb_res, 10);
689 return GetErrorMessageFromLocationCallbackResult(cb_res, statspec->grf_prop.grffile, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
690}
691
692
700int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
701{
702 uint i;
703
704 if (statspec == nullptr || st == nullptr) return 0;
705
706 for (i = 1; i < st->speclist.size() && i < NUM_STATIONSSPECS_PER_STATION; i++) {
707 if (st->speclist[i].spec == nullptr && st->speclist[i].grfid == 0) break;
708 }
709
711 /* As final effort when the spec list is already full...
712 * try to find the same spec and return that one. This might
713 * result in slightly "wrong" (as per specs) looking stations,
714 * but it's fairly unlikely that one reaches the limit anyways.
715 */
716 for (i = 1; i < st->speclist.size() && i < NUM_STATIONSSPECS_PER_STATION; i++) {
717 if (st->speclist[i].spec == statspec) return i;
718 }
719
720 return -1;
721 }
722
723 if (exec) {
724 if (i >= st->speclist.size()) st->speclist.resize(i + 1);
725 st->speclist[i].spec = statspec;
726 st->speclist[i].grfid = statspec->grf_prop.grfid;
727 st->speclist[i].localidx = statspec->grf_prop.local_id;
728
730 }
731
732 return i;
733}
734
735
742void DeallocateSpecFromStation(BaseStation *st, uint8_t specindex)
743{
744 /* specindex of 0 (default) is never freeable */
745 if (specindex == 0) return;
746
747 ETileArea area = ETileArea(st, INVALID_TILE, TA_WHOLE);
748 /* Check all tiles over the station to check if the specindex is still in use */
749 for (TileIndex tile : area) {
750 if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
751 return;
752 }
753 }
754
755 /* This specindex is no longer in use, so deallocate it */
756 st->speclist[specindex].spec = nullptr;
757 st->speclist[specindex].grfid = 0;
758 st->speclist[specindex].localidx = 0;
759
760 /* If this was the highest spec index, reallocate */
761 if (specindex == st->speclist.size() - 1) {
762 size_t num_specs;
763 for (num_specs = st->speclist.size() - 1; num_specs > 0; num_specs--) {
764 if (st->speclist[num_specs].grfid != 0) break;
765 }
766
767 if (num_specs > 0) {
768 st->speclist.resize(num_specs + 1);
769 } else {
770 st->speclist.clear();
771 st->cached_anim_triggers = 0;
772 st->cached_cargo_triggers = 0;
773 return;
774 }
775 }
776
778}
779
790bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
791{
792 const DrawTileSprites *sprites = nullptr;
793 const RailTypeInfo *rti = GetRailTypeInfo(railtype);
794 PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company);
795 uint tile = 2;
796
797 const StationSpec *statspec = StationClass::Get(sclass)->GetSpec(station);
798 if (statspec == nullptr) return false;
799
801 uint16_t callback = GetStationCallback(CBID_STATION_DRAW_TILE_LAYOUT, 0, 0, statspec, nullptr, INVALID_TILE);
802 if (callback != CALLBACK_FAILED) tile = callback & ~1;
803 }
804
805 uint32_t total_offset = rti->GetRailtypeSpriteOffset();
806 uint32_t relocation = 0;
807 uint32_t ground_relocation = 0;
808 const NewGRFSpriteLayout *layout = nullptr;
809 DrawTileSpriteSpan tmp_rail_layout;
810
811 if (statspec->renderdata.empty()) {
812 sprites = GetStationTileLayout(StationType::Rail, tile + axis);
813 } else {
814 layout = &statspec->renderdata[(tile < statspec->renderdata.size()) ? tile + axis : (uint)axis];
815 if (!layout->NeedsPreprocessing()) {
816 sprites = layout;
817 layout = nullptr;
818 }
819 }
820
821 if (layout != nullptr) {
822 /* Sprite layout which needs preprocessing */
823 bool separate_ground = statspec->flags.Test(StationSpecFlag::SeparateGround);
824 uint32_t var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground);
825 for (uint8_t var10 : SetBitIterator(var10_values)) {
826 uint32_t var10_relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, var10);
827 layout->ProcessRegisters(var10, var10_relocation, separate_ground);
828 }
829
830 tmp_rail_layout.seq = layout->GetLayout(&tmp_rail_layout.ground);
831 sprites = &tmp_rail_layout;
832 total_offset = 0;
833 } else {
834 /* Simple sprite layout */
835 ground_relocation = relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, 0);
837 ground_relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, 1);
838 }
839 ground_relocation += rti->fallback_railtype;
840 }
841
842 SpriteID image = sprites->ground.sprite;
843 PaletteID pal = sprites->ground.pal;
844 RailTrackOffset overlay_offset;
845 if (rti->UsesOverlay() && SplitGroundSpriteForOverlay(nullptr, &image, &overlay_offset)) {
847 DrawSprite(image, PAL_NONE, x, y);
848 DrawSprite(ground + overlay_offset, PAL_NONE, x, y);
849 } else {
850 image += HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? ground_relocation : total_offset;
851 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += ground_relocation;
852 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
853 }
854
855 DrawRailTileSeqInGUI(x, y, sprites, total_offset, relocation, palette);
856
857 return true;
858}
859
860
861const StationSpec *GetStationSpec(TileIndex t)
862{
863 if (!IsCustomStationSpecIndex(t)) return nullptr;
864
865 const BaseStation *st = BaseStation::GetByTile(t);
866 uint specindex = GetCustomStationSpecIndex(t);
867 return specindex < st->speclist.size() ? st->speclist[specindex].spec : nullptr;
868}
869
871uint16_t GetAnimStationCallback(CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, int)
872{
873 return GetStationCallback(callback, param1, param2, statspec, st, tile);
874}
875
884
885void AnimateStationTile(TileIndex tile)
886{
887 const StationSpec *ss = GetStationSpec(tile);
888 if (ss == nullptr) return;
889
891}
892
893void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoType cargo_type)
894{
895 /* List of coverage areas for each animation trigger */
896 static const TriggerArea tas[] = {
897 TA_TILE, TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_WHOLE
898 };
899
900 /* Get Station if it wasn't supplied */
901 if (st == nullptr) st = BaseStation::GetByTile(trigger_tile);
902
903 /* Check the cached animation trigger bitmask to see if we need
904 * to bother with any further processing. */
905 if (!HasBit(st->cached_anim_triggers, trigger)) return;
906
907 uint16_t random_bits = Random();
908 ETileArea area = ETileArea(st, trigger_tile, tas[trigger]);
909
910 /* Check all tiles over the station to check if the specindex is still in use */
911 for (TileIndex tile : area) {
912 if (st->TileBelongsToRailStation(tile)) {
913 const StationSpec *ss = GetStationSpec(tile);
914 if (ss != nullptr && HasBit(ss->animation.triggers, trigger)) {
915 CargoType cargo;
916 if (!IsValidCargoType(cargo_type)) {
917 cargo = INVALID_CARGO;
918 } else {
919 cargo = ss->grf_prop.grffile->cargo_map[cargo_type];
920 }
921 StationAnimationBase::ChangeAnimationFrame(CBID_STATION_ANIM_START_STOP, ss, st, tile, (random_bits << 16) | GB(Random(), 0, 16), (uint8_t)trigger | (cargo << 8));
922 }
923 }
924 }
925}
926
935{
936 /* List of coverage areas for each animation trigger */
937 static const TriggerArea tas[] = {
938 TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM
939 };
940
941 /* Get Station if it wasn't supplied */
942 if (st == nullptr) st = Station::GetByTile(trigger_tile);
943
944 /* Check the cached cargo trigger bitmask to see if we need
945 * to bother with any further processing. */
946 if (st->cached_cargo_triggers == 0) return;
947 if (IsValidCargoType(cargo_type) && !HasBit(st->cached_cargo_triggers, cargo_type)) return;
948
949 uint32_t whole_reseed = 0;
950 ETileArea area = ETileArea(st, trigger_tile, tas[trigger]);
951
952 /* Bitmask of completely empty cargo types to be matched. */
953 CargoTypes empty_mask = (trigger == SRT_CARGO_TAKEN) ? GetEmptyMask(st) : 0;
954
955 /* Store triggers now for var 5F */
956 SetBit(st->waiting_triggers, trigger);
957 uint32_t used_triggers = 0;
958
959 /* Check all tiles over the station to check if the specindex is still in use */
960 for (TileIndex tile : area) {
961 if (st->TileBelongsToRailStation(tile)) {
962 const StationSpec *ss = GetStationSpec(tile);
963 if (ss == nullptr) continue;
964
965 /* Cargo taken "will only be triggered if all of those
966 * cargo types have no more cargo waiting." */
967 if (trigger == SRT_CARGO_TAKEN) {
968 if ((ss->cargo_triggers & ~empty_mask) != 0) continue;
969 }
970
971 if (!IsValidCargoType(cargo_type) || HasBit(ss->cargo_triggers, cargo_type)) {
972 StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
973 object.waiting_triggers = st->waiting_triggers;
974
975 const SpriteGroup *group = object.Resolve();
976 if (group == nullptr) continue;
977
978 used_triggers |= object.used_triggers;
979
980 uint32_t reseed = object.GetReseedSum();
981 if (reseed != 0) {
982 whole_reseed |= reseed;
983 reseed >>= 16;
984
985 /* Set individual tile random bits */
986 uint8_t random_bits = GetStationTileRandomBits(tile);
987 random_bits &= ~reseed;
988 random_bits |= Random() & reseed;
989 SetStationTileRandomBits(tile, random_bits);
990
992 }
993 }
994 }
995 }
996
997 /* Update whole station random bits */
998 st->waiting_triggers &= ~used_triggers;
999 if ((whole_reseed & 0xFFFF) != 0) {
1000 st->random_bits &= ~whole_reseed;
1001 st->random_bits |= Random() & whole_reseed;
1002 }
1003}
1004
1010{
1011 st->cached_anim_triggers = 0;
1012 st->cached_cargo_triggers = 0;
1013
1014 /* Combine animation trigger bitmask for all station specs
1015 * of this station. */
1016 for (const auto &sm : GetStationSpecList<StationSpec>(st)) {
1017 if (sm.spec == nullptr) continue;
1018 st->cached_anim_triggers |= sm.spec->animation.triggers;
1019 st->cached_cargo_triggers |= sm.spec->cargo_triggers;
1020 }
1021}
1022
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
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.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:23
bool IsValidCargoType(CargoType t)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:106
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
uint PeriodsInTransit() const
Returns average number of cargo aging periods in transit for a cargo entity.
Common return value for all commands.
Struct containing information relating to NewGRF classes for stations and airports.
StringID name
Name of this class.
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
void Insert(Tspec *spec)
Insert a spec into the class, and update its index.
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.
static void InsertDefaults()
Initialise the defaults.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
This struct contains all the info that is needed to draw and construct tracks.
Definition rail.h:118
uint8_t fallback_railtype
Original railtype number to use when drawing non-newgrf railtypes, or when drawing stations.
Definition rail.h:192
uint GetRailtypeSpriteOffset() const
Offset between the current railtype and normal rail.
Definition rail.h:288
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
StationID GetFirstStation() const
Returns first station of the first cargo packet in this list.
static Date date
Current date in days (day counter).
static constexpr TimerGame< struct Calendar >::Date DAYS_TILL_ORIGINAL_BASE_YEAR
The date of the first day of the original base year.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
Direction
Defines the 8 directions on the map.
@ DIR_SW
Southwest.
@ DIR_NW
Northwest.
@ DIR_N
North.
@ DIR_SE
Southeast.
@ DIR_S
South.
@ DIR_NE
Northeast.
@ DIR_W
West.
@ DIR_E
East.
Axis
Allow incrementing of DiagDirDiff variables.
@ INVALID_AXIS
Flag for an invalid Axis.
@ AXIS_X
The X axis.
@ AXIS_Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_NW
Northwest.
@ DIAGDIR_SE
Southeast.
@ DIAGDIR_SW
Southwest.
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:989
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
@ Random
Randomise borders.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:388
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
Definition map_func.h:554
constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
Adds a given offset to a tile.
Definition map_func.h:456
TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Definition map_func.h:583
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:424
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:414
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
constexpr void Swap(T &a, T &b)
Type safe swap operation.
static constexpr CargoType SG_PURCHASE
Used in purchase lists before an item exists.
static constexpr CargoType SG_DEFAULT
Default type used when no more-specific cargo matches.
static constexpr CargoType SG_DEFAULT_NA
Used only by stations and roads when no more-specific cargo matches.
GrfSpecFeature
Definition newgrf.h:68
@ ATP_TTDP_LARGE
Same as AT_LARGE.
Function implementations related to NewGRF animation.
StationAnimationTrigger
Animation triggers for station.
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.
Functions related to NewGRF badges.
StationCallbackMask
Callback masks for stations.
@ DrawTileLayout
Use callback to select a tile layout to use when drawing.
@ AnimationNextFrame
Use a custom next frame callback.
@ AnimationSpeed
Customize the animation speed of the station.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_STATION_DRAW_TILE_LAYOUT
Choose a tile layout to draw, instead of the standard range.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
@ CBID_STATION_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
@ CBID_STATION_ANIM_START_STOP
Called for periodically starting or stopping the animation.
@ CBID_STATION_LAND_SLOPE_CHECK
Callback done for each tile of a station to check the slope.
@ CBID_STATION_ANIM_NEXT_FRAME
Called to determine station tile next animation frame.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
CargoType GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoType.
Cargo support for NewGRFs.
Implementation of the NewGRF class' functions.
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
uint32_t GetCompanyInfo(CompanyID owner, const Livery *l)
Returns company information like in vehicle var 43 or station var 43.
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
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 ...
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
@ Invalid
GRF is unusable with this version of OpenTTD.
uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
NewGRF handling of rail types.
Functions related to NewGRF provided sounds.
Action 2 handling.
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
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.
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.
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10)
Resolve sprites for drawing a station tile.
static struct @17 _svc
Station variable cache This caches 'expensive' station variable lookups which iterate over several ti...
void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoType cargo_type)
Trigger station randomisation.
SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
Resolve the sprites for custom station foundations.
uint8_t valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
Draw representation of a station tile for GUI purposes.
void DeallocateSpecFromStation(BaseStation *st, uint8_t specindex)
Deallocate a StationSpec from a Station.
static const uint NUM_STATIONSSPECS_PER_STATION
Maximum number of parts per station.
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.
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.
Header file for NewGRF stations.
@ Cb141RandomBits
Callback 141 needs random bits.
@ SeparateGround
Use different sprite set for ground sprites.
@ DivByStationSize
Divide cargo amount by station size.
StationRandomTrigger
Randomisation triggers for stations.
@ SRT_CARGO_TAKEN
Trigger station when cargo is completely taken.
StationClassID
Functions to handle the town part of NewGRF towns.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:300
@ RTSG_GROUND
Main group of ground images.
Definition rail.h:43
RailTrackOffset
Offsets for sprites within an overlay/underlay set.
Definition rail.h:61
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:27
Base class for roadstops.
A number of safeguards to prevent using unsafe methods.
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
@ SLOPE_EW
east and west corner are raised
Definition slope_type.h:59
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
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
static constexpr uint8_t SPRITE_MODIFIER_CUSTOM_SPRITE
these masks change the colours of the palette for a sprite.
Definition sprites.h:1549
Base classes/functions for stations.
CargoTypes GetEmptyMask(const Station *st)
Get a mask of the cargo types that are empty at the station.
const DrawTileSprites * GetStationTileLayout(StationType st, uint8_t gfx)
Get station tile layout for a station type and its station gfx.
CargoTypes GetAcceptanceMask(const Station *st)
Get a mask of the cargo types that the station accepts.
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...
StationGfx GetStationGfx(Tile t)
Get the station graphics of this tile.
Definition station_map.h:68
bool IsCompatibleTrainStationTile(Tile test_tile, Tile station_tile)
Check if a tile is a valid continuation to a railstation tile.
uint8_t GetStationTileRandomBits(Tile t)
Get the random bits of a station tile.
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
void SetStationTileRandomBits(Tile t, uint8_t random_bits)
Set the random bits for a station tile.
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
bool IsCustomStationSpecIndex(Tile t)
Is there a custom rail station spec on this tile?
bool HasStationRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
@ HVOT_WAYPOINT
Station is a waypoint (NewGRF only!)
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:277
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
AirportBlocks blocks
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Helper class for a unified approach to NewGRF animation.
static void AnimateTile(const StationSpec *spec, BaseStation *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
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.
uint16_t triggers
The triggers that trigger animation.
Base class for all station-ish types.
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.
StringID string_id
Default name (town area) of station.
std::vector< SpecMapping< StationSpec > > speclist
List of rail station specs of this station.
StationFacilities facilities
The facilities that this station has.
uint8_t cached_anim_triggers
NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
TileArea train_station
Tile area the train 'station' part covers.
Owner owner
The owner of this station.
virtual void GetTileArea(TileArea *ta, StationType type) const =0
Get the tile area for a given station type.
Town * town
The town this station is associated with.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
virtual bool TileBelongsToRailStation(TileIndex tile) const =0
Check whether a specific tile belongs to this station.
uint16_t random_bits
Random bits assigned to this station.
uint8_t waiting_triggers
Waiting triggers (NewGRF) for this station.
TimerGameCalendar::Date build_date
Date of construction.
CargoTypes cached_cargo_triggers
NOSAVE: Combined cargo trigger bitmask.
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:61
std::span< const DrawTileSeqStruct > seq
Child sprites,.
Definition sprite.h:62
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:46
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:47
const struct GRFFile * grffile
grf file that introduced this entity
uint16_t local_id
id defined by the grf file for this entity
uint32_t grfid
grfid that introduced this entity.
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoType -> local ID)
Definition newgrf.h:133
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Stores station stats for a single cargo.
bool HasRating() const
Does this cargo have a rating at this station?
uint8_t last_speed
Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
uint8_t last_age
Age in years (up to 255) of the last vehicle that tried to load this cargo.
uint8_t time_since_pickup
Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.
debug_inline const GoodsEntryData & GetData() const
Get optional cargo packet/flow data.
bool HasVehicleEverTriedLoading() const
Reports whether a vehicle has ever tried to load the cargo at this station.
uint8_t rating
Station rating for this cargo.
uint8_t status
Status of this cargo, see GoodsEntryStatus.
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
@ GES_LAST_MONTH
Set when cargo was delivered for final delivery last month.
@ GES_CURRENT_MONTH
Set when cargo was delivered for final delivery this month.
@ GES_EVER_ACCEPTED
Set when a vehicle ever delivered cargo to the station for final delivery.
@ GES_ACCEPTED_BIGTICK
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval.
debug_inline bool HasData() const
Test if this goods entry has optional cargo packet/flow data.
NewGRF supplied spritelayout.
uint32_t PrepareLayout(uint32_t orig_offset, uint32_t newgrf_ground_offset, uint32_t newgrf_offset, uint constr_stage, bool separate_ground) const
Prepares a sprite layout before resolving action-1-2-3 chains.
void ProcessRegisters(uint8_t resolved_var10, uint32_t resolved_sprite, bool separate_ground) const
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
bool NeedsPreprocessing() const
Tests whether this spritelayout needs preprocessing by PrepareLayout() and ProcessRegisters(),...
std::span< DrawTileSeqStruct > GetLayout(PalSpriteID *ground) const
Returns the result spritelayout after preprocessing.
Represents the covered area of e.g.
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
std::vector< const SpriteGroup * > loaded
List of loaded groups (can be SpriteIDs or Callback results)
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results)
Interface for SpriteGroup-s to access the gamestate.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
uint8_t status
Current status of the Stop,.
ResolverObject & ro
Surrounding resolver object.
Iterable ensemble of each set bit in a value.
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
Helper class for animation control.
Station resolver.
StationScopeResolver station_scope
The station scope resolver.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
TownScopeResolver * GetTown()
Get the town scope associated with a station, if it exists.
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
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.
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
CargoType cargo_type
Type of cargo of the station.
struct BaseStation * st
Instance of the station.
uint32_t GetTriggers() const override
Get the triggers.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
uint32_t GetRandomBits() const override
Get a few random bits.
const struct StationSpec * statspec
Station (type) specification.
Axis axis
Station axis, used only for the slope check callback.
TileIndex tile
Tile of the station.
Station specification.
VariableGRFFileProps grf_prop
Properties related the the grf file.
uint16_t cargo_threshold
Cargo threshold for choosing between little and lots of cargo.
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
std::vector< NewGRFSpriteLayout > renderdata
Number of tile layouts.
StationCallbackMasks callback_mask
Bitmask of station callbacks that have to be called.
StationSpecFlags flags
Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size.
Station data structure.
RoadStop * bus_stops
All the road stops.
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
bool TileBelongsToRailStation(TileIndex tile) const override
Check whether a specific tile belongs to this station.
Airport airport
Tile area the airport covers.
RoadStop * truck_stops
All the truck stops.
Scope resolver for a town.
Definition newgrf_town.h:22
Town data structure.
Definition town.h:52
std::vector< CargoSpriteGroup > spritegroups
pointers to the different sprite groups of the entity
const struct SpriteGroup * GetSpriteGroup(size_t index) const
Get the SpriteGroup at the specified index.
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.
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
Definition tile_map.h:250
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
Definition of the game-calendar-timer.
Base of the town class.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
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
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition track_func.h:363
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
@ TRACK_BIT_NONE
No track.
Definition track_type.h:36
@ TRANSPORT_RAIL
Transport by train.
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Base of waypoints.