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()
74 time_since_unload(255),
91 this->goods[c].cargo.OnCleanPool();
96 while (!this->loading_vehicles.empty()) {
97 this->loading_vehicles.front()->LeaveStation();
101 if (!a->IsNormalAircraft())
continue;
102 if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
107 if (lg ==
nullptr)
continue;
109 for (NodeID node = 0; node < lg->
Size(); ++node) {
112 if ((*lg)[node][this->goods[c].node].LastUpdate() !=
INVALID_DATE) {
118 if (lg->
Size() == 0) {
126 if (v->last_station_visited == this->index) {
127 v->last_station_visited = INVALID_STATION;
129 if (v->last_loading_station == this->index) {
130 v->last_loading_station = INVALID_STATION;
135 this->RemoveFromAllNearbyLists();
138 delete this->airport.psa;
156 this->goods[c].cargo.Truncate();
161 _station_kdtree.
Remove(this->index);
162 if (this->sign.kdtree_valid) _viewport_sign_kdtree.
Remove(ViewportSignKdtreeItem::MakeStation(this->index));
185 for (; rs !=
nullptr; rs = rs->
next) {
205 this->MoveSign(facil_xy);
206 this->random_bits = Random();
208 this->facilities |= new_facility_bit;
210 this->build_date =
_date;
220 TileIndex tile = this->train_station.tile;
231 if (this->num_specs == 0)
return;
234 for (h = 0; h < train_station.h; h++) {
235 for (w = 0; w < train_station.w; w++) {
236 if (this->TileBelongsToRailStation(tile)) {
247 assert(this->TileBelongsToRailStation(tile));
298 case STATION_TRUCK:
return CA_TRUCK;
299 case STATION_BUS:
return CA_BUS;
300 case STATION_DOCK:
return CA_DOCK;
302 default: NOT_REACHED();
304 case STATION_WAYPOINT:
return CA_NONE;
310 case STATION_WAYPOINT:
return CA_NONE;
324 if (this->bus_stops !=
nullptr) ret = max<uint>(ret,
CA_BUS);
325 if (this->truck_stops !=
nullptr) ret = max<uint>(ret,
CA_TRUCK);
328 if (this->airport.tile !=
INVALID_TILE) ret = max<uint>(ret, this->airport.GetSpec()->catchment);
330 if (this->bus_stops !=
nullptr || this->truck_stops !=
nullptr || this->train_station.tile !=
INVALID_TILE || this->ship_station.tile !=
INVALID_TILE || this->airport.tile !=
INVALID_TILE) {
344 assert(!this->rect.IsEmpty());
347 int catchment_radius = this->GetCatchmentRadius();
350 max<int>(this->rect.left - catchment_radius, 0),
351 max<int>(this->rect.top - catchment_radius, 0),
352 min<int>(this->rect.right + catchment_radius,
MapMaxX()),
353 min<int>(this->rect.bottom + catchment_radius,
MapMaxY())
410 this->industries_near.clear();
411 this->RemoveFromAllNearbyLists();
413 if (this->rect.IsEmpty()) {
414 this->catchment_tiles.Reset();
420 this->catchment_tiles.Initialize(this->industry->location);
423 this->catchment_tiles.SetTile(tile);
427 for (
Station *st : this->industry->stations_near) {
430 this->industry->stations_near.clear();
431 this->industry->stations_near.insert(
this);
432 this->industries_near.insert(this->industry);
436 this->catchment_tiles.Initialize(GetCatchmentRect());
439 TileArea ta(
TileXY(this->rect.left, this->rect.top),
TileXY(this->rect.right, this->rect.bottom));
455 Town *t = Town::GetByTile(tile);
485 StationRect::StationRect()
490 void StationRect::MakeEmpty()
492 this->left = this->top = this->right = this->bottom = 0;
506 return this->left - distance <= x && x <= this->right + distance &&
507 this->top - distance <= y && y <= this->bottom + distance;
510 bool StationRect::IsEmpty()
const 512 return this->left == 0 || this->left > this->right || this->top > this->bottom;
519 if (this->IsEmpty()) {
521 if (mode != ADD_TEST) {
522 this->left = this->right = x;
523 this->top = this->bottom = y;
525 }
else if (!this->PtInExtendedRect(x, y)) {
528 Rect new_rect = {
min(x, this->left),
min(y, this->top),
max(x, this->right),
max(y, this->bottom)};
531 int w = new_rect.right - new_rect.left + 1;
532 int h = new_rect.bottom - new_rect.top + 1;
534 assert(mode != ADD_TRY);
539 if (mode != ADD_TEST) {
589 bool left_edge = (x == this->left);
590 bool right_edge = (x == this->right);
591 bool top_edge = (y == this->top);
592 bool bottom_edge = (y == this->bottom);
595 bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->
index, x, this->top, x, this->bottom));
596 bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->
index, this->left, y, this->right, y));
597 if (!(reduce_x || reduce_y))
break;
603 this->left = x = x + 1;
606 this->right = x = x - 1;
613 this->top = y = y + 1;
616 this->bottom = y = y - 1;
620 if (left > right || top > bottom) {
634 bool empty = this->AfterRemoveTile(st, ta.
tile);
635 if (ta.
w != 1 || ta.
h != 1) empty = empty || this->AfterRemoveTile(st,
TILE_ADDXY(ta.
tile, ta.
w - 1, ta.
h - 1));
641 this->left = src.left;
643 this->right = src.right;
644 this->bottom = src.bottom;
655 Money total_cost = 0;
659 total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
663 return total_cost >> 3;
666 bool StationCompare::operator() (
const Station *lhs,
const Station *rhs)
const Owner
Enum for all companies/owners.
Iterator to iterate over all tiles belonging to a bitmaptilearea.
static bool HasTileAnyRoadType(TileIndex t, RoadTypes rts)
Check if a tile has one of the specified road types.
StationFacility facilities
The facilities that this station has.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Select station (when joining stations); Window numbers:
A standard stop for trucks.
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
The information about a vehicle list.
Non-existing type of vehicle.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Base class for roadstops.
Functions and type for generating vehicle lists.
int32 TileIndexDiff
An offset value between to tiles.
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Functions related to dates.
Maximal number of cargo types in a game.
TileIndex xy
Position on the map.
bool CatchmentCoversTown(TownID t) const
Test if the given town ID is covered by our catchment area.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Aircraft, helicopters, rotors and their shadows belong to this class.
The station has no facilities at all.
static uint TileX(TileIndex tile)
Get the X component of a tile.
A standard stop for buses.
byte station_spread
amount a station may spread
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
Defines the internal data of a functional industry.
Tindex index
Index of this pool item.
Declarations for accessing the k-d tree of stations.
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
void RecomputeCatchment()
Recompute tiles covered in our catchment area.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Common return value for all commands.
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Catchment for bus stops with "modified catchment" enabled.
static T max(const T a, const T b)
Returns the maximum of two values.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
uint16 w
The width of the area.
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
StationSettings station
settings related to station management
GoodsEntry goods[NUM_CARGO]
Goods at this station.
void MarkDirty(ZoomLevel maxzoom=ZOOM_LVL_MAX) const
Mark the sign dirty in all viewports.
StationList stations_near
NOSAVE: List of nearby stations.
Functions related to (drawing on) viewports.
Pseudo random number generator.
A connected component of a link graph.
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 bool IsCompatibleTrainStationTile(TileIndex test_tile, TileIndex station_tile)
Check if a tile is a valid continuation to a railstation tile.
Buses, trucks and trams belong to this class.
byte catchment
catchment area of this airport
Some methods of Pool are placed here in order to reduce compilation time and binary size...
uint Size() const
Get the current size of the component.
The tile has no ownership.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
static void AddIndustryToDeliver(Industry *ind, Station *st)
Add nearby industry to station's industries_near list if it accepts cargo.
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
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,.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
bool Succeeded() const
Did this command succeed?
~Station()
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats...
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
static const Date INVALID_DATE
Representation of an invalid date.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
A number of safeguards to prevent using unsafe methods.
StationList stations_near
NOSAVE: List of nearby stations.
Declaration of link graph schedule used for cargo distribution.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
struct RoadStop * next
Next stop of the given type at this station.
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
Represents the covered area of e.g.
static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
Get the catchment size of an individual station tile.
Road vehicle list; Window numbers:
StationSpecList * speclist
List of station specs of this station.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Station view; Window numbers:
StationRect - used to track station spread out rectangle - cheaper than scanning whole map...
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
Catchment for truck stops with "modified catchment" enabled.
Catchment for all stations with "modified catchment" disabled.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Base class for all pools.
Station list; Window numbers:
FlowStatMap flows
Planned flows through this station.
TileIndex tile
The base tile of the area.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Catchment for docks with "modified catchment" enabled.
Functions related to companies.
Catchment when the station has no facilities.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
bool IsBus() const
Check whether a roadvehicle is a bus.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
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...
void Build(It begin, It end)
Clear and rebuild the tree from a new sequence of elements,.
StationFacility
The facilities a station might be having.
Ships list; Window numbers:
uint32 TileIndex
The index/ID of a 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.
bool modified_catchment
different-size catchment areas
void Remove(const T &element)
Remove a single element from the tree, if it exists.
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Catchment for train stations with "modified catchment" enabled.
Trains list; Window numbers:
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Aircraft list; Window numbers:
Station * neutral_station
Associated neutral station.
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Functions related to commands.
A Stop for a Road Vehicle.
CompanyID _current_company
Company currently doing an action.
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
Owner owner
The owner of this station.
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. ...
Declaration of link graph classes used for cargo distribution.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
static Pool::IterateWrapper< Aircraft > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
K-dimensional tree, specialised for 2-dimensional space.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Airport airport
Tile area the airport covers.
static void PostDestructor(size_t index)
Invalidating of the JoinStation window has to be done after removing item from the pool...
DiagDirection
Enumeration for diagonal directions.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Specification of a rectangle with absolute coordinates of all edges.
byte CargoID
Cargo slots to indicate a cargo type within a game.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Functions related to news.
StationPool _station_pool("Station")
The pool of stations.
Base classes/functions for stations.
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
uint16 h
The height of the area.
void RemoveFromAllNearbyLists()
Remove this station from the nearby stations lists of all towns and industries.
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile...
Base class for all station-ish types.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Class defining several overloaded accessors so we don't have to cast base stations that often...
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-...