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/>.
8 /** @file station.cpp Implementation of the station base class. */
11 #include "company_func.h"
12 #include "company_base.h"
14 #include "viewport_func.h"
15 #include "viewport_kdtree.h"
16 #include "command_func.h"
17 #include "news_func.h"
19 #include "vehiclelist.h"
20 #include "core/pool_func.hpp"
21 #include "station_base.h"
22 #include "station_kdtree.h"
23 #include "roadstop_base.h"
26 #include "core/random_func.hpp"
27 #include "linkgraph/linkgraph.h"
28 #include "linkgraph/linkgraphschedule.h"
30 #include "table/strings.h"
32 #include "safeguards.h"
34 /** The pool of stations. */
35 StationPool
_station_pool("Station");
36 INSTANTIATE_POOL_METHODS(Station
)
39 StationKdtree
_station_kdtree(Kdtree_StationXYFunc
);
41 void RebuildStationKdtree()
43 std::vector
<StationID
> stids
;
44 for (const Station
*st
: Station::Iterate()) {
45 stids
.push_back(st
->index
);
47 _station_kdtree
.Build(stids
.begin(), stids
.end());
51 BaseStation::~BaseStation()
53 if (CleaningPool()) return;
55 CloseWindowById(WC_TRAINS_LIST
, VehicleListIdentifier(VL_STATION_LIST
, VEH_TRAIN
, this->owner
, this->index
).Pack());
56 CloseWindowById(WC_ROADVEH_LIST
, VehicleListIdentifier(VL_STATION_LIST
, VEH_ROAD
, this->owner
, this->index
).Pack());
57 CloseWindowById(WC_SHIPS_LIST
, VehicleListIdentifier(VL_STATION_LIST
, VEH_SHIP
, this->owner
, this->index
).Pack());
58 CloseWindowById(WC_AIRCRAFT_LIST
, VehicleListIdentifier(VL_STATION_LIST
, VEH_AIRCRAFT
, this->owner
, this->index
).Pack());
60 this->sign
.MarkDirty();
63 Station::Station(TileIndex tile
) :
64 SpecializedStation
<Station
, false>(tile
),
65 bus_station(INVALID_TILE
, 0, 0),
66 truck_station(INVALID_TILE
, 0, 0),
67 ship_station(INVALID_TILE
, 0, 0),
70 time_since_unload(255),
71 last_vehicle_type(VEH_INVALID
)
73 /* this->random_bits is set in Station::AddFacility() */
77 * Clean up a station by clearing vehicle orders, invalidating windows and
78 * removing link stats.
79 * Aircraft-Hangar orders need special treatment here, as the hangars are
80 * actually part of a station (tiletype is STATION), but the order type
86 for (GoodsEntry
&ge
: this->goods
) {
87 ge
.cargo
.OnCleanPool();
92 while (!this->loading_vehicles
.empty()) {
93 this->loading_vehicles
.front()->LeaveStation();
96 for (Aircraft
*a
: Aircraft::Iterate()) {
97 if (!a
->IsNormalAircraft()) continue;
98 if (a
->targetairport
== this->index
) a
->targetairport
= INVALID_STATION
;
101 for (CargoID c
= 0; c
< NUM_CARGO
; ++c
) {
102 LinkGraph
*lg
= LinkGraph::GetIfValid(this->goods
[c
].link_graph
);
103 if (lg
== nullptr) continue;
105 for (NodeID node
= 0; node
< lg
->Size(); ++node
) {
106 Station
*st
= Station::Get((*lg
)[node
].station
);
107 st
->goods
[c
].flows
.erase(this->index
);
108 if ((*lg
)[node
].HasEdgeTo(this->goods
[c
].node
) && (*lg
)[node
][this->goods
[c
].node
].LastUpdate() != EconomyTime::INVALID_DATE
) {
109 st
->goods
[c
].flows
.DeleteFlows(this->index
);
110 RerouteCargo(st
, c
, this->index
, st
->index
);
113 lg
->RemoveNode(this->goods
[c
].node
);
114 if (lg
->Size() == 0) {
115 LinkGraphSchedule::instance
.Unqueue(lg
);
120 for (Vehicle
*v
: Vehicle::Iterate()) {
121 /* Forget about this station if this station is removed */
122 if (v
->last_station_visited
== this->index
) {
123 v
->last_station_visited
= INVALID_STATION
;
125 if (v
->last_loading_station
== this->index
) {
126 v
->last_loading_station
= INVALID_STATION
;
130 /* Remove station from industries and towns that reference it. */
131 this->RemoveFromAllNearbyLists();
133 /* Clear the persistent storage. */
134 delete this->airport
.psa
;
136 if (this->owner
== OWNER_NONE
) {
137 /* Invalidate all in case of oil rigs. */
138 InvalidateWindowClassesData(WC_STATION_LIST
, 0);
140 InvalidateWindowData(WC_STATION_LIST
, this->owner
, 0);
143 CloseWindowById(WC_STATION_VIEW
, index
);
145 /* Now delete all orders that go to the station */
146 RemoveOrderFromAllVehicles(OT_GOTO_STATION
, this->index
);
148 /* Remove all news items */
149 DeleteStationNews(this->index
);
151 for (GoodsEntry
&ge
: this->goods
) {
155 CargoPacket::InvalidateAllFrom(this->index
);
157 _station_kdtree
.Remove(this->index
);
158 if (this->sign
.kdtree_valid
) _viewport_sign_kdtree
.Remove(ViewportSignKdtreeItem::MakeStation(this->index
));
163 * Invalidating of the JoinStation window has to be done
164 * after removing item from the pool.
166 void BaseStation::PostDestructor(size_t)
168 InvalidateWindowData(WC_SELECT_STATION
, 0, 0);
171 bool BaseStation::SetRoadStopTileData(TileIndex tile
, uint8_t data
, bool animation
)
173 for (RoadStopTileData
&tile_data
: this->custom_roadstop_tile_data
) {
174 if (tile_data
.tile
== tile
) {
175 uint8_t &v
= animation
? tile_data
.animation_frame
: tile_data
.random_bits
;
176 if (v
== data
) return false;
181 RoadStopTileData tile_data
;
182 tile_data
.tile
= tile
;
183 tile_data
.animation_frame
= animation
? data
: 0;
184 tile_data
.random_bits
= animation
? 0 : data
;
185 this->custom_roadstop_tile_data
.push_back(tile_data
);
189 void BaseStation::RemoveRoadStopTileData(TileIndex tile
)
191 for (RoadStopTileData
&tile_data
: this->custom_roadstop_tile_data
) {
192 if (tile_data
.tile
== tile
) {
193 tile_data
= this->custom_roadstop_tile_data
.back();
194 this->custom_roadstop_tile_data
.pop_back();
201 * Get the primary road stop (the first road stop) that the given vehicle can load/unload.
202 * @param v the vehicle to get the first road stop for
203 * @return the first roadstop that this vehicle can load at
205 RoadStop
*Station::GetPrimaryRoadStop(const RoadVehicle
*v
) const
207 RoadStop
*rs
= this->GetPrimaryRoadStop(v
->IsBus() ? ROADSTOP_BUS
: ROADSTOP_TRUCK
);
209 for (; rs
!= nullptr; rs
= rs
->next
) {
210 /* The vehicle cannot go to this roadstop (different roadtype) */
211 if (!HasTileAnyRoadType(rs
->xy
, v
->compatible_roadtypes
)) continue;
212 /* The vehicle is articulated and can therefore not go to a standard road stop. */
213 if (IsBayRoadStopTile(rs
->xy
) && v
->HasArticulatedPart()) continue;
215 /* The vehicle can actually go to this road stop. So, return it! */
223 * Called when new facility is built on the station. If it is the first facility
224 * it initializes also 'xy' and 'random_bits' members
226 void Station::AddFacility(StationFacility new_facility_bit
, TileIndex facil_xy
)
228 if (this->facilities
== FACIL_NONE
) {
229 this->MoveSign(facil_xy
);
230 this->random_bits
= Random();
232 this->facilities
|= new_facility_bit
;
233 this->owner
= _current_company
;
234 this->build_date
= TimerGameCalendar::date
;
235 SetWindowClassesDirty(WC_VEHICLE_ORDERS
);
239 * Marks the tiles of the station as dirty.
243 void Station::MarkTilesDirty(bool cargo_change
) const
245 TileIndex tile
= this->train_station
.tile
;
248 if (tile
== INVALID_TILE
) return;
250 /* cargo_change is set if we're refreshing the tiles due to cargo moving
253 /* Don't waste time updating if there are no custom station graphics
254 * that might change. Even if there are custom graphics, they might
255 * not change. Unfortunately we have no way of telling. */
256 if (this->speclist
.empty()) return;
259 for (h
= 0; h
< train_station
.h
; h
++) {
260 for (w
= 0; w
< train_station
.w
; w
++) {
261 if (this->TileBelongsToRailStation(tile
)) {
262 MarkTileDirtyByTile(tile
);
264 tile
+= TileDiffXY(1, 0);
266 tile
+= TileDiffXY(-w
, 1);
270 /* virtual */ uint
Station::GetPlatformLength(TileIndex tile
) const
272 assert(this->TileBelongsToRailStation(tile
));
274 TileIndexDiff delta
= (GetRailStationAxis(tile
) == AXIS_X
? TileDiffXY(1, 0) : TileDiffXY(0, 1));
281 } while (IsCompatibleTrainStationTile(t
, tile
));
287 } while (IsCompatibleTrainStationTile(t
, tile
));
292 /* virtual */ uint
Station::GetPlatformLength(TileIndex tile
, DiagDirection dir
) const
294 TileIndex start_tile
= tile
;
296 assert(IsRailStationTile(tile
));
297 assert(dir
< DIAGDIR_END
);
301 tile
+= TileOffsByDiagDir(dir
);
302 } while (IsCompatibleTrainStationTile(tile
, start_tile
));
308 * Get the catchment size of an individual station tile.
309 * @param tile Station tile to get catchment size of.
310 * @param st Associated station of station tile.
311 * @pre IsTileType(tile, MP_STATION)
312 * @return The catchment size of the station tile.
314 static uint
GetTileCatchmentRadius(TileIndex tile
, const Station
*st
)
316 assert(IsTileType(tile
, MP_STATION
));
318 if (_settings_game
.station
.modified_catchment
) {
319 switch (GetStationType(tile
)) {
320 case STATION_RAIL
: return CA_TRAIN
;
321 case STATION_OILRIG
: return CA_UNMODIFIED
;
322 case STATION_AIRPORT
: return st
->airport
.GetSpec()->catchment
;
323 case STATION_TRUCK
: return CA_TRUCK
;
324 case STATION_BUS
: return CA_BUS
;
325 case STATION_DOCK
: return CA_DOCK
;
327 default: NOT_REACHED();
329 case STATION_WAYPOINT
:
330 case STATION_ROADWAYPOINT
: return CA_NONE
;
333 switch (GetStationType(tile
)) {
334 default: return CA_UNMODIFIED
;
336 case STATION_WAYPOINT
:
337 case STATION_ROADWAYPOINT
: return CA_NONE
;
343 * Determines the catchment radius of the station
346 uint
Station::GetCatchmentRadius() const
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
);
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
) {
366 * Determines catchment rectangle of this station
367 * @return clamped catchment rectangle
369 Rect
Station::GetCatchmentRect() const
371 assert(!this->rect
.IsEmpty());
373 /* Compute acceptance rectangle */
374 int catchment_radius
= this->GetCatchmentRadius();
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())
387 * Add nearby industry to station's industries_near list if it accepts cargo.
388 * For industries that are already on the list update distance if it's closer.
389 * @param ind Industry
390 * @param tile Tile of the industry to measure distance to.
392 void Station::AddIndustryToDeliver(Industry
*ind
, TileIndex tile
)
394 /* Using DistanceMax to get about the same order as with previously used CircularTileSearch. */
395 uint distance
= DistanceMax(this->xy
, tile
);
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::find_if(this->industries_near
.begin(), this->industries_near
.end(), [&](const IndustryListEntry
&e
) { return e
.industry
->index
== ind
->index
; });
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
));
408 /* Include only industries that can accept cargo */
409 if (!ind
->IsCargoAccepted()) return;
411 this->industries_near
.insert(IndustryListEntry
{distance
, ind
});
415 * Remove nearby industry from station's industries_near list.
416 * @param ind Industry
418 void Station::RemoveIndustryToDeliver(Industry
*ind
)
420 auto pos
= std::find_if(this->industries_near
.begin(), this->industries_near
.end(), [&](const IndustryListEntry
&e
) { return e
.industry
->index
== ind
->index
; });
421 if (pos
!= this->industries_near
.end()) {
422 this->industries_near
.erase(pos
);
428 * Remove this station from the nearby stations lists of nearby towns and industries.
430 void Station::RemoveFromAllNearbyLists()
432 std::set
<TownID
> towns
;
433 std::set
<IndustryID
> industries
;
435 for (const auto &tile
: this->catchment_tiles
) {
436 TileType type
= GetTileType(tile
);
437 if (type
== MP_HOUSE
) {
438 towns
.insert(GetTownIndex(tile
));
439 } else if (type
== MP_INDUSTRY
) {
440 industries
.insert(GetIndustryIndex(tile
));
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); }
449 * Test if the given town ID is covered by our catchment area.
450 * This is used when removing a house tile to determine if it was the last house tile
451 * within our catchment.
452 * @param t TownID to test.
453 * @return true if at least one house tile of TownID is covered.
455 bool Station::CatchmentCoversTown(TownID t
) const
457 BitmapTileIterator
it(this->catchment_tiles
);
458 for (TileIndex tile
= it
; tile
!= INVALID_TILE
; tile
= ++it
) {
459 if (IsTileType(tile
, MP_HOUSE
) && GetTownIndex(tile
) == t
) return true;
465 * Recompute tiles covered in our catchment area.
466 * This will additionally recompute nearby towns and industries.
467 * @param no_clear_nearby_lists If Station::RemoveFromAllNearbyLists does not need to be called.
469 void Station::RecomputeCatchment(bool no_clear_nearby_lists
)
471 this->industries_near
.clear();
472 if (!no_clear_nearby_lists
) this->RemoveFromAllNearbyLists();
474 if (this->rect
.IsEmpty()) {
475 this->catchment_tiles
.Reset();
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
, MP_INDUSTRY
) && GetIndustryIndex(tile
) == this->industry
->index
) {
484 this->catchment_tiles
.SetTile(tile
);
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
) {
489 st
->RemoveIndustryToDeliver(this->industry
);
491 this->industry
->stations_near
.clear();
492 this->industry
->stations_near
.insert(this);
493 this->industries_near
.insert(IndustryListEntry
{0, this->industry
});
497 this->catchment_tiles
.Initialize(GetCatchmentRect());
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
, MP_STATION
) || GetStationIndex(tile
) != this->index
) continue;
504 uint r
= GetTileCatchmentRadius(tile
, this);
505 if (r
== CA_NONE
) continue;
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
);
512 /* Search catchment tiles for towns and industries */
513 BitmapTileIterator
it(this->catchment_tiles
);
514 for (TileIndex tile
= it
; tile
!= INVALID_TILE
; tile
= ++it
) {
515 if (IsTileType(tile
, MP_HOUSE
)) {
516 Town
*t
= Town::GetByTile(tile
);
517 t
->stations_near
.insert(this);
519 if (IsTileType(tile
, MP_INDUSTRY
)) {
520 Industry
*i
= Industry::GetByTile(tile
);
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;
525 i
->stations_near
.insert(this);
527 /* Add if we can deliver to this industry as well */
528 this->AddIndustryToDeliver(i
, tile
);
534 * Recomputes catchment of all stations.
535 * This will additionally recompute nearby stations for all towns and industries.
537 /* static */ void Station::RecomputeCatchmentForAll()
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); }
544 /************************************************************************/
545 /* StationRect implementation */
546 /************************************************************************/
548 StationRect::StationRect()
553 void StationRect::MakeEmpty()
555 this->left
= this->top
= this->right
= this->bottom
= 0;
559 * Determines whether a given point (x, y) is within a certain distance of
560 * the station rectangle.
561 * @note x and y are in Tile coordinates
562 * @param x X coordinate
563 * @param y Y coordinate
564 * @param distance The maximum distance a point may have (L1 norm)
565 * @return true if the point is within distance tiles of the station rectangle
567 bool StationRect::PtInExtendedRect(int x
, int y
, int distance
) const
569 return this->left
- distance
<= x
&& x
<= this->right
+ distance
&&
570 this->top
- distance
<= y
&& y
<= this->bottom
+ distance
;
573 bool StationRect::IsEmpty() const
575 return this->left
== 0 || this->left
> this->right
|| this->top
> this->bottom
;
578 CommandCost
StationRect::BeforeAddTile(TileIndex tile
, StationRectMode mode
)
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
;
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
)};
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_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT
);
601 /* spread-out ok, return true */
602 if (mode
!= ADD_TEST
) {
603 /* we should update the station rect */
607 ; // new point is inside the rect, we don't need to do anything
609 return CommandCost();
612 CommandCost
StationRect::BeforeAddRect(TileIndex tile
, int w
, int h
, StationRectMode mode
)
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
);
620 return CommandCost();
624 * Check whether station tiles of the given station id exist in the given rectangle
625 * @param st_id Station ID to look for in the rectangle
626 * @param left_a Minimal tile X edge of the rectangle
627 * @param top_a Minimal tile Y edge of the rectangle
628 * @param right_a Maximal tile X edge of the rectangle (inclusive)
629 * @param bottom_a Maximal tile Y edge of the rectangle (inclusive)
630 * @return \c true if a station tile with the given \a st_id exists in the rectangle, \c false otherwise
632 /* static */ bool StationRect::ScanForStationTiles(StationID st_id
, int left_a
, int top_a
, int right_a
, int bottom_a
)
634 TileArea
ta(TileXY(left_a
, top_a
), TileXY(right_a
, bottom_a
));
635 for (TileIndex tile
: ta
) {
636 if (IsTileType(tile
, MP_STATION
) && GetStationIndex(tile
) == st_id
) return true;
642 bool StationRect::AfterRemoveTile(BaseStation
*st
, TileIndex tile
)
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 */
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
);
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)
663 /* reduce horizontally */
665 /* move left edge right */
666 this->left
= x
= x
+ 1;
668 /* move right edge left */
669 this->right
= x
= x
- 1;
673 /* reduce vertically */
675 /* move top edge down */
676 this->top
= y
= y
+ 1;
678 /* move bottom edge up */
679 this->bottom
= y
= y
- 1;
683 if (left
> right
|| top
> bottom
) {
684 /* can't continue, if the remaining rectangle is empty */
686 return true; // empty remaining rect
689 return false; // non-empty remaining rect
692 bool StationRect::AfterRemoveRect(BaseStation
*st
, TileArea ta
)
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));
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));
702 StationRect
& StationRect::operator = (const Rect
&src
)
704 this->left
= src
.left
;
706 this->right
= src
.right
;
707 this->bottom
= src
.bottom
;
712 * Calculates the maintenance cost of all airports of a company.
713 * @param owner Company.
714 * @return Total cost.
716 Money
AirportMaintenanceCost(Owner owner
)
718 Money total_cost
= 0;
720 for (const Station
*st
: Station::Iterate()) {
721 if (st
->owner
== owner
&& (st
->facilities
& FACIL_AIRPORT
)) {
722 total_cost
+= _price
[PR_INFRASTRUCTURE_AIRPORT
] * st
->airport
.GetSpec()->maintenance_cost
;
725 /* 3 bits fraction for the maintenance cost factor. */
726 return total_cost
>> 3;
729 bool StationCompare::operator() (const Station
*lhs
, const Station
*rhs
) const
731 return lhs
->index
< rhs
->index
;