15 #include "viewport_kdtree.h"
30 #include "table/strings.h"
41 void RebuildStationKdtree()
43 std::vector<StationID> stids;
45 stids.push_back(st->index);
47 _station_kdtree.
Build(stids.begin(), stids.end());
51 BaseStation::~BaseStation()
70 time_since_unload(255),
87 ge.cargo.OnCleanPool();
92 while (!this->loading_vehicles.empty()) {
93 this->loading_vehicles.front()->LeaveStation();
97 if (!a->IsNormalAircraft())
continue;
98 if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
103 if (lg ==
nullptr)
continue;
105 for (NodeID node = 0; node < lg->
Size(); ++node) {
114 if (lg->
Size() == 0) {
122 if (v->last_station_visited == this->index) {
123 v->last_station_visited = INVALID_STATION;
125 if (v->last_loading_station == this->index) {
126 v->last_loading_station = INVALID_STATION;
171 bool BaseStation::SetRoadStopTileData(
TileIndex tile, uint8_t data,
bool animation)
174 if (tile_data.tile == tile) {
175 uint8_t &v = animation ? tile_data.animation_frame : tile_data.random_bits;
176 if (v == data)
return false;
182 tile_data.tile = tile;
183 tile_data.animation_frame = animation ? data : 0;
184 tile_data.random_bits = animation ? 0 : data;
185 this->custom_roadstop_tile_data.push_back(tile_data);
189 void BaseStation::RemoveRoadStopTileData(
TileIndex tile)
192 if (tile_data.tile == tile) {
193 tile_data = this->custom_roadstop_tile_data.back();
194 this->custom_roadstop_tile_data.pop_back();
209 for (; rs !=
nullptr; rs = rs->
next) {
316 case STATION_TRUCK:
return CA_TRUCK;
317 case STATION_BUS:
return CA_BUS;
318 case STATION_DOCK:
return CA_DOCK;
320 default: NOT_REACHED();
322 case STATION_WAYPOINT:
323 case STATION_ROADWAYPOINT:
return CA_NONE;
329 case STATION_WAYPOINT:
330 case STATION_ROADWAYPOINT:
return CA_NONE;
364 assert(!this->
rect.IsEmpty());
370 std::max<int>(this->
rect.left - catchment_radius, 0),
371 std::max<int>(this->
rect.top - catchment_radius, 0),
372 std::min<int>(this->
rect.right + catchment_radius,
Map::MaxX()),
373 std::min<int>(this->
rect.bottom + catchment_radius,
Map::MaxY())
391 auto pos = std::find_if(this->
industries_near.begin(), this->industries_near.end(), [&](
const IndustryListEntry &e) { return e.industry->index == ind->index; });
393 if (pos->distance > distance) {
395 node.value().distance = distance;
413 auto pos = std::find_if(this->
industries_near.begin(), this->industries_near.end(), [&](
const IndustryListEntry &e) { return e.industry->index == ind->index; });
425 std::set<TownID> towns;
426 std::set<IndustryID> industries;
437 for (
const TownID &townid : towns) {
Town::Get(townid)->stations_near.erase(
this); }
438 for (
const IndustryID &industryid : industries) {
Industry::Get(industryid)->stations_near.erase(
this); }
467 if (this->
rect.IsEmpty()) {
509 Town *t = Town::GetByTile(tile);
541 StationRect::StationRect()
546 void StationRect::MakeEmpty()
548 this->left = this->top = this->right = this->bottom = 0;
562 return this->left - distance <= x && x <= this->right + distance &&
563 this->top - distance <= y && y <= this->bottom + distance;
566 bool StationRect::IsEmpty()
const
568 return this->left == 0 || this->left > this->right || this->top > this->bottom;
575 if (this->IsEmpty()) {
577 if (mode != ADD_TEST) {
578 this->left = this->right = x;
579 this->top = this->bottom = y;
584 Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
587 int w = new_rect.
Width();
588 int h = new_rect.
Height();
590 assert(mode != ADD_TRY);
595 if (mode != ADD_TEST) {
645 bool left_edge = (x == this->left);
646 bool right_edge = (x == this->right);
647 bool top_edge = (y == this->top);
648 bool bottom_edge = (y == this->bottom);
653 if (!(reduce_x || reduce_y))
break;
659 this->left = x = x + 1;
662 this->right = x = x - 1;
669 this->top = y = y + 1;
672 this->bottom = y = y - 1;
676 if (left > right || top > bottom) {
690 bool empty = this->AfterRemoveTile(st, ta.
tile);
691 if (ta.
w != 1 || ta.
h != 1) empty = empty || this->AfterRemoveTile(st,
TileAddXY(ta.
tile, ta.
w - 1, ta.
h - 1));
697 this->left = src.left;
699 this->right = src.right;
700 this->bottom = src.bottom;
711 Money total_cost = 0;
715 total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
719 return total_cost >> 3;
722 bool StationCompare::operator() (
const Station *lhs,
const Station *rhs)
const
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
void SetTile(TileIndex tile)
Add a tile as part of the tile area.
void Initialize(const Rect &r)
Initialize the BitmapTileArea with the specified Rect.
void Reset()
Reset and clear the BitmapTileArea.
Iterator to iterate over all tiles belonging to a bitmaptilearea.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
K-dimensional tree, specialised for 2-dimensional space.
void Build(It begin, It end)
Clear and rebuild the tree from a new sequence of elements,.
void Remove(const T &element)
Remove a single element from the tree, if it exists.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
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
Representation of an invalid date.
Functions related to commands.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
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.
Owner
Enum for all companies/owners.
@ OWNER_NONE
The tile has no ownership.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_END
Used for iterations.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
void MarkDirty(ZoomLevel maxzoom=ZOOM_LVL_MAX) const
Mark the sign dirty in all viewports.
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 TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
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.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
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, CargoID c, 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.
@ ROADSTOP_BUS
A standard stop for buses.
@ ROADSTOP_TRUCK
A standard stop for trucks.
StationFacility
The facilities a station might be having.
@ FACIL_AIRPORT
Station with an airport.
@ FACIL_NONE
The station has no facilities at all.
static constexpr uint CA_NONE
Catchment when the station has no facilities.
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
PersistentStorage * psa
Persistent storage for NewGRF airports.
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Base class for all station-ish types.
StationFacility facilities
The facilities that this station has.
TileIndex xy
Base tile of the station.
std::vector< SpecMapping< StationSpec > > speclist
List of rail station specs of this station.
TileArea train_station
Tile area the train 'station' part covers.
Owner owner
The owner of this station.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
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.
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
StationSettings station
settings related to station management
Stores station stats for a single cargo.
FlowStatMap flows
Planned flows through this station.
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.
TileArea location
Location of the industry.
Station * neutral_station
Associated neutral station.
StationList stations_near
NOSAVE: List of nearby stations.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Represents the covered area of e.g.
uint16_t w
The width of the area.
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.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Base class for all pools.
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
int Height() const
Get height of Rect.
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)
Returns an iterable ensemble of all valid stations of type T.
static Station * Get(size_t index)
Gets station with given index.
static Pool::IterateWrapper< Aircraft > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
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.
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.
uint8_t station_spread
amount a station may spread
bool modified_catchment
different-size catchment areas
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
~Station()
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile.
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,.
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
GoodsEntry goods[NUM_CARGO]
Goods at this station.
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.
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.
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
The information about a vehicle list.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
TileType
The different types of tiles.
@ MP_STATION
A tile of a station.
@ MP_HOUSE
A house by a town.
@ MP_INDUSTRY
Part of an industry.
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.
@ VEH_INVALID
Non-existing type of vehicle.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
Functions and type for generating vehicle lists.
Functions related to (drawing on) 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...
@ WC_STATION_LIST
Station list; Window numbers:
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ WC_STATION_VIEW
Station view; Window numbers:
@ WC_TRAINS_LIST
Trains list; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers: