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