OpenTTD Source  13.0-beta1
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 "date_func.h"
17 #include "command_func.h"
18 #include "news_func.h"
19 #include "aircraft.h"
20 #include "vehiclelist.h"
21 #include "core/pool_func.hpp"
22 #include "station_base.h"
23 #include "station_kdtree.h"
24 #include "roadstop_base.h"
25 #include "industry.h"
26 #include "town.h"
27 #include "core/random_func.hpp"
28 #include "linkgraph/linkgraph.h"
30 
31 #include "table/strings.h"
32 
33 #include "safeguards.h"
34 
36 StationPool _station_pool("Station");
38 
39 
40 StationKdtree _station_kdtree(Kdtree_StationXYFunc);
41 
42 void RebuildStationKdtree()
43 {
44  std::vector<StationID> stids;
45  for (const Station *st : Station::Iterate()) {
46  stids.push_back(st->index);
47  }
48  _station_kdtree.Build(stids.begin(), stids.end());
49 }
50 
51 
52 BaseStation::~BaseStation()
53 {
54  free(this->speclist);
55 
56  if (CleaningPool()) return;
57 
58  CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).Pack());
59  CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).Pack());
60  CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).Pack());
61  CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack());
62 
63  this->sign.MarkDirty();
64 }
65 
66 Station::Station(TileIndex tile) :
67  SpecializedStation<Station, false>(tile),
68  bus_station(INVALID_TILE, 0, 0),
69  truck_station(INVALID_TILE, 0, 0),
70  ship_station(INVALID_TILE, 0, 0),
71  indtype(IT_INVALID),
72  time_since_load(255),
73  time_since_unload(255),
74  last_vehicle_type(VEH_INVALID)
75 {
76  /* this->random_bits is set in Station::AddFacility() */
77 }
78 
87 {
88  if (CleaningPool()) {
89  for (CargoID c = 0; c < NUM_CARGO; c++) {
90  this->goods[c].cargo.OnCleanPool();
91  }
92  return;
93  }
94 
95  while (!this->loading_vehicles.empty()) {
96  this->loading_vehicles.front()->LeaveStation();
97  }
98 
99  for (Aircraft *a : Aircraft::Iterate()) {
100  if (!a->IsNormalAircraft()) continue;
101  if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
102  }
103 
104  for (CargoID c = 0; c < NUM_CARGO; ++c) {
105  LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
106  if (lg == nullptr) continue;
107 
108  for (NodeID node = 0; node < lg->Size(); ++node) {
109  Station *st = Station::Get((*lg)[node].Station());
110  st->goods[c].flows.erase(this->index);
111  if ((*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) {
112  st->goods[c].flows.DeleteFlows(this->index);
113  RerouteCargo(st, c, this->index, st->index);
114  }
115  }
116  lg->RemoveNode(this->goods[c].node);
117  if (lg->Size() == 0) {
119  delete lg;
120  }
121  }
122 
123  for (Vehicle *v : Vehicle::Iterate()) {
124  /* Forget about this station if this station is removed */
125  if (v->last_station_visited == this->index) {
126  v->last_station_visited = INVALID_STATION;
127  }
128  if (v->last_loading_station == this->index) {
129  v->last_loading_station = INVALID_STATION;
130  }
131  }
132 
133  /* Remove station from industries and towns that reference it. */
134  this->RemoveFromAllNearbyLists();
135 
136  /* Clear the persistent storage. */
137  delete this->airport.psa;
138 
139  if (this->owner == OWNER_NONE) {
140  /* Invalidate all in case of oil rigs. */
142  } else {
144  }
145 
147 
148  /* Now delete all orders that go to the station */
149  RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);
150 
151  /* Remove all news items */
152  DeleteStationNews(this->index);
153 
154  for (CargoID c = 0; c < NUM_CARGO; c++) {
155  this->goods[c].cargo.Truncate();
156  }
157 
159 
160  _station_kdtree.Remove(this->index);
161  if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
162 }
163 
164 
170 void BaseStation::PostDestructor(size_t index)
171 {
173 }
174 
180 RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const
181 {
182  RoadStop *rs = this->GetPrimaryRoadStop(v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK);
183 
184  for (; rs != nullptr; rs = rs->next) {
185  /* The vehicle cannot go to this roadstop (different roadtype) */
186  if (!HasTileAnyRoadType(rs->xy, v->compatible_roadtypes)) continue;
187  /* The vehicle is articulated and can therefore not go to a standard road stop. */
188  if (IsStandardRoadStopTile(rs->xy) && v->HasArticulatedPart()) continue;
189 
190  /* The vehicle can actually go to this road stop. So, return it! */
191  break;
192  }
193 
194  return rs;
195 }
196 
201 void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
202 {
203  if (this->facilities == FACIL_NONE) {
204  this->MoveSign(facil_xy);
205  this->random_bits = Random();
206  }
207  this->facilities |= new_facility_bit;
208  this->owner = _current_company;
209  this->build_date = _date;
210 }
211 
217 void Station::MarkTilesDirty(bool cargo_change) const
218 {
219  TileIndex tile = this->train_station.tile;
220  int w, h;
221 
222  if (tile == INVALID_TILE) return;
223 
224  /* cargo_change is set if we're refreshing the tiles due to cargo moving
225  * around. */
226  if (cargo_change) {
227  /* Don't waste time updating if there are no custom station graphics
228  * that might change. Even if there are custom graphics, they might
229  * not change. Unfortunately we have no way of telling. */
230  if (this->num_specs == 0) return;
231  }
232 
233  for (h = 0; h < train_station.h; h++) {
234  for (w = 0; w < train_station.w; w++) {
235  if (this->TileBelongsToRailStation(tile)) {
236  MarkTileDirtyByTile(tile);
237  }
238  tile += TileDiffXY(1, 0);
239  }
240  tile += TileDiffXY(-w, 1);
241  }
242 }
243 
244 /* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
245 {
246  assert(this->TileBelongsToRailStation(tile));
247 
248  TileIndexDiff delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
249 
250  TileIndex t = tile;
251  uint len = 0;
252  do {
253  t -= delta;
254  len++;
255  } while (IsCompatibleTrainStationTile(t, tile));
256 
257  t = tile;
258  do {
259  t += delta;
260  len++;
261  } while (IsCompatibleTrainStationTile(t, tile));
262 
263  return len - 1;
264 }
265 
266 /* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
267 {
268  TileIndex start_tile = tile;
269  uint length = 0;
270  assert(IsRailStationTile(tile));
271  assert(dir < DIAGDIR_END);
272 
273  do {
274  length++;
275  tile += TileOffsByDiagDir(dir);
276  } while (IsCompatibleTrainStationTile(tile, start_tile));
277 
278  return length;
279 }
280 
288 static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
289 {
290  assert(IsTileType(tile, MP_STATION));
291 
293  switch (GetStationType(tile)) {
294  case STATION_RAIL: return CA_TRAIN;
295  case STATION_OILRIG: return CA_UNMODIFIED;
296  case STATION_AIRPORT: return st->airport.GetSpec()->catchment;
297  case STATION_TRUCK: return CA_TRUCK;
298  case STATION_BUS: return CA_BUS;
299  case STATION_DOCK: return CA_DOCK;
300 
301  default: NOT_REACHED();
302  case STATION_BUOY:
303  case STATION_WAYPOINT: return CA_NONE;
304  }
305  } else {
306  switch (GetStationType(tile)) {
307  default: return CA_UNMODIFIED;
308  case STATION_BUOY:
309  case STATION_WAYPOINT: return CA_NONE;
310  }
311  }
312 }
313 
319 {
320  uint ret = CA_NONE;
321 
323  if (this->bus_stops != nullptr) ret = std::max<uint>(ret, CA_BUS);
324  if (this->truck_stops != nullptr) ret = std::max<uint>(ret, CA_TRUCK);
325  if (this->train_station.tile != INVALID_TILE) ret = std::max<uint>(ret, CA_TRAIN);
326  if (this->ship_station.tile != INVALID_TILE) ret = std::max<uint>(ret, CA_DOCK);
327  if (this->airport.tile != INVALID_TILE) ret = std::max<uint>(ret, this->airport.GetSpec()->catchment);
328  } else {
329  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) {
330  ret = CA_UNMODIFIED;
331  }
332  }
333 
334  return ret;
335 }
336 
342 {
343  assert(!this->rect.IsEmpty());
344 
345  /* Compute acceptance rectangle */
346  int catchment_radius = this->GetCatchmentRadius();
347 
348  Rect ret = {
349  std::max<int>(this->rect.left - catchment_radius, 0),
350  std::max<int>(this->rect.top - catchment_radius, 0),
351  std::min<int>(this->rect.right + catchment_radius, MapMaxX()),
352  std::min<int>(this->rect.bottom + catchment_radius, MapMaxY())
353  };
354 
355  return ret;
356 }
357 
365 {
366  /* Using DistanceMax to get about the same order as with previously used CircularTileSearch. */
367  uint distance = DistanceMax(this->xy, tile);
368 
369  /* Don't check further if this industry is already in the list but update the distance if it's closer */
370  auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
371  if (pos != this->industries_near.end()) {
372  if (pos->distance > distance) {
373  auto node = this->industries_near.extract(pos);
374  node.value().distance = distance;
375  this->industries_near.insert(std::move(node));
376  }
377  return;
378  }
379 
380  /* Include only industries that can accept cargo */
381  uint cargo_index;
382  for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
383  if (ind->accepts_cargo[cargo_index] != CT_INVALID) break;
384  }
385  if (cargo_index >= lengthof(ind->accepts_cargo)) return;
386 
387  this->industries_near.insert(IndustryListEntry{distance, ind});
388 }
389 
395  auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
396  if (pos != this->industries_near.end()) {
397  this->industries_near.erase(pos);
398  }
399 }
400 
401 
406 {
407  for (Town *t : Town::Iterate()) { t->stations_near.erase(this); }
408  for (Industry *i : Industry::Iterate()) { i->stations_near.erase(this); }
409 }
410 
418 bool Station::CatchmentCoversTown(TownID t) const
419 {
421  for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
422  if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) == t) return true;
423  }
424  return false;
425 }
426 
432 {
433  this->industries_near.clear();
434  this->RemoveFromAllNearbyLists();
435 
436  if (this->rect.IsEmpty()) {
437  this->catchment_tiles.Reset();
438  return;
439  }
440 
441  if (!_settings_game.station.serve_neutral_industries && this->industry != nullptr) {
442  /* Station is associated with an industry, so we only need to deliver to that industry. */
444  for (TileIndex tile : this->industry->location) {
445  if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->industry->index) {
446  this->catchment_tiles.SetTile(tile);
447  }
448  }
449  /* The industry's stations_near may have been computed before its neutral station was built so clear and re-add here. */
450  for (Station *st : this->industry->stations_near) {
452  }
453  this->industry->stations_near.clear();
454  this->industry->stations_near.insert(this);
455  this->industries_near.insert(IndustryListEntry{0, this->industry});
456  return;
457  }
458 
460 
461  /* Loop finding all station tiles */
462  TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom));
463  for (TileIndex tile : ta) {
464  if (!IsTileType(tile, MP_STATION) || GetStationIndex(tile) != this->index) continue;
465 
466  uint r = GetTileCatchmentRadius(tile, this);
467  if (r == CA_NONE) continue;
468 
469  /* This tile sub-loop doesn't need to test any tiles, they are simply added to the catchment set. */
470  TileArea ta2 = TileArea(tile, 1, 1).Expand(r);
471  for (TileIndex tile2 : ta2) this->catchment_tiles.SetTile(tile2);
472  }
473 
474  /* Search catchment tiles for towns and industries */
476  for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
477  if (IsTileType(tile, MP_HOUSE)) {
478  Town *t = Town::GetByTile(tile);
479  t->stations_near.insert(this);
480  }
481  if (IsTileType(tile, MP_INDUSTRY)) {
482  Industry *i = Industry::GetByTile(tile);
483 
484  /* Ignore industry if it has a neutral station. It already can't be this station. */
485  if (!_settings_game.station.serve_neutral_industries && i->neutral_station != nullptr) continue;
486 
487  i->stations_near.insert(this);
488 
489  /* Add if we can deliver to this industry as well */
490  this->AddIndustryToDeliver(i, tile);
491  }
492  }
493 }
494 
500 {
501  for (Station *st : Station::Iterate()) { st->RecomputeCatchment(); }
502 }
503 
504 /************************************************************************/
505 /* StationRect implementation */
506 /************************************************************************/
507 
508 StationRect::StationRect()
509 {
510  this->MakeEmpty();
511 }
512 
513 void StationRect::MakeEmpty()
514 {
515  this->left = this->top = this->right = this->bottom = 0;
516 }
517 
527 bool StationRect::PtInExtendedRect(int x, int y, int distance) const
528 {
529  return this->left - distance <= x && x <= this->right + distance &&
530  this->top - distance <= y && y <= this->bottom + distance;
531 }
532 
533 bool StationRect::IsEmpty() const
534 {
535  return this->left == 0 || this->left > this->right || this->top > this->bottom;
536 }
537 
538 CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
539 {
540  int x = TileX(tile);
541  int y = TileY(tile);
542  if (this->IsEmpty()) {
543  /* we are adding the first station tile */
544  if (mode != ADD_TEST) {
545  this->left = this->right = x;
546  this->top = this->bottom = y;
547  }
548  } else if (!this->PtInExtendedRect(x, y)) {
549  /* current rect is not empty and new point is outside this rect
550  * make new spread-out rectangle */
551  Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
552 
553  /* check new rect dimensions against preset max */
554  int w = new_rect.right - new_rect.left + 1;
555  int h = new_rect.bottom - new_rect.top + 1;
556  if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
557  assert(mode != ADD_TRY);
558  return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
559  }
560 
561  /* spread-out ok, return true */
562  if (mode != ADD_TEST) {
563  /* we should update the station rect */
564  *this = new_rect;
565  }
566  } else {
567  ; // new point is inside the rect, we don't need to do anything
568  }
569  return CommandCost();
570 }
571 
572 CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
573 {
574  if (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) {
575  /* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
576  CommandCost ret = this->BeforeAddTile(tile, mode);
577  if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
578  return ret;
579  }
580  return CommandCost();
581 }
582 
592 /* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
593 {
594  TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
595  for (TileIndex tile : ta) {
596  if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
597  }
598 
599  return false;
600 }
601 
602 bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
603 {
604  int x = TileX(tile);
605  int y = TileY(tile);
606 
607  /* look if removed tile was on the bounding rect edge
608  * and try to reduce the rect by this edge
609  * do it until we have empty rect or nothing to do */
610  for (;;) {
611  /* check if removed tile is on rect edge */
612  bool left_edge = (x == this->left);
613  bool right_edge = (x == this->right);
614  bool top_edge = (y == this->top);
615  bool bottom_edge = (y == this->bottom);
616 
617  /* can we reduce the rect in either direction? */
618  bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, this->top, x, this->bottom));
619  bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->index, this->left, y, this->right, y));
620  if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce)
621 
622  if (reduce_x) {
623  /* reduce horizontally */
624  if (left_edge) {
625  /* move left edge right */
626  this->left = x = x + 1;
627  } else {
628  /* move right edge left */
629  this->right = x = x - 1;
630  }
631  }
632  if (reduce_y) {
633  /* reduce vertically */
634  if (top_edge) {
635  /* move top edge down */
636  this->top = y = y + 1;
637  } else {
638  /* move bottom edge up */
639  this->bottom = y = y - 1;
640  }
641  }
642 
643  if (left > right || top > bottom) {
644  /* can't continue, if the remaining rectangle is empty */
645  this->MakeEmpty();
646  return true; // empty remaining rect
647  }
648  }
649  return false; // non-empty remaining rect
650 }
651 
652 bool StationRect::AfterRemoveRect(BaseStation *st, TileArea ta)
653 {
654  assert(this->PtInExtendedRect(TileX(ta.tile), TileY(ta.tile)));
655  assert(this->PtInExtendedRect(TileX(ta.tile) + ta.w - 1, TileY(ta.tile) + ta.h - 1));
656 
657  bool empty = this->AfterRemoveTile(st, ta.tile);
658  if (ta.w != 1 || ta.h != 1) empty = empty || this->AfterRemoveTile(st, TILE_ADDXY(ta.tile, ta.w - 1, ta.h - 1));
659  return empty;
660 }
661 
662 StationRect& StationRect::operator = (const Rect &src)
663 {
664  this->left = src.left;
665  this->top = src.top;
666  this->right = src.right;
667  this->bottom = src.bottom;
668  return *this;
669 }
670 
677 {
678  Money total_cost = 0;
679 
680  for (const Station *st : Station::Iterate()) {
681  if (st->owner == owner && (st->facilities & FACIL_AIRPORT)) {
682  total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
683  }
684  }
685  /* 3 bits fraction for the maintenance cost factor. */
686  return total_cost >> 3;
687 }
688 
689 bool StationCompare::operator() (const Station *lhs, const Station *rhs) const
690 {
691  return lhs->index < rhs->index;
692 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
RoadVehicle
Buses, trucks and trams belong to this class.
Definition: roadveh.h:107
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:63
CA_UNMODIFIED
@ CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition: station_type.h:83
WC_ROADVEH_LIST
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
Definition: window_type.h:306
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:3234
Station::goods
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:483
HasTileAnyRoadType
static bool HasTileAnyRoadType(TileIndex t, RoadTypes rts)
Check if a tile has one of the specified road types.
Definition: road_map.h:222
StationRect
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
Definition: base_station_base.h:29
station_kdtree.h
TileOffsByDiagDir
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
GameSettings::station
StationSettings station
settings related to station management
Definition: settings_type.h:592
BitmapTileArea::Initialize
void Initialize(const Rect &r)
Initialize the BitmapTileArea with the specified Rect.
Definition: bitmap_type.h:58
CargoList::OnCleanPool
void OnCleanPool()
Empty the cargo list, but don't free the cargo packets; the cargo packets are cleaned by CargoPacket'...
Definition: cargopacket.cpp:167
LinkGraph
A connected component of a link graph.
Definition: linkgraph.h:39
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:266
ROADSTOP_TRUCK
@ ROADSTOP_TRUCK
A standard stop for trucks.
Definition: station_type.h:46
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:3584
Pool::PoolItem<&_link_graph_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
CA_NONE
@ CA_NONE
Catchment when the station has no facilities.
Definition: station_type.h:77
Kdtree
K-dimensional tree, specialised for 2-dimensional space.
Definition: kdtree.hpp:37
VehicleListIdentifier
The information about a vehicle list.
Definition: vehiclelist.h:29
BitmapTileArea::SetTile
void SetTile(TileIndex tile)
Add a tile as part of the tile area.
Definition: bitmap_type.h:80
company_base.h
RoadStop::xy
TileIndex xy
Position on the map.
Definition: roadstop_base.h:67
Station
Station data structure.
Definition: station_base.h:454
Station::RecomputeCatchment
void RecomputeCatchment()
Recompute tiles covered in our catchment area.
Definition: station.cpp:431
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:127
SpecializedStation
Class defining several overloaded accessors so we don't have to cast base stations that often.
Definition: base_station_base.h:182
_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:936
vehiclelist.h
BitmapTileIterator
Iterator to iterate over all tiles belonging to a bitmaptilearea.
Definition: bitmap_type.h:107
LinkGraphSchedule::instance
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Definition: linkgraphschedule.h:52
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:83
Pool::PoolItem<&_station_pool >::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
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:527
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
IsCompatibleTrainStationTile
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:378
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Station::MoveSign
void MoveSign(TileIndex new_xy) override
Move the station main coordinate somewhere else.
Definition: station_cmd.cpp:438
IsStandardRoadStopTile
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
Definition: station_map.h:223
aircraft.h
FACIL_NONE
@ FACIL_NONE
The station has no facilities at all.
Definition: station_type.h:52
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:219
MP_INDUSTRY
@ MP_INDUSTRY
Part of an industry.
Definition: tile_type.h:56
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
GetTileCatchmentRadius
static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
Get the catchment size of an individual station tile.
Definition: station.cpp:288
LinkGraph::Size
NodeID Size() const
Get the current size of the component.
Definition: linkgraph.h:508
WC_STATION_VIEW
@ WC_STATION_VIEW
Station view; Window numbers:
Definition: window_type.h:337
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
Industry
Defines the internal data of a functional industry.
Definition: industry.h:66
Station::CatchmentCoversTown
bool CatchmentCoversTown(TownID t) const
Test if the given town ID is covered by our catchment area.
Definition: station.cpp:418
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:128
Kdtree::Build
void Build(It begin, It end)
Clear and rebuild the tree from a new sequence of elements,.
Definition: kdtree.hpp:364
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:62
GetTownIndex
static TownID GetTownIndex(TileIndex t)
Get the index of which town this house/street is attached to.
Definition: town_map.h:22
Industry::neutral_station
Station * neutral_station
Associated neutral station.
Definition: industry.h:69
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:151
BaseStation::num_specs
uint8 num_specs
Number of specs in the speclist.
Definition: base_station_base.h:65
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition: kdtree.hpp:419
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:270
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
GoodsEntry::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:252
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:4623
StationSettings::serve_neutral_industries
bool serve_neutral_industries
company stations can serve industries with attached neutral stations
Definition: settings_type.h:553
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
BaseStation::sign
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
Definition: base_station_base.h:54
Industry::stations_near
StationList stations_near
NOSAVE: List of nearby stations.
Definition: industry.h:91
CommandCost
Common return value for all commands.
Definition: command_type.h:24
Industry::location
TileArea location
Location of the industry.
Definition: industry.h:67
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition: base_station_base.h:75
Industry::GetByTile
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:144
Station::RecomputeCatchmentForAll
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition: station.cpp:499
BaseStation::random_bits
uint16 random_bits
Random bits assigned to this station.
Definition: base_station_base.h:70
roadstop_base.h
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition: base_station_base.h:76
TileIndexDiff
int32 TileIndexDiff
An offset value between two tiles.
Definition: map_func.h:154
Station::MarkTilesDirty
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
Definition: station.cpp:217
BitmapTileArea::Reset
void Reset()
Reset and clear the BitmapTileArea.
Definition: bitmap_type.h:46
OrthogonalTileArea::w
uint16 w
The width of the area.
Definition: tilearea_type.h:20
Town::stations_near
StationList stations_near
NOSAVE: List of nearby stations.
Definition: town.h:83
GetStationType
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
Definition: station_map.h:44
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:468
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:201
Station::TileBelongsToRailStation
bool TileBelongsToRailStation(TileIndex tile) const override
Check whether a specific tile belongs to this station.
Definition: station_base.h:519
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
ViewportSign::MarkDirty
void MarkDirty(ZoomLevel maxzoom=ZOOM_LVL_MAX) const
Mark the sign dirty in all viewports.
Definition: viewport.cpp:1472
Station::~Station
~Station()
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
Definition: station.cpp:86
industry.h
safeguards.h
CA_BUS
@ CA_BUS
Catchment for bus stops with "modified catchment" enabled.
Definition: station_type.h:78
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:312
RoadVehicle::compatible_roadtypes
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Definition: roadveh.h:118
AirportMaintenanceCost
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Definition: station.cpp:676
CA_TRUCK
@ CA_TRUCK
Catchment for truck stops with "modified catchment" enabled.
Definition: station_type.h:79
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:77
WC_TRAINS_LIST
@ WC_TRAINS_LIST
Trains list; Window numbers:
Definition: window_type.h:300
StationSettings::station_spread
byte station_spread
amount a station may spread
Definition: settings_type.h:557
date_func.h
IsRailStationTile
static bool IsRailStationTile(TileIndex t)
Is this tile a station tile and a rail station?
Definition: station_map.h:102
linkgraphschedule.h
stdafx.h
Station::truck_stops
RoadStop * truck_stops
All the truck stops.
Definition: station_base.h:465
Station::industry
Industry * industry
NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
Definition: station_base.h:487
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:592
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
StationFacility
StationFacility
The facilities a station might be having.
Definition: station_type.h:51
OrthogonalTileArea::h
uint16 h
The height of the area.
Definition: tilearea_type.h:21
DistanceMax
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Definition: map.cpp:189
CA_DOCK
@ CA_DOCK
Catchment for docks with "modified catchment" enabled.
Definition: station_type.h:81
ROADSTOP_BUS
@ ROADSTOP_BUS
A standard stop for buses.
Definition: station_type.h:45
Station::industries_near
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
Definition: station_base.h:486
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition: window_type.h:234
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:386
Pool
Base class for all pools.
Definition: pool_type.hpp:81
MapMaxY
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
INVALID_DATE
static const Date INVALID_DATE
Representation of an invalid date.
Definition: date_type.h:111
GetRailStationAxis
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:337
GoodsEntry::flows
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:256
Station::GetCatchmentRadius
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
Definition: station.cpp:318
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:1765
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:3251
GetIndustryIndex
static IndustryID GetIndustryIndex(TileIndex t)
Get the industry ID of the given tile.
Definition: industry_map.h:63
Pool::PoolItem<&_station_pool >::CleaningPool
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:316
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:1988
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
TileDiffXY
static TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition: map_func.h:179
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:53
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
Vehicle::HasArticulatedPart
bool HasArticulatedPart() const
Check if an engine has an articulated part.
Definition: vehicle_base.h:921
TrackedViewportSign::kdtree_valid
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Definition: viewport_type.h:58
Station::GetCatchmentRect
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
Definition: station.cpp:341
Station::RemoveIndustryToDeliver
void RemoveIndustryToDeliver(Industry *ind)
Remove nearby industry from station's industries_near list.
Definition: station.cpp:394
linkgraph.h
Station::catchment_tiles
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
Definition: station_base.h:474
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:53
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:52
IndustryListEntry
Definition: station_base.h:440
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:1239
MapMaxX
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:224
AXIS_X
@ AXIS_X
The X axis.
Definition: direction_type.h:126
TILE_ADDXY
#define TILE_ADDXY(tile, x, y)
Adds a given offset to a tile.
Definition: map_func.h:258
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:102
BaseStation::speclist
StationSpecList * speclist
List of station specs of this station.
Definition: base_station_base.h:66
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Station::RemoveFromAllNearbyLists
void RemoveFromAllNearbyLists()
Remove this station from the nearby stations lists of all towns and industries.
Definition: station.cpp:405
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:170
CA_TRAIN
@ CA_TRAIN
Catchment for train stations with "modified catchment" enabled.
Definition: station_type.h:80
random_func.hpp
OverflowSafeInt< int64 >
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:81
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:463
LinkGraphSchedule::Unqueue
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Definition: linkgraphschedule.h:77
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
Industry::accepts_cargo
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
Definition: industry.h:75
RoadStop
A Stop for a Road Vehicle.
Definition: roadstop_base.h:22
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition: station_type.h:56
Airport::psa
PersistentStorage * psa
Persistent storage for NewGRF airports.
Definition: station_base.h:310
Airport::GetSpec
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Definition: station_base.h:317
pool_func.hpp
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
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:47
WC_AIRCRAFT_LIST
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Definition: window_type.h:318
BaseStation::build_date
Date build_date
Date of construction.
Definition: base_station_base.h:68
WC_STATION_LIST
@ WC_STATION_LIST
Station list; Window numbers:
Definition: window_type.h:294
AirportSpec::catchment
byte catchment
catchment area of this airport
Definition: newgrf_airport.h:108
StationCargoList::Truncate
uint Truncate(uint max_move=UINT_MAX, StationCargoAmountMap *cargo_per_source=nullptr)
Truncates where each destination loses roughly the same percentage of its cargo.
Definition: cargopacket.cpp:769
Station::ship_station
TileArea ship_station
Tile area the ship 'station' part covers.
Definition: station_base.h:469
Station::AddIndustryToDeliver
void AddIndustryToDeliver(Industry *ind, TileIndex tile)
Add nearby industry to station's industries_near list if it accepts cargo.
Definition: station.cpp:364
StationSettings::modified_catchment
bool modified_catchment
different-size catchment areas
Definition: settings_type.h:552
news_func.h
roadveh.h