OpenTTD

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