OpenTTD Source: src/newgrf_station.cpp Source File

OpenTTD Source 14.0-RC3

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_cargo.h"
16 #include "newgrf_station.h"
17 #include "newgrf_spritegroup.h"
18 #include "newgrf_sound.h"
19 #include "newgrf_railtype.h"
20 #include "town.h"
21 #include "newgrf_town.h"
22 #include "company_func.h"
23 #include "tunnelbridge_map.h"
24 #include "newgrf_animation_base.h"
25 #include "newgrf_class_func.h"
26 #include "timer/timer_game_calendar.h"
27
28 #include "safeguards.h"
29
30
31 template <typename Tspec, typename Tid, Tid Tmax>
32 /* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
33 {
34 /* Set up initial data */
35 StationClass::Get(StationClass::Allocate('DFLT'))->name = STR_STATION_CLASS_DFLT;
36 StationClass::Get(StationClass::Allocate('DFLT'))->Insert(nullptr);
37 StationClass::Get(StationClass::Allocate('WAYP'))->name = STR_STATION_CLASS_WAYP;
38 StationClass::Get(StationClass::Allocate('WAYP'))->Insert(nullptr);
39 }
40
41 template <typename Tspec, typename Tid, Tid Tmax>
42 bool NewGRFClass<Tspec, Tid, Tmax>::IsUIAvailable(uint) const
43 {
44 return true;
45 }
46
47 INSTANTIATE_NEWGRF_CLASS_METHODS(StationClass, StationSpec, StationClassID, STAT_CLASS_MAX)
48
49 static const uint NUM_STATIONSSPECS_PER_STATION = 255;
50
51 enum TriggerArea {
52 TA_TILE,
53 TA_PLATFORM,
54 TA_WHOLE,
55 };
56
57 struct ETileArea : TileArea {
58 ETileArea(const BaseStation *st, TileIndex tile, TriggerArea ta)
59 {
60 switch (ta) {
61 default: NOT_REACHED();
62
63 case TA_TILE:
64 this->tile = tile;
65 this->w = 1;
66 this->h = 1;
67 break;
68
69 case TA_PLATFORM: {
70 TileIndex start, end;
71 Axis axis = GetRailStationAxis(tile);
72 TileIndexDiff delta = TileOffsByDiagDir(AxisToDiagDir(axis));
73
74 for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(end + delta, tile); end += delta) { /* Nothing */ }
75 for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(start - delta, tile); start -= delta) { /* Nothing */ }
76
77 this->tile = start;
78 this->w = TileX(end) - TileX(start) + 1;
79 this->h = TileY(end) - TileY(start) + 1;
80 break;
81 }
82
83 case TA_WHOLE:
84 st->GetTileArea(this, Station::IsExpected(st) ? STATION_RAIL : STATION_WAYPOINT);
85 break;
86 }
87 }
88 };
89
90
103 uint32_t GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred)
104 {
105 uint32_t retval = 0;
106
107 if (axis == AXIS_X) {
108 Swap(platforms, length);
109 Swap(x, y);
110 }
111
112 if (centred) {
113 x -= platforms / 2;
114 y -= length / 2;
115 x = Clamp(x, -8, 7);
116 y = Clamp(y, -8, 7);
117 SB(retval, 0, 4, y & 0xF);
118 SB(retval, 4, 4, x & 0xF);
119 } else {
120 SB(retval, 0, 4, std::min(15, y));
121 SB(retval, 4, 4, std::min(15, length - y - 1));
122 SB(retval, 8, 4, std::min(15, x));
123 SB(retval, 12, 4, std::min(15, platforms - x - 1));
124 }
125 SB(retval, 16, 4, std::min(15, length));
126 SB(retval, 20, 4, std::min(15, platforms));
127 SB(retval, 24, 4, tile);
128
129 return retval;
130 }
131
132
141 static TileIndex FindRailStationEnd(TileIndex tile, TileIndexDiff delta, bool check_type, bool check_axis)
142 {
143 byte orig_type = 0;
144 Axis orig_axis = AXIS_X;
145 StationID sid = GetStationIndex(tile);
146
147 if (check_type) orig_type = GetCustomStationSpecIndex(tile);
148 if (check_axis) orig_axis = GetRailStationAxis(tile);
149
150 for (;;) {
151 TileIndex new_tile = TILE_ADD(tile, delta);
152
153 if (!IsTileType(new_tile, MP_STATION) || GetStationIndex(new_tile) != sid) break;
154 if (!HasStationRail(new_tile)) break;
155 if (check_type && GetCustomStationSpecIndex(new_tile) != orig_type) break;
156 if (check_axis && GetRailStationAxis(new_tile) != orig_axis) break;
157
158 tile = new_tile;
159 }
160 return tile;
161 }
162
163
164 static uint32_t GetPlatformInfoHelper(TileIndex tile, bool check_type, bool check_axis, bool centred)
165 {
166 int tx = TileX(tile);
167 int ty = TileY(tile);
168 int sx = TileX(FindRailStationEnd(tile, TileDiffXY(-1, 0), check_type, check_axis));
169 int sy = TileY(FindRailStationEnd(tile, TileDiffXY( 0, -1), check_type, check_axis));
170 int ex = TileX(FindRailStationEnd(tile, TileDiffXY( 1, 0), check_type, check_axis)) + 1;
171 int ey = TileY(FindRailStationEnd(tile, TileDiffXY( 0, 1), check_type, check_axis)) + 1;
172
173 tx -= sx; ex -= sx;
174 ty -= sy; ey -= sy;
175
176 return GetPlatformInfo(GetRailStationAxis(tile), GetStationGfx(tile), ex, ey, tx, ty, centred);
177 }
178
179
180 static uint32_t GetRailContinuationInfo(TileIndex tile)
181 {
182 /* Tile offsets and exit dirs for X axis */
183 static const Direction x_dir[8] = { DIR_SW, DIR_NE, DIR_SE, DIR_NW, DIR_S, DIR_E, DIR_W, DIR_N };
184 static const DiagDirection x_exits[8] = { DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SW, DIAGDIR_NE };
185
186 /* Tile offsets and exit dirs for Y axis */
187 static const Direction y_dir[8] = { DIR_SE, DIR_NW, DIR_SW, DIR_NE, DIR_S, DIR_W, DIR_E, DIR_N };
188 static const DiagDirection y_exits[8] = { DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_NW };
189
190 Axis axis = GetRailStationAxis(tile);
191
192 /* Choose appropriate lookup table to use */
193 const Direction *dir = axis == AXIS_X ? x_dir : y_dir;
194 const DiagDirection *diagdir = axis == AXIS_X ? x_exits : y_exits;
195
196 uint32_t res = 0;
197 uint i;
198
199 for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) {
200 TileIndex neighbour_tile = tile + TileOffsByDir(*dir);
201 TrackBits trackbits = TrackStatusToTrackBits(GetTileTrackStatus(neighbour_tile, TRANSPORT_RAIL, 0));
202 if (trackbits != TRACK_BIT_NONE) {
203 /* If there is any track on the tile, set the bit in the second byte */
204 SetBit(res, i + 8);
205
206 /* With tunnels and bridges the tile has tracks, but they are not necessarily connected
207 * with the next tile because the ramp is not going in the right direction. */
208 if (IsTileType(neighbour_tile, MP_TUNNELBRIDGE) && GetTunnelBridgeDirection(neighbour_tile) != *diagdir) {
209 continue;
210 }
211
212 /* If any track reaches our exit direction, set the bit in the lower byte */
213 if (trackbits & DiagdirReachesTracks(*diagdir)) SetBit(res, i);
214 }
215 }
216
217 return res;
218 }
219
220
221 /* Station Resolver Functions */
222 /* virtual */ uint32_t StationScopeResolver::GetRandomBits() const
223 {
224 return (this->st == nullptr ? 0 : this->st->random_bits) | (this->tile == INVALID_TILE ? 0 : GetStationTileRandomBits(this->tile) << 16);
225 }
226
227
228 /* virtual */ uint32_t StationScopeResolver::GetTriggers() const
229 {
230 return this->st == nullptr ? 0 : this->st->waiting_triggers;
231 }
232
233
239 static struct {
240 uint32_t v40;
241 uint32_t v41;
242 uint32_t v45;
243 uint32_t v46;
244 uint32_t v47;
245 uint32_t v49;
246 uint8_t valid;
247 } _svc;
248
254 TownScopeResolver *StationResolverObject::GetTown()
255 {
256 if (this->town_scope == nullptr) {
257 Town *t = nullptr;
258 if (this->station_scope.st != nullptr) {
259 t = this->station_scope.st->town;
260 } else if (this->station_scope.tile != INVALID_TILE) {
261 t = ClosestTownFromTile(this->station_scope.tile, UINT_MAX);
262 }
263 if (t == nullptr) return nullptr;
264 this->town_scope = new TownScopeResolver(*this, t, this->station_scope.st == nullptr);
265 }
266 return this->town_scope;
267 }
268
269 /* virtual */ uint32_t StationScopeResolver::GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const
270 {
271 if (this->st == nullptr) {
272 /* Station does not exist, so we're in a purchase list or the land slope check callback. */
273 switch (variable) {
274 case 0x40:
275 case 0x41:
276 case 0x46:
277 case 0x47:
278 case 0x49: return 0x2110000; // Platforms, tracks & position
279 case 0x42: return 0; // Rail type (XXX Get current type from GUI?)
280 case 0x43: return GetCompanyInfo(_current_company); // Station owner
281 case 0x44: return 2; // PBS status
282 case 0x67: // Land info of nearby tile
283 if (this->axis != INVALID_AXIS && this->tile != INVALID_TILE) {
284 TileIndex tile = this->tile;
285 if (parameter != 0) tile = GetNearbyTile(parameter, tile, true, this->axis); // only perform if it is required
286
287 Slope tileh = GetTileSlope(tile);
288 bool swap = (this->axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
289
290 return GetNearbyTileInformation(tile, this->ro.grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
291 }
292 break;
293
294 case 0xFA: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value
295 }
296
297 *available = false;
298 return UINT_MAX;
299 }
300
301 switch (variable) {
302 /* Calculated station variables */
303 case 0x40:
304 if (!HasBit(_svc.valid, 0)) { _svc.v40 = GetPlatformInfoHelper(this->tile, false, false, false); SetBit(_svc.valid, 0); }
305 return _svc.v40;
306
307 case 0x41:
308 if (!HasBit(_svc.valid, 1)) { _svc.v41 = GetPlatformInfoHelper(this->tile, true, false, false); SetBit(_svc.valid, 1); }
309 return _svc.v41;
310
311 case 0x42: return GetTerrainType(this->tile) | (GetReverseRailTypeTranslation(GetRailType(this->tile), this->statspec->grf_prop.grffile) << 8);
312 case 0x43: return GetCompanyInfo(this->st->owner); // Station owner
313 case 0x44: return HasStationReservation(this->tile) ? 7 : 4; // PBS status
314 case 0x45:
315 if (!HasBit(_svc.valid, 2)) { _svc.v45 = GetRailContinuationInfo(this->tile); SetBit(_svc.valid, 2); }
316 return _svc.v45;
317
318 case 0x46:
319 if (!HasBit(_svc.valid, 3)) { _svc.v46 = GetPlatformInfoHelper(this->tile, false, false, true); SetBit(_svc.valid, 3); }
320 return _svc.v46;
321
322 case 0x47:
323 if (!HasBit(_svc.valid, 4)) { _svc.v47 = GetPlatformInfoHelper(this->tile, true, false, true); SetBit(_svc.valid, 4); }
324 return _svc.v47;
325
326 case 0x49:
327 if (!HasBit(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(this->tile, false, true, false); SetBit(_svc.valid, 5); }
328 return _svc.v49;
329
330 case 0x4A: // Animation frame of tile
331 return GetAnimationFrame(this->tile);
332
333 /* Variables which use the parameter */
334 /* Variables 0x60 to 0x65 and 0x69 are handled separately below */
335 case 0x66: { // Animation frame of nearby tile
336 TileIndex tile = this->tile;
337 if (parameter != 0) tile = GetNearbyTile(parameter, tile);
338 return this->st->TileBelongsToRailStation(tile) ? GetAnimationFrame(tile) : UINT_MAX;
339 }
340
341 case 0x67: { // Land info of nearby tile
342 Axis axis = GetRailStationAxis(this->tile);
343 TileIndex tile = this->tile;
344 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
345
346 Slope tileh = GetTileSlope(tile);
347 bool swap = (axis == AXIS_Y && HasBit(tileh, CORNER_W) != HasBit(tileh, CORNER_E));
348
349 return GetNearbyTileInformation(tile, this->ro.grffile->grf_version >= 8) ^ (swap ? SLOPE_EW : 0);
350 }
351
352 case 0x68: { // Station info of nearby tiles
353 TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
354
355 if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
356
357 uint32_t grfid = this->st->speclist[GetCustomStationSpecIndex(this->tile)].grfid;
358 bool perpendicular = GetRailStationAxis(this->tile) != GetRailStationAxis(nearby_tile);
359 bool same_station = this->st->TileBelongsToRailStation(nearby_tile);
360 uint32_t res = GB(GetStationGfx(nearby_tile), 1, 2) << 12 | !!perpendicular << 11 | !!same_station << 10;
361
362 if (IsCustomStationSpecIndex(nearby_tile)) {
363 const StationSpecList ssl = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
364 res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ClampTo<uint8_t>(ssl.localidx);
365 }
366 return res;
367 }
368
369 case 0x6A: { // GRFID of nearby station tiles
370 TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
371
372 if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
373 if (!IsCustomStationSpecIndex(nearby_tile)) return 0;
374
375 const StationSpecList ssl = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
376 return ssl.grfid;
377 }
378
379 case 0x6B: { // 16 bit Station ID of nearby tiles
380 TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
381
382 if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
383 if (!IsCustomStationSpecIndex(nearby_tile)) return 0xFFFE;
384
385 uint32_t grfid = this->st->speclist[GetCustomStationSpecIndex(this->tile)].grfid;
386
387 const StationSpecList ssl = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)];
388 if (ssl.grfid == grfid) {
389 return ssl.localidx;
390 }
391
392 return 0xFFFE;
393 }
394
395 /* General station variables */
396 case 0x82: return 50;
397 case 0x84: return this->st->string_id;
398 case 0x86: return 0;
399 case 0xF0: return this->st->facilities;
400 case 0xFA: return ClampTo<uint16_t>(this->st->build_date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR);
401 }
402
403 return this->st->GetNewGRFVariable(this->ro, variable, parameter, available);
404 }
405
406 uint32_t Station::GetNewGRFVariable(const ResolverObject &object, byte variable, byte parameter, bool *available) const
407 {
408 switch (variable) {
409 case 0x48: { // Accepted cargo types
410 uint32_t value = GetAcceptanceMask(this);
411 return value;
412 }
413
414 case 0x8A: return this->had_vehicle_of_type;
415 case 0xF1: return (this->airport.tile != INVALID_TILE) ? this->airport.GetSpec()->ttd_airport_type : ATP_TTDP_LARGE;
416 case 0xF2: return (this->truck_stops != nullptr) ? this->truck_stops->status : 0;
417 case 0xF3: return (this->bus_stops != nullptr) ? this->bus_stops->status : 0;
418 case 0xF6: return this->airport.flags;
419 case 0xF7: return GB(this->airport.flags, 8, 8);
420 }
421
422 /* Handle cargo variables with parameter, 0x60 to 0x65 and 0x69 */
423 if ((variable >= 0x60 && variable <= 0x65) || variable == 0x69) {
424 CargoID c = GetCargoTranslation(parameter, object.grffile);
425
426 if (!IsValidCargoID(c)) {
427 switch (variable) {
428 case 0x62: return 0xFFFFFFFF;
429 case 0x64: return 0xFF00;
430 default: return 0;
431 }
432 }
433 const GoodsEntry *ge = &this->goods[c];
434
435 switch (variable) {
436 case 0x60: return std::min(ge->cargo.TotalCount(), 4095u);
437 case 0x61: return ge->HasVehicleEverTriedLoading() ? ge->time_since_pickup : 0;
438 case 0x62: return ge->HasRating() ? ge->rating : 0xFFFFFFFF;
439 case 0x63: return ge->cargo.PeriodsInTransit();
440 case 0x64: return ge->HasVehicleEverTriedLoading() ? ge->last_speed | (ge->last_age << 8) : 0xFF00;
441 case 0x65: return GB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1) << 3;
442 case 0x69: {
443 static_assert((int)GoodsEntry::GES_EVER_ACCEPTED + 1 == (int)GoodsEntry::GES_LAST_MONTH);
444 static_assert((int)GoodsEntry::GES_EVER_ACCEPTED + 2 == (int)GoodsEntry::GES_CURRENT_MONTH);
445 static_assert((int)GoodsEntry::GES_EVER_ACCEPTED + 3 == (int)GoodsEntry::GES_ACCEPTED_BIGTICK);
446 return GB(ge->status, GoodsEntry::GES_EVER_ACCEPTED, 4);
447 }
448 }
449 }
450
451 /* Handle cargo variables (deprecated) */
452 if (variable >= 0x8C && variable <= 0xEC) {
453 const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)];
454 switch (GB(variable - 0x8C, 0, 3)) {
455 case 0: return g->cargo.TotalCount();
456 case 1: return GB(std::min(g->cargo.TotalCount(), 4095u), 0, 4) | (GB(g->status, GoodsEntry::GES_ACCEPTANCE, 1) << 7);
457 case 2: return g->time_since_pickup;
458 case 3: return g->rating;
459 case 4: return g->cargo.GetFirstStation();
460 case 5: return g->cargo.PeriodsInTransit();
461 case 6: return g->last_speed;
462 case 7: return g->last_age;
463 }
464 }
465
466 Debug(grf, 1, "Unhandled station variable 0x{:X}", variable);
467
468 *available = false;
469 return UINT_MAX;
470 }
471
472 uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, byte variable, [[maybe_unused]] byte parameter, bool *available) const
473 {
474 switch (variable) {
475 case 0x48: return 0; // Accepted cargo types
476 case 0x8A: return HVOT_WAYPOINT;
477 case 0xF1: return 0; // airport type
478 case 0xF2: return 0; // truck stop status
479 case 0xF3: return 0; // bus stop status
480 case 0xF6: return 0; // airport flags
481 case 0xF7: return 0; // airport flags cont.
482 }
483
484 /* Handle cargo variables with parameter, 0x60 to 0x65 */
485 if (variable >= 0x60 && variable <= 0x65) {
486 return 0;
487 }
488
489 /* Handle cargo variables (deprecated) */
490 if (variable >= 0x8C && variable <= 0xEC) {
491 switch (GB(variable - 0x8C, 0, 3)) {
492 case 3: return INITIAL_STATION_RATING;
493 case 4: return INVALID_STATION;
494 default: return 0;
495 }
496 }
497
498 Debug(grf, 1, "Unhandled station variable 0x{:X}", variable);
499
500 *available = false;
501 return UINT_MAX;
502 }
503
504 /* virtual */ const SpriteGroup *StationResolverObject::ResolveReal(const RealSpriteGroup *group) const
505 {
506 if (this->station_scope.st == nullptr || this->station_scope.statspec->cls_id == STAT_CLASS_WAYP) {
507 return group->loading[0];
508 }
509
510 uint cargo = 0;
511 const Station *st = Station::From(this->station_scope.st);
512
513 switch (this->station_scope.cargo_type) {
514 case INVALID_CARGO:
515 case SpriteGroupCargo::SG_DEFAULT_NA:
516 case SpriteGroupCargo::SG_PURCHASE:
517 cargo = 0;
518 break;
519
520 case SpriteGroupCargo::SG_DEFAULT:
521 for (const GoodsEntry &ge : st->goods) {
522 cargo += ge.cargo.TotalCount();
523 }
524 break;
525
526 default:
527 cargo = st->goods[this->station_scope.cargo_type].cargo.TotalCount();
528 break;
529 }
530
531 if (HasBit(this->station_scope.statspec->flags, SSF_DIV_BY_STATION_SIZE)) cargo /= (st->train_station.w + st->train_station.h);
532 cargo = std::min(0xfffu, cargo);
533
534 if (cargo > this->station_scope.statspec->cargo_threshold) {
535 if (!group->loading.empty()) {
536 uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * (uint)group->loading.size()) / (4096 - this->station_scope.statspec->cargo_threshold);
537 return group->loading[set];
538 }
539 } else {
540 if (!group->loaded.empty()) {
541 uint set = (cargo * (uint)group->loaded.size()) / (this->station_scope.statspec->cargo_threshold + 1);
542 return group->loaded[set];
543 }
544 }
545
546 return group->loading[0];
547 }
548
549 GrfSpecFeature StationResolverObject::GetFeature() const
550 {
551 return GSF_STATIONS;
552 }
553
554 uint32_t StationResolverObject::GetDebugID() const
555 {
556 return this->station_scope.statspec->grf_prop.local_id;
557 }
558
568 StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseStation *base_station, TileIndex tile,
569 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
570 : ResolverObject(statspec->grf_prop.grffile, callback, callback_param1, callback_param2),
571 station_scope(*this, statspec, base_station, tile), town_scope(nullptr)
572 {
573 /* Invalidate all cached vars */
574 _svc.valid = 0;
575
576 CargoID ctype = SpriteGroupCargo::SG_DEFAULT_NA;
577
578 if (this->station_scope.st == nullptr) {
579 /* No station, so we are in a purchase list */
580 ctype = SpriteGroupCargo::SG_PURCHASE;
581 } else if (Station::IsExpected(this->station_scope.st)) {
582 const Station *st = Station::From(this->station_scope.st);
583 /* Pick the first cargo that we have waiting */
584 for (const CargoSpec *cs : CargoSpec::Iterate()) {
585 if (this->station_scope.statspec->grf_prop.spritegroup[cs->Index()] != nullptr &&
586 st->goods[cs->Index()].cargo.TotalCount() > 0) {
587 ctype = cs->Index();
588 break;
589 }
590 }
591 }
592
593 if (this->station_scope.statspec->grf_prop.spritegroup[ctype] == nullptr) {
594 ctype = SpriteGroupCargo::SG_DEFAULT;
595 }
596
597 /* Remember the cargo type we've picked */
598 this->station_scope.cargo_type = ctype;
599 this->root_spritegroup = this->station_scope.statspec->grf_prop.spritegroup[this->station_scope.cargo_type];
600 }
601
602 StationResolverObject::~StationResolverObject()
603 {
604 delete this->town_scope;
605 }
606
615 SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10)
616 {
617 StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, var10);
618 const SpriteGroup *group = object.Resolve();
619 if (group == nullptr || group->type != SGT_RESULT) return 0;
620 return group->GetResult() - 0x42D;
621 }
622
632 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info)
633 {
634 /* callback_param1 == 2 means we are resolving the foundation sprites. */
635 StationResolverObject object(statspec, st, tile, CBID_NO_CALLBACK, 2, layout | (edge_info << 16));
636
637 const SpriteGroup *group = object.Resolve();
638 if (group == nullptr || group->type != SGT_RESULT) return 0;
639
640 /* Note: SpriteGroup::Resolve zeroes all registers, so register 0x100 is initialised to 0. (compatibility) */
641 return group->GetResult() + GetRegister(0x100);
642 }
643
644
645 uint16_t GetStationCallback(CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile)
646 {
647 StationResolverObject object(statspec, st, tile, callback, param1, param2);
648 return object.ResolveCallback();
649 }
650
661 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
662 {
663 TileIndex diff = cur_tile - north_tile;
664 Slope slope = GetTileSlope(cur_tile);
665
666 StationResolverObject object(statspec, nullptr, cur_tile, CBID_STATION_LAND_SLOPE_CHECK,
667 (slope << 4) | (slope ^ (axis == AXIS_Y && HasBit(slope, CORNER_W) != HasBit(slope, CORNER_E) ? SLOPE_EW : 0)),
668 (numtracks << 24) | (plat_len << 16) | (axis == AXIS_Y ? TileX(diff) << 8 | TileY(diff) : TileY(diff) << 8 | TileX(diff)));
669 object.station_scope.axis = axis;
670
671 uint16_t cb_res = object.ResolveCallback();
672
673 /* Failed callback means success. */
674 if (cb_res == CALLBACK_FAILED) return CommandCost();
675
676 /* The meaning of bit 10 is inverted for a grf version < 8. */
677 if (statspec->grf_prop.grffile->grf_version < 8) ToggleBit(cb_res, 10);
678 return GetErrorMessageFromLocationCallbackResult(cb_res, statspec->grf_prop.grffile, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
679 }
680
681
689 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
690 {
691 uint i;
692
693 if (statspec == nullptr || st == nullptr) return 0;
694
695 for (i = 1; i < st->speclist.size() && i < NUM_STATIONSSPECS_PER_STATION; i++) {
696 if (st->speclist[i].spec == nullptr && st->speclist[i].grfid == 0) break;
697 }
698
699 if (i == NUM_STATIONSSPECS_PER_STATION) {
700 /* As final effort when the spec list is already full...
701 * try to find the same spec and return that one. This might
702 * result in slightly "wrong" (as per specs) looking stations,
703 * but it's fairly unlikely that one reaches the limit anyways.
704 */
705 for (i = 1; i < st->speclist.size() && i < NUM_STATIONSSPECS_PER_STATION; i++) {
706 if (st->speclist[i].spec == statspec) return i;
707 }
708
709 return -1;
710 }
711
712 if (exec) {
713 if (i >= st->speclist.size()) st->speclist.resize(i + 1);
714 st->speclist[i].spec = statspec;
715 st->speclist[i].grfid = statspec->grf_prop.grffile->grfid;
716 st->speclist[i].localidx = statspec->grf_prop.local_id;
717
718 StationUpdateCachedTriggers(st);
719 }
720
721 return i;
722 }
723
724
731 void DeallocateSpecFromStation(BaseStation *st, byte specindex)
732 {
733 /* specindex of 0 (default) is never freeable */
734 if (specindex == 0) return;
735
736 ETileArea area = ETileArea(st, INVALID_TILE, TA_WHOLE);
737 /* Check all tiles over the station to check if the specindex is still in use */
738 for (TileIndex tile : area) {
739 if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
740 return;
741 }
742 }
743
744 /* This specindex is no longer in use, so deallocate it */
745 st->speclist[specindex].spec = nullptr;
746 st->speclist[specindex].grfid = 0;
747 st->speclist[specindex].localidx = 0;
748
749 /* If this was the highest spec index, reallocate */
750 if (specindex == st->speclist.size() - 1) {
751 size_t num_specs;
752 for (num_specs = st->speclist.size() - 1; num_specs > 0; num_specs--) {
753 if (st->speclist[num_specs].grfid != 0) break;
754 }
755
756 if (num_specs > 0) {
757 st->speclist.resize(num_specs + 1);
758 } else {
759 st->speclist.clear();
760 st->cached_anim_triggers = 0;
761 st->cached_cargo_triggers = 0;
762 return;
763 }
764 }
765
766 StationUpdateCachedTriggers(st);
767 }
768
779 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
780 {
781 const DrawTileSprites *sprites = nullptr;
782 const RailTypeInfo *rti = GetRailTypeInfo(railtype);
783 PaletteID palette = COMPANY_SPRITE_COLOUR(_local_company);
784 uint tile = 2;
785
786 const StationSpec *statspec = StationClass::Get(sclass)->GetSpec(station);
787 if (statspec == nullptr) return false;
788
789 if (HasBit(statspec->callback_mask, CBM_STATION_SPRITE_LAYOUT)) {
790 uint16_t callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, nullptr, INVALID_TILE);
791 if (callback != CALLBACK_FAILED) tile = callback & ~1;
792 }
793
794 uint32_t total_offset = rti->GetRailtypeSpriteOffset();
795 uint32_t relocation = 0;
796 uint32_t ground_relocation = 0;
797 const NewGRFSpriteLayout *layout = nullptr;
798 DrawTileSprites tmp_rail_layout;
799
800 if (statspec->renderdata.empty()) {
801 sprites = GetStationTileLayout(STATION_RAIL, tile + axis);
802 } else {
803 layout = &statspec->renderdata[(tile < statspec->renderdata.size()) ? tile + axis : (uint)axis];
804 if (!layout->NeedsPreprocessing()) {
805 sprites = layout;
806 layout = nullptr;
807 }
808 }
809
810 if (layout != nullptr) {
811 /* Sprite layout which needs preprocessing */
812 bool separate_ground = HasBit(statspec->flags, SSF_SEPARATE_GROUND);
813 uint32_t var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground);
814 for (uint8_t var10 : SetBitIterator(var10_values)) {
815 uint32_t var10_relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, var10);
816 layout->ProcessRegisters(var10, var10_relocation, separate_ground);
817 }
818
819 tmp_rail_layout.seq = layout->GetLayout(&tmp_rail_layout.ground);
820 sprites = &tmp_rail_layout;
821 total_offset = 0;
822 } else {
823 /* Simple sprite layout */
824 ground_relocation = relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, 0);
825 if (HasBit(sprites->ground.sprite, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
826 ground_relocation = GetCustomStationRelocation(statspec, nullptr, INVALID_TILE, 1);
827 }
828 ground_relocation += rti->fallback_railtype;
829 }
830
831 SpriteID image = sprites->ground.sprite;
832 PaletteID pal = sprites->ground.pal;
833 RailTrackOffset overlay_offset;
834 if (rti->UsesOverlay() && SplitGroundSpriteForOverlay(nullptr, &image, &overlay_offset)) {
835 SpriteID ground = GetCustomRailSprite(rti, INVALID_TILE, RTSG_GROUND);
836 DrawSprite(image, PAL_NONE, x, y);
837 DrawSprite(ground + overlay_offset, PAL_NONE, x, y);
838 } else {
839 image += HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? ground_relocation : total_offset;
840 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += ground_relocation;
841 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
842 }
843
844 DrawRailTileSeqInGUI(x, y, sprites, total_offset, relocation, palette);
845
846 return true;
847 }
848
849
850 const StationSpec *GetStationSpec(TileIndex t)
851 {
852 if (!IsCustomStationSpecIndex(t)) return nullptr;
853
854 const BaseStation *st = BaseStation::GetByTile(t);
855 uint specindex = GetCustomStationSpecIndex(t);
856 return specindex < st->speclist.size() ? st->speclist[specindex].spec : nullptr;
857 }
858
860 uint16_t GetAnimStationCallback(CallbackID callback, uint32_t param1, uint32_t param2, const StationSpec *statspec, BaseStation *st, TileIndex tile, int)
861 {
862 return GetStationCallback(callback, param1, param2, statspec, st, tile);
863 }
864
866 struct StationAnimationBase : public AnimationBase<StationAnimationBase, StationSpec, BaseStation, int, GetAnimStationCallback, TileAnimationFrameAnimationHelper<BaseStation> > {
867 static const CallbackID cb_animation_speed = CBID_STATION_ANIMATION_SPEED;
868 static const CallbackID cb_animation_next_frame = CBID_STATION_ANIM_NEXT_FRAME;
869
870 static const StationCallbackMask cbm_animation_speed = CBM_STATION_ANIMATION_SPEED;
871 static const StationCallbackMask cbm_animation_next_frame = CBM_STATION_ANIMATION_NEXT_FRAME;
872 };
873
874 void AnimateStationTile(TileIndex tile)
875 {
876 const StationSpec *ss = GetStationSpec(tile);
877 if (ss == nullptr) return;
878
879 StationAnimationBase::AnimateTile(ss, BaseStation::GetByTile(tile), tile, HasBit(ss->flags, SSF_CB141_RANDOM_BITS));
880 }
881
882 void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoID cargo_type)
883 {
884 /* List of coverage areas for each animation trigger */
885 static const TriggerArea tas[] = {
886 TA_TILE, TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_WHOLE
887 };
888
889 /* Get Station if it wasn't supplied */
890 if (st == nullptr) st = BaseStation::GetByTile(trigger_tile);
891
892 /* Check the cached animation trigger bitmask to see if we need
893 * to bother with any further processing. */
894 if (!HasBit(st->cached_anim_triggers, trigger)) return;
895
896 uint16_t random_bits = Random();
897 ETileArea area = ETileArea(st, trigger_tile, tas[trigger]);
898
899 /* Check all tiles over the station to check if the specindex is still in use */
900 for (TileIndex tile : area) {
901 if (st->TileBelongsToRailStation(tile)) {
902 const StationSpec *ss = GetStationSpec(tile);
903 if (ss != nullptr && HasBit(ss->animation.triggers, trigger)) {
904 CargoID cargo;
905 if (!IsValidCargoID(cargo_type)) {
906 cargo = INVALID_CARGO;
907 } else {
908 cargo = ss->grf_prop.grffile->cargo_map[cargo_type];
909 }
910 StationAnimationBase::ChangeAnimationFrame(CBID_STATION_ANIM_START_STOP, ss, st, tile, (random_bits << 16) | GB(Random(), 0, 16), (uint8_t)trigger | (cargo << 8));
911 }
912 }
913 }
914 }
915
923 void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoID cargo_type)
924 {
925 /* List of coverage areas for each animation trigger */
926 static const TriggerArea tas[] = {
927 TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM
928 };
929
930 /* Get Station if it wasn't supplied */
931 if (st == nullptr) st = Station::GetByTile(trigger_tile);
932
933 /* Check the cached cargo trigger bitmask to see if we need
934 * to bother with any further processing. */
935 if (st->cached_cargo_triggers == 0) return;
936 if (IsValidCargoID(cargo_type) && !HasBit(st->cached_cargo_triggers, cargo_type)) return;
937
938 uint32_t whole_reseed = 0;
939 ETileArea area = ETileArea(st, trigger_tile, tas[trigger]);
940
941 /* Bitmask of completely empty cargo types to be matched. */
942 CargoTypes empty_mask = (trigger == SRT_CARGO_TAKEN) ? GetEmptyMask(st) : 0;
943
944 /* Store triggers now for var 5F */
945 SetBit(st->waiting_triggers, trigger);
946 uint32_t used_triggers = 0;
947
948 /* Check all tiles over the station to check if the specindex is still in use */
949 for (TileIndex tile : area) {
950 if (st->TileBelongsToRailStation(tile)) {
951 const StationSpec *ss = GetStationSpec(tile);
952 if (ss == nullptr) continue;
953
954 /* Cargo taken "will only be triggered if all of those
955 * cargo types have no more cargo waiting." */
956 if (trigger == SRT_CARGO_TAKEN) {
957 if ((ss->cargo_triggers & ~empty_mask) != 0) continue;
958 }
959
960 if (!IsValidCargoID(cargo_type) || HasBit(ss->cargo_triggers, cargo_type)) {
961 StationResolverObject object(ss, st, tile, CBID_RANDOM_TRIGGER, 0);
962 object.waiting_triggers = st->waiting_triggers;
963
964 const SpriteGroup *group = object.Resolve();
965 if (group == nullptr) continue;
966
967 used_triggers |= object.used_triggers;
968
969 uint32_t reseed = object.GetReseedSum();
970 if (reseed != 0) {
971 whole_reseed |= reseed;
972 reseed >>= 16;
973
974 /* Set individual tile random bits */
975 uint8_t random_bits = GetStationTileRandomBits(tile);
976 random_bits &= ~reseed;
977 random_bits |= Random() & reseed;
978 SetStationTileRandomBits(tile, random_bits);
979
980 MarkTileDirtyByTile(tile);
981 }
982 }
983 }
984 }
985
986 /* Update whole station random bits */
987 st->waiting_triggers &= ~used_triggers;
988 if ((whole_reseed & 0xFFFF) != 0) {
989 st->random_bits &= ~whole_reseed;
990 st->random_bits |= Random() & whole_reseed;
991 }
992 }
993
998 void StationUpdateCachedTriggers(BaseStation *st)
999 {
1000 st->cached_anim_triggers = 0;
1001 st->cached_cargo_triggers = 0;
1002
1003 /* Combine animation trigger bitmask for all station specs
1004 * of this station. */
1005 for (uint i = 0; i < st->speclist.size(); i++) {
1006 const StationSpec *ss = st->speclist[i].spec;
1007 if (ss != nullptr) {
1008 st->cached_anim_triggers |= ss->animation.triggers;
1009 st->cached_cargo_triggers |= ss->cargo_triggers;
1010 }
1011 }
1012 }
1013
AllocateSpecToStation
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition: newgrf_station.cpp:689
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
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:75
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition: direction_type.h:76
TileOffsByDir
TileIndexDiff TileOffsByDir(Direction dir)
Convert a Direction to a TileIndexDiff.
Definition: map_func.h:577
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:2884
BaseStation::speclist
std::vector< StationSpecList > speclist
List of rail station specs of this station.
Definition: base_station_base.h:77
TILE_ADD
#define TILE_ADD(x, y)
Adds two tiles together.
Definition: map_func.h:466
DIR_SW
@ DIR_SW
Southwest.
Definition: direction_type.h:31
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:168
StationScopeResolver::cargo_type
CargoID cargo_type
Type of cargo of the station.
Definition: newgrf_station.h:28
AXIS_Y
@ AXIS_Y
The y axis.
Definition: direction_type.h:118
Airport::flags
uint64_t flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition: station_base.h:293
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:471
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:36
GoodsEntry::rating
uint8_t rating
Station rating for this cargo.
Definition: station_base.h:226
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
newgrf_station.h
StationSpec::flags
byte flags
Bitmask of flags, bit 0: use different sprite set; bit 1: divide cargo about by station size.
Definition: newgrf_station.h:159
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
StationSpecList::grfid
uint32_t grfid
GRF ID of this custom station.
Definition: base_station_base.h:24
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
StationSpec::renderdata
std::vector< NewGRFSpriteLayout > renderdata
Number of tile layouts.
Definition: newgrf_station.h:147
DIR_SE
@ DIR_SE
Southeast.
Definition: direction_type.h:29
Swap
constexpr void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:283
GetRailTypeInfo
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:307
RailTypeInfo::GetRailtypeSpriteOffset
uint GetRailtypeSpriteOffset() const
Offset between the current railtype and normal rail.
Definition: rail.h:295
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:3744
BaseStation::GetTileArea
virtual void GetTileArea(TileArea *ta, StationType type) const =0
Get the tile area for a given station type.
BaseStation::waiting_triggers
byte waiting_triggers
Waiting triggers (NewGRF) for this station.
Definition: base_station_base.h:83
StationRandomTrigger
StationRandomTrigger
Randomisation triggers for stations.
Definition: newgrf_station.h:102
tunnelbridge_map.h
BaseStation::town
Town * town
The town this station is associated with.
Definition: base_station_base.h:73
timer_game_calendar.h
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:116
Station
Station data structure.
Definition: station_base.h:442
BaseStation::GetByTile
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
Definition: base_station_base.h:171
StationSpecList
Definition: base_station_base.h:22
AnimationInfo::triggers
uint16_t triggers
The triggers that trigger animation.
Definition: newgrf_animation_type.h:22
DIR_NW
@ DIR_NW
Northwest.
Definition: direction_type.h:33
SSF_DIV_BY_STATION_SIZE
@ SSF_DIV_BY_STATION_SIZE
Divide cargo amount by station size.
Definition: newgrf_station.h:95
GB
constexpr static debug_inline 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
GetRegister
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Definition: newgrf_spritegroup.h:29
valid
uint8_t valid
Bits indicating what variable is valid (for each bit, 0 is invalid, 1 is valid).
Definition: newgrf_station.cpp:246
INSTANTIATE_NEWGRF_CLASS_METHODS
#define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
Force instantiation of the methods so we don't get linker errors.
Definition: newgrf_class_func.h:212
GetAcceptanceMask
CargoTypes GetAcceptanceMask(const Station *st)
Get a mask of the cargo types that the station accepts.
Definition: station_cmd.cpp:497
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition: newgrf_spritegroup.h:335
RailTypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:127
newgrf_animation_base.h
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:860
StationScopeResolver::statspec
const struct StationSpec * statspec
Station (type) specification.
Definition: newgrf_station.h:27
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:451
IsRailStationTile
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
Definition: station_map.h:102
CargoSpec::Iterate
static IterateWrapper Iterate(size_t from=0)
Returns an iterable ensemble of all valid CargoSpec.
Definition: cargotype.h:187
CBM_STATION_ANIMATION_NEXT_FRAME
@ CBM_STATION_ANIMATION_NEXT_FRAME
Use a custom next frame callback.
Definition: newgrf_callbacks.h:312
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:99
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:68
town.h
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
newgrf_class_func.h
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition: direction_type.h:78
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:331
DIR_W
@ DIR_W
West.
Definition: direction_type.h:32
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
StationScopeResolver::GetTriggers
uint32_t GetTriggers() const override
Get the triggers.
Definition: newgrf_station.cpp:228
NewGRFSpriteLayout::ProcessRegisters
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.
Definition: newgrf_commons.cpp:710
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
StationResolverObject::station_scope
StationScopeResolver station_scope
The station scope resolver.
Definition: newgrf_station.h:51
StationResolverObject::GetTown
TownScopeResolver * GetTown()
Get the town scope associated with a station, if it exists.
Definition: newgrf_station.cpp:254
DeallocateSpecFromStation
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Definition: newgrf_station.cpp:731
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:74
DIR_N
@ DIR_N
North.
Definition: direction_type.h:26
NUM_STATIONSSPECS_PER_STATION
static const uint NUM_STATIONSSPECS_PER_STATION
Maximum number of parts per station.
Definition: newgrf_station.cpp:49
GetCustomStationRelocation
SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32_t var10)
Resolve sprites for drawing a station tile.
Definition: newgrf_station.cpp:615
GetRailStationAxis
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Definition: station_map.h:410
GoodsEntry::status
byte status
Status of this cargo, see GoodsEntryStatus.
Definition: station_base.h:217
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition: tilearea_type.h:21
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:224
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition: cargopacket.h:607
BaseStation::TileBelongsToRailStation
virtual bool TileBelongsToRailStation(TileIndex tile) const =0
Check whether a specific tile belongs to this station.
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition: base_station_base.h:70
GetTileTrackStatus
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:556
BaseStation::cached_cargo_triggers
CargoTypes cached_cargo_triggers
NOSAVE: Combined cargo trigger bitmask.
Definition: base_station_base.h:86
SSF_SEPARATE_GROUND
@ SSF_SEPARATE_GROUND
Use different sprite set for ground sprites.
Definition: newgrf_station.h:94
SSF_CB141_RANDOM_BITS
@ SSF_CB141_RANDOM_BITS
Callback 141 needs random bits.
Definition: newgrf_station.h:96
GoodsEntry::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:210
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
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:36
RealSpriteGroup::loading
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results)
Definition: newgrf_spritegroup.h:90
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
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:568
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition: direction_type.h:77
StationCallbackMask
StationCallbackMask
Callback masks for stations.
Definition: newgrf_callbacks.h:309
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
GetStationGfx
StationGfx GetStationGfx(Tile t)
Get the station graphics of this tile.
Definition: station_map.h:68
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
STAT_CLASS_WAYP
@ STAT_CLASS_WAYP
Waypoint class.
Definition: newgrf_station.h:86
CommandCost
Common return value for all commands.
Definition: command_type.h:23
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:212
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:282
GoodsEntry::GES_EVER_ACCEPTED
@ GES_EVER_ACCEPTED
Set when a vehicle ever delivered cargo to the station for final delivery.
Definition: station_base.h:189
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition: base_station_base.h:89
StationScopeResolver::GetVariable
uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override
Get a variable value.
Definition: newgrf_station.cpp:269
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:450
DIR_E
@ DIR_E
East.
Definition: direction_type.h:28
CBM_STATION_ANIMATION_SPEED
@ CBM_STATION_ANIMATION_SPEED
Customize the animation speed of the station.
Definition: newgrf_callbacks.h:313
StationResolverObject::town_scope
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Definition: newgrf_station.h:52
GetStationTileRandomBits
byte GetStationTileRandomBits(Tile t)
Get the random bits of a station tile.
Definition: station_map.h:609
roadstop_base.h
GoodsEntry::HasRating
bool HasRating() const
Does this cargo have a rating at this station?
Definition: station_base.h:258
HVOT_WAYPOINT
@ HVOT_WAYPOINT
Station is a waypoint (NewGRF only!)
Definition: station_type.h:70
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:22
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition: newgrf_spritegroup.h:336
GoodsEntry::GES_ACCEPTED_BIGTICK
@ GES_ACCEPTED_BIGTICK
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval.
Definition: station_base.h:207
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:240
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:456
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
DIR_NE
@ DIR_NE
Northeast.
Definition: direction_type.h:27
AxisToDiagDir
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Definition: direction_func.h:232
SpriteGroupCargo::SG_DEFAULT
static constexpr CargoID SG_DEFAULT
Default type used when no more-specific cargo matches.
Definition: newgrf_cargo.h:23
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:20
Station::TileBelongsToRailStation
bool TileBelongsToRailStation(TileIndex tile) const override
Check whether a specific tile belongs to this station.
Definition: station_base.h:507
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
GetEmptyMask
CargoTypes GetEmptyMask(const Station *st)
Get a mask of the cargo types that are empty at the station.
Definition: station_cmd.cpp:512
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:401
StationSpec::cargo_threshold
uint16_t cargo_threshold
Cargo threshold for choosing between little and lots of cargo.
Definition: newgrf_station.h:153
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:429
AirportSpec::ttd_airport_type
TTDPAirportType ttd_airport_type
ttdpatch airport type (Small/Large/Helipad/Oilrig)
Definition: newgrf_airport.h:114
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
BaseStation::GetNewGRFVariable
virtual uint32_t GetNewGRFVariable(const struct ResolverObject &object, byte variable, byte parameter, bool *available) const =0
Helper function to get a NewGRF variable that isn't implemented by the base class.
NewGRFSpriteLayout
NewGRF supplied spritelayout.
Definition: newgrf_commons.h:112
safeguards.h
NewGRFSpriteLayout::NeedsPreprocessing
bool NeedsPreprocessing() const
Tests whether this spritelayout needs preprocessing by PrepareLayout() and ProcessRegisters(),...
Definition: newgrf_commons.h:149
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
DIR_S
@ DIR_S
South.
Definition: direction_type.h:30
SPRITE_MODIFIER_CUSTOM_SPRITE
@ SPRITE_MODIFIER_CUSTOM_SPRITE
Set when a sprite originates from an Action 1.
Definition: sprites.h:1539
OrthogonalTileArea::end
OrthogonalTileIterator end() const
Returns an iterator to the end of the tile area.
Definition: tilearea.cpp:162
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
STAT_CLASS_MAX
@ STAT_CLASS_MAX
Maximum number of classes.
Definition: newgrf_station.h:87
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:1003
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:124
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:57
GetPlatformInfo
uint32_t GetPlatformInfo(Axis axis, byte 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:103
RTSG_GROUND
@ RTSG_GROUND
Main group of ground images.
Definition: rail.h:52
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:22
TileIndexDiff
int32_t TileIndexDiff
An offset value between two tiles.
Definition: map_func.h:376
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
GetErrorMessageFromLocationCallbackResult
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Definition: newgrf_commons.cpp:463
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
StationResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_station.cpp:554
SpecializedStation< Station, false >::From
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
Definition: base_station_base.h:288
CargoList::PeriodsInTransit
uint PeriodsInTransit() const
Returns average number of cargo aging periods in transit for a cargo entity.
Definition: cargopacket.h:338
TrackStatusToTrackBits
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:363
CBID_STATION_ANIM_NEXT_FRAME
@ CBID_STATION_ANIM_NEXT_FRAME
Called to determine station tile next animation frame.
Definition: newgrf_callbacks.h:188
stdafx.h
SetStationTileRandomBits
void SetStationTileRandomBits(Tile t, byte random_bits)
Set the random bits for a station tile.
Definition: station_map.h:597
Station::truck_stops
RoadStop * truck_stops
All the truck stops.
Definition: station_base.h:453
StationResolverObject::ResolveReal
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
Definition: newgrf_station.cpp:504
NewGRFSpriteLayout::PrepareLayout
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.
Definition: newgrf_commons.cpp:639
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
NewGRFClass::InsertDefaults
static void InsertDefaults()
Initialise the defaults.
Definition: newgrf_airport.cpp:27
StationScopeResolver::axis
Axis axis
Station axis, used only for the slope check callback.
Definition: newgrf_station.h:29
RealSpriteGroup::loaded
std::vector< const SpriteGroup * > loaded
List of loaded groups (can be SpriteIDs or Callback results)
Definition: newgrf_spritegroup.h:89
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition: newgrf_commons.h:318
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:563
newgrf_spritegroup.h
newgrf_town.h
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
SRT_CARGO_TAKEN
@ SRT_CARGO_TAKEN
Trigger station when cargo is completely taken.
Definition: newgrf_station.h:104
GoodsEntry::GES_CURRENT_MONTH
@ GES_CURRENT_MONTH
Set when cargo was delivered for final delivery this month.
Definition: station_base.h:201
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:420
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:166
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:51
station_base.h
newgrf_sound.h
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:320
StationSpec
Station specification.
Definition: newgrf_station.h:112
GetReverseRailTypeTranslation
uint8_t GetReverseRailTypeTranslation(RailType railtype, const GRFFile *grffile)
Perform a reverse railtype lookup to get the GRF internal ID.
Definition: newgrf_railtype.cpp:163
SLOPE_EW
@ SLOPE_EW
east and west corner are raised
Definition: slope_type.h:59
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition: direction_type.h:120
RailTypeInfo::fallback_railtype
byte fallback_railtype
Original railtype number to use when drawing non-newgrf railtypes, or when drawing stations.
Definition: rail.h:201
PerformStationTileSlopeCheck
CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks)
Check the slope of a tile of a new station.
Definition: newgrf_station.cpp:661
IsCustomStationSpecIndex
bool IsCustomStationSpecIndex(Tile t)
Is there a custom rail station spec on this tile?
Definition: station_map.h:525
RailTrackOffset
RailTrackOffset
Offsets for sprites within an overlay/underlay set.
Definition: rail.h:70
CBID_STATION_ANIM_START_STOP
@ CBID_STATION_ANIM_START_STOP
Called for periodically starting or stopping the animation.
Definition: newgrf_callbacks.h:185
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition: station_map.h:28
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
HasStationReservation
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
Definition: station_map.h:466
RealSpriteGroup
Definition: newgrf_spritegroup.h:79
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
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:243
StationAnimationTrigger
StationAnimationTrigger
Animation triggers for station.
Definition: newgrf_animation_type.h:26
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:2051
SpriteGroupCargo::SG_PURCHASE
static constexpr CargoID SG_PURCHASE
Used in purchase lists before an item exists.
Definition: newgrf_cargo.h:24
StationScopeResolver::st
struct BaseStation * st
Instance of the station.
Definition: newgrf_station.h:26
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
GoodsEntry::GES_ACCEPTANCE
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
Definition: station_base.h:173
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:278
waypoint_base.h
StationClassID
StationClassID
Definition: newgrf_station.h:83
NewGRFClass::name
StringID name
Name of this class.
Definition: newgrf_class.h:39
CBID_STATION_ANIMATION_SPEED
@ CBID_STATION_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Definition: newgrf_callbacks.h:191
Waypoint::GetNewGRFVariable
uint32_t GetNewGRFVariable(const struct ResolverObject &object, byte variable, byte parameter, bool *available) const override
Helper function to get a NewGRF variable that isn't implemented by the base class.
Definition: newgrf_station.cpp:472
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:64
BaseStation::cached_anim_triggers
uint8_t cached_anim_triggers
NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
Definition: base_station_base.h:84
company_func.h
RoadStop::status
byte status
Current status of the Stop,.
Definition: roadstop_base.h:68
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:45
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:117
BaseStation::random_bits
uint16_t random_bits
Random bits assigned to this station.
Definition: base_station_base.h:82
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition: tilearea_type.h:20
StationSpecList::localidx
uint16_t localidx
Station ID within GRF of station.
Definition: base_station_base.h:25
TriggerStationRandomisation
void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoID cargo_type)
Trigger station randomisation.
Definition: newgrf_station.cpp:923
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition: newgrf_animation_base.h:36
SpriteGroup::Resolve
virtual const SpriteGroup * Resolve([[maybe_unused]] ResolverObject &object) const
Base sprite group resolver.
Definition: newgrf_spritegroup.h:61
DrawTileSprites::seq
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
Definition: sprite.h:60
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
GetAnimationFrame
byte GetAnimationFrame(Tile t)
Get the current animation frame.
Definition: tile_map.h:250
StationSpec::grf_prop
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
Definition: newgrf_station.h:124
NewGRFClass::Get
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Definition: newgrf_class_func.h:98
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:632
GetNearbyTile
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition: newgrf_commons.cpp:406
ETileArea
Definition: newgrf_station.cpp:57
NewGRFSpriteLayout::GetLayout
const DrawTileSeqStruct * GetLayout(PalSpriteID *ground) const
Returns the result spritelayout after preprocessing.
Definition: newgrf_commons.h:162
SpriteGroupCargo::SG_DEFAULT_NA
static constexpr CargoID SG_DEFAULT_NA
Used only by stations and roads when no more-specific cargo matches.
Definition: newgrf_cargo.h:25
ATP_TTDP_LARGE
@ ATP_TTDP_LARGE
Same as AT_LARGE.
Definition: newgrf_airport.h:85
IsValidCargoID
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
Definition: cargo_type.h:107
Station::bus_stops
RoadStop * bus_stops
All the road stops.
Definition: station_base.h:451
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
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
StationResolverObject
Station resolver.
Definition: newgrf_station.h:50
CBID_RANDOM_TRIGGER
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
Definition: newgrf_callbacks.h:25
StationSpec::callback_mask
byte callback_mask
Bitmask of station callbacks that have to be called.
Definition: newgrf_station.h:157
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:141
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
StationAnimationBase
Helper class for animation control.
Definition: newgrf_station.cpp:866
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:319
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
CBM_STATION_SPRITE_LAYOUT
@ CBM_STATION_SPRITE_LAYOUT
Use callback to select a sprite layout to use.
Definition: newgrf_callbacks.h:311
_svc
static struct @18 _svc
Station variable cache This caches 'expensive' station variable lookups which iterate over several ti...
Airport::GetSpec
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition: station_base.h:305
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition: direction_type.h:75
GetCargoTranslation
CargoID GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
Definition: newgrf_cargo.cpp:79
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:779
StationUpdateCachedTriggers
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
Definition: newgrf_station.cpp:998
GRFFile::cargo_map
std::array< uint8_t, NUM_CARGO > cargo_map
Inverse cargo translation table (CargoID -> local ID)
Definition: newgrf.h:130
CBID_STATION_SPRITE_LAYOUT
@ CBID_STATION_SPRITE_LAYOUT
Choose a sprite layout to draw, instead of the standard 0-7 range.
Definition: newgrf_callbacks.h:42
newgrf_cargo.h
GoodsEntry::HasVehicleEverTriedLoading
bool HasVehicleEverTriedLoading() const
Reports whether a vehicle has ever tried to load the cargo at this station.
Definition: station_base.h:252
StationSpec::cargo_triggers
CargoTypes cargo_triggers
Bitmask of cargo types which cause trigger re-randomizing.
Definition: newgrf_station.h:155
StationScopeResolver::tile
TileIndex tile
Tile of the station.
Definition: newgrf_station.h:25
SpriteGroup
Definition: newgrf_spritegroup.h:57
StationCargoList::GetFirstStation
StationID GetFirstStation() const
Returns first station of the first cargo packet in this list.
Definition: cargopacket.h:578
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
newgrf_railtype.h
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:237
StationScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition: newgrf_station.cpp:222
debug.h
GoodsEntry::GES_LAST_MONTH
@ GES_LAST_MONTH
Set when cargo was delivered for final delivery last month.
Definition: station_base.h:195
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:96
StationResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_station.cpp:549
GetTunnelBridgeDirection
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
Definition: tunnelbridge_map.h:26
BaseStation::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition: base_station_base.h:80
GetCustomStationSpecIndex
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
Definition: station_map.h:549
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103