Go to the documentation of this file.
15 #include "viewport_kdtree.h"
31 #include "table/strings.h"
42 void RebuildStationKdtree()
44 std::vector<StationID> stids;
46 stids.push_back(st->index);
48 _station_kdtree.
Build(stids.begin(), stids.end());
52 BaseStation::~BaseStation()
71 time_since_unload(255),
93 while (!this->loading_vehicles.empty()) {
94 this->loading_vehicles.front()->LeaveStation();
98 if (!a->IsNormalAircraft())
continue;
99 if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
104 if (lg ==
nullptr)
continue;
106 for (NodeID node = 0; node < lg->
Size(); ++node) {
115 if (lg->
Size() == 0) {
123 if (v->last_station_visited == this->index) {
124 v->last_station_visited = INVALID_STATION;
126 if (v->last_loading_station == this->index) {
127 v->last_loading_station = INVALID_STATION;
182 for (; rs !=
nullptr; rs = rs->
next) {
228 if (this->
speclist.size() == 0)
return;
295 case STATION_TRUCK:
return CA_TRUCK;
296 case STATION_BUS:
return CA_BUS;
297 case STATION_DOCK:
return CA_DOCK;
299 default: NOT_REACHED();
301 case STATION_WAYPOINT:
return CA_NONE;
307 case STATION_WAYPOINT:
return CA_NONE;
341 assert(!this->
rect.IsEmpty());
347 std::max<int>(this->
rect.left - catchment_radius, 0),
348 std::max<int>(this->
rect.top - catchment_radius, 0),
349 std::min<int>(this->
rect.right + catchment_radius,
MapMaxX()),
350 std::min<int>(this->
rect.bottom + catchment_radius,
MapMaxY())
368 auto pos = std::find_if(this->
industries_near.begin(), this->industries_near.end(), [&](
const IndustryListEntry &e) { return e.industry->index == ind->index; });
370 if (pos->distance > distance) {
372 node.value().distance = distance;
393 auto pos = std::find_if(this->
industries_near.begin(), this->industries_near.end(), [&](
const IndustryListEntry &e) { return e.industry->index == ind->index; });
434 if (this->
rect.IsEmpty()) {
476 Town *t = Town::GetByTile(tile);
506 StationRect::StationRect()
511 void StationRect::MakeEmpty()
513 this->left = this->top = this->right = this->bottom = 0;
527 return this->left - distance <= x && x <= this->right + distance &&
528 this->top - distance <= y && y <= this->bottom + distance;
531 bool StationRect::IsEmpty()
const
533 return this->left == 0 || this->left > this->right || this->top > this->bottom;
540 if (this->IsEmpty()) {
542 if (mode != ADD_TEST) {
543 this->left = this->right = x;
544 this->top = this->bottom = y;
549 Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
552 int w = new_rect.
Width();
553 int h = new_rect.
Height();
555 assert(mode != ADD_TRY);
560 if (mode != ADD_TEST) {
610 bool left_edge = (x == this->left);
611 bool right_edge = (x == this->right);
612 bool top_edge = (y == this->top);
613 bool bottom_edge = (y == this->bottom);
618 if (!(reduce_x || reduce_y))
break;
624 this->left = x = x + 1;
627 this->right = x = x - 1;
634 this->top = y = y + 1;
637 this->bottom = y = y - 1;
641 if (left > right || top > bottom) {
655 bool empty = this->AfterRemoveTile(st, ta.
tile);
656 if (ta.
w != 1 || ta.
h != 1) empty = empty || this->AfterRemoveTile(st,
TILE_ADDXY(ta.
tile, ta.
w - 1, ta.
h - 1));
662 this->left = src.left;
664 this->right = src.right;
665 this->bottom = src.bottom;
676 Money total_cost = 0;
680 total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
684 return total_cost >> 3;
687 bool StationCompare::operator() (
const Station *lhs,
const Station *rhs)
const
@ VEH_AIRCRAFT
Aircraft vehicle type.
Buses, trucks and trams belong to this class.
@ MP_HOUSE
A house by a town.
StationFacility facilities
The facilities that this station has.
@ CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
std::vector< StationSpecList > speclist
List of rail station specs of this station.
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-...
GoodsEntry goods[NUM_CARGO]
Goods at this station.
static bool HasTileAnyRoadType(TileIndex t, RoadTypes rts)
Check if a tile has one of the specified road types.
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
int Height() const
Get height of Rect.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
StationSettings station
settings related to station management
void Initialize(const Rect &r)
Initialize the BitmapTileArea with the specified Rect.
void OnCleanPool()
Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket'...
A connected component of a link graph.
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile.
@ ROADSTOP_TRUCK
A standard stop for trucks.
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
@ CA_NONE
Catchment when the station has no facilities.
K-dimensional tree, specialised for 2-dimensional space.
The information about a vehicle list.
void SetTile(TileIndex tile)
Add a tile as part of the tile area.
TileIndex xy
Position on the map.
void RecomputeCatchment()
Recompute tiles covered in our catchment area.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Class defining several overloaded accessors so we don't have to cast base stations that often.
StationPool _station_pool("Station")
The pool of stations.
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
Iterator to iterate over all tiles belonging to a bitmaptilearea.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
@ DIAGDIR_END
Used for iterations.
Tindex index
Index of this pool item.
bool PtInExtendedRect(int x, int y, int distance=0) const
Determines whether a given point (x, y) is within a certain distance of the station rectangle.
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static bool IsCompatibleTrainStationTile(TileIndex test_tile, TileIndex station_tile)
Check if a tile is a valid continuation to a railstation tile.
void MoveSign(TileIndex new_xy) override
Move the station main coordinate somewhere else.
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
@ FACIL_NONE
The station has no facilities at all.
static Station * Get(size_t index)
Gets station with given index.
@ MP_INDUSTRY
Part of an industry.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
Get the catchment size of an individual station tile.
NodeID Size() const
Get the current size of the component.
@ WC_STATION_VIEW
Station view; Window numbers:
@ VEH_ROAD
Road vehicle type.
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.
Owner
Enum for all companies/owners.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
void Build(It begin, It end)
Clear and rebuild the tree from a new sequence of elements,.
Owner owner
The owner of this station.
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
Station * neutral_station
Associated neutral station.
bool Succeeded() const
Did this command succeed?
static uint TileX(TileIndex tile)
Get the X component of a tile.
void Remove(const T &element)
Remove a single element from the tree, if it exists.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Aircraft, helicopters, rotors and their shadows belong to this class.
StationCargoList cargo
The cargo packets of cargo waiting in this station.
struct RoadStop * next
Next stop of the given type at this station.
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
StationList stations_near
NOSAVE: List of nearby stations.
Common return value for all commands.
TileArea location
Location of the industry.
Date _date
Current date in days (day counter)
TileArea train_station
Tile area the train 'station' part covers.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
uint16 random_bits
Random bits assigned to this station.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
int32 TileIndexDiff
An offset value between two tiles.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
void Reset()
Reset and clear the BitmapTileArea.
uint16 w
The width of the area.
StationList stations_near
NOSAVE: List of nearby stations.
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
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.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void MarkDirty(ZoomLevel maxzoom=ZOOM_LVL_MAX) const
Mark the sign dirty in all viewports.
~Station()
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
@ CA_BUS
Catchment for bus stops with "modified catchment" enabled.
@ VEH_INVALID
Non-existing type of vehicle.
@ WC_SHIPS_LIST
Ships list; Window numbers:
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
@ CA_TRUCK
Catchment for truck stops with "modified catchment" enabled.
DiagDirection
Enumeration for diagonal directions.
@ WC_TRAINS_LIST
Trains list; Window numbers:
byte station_spread
amount a station may spread
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
RoadStop * truck_stops
All the truck stops.
Industry * industry
NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
Check whether station tiles of the given station id exist in the given rectangle.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
StationFacility
The facilities a station might be having.
uint16 h
The height of the area.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
@ CA_DOCK
Catchment for docks with "modified catchment" enabled.
@ ROADSTOP_BUS
A standard stop for buses.
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
CompanyID _current_company
Company currently doing an action.
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Base class for all pools.
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static const Date INVALID_DATE
Representation of an invalid date.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
FlowStatMap flows
Planned flows through this station.
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
TileIndex tile
The base tile of the area.
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
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...
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
@ OWNER_NONE
The tile has no ownership.
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.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
void RemoveIndustryToDeliver(Industry *ind)
Remove nearby industry from station's industries_near list.
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
TileIndex xy
Base tile of the station.
Base class for all station-ish types.
static Pool::IterateWrapper< Aircraft > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
#define lengthof(x)
Return the length of an fixed size array.
void RemoveFromAllNearbyLists()
Remove this station from the nearby stations lists of all towns and industries.
static void PostDestructor(size_t index)
Invalidating of the JoinStation window has to be done after removing item from the pool.
@ CA_TRAIN
Catchment for train stations with "modified catchment" enabled.
byte CargoID
Cargo slots to indicate a cargo type within a game.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
bool IsBus() const
Check whether a roadvehicle is a bus.
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.
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
@ VEH_TRAIN
Train vehicle type.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
A Stop for a Road Vehicle.
@ FACIL_AIRPORT
Station with an airport.
PersistentStorage * psa
Persistent storage for NewGRF airports.
int Width() const
Get width of Rect.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
@ CT_INVALID
Invalid cargo type.
@ VEH_SHIP
Ship vehicle type.
Specification of a rectangle with absolute coordinates of all edges.
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Date build_date
Date of construction.
@ WC_STATION_LIST
Station list; Window numbers:
byte catchment
catchment area of this airport
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=nullptr)
Truncates where each destination loses roughly the same percentage of its cargo.
TileArea ship_station
Tile area the ship 'station' part covers.
void AddIndustryToDeliver(Industry *ind, TileIndex tile)
Add nearby industry to station's industries_near list if it accepts cargo.
bool modified_catchment
different-size catchment areas