|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
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 void BaseStation::SetRoadStopTileData(
TileIndex tile,
byte data,
bool animation)
174 if (tile_data.tile == tile) {
176 tile_data.animation_frame = data;
178 tile_data.random_bits = data;
184 tile_data.tile = tile;
185 tile_data.animation_frame = animation ? data : 0;
186 tile_data.random_bits = animation ? 0 : data;
187 this->custom_roadstop_tile_data.push_back(tile_data);
190 void BaseStation::RemoveRoadStopTileData(
TileIndex tile)
193 if (tile_data.tile == tile) {
194 tile_data = this->custom_roadstop_tile_data.back();
195 this->custom_roadstop_tile_data.pop_back();
210 for (; rs !=
nullptr; rs = rs->
next) {
323 case STATION_TRUCK:
return CA_TRUCK;
324 case STATION_BUS:
return CA_BUS;
325 case STATION_DOCK:
return CA_DOCK;
327 default: NOT_REACHED();
329 case STATION_WAYPOINT:
return CA_NONE;
335 case STATION_WAYPOINT:
return CA_NONE;
369 assert(!this->
rect.IsEmpty());
375 std::max<int>(this->
rect.left - catchment_radius, 0),
376 std::max<int>(this->
rect.top - catchment_radius, 0),
377 std::min<int>(this->
rect.right + catchment_radius,
Map::MaxX()),
378 std::min<int>(this->
rect.bottom + catchment_radius,
Map::MaxY())
396 auto pos = std::find_if(this->
industries_near.begin(), this->industries_near.end(), [&](
const IndustryListEntry &e) { return e.industry->index == ind->index; });
398 if (pos->distance > distance) {
400 node.value().distance = distance;
418 auto pos = std::find_if(this->
industries_near.begin(), this->industries_near.end(), [&](
const IndustryListEntry &e) { return e.industry->index == ind->index; });
460 if (this->
rect.IsEmpty()) {
502 Town *t = Town::GetByTile(tile);
534 StationRect::StationRect()
539 void StationRect::MakeEmpty()
541 this->left = this->top = this->right = this->bottom = 0;
555 return this->left - distance <= x && x <= this->right + distance &&
556 this->top - distance <= y && y <= this->bottom + distance;
559 bool StationRect::IsEmpty()
const
561 return this->left == 0 || this->left > this->right || this->top > this->bottom;
568 if (this->IsEmpty()) {
570 if (mode != ADD_TEST) {
571 this->left = this->right = x;
572 this->top = this->bottom = y;
577 Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
580 int w = new_rect.
Width();
581 int h = new_rect.
Height();
583 assert(mode != ADD_TRY);
588 if (mode != ADD_TEST) {
638 bool left_edge = (x == this->left);
639 bool right_edge = (x == this->right);
640 bool top_edge = (y == this->top);
641 bool bottom_edge = (y == this->bottom);
646 if (!(reduce_x || reduce_y))
break;
652 this->left = x = x + 1;
655 this->right = x = x - 1;
662 this->top = y = y + 1;
665 this->bottom = y = y - 1;
669 if (left > right || top > bottom) {
683 bool empty = this->AfterRemoveTile(st, ta.
tile);
684 if (ta.
w != 1 || ta.
h != 1) empty = empty || this->AfterRemoveTile(st,
TILE_ADDXY(ta.
tile, ta.
w - 1, ta.
h - 1));
690 this->left = src.left;
692 this->right = src.right;
693 this->bottom = src.bottom;
704 Money total_cost = 0;
708 total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
712 return total_cost >> 3;
715 bool StationCompare::operator() (
const Station *lhs,
const Station *rhs)
const
@ VEH_AIRCRAFT
Aircraft vehicle type.
Buses, trucks and trams belong to this class.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
@ 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.
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
int Height() const
Get height of Rect.
StationSettings station
settings related to station management
void Initialize(const Rect &r)
Initialize the BitmapTileArea with the specified Rect.
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.
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
TileIndex xy
Position on the map.
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...
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
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.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
void MoveSign(TileIndex new_xy) override
Move the station main coordinate somewhere else.
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?
@ 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 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.
void RecomputeCatchment(bool no_clear_nearby_lists=false)
Recompute tiles covered in our catchment area.
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
uint16_t h
The height of the area.
Station * neutral_station
Associated neutral station.
bool Succeeded() const
Did this command succeed?
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.
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.
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
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.
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.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
void Reset()
Reset and clear the BitmapTileArea.
StationList stations_near
NOSAVE: List of nearby stations.
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.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
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.
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
@ 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.
int32_t TileIndexDiff
An offset value between two tiles.
byte CargoID
Cargo slots to indicate a cargo type within a game.
DiagDirection
Enumeration for diagonal directions.
@ WC_TRAINS_LIST
Trains list; Window numbers:
byte station_spread
amount a station may spread
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.
StationType GetStationType(Tile t)
Get the station type of this tile.
StationFacility
The facilities a station might be having.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
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,.
Stores station stats for a single 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.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Base class for all pools.
FlowStatMap flows
Planned flows through this station.
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
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 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.
@ MP_STATION
A tile of a station.
static constexpr TimerGame< struct Economy >::Date INVALID_DATE
Representation of an invalid date.
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.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
uint16_t random_bits
Random bits assigned to this station.
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
uint16_t w
The width of the area.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
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.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
@ CA_TRAIN
Catchment for train stations with "modified catchment" enabled.
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.
static Date date
Current date in days (day counter).
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
@ VEH_TRAIN
Train vehicle type.
A Stop for a Road Vehicle.
@ FACIL_AIRPORT
Station with an airport.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
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.
bool HasTileAnyRoadType(Tile t, RoadTypes rts)
Check if a tile has one of the specified road types.
@ VEH_SHIP
Ship vehicle type.
Specification of a rectangle with absolute coordinates of all edges.
std::vector< RoadStopTileData > custom_roadstop_tile_data
List of custom road stop tile data.
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
@ WC_STATION_LIST
Station list; Window numbers:
byte catchment
catchment area of this airport
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
TownID GetTownIndex(Tile t)
Get the index of which town this house/street is attached to.
TimerGameCalendar::Date build_date
Date of construction.