OpenTTD Source: src/station_base.h Source File

OpenTTD Source 15.3

station_base.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef STATION_BASE_H
11#define STATION_BASE_H
12
13#include "core/flatset_type.hpp"
14#include "core/random_func.hpp"
15#include "base_station_base.h"
16#include "newgrf_airport.h"
17#include "cargopacket.h"
18#include "industry_type.h"
19#include "linkgraph/linkgraph_type.h"
20#include "newgrf_storage.h"
21#include "bitmap_type.h"
22
23static const uint8_t INITIAL_STATION_RATING = 175;
24static const uint8_t MAX_STATION_RATING = 255;
25
33 class FlowStat {
34public:
35 typedef std::map<uint32_t, StationID> SharesMap;
36
37 static const SharesMap empty_sharesmap;
38
44 inline FlowStat() {NOT_REACHED();}
45
52 inline FlowStat(StationID st, uint flow, bool restricted = false)
53 {
54 assert(flow > 0);
55 this->shares[flow] = st;
56 this->unrestricted = restricted ? 0 : flow;
57 }
58
67 inline void AppendShare(StationID st, uint flow, bool restricted = false)
68 {
69 assert(flow > 0);
70 this->shares[(--this->shares.end())->first + flow] = st;
71 if (!restricted) this->unrestricted += flow;
72 }
73
74 uint GetShare(StationID st) const;
75
76 void ChangeShare(StationID st, int flow);
77
78 void RestrictShare(StationID st);
79
80 void ReleaseShare(StationID st);
81
82 void ScaleToMonthly(uint runtime);
83
89 inline const SharesMap *GetShares() const { return &this->shares; }
90
95 inline uint GetUnrestricted() const { return this->unrestricted; }
96
102 inline void SwapShares(FlowStat &other)
103 {
104 this->shares.swap(other.shares);
105 std::swap(this->unrestricted, other.unrestricted);
106 }
107
116 inline StationID GetViaWithRestricted(bool &is_restricted) const
117 {
118 assert(!this->shares.empty());
119 uint rand = RandomRange((--this->shares.end())->first);
120 is_restricted = rand >= this->unrestricted;
121 return this->shares.upper_bound(rand)->second;
122 }
123
131 inline StationID GetVia() const
132 {
133 assert(!this->shares.empty());
134 return this->unrestricted > 0 ?
135 this->shares.upper_bound(RandomRange(this->unrestricted))->second :
136 StationID::Invalid();
137 }
138
139 StationID GetVia(StationID excluded, StationID excluded2 = StationID::Invalid()) const;
140
141 void Invalidate();
142
143private:
144 SharesMap shares{};
145 uint unrestricted = 0;
146};
147
149 class FlowStatMap : public std::map<StationID, FlowStat> {
150public:
151 uint GetFlow() const;
152 uint GetFlowVia(StationID via) const;
153 uint GetFlowFrom(StationID from) const;
154 uint GetFlowFromVia(StationID from, StationID via) const;
155
156 void AddFlow(StationID origin, StationID via, uint amount);
157 void PassOnFlow(StationID origin, StationID via, uint amount);
158 std::vector<StationID> DeleteFlows(StationID via);
159 void RestrictFlows(StationID via);
160 void ReleaseFlows(StationID via);
161 void FinalizeLocalConsumption(StationID self);
162};
163
167 struct GoodsEntry {
169 enum class State : uint8_t {
174 Acceptance = 0,
175
184 Rating = 1,
185
190 EverAccepted = 2,
191
196 LastMonth = 3,
197
202 CurrentMonth = 4,
203
208 AcceptedBigtick = 5,
209 };
210 using States = EnumBitSet<State, uint8_t>;
211
212 struct GoodsEntryData {
213 StationCargoList cargo{};
214 FlowStatMap flows{};
215
216 bool IsEmpty() const
217 {
218 return this->cargo.TotalCount() == 0 && this->flows.empty();
219 }
220 };
221
222 uint max_waiting_cargo = 0;
223 NodeID node = INVALID_NODE;
224 LinkGraphID link_graph = LinkGraphID::Invalid();
225
226 States status{};
227
233 uint8_t time_since_pickup = 255;
234
235 uint8_t rating = INITIAL_STATION_RATING;
236
246 uint8_t last_speed = 0;
247
252 uint8_t last_age = 255;
253
254 uint8_t amount_fract = 0;
255
261 bool HasVehicleEverTriedLoading() const { return this->last_speed != 0; }
262
267 inline bool HasRating() const
268 {
269 return this->status.Test(GoodsEntry::State::Rating);
270 }
271
277 inline StationID GetVia(StationID source) const
278 {
279 if (!this->HasData()) return StationID::Invalid();
280
281 FlowStatMap::const_iterator flow_it(this->GetData().flows.find(source));
282 return flow_it != this->GetData().flows.end() ? flow_it->second.GetVia() : StationID::Invalid();
283 }
284
293 inline StationID GetVia(StationID source, StationID excluded, StationID excluded2 = StationID::Invalid()) const
294 {
295 if (!this->HasData()) return StationID::Invalid();
296
297 FlowStatMap::const_iterator flow_it(this->GetData().flows.find(source));
298 return flow_it != this->GetData().flows.end() ? flow_it->second.GetVia(excluded, excluded2) : StationID::Invalid();
299 }
300
305 [[debug_inline]] inline bool HasData() const { return this->data != nullptr; }
306
310 void ClearData() { this->data.reset(); }
311
317 [[debug_inline]] inline const GoodsEntryData &GetData() const
318 {
319 assert(this->HasData());
320 return *this->data;
321 }
322
328 [[debug_inline]] inline GoodsEntryData &GetData()
329 {
330 assert(this->HasData());
331 return *this->data;
332 }
333
338 inline GoodsEntryData &GetOrCreateData()
339 {
340 if (!this->HasData()) this->data = std::make_unique<GoodsEntryData>();
341 return *this->data;
342 }
343
344 uint8_t ConvertState() const;
345
351 inline uint AvailableCount() const
352 {
353 return this->HasData() ? this->GetData().cargo.AvailableCount() : 0;
354 }
355
361 inline uint TotalCount() const
362 {
363 return this->HasData() ? this->GetData().cargo.TotalCount() : 0;
364 }
365
366private:
367 std::unique_ptr<GoodsEntryData> data = nullptr;
368};
369
371 struct Airport : public TileArea {
372 Airport() : TileArea(INVALID_TILE, 0, 0) {}
373
374 AirportBlocks blocks{};
375 uint8_t type = 0;
376 uint8_t layout = 0;
377 Direction rotation = INVALID_DIR;
378
379 PersistentStorage *psa = nullptr;
380
386 const AirportSpec *GetSpec() const
387 {
388 if (this->tile == INVALID_TILE) return &AirportSpec::dummy;
389 return AirportSpec::Get(this->type);
390 }
391
398 const AirportFTAClass *GetFTA() const
399 {
400 return this->GetSpec()->fsm;
401 }
402
404 inline bool HasHangar() const
405 {
406 return !this->GetSpec()->depots.empty();
407 }
408
417 inline TileIndex GetRotatedTileFromOffset(TileIndexDiffC tidc) const
418 {
419 const AirportSpec *as = this->GetSpec();
420 switch (this->rotation) {
421 case DIR_N: return this->tile + ToTileIndexDiff(tidc);
422
423 case DIR_E: return this->tile + TileDiffXY(tidc.y, as->size_x - 1 - tidc.x);
424
425 case DIR_S: return this->tile + TileDiffXY(as->size_x - 1 - tidc.x, as->size_y - 1 - tidc.y);
426
427 case DIR_W: return this->tile + TileDiffXY(as->size_y - 1 - tidc.y, tidc.x);
428
429 default: NOT_REACHED();
430 }
431 }
432
439 inline TileIndex GetHangarTile(uint hangar_num) const
440 {
441 for (const auto &depot : this->GetSpec()->depots) {
442 if (depot.hangar_num == hangar_num) {
443 return this->GetRotatedTileFromOffset(depot.ti);
444 }
445 }
446 NOT_REACHED();
447 }
448
455 inline Direction GetHangarExitDirection(TileIndex tile) const
456 {
457 const AirportSpec *as = this->GetSpec();
458 const HangarTileTable *htt = GetHangarDataByTile(tile);
459 return ChangeDir(htt->dir, DirDifference(this->rotation, as->layouts[0].rotation));
460 }
461
468 inline uint GetHangarNum(TileIndex tile) const
469 {
470 const HangarTileTable *htt = GetHangarDataByTile(tile);
471 return htt->hangar_num;
472 }
473
475 inline uint GetNumHangars() const
476 {
477 uint num = 0;
478 uint counted = 0;
479 for (const auto &depot : this->GetSpec()->depots) {
480 if (!HasBit(counted, depot.hangar_num)) {
481 num++;
482 SetBit(counted, depot.hangar_num);
483 }
484 }
485 return num;
486 }
487
488private:
495 inline const HangarTileTable *GetHangarDataByTile(TileIndex tile) const
496 {
497 for (const auto &depot : this->GetSpec()->depots) {
498 if (this->GetRotatedTileFromOffset(depot.ti) == tile) {
499 return &depot;
500 }
501 }
502 NOT_REACHED();
503 }
504};
505
506 struct IndustryListEntry {
507 uint distance = 0;
508 Industry *industry = nullptr;
509
510 bool operator== (const IndustryListEntry &other) const { return this->distance == other.distance && this->industry == other.industry; };
511};
512
513 struct IndustryCompare {
514 bool operator() (const IndustryListEntry &lhs, const IndustryListEntry &rhs) const;
515};
516
517typedef std::set<IndustryListEntry, IndustryCompare> IndustryList;
518
520 struct Station final : SpecializedStation<Station, false> {
521public:
522 RoadStop *GetPrimaryRoadStop(RoadStopType type) const
523 {
524 return type == RoadStopType::Bus ? bus_stops : truck_stops;
525 }
526
527 RoadStop *GetPrimaryRoadStop(const struct RoadVehicle *v) const;
528
529 RoadStop *bus_stops = nullptr;
530 TileArea bus_station{};
531 RoadStop *truck_stops = nullptr;
532 TileArea truck_station{};
533
534 Airport airport{};
535 TileArea ship_station{};
536 TileArea docking_station{};
537
538 IndustryType indtype = IT_INVALID;
539
540 BitmapTileArea catchment_tiles{};
541
542 StationHadVehicleOfType had_vehicle_of_type{};
543
544 uint8_t time_since_load = 0;
545 uint8_t time_since_unload = 0;
546
547 uint8_t last_vehicle_type = 0;
548 std::list<Vehicle *> loading_vehicles{};
549 std::array<GoodsEntry, NUM_CARGO> goods;
550 CargoTypes always_accepted{};
551
552 IndustryList industries_near{};
553 Industry *industry = nullptr;
554
555 Station(TileIndex tile = INVALID_TILE);
556 ~Station();
557
558 void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy);
559
560 void MarkTilesDirty(bool cargo_change) const;
561
562 void UpdateVirtCoord() override;
563
564 void MoveSign(TileIndex new_xy) override;
565
566 void AfterStationTileSetChange(bool adding, StationType type);
567
568 uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override;
569 uint GetPlatformLength(TileIndex tile) const override;
570 void RecomputeCatchment(bool no_clear_nearby_lists = false);
571 static void RecomputeCatchmentForAll();
572
573 uint GetCatchmentRadius() const;
574 Rect GetCatchmentRect() const;
575 bool CatchmentCoversTown(TownID t) const;
576 void AddIndustryToDeliver(Industry *ind, TileIndex tile);
577 void RemoveIndustryToDeliver(Industry *ind);
578 void RemoveFromAllNearbyLists();
579
580 inline bool TileIsInCatchment(TileIndex tile) const
581 {
582 return this->catchment_tiles.HasTile(tile);
583 }
584
585 inline bool TileBelongsToRailStation(TileIndex tile) const override
586 {
587 return IsRailStationTile(tile) && GetStationIndex(tile) == this->index;
588 }
589
590 inline bool TileBelongsToRoadStop(TileIndex tile) const
591 {
592 return IsStationRoadStopTile(tile) && GetStationIndex(tile) == this->index;
593 }
594
595 inline bool TileBelongsToAirport(TileIndex tile) const
596 {
597 return IsAirportTile(tile) && GetStationIndex(tile) == this->index;
598 }
599
600 uint32_t GetNewGRFVariable(const ResolverObject &object, uint8_t variable, uint8_t parameter, bool &available) const override;
601
602 TileArea GetTileArea(StationType type) const override;
603};
604
606 class AirportTileIterator : public OrthogonalTileIterator {
607private:
608 const Station *st = nullptr;
609
610public:
615 AirportTileIterator(const Station *st) : OrthogonalTileIterator(st->airport), st(st)
616 {
617 if (!st->TileBelongsToAirport(this->tile)) ++(*this);
618 }
619
620 inline TileIterator& operator ++() override
621 {
622 this->OrthogonalTileIterator::operator++();
623 while (this->tile != INVALID_TILE && !st->TileBelongsToAirport(this->tile)) {
624 this->OrthogonalTileIterator::operator++();
625 }
626 return *this;
627 }
628
629 std::unique_ptr<TileIterator> Clone() const override
630 {
631 return std::make_unique<AirportTileIterator>(*this);
632 }
633};
634
635void RebuildStationKdtree();
636
644template <typename Func>
645 void ForAllStationsAroundTiles(const TileArea &ta, Func func)
646{
647 /* There are no stations, so we will never find anything. */
648 if (Station::GetNumItems() == 0) return;
649
650 /* Not using, or don't have a nearby stations list, so we need to scan. */
651 FlatSet<StationID> seen_stations;
652
653 /* Scan an area around the building covering the maximum possible station
654 * to find the possible nearby stations. */
655 uint max_c = _settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED;
656 TileArea ta_ext = TileArea(ta).Expand(max_c);
657 for (TileIndex tile : ta_ext) {
658 if (!IsTileType(tile, MP_STATION)) continue;
659 seen_stations.insert(GetStationIndex(tile));
660 }
661
662 for (StationID stationid : seen_stations) {
663 Station *st = Station::GetIfValid(stationid);
664 if (st == nullptr) continue; /* Waypoint */
665
666 /* Check if station is attached to an industry */
667 if (!_settings_game.station.serve_neutral_industries && st->industry != nullptr) continue;
668
669 /* Test if the tile is within the station's catchment */
670 for (TileIndex tile : ta) {
671 if (st->TileIsInCatchment(tile)) {
672 if (func(st, tile)) break;
673 }
674 }
675 }
676}
677
678#endif /* STATION_BASE_H */
base_station_base.h
Base classes/functions for base stations.
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
cargopacket.h
Base class for cargo packets.
AirportTileIterator
Iterator to iterate over all tiles belonging to an airport.
Definition station_base.h:606
AirportTileIterator::Clone
std::unique_ptr< TileIterator > Clone() const override
Allocate a new iterator that is a copy of this one.
Definition station_base.h:629
AirportTileIterator::operator++
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
Definition station_base.h:620
AirportTileIterator::st
const Station * st
The station the airport is a part of.
Definition station_base.h:608
AirportTileIterator::AirportTileIterator
AirportTileIterator(const Station *st)
Construct the iterator.
Definition station_base.h:615
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BitmapTileArea
Represents a tile area containing containing individually set tiles.
Definition bitmap_type.h:18
BitmapTileArea::HasTile
bool HasTile(TileIndex tile) const
Test if a tile is part of the tile area.
Definition bitmap_type.h:99
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
FlatSet
Flat set implementation that uses a sorted vector for storage.
Definition flatset_type.hpp:20
FlatSet::insert
std::pair< const_iterator, bool > insert(const Tkey &key)
Insert a key into the set, if it does not already exist.
Definition flatset_type.hpp:31
FlowStatMap
Flow descriptions by origin stations.
Definition station_base.h:149
FlowStatMap::GetFlow
uint GetFlow() const
Get the sum of all flows from this FlowStatMap.
Definition station_cmd.cpp:5318
FlowStatMap::PassOnFlow
void PassOnFlow(StationID origin, StationID via, uint amount)
Pass on some flow, remembering it as invalid, for later subtraction from locally consumed flow.
Definition station_cmd.cpp:5233
FlowStatMap::DeleteFlows
std::vector< StationID > DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
Definition station_cmd.cpp:5276
FlowStatMap::AddFlow
void AddFlow(StationID origin, StationID via, uint amount)
Add some flow from "origin", going via "via".
Definition station_cmd.cpp:5214
FlowStatMap::GetFlowFrom
uint GetFlowFrom(StationID from) const
Get the sum of flows from a specific station from this FlowStatMap.
Definition station_cmd.cpp:5346
FlowStatMap::FinalizeLocalConsumption
void FinalizeLocalConsumption(StationID self)
Subtract invalid flows from locally consumed flow.
Definition station_cmd.cpp:5251
FlowStatMap::ReleaseFlows
void ReleaseFlows(StationID via)
Release all flows at a station for specific cargo and destination.
Definition station_cmd.cpp:5307
FlowStatMap::GetFlowFromVia
uint GetFlowFromVia(StationID from, StationID via) const
Get the flow from a specific station via a specific other station.
Definition station_cmd.cpp:5359
FlowStatMap::GetFlowVia
uint GetFlowVia(StationID via) const
Get the sum of flows via a specific station from this FlowStatMap.
Definition station_cmd.cpp:5332
FlowStatMap::RestrictFlows
void RestrictFlows(StationID via)
Restrict all flows at a station for specific cargo and destination.
Definition station_cmd.cpp:5296
FlowStat
Flow statistics telling how much flow should be sent along a link.
Definition station_base.h:33
FlowStat::empty_sharesmap
static const SharesMap empty_sharesmap
Static instance of FlowStat::SharesMap.
Definition station_base.h:37
FlowStat::ScaleToMonthly
void ScaleToMonthly(uint runtime)
Scale all shares from link graph's runtime to monthly values.
Definition station_cmd.cpp:5195
FlowStat::RestrictShare
void RestrictShare(StationID st)
Restrict a flow by moving it to the end of the map and decreasing the amount of unrestricted flow.
Definition station_cmd.cpp:5127
FlowStat::GetShare
uint GetShare(StationID st) const
Get flow for a station.
Definition station_cmd.cpp:4986
FlowStat::SwapShares
void SwapShares(FlowStat &other)
Swap the shares maps, and thus the content of this FlowStat with the other one.
Definition station_base.h:102
FlowStat::GetUnrestricted
uint GetUnrestricted() const
Return total amount of unrestricted shares.
Definition station_base.h:95
FlowStat::GetVia
StationID GetVia() const
Get a station a package can be routed to.
Definition station_base.h:131
FlowStat::GetViaWithRestricted
StationID GetViaWithRestricted(bool &is_restricted) const
Get a station a package can be routed to.
Definition station_base.h:116
FlowStat::GetShares
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
Definition station_base.h:89
FlowStat::shares
SharesMap shares
Shares of flow to be sent via specified station (or consumed locally).
Definition station_base.h:144
FlowStat::ReleaseShare
void ReleaseShare(StationID st)
Release ("unrestrict") a flow by moving it to the begin of the map and increasing the amount of unres...
Definition station_cmd.cpp:5158
FlowStat::ChangeShare
void ChangeShare(StationID st, int flow)
Change share for specified station.
Definition station_cmd.cpp:5077
FlowStat::AppendShare
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
Definition station_base.h:67
FlowStat::FlowStat
FlowStat()
Invalid constructor.
Definition station_base.h:44
FlowStat::Invalidate
void Invalidate()
Reduce all flows to minimum capacity so that they don't get in the way of link usage statistics too m...
Definition station_cmd.cpp:5058
FlowStat::unrestricted
uint unrestricted
Limit for unrestricted shares.
Definition station_base.h:145
FlowStat::FlowStat
FlowStat(StationID st, uint flow, bool restricted=false)
Create a FlowStat with an initial entry.
Definition station_base.h:52
OrthogonalTileIterator
Iterator to iterate over a tile area (rectangle) of the map.
Definition tilearea_type.h:168
OrthogonalTileIterator::operator++
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
Definition tilearea_type.h:196
StationCargoList
CargoList that is used for stations.
Definition cargopacket.h:519
StationCargoList::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition cargopacket.h:597
StationCargoList::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the station.
Definition cargopacket.h:578
TileIterator
Base class for tile iterators.
Definition tilearea_type.h:105
TileIterator::tile
TileIndex tile
The current tile we are at.
Definition tilearea_type.h:107
DirDifference
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Definition direction_func.h:68
ChangeDir
Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
Definition direction_func.h:104
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
INVALID_DIR
@ INVALID_DIR
Flag for an invalid direction.
Definition direction_type.h:35
DIR_N
@ DIR_N
North.
Definition direction_type.h:26
DIR_S
@ DIR_S
South.
Definition direction_type.h:30
DIR_W
@ DIR_W
West.
Definition direction_type.h:32
DIR_E
@ DIR_E
East.
Definition direction_type.h:28
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
flatset_type.hpp
Flat set container implementation.
Station::MarkTilesDirty
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
Definition station.cpp:247
industry_type.h
Types related to the industry.
linkgraph_type.h
Declaration of link graph types used for cargo distribution.
ToTileIndexDiff
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
Definition map_func.h:453
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:401
newgrf_airport.h
NewGRF handling of airports.
newgrf_storage.h
Functionality related to the temporary and persistent storage arrays for NewGRFs.
random_func.hpp
Pseudo random number generator.
RandomRange
uint32_t RandomRange(uint32_t limit, const std::source_location location=std::source_location::current())
Pick a random number between 0 and limit - 1, inclusive.
Definition random_func.hpp:88
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ForAllStationsAroundTiles
void ForAllStationsAroundTiles(const TileArea &ta, Func func)
Call a function on all stations that have any part of the requested area within their catchment.
Definition station_base.h:645
IsStationRoadStopTile
bool IsStationRoadStopTile(Tile t)
Is tile t a road stop station?
Definition station_map.h:234
IsAirportTile
bool IsAirportTile(Tile t)
Is this tile a station tile and an airport tile?
Definition station_map.h:167
IsRailStationTile
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
Definition station_map.h:102
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
RoadStopType
RoadStopType
Types of RoadStops.
Definition station_type.h:43
RoadStopType::Bus
@ Bus
A standard stop for buses.
StationHadVehicleOfType
StationHadVehicleOfType
The vehicles that may have visited a station.
Definition station_type.h:64
StationFacility
StationFacility
The facilities a station might be having.
Definition station_type.h:50
StationType
StationType
Station types.
Definition station_type.h:29
MAX_CATCHMENT
static constexpr uint MAX_CATCHMENT
Maximum catchment for airports with "modified catchment" enabled.
Definition station_type.h:122
CA_UNMODIFIED
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition station_type.h:120
AirportFTAClass
Finite sTate mAchine (FTA) of an airport.
Definition airport.h:159
AirportSpec
Defines the data structure for an airport.
Definition newgrf_airport.h:109
AirportSpec::layouts
std::vector< AirportTileLayout > layouts
List of layouts composing the airport.
Definition newgrf_airport.h:111
AirportSpec::dummy
static const AirportSpec dummy
The dummy airport.
Definition newgrf_airport.h:143
AirportSpec::fsm
const struct AirportFTAClass * fsm
the finite statemachine for the default airports
Definition newgrf_airport.h:110
AirportSpec::size_y
uint8_t size_y
size of airport in y direction
Definition newgrf_airport.h:114
AirportSpec::size_x
uint8_t size_x
size of airport in x direction
Definition newgrf_airport.h:113
AirportSpec::Get
static const AirportSpec * Get(uint8_t type)
Retrieve airport spec for the given airport.
Definition newgrf_airport.cpp:59
AirportSpec::depots
std::span< const HangarTileTable > depots
Position of the depots on the airports.
Definition newgrf_airport.h:112
Airport
All airport-related information.
Definition station_base.h:371
Airport::blocks
AirportBlocks blocks
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
Definition station_base.h:374
Airport::GetRotatedTileFromOffset
TileIndex GetRotatedTileFromOffset(TileIndexDiffC tidc) const
Add the tileoffset to the base tile of this airport but rotate it first.
Definition station_base.h:417
Airport::HasHangar
bool HasHangar() const
Check if this airport has at least one hangar.
Definition station_base.h:404
Airport::GetHangarNum
uint GetHangarNum(TileIndex tile) const
Get the hangar number of the hangar at a specific tile.
Definition station_base.h:468
Airport::rotation
Direction rotation
How this airport is rotated.
Definition station_base.h:377
Airport::type
uint8_t type
Type of this airport,.
Definition station_base.h:375
Airport::GetHangarExitDirection
Direction GetHangarExitDirection(TileIndex tile) const
Get the exit direction of the hangar at a specific tile.
Definition station_base.h:455
Airport::psa
PersistentStorage * psa
Persistent storage for NewGRF airports.
Definition station_base.h:379
Airport::GetNumHangars
uint GetNumHangars() const
Get the number of hangars on this airport.
Definition station_base.h:475
Airport::GetFTA
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
Definition station_base.h:398
Airport::GetHangarTile
TileIndex GetHangarTile(uint hangar_num) const
Get the first tile of the given hangar.
Definition station_base.h:439
Airport::GetHangarDataByTile
const HangarTileTable * GetHangarDataByTile(TileIndex tile) const
Retrieve hangar information of a hangar at a given tile.
Definition station_base.h:495
Airport::GetSpec
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition station_base.h:386
Airport::layout
uint8_t layout
Airport layout number.
Definition station_base.h:376
GameSettings::station
StationSettings station
settings related to station management
Definition settings_type.h:644
GoodsEntry::GoodsEntryData
Definition station_base.h:212
GoodsEntry::GoodsEntryData::flows
FlowStatMap flows
Planned flows through this station.
Definition station_base.h:214
GoodsEntry::GoodsEntryData::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition station_base.h:213
GoodsEntry
Stores station stats for a single cargo.
Definition station_base.h:167
GoodsEntry::max_waiting_cargo
uint max_waiting_cargo
Max cargo from this station waiting at any station.
Definition station_base.h:222
GoodsEntry::HasRating
bool HasRating() const
Does this cargo have a rating at this station?
Definition station_base.h:267
GoodsEntry::GetVia
StationID GetVia(StationID source, StationID excluded, StationID excluded2=StationID::Invalid()) const
Get the best next hop for a cargo packet from station source, optionally excluding one or two station...
Definition station_base.h:293
GoodsEntry::ClearData
void ClearData()
Clear optional cargo packet/flow data.
Definition station_base.h:310
GoodsEntry::last_speed
uint8_t last_speed
Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
Definition station_base.h:246
GoodsEntry::TotalCount
uint TotalCount() const
Returns total count of cargo at the station, including cargo which is already reserved for loading.
Definition station_base.h:361
GoodsEntry::last_age
uint8_t last_age
Age in years (up to 255) of the last vehicle that tried to load this cargo.
Definition station_base.h:252
GoodsEntry::time_since_pickup
uint8_t time_since_pickup
Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.
Definition station_base.h:233
GoodsEntry::data
std::unique_ptr< GoodsEntryData > data
Optional cargo packet and flow data.
Definition station_base.h:367
GoodsEntry::status
States status
Status of this cargo, see State.
Definition station_base.h:226
GoodsEntry::node
NodeID node
ID of node in link graph referring to this goods entry.
Definition station_base.h:223
GoodsEntry::State
State
Status of this cargo for the station.
Definition station_base.h:169
GoodsEntry::State::LastMonth
@ LastMonth
Set when cargo was delivered for final delivery last month.
GoodsEntry::State::Acceptance
@ Acceptance
Set when the station accepts the cargo currently for final deliveries.
GoodsEntry::State::EverAccepted
@ EverAccepted
Set when a vehicle ever delivered cargo to the station for final delivery.
GoodsEntry::State::Rating
@ Rating
This indicates whether a cargo has a rating at the station.
GoodsEntry::State::AcceptedBigtick
@ AcceptedBigtick
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval.
GoodsEntry::State::CurrentMonth
@ CurrentMonth
Set when cargo was delivered for final delivery this month.
GoodsEntry::GetData
const GoodsEntryData & GetData() const
Get optional cargo packet/flow data.
Definition station_base.h:317
GoodsEntry::amount_fract
uint8_t amount_fract
Fractional part of the amount in the cargo list.
Definition station_base.h:254
GoodsEntry::link_graph
LinkGraphID link_graph
Link graph this station belongs to.
Definition station_base.h:224
GoodsEntry::HasVehicleEverTriedLoading
bool HasVehicleEverTriedLoading() const
Reports whether a vehicle has ever tried to load the cargo at this station.
Definition station_base.h:261
GoodsEntry::rating
uint8_t rating
Station rating for this cargo.
Definition station_base.h:235
GoodsEntry::HasData
bool HasData() const
Test if this goods entry has optional cargo packet/flow data.
Definition station_base.h:305
GoodsEntry::GetOrCreateData
GoodsEntryData & GetOrCreateData()
Get optional cargo packet/flow data.
Definition station_base.h:338
GoodsEntry::GetData
GoodsEntryData & GetData()
Get non-const optional cargo packet/flow data.
Definition station_base.h:328
GoodsEntry::AvailableCount
uint AvailableCount() const
Returns sum of cargo still available for loading at the station.
Definition station_base.h:351
GoodsEntry::ConvertState
uint8_t ConvertState() const
Convert GoodsEntry status to the form required for NewGRF variables.
Definition newgrf_station.cpp:60
GoodsEntry::GetVia
StationID GetVia(StationID source) const
Get the best next hop for a cargo packet from station source.
Definition station_base.h:277
HangarTileTable
A list of all hangar tiles in an airport.
Definition newgrf_airport.h:95
HangarTileTable::dir
Direction dir
Direction of the exit.
Definition newgrf_airport.h:97
HangarTileTable::hangar_num
uint8_t hangar_num
The hangar to which this tile belongs.
Definition newgrf_airport.h:98
IndustryCompare
Definition station_base.h:513
IndustryListEntry
Definition station_base.h:506
Industry
Defines the internal data of a functional industry.
Definition industry.h:62
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition tilearea_type.h:19
OrthogonalTileArea::Expand
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Definition tilearea.cpp:123
PersistentStorage
Class for pooled persistent storage of data.
Definition newgrf_storage.h:199
PoolID< uint16_t, struct StationIDTag, 64000, 0xFFFF >
Pool::PoolItem<&_station_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition pool_type.hpp:417
Pool::PoolItem<&_station_pool >::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
RoadStop
A Stop for a Road Vehicle.
Definition roadstop_base.h:21
RoadVehicle
Buses, trucks and trams belong to this class.
Definition roadveh.h:98
SpecializedStation
Class defining several overloaded accessors so we don't have to cast base stations that often.
Definition base_station_base.h:211
SpecializedStation< Station, false >::GetIfValid
static Station * GetIfValid(auto index)
Returns station if the index is a valid index for this station type.
Definition base_station_base.h:257
StationSettings::modified_catchment
bool modified_catchment
different-size catchment areas
Definition settings_type.h:593
StationSettings::serve_neutral_industries
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
Definition settings_type.h:594
Station
Station data structure.
Definition station_base.h:520
Station::~Station
~Station()
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
Definition station.cpp:84
Station::GetTileArea
TileArea GetTileArea(StationType type) const override
Get the tile area for a given station type.
Definition station_cmd.cpp:416
Station::GetPlatformLength
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile.
Definition station.cpp:289
Station::bus_stops
RoadStop * bus_stops
All the road stops.
Definition station_base.h:529
Station::CatchmentCoversTown
bool CatchmentCoversTown(TownID t) const
Test if the given town ID is covered by our catchment area.
Definition station.cpp:452
Station::ship_station
TileArea ship_station
Tile area the ship 'station' part covers.
Definition station_base.h:535
Station::indtype
IndustryType indtype
Industry type to get the name from.
Definition station_base.h:538
Station::industries_near
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
Definition station_base.h:552
Station::docking_station
TileArea docking_station
Tile area the docking tiles cover.
Definition station_base.h:536
Station::always_accepted
CargoTypes always_accepted
Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept c...
Definition station_base.h:550
Station::GetCatchmentRect
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
Definition station.cpp:366
Station::industry
Industry * industry
NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
Definition station_base.h:553
Station::MoveSign
void MoveSign(TileIndex new_xy) override
Move the station main coordinate somewhere else.
Definition station_cmd.cpp:452
Station::RecomputeCatchmentForAll
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition station.cpp:534
Station::goods
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
Definition station_base.h:549
Station::RemoveFromAllNearbyLists
void RemoveFromAllNearbyLists()
Remove this station from the nearby stations lists of nearby towns and industries.
Definition station.cpp:427
Station::bus_station
TileArea bus_station
Tile area the bus 'station' part covers.
Definition station_base.h:530
Station::TileBelongsToRailStation
bool TileBelongsToRailStation(TileIndex tile) const override
Check whether a specific tile belongs to this station.
Definition station_base.h:585
Station::catchment_tiles
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
Definition station_base.h:540
Station::RecomputeCatchment
void RecomputeCatchment(bool no_clear_nearby_lists=false)
Recompute tiles covered in our catchment area.
Definition station.cpp:466
Station::GetCatchmentRadius
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
Definition station.cpp:343
Station::AfterStationTileSetChange
void AfterStationTileSetChange(bool adding, StationType type)
After adding/removing tiles to station, update some station-related stuff.
Definition station_cmd.cpp:739
Station::airport
Airport airport
Tile area the airport covers.
Definition station_base.h:534
Station::UpdateVirtCoord
void UpdateVirtCoord() override
Update the virtual coords needed to draw the station sign.
Definition station_cmd.cpp:432
Station::truck_station
TileArea truck_station
Tile area the truck 'station' part covers.
Definition station_base.h:532
Station::AddIndustryToDeliver
void AddIndustryToDeliver(Industry *ind, TileIndex tile)
Add nearby industry to station's industries_near list if it accepts cargo.
Definition station.cpp:389
Station::RemoveIndustryToDeliver
void RemoveIndustryToDeliver(Industry *ind)
Remove nearby industry from station's industries_near list.
Definition station.cpp:415
Station::truck_stops
RoadStop * truck_stops
All the truck stops.
Definition station_base.h:531
Station::AddFacility
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
Definition station.cpp:230
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileIndexDiffC
A pair-construct of a TileIndexDiff.
Definition map_type.h:31
TileIndexDiffC::x
int16_t x
The x value of the coordinate.
Definition map_type.h:32
TileIndexDiffC::y
int16_t y
The y value of the coordinate.
Definition map_type.h:33
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition tilearea_type.h:102