12 #ifndef STATION_BASE_H 13 #define STATION_BASE_H 22 #include "bitmap_type.h" 29 static const byte INITIAL_STATION_RATING = 175;
40 typedef std::map<uint32, StationID> SharesMap;
57 inline FlowStat(StationID st, uint flow,
bool restricted =
false)
72 inline void AppendShare(StationID st, uint flow,
bool restricted =
false)
123 assert(!this->
shares.empty());
126 return this->
shares.upper_bound(rand)->second;
138 assert(!this->
shares.empty());
144 StationID
GetVia(StationID excluded, StationID excluded2 = INVALID_STATION)
const;
156 uint GetFlow()
const;
157 uint GetFlowVia(StationID via)
const;
158 uint GetFlowFrom(StationID from)
const;
159 uint GetFlowFromVia(StationID from, StationID via)
const;
161 void AddFlow(StationID origin, StationID via, uint amount);
162 void PassOnFlow(StationID origin, StationID via, uint amount);
164 void RestrictFlows(StationID via);
165 void ReleaseFlows(StationID via);
166 void FinalizeLocalConsumption(StationID
self);
218 time_since_pickup(255),
219 rating(INITIAL_STATION_RATING),
223 link_graph(INVALID_LINK_GRAPH),
277 return HasBit(this->status, GES_RATING);
285 inline StationID
GetVia(StationID source)
const 287 FlowStatMap::const_iterator flow_it(this->flows.find(source));
288 return flow_it != this->flows.end() ? flow_it->second.GetVia() : INVALID_STATION;
299 inline StationID
GetVia(StationID source, StationID excluded, StationID excluded2 = INVALID_STATION)
const 301 FlowStatMap::const_iterator flow_it(this->flows.find(source));
302 return flow_it != this->flows.end() ? flow_it->second.GetVia(excluded, excluded2) : INVALID_STATION;
336 return this->GetSpec()->fsm;
342 return this->GetSpec()->nof_depots > 0;
356 switch (this->rotation) {
365 default: NOT_REACHED();
380 return this->GetRotatedTileFromOffset(as->
depot_table[i].
ti);
437 if (this->GetRotatedTileFromOffset(as->
depot_table[i].
ti) == tile) {
449 typedef std::set<Industry *, IndustryCompare> IndustryList;
476 byte time_since_load;
477 byte time_since_unload;
479 byte last_vehicle_type;
480 std::list<Vehicle *> loading_vehicles;
492 void MarkTilesDirty(
bool cargo_change)
const;
494 void UpdateVirtCoord()
override;
496 void MoveSign(
TileIndex new_xy)
override;
498 void AfterStationTileSetChange(
bool adding,
StationType type);
501 uint GetPlatformLength(
TileIndex tile)
const override;
502 void RecomputeCatchment();
503 static void RecomputeCatchmentForAll();
505 uint GetCatchmentRadius()
const;
506 Rect GetCatchmentRect()
const;
507 bool CatchmentCoversTown(TownID t)
const;
508 void RemoveFromAllNearbyLists();
510 inline bool TileIsInCatchment(
TileIndex tile)
const 512 return this->catchment_tiles.
HasTile(tile);
520 inline bool TileBelongsToAirport(
TileIndex tile)
const 525 uint32 GetNewGRFVariable(
const ResolverObject &
object, byte variable, byte parameter,
bool *available)
const override;
530 #define FOR_ALL_STATIONS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Station, var) 544 if (!st->TileBelongsToAirport(this->tile)) ++(*
this);
549 (*this).OrthogonalTileIterator::operator++();
550 while (this->tile !=
INVALID_TILE && !st->TileBelongsToAirport(this->tile)) {
551 (*this).OrthogonalTileIterator::operator++();
562 void RebuildStationKdtree();
static void Swap(T &a, T &b)
Type safe swap operation.
byte type
Type of this airport,.
const HangarTileTable * GetHangarDataByTile(TileIndex tile) const
Retrieve hangar information of a hangar at a given tile.
Finite sTate mAchine (FTA) of an airport.
Types related to the industry.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
TileArea bus_station
Tile area the bus 'station' part covers.
Direction rotation
How this airport is rotated.
Minimal stack that uses a pool to avoid pointers.
const Station * st
The station the airport is a part of.
TileArea ship_station
Tile area the ship 'station' part covers.
Direction GetHangarExitDirection(TileIndex tile) const
Get the exit direction of the hangar at a specific tile.
byte size_y
size of airport in y direction
Iterator to iterate over all tiles belonging to an airport.
SharesMap shares
Shares of flow to be sent via specified station (or consumed locally).
bool HasVehicleEverTriedLoading() const
Reports whether a vehicle has ever tried to load the cargo at this station.
static bool IsAirportTile(TileIndex t)
Is this tile a station tile and an airport tile?
uint GetNumHangars() const
Get the number of hangars on this airport.
byte hangar_num
The hangar to which this tile belongs.
bool HasHangar() const
Check if this airport has at least one hangar.
CargoList that is used for stations.
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
void SwapShares(FlowStat &other)
Swap the shares maps, and thus the content of this FlowStat with the other one.
Functionality related to the temporary and persistent storage arrays for NewGRFs. ...
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Interface for SpriteGroup-s to access the gamestate.
Maximal number of cargo types in a game.
Set when cargo was delivered for final delivery during the current STATION_ACCEPTANCE_TICKS interval...
Set when cargo was delivered for final delivery this month.
const HangarTileTable * depot_table
gives the position of the depots on the airports
A standard stop for buses.
Defines the internal data of a functional industry.
Stores station stats for a single cargo.
static const AirportSpec dummy
The dummy airport.
A list of all hangar tiles in an airport.
virtual TileIterator * Clone() const
Allocate a new iterator that is a copy of this one.
StationPool _station_pool
The pool of stations.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
bool HasRating() const
Does this cargo have a rating at this station?
byte nof_depots
the number of hangar tiles in this airport
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
RoadStopType
Types of RoadStops.
NewGRF handling of airports.
Pseudo random number generator.
int16 y
The y value of the coordinate.
Set when cargo was delivered for final delivery last month.
Base class for cargo packets.
void ScaleToMonthly(uint runtime)
Scale all shares from link graph's runtime to monthly values.
TileArea docking_station
Tile area the docking tiles cover.
Buses, trucks and trams belong to this class.
uint GetShare(StationID st) const
Get flow for a station.
bool TileBelongsToRailStation(TileIndex tile) const override
Check whether a specific tile belongs to this station.
byte amount_fract
Fractional part of the amount in the cargo list.
byte rating
Station rating for this cargo.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
RoadStop * truck_stops
All the truck stops.
This indicates whether a cargo has a rating at the station.
StationID GetVia(StationID source) const
Get the best next hop for a cargo packet from station source.
LinkGraphID link_graph
Link graph this station belongs to.
uint unrestricted
Limit for unrestricted shares.
GoodsEntryStatus
Status of this cargo for the station.
FlowStat()
Invalid constructor.
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
const Direction * rotation
the rotation of each tiletable
StationID GetVia() const
Get a station a package can be routed to.
TileArea truck_station
Tile area the truck 'station' part covers.
byte status
Status of this cargo, see GoodsEntryStatus.
byte layout
Airport layout number.
FlowStat(StationID st, uint flow, bool restricted=false)
Create a FlowStat with an initial entry.
int16 x
The x value of the coordinate.
Direction
Defines the 8 directions on the map.
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...
NodeID node
ID of node in link graph referring to this goods entry.
Represents the covered area of e.g.
Class for pooled persistent storage of data.
Represents a tile area containing containing individually set tiles.
Base class for tile iterators.
static const AirportSpec * Get(byte type)
Retrieve airport spec for the given airport.
PersistentStorage * psa
Persistent storage for NewGRF airports.
All airport-related information.
static DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
void RestrictShare(StationID st)
Restrict a flow by moving it to the end of the map and decreasing the amount of unrestricted flow...
uint64 flags
stores which blocks on the airport are taken. was 16 bit earlier on, then 32
static const SharesMap empty_sharesmap
Static instance of FlowStat::SharesMap.
byte last_speed
Maximum speed (up to 255) of the last vehicle that tried to load this cargo.
Declaration of link graph types used for cargo distribution.
bool HasTile(TileIndex tile) const
Test if a tile is part of the tile area.
byte last_age
Age in years (up to 255) of the last vehicle that tried to load this cargo.
TileIndex GetHangarTile(uint hangar_num) const
Get the first tile of the given hangar.
TileIndexDiffC ti
Tile offset from the top-most airport tile.
RoadStop * bus_stops
All the road stops.
Base class for all pools.
FlowStatMap flows
Planned flows through this station.
void ChangeShare(StationID st, int flow)
Change share for specified station.
StationID GetViaWithRestricted(bool &is_restricted) const
Get a station a package can be routed to.
A pair-construct of a TileIndexDiff.
void ReleaseShare(StationID st)
Release ("unrestrict") a flow by moving it to the begin of the map and increasing the amount of unres...
static TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
Return the offset between to tiles from a TileIndexDiffC struct.
uint GetUnrestricted() const
Return total amount of unrestricted shares.
Set when a vehicle ever delivered cargo to the station for final delivery.
uint GetHangarNum(TileIndex tile) const
Get the hangar number of the hangar at a specific tile.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
StationType
Station types.
Direction dir
Direction of the exit.
uint max_waiting_cargo
Max cargo from this station waiting at any station.
StationFacility
The facilities a station might be having.
uint32 TileIndex
The index/ID of a Tile.
void Invalidate()
Reduce all flows to minimum capacity so that they don't get in the way of link usage statistics too m...
const SharesMap * GetShares() const
Get the actual shares as a const pointer so that they can be iterated over.
byte size_x
size of airport in x direction
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
Flow statistics telling how much flow should be sent along a link.
A Stop for a Road Vehicle.
Iterator to iterate over a tile area (rectangle) of the map.
Base classes/functions for base stations.
Flow descriptions by origin stations.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Airport airport
Tile area the airport covers.
TileIndex GetRotatedTileFromOffset(TileIndexDiffC tidc) const
Add the tileoffset to the base tile of this airport but rotate it first.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
DiagDirection
Enumeration for diagonal directions.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Specification of a rectangle with absolute coordinates of all edges.
IndustryType indtype
Industry type to get the name from.
byte time_since_pickup
Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo.
Defines the data structure for an airport.
StationHadVehicleOfType
The vehicles that may have visited a station.
Industry * industry
NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st) ...
Set when the station accepts the cargo currently for final deliveries.
Class defining several overloaded accessors so we don't have to cast base stations that often...
AirportTileIterator(const Station *st)
Construct the iterator.
CargoTypes always_accepted
Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept c...