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 if (this->train_station
.tile
== INVALID_TILE
) return;
247 /* cargo_change is set if we're refreshing the tiles due to cargo moving
250 /* Don't waste time updating if there are no custom station graphics
251 * that might change. Even if there are custom graphics, they might
252 * not change. Unfortunately we have no way of telling. */
253 if (this->speclist
.empty()) return;
256 for (TileIndex tile
: this->train_station
) {
257 if (this->TileBelongsToRailStation(tile
)) {
258 MarkTileDirtyByTile(tile
);
263 /* virtual */ uint
Station::GetPlatformLength(TileIndex tile
) const
265 assert(this->TileBelongsToRailStation(tile
));
267 TileIndexDiff delta
= TileOffsByAxis(GetRailStationAxis(tile
));
274 } while (IsCompatibleTrainStationTile(t
, tile
));
280 } while (IsCompatibleTrainStationTile(t
, tile
));
285 /* virtual */ uint
Station::GetPlatformLength(TileIndex tile
, DiagDirection dir
) const
287 TileIndex start_tile
= tile
;
289 assert(IsRailStationTile(tile
));
290 assert(dir
< DIAGDIR_END
);
294 tile
+= TileOffsByDiagDir(dir
);
295 } while (IsCompatibleTrainStationTile(tile
, start_tile
));
301 * Get the catchment size of an individual station tile.
302 * @param tile Station tile to get catchment size of.
303 * @param st Associated station of station tile.
304 * @pre IsTileType(tile, MP_STATION)
305 * @return The catchment size of the station tile.
307 static uint
GetTileCatchmentRadius(TileIndex tile
, const Station
*st
)
309 assert(IsTileType(tile
, MP_STATION
));
311 if (_settings_game
.station
.modified_catchment
) {
312 switch (GetStationType(tile
)) {
313 case STATION_RAIL
: return CA_TRAIN
;
314 case STATION_OILRIG
: return CA_UNMODIFIED
;
315 case STATION_AIRPORT
: return st
->airport
.GetSpec()->catchment
;
316 case STATION_TRUCK
: return CA_TRUCK
;
317 case STATION_BUS
: return CA_BUS
;
318 case STATION_DOCK
: return CA_DOCK
;
320 default: NOT_REACHED();
322 case STATION_WAYPOINT
:
323 case STATION_ROADWAYPOINT
: return CA_NONE
;
326 switch (GetStationType(tile
)) {
327 default: return CA_UNMODIFIED
;
329 case STATION_WAYPOINT
:
330 case STATION_ROADWAYPOINT
: return CA_NONE
;
336 * Determines the catchment radius of the station
339 uint
Station::GetCatchmentRadius() const
343 if (_settings_game
.station
.modified_catchment
) {
344 if (this->bus_stops
!= nullptr) ret
= std::max
<uint
>(ret
, CA_BUS
);
345 if (this->truck_stops
!= nullptr) ret
= std::max
<uint
>(ret
, CA_TRUCK
);
346 if (this->train_station
.tile
!= INVALID_TILE
) ret
= std::max
<uint
>(ret
, CA_TRAIN
);
347 if (this->ship_station
.tile
!= INVALID_TILE
) ret
= std::max
<uint
>(ret
, CA_DOCK
);
348 if (this->airport
.tile
!= INVALID_TILE
) ret
= std::max
<uint
>(ret
, this->airport
.GetSpec()->catchment
);
350 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
) {
359 * Determines catchment rectangle of this station
360 * @return clamped catchment rectangle
362 Rect
Station::GetCatchmentRect() const
364 assert(!this->rect
.IsEmpty());
366 /* Compute acceptance rectangle */
367 int catchment_radius
= this->GetCatchmentRadius();
370 std::max
<int>(this->rect
.left
- catchment_radius
, 0),
371 std::max
<int>(this->rect
.top
- catchment_radius
, 0),
372 std::min
<int>(this->rect
.right
+ catchment_radius
, Map::MaxX()),
373 std::min
<int>(this->rect
.bottom
+ catchment_radius
, Map::MaxY())
380 * Add nearby industry to station's industries_near list if it accepts cargo.
381 * For industries that are already on the list update distance if it's closer.
382 * @param ind Industry
383 * @param tile Tile of the industry to measure distance to.
385 void Station::AddIndustryToDeliver(Industry
*ind
, TileIndex tile
)
387 /* Using DistanceMax to get about the same order as with previously used CircularTileSearch. */
388 uint distance
= DistanceMax(this->xy
, tile
);
390 /* Don't check further if this industry is already in the list but update the distance if it's closer */
391 auto pos
= std::find_if(this->industries_near
.begin(), this->industries_near
.end(), [&](const IndustryListEntry
&e
) { return e
.industry
->index
== ind
->index
; });
392 if (pos
!= this->industries_near
.end()) {
393 if (pos
->distance
> distance
) {
394 auto node
= this->industries_near
.extract(pos
);
395 node
.value().distance
= distance
;
396 this->industries_near
.insert(std::move(node
));
401 /* Include only industries that can accept cargo */
402 if (!ind
->IsCargoAccepted()) return;
404 this->industries_near
.insert(IndustryListEntry
{distance
, ind
});
408 * Remove nearby industry from station's industries_near list.
409 * @param ind Industry
411 void Station::RemoveIndustryToDeliver(Industry
*ind
)
413 auto pos
= std::find_if(this->industries_near
.begin(), this->industries_near
.end(), [&](const IndustryListEntry
&e
) { return e
.industry
->index
== ind
->index
; });
414 if (pos
!= this->industries_near
.end()) {
415 this->industries_near
.erase(pos
);
421 * Remove this station from the nearby stations lists of nearby towns and industries.
423 void Station::RemoveFromAllNearbyLists()
425 std::set
<TownID
> towns
;
426 std::set
<IndustryID
> industries
;
428 for (const auto &tile
: this->catchment_tiles
) {
429 TileType type
= GetTileType(tile
);
430 if (type
== MP_HOUSE
) {
431 towns
.insert(GetTownIndex(tile
));
432 } else if (type
== MP_INDUSTRY
) {
433 industries
.insert(GetIndustryIndex(tile
));
437 for (const TownID
&townid
: towns
) { Town::Get(townid
)->stations_near
.erase(this); }
438 for (const IndustryID
&industryid
: industries
) { Industry::Get(industryid
)->stations_near
.erase(this); }
442 * Test if the given town ID is covered by our catchment area.
443 * This is used when removing a house tile to determine if it was the last house tile
444 * within our catchment.
445 * @param t TownID to test.
446 * @return true if at least one house tile of TownID is covered.
448 bool Station::CatchmentCoversTown(TownID t
) const
450 BitmapTileIterator
it(this->catchment_tiles
);
451 for (TileIndex tile
= it
; tile
!= INVALID_TILE
; tile
= ++it
) {
452 if (IsTileType(tile
, MP_HOUSE
) && GetTownIndex(tile
) == t
) return true;
458 * Recompute tiles covered in our catchment area.
459 * This will additionally recompute nearby towns and industries.
460 * @param no_clear_nearby_lists If Station::RemoveFromAllNearbyLists does not need to be called.
462 void Station::RecomputeCatchment(bool no_clear_nearby_lists
)
464 this->industries_near
.clear();
465 if (!no_clear_nearby_lists
) this->RemoveFromAllNearbyLists();
467 if (this->rect
.IsEmpty()) {
468 this->catchment_tiles
.Reset();
472 if (!_settings_game
.station
.serve_neutral_industries
&& this->industry
!= nullptr) {
473 /* Station is associated with an industry, so we only need to deliver to that industry. */
474 this->catchment_tiles
.Initialize(this->industry
->location
);
475 for (TileIndex tile
: this->industry
->location
) {
476 if (IsTileType(tile
, MP_INDUSTRY
) && GetIndustryIndex(tile
) == this->industry
->index
) {
477 this->catchment_tiles
.SetTile(tile
);
480 /* The industry's stations_near may have been computed before its neutral station was built so clear and re-add here. */
481 for (Station
*st
: this->industry
->stations_near
) {
482 st
->RemoveIndustryToDeliver(this->industry
);
484 this->industry
->stations_near
.clear();
485 this->industry
->stations_near
.insert(this);
486 this->industries_near
.insert(IndustryListEntry
{0, this->industry
});
490 this->catchment_tiles
.Initialize(GetCatchmentRect());
492 /* Loop finding all station tiles */
493 TileArea
ta(TileXY(this->rect
.left
, this->rect
.top
), TileXY(this->rect
.right
, this->rect
.bottom
));
494 for (TileIndex tile
: ta
) {
495 if (!IsTileType(tile
, MP_STATION
) || GetStationIndex(tile
) != this->index
) continue;
497 uint r
= GetTileCatchmentRadius(tile
, this);
498 if (r
== CA_NONE
) continue;
500 /* This tile sub-loop doesn't need to test any tiles, they are simply added to the catchment set. */
501 TileArea ta2
= TileArea(tile
, 1, 1).Expand(r
);
502 for (TileIndex tile2
: ta2
) this->catchment_tiles
.SetTile(tile2
);
505 /* Search catchment tiles for towns and industries */
506 BitmapTileIterator
it(this->catchment_tiles
);
507 for (TileIndex tile
= it
; tile
!= INVALID_TILE
; tile
= ++it
) {
508 if (IsTileType(tile
, MP_HOUSE
)) {
509 Town
*t
= Town::GetByTile(tile
);
510 t
->stations_near
.insert(this);
512 if (IsTileType(tile
, MP_INDUSTRY
)) {
513 Industry
*i
= Industry::GetByTile(tile
);
515 /* Ignore industry if it has a neutral station. It already can't be this station. */
516 if (!_settings_game
.station
.serve_neutral_industries
&& i
->neutral_station
!= nullptr) continue;
518 i
->stations_near
.insert(this);
520 /* Add if we can deliver to this industry as well */
521 this->AddIndustryToDeliver(i
, tile
);
527 * Recomputes catchment of all stations.
528 * This will additionally recompute nearby stations for all towns and industries.
530 /* static */ void Station::RecomputeCatchmentForAll()
532 for (Town
*t
: Town::Iterate()) { t
->stations_near
.clear(); }
533 for (Industry
*i
: Industry::Iterate()) { i
->stations_near
.clear(); }
534 for (Station
*st
: Station::Iterate()) { st
->RecomputeCatchment(true); }
537 /************************************************************************/
538 /* StationRect implementation */
539 /************************************************************************/
541 StationRect::StationRect()
546 void StationRect::MakeEmpty()
548 this->left
= this->top
= this->right
= this->bottom
= 0;
552 * Determines whether a given point (x, y) is within a certain distance of
553 * the station rectangle.
554 * @note x and y are in Tile coordinates
555 * @param x X coordinate
556 * @param y Y coordinate
557 * @param distance The maximum distance a point may have (L1 norm)
558 * @return true if the point is within distance tiles of the station rectangle
560 bool StationRect::PtInExtendedRect(int x
, int y
, int distance
) const
562 return this->left
- distance
<= x
&& x
<= this->right
+ distance
&&
563 this->top
- distance
<= y
&& y
<= this->bottom
+ distance
;
566 bool StationRect::IsEmpty() const
568 return this->left
== 0 || this->left
> this->right
|| this->top
> this->bottom
;
571 CommandCost
StationRect::BeforeAddTile(TileIndex tile
, StationRectMode mode
)
575 if (this->IsEmpty()) {
576 /* we are adding the first station tile */
577 if (mode
!= ADD_TEST
) {
578 this->left
= this->right
= x
;
579 this->top
= this->bottom
= y
;
581 } else if (!this->PtInExtendedRect(x
, y
)) {
582 /* current rect is not empty and new point is outside this rect
583 * make new spread-out rectangle */
584 Rect new_rect
= {std::min(x
, this->left
), std::min(y
, this->top
), std::max(x
, this->right
), std::max(y
, this->bottom
)};
586 /* check new rect dimensions against preset max */
587 int w
= new_rect
.Width();
588 int h
= new_rect
.Height();
589 if (mode
!= ADD_FORCE
&& (w
> _settings_game
.station
.station_spread
|| h
> _settings_game
.station
.station_spread
)) {
590 assert(mode
!= ADD_TRY
);
591 return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT
);
594 /* spread-out ok, return true */
595 if (mode
!= ADD_TEST
) {
596 /* we should update the station rect */
600 ; // new point is inside the rect, we don't need to do anything
602 return CommandCost();
605 CommandCost
StationRect::BeforeAddRect(TileIndex tile
, int w
, int h
, StationRectMode mode
)
607 if (mode
== ADD_FORCE
|| (w
<= _settings_game
.station
.station_spread
&& h
<= _settings_game
.station
.station_spread
)) {
608 /* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
609 CommandCost ret
= this->BeforeAddTile(tile
, mode
);
610 if (ret
.Succeeded()) ret
= this->BeforeAddTile(TileAddXY(tile
, w
- 1, h
- 1), mode
);
613 return CommandCost();
617 * Check whether station tiles of the given station id exist in the given rectangle
618 * @param st_id Station ID to look for in the rectangle
619 * @param left_a Minimal tile X edge of the rectangle
620 * @param top_a Minimal tile Y edge of the rectangle
621 * @param right_a Maximal tile X edge of the rectangle (inclusive)
622 * @param bottom_a Maximal tile Y edge of the rectangle (inclusive)
623 * @return \c true if a station tile with the given \a st_id exists in the rectangle, \c false otherwise
625 /* static */ bool StationRect::ScanForStationTiles(StationID st_id
, int left_a
, int top_a
, int right_a
, int bottom_a
)
627 TileArea
ta(TileXY(left_a
, top_a
), TileXY(right_a
, bottom_a
));
628 for (TileIndex tile
: ta
) {
629 if (IsTileType(tile
, MP_STATION
) && GetStationIndex(tile
) == st_id
) return true;
635 bool StationRect::AfterRemoveTile(BaseStation
*st
, TileIndex tile
)
640 /* look if removed tile was on the bounding rect edge
641 * and try to reduce the rect by this edge
642 * do it until we have empty rect or nothing to do */
644 /* check if removed tile is on rect edge */
645 bool left_edge
= (x
== this->left
);
646 bool right_edge
= (x
== this->right
);
647 bool top_edge
= (y
== this->top
);
648 bool bottom_edge
= (y
== this->bottom
);
650 /* can we reduce the rect in either direction? */
651 bool reduce_x
= ((left_edge
|| right_edge
) && !ScanForStationTiles(st
->index
, x
, this->top
, x
, this->bottom
));
652 bool reduce_y
= ((top_edge
|| bottom_edge
) && !ScanForStationTiles(st
->index
, this->left
, y
, this->right
, y
));
653 if (!(reduce_x
|| reduce_y
)) break; // nothing to do (can't reduce)
656 /* reduce horizontally */
658 /* move left edge right */
659 this->left
= x
= x
+ 1;
661 /* move right edge left */
662 this->right
= x
= x
- 1;
666 /* reduce vertically */
668 /* move top edge down */
669 this->top
= y
= y
+ 1;
671 /* move bottom edge up */
672 this->bottom
= y
= y
- 1;
676 if (left
> right
|| top
> bottom
) {
677 /* can't continue, if the remaining rectangle is empty */
679 return true; // empty remaining rect
682 return false; // non-empty remaining rect
685 bool StationRect::AfterRemoveRect(BaseStation
*st
, TileArea ta
)
687 assert(this->PtInExtendedRect(TileX(ta
.tile
), TileY(ta
.tile
)));
688 assert(this->PtInExtendedRect(TileX(ta
.tile
) + ta
.w
- 1, TileY(ta
.tile
) + ta
.h
- 1));
690 bool empty
= this->AfterRemoveTile(st
, ta
.tile
);
691 if (ta
.w
!= 1 || ta
.h
!= 1) empty
= empty
|| this->AfterRemoveTile(st
, TileAddXY(ta
.tile
, ta
.w
- 1, ta
.h
- 1));
695 StationRect
& StationRect::operator = (const Rect
&src
)
697 this->left
= src
.left
;
699 this->right
= src
.right
;
700 this->bottom
= src
.bottom
;
705 * Calculates the maintenance cost of all airports of a company.
706 * @param owner Company.
707 * @return Total cost.
709 Money
AirportMaintenanceCost(Owner owner
)
711 Money total_cost
= 0;
713 for (const Station
*st
: Station::Iterate()) {
714 if (st
->owner
== owner
&& (st
->facilities
& FACIL_AIRPORT
)) {
715 total_cost
+= _price
[PR_INFRASTRUCTURE_AIRPORT
] * st
->airport
.GetSpec()->maintenance_cost
;
718 /* 3 bits fraction for the maintenance cost factor. */
719 return total_cost
>> 3;
722 bool StationCompare::operator() (const Station
*lhs
, const Station
*rhs
) const
724 return lhs
->index
< rhs
->index
;