10 #ifndef STATION_BASE_H
11 #define STATION_BASE_H
20 #include "bitmap_type.h"
22 static const uint8_t INITIAL_STATION_RATING = 175;
23 static const uint8_t MAX_STATION_RATING = 255;
34 typedef std::map<uint32_t, StationID> SharesMap;
51 inline FlowStat(StationID st, uint flow,
bool restricted =
false)
66 inline void AppendShare(StationID st, uint flow,
bool restricted =
false)
117 assert(!this->
shares.empty());
120 return this->
shares.upper_bound(rand)->second;
132 assert(!this->
shares.empty());
138 StationID
GetVia(StationID excluded, StationID excluded2 = INVALID_STATION)
const;
155 void AddFlow(StationID origin, StationID via, uint amount);
156 void PassOnFlow(StationID origin, StationID via, uint amount);
268 inline StationID
GetVia(StationID source)
const
270 FlowStatMap::const_iterator flow_it(this->
flows.find(source));
271 return flow_it != this->
flows.end() ? flow_it->second.GetVia() : INVALID_STATION;
282 inline StationID
GetVia(StationID source, StationID excluded, StationID excluded2 = INVALID_STATION)
const
284 FlowStatMap::const_iterator flow_it(this->
flows.find(source));
285 return flow_it != this->
flows.end() ? flow_it->second.GetVia(excluded, excluded2) : INVALID_STATION;
339 switch (this->rotation) {
348 default: NOT_REACHED();
360 for (
const auto &depot : this->
GetSpec()->depots) {
361 if (depot.hangar_num == hangar_num) {
398 for (
const auto &depot : this->
GetSpec()->depots) {
399 if (!
HasBit(counted, depot.hangar_num)) {
401 SetBit(counted, depot.hangar_num);
416 for (
const auto &depot : this->
GetSpec()->depots) {
429 bool operator== (
const IndustryListEntry &other)
const {
return this->distance == other.distance && this->industry == other.industry; };
436 typedef std::set<IndustryListEntry, IndustryCompare> IndustryList;
463 uint8_t time_since_load;
464 uint8_t time_since_unload;
466 uint8_t last_vehicle_type;
467 std::list<Vehicle *> loading_vehicles;
499 inline bool TileIsInCatchment(
TileIndex tile)
const
501 return this->catchment_tiles.
HasTile(tile);
509 inline bool TileBelongsToRoadStop(
TileIndex tile)
const
514 inline bool TileBelongsToAirport(
TileIndex tile)
const
519 uint32_t GetNewGRFVariable(
const ResolverObject &
object, uint8_t variable, uint8_t parameter,
bool &available)
const override;
536 if (!
st->TileBelongsToAirport(this->tile)) ++(*this);
541 (*this).OrthogonalTileIterator::operator++();
542 while (this->
tile !=
INVALID_TILE && !st->TileBelongsToAirport(this->tile)) {
543 (*this).OrthogonalTileIterator::operator++();
548 std::unique_ptr<TileIterator>
Clone()
const override
550 return std::make_unique<AirportTileIterator>(*
this);
554 void RebuildStationKdtree();
563 template<
typename Func>
570 std::set<StationID> seen_stations;
580 for (StationID stationid : seen_stations) {
582 if (st ==
nullptr)
continue;
589 if (st->TileIsInCatchment(tile)) {
590 if (func(st, tile))
break;
Base classes/functions for base stations.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Base class for cargo packets.
Iterator to iterate over all tiles belonging to an airport.
const Station * st
The station the airport is a part of.
AirportTileIterator(const Station *st)
Construct the iterator.
TileIterator & operator++() override
Move ourselves to the next tile in the rectangle on the map.
std::unique_ptr< TileIterator > Clone() const override
Allocate a new iterator that is a copy of this one.
Represents a tile area containing containing individually set tiles.
bool HasTile(TileIndex tile) const
Test if a tile is part of the tile area.
Flow descriptions by origin stations.
uint GetFlow() const
Get the sum of all flows from this FlowStatMap.
void PassOnFlow(StationID origin, StationID via, uint amount)
Pass on some flow, remembering it as invalid, for later subtraction from locally consumed flow.
void AddFlow(StationID origin, StationID via, uint amount)
Add some flow from "origin", going via "via".
uint GetFlowFrom(StationID from) const
Get the sum of flows from a specific station from this FlowStatMap.
void FinalizeLocalConsumption(StationID self)
Subtract invalid flows from locally consumed flow.
void ReleaseFlows(StationID via)
Release all flows at a station for specific cargo and destination.
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
uint GetFlowFromVia(StationID from, StationID via) const
Get the flow from a specific station via a specific other station.
uint GetFlowVia(StationID via) const
Get the sum of flows via a specific station from this FlowStatMap.
void RestrictFlows(StationID via)
Restrict all flows at a station for specific cargo and destination.
Flow statistics telling how much flow should be sent along a link.
static const SharesMap empty_sharesmap
Static instance of FlowStat::SharesMap.
void ScaleToMonthly(uint runtime)
Scale all shares from link graph's runtime to monthly values.
void RestrictShare(StationID st)
Restrict a flow by moving it to the end of the map and decreasing the amount of unrestricted flow.
uint GetShare(StationID st) const
Get flow for a station.
void SwapShares(FlowStat &other)
Swap the shares maps, and thus the content of this FlowStat with the other one.
uint GetUnrestricted() const
Return total amount of unrestricted shares.
StationID GetVia() const
Get a station a package can be routed to.
StationID GetViaWithRestricted(bool &is_restricted) const
Get a station a package can be routed to.
SharesMap shares
Shares of flow to be sent via specified station (or consumed locally).
void ReleaseShare(StationID st)
Release ("unrestrict") a flow by moving it to the begin of the map and increasing the amount of unres...
void ChangeShare(StationID st, int flow)
Change share for specified station.
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
FlowStat()
Invalid constructor.
void Invalidate()
Reduce all flows to minimum capacity so that they don't get in the way of link usage statistics too m...
uint unrestricted
Limit for unrestricted shares.
FlowStat(StationID st, uint flow, bool restricted=false)
Create a FlowStat with an initial entry.
Iterator to iterate over a tile area (rectangle) of the map.
Minimal stack that uses a pool to avoid pointers.
CargoList that is used for stations.
Base class for tile iterators.
TileIndex tile
The current tile we are at.
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
Direction
Defines the 8 directions on the map.
DiagDirection
Enumeration for diagonal directions.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
Types related to the industry.
Declaration of link graph types used for cargo distribution.
TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between two tiles from a TileIndexDiffC struct.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
constexpr void Swap(T &a, T &b)
Type safe swap operation.
NewGRF handling of airports.
Functionality related to the temporary and persistent storage arrays for NewGRFs.
Pseudo random number generator.
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.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void ForAllStationsAroundTiles(const TileArea &ta, Func func)
Call a function on all stations that have any part of the requested area within their catchment.
bool IsStationRoadStopTile(Tile t)
Is tile t a road stop station?
bool IsAirportTile(Tile t)
Is this tile a station tile and an airport tile?
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
StationID GetStationIndex(Tile t)
Get StationID from a tile.
RoadStopType
Types of RoadStops.
@ ROADSTOP_BUS
A standard stop for buses.
StationHadVehicleOfType
The vehicles that may have visited a station.
StationFacility
The facilities a station might be having.
StationType
Station types.
static constexpr uint MAX_CATCHMENT
Maximum catchment for airports with "modified catchment" enabled.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Finite sTate mAchine (FTA) of an airport.
Defines the data structure for an airport.
std::vector< AirportTileLayout > layouts
List of layouts composing the airport.
static const AirportSpec dummy
The dummy airport.
const struct AirportFTAClass * fsm
the finite statemachine for the default airports
uint8_t size_y
size of airport in y direction
uint8_t size_x
size of airport in x direction
static const AirportSpec * Get(uint8_t type)
Retrieve airport spec for the given airport.
std::span< const HangarTileTable > depots
Position of the depots on the airports.
All airport-related information.
TileIndex GetRotatedTileFromOffset(TileIndexDiffC tidc) const
Add the tileoffset to the base tile of this airport but rotate it first.
bool HasHangar() const
Check if this airport has at least one hangar.
const HangarTileTable * GetHangarDataByTile(TileIndex tile) const
Retrieve hangar information of a hangar at a given tile.
uint GetHangarNum(TileIndex tile) const
Get the hangar number of the hangar at a specific tile.
Direction rotation
How this airport is rotated.
uint8_t type
Type of this airport,.
Direction GetHangarExitDirection(TileIndex tile) const
Get the exit direction of the hangar at a specific tile.
PersistentStorage * psa
Persistent storage for NewGRF airports.
uint GetNumHangars() const
Get the number of hangars on this airport.
uint64_t flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
TileIndex GetHangarTile(uint hangar_num) const
Get the first tile of the given hangar.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
uint8_t layout
Airport layout number.
StationSettings station
settings related to station management
Stores station stats for a single cargo.
FlowStatMap flows
Planned flows through this station.
uint max_waiting_cargo
Max cargo from this station waiting at any station.
bool HasRating() const
Does this cargo have a rating at this station?
GoodsEntryStatus
Status of this cargo for the station.
@ GES_ACCEPTANCE
Set when the station accepts the cargo currently for final deliveries.
@ GES_LAST_MONTH
Set when cargo was delivered for final delivery last month.
@ GES_RATING
This indicates whether a cargo has a rating at the station.
@ GES_CURRENT_MONTH
Set when cargo was delivered for final delivery this month.
@ GES_EVER_ACCEPTED
Set when a vehicle ever delivered cargo to the station for final delivery.
@ GES_ACCEPTED_BIGTICK
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval.
uint8_t last_speed
Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
uint8_t last_age
Age in years (up to 255) of the last vehicle that tried to load this cargo.
uint8_t time_since_pickup
Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.
NodeID node
ID of node in link graph referring to this goods entry.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
uint8_t amount_fract
Fractional part of the amount in the cargo list.
LinkGraphID link_graph
Link graph this station belongs to.
bool HasVehicleEverTriedLoading() const
Reports whether a vehicle has ever tried to load the cargo at this station.
StationID GetVia(StationID source, StationID excluded, StationID excluded2=INVALID_STATION) const
Get the best next hop for a cargo packet from station source, optionally excluding one or two station...
uint8_t rating
Station rating for this cargo.
uint8_t status
Status of this cargo, see GoodsEntryStatus.
StationID GetVia(StationID source) const
Get the best next hop for a cargo packet from station source.
A list of all hangar tiles in an airport.
Direction dir
Direction of the exit.
uint8_t hangar_num
The hangar to which this tile belongs.
Defines the internal data of a functional industry.
Represents the covered area of e.g.
TileIndex tile
The base tile of the area.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Class for pooled persistent storage of data.
Tindex index
Index of this pool item.
static size_t GetNumItems()
Returns number of valid items in the pool.
Specification of a rectangle with absolute coordinates of all edges.
Interface for SpriteGroup-s to access the gamestate.
A Stop for a Road Vehicle.
Buses, trucks and trams belong to this class.
Class defining several overloaded accessors so we don't have to cast base stations that often.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
bool modified_catchment
different-size catchment areas
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
~Station()
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile.
RoadStop * bus_stops
All the road stops.
bool CatchmentCoversTown(TownID t) const
Test if the given town ID is covered by our catchment area.
TileArea ship_station
Tile area the ship 'station' part covers.
IndustryType indtype
Industry type to get the name from.
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
TileArea docking_station
Tile area the docking tiles cover.
CargoTypes always_accepted
Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept c...
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
void GetTileArea(TileArea *ta, StationType type) const override
Get the tile area for a given station type.
Industry * industry
NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
void MoveSign(TileIndex new_xy) override
Move the station main coordinate somewhere else.
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
void RemoveFromAllNearbyLists()
Remove this station from the nearby stations lists of nearby towns and industries.
TileArea bus_station
Tile area the bus 'station' part covers.
bool TileBelongsToRailStation(TileIndex tile) const override
Check whether a specific tile belongs to this station.
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
void RecomputeCatchment(bool no_clear_nearby_lists=false)
Recompute tiles covered in our catchment area.
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
void AfterStationTileSetChange(bool adding, StationType type)
After adding/removing tiles to station, update some station-related stuff.
Airport airport
Tile area the airport covers.
void UpdateVirtCoord() override
Update the virtual coords needed to draw the station sign.
TileArea truck_station
Tile area the truck 'station' part covers.
void AddIndustryToDeliver(Industry *ind, TileIndex tile)
Add nearby industry to station's industries_near list if it accepts cargo.
void RemoveIndustryToDeliver(Industry *ind)
Remove nearby industry from station's industries_near list.
RoadStop * truck_stops
All the truck stops.
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
A pair-construct of a TileIndexDiff.
int16_t x
The x value of the coordinate.
int16_t y
The y value of the coordinate.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_STATION
A tile of a station.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.