31#include "table/strings.h"
40StationKdtree _station_kdtree{};
42void RebuildStationKdtree()
44 std::vector<StationID> stids;
46 stids.push_back(st->index);
48 _station_kdtree.Build(stids.begin(), stids.end());
61 this->
sign.MarkDirty();
64Station::Station(StationID index,
TileIndex tile) :
71 time_since_unload(255),
88 if (!ge.HasData())
continue;
89 ge.GetData().cargo.OnCleanPool();
94 while (!this->loading_vehicles.empty()) {
95 this->loading_vehicles.front()->LeaveStation();
99 if (!a->IsNormalAircraft())
continue;
100 if (a->targetairport == this->index) a->targetairport = StationID::Invalid();
105 if (lg ==
nullptr)
continue;
107 for (NodeID node = 0; node < lg->
Size(); ++node) {
109 if (!st->
goods[cargo].HasData())
continue;
110 st->
goods[cargo].GetData().flows.erase(this->
index);
112 st->
goods[cargo].GetData().flows.DeleteFlows(this->
index);
117 if (lg->
Size() == 0) {
125 if (v->last_station_visited == this->index) {
126 v->last_station_visited = StationID::Invalid();
128 if (v->last_loading_station == this->index) {
129 v->last_loading_station = StationID::Invalid();
155 if (!ge.HasData())
continue;
156 ge.GetData().cargo.Truncate();
161 _station_kdtree.Remove(this->
index);
162 if (this->
sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->
index));
176bool BaseStation::SetRoadStopTileData(
TileIndex tile, uint8_t data,
bool animation)
179 if (tile_data.tile == tile) {
180 uint8_t &v = animation ? tile_data.animation_frame : tile_data.random_bits;
181 if (v == data)
return false;
187 tile_data.tile = tile;
188 tile_data.animation_frame = animation ? data : 0;
189 tile_data.random_bits = animation ? 0 : data;
194void BaseStation::RemoveRoadStopTileData(
TileIndex tile)
197 if (tile_data.tile == tile) {
214 for (; rs !=
nullptr; rs = rs->
next) {
327 default: NOT_REACHED();
355 if (!this->
airport.IsEmpty()) ret = std::max<uint>(ret, this->
airport.GetSpec()->catchment);
377 auto pos = std::ranges::find(this->
industries_near, ind, &IndustryListEntry::industry);
379 if (pos->distance > distance) {
381 node.value().distance = distance;
399 auto pos = std::ranges::find(this->
industries_near, ind, &IndustryListEntry::industry);
423 for (
const TownID &townid : towns) {
Town::Get(townid)->stations_near.erase(
this); }
424 for (
const IndustryID &industryid : industries) {
Industry::Get(industryid)->stations_near.erase(
this); }
453 if (this->
spread.IsEmpty()) {
458 if (!
_settings_game.station.serve_neutral_industries && this->industry !=
nullptr) {
467 for (Station *st : this->
industry->stations_near) {
470 this->
industry->stations_near.clear();
471 this->
industry->stations_near.insert(
this);
494 Town *t = Town::GetByTile(tile);
531 if (new_area.
w == 0 || new_area.
h == 0)
return CMD_ERROR;
539 return CommandCost(STR_ERROR_STATION_TOO_SPREAD_OUT);
552 Money total_cost = 0;
560 return total_cost >> 3;
563bool StationCompare::operator() (
const Station *lhs,
const Station *rhs)
const
565 return lhs->index < rhs->index;
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
CargoType
Cargo slots to indicate a cargo type within a game.
Iterator to iterate over all tiles belonging to a bitmaptilearea.
Common return value for all commands.
Iterate a range of enum values.
Flat set implementation that uses a sorted vector for storage.
std::pair< const_iterator, bool > insert(const Tkey &key)
Insert a key into the set, if it does not already exist.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
A connected component of a link graph.
NodeID Size() const
Get the current size of the component.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
static Date date
Current date in days (day counter).
static constexpr TimerGame< struct Economy >::Date INVALID_DATE
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
DiagDirection
Enumeration for diagonal directions.
@ End
Used for iterations.
Prices _price
Prices and also the fractional part.
@ InfrastructureAirport
Airports maintenance cost.
Flat set container implementation.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
Declaration of link graph classes used for cargo distribution.
Declaration of link graph schedule used for cargo distribution.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
This function checks if we add addx/addy to tile, if we do wrap around the edges.
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
int32_t TileIndexDiff
An offset value between two tiles.
Functions related to news.
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Pseudo random number generator.
bool HasTileAnyRoadType(Tile t, RoadTypes rts)
Check if a tile has one of the specified road types.
Base class for roadstops.
A number of safeguards to prevent using unsafe methods.
@ Invalid
broken savegame (used internally)
@ RoadStopTileData
Saveload version: 340, GitHub pull request: 12883 Move storage of road stop tile data,...
GameSettings _settings_game
Game settings of a running game or the scenario editor.
CommandCost CheckStationSpread(TileArea area, const TileArea &new_area)
Check if adding a new area to a station will exceed the maximum station spread.
StationPool _station_pool("Station")
The pool of stations.
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
Get the catchment size of an individual station tile.
Base classes/functions for stations.
void RerouteCargo(Station *st, CargoType cargo, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
Declarations for accessing the k-d tree of stations.
StationType GetStationType(Tile t)
Get the station type of this tile.
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
bool IsCompatibleTrainStationTile(Tile test_tile, Tile station_tile)
Check if a tile is a valid continuation to a railstation tile.
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
static constexpr uint CA_TRAIN
Catchment for train stations with "modified catchment" enabled.
@ Bus
A standard stop for buses.
@ Truck
A standard stop for trucks.
StationFacility
The facilities a station might be having.
@ Airport
Station with an airport.
static constexpr uint CA_NONE
Catchment when the station has no facilities.
@ Rail
Railways/train station.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ RailWaypoint
Waypoint for trains.
@ Buoy
Waypoint for ships.
@ RoadWaypoint
Waypoint for trucks and busses.
@ Oilrig
Heliport on an oil rig.
@ Airport
Airports and heliports, excluding the ones on oil rigs.
static constexpr uint CA_DOCK
Catchment for docks with "modified catchment" enabled.
static constexpr uint CA_BUS
Catchment for bus stops with "modified catchment" enabled.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
static constexpr uint CA_TRUCK
Catchment for truck stops with "modified catchment" enabled.
Definition of base types and functions in a cross-platform compatible way.
Aircraft, helicopters, rotors and their shadows belong to this class.
uint8_t catchment
catchment area of this airport
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
TileIndex xy
Base tile of the station.
std::vector< SpecMapping< StationSpec > > speclist
List of rail station specs of this station.
StationFacilities facilities
The facilities that this station has.
virtual ~BaseStation()
Ensure the destructor of the sub classes are called as well.
TileArea train_station
Tile area the train 'station' part covers.
Owner owner
The owner of this station.
static void PostDestructor(size_t index)
Invalidating of the JoinStation window has to be done after removing item from the pool.
uint16_t random_bits
Random bits assigned to this station.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
std::vector< RoadStopTileData > custom_roadstop_tile_data
List of custom road stop tile data.
TimerGameCalendar::Date build_date
Date of construction.
TileArea spread
NOSAVE: Station spread tile area.
static void InvalidateAllFrom(Source src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Stores station stats for a single cargo.
Defines the internal data of a functional industry.
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Station * neutral_station
Associated neutral station.
StationList stations_near
NOSAVE: List of nearby stations.
uint16_t w
The width of the area.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
static Pool::IterateWrapper< Vehicle > Iterate(size_t from=0)
static Town * Get(auto index)
static bool CleaningPool()
static LinkGraph * GetIfValid(auto index)
A Stop for a Road Vehicle.
RoadStop * next
Next stop of the given type at this station.
TileIndex xy
Position on the map.
Buses, trucks and trams belong to this class.
RoadTypes compatible_roadtypes
NOSAVE: Roadtypes this consist is powered on.
bool IsBus() const
Check whether a roadvehicle is a bus.
Class defining several overloaded accessors so we don't have to cast base stations that often.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
static Station * Get(auto index)
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile.
~Station() override
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
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.
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
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.
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
void RemoveFromAllNearbyLists()
Remove this station from the nearby stations lists of nearby towns and industries.
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.
Airport airport
Tile area the airport 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.
StationList stations_near
NOSAVE: List of nearby stations.
The information about a vehicle list.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
TileType
The different types of tiles.
@ Station
A tile of a station or airport.
@ Industry
Part of an industry.
@ House
A house by a town.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
TownID GetTownIndex(Tile t)
Get the index of which town this house/street is attached to.
VehicleType
Available vehicle types.
@ Aircraft
Aircraft vehicle type.
@ Train
Train vehicle type.
Functions and type for generating vehicle lists.
@ Station
Index is the station.
Functions related to (drawing on) viewports.
Declarations for accessing the k-d tree of viewports.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting).
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...