30 #include "table/strings.h" 41 BaseStation::~BaseStation()
63 time_since_unload(255),
80 this->goods[c].cargo.OnCleanPool();
85 while (!this->loading_vehicles.empty()) {
86 this->loading_vehicles.front()->LeaveStation();
97 if (lg == NULL)
continue;
99 for (NodeID node = 0; node < lg->
Size(); ++node) {
102 if ((*lg)[node][this->goods[c].node].LastUpdate() !=
INVALID_DATE) {
108 if (lg->
Size() == 0) {
126 delete this->airport.psa;
144 this->goods[c].cargo.Truncate();
170 for (; rs != NULL; rs = rs->
next) {
191 this->random_bits = Random();
193 this->facilities |= new_facility_bit;
195 this->build_date =
_date;
205 TileIndex tile = this->train_station.tile;
216 if (this->num_specs == 0)
return;
219 for (h = 0; h < train_station.h; h++) {
220 for (w = 0; w < train_station.w; w++) {
221 if (this->TileBelongsToRailStation(tile)) {
232 assert(this->TileBelongsToRailStation(tile));
276 if (this->bus_stops != NULL) ret = max<uint>(ret,
CA_BUS);
277 if (this->truck_stops != NULL) ret = max<uint>(ret,
CA_TRUCK);
280 if (this->airport.tile !=
INVALID_TILE) ret = max<uint>(ret, this->airport.GetSpec()->catchment);
282 if (this->bus_stops != NULL || this->truck_stops != NULL || this->train_station.tile !=
INVALID_TILE || this->dock_tile !=
INVALID_TILE || this->airport.tile !=
INVALID_TILE) {
296 assert(!this->rect.IsEmpty());
299 int catchment_radius = this->GetCatchmentRadius();
302 max<int>(this->rect.left - catchment_radius, 0),
303 max<int>(this->rect.top - catchment_radius, 0),
304 min<int>(this->rect.right + catchment_radius,
MapMaxX()),
305 min<int>(this->rect.bottom + catchment_radius,
MapMaxY())
337 int x =
TileX(ind_tile);
338 int y =
TileY(ind_tile);
339 if (x < riv->rect.left || x > riv->
rect.right || y < riv->rect.top || y > riv->
rect.bottom)
return false;
359 this->industries_near.Clear();
360 if (this->rect.IsEmpty())
return;
363 this->GetCatchmentRect(),
364 &this->industries_near
369 uint max_radius =
max(
390 StationRect::StationRect()
395 void StationRect::MakeEmpty()
397 this->left = this->top = this->right = this->bottom = 0;
411 return this->left - distance <= x && x <= this->right + distance &&
412 this->top - distance <= y && y <= this->bottom + distance;
415 bool StationRect::IsEmpty()
const 417 return this->left == 0 || this->left > this->right || this->top > this->bottom;
424 if (this->IsEmpty()) {
426 if (mode != ADD_TEST) {
427 this->left = this->right = x;
428 this->top = this->bottom = y;
430 }
else if (!this->PtInExtendedRect(x, y)) {
433 Rect new_rect = {
min(x, this->left),
min(y, this->top),
max(x, this->right),
max(y, this->bottom)};
436 int w = new_rect.right - new_rect.left + 1;
437 int h = new_rect.bottom - new_rect.top + 1;
439 assert(mode != ADD_TRY);
444 if (mode != ADD_TEST) {
494 bool left_edge = (x == this->left);
495 bool right_edge = (x == this->right);
496 bool top_edge = (y == this->top);
497 bool bottom_edge = (y == this->bottom);
500 bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->
index, x, this->top, x, this->bottom));
501 bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->
index, this->left, y, this->right, y));
502 if (!(reduce_x || reduce_y))
break;
508 this->left = x = x + 1;
511 this->right = x = x - 1;
518 this->top = y = y + 1;
521 this->bottom = y = y - 1;
525 if (left > right || top > bottom) {
539 bool empty = this->AfterRemoveTile(st, ta.
tile);
540 if (ta.
w != 1 || ta.
h != 1) empty = empty || this->AfterRemoveTile(st,
TILE_ADDXY(ta.
tile, ta.
w - 1, ta.
h - 1));
546 this->left = src.left;
548 this->right = src.right;
549 this->bottom = src.bottom;
560 Money total_cost = 0;
563 FOR_ALL_STATIONS(st) {
569 return total_cost >> 3;
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.
Rect and pointer to IndustryVector.
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.
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.
Non-existing type of vehicle.
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.
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...
Aircraft, helicopters, rotors and their shadows belong to this class.
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.
StationFacility
The facilities a station might be having.
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
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. ...
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
T * Append(uint to_add=1)
Append an item and return it.
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.
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.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
IndustryVector * industries_near
The nearby industries.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
bool Contains(const T &item) const
Tests whether a item is present in the vector.
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination)
Removes an order from all vehicles.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
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...
A simplified pool which stores values instead of pointers and doesn't redefine operator new/delete...
#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.
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
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.
CargoID accepts_cargo[3]
3 input cargo slots
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
Represents the covered area of e.g.
void RecomputeIndustriesNear()
Recomputes Station::industries_near, list of industries possibly accepting cargo in station's catchme...
Road vehicle list; Window numbers:
StationSpecList * speclist
List of station specs of this station.
The tile has no ownership.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Station view; Window numbers:
StationRect - used to track station spread out rectangle - cheaper than scanning whole map...
StationFacilityByte facilities
The facilities that this station has.
DiagDirection
Enumeration for diagonal directions.
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.
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.
Maximal number of cargo types in a game.
TileIndex tile
The base tile of the area.
OwnerByte owner
The owner of this station.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
#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...
CompanyByte _current_company
Company currently doing an action.
Ships list; Window numbers:
uint32 TileIndex
The index/ID of a Tile.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
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
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.
static void RecomputeIndustriesNearForAll()
Recomputes Station::industries_near for all stations.
Aircraft list; Window numbers:
static bool FindIndustryToDeliver(TileIndex ind_tile, void *user_data)
Callback function for Station::RecomputeIndustriesNear() Tests whether tile is an industry and possib...
Functions related to commands.
A Stop for a Road Vehicle.
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
#define FOR_ALL_AIRCRAFT(var)
Macro for iterating over all aircrafts.
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 RoadTypes GetRoadTypes(TileIndex t)
Get the present road types of a tile.
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...
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Rect rect
The rectangle to search the industries in.
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.
Owner
Enum for all companies/owners.
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)
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const
Determines the REMAINING length of a platform, starting at (and including) the given tile...
uint16 h
The height of the area.
Base class for all station-ish types.
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
The station has no facilities at all.
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-...