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()
73 time_since_unload(255),
95 while (!this->loading_vehicles.empty()) {
96 this->loading_vehicles.front()->LeaveStation();
100 if (!a->IsNormalAircraft())
continue;
101 if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
106 if (lg ==
nullptr)
continue;
108 for (NodeID node = 0; node < lg->
Size(); ++node) {
117 if (lg->
Size() == 0) {
125 if (v->last_station_visited == this->index) {
126 v->last_station_visited = INVALID_STATION;
128 if (v->last_loading_station == this->index) {
129 v->last_loading_station = INVALID_STATION;
184 for (; rs !=
nullptr; rs = rs->
next) {
297 case STATION_TRUCK:
return CA_TRUCK;
298 case STATION_BUS:
return CA_BUS;
299 case STATION_DOCK:
return CA_DOCK;
301 default: NOT_REACHED();
303 case STATION_WAYPOINT:
return CA_NONE;
309 case STATION_WAYPOINT:
return CA_NONE;
343 assert(!this->
rect.IsEmpty());
349 std::max<int>(this->
rect.left - catchment_radius, 0),
350 std::max<int>(this->
rect.top - catchment_radius, 0),
351 std::min<int>(this->
rect.right + catchment_radius,
MapMaxX()),
352 std::min<int>(this->
rect.bottom + catchment_radius,
MapMaxY())
365 if (this->
industries_near.find(ind) != this->industries_near.end())
return;
411 if (this->
rect.IsEmpty()) {
453 Town *t = Town::GetByTile(tile);
483 StationRect::StationRect()
488 void StationRect::MakeEmpty()
490 this->left = this->top = this->right = this->bottom = 0;
504 return this->left - distance <= x && x <= this->right + distance &&
505 this->top - distance <= y && y <= this->bottom + distance;
508 bool StationRect::IsEmpty()
const
510 return this->left == 0 || this->left > this->right || this->top > this->bottom;
517 if (this->IsEmpty()) {
519 if (mode != ADD_TEST) {
520 this->left = this->right = x;
521 this->top = this->bottom = y;
526 Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
529 int w = new_rect.right - new_rect.left + 1;
530 int h = new_rect.bottom - new_rect.top + 1;
532 assert(mode != ADD_TRY);
537 if (mode != ADD_TEST) {
587 bool left_edge = (x == this->left);
588 bool right_edge = (x == this->right);
589 bool top_edge = (y == this->top);
590 bool bottom_edge = (y == this->bottom);
595 if (!(reduce_x || reduce_y))
break;
601 this->left = x = x + 1;
604 this->right = x = x - 1;
611 this->top = y = y + 1;
614 this->bottom = y = y - 1;
618 if (left > right || top > bottom) {
632 bool empty = this->AfterRemoveTile(st, ta.
tile);
633 if (ta.
w != 1 || ta.
h != 1) empty = empty || this->AfterRemoveTile(st,
TILE_ADDXY(ta.
tile, ta.
w - 1, ta.
h - 1));
639 this->left = src.left;
641 this->right = src.right;
642 this->bottom = src.bottom;
653 Money total_cost = 0;
657 total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
661 return total_cost >> 3;
664 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:
uint32 TileIndex
The index/ID of a Tile.
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.
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.
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 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.
@ 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?
uint8 num_specs
Number of specs in the speclist.
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.
@ ROADSTOP_BUS
A standard stop for buses.
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)
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
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 to 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.
uint Size() const
Get the current size of the component.
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.
void AddIndustryToDeliver(Industry *ind)
Add nearby industry to station's industries_near list if it accepts cargo.
@ CA_BUS
Catchment for bus stops with "modified catchment" enabled.
@ VEH_INVALID
Non-existing type of vehicle.
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ ROADSTOP_TRUCK
A standard stop for trucks.
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.
@ CA_DOCK
Catchment for docks with "modified catchment" enabled.
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.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
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.
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
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.
StationSpecList * speclist
List of station specs of this station.
#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.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
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.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
@ 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.
bool modified_catchment
different-size catchment areas