OpenTTD
station.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "stdafx.h"
13 #include "company_func.h"
14 #include "company_base.h"
15 #include "roadveh.h"
16 #include "viewport_func.h"
17 #include "date_func.h"
18 #include "command_func.h"
19 #include "news_func.h"
20 #include "aircraft.h"
21 #include "vehiclelist.h"
22 #include "core/pool_func.hpp"
23 #include "station_base.h"
24 #include "roadstop_base.h"
25 #include "industry.h"
26 #include "core/random_func.hpp"
27 #include "linkgraph/linkgraph.h"
29 
30 #include "table/strings.h"
31 
32 #include "safeguards.h"
33 
35 StationPool _station_pool("Station");
37 
38 BaseStation::~BaseStation()
39 {
40  free(this->name);
41  free(this->speclist);
42 
43  if (CleaningPool()) return;
44 
45  DeleteWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).Pack());
46  DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).Pack());
47  DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).Pack());
48  DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack());
49 
50  this->sign.MarkDirty();
51 }
52 
53 Station::Station(TileIndex tile) :
54  SpecializedStation<Station, false>(tile),
55  bus_station(INVALID_TILE, 0, 0),
56  truck_station(INVALID_TILE, 0, 0),
57  dock_tile(INVALID_TILE),
58  indtype(IT_INVALID),
59  time_since_load(255),
60  time_since_unload(255),
61  last_vehicle_type(VEH_INVALID)
62 {
63  /* this->random_bits is set in Station::AddFacility() */
64 }
65 
74 {
75  if (CleaningPool()) {
76  for (CargoID c = 0; c < NUM_CARGO; c++) {
77  this->goods[c].cargo.OnCleanPool();
78  }
79  return;
80  }
81 
82  while (!this->loading_vehicles.empty()) {
83  this->loading_vehicles.front()->LeaveStation();
84  }
85 
86  Aircraft *a;
87  FOR_ALL_AIRCRAFT(a) {
88  if (!a->IsNormalAircraft()) continue;
89  if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
90  }
91 
92  for (CargoID c = 0; c < NUM_CARGO; ++c) {
93  LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
94  if (lg == NULL) continue;
95 
96  for (NodeID node = 0; node < lg->Size(); ++node) {
97  Station *st = Station::Get((*lg)[node].Station());
98  st->goods[c].flows.erase(this->index);
99  if ((*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) {
100  st->goods[c].flows.DeleteFlows(this->index);
101  RerouteCargo(st, c, this->index, st->index);
102  }
103  }
104  lg->RemoveNode(this->goods[c].node);
105  if (lg->Size() == 0) {
107  delete lg;
108  }
109  }
110 
111  Vehicle *v;
112  FOR_ALL_VEHICLES(v) {
113  /* Forget about this station if this station is removed */
114  if (v->last_station_visited == this->index) {
115  v->last_station_visited = INVALID_STATION;
116  }
117  if (v->last_loading_station == this->index) {
118  v->last_loading_station = INVALID_STATION;
119  }
120  }
121 
122  /* Clear the persistent storage. */
123  delete this->airport.psa;
124 
125  if (this->owner == OWNER_NONE) {
126  /* Invalidate all in case of oil rigs. */
128  } else {
129  InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
130  }
131 
133 
134  /* Now delete all orders that go to the station */
135  RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);
136 
137  /* Remove all news items */
138  DeleteStationNews(this->index);
139 
140  for (CargoID c = 0; c < NUM_CARGO; c++) {
141  this->goods[c].cargo.Truncate();
142  }
143 
144  CargoPacket::InvalidateAllFrom(this->index);
145 }
146 
147 
153 void BaseStation::PostDestructor(size_t index)
154 {
156 }
157 
163 RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const
164 {
165  RoadStop *rs = this->GetPrimaryRoadStop(v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK);
166 
167  for (; rs != NULL; rs = rs->next) {
168  /* The vehicle cannot go to this roadstop (different roadtype) */
169  if ((GetRoadTypes(rs->xy) & v->compatible_roadtypes) == ROADTYPES_NONE) continue;
170  /* The vehicle is articulated and can therefore not go to a standard road stop. */
171  if (IsStandardRoadStopTile(rs->xy) && v->HasArticulatedPart()) continue;
172 
173  /* The vehicle can actually go to this road stop. So, return it! */
174  break;
175  }
176 
177  return rs;
178 }
179 
184 void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
185 {
186  if (this->facilities == FACIL_NONE) {
187  this->xy = facil_xy;
188  this->random_bits = Random();
189  }
190  this->facilities |= new_facility_bit;
191  this->owner = _current_company;
192  this->build_date = _date;
193 }
194 
200 void Station::MarkTilesDirty(bool cargo_change) const
201 {
202  TileIndex tile = this->train_station.tile;
203  int w, h;
204 
205  if (tile == INVALID_TILE) return;
206 
207  /* cargo_change is set if we're refreshing the tiles due to cargo moving
208  * around. */
209  if (cargo_change) {
210  /* Don't waste time updating if there are no custom station graphics
211  * that might change. Even if there are custom graphics, they might
212  * not change. Unfortunately we have no way of telling. */
213  if (this->num_specs == 0) return;
214  }
215 
216  for (h = 0; h < train_station.h; h++) {
217  for (w = 0; w < train_station.w; w++) {
218  if (this->TileBelongsToRailStation(tile)) {
219  MarkTileDirtyByTile(tile);
220  }
221  tile += TileDiffXY(1, 0);
222  }
223  tile += TileDiffXY(-w, 1);
224  }
225 }
226 
227 /* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
228 {
229  assert(this->TileBelongsToRailStation(tile));
230 
231  TileIndexDiff delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
232 
233  TileIndex t = tile;
234  uint len = 0;
235  do {
236  t -= delta;
237  len++;
238  } while (IsCompatibleTrainStationTile(t, tile));
239 
240  t = tile;
241  do {
242  t += delta;
243  len++;
244  } while (IsCompatibleTrainStationTile(t, tile));
245 
246  return len - 1;
247 }
248 
249 /* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
250 {
251  TileIndex start_tile = tile;
252  uint length = 0;
253  assert(IsRailStationTile(tile));
254  assert(dir < DIAGDIR_END);
255 
256  do {
257  length++;
258  tile += TileOffsByDiagDir(dir);
259  } while (IsCompatibleTrainStationTile(tile, start_tile));
260 
261  return length;
262 }
263 
269 {
270  uint ret = CA_NONE;
271 
273  if (this->bus_stops != NULL) ret = max<uint>(ret, CA_BUS);
274  if (this->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK);
275  if (this->train_station.tile != INVALID_TILE) ret = max<uint>(ret, CA_TRAIN);
276  if (this->dock_tile != INVALID_TILE) ret = max<uint>(ret, CA_DOCK);
277  if (this->airport.tile != INVALID_TILE) ret = max<uint>(ret, this->airport.GetSpec()->catchment);
278  } else {
279  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) {
280  ret = CA_UNMODIFIED;
281  }
282  }
283 
284  return ret;
285 }
286 
292 {
293  assert(!this->rect.IsEmpty());
294 
295  /* Compute acceptance rectangle */
296  int catchment_radius = this->GetCatchmentRadius();
297 
298  Rect ret = {
299  max<int>(this->rect.left - catchment_radius, 0),
300  max<int>(this->rect.top - catchment_radius, 0),
301  min<int>(this->rect.right + catchment_radius, MapMaxX()),
302  min<int>(this->rect.bottom + catchment_radius, MapMaxY())
303  };
304 
305  return ret;
306 }
307 
312 };
313 
322 static bool FindIndustryToDeliver(TileIndex ind_tile, void *user_data)
323 {
324  /* Only process industry tiles */
325  if (!IsTileType(ind_tile, MP_INDUSTRY)) return false;
326 
327  RectAndIndustryVector *riv = (RectAndIndustryVector *)user_data;
328  Industry *ind = Industry::GetByTile(ind_tile);
329 
330  /* Don't check further if this industry is already in the list */
331  if (riv->industries_near->Contains(ind)) return false;
332 
333  /* Only process tiles in the station acceptance rectangle */
334  int x = TileX(ind_tile);
335  int y = TileY(ind_tile);
336  if (x < riv->rect.left || x > riv->rect.right || y < riv->rect.top || y > riv->rect.bottom) return false;
337 
338  /* Include only industries that can accept cargo */
339  uint cargo_index;
340  for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
341  if (ind->accepts_cargo[cargo_index] != CT_INVALID) break;
342  }
343  if (cargo_index >= lengthof(ind->accepts_cargo)) return false;
344 
345  *riv->industries_near->Append() = ind;
346 
347  return false;
348 }
349 
355 {
356  this->industries_near.Clear();
357  if (this->rect.IsEmpty()) return;
358 
359  RectAndIndustryVector riv = {
360  this->GetCatchmentRect(),
361  &this->industries_near
362  };
363 
364  /* Compute maximum extent of acceptance rectangle wrt. station sign */
365  TileIndex start_tile = this->xy;
366  uint max_radius = max(
367  max(DistanceManhattan(start_tile, TileXY(riv.rect.left, riv.rect.top)), DistanceManhattan(start_tile, TileXY(riv.rect.left, riv.rect.bottom))),
368  max(DistanceManhattan(start_tile, TileXY(riv.rect.right, riv.rect.top)), DistanceManhattan(start_tile, TileXY(riv.rect.right, riv.rect.bottom)))
369  );
370 
371  CircularTileSearch(&start_tile, 2 * max_radius + 1, &FindIndustryToDeliver, &riv);
372 }
373 
378 {
379  Station *st;
380  FOR_ALL_STATIONS(st) st->RecomputeIndustriesNear();
381 }
382 
383 /************************************************************************/
384 /* StationRect implementation */
385 /************************************************************************/
386 
387 StationRect::StationRect()
388 {
389  this->MakeEmpty();
390 }
391 
392 void StationRect::MakeEmpty()
393 {
394  this->left = this->top = this->right = this->bottom = 0;
395 }
396 
406 bool StationRect::PtInExtendedRect(int x, int y, int distance) const
407 {
408  return this->left - distance <= x && x <= this->right + distance &&
409  this->top - distance <= y && y <= this->bottom + distance;
410 }
411 
412 bool StationRect::IsEmpty() const
413 {
414  return this->left == 0 || this->left > this->right || this->top > this->bottom;
415 }
416 
417 CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
418 {
419  int x = TileX(tile);
420  int y = TileY(tile);
421  if (this->IsEmpty()) {
422  /* we are adding the first station tile */
423  if (mode != ADD_TEST) {
424  this->left = this->right = x;
425  this->top = this->bottom = y;
426  }
427  } else if (!this->PtInExtendedRect(x, y)) {
428  /* current rect is not empty and new point is outside this rect
429  * make new spread-out rectangle */
430  Rect new_rect = {min(x, this->left), min(y, this->top), max(x, this->right), max(y, this->bottom)};
431 
432  /* check new rect dimensions against preset max */
433  int w = new_rect.right - new_rect.left + 1;
434  int h = new_rect.bottom - new_rect.top + 1;
435  if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
436  assert(mode != ADD_TRY);
437  return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
438  }
439 
440  /* spread-out ok, return true */
441  if (mode != ADD_TEST) {
442  /* we should update the station rect */
443  *this = new_rect;
444  }
445  } else {
446  ; // new point is inside the rect, we don't need to do anything
447  }
448  return CommandCost();
449 }
450 
451 CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
452 {
453  if (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) {
454  /* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
455  CommandCost ret = this->BeforeAddTile(tile, mode);
456  if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
457  return ret;
458  }
459  return CommandCost();
460 }
461 
471 /* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
472 {
473  TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
474  TILE_AREA_LOOP(tile, ta) {
475  if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
476  }
477 
478  return false;
479 }
480 
481 bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
482 {
483  int x = TileX(tile);
484  int y = TileY(tile);
485 
486  /* look if removed tile was on the bounding rect edge
487  * and try to reduce the rect by this edge
488  * do it until we have empty rect or nothing to do */
489  for (;;) {
490  /* check if removed tile is on rect edge */
491  bool left_edge = (x == this->left);
492  bool right_edge = (x == this->right);
493  bool top_edge = (y == this->top);
494  bool bottom_edge = (y == this->bottom);
495 
496  /* can we reduce the rect in either direction? */
497  bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, this->top, x, this->bottom));
498  bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->index, this->left, y, this->right, y));
499  if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce)
500 
501  if (reduce_x) {
502  /* reduce horizontally */
503  if (left_edge) {
504  /* move left edge right */
505  this->left = x = x + 1;
506  } else {
507  /* move right edge left */
508  this->right = x = x - 1;
509  }
510  }
511  if (reduce_y) {
512  /* reduce vertically */
513  if (top_edge) {
514  /* move top edge down */
515  this->top = y = y + 1;
516  } else {
517  /* move bottom edge up */
518  this->bottom = y = y - 1;
519  }
520  }
521 
522  if (left > right || top > bottom) {
523  /* can't continue, if the remaining rectangle is empty */
524  this->MakeEmpty();
525  return true; // empty remaining rect
526  }
527  }
528  return false; // non-empty remaining rect
529 }
530 
531 bool StationRect::AfterRemoveRect(BaseStation *st, TileArea ta)
532 {
533  assert(this->PtInExtendedRect(TileX(ta.tile), TileY(ta.tile)));
534  assert(this->PtInExtendedRect(TileX(ta.tile) + ta.w - 1, TileY(ta.tile) + ta.h - 1));
535 
536  bool empty = this->AfterRemoveTile(st, ta.tile);
537  if (ta.w != 1 || ta.h != 1) empty = empty || this->AfterRemoveTile(st, TILE_ADDXY(ta.tile, ta.w - 1, ta.h - 1));
538  return empty;
539 }
540 
541 StationRect& StationRect::operator = (const Rect &src)
542 {
543  this->left = src.left;
544  this->top = src.top;
545  this->right = src.right;
546  this->bottom = src.bottom;
547  return *this;
548 }
549 
556 {
557  Money total_cost = 0;
558 
559  const Station *st;
560  FOR_ALL_STATIONS(st) {
561  if (st->owner == owner && (st->facilities & FACIL_AIRPORT)) {
562  total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
563  }
564  }
565  /* 3 bits fraction for the maintenance cost factor. */
566  return total_cost >> 3;
567 }
Road vehicle states.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
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.
Definition: pool_type.hpp:257
Rect and pointer to IndustryVector.
Definition: station.cpp:309
Select station (when joining stations); Window numbers:
Definition: window_type.h:237
A standard stop for trucks.
Definition: station_type.h:48
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
Definition: station.cpp:291
The information about a vehicle list.
Definition: vehiclelist.h:31
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition: station_base.h:320
StationID targetairport
Airport to go to next.
Definition: aircraft.h:80
Base class for roadstops.
Non-existing type of vehicle.
Definition: vehicle_type.h:37
Part of an industry.
Definition: tile_type.h:51
Functions and type for generating vehicle lists.
int32 TileIndexDiff
An offset value between to tiles.
Definition: map_func.h:156
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Functions related to dates.
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
TileIndex xy
Position on the map.
Definition: roadstop_base.h:69
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
Definition: vehicle_base.h:303
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:76
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
A standard stop for buses.
Definition: station_type.h:47
Vehicle data structure.
Definition: vehicle_base.h:212
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.
Definition: industry.h:41
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
StationFacility
The facilities a station might be having.
Definition: station_type.h:52
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no &#39;unknown station now accepts Mail&#39; or &#39;First trai...
Definition: news_gui.cpp:821
Base for aircraft.
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:302
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
Definition: station.cpp:200
Common return value for all commands.
Definition: command_type.h:25
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:224
Catchment for bus stops with "modified catchment" enabled.
Definition: station_type.h:81
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
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.
Definition: tilearea_type.h:20
bool IsNormalAircraft() const
Check if the aircraft type is a normal flying device; eg not a rotor or a shadow. ...
Definition: aircraft.h:123
StationSettings station
settings related to station management
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:472
void MarkDirty(ZoomLevel maxzoom=ZOOM_LVL_MAX) const
Mark the sign dirty in all viewports.
Definition: viewport.cpp:1307
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.
Definition: linkgraph.h:40
Invalid cargo type.
Definition: cargo_type.h:70
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...
Definition: window.cpp:3319
static bool IsCompatibleTrainStationTile(TileIndex test_tile, TileIndex station_tile)
Check if a tile is a valid continuation to a railstation tile.
Definition: station_map.h:379
Buses, trucks and trams belong to this class.
Definition: roadveh.h:88
ViewportSign sign
NOSAVE: Dimensions of sign.
Aircraft vehicle type.
Definition: vehicle_type.h:29
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.
Definition: linkgraph.h:499
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:343
IndustryVector * industries_near
The nearby industries.
Definition: station.cpp:311
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
Definition: station_map.h:103
bool Contains(const T &item) const
Tests whether a item is present in the vector.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Definition: station.cpp:555
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:152
~Station()
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats...
Definition: station.cpp:73
#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.
Definition: date_type.h:110
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:260
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.
Definition: map.cpp:260
Declaration of link graph schedule used for cargo distribution.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:338
struct RoadStop * next
Next stop of the given type at this station.
Definition: roadstop_base.h:71
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
Definition: station.cpp:268
Used for iterations.
Represents the covered area of e.g.
Definition: tilearea_type.h:18
void RecomputeIndustriesNear()
Recomputes Station::industries_near, list of industries possibly accepting cargo in station&#39;s catchme...
Definition: station.cpp:354
Road vehicle list; Window numbers:
Definition: window_type.h:309
StationSpecList * speclist
List of station specs of this station.
The tile has no ownership.
Definition: company_type.h:27
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:901
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1785
Station view; Window numbers:
Definition: window_type.h:340
StationRect - used to track station spread out rectangle - cheaper than scanning whole map...
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
Definition: industry.h:49
StationFacilityByte facilities
The facilities that this station has.
DiagDirection
Enumeration for diagonal directions.
Catchment for truck stops with "modified catchment" enabled.
Definition: station_type.h:82
Catchment for all stations with "modified catchment" disabled.
Definition: station_type.h:86
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
Road vehicle type.
Definition: vehicle_type.h:27
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
Definition: linkgraph.cpp:121
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:35
Base class for all pools.
Definition: pool_type.hpp:83
Station list; Window numbers:
Definition: window_type.h:297
Ship vehicle type.
Definition: vehicle_type.h:28
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:259
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
OwnerByte owner
The owner of this station.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don&#39;t get linker errors.
Definition: pool_func.hpp:226
The X axis.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1146
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:225
Catchment for docks with "modified catchment" enabled.
Definition: station_type.h:84
Functions related to companies.
Catchment when the station has no facilities.
Definition: station_type.h:80
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:29
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:81
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...
Definition: station.cpp:406
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
Ships list; Window numbers:
Definition: window_type.h:315
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
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.
Definition: map_func.h:217
Catchment for train stations with "modified catchment" enabled.
Definition: station_type.h:83
Trains list; Window numbers:
Definition: window_type.h:303
A tile of a station.
Definition: tile_type.h:48
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:113
static void RecomputeIndustriesNearForAll()
Recomputes Station::industries_near for all stations.
Definition: station.cpp:377
Aircraft list; Window numbers:
Definition: window_type.h:321
static bool FindIndustryToDeliver(TileIndex ind_tile, void *user_data)
Callback function for Station::RecomputeIndustriesNear() Tests whether tile is an industry and possib...
Definition: station.cpp:322
Functions related to commands.
No roadtypes.
Definition: road_type.h:37
A Stop for a Road Vehicle.
Definition: roadstop_base.h:24
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
Definition: station.cpp:184
#define FOR_ALL_AIRCRAFT(var)
Macro for iterating over all aircraft.
Definition: aircraft.h:144
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. ...
Definition: station.cpp:471
Declaration of link graph classes used for cargo distribution.
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:181
Base of all industries.
static RoadTypes GetRoadTypes(TileIndex t)
Get the present road types of a tile.
Definition: road_map.h:166
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
Airport airport
Tile area the airport covers.
Definition: station_base.h:460
static void PostDestructor(size_t index)
Invalidating of the JoinStation window has to be done after removing item from the pool...
Definition: station.cpp:153
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
Definition: vehicle_base.h:987
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Rect rect
The rectangle to search the industries in.
Definition: station.cpp:310
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Definition: order_cmd.cpp:1840
Specification of a rectangle with absolute coordinates of all edges.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:104
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:112
Owner
Enum for all companies/owners.
Definition: company_type.h:20
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)
Definition: date.cpp:28
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const
Determines the REMAINING length of a platform, starting at (and including) the given tile...
Definition: station.cpp:249
char * name
Custom name.
uint16 h
The height of the area.
Definition: tilearea_type.h:21
Base class for all station-ish types.
Station data structure.
Definition: station_base.h:446
Station with an airport.
Definition: station_type.h:57
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:165
The station has no facilities at all.
Definition: station_type.h:53
Class defining several overloaded accessors so we don&#39;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-...
Definition: window.cpp:3301
Train vehicle type.
Definition: vehicle_type.h:26