17 #include "viewport_kdtree.h" 33 #include "table/strings.h" 44 void RebuildStationKdtree()
46 std::vector<StationID> stids;
48 FOR_ALL_STATIONS(st) {
49 stids.push_back(st->
index);
51 _station_kdtree.
Build(stids.begin(), stids.end());
55 BaseStation::~BaseStation()
77 time_since_unload(255),
94 this->goods[c].cargo.OnCleanPool();
99 while (!this->loading_vehicles.empty()) {
100 this->loading_vehicles.front()->LeaveStation();
111 if (lg ==
nullptr)
continue;
113 for (NodeID node = 0; node < lg->
Size(); ++node) {
116 if ((*lg)[node][this->goods[c].node].LastUpdate() !=
INVALID_DATE) {
122 if (lg->
Size() == 0) {
140 this->RemoveFromAllNearbyLists();
143 delete this->airport.psa;
161 this->goods[c].cargo.Truncate();
166 _station_kdtree.
Remove(this->index);
167 _viewport_sign_kdtree.
Remove(ViewportSignKdtreeItem::MakeStation(this->index));
190 for (; rs !=
nullptr; rs = rs->
next) {
210 this->MoveSign(facil_xy);
211 this->random_bits = Random();
213 this->facilities |= new_facility_bit;
215 this->build_date =
_date;
225 TileIndex tile = this->train_station.tile;
236 if (this->num_specs == 0)
return;
239 for (h = 0; h < train_station.h; h++) {
240 for (w = 0; w < train_station.w; w++) {
241 if (this->TileBelongsToRailStation(tile)) {
252 assert(this->TileBelongsToRailStation(tile));
303 case STATION_TRUCK:
return CA_TRUCK;
304 case STATION_BUS:
return CA_BUS;
305 case STATION_DOCK:
return CA_DOCK;
307 default: NOT_REACHED();
309 case STATION_WAYPOINT:
return CA_NONE;
315 case STATION_WAYPOINT:
return CA_NONE;
329 if (this->bus_stops !=
nullptr) ret = max<uint>(ret,
CA_BUS);
330 if (this->truck_stops !=
nullptr) ret = max<uint>(ret,
CA_TRUCK);
333 if (this->airport.tile !=
INVALID_TILE) ret = max<uint>(ret, this->airport.GetSpec()->catchment);
335 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) {
349 assert(!this->rect.IsEmpty());
352 int catchment_radius = this->GetCatchmentRadius();
355 max<int>(this->rect.left - catchment_radius, 0),
356 max<int>(this->rect.top - catchment_radius, 0),
357 min<int>(this->rect.right + catchment_radius,
MapMaxX()),
358 min<int>(this->rect.bottom + catchment_radius,
MapMaxY())
417 this->industries_near.clear();
418 this->RemoveFromAllNearbyLists();
420 if (this->rect.IsEmpty()) {
421 this->catchment_tiles.Reset();
427 this->catchment_tiles.Initialize(this->industry->location);
430 this->catchment_tiles.SetTile(tile);
434 for (
Station *st : this->industry->stations_near) {
437 this->industry->stations_near.clear();
438 this->industry->stations_near.insert(
this);
439 this->industries_near.insert(this->industry);
443 this->catchment_tiles.Initialize(GetCatchmentRect());
446 TileArea ta(
TileXY(this->rect.left, this->rect.top),
TileXY(this->rect.right, this->rect.bottom));
462 Town *t = Town::GetByTile(tile);
493 StationRect::StationRect()
498 void StationRect::MakeEmpty()
500 this->left = this->top = this->right = this->bottom = 0;
514 return this->left - distance <= x && x <= this->right + distance &&
515 this->top - distance <= y && y <= this->bottom + distance;
518 bool StationRect::IsEmpty()
const 520 return this->left == 0 || this->left > this->right || this->top > this->bottom;
527 if (this->IsEmpty()) {
529 if (mode != ADD_TEST) {
530 this->left = this->right = x;
531 this->top = this->bottom = y;
533 }
else if (!this->PtInExtendedRect(x, y)) {
536 Rect new_rect = {
min(x, this->left),
min(y, this->top),
max(x, this->right),
max(y, this->bottom)};
539 int w = new_rect.right - new_rect.left + 1;
540 int h = new_rect.bottom - new_rect.top + 1;
542 assert(mode != ADD_TRY);
547 if (mode != ADD_TEST) {
597 bool left_edge = (x == this->left);
598 bool right_edge = (x == this->right);
599 bool top_edge = (y == this->top);
600 bool bottom_edge = (y == this->bottom);
603 bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->
index, x, this->top, x, this->bottom));
604 bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->
index, this->left, y, this->right, y));
605 if (!(reduce_x || reduce_y))
break;
611 this->left = x = x + 1;
614 this->right = x = x - 1;
621 this->top = y = y + 1;
624 this->bottom = y = y - 1;
628 if (left > right || top > bottom) {
642 bool empty = this->AfterRemoveTile(st, ta.
tile);
643 if (ta.
w != 1 || ta.
h != 1) empty = empty || this->AfterRemoveTile(st,
TILE_ADDXY(ta.
tile, ta.
w - 1, ta.
h - 1));
649 this->left = src.left;
651 this->right = src.right;
652 this->bottom = src.bottom;
663 Money total_cost = 0;
666 FOR_ALL_STATIONS(st) {
672 return total_cost >> 3;
675 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.
StationID targetairport
Airport to go to next.
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.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
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.
StationID last_station_visited
The last station we stopped at.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
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.
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow. ...
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.
uint16 maintenance_cost
maintenance cost multiplier
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.
ViewportSign sign
NOSAVE: Dimensions of sign.
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.
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.
#define FOR_ALL_AIRCRAFT(var)
Macro for iterating over all aircraft.
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).
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.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
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.
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-...