OpenTTD
station.cpp
Go to the documentation of this file.
1 /* $Id: station.cpp 27178 2015-03-07 18:27:01Z frosch $ */
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 
39 template<> StationIDStackPool StationIDStack::_pool = StationIDStackPool();
40 
41 BaseStation::~BaseStation()
42 {
43  free(this->name);
44  free(this->speclist);
45 
46  if (CleaningPool()) return;
47 
48  DeleteWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).Pack());
49  DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).Pack());
50  DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).Pack());
51  DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack());
52 
53  this->sign.MarkDirty();
54 }
55 
56 Station::Station(TileIndex tile) :
57  SpecializedStation<Station, false>(tile),
58  bus_station(INVALID_TILE, 0, 0),
59  truck_station(INVALID_TILE, 0, 0),
60  dock_tile(INVALID_TILE),
61  indtype(IT_INVALID),
62  time_since_load(255),
63  time_since_unload(255),
64  last_vehicle_type(VEH_INVALID)
65 {
66  /* this->random_bits is set in Station::AddFacility() */
67 }
68 
77 {
78  if (CleaningPool()) {
79  for (CargoID c = 0; c < NUM_CARGO; c++) {
80  this->goods[c].cargo.OnCleanPool();
81  }
82  return;
83  }
84 
85  while (!this->loading_vehicles.empty()) {
86  this->loading_vehicles.front()->LeaveStation();
87  }
88 
89  Aircraft *a;
90  FOR_ALL_AIRCRAFT(a) {
91  if (!a->IsNormalAircraft()) continue;
92  if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
93  }
94 
95  for (CargoID c = 0; c < NUM_CARGO; ++c) {
96  LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
97  if (lg == NULL) continue;
98 
99  for (NodeID node = 0; node < lg->Size(); ++node) {
100  Station *st = Station::Get((*lg)[node].Station());
101  st->goods[c].flows.erase(this->index);
102  if ((*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) {
103  st->goods[c].flows.DeleteFlows(this->index);
104  RerouteCargo(st, c, this->index, st->index);
105  }
106  }
107  lg->RemoveNode(this->goods[c].node);
108  if (lg->Size() == 0) {
110  delete lg;
111  }
112  }
113 
114  Vehicle *v;
115  FOR_ALL_VEHICLES(v) {
116  /* Forget about this station if this station is removed */
117  if (v->last_station_visited == this->index) {
118  v->last_station_visited = INVALID_STATION;
119  }
120  if (v->last_loading_station == this->index) {
121  v->last_loading_station = INVALID_STATION;
122  }
123  }
124 
125  /* Clear the persistent storage. */
126  delete this->airport.psa;
127 
128  if (this->owner == OWNER_NONE) {
129  /* Invalidate all in case of oil rigs. */
131  } else {
132  InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
133  }
134 
136 
137  /* Now delete all orders that go to the station */
138  RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);
139 
140  /* Remove all news items */
141  DeleteStationNews(this->index);
142 
143  for (CargoID c = 0; c < NUM_CARGO; c++) {
144  this->goods[c].cargo.Truncate();
145  }
146 
147  CargoPacket::InvalidateAllFrom(this->index);
148 }
149 
150 
156 void BaseStation::PostDestructor(size_t index)
157 {
159 }
160 
166 RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const
167 {
168  RoadStop *rs = this->GetPrimaryRoadStop(v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK);
169 
170  for (; rs != NULL; rs = rs->next) {
171  /* The vehicle cannot go to this roadstop (different roadtype) */
172  if ((GetRoadTypes(rs->xy) & v->compatible_roadtypes) == ROADTYPES_NONE) continue;
173  /* The vehicle is articulated and can therefore not go to a standard road stop. */
174  if (IsStandardRoadStopTile(rs->xy) && v->HasArticulatedPart()) continue;
175 
176  /* The vehicle can actually go to this road stop. So, return it! */
177  break;
178  }
179 
180  return rs;
181 }
182 
187 void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
188 {
189  if (this->facilities == FACIL_NONE) {
190  this->xy = facil_xy;
191  this->random_bits = Random();
192  }
193  this->facilities |= new_facility_bit;
194  this->owner = _current_company;
195  this->build_date = _date;
196 }
197 
203 void Station::MarkTilesDirty(bool cargo_change) const
204 {
205  TileIndex tile = this->train_station.tile;
206  int w, h;
207 
208  if (tile == INVALID_TILE) return;
209 
210  /* cargo_change is set if we're refreshing the tiles due to cargo moving
211  * around. */
212  if (cargo_change) {
213  /* Don't waste time updating if there are no custom station graphics
214  * that might change. Even if there are custom graphics, they might
215  * not change. Unfortunately we have no way of telling. */
216  if (this->num_specs == 0) return;
217  }
218 
219  for (h = 0; h < train_station.h; h++) {
220  for (w = 0; w < train_station.w; w++) {
221  if (this->TileBelongsToRailStation(tile)) {
222  MarkTileDirtyByTile(tile);
223  }
224  tile += TileDiffXY(1, 0);
225  }
226  tile += TileDiffXY(-w, 1);
227  }
228 }
229 
230 /* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
231 {
232  assert(this->TileBelongsToRailStation(tile));
233 
234  TileIndexDiff delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
235 
236  TileIndex t = tile;
237  uint len = 0;
238  do {
239  t -= delta;
240  len++;
241  } while (IsCompatibleTrainStationTile(t, tile));
242 
243  t = tile;
244  do {
245  t += delta;
246  len++;
247  } while (IsCompatibleTrainStationTile(t, tile));
248 
249  return len - 1;
250 }
251 
252 /* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
253 {
254  TileIndex start_tile = tile;
255  uint length = 0;
256  assert(IsRailStationTile(tile));
257  assert(dir < DIAGDIR_END);
258 
259  do {
260  length++;
261  tile += TileOffsByDiagDir(dir);
262  } while (IsCompatibleTrainStationTile(tile, start_tile));
263 
264  return length;
265 }
266 
272 {
273  uint ret = CA_NONE;
274 
276  if (this->bus_stops != NULL) ret = max<uint>(ret, CA_BUS);
277  if (this->truck_stops != NULL) ret = max<uint>(ret, CA_TRUCK);
278  if (this->train_station.tile != INVALID_TILE) ret = max<uint>(ret, CA_TRAIN);
279  if (this->dock_tile != INVALID_TILE) ret = max<uint>(ret, CA_DOCK);
280  if (this->airport.tile != INVALID_TILE) ret = max<uint>(ret, this->airport.GetSpec()->catchment);
281  } else {
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) {
283  ret = CA_UNMODIFIED;
284  }
285  }
286 
287  return ret;
288 }
289 
295 {
296  assert(!this->rect.IsEmpty());
297 
298  /* Compute acceptance rectangle */
299  int catchment_radius = this->GetCatchmentRadius();
300 
301  Rect ret = {
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())
306  };
307 
308  return ret;
309 }
310 
315 };
316 
325 static bool FindIndustryToDeliver(TileIndex ind_tile, void *user_data)
326 {
327  /* Only process industry tiles */
328  if (!IsTileType(ind_tile, MP_INDUSTRY)) return false;
329 
330  RectAndIndustryVector *riv = (RectAndIndustryVector *)user_data;
331  Industry *ind = Industry::GetByTile(ind_tile);
332 
333  /* Don't check further if this industry is already in the list */
334  if (riv->industries_near->Contains(ind)) return false;
335 
336  /* Only process tiles in the station acceptance rectangle */
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;
340 
341  /* Include only industries that can accept cargo */
342  uint cargo_index;
343  for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
344  if (ind->accepts_cargo[cargo_index] != CT_INVALID) break;
345  }
346  if (cargo_index >= lengthof(ind->accepts_cargo)) return false;
347 
348  *riv->industries_near->Append() = ind;
349 
350  return false;
351 }
352 
358 {
359  this->industries_near.Clear();
360  if (this->rect.IsEmpty()) return;
361 
362  RectAndIndustryVector riv = {
363  this->GetCatchmentRect(),
364  &this->industries_near
365  };
366 
367  /* Compute maximum extent of acceptance rectangle wrt. station sign */
368  TileIndex start_tile = this->xy;
369  uint max_radius = max(
370  max(DistanceManhattan(start_tile, TileXY(riv.rect.left, riv.rect.top)), DistanceManhattan(start_tile, TileXY(riv.rect.left, riv.rect.bottom))),
371  max(DistanceManhattan(start_tile, TileXY(riv.rect.right, riv.rect.top)), DistanceManhattan(start_tile, TileXY(riv.rect.right, riv.rect.bottom)))
372  );
373 
374  CircularTileSearch(&start_tile, 2 * max_radius + 1, &FindIndustryToDeliver, &riv);
375 }
376 
381 {
382  Station *st;
383  FOR_ALL_STATIONS(st) st->RecomputeIndustriesNear();
384 }
385 
386 /************************************************************************/
387 /* StationRect implementation */
388 /************************************************************************/
389 
390 StationRect::StationRect()
391 {
392  this->MakeEmpty();
393 }
394 
395 void StationRect::MakeEmpty()
396 {
397  this->left = this->top = this->right = this->bottom = 0;
398 }
399 
409 bool StationRect::PtInExtendedRect(int x, int y, int distance) const
410 {
411  return this->left - distance <= x && x <= this->right + distance &&
412  this->top - distance <= y && y <= this->bottom + distance;
413 }
414 
415 bool StationRect::IsEmpty() const
416 {
417  return this->left == 0 || this->left > this->right || this->top > this->bottom;
418 }
419 
420 CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
421 {
422  int x = TileX(tile);
423  int y = TileY(tile);
424  if (this->IsEmpty()) {
425  /* we are adding the first station tile */
426  if (mode != ADD_TEST) {
427  this->left = this->right = x;
428  this->top = this->bottom = y;
429  }
430  } else if (!this->PtInExtendedRect(x, y)) {
431  /* current rect is not empty and new point is outside this rect
432  * make new spread-out rectangle */
433  Rect new_rect = {min(x, this->left), min(y, this->top), max(x, this->right), max(y, this->bottom)};
434 
435  /* check new rect dimensions against preset max */
436  int w = new_rect.right - new_rect.left + 1;
437  int h = new_rect.bottom - new_rect.top + 1;
438  if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
439  assert(mode != ADD_TRY);
440  return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
441  }
442 
443  /* spread-out ok, return true */
444  if (mode != ADD_TEST) {
445  /* we should update the station rect */
446  *this = new_rect;
447  }
448  } else {
449  ; // new point is inside the rect, we don't need to do anything
450  }
451  return CommandCost();
452 }
453 
454 CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
455 {
456  if (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) {
457  /* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
458  CommandCost ret = this->BeforeAddTile(tile, mode);
459  if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
460  return ret;
461  }
462  return CommandCost();
463 }
464 
474 /* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
475 {
476  TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
477  TILE_AREA_LOOP(tile, ta) {
478  if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
479  }
480 
481  return false;
482 }
483 
484 bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
485 {
486  int x = TileX(tile);
487  int y = TileY(tile);
488 
489  /* look if removed tile was on the bounding rect edge
490  * and try to reduce the rect by this edge
491  * do it until we have empty rect or nothing to do */
492  for (;;) {
493  /* check if removed tile is on rect edge */
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);
498 
499  /* can we reduce the rect in either direction? */
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; // nothing to do (can't reduce)
503 
504  if (reduce_x) {
505  /* reduce horizontally */
506  if (left_edge) {
507  /* move left edge right */
508  this->left = x = x + 1;
509  } else {
510  /* move right edge left */
511  this->right = x = x - 1;
512  }
513  }
514  if (reduce_y) {
515  /* reduce vertically */
516  if (top_edge) {
517  /* move top edge down */
518  this->top = y = y + 1;
519  } else {
520  /* move bottom edge up */
521  this->bottom = y = y - 1;
522  }
523  }
524 
525  if (left > right || top > bottom) {
526  /* can't continue, if the remaining rectangle is empty */
527  this->MakeEmpty();
528  return true; // empty remaining rect
529  }
530  }
531  return false; // non-empty remaining rect
532 }
533 
534 bool StationRect::AfterRemoveRect(BaseStation *st, TileArea ta)
535 {
536  assert(this->PtInExtendedRect(TileX(ta.tile), TileY(ta.tile)));
537  assert(this->PtInExtendedRect(TileX(ta.tile) + ta.w - 1, TileY(ta.tile) + ta.h - 1));
538 
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));
541  return empty;
542 }
543 
544 StationRect& StationRect::operator = (const Rect &src)
545 {
546  this->left = src.left;
547  this->top = src.top;
548  this->right = src.right;
549  this->bottom = src.bottom;
550  return *this;
551 }
552 
559 {
560  Money total_cost = 0;
561 
562  const Station *st;
563  FOR_ALL_STATIONS(st) {
564  if (st->owner == owner && (st->facilities & FACIL_AIRPORT)) {
565  total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
566  }
567  }
568  /* 3 bits fraction for the maintenance cost factor. */
569  return total_cost >> 3;
570 }
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:312
Select station (when joining stations); Window numbers:
Definition: window_type.h:237
A standard stop for trucks.
Definition: station_type.h:49
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
Definition: station.cpp:294
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:78
Base class for roadstops.
Non-existing type of vehicle.
Definition: vehicle_type.h:35
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.
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:74
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:48
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:39
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
StationFacility
The facilities a station might be having.
Definition: station_type.h:53
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:807
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:203
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:82
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:121
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:1341
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
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:3238
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:27
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:314
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
Definition: tile_map.h:143
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.
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination)
Removes an order from all vehicles.
Definition: order_cmd.cpp:1837
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Definition: station.cpp:558
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:76
A simplified pool which stores values instead of pointers and doesn&#39;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.
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
CargoID accepts_cargo[3]
3 input cargo slots
Definition: industry.h:47
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
Definition: station.cpp:271
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:357
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:900
Station view; Window numbers:
Definition: window_type.h:340
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.
Definition: station_type.h:83
Catchment for all stations with "modified catchment" disabled.
Definition: station_type.h:87
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
Road vehicle type.
Definition: vehicle_type.h:25
Invalid cargo type.
Definition: cargo_type.h:70
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:26
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:259
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
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.
Definition: viewport.cpp:1904
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don&#39;t get linker errors.
Definition: pool_func.hpp:224
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:1137
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:85
Functions related to companies.
Catchment when the station has no facilities.
Definition: station_type.h:81
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:80
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:409
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:84
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:380
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:325
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:187
#define FOR_ALL_AIRCRAFT(var)
Macro for iterating over all aircrafts.
Definition: aircraft.h:142
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:474
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:156
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
Definition: vehicle_base.h:986
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:313
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:94
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:252
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:58
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:54
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:3220
Train vehicle type.
Definition: vehicle_type.h:24