OpenTTD Source 20260311-master-g511d3794ce
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "core/flatset_type.hpp"
12#include "company_func.h"
13#include "company_base.h"
14#include "roadveh.h"
15#include "viewport_func.h"
16#include "viewport_kdtree.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
36StationPool _station_pool("Station");
38
39
40StationKdtree _station_kdtree{};
41
42void 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
63
64Station::Station(StationID index, TileIndex tile) :
65 SpecializedStation<Station, false>(index, tile),
66 bus_station(INVALID_TILE, 0, 0),
67 truck_station(INVALID_TILE, 0, 0),
68 ship_station(INVALID_TILE, 0, 0),
69 indtype(IT_INVALID),
70 time_since_load(255),
71 time_since_unload(255),
72 last_vehicle_type(VEH_INVALID)
73{
74 /* this->random_bits is set in Station::AddFacility() */
75}
76
85{
86 if (CleaningPool()) {
87 for (GoodsEntry &ge : this->goods) {
88 if (!ge.HasData()) continue;
89 ge.GetData().cargo.OnCleanPool();
90 }
91 return;
92 }
93
94 while (!this->loading_vehicles.empty()) {
95 this->loading_vehicles.front()->LeaveStation();
96 }
97
98 for (Aircraft *a : Aircraft::Iterate()) {
99 if (!a->IsNormalAircraft()) continue;
100 if (a->targetairport == this->index) a->targetairport = StationID::Invalid();
101 }
102
103 for (CargoType cargo = 0; cargo < NUM_CARGO; ++cargo) {
104 LinkGraph *lg = LinkGraph::GetIfValid(this->goods[cargo].link_graph);
105 if (lg == nullptr) continue;
106
107 for (NodeID node = 0; node < lg->Size(); ++node) {
108 Station *st = Station::Get((*lg)[node].station);
109 if (!st->goods[cargo].HasData()) continue;
110 st->goods[cargo].GetData().flows.erase(this->index);
111 if ((*lg)[node].HasEdgeTo(this->goods[cargo].node) && (*lg)[node][this->goods[cargo].node].LastUpdate() != EconomyTime::INVALID_DATE) {
112 st->goods[cargo].GetData().flows.DeleteFlows(this->index);
113 RerouteCargo(st, cargo, this->index, st->index);
114 }
115 }
116 lg->RemoveNode(this->goods[cargo].node);
117 if (lg->Size() == 0) {
118 LinkGraphSchedule::instance.Dequeue(lg);
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 = StationID::Invalid();
127 }
128 if (v->last_loading_station == this->index) {
129 v->last_loading_station = StationID::Invalid();
130 }
131 }
132
133 /* Remove station from industries and towns that reference it. */
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 */
153
154 for (GoodsEntry &ge : this->goods) {
155 if (!ge.HasData()) continue;
156 ge.GetData().cargo.Truncate();
157 }
158
160
161 _station_kdtree.Remove(this->index);
162 if (this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
163}
164
165
171void BaseStation::PostDestructor([[maybe_unused]] size_t index)
172{
174}
175
176bool BaseStation::SetRoadStopTileData(TileIndex tile, uint8_t data, bool animation)
177{
178 for (RoadStopTileData &tile_data : this->custom_roadstop_tile_data) {
179 if (tile_data.tile == tile) {
180 uint8_t &v = animation ? tile_data.animation_frame : tile_data.random_bits;
181 if (v == data) return false;
182 v = data;
183 return true;
184 }
185 }
186 RoadStopTileData tile_data;
187 tile_data.tile = tile;
188 tile_data.animation_frame = animation ? data : 0;
189 tile_data.random_bits = animation ? 0 : data;
190 this->custom_roadstop_tile_data.push_back(tile_data);
191 return data != 0;
192}
193
194void BaseStation::RemoveRoadStopTileData(TileIndex tile)
195{
196 for (RoadStopTileData &tile_data : this->custom_roadstop_tile_data) {
197 if (tile_data.tile == tile) {
198 tile_data = this->custom_roadstop_tile_data.back();
199 this->custom_roadstop_tile_data.pop_back();
200 return;
201 }
202 }
203}
204
210RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const
211{
212 RoadStop *rs = this->GetPrimaryRoadStop(v->IsBus() ? RoadStopType::Bus : RoadStopType::Truck);
213
214 for (; rs != nullptr; rs = rs->next) {
215 /* The vehicle cannot go to this roadstop (different roadtype) */
216 if (!HasTileAnyRoadType(rs->xy, v->compatible_roadtypes)) continue;
217 /* The vehicle is articulated and can therefore not go to a standard road stop. */
218 if (IsBayRoadStopTile(rs->xy) && v->HasArticulatedPart()) continue;
219
220 /* The vehicle can actually go to this road stop. So, return it! */
221 break;
222 }
223
224 return rs;
225}
226
233void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
234{
235 if (this->facilities.None()) {
236 this->MoveSign(facil_xy);
237 this->random_bits = Random();
238 }
239 this->facilities.Set(new_facility_bit);
240 this->owner = _current_company;
243}
244
250void Station::MarkTilesDirty(bool cargo_change) const
251{
252 if (this->train_station.tile == INVALID_TILE) return;
253
254 /* cargo_change is set if we're refreshing the tiles due to cargo moving
255 * around. */
256 if (cargo_change) {
257 /* Don't waste time updating if there are no custom station graphics
258 * that might change. Even if there are custom graphics, they might
259 * not change. Unfortunately we have no way of telling. */
260 if (this->speclist.empty()) return;
261 }
262
263 for (TileIndex tile : this->train_station) {
264 if (this->TileBelongsToRailStation(tile)) {
266 }
267 }
268}
269
270/* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
271{
272 assert(this->TileBelongsToRailStation(tile));
273
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
314static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
315{
316 assert(IsTileType(tile, TileType::Station));
317
318 if (_settings_game.station.modified_catchment) {
319 switch (GetStationType(tile)) {
320 case StationType::Rail: return CA_TRAIN;
322 case StationType::Airport: return st->airport.GetSpec()->catchment;
323 case StationType::Truck: return CA_TRUCK;
324 case StationType::Bus: return CA_BUS;
325 case StationType::Dock: return CA_DOCK;
326
327 default: NOT_REACHED();
331 }
332 } else {
333 switch (GetStationType(tile)) {
334 default: return CA_UNMODIFIED;
338 }
339 }
340}
341
347{
348 uint ret = CA_NONE;
349
350 if (_settings_game.station.modified_catchment) {
351 if (this->bus_stops != nullptr) ret = std::max<uint>(ret, CA_BUS);
352 if (this->truck_stops != nullptr) ret = std::max<uint>(ret, CA_TRUCK);
353 if (this->train_station.tile != INVALID_TILE) ret = std::max<uint>(ret, CA_TRAIN);
354 if (this->ship_station.tile != INVALID_TILE) ret = std::max<uint>(ret, CA_DOCK);
355 if (this->airport.tile != INVALID_TILE) ret = std::max<uint>(ret, this->airport.GetSpec()->catchment);
356 } else {
357 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) {
358 ret = CA_UNMODIFIED;
359 }
360 }
361
362 return ret;
363}
364
370{
371 assert(!this->rect.IsEmpty());
372
373 /* Compute acceptance rectangle */
374 int catchment_radius = this->GetCatchmentRadius();
375
376 Rect ret = {
377 std::max<int>(this->rect.left - catchment_radius, 0),
378 std::max<int>(this->rect.top - catchment_radius, 0),
379 std::min<int>(this->rect.right + catchment_radius, Map::MaxX()),
380 std::min<int>(this->rect.bottom + catchment_radius, Map::MaxY())
381 };
382
383 return ret;
384}
385
393{
394 /* Using DistanceMax to get about the same order as with previously used SpiralTileSequence. */
395 uint distance = DistanceMax(this->xy, tile);
396
397 /* Don't check further if this industry is already in the list but update the distance if it's closer */
398 auto pos = std::ranges::find(this->industries_near, ind, &IndustryListEntry::industry);
399 if (pos != this->industries_near.end()) {
400 if (pos->distance > distance) {
401 auto node = this->industries_near.extract(pos);
402 node.value().distance = distance;
403 this->industries_near.insert(std::move(node));
404 }
405 return;
406 }
407
408 /* Include only industries that can accept cargo */
409 if (!ind->IsCargoAccepted()) return;
410
411 this->industries_near.insert(IndustryListEntry{distance, ind});
412}
413
419{
420 auto pos = std::ranges::find(this->industries_near, ind, &IndustryListEntry::industry);
421 if (pos != this->industries_near.end()) {
422 this->industries_near.erase(pos);
423 }
424}
425
426
431{
432 FlatSet<TownID> towns;
433 FlatSet<IndustryID> industries;
434
435 for (const auto &tile : this->catchment_tiles) {
436 TileType type = GetTileType(tile);
437 if (type == TileType::House) {
438 towns.insert(GetTownIndex(tile));
439 } else if (type == TileType::Industry) {
440 industries.insert(GetIndustryIndex(tile));
441 }
442 }
443
444 for (const TownID &townid : towns) { Town::Get(townid)->stations_near.erase(this); }
445 for (const IndustryID &industryid : industries) { Industry::Get(industryid)->stations_near.erase(this); }
446}
447
456{
458 for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
459 if (IsTileType(tile, TileType::House) && GetTownIndex(tile) == t) return true;
460 }
461 return false;
462}
463
469void Station::RecomputeCatchment(bool no_clear_nearby_lists)
470{
471 this->industries_near.clear();
472 if (!no_clear_nearby_lists) this->RemoveFromAllNearbyLists();
473
474 if (this->rect.IsEmpty()) {
475 this->catchment_tiles.Reset();
476 return;
477 }
478
479 if (!_settings_game.station.serve_neutral_industries && this->industry != nullptr) {
480 /* Station is associated with an industry, so we only need to deliver to that industry. */
481 this->catchment_tiles.Initialize(this->industry->location);
482 for (TileIndex tile : this->industry->location) {
483 if (IsTileType(tile, TileType::Industry) && GetIndustryIndex(tile) == this->industry->index) {
484 this->catchment_tiles.SetTile(tile);
485 }
486 }
487 /* The industry's stations_near may have been computed before its neutral station was built so clear and re-add here. */
488 for (Station *st : this->industry->stations_near) {
490 }
491 this->industry->stations_near.clear();
492 this->industry->stations_near.insert(this);
493 this->industries_near.insert(IndustryListEntry{0, this->industry});
494 return;
495 }
496
497 this->catchment_tiles.Initialize(GetCatchmentRect());
498
499 /* Loop finding all station tiles */
500 TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom));
501 for (TileIndex tile : ta) {
502 if (!IsTileType(tile, TileType::Station) || GetStationIndex(tile) != this->index) continue;
503
504 uint r = GetTileCatchmentRadius(tile, this);
505 if (r == CA_NONE) continue;
506
507 /* This tile sub-loop doesn't need to test any tiles, they are simply added to the catchment set. */
508 TileArea ta2 = TileArea(tile, 1, 1).Expand(r);
509 for (TileIndex tile2 : ta2) this->catchment_tiles.SetTile(tile2);
510 }
511
512 /* Search catchment tiles for towns and industries */
514 for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
515 if (IsTileType(tile, TileType::House)) {
516 Town *t = Town::GetByTile(tile);
517 t->stations_near.insert(this);
518 }
519 if (IsTileType(tile, TileType::Industry)) {
520 Industry *i = Industry::GetByTile(tile);
521
522 /* Ignore industry if it has a neutral station. It already can't be this station. */
523 if (!_settings_game.station.serve_neutral_industries && i->neutral_station != nullptr) continue;
524
525 i->stations_near.insert(this);
526
527 /* Add if we can deliver to this industry as well */
528 this->AddIndustryToDeliver(i, tile);
529 }
530 }
531}
532
538{
539 for (Town *t : Town::Iterate()) { t->stations_near.clear(); }
540 for (Industry *i : Industry::Iterate()) { i->stations_near.clear(); }
541 for (Station *st : Station::Iterate()) { st->RecomputeCatchment(true); }
542}
543
544/************************************************************************/
545/* StationRect implementation */
546/************************************************************************/
547
548StationRect::StationRect()
549{
550 this->MakeEmpty();
551}
552
553void StationRect::MakeEmpty()
554{
555 this->left = this->top = this->right = this->bottom = 0;
556}
557
567bool StationRect::PtInExtendedRect(int x, int y, int distance) const
568{
569 return this->left - distance <= x && x <= this->right + distance &&
570 this->top - distance <= y && y <= this->bottom + distance;
571}
572
573bool StationRect::IsEmpty() const
574{
575 return this->left == 0 || this->left > this->right || this->top > this->bottom;
576}
577
578CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
579{
580 int x = TileX(tile);
581 int y = TileY(tile);
582 if (this->IsEmpty()) {
583 /* we are adding the first station tile */
584 if (mode != ADD_TEST) {
585 this->left = this->right = x;
586 this->top = this->bottom = y;
587 }
588 } else if (!this->PtInExtendedRect(x, y)) {
589 /* current rect is not empty and new point is outside this rect
590 * make new spread-out rectangle */
591 Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
592
593 /* check new rect dimensions against preset max */
594 int w = new_rect.Width();
595 int h = new_rect.Height();
596 if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
597 assert(mode != ADD_TRY);
598 return CommandCost(STR_ERROR_STATION_TOO_SPREAD_OUT);
599 }
600
601 /* spread-out ok, return true */
602 if (mode != ADD_TEST) {
603 /* we should update the station rect */
604 *this = new_rect;
605 }
606 } else {
607 ; // new point is inside the rect, we don't need to do anything
608 }
609 return CommandCost();
610}
611
612CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
613{
614 if (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) {
615 /* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
616 CommandCost ret = this->BeforeAddTile(tile, mode);
617 if (ret.Succeeded()) ret = this->BeforeAddTile(TileAddXY(tile, w - 1, h - 1), mode);
618 return ret;
619 }
620 return CommandCost();
621}
622
632/* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
633{
634 TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
635 for (TileIndex tile : ta) {
636 if (IsTileType(tile, TileType::Station) && GetStationIndex(tile) == st_id) return true;
637 }
638
639 return false;
640}
641
642bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
643{
644 int x = TileX(tile);
645 int y = TileY(tile);
646
647 /* look if removed tile was on the bounding rect edge
648 * and try to reduce the rect by this edge
649 * do it until we have empty rect or nothing to do */
650 for (;;) {
651 /* check if removed tile is on rect edge */
652 bool left_edge = (x == this->left);
653 bool right_edge = (x == this->right);
654 bool top_edge = (y == this->top);
655 bool bottom_edge = (y == this->bottom);
656
657 /* can we reduce the rect in either direction? */
658 bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, this->top, x, this->bottom));
659 bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->index, this->left, y, this->right, y));
660 if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce)
661
662 if (reduce_x) {
663 /* reduce horizontally */
664 if (left_edge) {
665 /* move left edge right */
666 this->left = x = x + 1;
667 } else {
668 /* move right edge left */
669 this->right = x = x - 1;
670 }
671 }
672 if (reduce_y) {
673 /* reduce vertically */
674 if (top_edge) {
675 /* move top edge down */
676 this->top = y = y + 1;
677 } else {
678 /* move bottom edge up */
679 this->bottom = y = y - 1;
680 }
681 }
682
683 if (left > right || top > bottom) {
684 /* can't continue, if the remaining rectangle is empty */
685 this->MakeEmpty();
686 return true; // empty remaining rect
687 }
688 }
689 return false; // non-empty remaining rect
690}
691
692bool StationRect::AfterRemoveRect(BaseStation *st, TileArea ta)
693{
694 assert(this->PtInExtendedRect(TileX(ta.tile), TileY(ta.tile)));
695 assert(this->PtInExtendedRect(TileX(ta.tile) + ta.w - 1, TileY(ta.tile) + ta.h - 1));
696
697 bool empty = this->AfterRemoveTile(st, ta.tile);
698 if (ta.w != 1 || ta.h != 1) empty = empty || this->AfterRemoveTile(st, TileAddXY(ta.tile, ta.w - 1, ta.h - 1));
699 return empty;
700}
701
702StationRect& StationRect::operator = (const Rect &src)
703{
704 this->left = src.left;
705 this->top = src.top;
706 this->right = src.right;
707 this->bottom = src.bottom;
708 return *this;
709}
710
716Money AirportMaintenanceCost(Owner owner)
717{
718 Money total_cost = 0;
719
720 for (const Station *st : Station::Iterate()) {
721 if (st->owner == owner && st->facilities.Test(StationFacility::Airport)) {
722 total_cost += _price[Price::InfrastructureAirport] * st->airport.GetSpec()->maintenance_cost;
723 }
724 }
725 /* 3 bits fraction for the maintenance cost factor. */
726 return total_cost >> 3;
727}
728
729bool StationCompare::operator() (const Station *lhs, const Station *rhs) const
730{
731 return lhs->index < rhs->index;
732}
Base for aircraft.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:73
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Iterator to iterate over all tiles belonging to a bitmaptilearea.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
Flat set implementation that uses a sorted vector for storage.
std::pair< const_iterator, bool > insert(const Tkey &key)
Insert a key into the set, if it does not already exist.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
A connected component of a link graph.
Definition linkgraph.h:37
NodeID Size() const
Get the current size of the component.
Definition linkgraph.h:234
void RemoveNode(NodeID id)
Remove a node from the link graph by overwriting it with the last node.
static Date date
Current date in days (day counter).
static constexpr TimerGame< struct Economy >::Date INVALID_DATE
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_END
Used for iterations.
Prices _price
Prices and also the fractional part.
Definition economy.cpp:106
@ InfrastructureAirport
Airports maintenance cost.
Flat set container implementation.
void MarkTilesDirty(bool cargo_change) const
Marks the tiles of the station as dirty.
Definition station.cpp:250
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Base of all industries.
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
Declaration of link graph classes used for cargo distribution.
Declaration of link graph schedule used for cargo distribution.
#define Rect
Macro that prevents name conflicts between included headers.
uint DistanceMax(TileIndex t0, TileIndex t1)
Gets the biggest distance component (x or y) between the two given tiles.
Definition map.cpp:201
TileIndex TileAddXY(TileIndex tile, int x, int y)
Adds a given offset to a tile.
Definition map_func.h:474
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
Definition map_func.h:559
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:376
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:429
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:419
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:574
int32_t TileIndexDiff
An offset value between two tiles.
Definition map_type.h:23
Functions related to news.
void DeleteStationNews(StationID sid)
Remove news regarding given station so there are no 'unknown station now accepts Mail' or 'First trai...
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Pseudo random number generator.
bool HasTileAnyRoadType(Tile t, RoadTypes rts)
Check if a tile has one of the specified road types.
Definition road_map.h:232
Base class for roadstops.
Road vehicle states.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
StationPool _station_pool("Station")
The pool of stations.
Money AirportMaintenanceCost(Owner owner)
Calculates the maintenance cost of all airports of a company.
Definition station.cpp:716
static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
Get the catchment size of an individual station tile.
Definition station.cpp:314
Base classes/functions for stations.
void RerouteCargo(Station *st, CargoType cargo, StationID avoid, StationID avoid2)
Reroute cargo of type c at station st or in any vehicles unloading there.
Declarations for accessing the k-d tree of stations.
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition station_map.h:44
bool IsBayRoadStopTile(Tile t)
Is tile t a bay (non-drive through) road stop station?
bool IsCompatibleTrainStationTile(Tile test_tile, Tile station_tile)
Check if a tile is a valid continuation to a railstation tile.
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
static constexpr uint CA_TRAIN
Catchment for train stations with "modified catchment" enabled.
@ Bus
A standard stop for buses.
@ Truck
A standard stop for trucks.
StationFacility
The facilities a station might be having.
@ Airport
Station with an airport.
static constexpr uint CA_NONE
Catchment when the station has no facilities.
@ Dock
Ship port.
@ Rail
Railways/train station.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ RailWaypoint
Waypoint for trains.
@ Buoy
Waypoint for ships.
@ RoadWaypoint
Waypoint for trucks and busses.
@ Oilrig
Heliport on an oil rig.
@ Airport
Airports and heliports, excluding the ones on oil rigs.
static constexpr uint CA_DOCK
Catchment for docks with "modified catchment" enabled.
static constexpr uint CA_BUS
Catchment for bus stops with "modified catchment" enabled.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
static constexpr uint CA_TRUCK
Catchment for truck stops with "modified catchment" enabled.
Definition of base types and functions in a cross-platform compatible way.
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition aircraft.h:73
uint8_t catchment
catchment area of this airport
const AirportSpec * GetSpec() const
Get the AirportSpec that from the airport type of this airport.
Base class for all station-ish types.
TileIndex xy
Base tile of the station.
std::vector< SpecMapping< StationSpec > > speclist
List of rail station specs of this station.
StationFacilities facilities
The facilities that this station has.
virtual ~BaseStation()
Ensure the destructor of the sub classes are called as well.
Definition station.cpp:52
TileArea train_station
Tile area the train 'station' part covers.
Owner owner
The owner of this station.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
static void PostDestructor(size_t index)
Invalidating of the JoinStation window has to be done after removing item from the pool.
Definition station.cpp:171
uint16_t random_bits
Random bits assigned to this station.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
std::vector< RoadStopTileData > custom_roadstop_tile_data
List of custom road stop tile data.
TimerGameCalendar::Date build_date
Date of construction.
static void InvalidateAllFrom(Source src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
StationSettings station
settings related to station management
Stores station stats for a single cargo.
Defines the internal data of a functional industry.
Definition industry.h:62
bool IsCargoAccepted() const
Test if this industry accepts any cargo.
Definition industry.h:223
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition industry.h:251
Station * neutral_station
Associated neutral station.
Definition industry.h:108
StationList stations_near
NOSAVE: List of nearby stations.
Definition industry.h:123
static uint MaxY()
Gets the maximum Y coordinate within the map, including TileType::Void.
Definition map_func.h:298
static uint MaxX()
Gets the maximum X coordinate within the map, including TileType::Void.
Definition map_func.h:289
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
OrthogonalTileArea & Expand(int rad)
Expand a tile area by rad tiles in each direction, keeping within map bounds.
Definition tilearea.cpp:123
static Pool::IterateWrapper< Vehicle > Iterate(size_t from=0)
static Town * Get(auto index)
static LinkGraph * GetIfValid(auto index)
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
int Height() const
Get height of Rect.
A Stop for a Road Vehicle.
RoadStop * next
Next stop of the given type at this station.
TileIndex xy
Position on the map.
Buses, trucks and trams belong to this class.
Definition roadveh.h:105
RoadTypes compatible_roadtypes
NOSAVE: Roadtypes this consist is powered on.
Definition roadveh.h:117
bool IsBus() const
Check whether a roadvehicle is a bus.
Class defining several overloaded accessors so we don't have to cast base stations that often.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
static Station * Get(auto index)
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
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:632
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:567
uint8_t station_spread
amount a station may spread
Station data structure.
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
~Station() override
Clean up a station by clearing vehicle orders, invalidating windows and removing link stats.
Definition station.cpp:84
RoadStop * bus_stops
All the road stops.
bool CatchmentCoversTown(TownID t) const
Test if the given town ID is covered by our catchment area.
Definition station.cpp:455
TileArea ship_station
Tile area the ship 'station' part covers.
IndustryList industries_near
Cached list of industries near the station that can accept cargo,.
Rect GetCatchmentRect() const
Determines catchment rectangle of this station.
Definition station.cpp:369
Industry * industry
NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st).
void MoveSign(TileIndex new_xy) override
Move the station main coordinate somewhere else.
static void RecomputeCatchmentForAll()
Recomputes catchment of all stations.
Definition station.cpp:537
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
void RemoveFromAllNearbyLists()
Remove this station from the nearby stations lists of nearby towns and industries.
Definition station.cpp:430
bool TileBelongsToRailStation(TileIndex tile) const override
Check whether a specific tile belongs to this station.
BitmapTileArea catchment_tiles
NOSAVE: Set of individual tiles covered by catchment area.
void RecomputeCatchment(bool no_clear_nearby_lists=false)
Recompute tiles covered in our catchment area.
Definition station.cpp:469
uint GetCatchmentRadius() const
Determines the catchment radius of the station.
Definition station.cpp:346
Airport airport
Tile area the airport covers.
void AddIndustryToDeliver(Industry *ind, TileIndex tile)
Add nearby industry to station's industries_near list if it accepts cargo.
Definition station.cpp:392
void RemoveIndustryToDeliver(Industry *ind)
Remove nearby industry from station's industries_near list.
Definition station.cpp:418
RoadStop * truck_stops
All the truck stops.
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
Called when new facility is built on the station.
Definition station.cpp:233
Town data structure.
Definition town.h:63
StationList stations_near
NOSAVE: List of nearby stations.
Definition town.h:142
The information about a vehicle list.
Definition vehiclelist.h:32
Vehicle data structure.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
TileType
The different types of tiles.
Definition tile_type.h:48
@ Station
A tile of a station or airport.
Definition tile_type.h:54
@ Industry
Part of an industry.
Definition tile_type.h:57
@ House
A house by a town.
Definition tile_type.h:52
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Base of the town class.
TownID GetTownIndex(Tile t)
Get the index of which town this house/street is attached to.
Definition town_map.h:23
@ VEH_INVALID
Non-existing type of vehicle.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
Functions and type for generating vehicle lists.
@ VL_STATION_LIST
Index is the station.
Definition vehiclelist.h:25
Functions related to (drawing on) viewports.
Declarations for accessing the k-d tree of viewports.
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:1209
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting).
Definition window.cpp:3229
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:3321
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:3339
@ WC_STATION_LIST
Station list; Window numbers:
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ WC_STATION_VIEW
Station view; Window numbers:
@ WC_TRAINS_LIST
Trains list; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers: