OpenTTD Source  14.0-beta3
station.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #include "stdafx.h"
11 #include "company_func.h"
12 #include "company_base.h"
13 #include "roadveh.h"
14 #include "viewport_func.h"
15 #include "viewport_kdtree.h"
16 #include "command_func.h"
17 #include "news_func.h"
18 #include "aircraft.h"
19 #include "vehiclelist.h"
20 #include "core/pool_func.hpp"
21 #include "station_base.h"
22 #include "station_kdtree.h"
23 #include "roadstop_base.h"
24 #include "industry.h"
25 #include "town.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 
39 StationKdtree _station_kdtree(Kdtree_StationXYFunc);
40 
41 void RebuildStationKdtree()
42 {
43  std::vector<StationID> stids;
44  for (const Station *st : Station::Iterate()) {
45  stids.push_back(st->index);
46  }
47  _station_kdtree.Build(stids.begin(), stids.end());
48 }
49 
50 
51 BaseStation::~BaseStation()
52 {
53  if (CleaningPool()) return;
54 
55  CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).Pack());
56  CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).Pack());
57  CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).Pack());
58  CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack());
59 
60  this->sign.MarkDirty();
61 }
62 
63 Station::Station(TileIndex tile) :
64  SpecializedStation<Station, false>(tile),
65  bus_station(INVALID_TILE, 0, 0),
66  truck_station(INVALID_TILE, 0, 0),
67  ship_station(INVALID_TILE, 0, 0),
68  indtype(IT_INVALID),
69  time_since_load(255),
70  time_since_unload(255),
71  last_vehicle_type(VEH_INVALID)
72 {
73  /* this->random_bits is set in Station::AddFacility() */
74 }
75 
84 {
85  if (CleaningPool()) {
86  for (GoodsEntry &ge : this->goods) {
87  ge.cargo.OnCleanPool();
88  }
89  return;
90  }
91 
92  while (!this->loading_vehicles.empty()) {
93  this->loading_vehicles.front()->LeaveStation();
94  }
95 
96  for (Aircraft *a : Aircraft::Iterate()) {
97  if (!a->IsNormalAircraft()) continue;
98  if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
99  }
100 
101  for (CargoID c = 0; c < NUM_CARGO; ++c) {
102  LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
103  if (lg == nullptr) continue;
104 
105  for (NodeID node = 0; node < lg->Size(); ++node) {
106  Station *st = Station::Get((*lg)[node].station);
107  st->goods[c].flows.erase(this->index);
108  if ((*lg)[node].HasEdgeTo(this->goods[c].node) && (*lg)[node][this->goods[c].node].LastUpdate() != EconomyTime::INVALID_DATE) {
109  st->goods[c].flows.DeleteFlows(this->index);
110  RerouteCargo(st, c, this->index, st->index);
111  }
112  }
113  lg->RemoveNode(this->goods[c].node);
114  if (lg->Size() == 0) {
116  delete lg;
117  }
118  }
119 
120  for (Vehicle *v : Vehicle::Iterate()) {
121  /* Forget about this station if this station is removed */
122  if (v->last_station_visited == this->index) {
123  v->last_station_visited = INVALID_STATION;
124  }
125  if (v->last_loading_station == this->index) {
126  v->last_loading_station = INVALID_STATION;
127  }
128  }
129 
130  /* Remove station from industries and towns that reference it. */
131  this->RemoveFromAllNearbyLists();
132 
133  /* Clear the persistent storage. */
134  delete this->airport.psa;
135 
136  if (this->owner == OWNER_NONE) {
137  /* Invalidate all in case of oil rigs. */
139  } else {
141  }
142 
144 
145  /* Now delete all orders that go to the station */
146  RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);
147 
148  /* Remove all news items */
149  DeleteStationNews(this->index);
150 
151  for (GoodsEntry &ge : this->goods) {
152  ge.cargo.Truncate();
153  }
154 
156 
157  _station_kdtree.Remove(this->index);
158  if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
159 }
160 
161 
167 {
169 }
170 
171 void BaseStation::SetRoadStopTileData(TileIndex tile, byte data, bool animation)
172 {
173  for (RoadStopTileData &tile_data : this->custom_roadstop_tile_data) {
174  if (tile_data.tile == tile) {
175  if (animation) {
176  tile_data.animation_frame = data;
177  } else {
178  tile_data.random_bits = data;
179  }
180  return;
181  }
182  }
183  RoadStopTileData tile_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);
188 }
189 
190 void BaseStation::RemoveRoadStopTileData(TileIndex tile)
191 {
192  for (RoadStopTileData &tile_data : this->custom_roadstop_tile_data) {
193  if (tile_data.tile == tile) {
194  tile_data = this->custom_roadstop_tile_data.back();
195  this->custom_roadstop_tile_data.pop_back();
196  return;
197  }
198  }
199 }
200 
206 RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const
207 {
208  RoadStop *rs = this->GetPrimaryRoadStop(v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK);
209 
210  for (; rs != nullptr; rs = rs->next) {
211  /* The vehicle cannot go to this roadstop (different roadtype) */
212  if (!HasTileAnyRoadType(rs->xy, v->compatible_roadtypes)) continue;
213  /* The vehicle is articulated and can therefore not go to a standard road stop. */
214  if (IsBayRoadStopTile(rs->xy) && v->HasArticulatedPart()) continue;
215 
216  /* The vehicle can actually go to this road stop. So, return it! */
217  break;
218  }
219 
220  return rs;
221 }
222 
227 void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
228 {
229  if (this->facilities == FACIL_NONE) {
230  this->MoveSign(facil_xy);
231  this->random_bits = Random();
232  }
233  this->facilities |= new_facility_bit;
234  this->owner = _current_company;
236 }
237 
243 void Station::MarkTilesDirty(bool cargo_change) const
244 {
245  TileIndex tile = this->train_station.tile;
246  int w, h;
247 
248  if (tile == INVALID_TILE) return;
249 
250  /* cargo_change is set if we're refreshing the tiles due to cargo moving
251  * around. */
252  if (cargo_change) {
253  /* Don't waste time updating if there are no custom station graphics
254  * that might change. Even if there are custom graphics, they might
255  * not change. Unfortunately we have no way of telling. */
256  if (this->speclist.empty()) return;
257  }
258 
259  for (h = 0; h < train_station.h; h++) {
260  for (w = 0; w < train_station.w; w++) {
261  if (this->TileBelongsToRailStation(tile)) {
262  MarkTileDirtyByTile(tile);
263  }
264  tile += TileDiffXY(1, 0);
265  }
266  tile += TileDiffXY(-w, 1);
267  }
268 }
269 
270 /* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
271 {
272  assert(this->TileBelongsToRailStation(tile));
273 
274  TileIndexDiff delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
275 
276  TileIndex t = tile;
277  uint len = 0;
278  do {
279  t -= delta;
280  len++;
281  } while (IsCompatibleTrainStationTile(t, tile));
282 
283  t = tile;
284  do {
285  t += delta;
286  len++;
287  } while (IsCompatibleTrainStationTile(t, tile));
288 
289  return len - 1;
290 }
291 
292 /* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
293 {
294  TileIndex start_tile = tile;
295  uint length = 0;
296  assert(IsRailStationTile(tile));
297  assert(dir < DIAGDIR_END);
298 
299  do {
300  length++;
301  tile += TileOffsByDiagDir(dir);
302  } while (IsCompatibleTrainStationTile(tile, start_tile));
303 
304  return length;
305 }
306 
314 static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
315 {
316  assert(IsTileType(tile, MP_STATION));
317 
319  switch (GetStationType(tile)) {
320  case STATION_RAIL: return CA_TRAIN;
321  case STATION_OILRIG: return CA_UNMODIFIED;
322  case STATION_AIRPORT: return st->airport.GetSpec()->catchment;
323  case STATION_TRUCK: return CA_TRUCK;
324  case STATION_BUS: return CA_BUS;
325  case STATION_DOCK: return CA_DOCK;
326 
327  default: NOT_REACHED();
328  case STATION_BUOY:
329  case STATION_WAYPOINT: return CA_NONE;
330  }
331  } else {
332  switch (GetStationType(tile)) {
333  default: return CA_UNMODIFIED;
334  case STATION_BUOY:
335  case STATION_WAYPOINT: return CA_NONE;
336  }
337  }
338 }
339 
345 {
346  uint ret = CA_NONE;
347 
349  if (this->bus_stops != nullptr) ret = std::max<uint>(ret, CA_BUS);
350  if (this->truck_stops != nullptr) ret = std::max<uint>(ret, CA_TRUCK);
351  if (this->train_station.tile != INVALID_TILE) ret = std::max<uint>(ret, CA_TRAIN);
352  if (this->ship_station.tile != INVALID_TILE) ret = std::max<uint>(ret, CA_DOCK);
353  if (this->airport.tile != INVALID_TILE) ret = std::max<uint>(ret, this->airport.GetSpec()->catchment);
354  } else {
355  if (this->bus_stops != nullptr || this->truck_stops != nullptr || this->train_station.tile != INVALID_TILE || this->ship_station.tile != INVALID_TILE || this->airport.tile != INVALID_TILE) {
356  ret = CA_UNMODIFIED;
357  }
358  }
359 
360  return ret;
361 }
362 
368 {
369  assert(!this->rect.IsEmpty());
370 
371  /* Compute acceptance rectangle */
372  int catchment_radius = this->GetCatchmentRadius();
373 
374  Rect ret = {
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())
379  };
380 
381  return ret;
382 }
383 
391 {
392  /* Using DistanceMax to get about the same order as with previously used CircularTileSearch. */
393  uint distance = DistanceMax(this->xy, tile);
394 
395  /* Don't check further if this industry is already in the list but update the distance if it's closer */
396  auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
397  if (pos != this->industries_near.end()) {
398  if (pos->distance > distance) {
399  auto node = this->industries_near.extract(pos);
400  node.value().distance = distance;
401  this->industries_near.insert(std::move(node));
402  }
403  return;
404  }
405 
406  /* Include only industries that can accept cargo */
407  if (!ind->IsCargoAccepted()) return;
408 
409  this->industries_near.insert(IndustryListEntry{distance, ind});
410 }
411 
417 {
418  auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
419  if (pos != this->industries_near.end()) {
420  this->industries_near.erase(pos);
421  }
422 }
423 
424 
429 {
430  for (Town *t : Town::Iterate()) { t->stations_near.erase(this); }
431  for (Industry *i : Industry::Iterate()) { i->stations_near.erase(this); }
432 }
433 
441 bool Station::CatchmentCoversTown(TownID t) const
442 {
444  for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
445  if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) == t) return true;
446  }
447  return false;
448 }
449 
455 void Station::RecomputeCatchment(bool no_clear_nearby_lists)
456 {
457  this->industries_near.clear();
458  if (!no_clear_nearby_lists) this->RemoveFromAllNearbyLists();
459 
460  if (this->rect.IsEmpty()) {
461  this->catchment_tiles.Reset();
462  return;
463  }
464 
465  if (!_settings_game.station.serve_neutral_industries && this->industry != nullptr) {
466  /* Station is associated with an industry, so we only need to deliver to that industry. */
468  for (TileIndex tile : this->industry->location) {
469  if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->industry->index) {
470  this->catchment_tiles.SetTile(tile);
471  }
472  }
473  /* The industry's stations_near may have been computed before its neutral station was built so clear and re-add here. */
474  for (Station *st : this->industry->stations_near) {
476  }
477  this->industry->stations_near.clear();
478  this->industry->stations_near.insert(this);
479  this->industries_near.insert(IndustryListEntry{0, this->industry});
480  return;
481  }
482 
484 
485  /* Loop finding all station tiles */
486  TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom));
487  for (TileIndex tile : ta) {
488  if (!IsTileType(tile, MP_STATION) || GetStationIndex(tile) != this->index) continue;
489 
490  uint r = GetTileCatchmentRadius(tile, this);
491  if (r == CA_NONE) continue;
492 
493  /* This tile sub-loop doesn't need to test any tiles, they are simply added to the catchment set. */
494  TileArea ta2 = TileArea(tile, 1, 1).Expand(r);
495  for (TileIndex tile2 : ta2) this->catchment_tiles.SetTile(tile2);
496  }
497 
498  /* Search catchment tiles for towns and industries */
500  for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
501  if (IsTileType(tile, MP_HOUSE)) {
502  Town *t = Town::GetByTile(tile);
503  t->stations_near.insert(this);
504  }
505  if (IsTileType(tile, MP_INDUSTRY)) {
506  Industry *i = Industry::GetByTile(tile);
507 
508  /* Ignore industry if it has a neutral station. It already can't be this station. */
509  if (!_settings_game.station.serve_neutral_industries && i->neutral_station != nullptr) continue;
510 
511  i->stations_near.insert(this);
512 
513  /* Add if we can deliver to this industry as well */
514  this->AddIndustryToDeliver(i, tile);
515  }
516  }
517 }
518 
524 {
525  for (Town *t : Town::Iterate()) { t->stations_near.clear(); }
526  for (Industry *i : Industry::Iterate()) { i->stations_near.clear(); }
527  for (Station *st : Station::Iterate()) { st->RecomputeCatchment(true); }
528 }
529 
530 /************************************************************************/
531 /* StationRect implementation */
532 /************************************************************************/
533 
534 StationRect::StationRect()
535 {
536  this->MakeEmpty();
537 }
538 
539 void StationRect::MakeEmpty()
540 {
541  this->left = this->top = this->right = this->bottom = 0;
542 }
543 
553 bool StationRect::PtInExtendedRect(int x, int y, int distance) const
554 {
555  return this->left - distance <= x && x <= this->right + distance &&
556  this->top - distance <= y && y <= this->bottom + distance;
557 }
558 
559 bool StationRect::IsEmpty() const
560 {
561  return this->left == 0 || this->left > this->right || this->top > this->bottom;
562 }
563 
564 CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
565 {
566  int x = TileX(tile);
567  int y = TileY(tile);
568  if (this->IsEmpty()) {
569  /* we are adding the first station tile */
570  if (mode != ADD_TEST) {
571  this->left = this->right = x;
572  this->top = this->bottom = y;
573  }
574  } else if (!this->PtInExtendedRect(x, y)) {
575  /* current rect is not empty and new point is outside this rect
576  * make new spread-out rectangle */
577  Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
578 
579  /* check new rect dimensions against preset max */
580  int w = new_rect.Width();
581  int h = new_rect.Height();
582  if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
583  assert(mode != ADD_TRY);
584  return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
585  }
586 
587  /* spread-out ok, return true */
588  if (mode != ADD_TEST) {
589  /* we should update the station rect */
590  *this = new_rect;
591  }
592  } else {
593  ; // new point is inside the rect, we don't need to do anything
594  }
595  return CommandCost();
596 }
597 
598 CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
599 {
600  if (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) {
601  /* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
602  CommandCost ret = this->BeforeAddTile(tile, mode);
603  if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
604  return ret;
605  }
606  return CommandCost();
607 }
608 
618 /* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
619 {
620  TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
621  for (TileIndex tile : ta) {
622  if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
623  }
624 
625  return false;
626 }
627 
628 bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
629 {
630  int x = TileX(tile);
631  int y = TileY(tile);
632 
633  /* look if removed tile was on the bounding rect edge
634  * and try to reduce the rect by this edge
635  * do it until we have empty rect or nothing to do */
636  for (;;) {
637  /* check if removed tile is on rect edge */
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);
642 
643  /* can we reduce the rect in either direction? */
644  bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, this->top, x, this->bottom));
645  bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->index, this->left, y, this->right, y));
646  if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce)
647 
648  if (reduce_x) {
649  /* reduce horizontally */
650  if (left_edge) {
651  /* move left edge right */
652  this->left = x = x + 1;
653  } else {
654  /* move right edge left */
655  this->right = x = x - 1;
656  }
657  }
658  if (reduce_y) {
659  /* reduce vertically */
660  if (top_edge) {
661  /* move top edge down */
662  this->top = y = y + 1;
663  } else {
664  /* move bottom edge up */
665  this->bottom = y = y - 1;
666  }
667  }
668 
669  if (left > right || top > bottom) {
670  /* can't continue, if the remaining rectangle is empty */
671  this->MakeEmpty();
672  return true; // empty remaining rect
673  }
674  }
675  return false; // non-empty remaining rect
676 }
677 
678 bool StationRect::AfterRemoveRect(BaseStation *st, TileArea ta)
679 {
680  assert(this->PtInExtendedRect(TileX(ta.tile), TileY(ta.tile)));
681  assert(this->PtInExtendedRect(TileX(ta.tile) + ta.w - 1, TileY(ta.tile) + ta.h - 1));
682 
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));
685  return empty;
686 }
687 
688 StationRect& StationRect::operator = (const Rect &src)
689 {
690  this->left = src.left;
691  this->top = src.top;
692  this->right = src.right;
693  this->bottom = src.bottom;
694  return *this;
695 }
696 
703 {
704  Money total_cost = 0;
705 
706  for (const Station *st : Station::Iterate()) {
707  if (st->owner == owner && (st->facilities & FACIL_AIRPORT)) {
708  total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
709  }
710  }
711  /* 3 bits fraction for the maintenance cost factor. */
712  return total_cost >> 3;
713 }
714 
715 bool StationCompare::operator() (const Station *lhs, const Station *rhs) const
716 {
717  return lhs->index < rhs->index;
718 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:106
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition: tile_type.h:51
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:75
CA_UNMODIFIED
@ CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition: station_type.h:82
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition: window_type.h:314
BaseStation::speclist
std::vector< StationSpecList > speclist
List of rail station specs of this station.
Definition: base_station_base.h:77
InvalidateWindowData
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:3200
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:471
StationRect
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
Definition: base_station_base.h:41
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
station_kdtree.h
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:630
BitmapTileArea::Initialize
void Initialize(const Rect &r)
Initialize the BitmapTileArea with the specified Rect.
Definition: bitmap_type.h:57
LinkGraph
A connected component of a link graph.
Definition: linkgraph.h:37
Station::GetPlatformLength
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const override
Determines the REMAINING length of a platform, starting at (and including) the given tile.
Definition: station.cpp:292
ROADSTOP_TRUCK
@ ROADSTOP_TRUCK
A standard stop for trucks.
Definition: station_type.h:45
command_func.h
RerouteCargo
void RerouteCargo(Station *st, CargoID c, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
Definition: station_cmd.cpp:3793
Pool::PoolItem<&_link_graph_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:346
CA_NONE
@ CA_NONE
Catchment when the station has no facilities.
Definition: station_type.h:76
Kdtree
K-dimensional tree, specialised for 2-dimensional space.
Definition: kdtree.hpp:35
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:28
BitmapTileArea::SetTile
void SetTile(TileIndex tile)
Add a tile as part of the tile area.
Definition: bitmap_type.h:79
Map::MaxX
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:297
company_base.h
RoadStop::xy
TileIndex xy
Position on the map.
Definition: roadstop_base.h:67
Station
Station data structure.
Definition: station_base.h:442
CargoPacket::InvalidateAllFrom
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Definition: cargopacket.cpp:137
SpecializedStation
Class defining several overloaded accessors so we don't have to cast base stations that often.
Definition: base_station_base.h:222
_station_pool
StationPool _station_pool("Station")
The pool of stations.
DeleteStationNews
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
Definition: news_gui.cpp:938
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
vehiclelist.h
BitmapTileIterator
Iterator to iterate over all tiles belonging to a bitmaptilearea.
Definition: bitmap_type.h:106
LinkGraphSchedule::instance
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Definition: linkgraphschedule.h:52
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:79
Pool::PoolItem<&_station_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
StationRect::PtInExtendedRect
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:553
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
Station::MoveSign
void MoveSign(TileIndex new_xy) override
Move the station main coordinate somewhere else.
Definition: station_cmd.cpp:460
IsCompatibleTrainStationTile
bool IsCompatibleTrainStationTile(Tile test_tile, Tile station_tile)
Check if a tile is a valid continuation to a railstation tile.
Definition: station_map.h:451
IsRailStationTile
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
Definition: station_map.h:102
aircraft.h
FACIL_NONE
@ FACIL_NONE
The station has no facilities at all.
Definition: station_type.h:51
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:259
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
town.h
GetTileCatchmentRadius
static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
Get the catchment size of an individual station tile.
Definition: station.cpp:314
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
LinkGraph::Size
NodeID Size() const
Get the current size of the component.
Definition: linkgraph.h:230
WC_STATION_VIEW
@ WC_STATION_VIEW
Station view; Window numbers:
Definition: window_type.h:345
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:240
Industry
Defines the internal data of a functional industry.
Definition: industry.h:68
Station::CatchmentCoversTown
bool CatchmentCoversTown(TownID t) const
Test if the given town ID is covered by our catchment area.
Definition: station.cpp:441
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
LinkGraph::RemoveNode
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
Definition: linkgraph.cpp:116
Kdtree::Build
void Build(It begin, It end)
Clear and rebuild the tree from a new sequence of elements,.
Definition: kdtree.hpp:362
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:74
Station::RecomputeCatchment
void RecomputeCatchment(bool no_clear_nearby_lists=false)
Recompute tiles covered in our catchment area.
Definition: station.cpp:455
GetRailStationAxis
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Definition: station_map.h:410
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition: tilearea_type.h:21
Industry::neutral_station
Station * neutral_station
Associated neutral station.
Definition: industry.h:98
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition: kdtree.hpp:417
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:310
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
RoadStop::next
struct RoadStop * next
Next stop of the given type at this station.
Definition: roadstop_base.h:69
FlowStatMap::DeleteFlows
StationIDStack DeleteFlows(StationID via)
Delete all flows at a station for specific cargo and destination.
Definition: station_cmd.cpp:4834
StationSettings::serve_neutral_industries
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
Definition: settings_type.h:591
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
IsBayRoadStopTile
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
Definition: station_map.h:223
BaseStation::sign
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
Definition: base_station_base.h:66
Industry::stations_near
StationList stations_near
NOSAVE: List of nearby stations.
Definition: industry.h:112
CommandCost
Common return value for all commands.
Definition: command_type.h:23
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:96
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition: base_station_base.h:89
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:207
Station::RecomputeCatchmentForAll
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition: station.cpp:523
roadstop_base.h
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:90
Station::MarkTilesDirty
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
Definition: station.cpp:243
BitmapTileArea::Reset
void Reset()
Reset and clear the BitmapTileArea.
Definition: bitmap_type.h:45
Town::stations_near
StationList stations_near
NOSAVE: List of nearby stations.
Definition: town.h:87
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:456
OrthogonalTileArea
Represents the covered area of e.g.
Definition: tilearea_type.h:18
Station::AddFacility
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
Definition: station.cpp:227
Station::TileBelongsToRailStation
bool TileBelongsToRailStation(TileIndex tile) const override
Check whether a specific tile belongs to this station.
Definition: station_base.h:507
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:401
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
ViewportSign::MarkDirty
void MarkDirty(ZoomLevel maxzoom=ZOOM_LVL_MAX) const
Mark the sign dirty in all viewports.
Definition: viewport.cpp:1489
Station::~Station
~Station()
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
Definition: station.cpp:83
GetIndustryIndex
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
industry.h
safeguards.h
CA_BUS
@ CA_BUS
Catchment for bus stops with "modified catchment" enabled.
Definition: station_type.h:77
VEH_INVALID
@ VEH_INVALID
Non-existing type of vehicle.
Definition: vehicle_type.h:35
WC_SHIPS_LIST
@ WC_SHIPS_LIST
Ships list; Window numbers:
Definition: window_type.h:320
RoadVehicle::compatible_roadtypes
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Definition: roadveh.h:117
AirportMaintenanceCost
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Definition: station.cpp:702
CA_TRUCK
@ CA_TRUCK
Catchment for truck stops with "modified catchment" enabled.
Definition: station_type.h:78
RoadStopTileData
Definition: base_station_base.h:34
TileIndexDiff
int32_t TileIndexDiff
An offset value between two tiles.
Definition: map_func.h:376
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:308
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:595
linkgraphschedule.h
stdafx.h
Station::truck_stops
RoadStop * truck_stops
All the truck stops.
Definition: station_base.h:453
Station::industry
Industry * industry
NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
Definition: station_base.h:475
viewport_func.h
StationRect::ScanForStationTiles
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:618
GetStationType
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition: station_map.h:44
StationFacility
StationFacility
The facilities a station might be having.
Definition: station_type.h:50
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:563
DistanceMax
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Definition: map.cpp:191
CA_DOCK
@ CA_DOCK
Catchment for docks with "modified catchment" enabled.
Definition: station_type.h:80
ROADSTOP_BUS
@ ROADSTOP_BUS
A standard stop for buses.
Definition: station_type.h:44
Station::industries_near
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
Definition: station_base.h:474
GoodsEntry
Stores station stats for a single cargo.
Definition: station_base.h:166
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:50
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition: window_type.h:242
station_base.h
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:384
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:306
Pool
Base class for all pools.
Definition: pool_type.hpp:80
GoodsEntry::flows
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:211
Station::GetCatchmentRadius
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
Definition: station.cpp:344
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition: station_map.h:28
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
RemoveOrderFromAllVehicles
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Definition: order_cmd.cpp:1787
InvalidateWindowClassesData
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:3217
Pool::PoolItem<&_station_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:314
MarkTileDirtyByTile
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:2051
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
TimerGameConst< struct Economy >::INVALID_DATE
static constexpr TimerGame< struct Economy >::Date INVALID_DATE
Representation of an invalid date.
Definition: timer_game_common.h:193
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:949
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition: viewport_type.h:50
Station::GetCatchmentRect
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
Definition: station.cpp:367
Station::RemoveIndustryToDeliver
void RemoveIndustryToDeliver(Industry *ind)
Remove nearby industry from station's industries_near list.
Definition: station.cpp:416
linkgraph.h
Station::catchment_tiles
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
Definition: station_base.h:462
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:65
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:64
IndustryListEntry
Definition: station_base.h:428
company_func.h
SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::Iterate
static Pool::IterateWrapper< Aircraft > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
Definition: vehicle_base.h:1270
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:225
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:117
BaseStation::random_bits
uint16_t random_bits
Random bits assigned to this station.
Definition: base_station_base.h:82
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:480
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition: tilearea_type.h:20
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:102
Town
Town data structure.
Definition: town.h:50
Station::RemoveFromAllNearbyLists
void RemoveFromAllNearbyLists()
Remove this station from the nearby stations lists of all towns and industries.
Definition: station.cpp:428
BaseStation::PostDestructor
static void PostDestructor(size_t index)
Invalidating of the JoinStation window has to be done after removing item from the pool.
Definition: station.cpp:166
TileXY
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:385
CA_TRAIN
@ CA_TRAIN
Catchment for train stations with "modified catchment" enabled.
Definition: station_type.h:79
random_func.hpp
OverflowSafeInt< int64_t >
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:83
OrthogonalTileArea::Expand
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Definition: tilearea.cpp:123
Station::bus_stops
RoadStop * bus_stops
All the road stops.
Definition: station_base.h:451
LinkGraphSchedule::Unqueue
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Definition: linkgraphschedule.h:77
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
Industry::IsCargoAccepted
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
Definition: industry.h:179
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
RoadStop
A Stop for a Road Vehicle.
Definition: roadstop_base.h:22
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition: station_type.h:55
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition: cargo_type.h:74
Airport::psa
PersistentStorage * psa
Persistent storage for NewGRF airports.
Definition: station_base.h:298
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
Airport::GetSpec
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition: station_base.h:305
pool_func.hpp
HasTileAnyRoadType
bool HasTileAnyRoadType(Tile t, RoadTypes rts)
Check if a tile has one of the specified road types.
Definition: road_map.h:222
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
BaseStation::custom_roadstop_tile_data
std::vector< RoadStopTileData > custom_roadstop_tile_data
List of custom road stop tile data.
Definition: base_station_base.h:92
WC_AIRCRAFT_LIST
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Definition: window_type.h:326
WC_STATION_LIST
@ WC_STATION_LIST
Station list; Window numbers:
Definition: window_type.h:302
AirportSpec::catchment
byte catchment
catchment area of this airport
Definition: newgrf_airport.h:110
Station::ship_station
TileArea ship_station
Tile area the ship 'station' part covers.
Definition: station_base.h:457
Station::AddIndustryToDeliver
void AddIndustryToDeliver(Industry *ind, TileIndex tile)
Add nearby industry to station's industries_near list if it accepts cargo.
Definition: station.cpp:390
StationSettings::modified_catchment
bool modified_catchment
different-size catchment areas
Definition: settings_type.h:590
news_func.h
roadveh.h
GetTownIndex
TownID GetTownIndex(Tile t)
Get the index of which town this house/street is attached to.
Definition: town_map.h:23
BaseStation::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition: base_station_base.h:80