2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file station.cpp Implementation of the station base class. */
|
2007-01-14 19:18:50 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2010-06-10 23:52:09 +00:00
|
|
|
#include "company_base.h"
|
2007-08-24 19:19:18 +00:00
|
|
|
#include "roadveh.h"
|
2011-02-07 22:29:47 +00:00
|
|
|
#include "viewport_func.h"
|
2019-02-22 16:57:28 +00:00
|
|
|
#include "viewport_kdtree.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2008-01-13 21:41:24 +00:00
|
|
|
#include "command_func.h"
|
2008-09-13 10:19:51 +00:00
|
|
|
#include "news_func.h"
|
2008-09-16 16:07:18 +00:00
|
|
|
#include "aircraft.h"
|
2010-09-08 21:37:13 +00:00
|
|
|
#include "vehiclelist.h"
|
2009-05-22 15:13:50 +00:00
|
|
|
#include "core/pool_func.hpp"
|
2009-06-24 17:39:54 +00:00
|
|
|
#include "station_base.h"
|
2019-02-18 20:14:52 +00:00
|
|
|
#include "station_kdtree.h"
|
2009-06-23 21:44:48 +00:00
|
|
|
#include "roadstop_base.h"
|
2009-08-30 11:47:41 +00:00
|
|
|
#include "industry.h"
|
2019-02-14 21:07:15 +00:00
|
|
|
#include "town.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/random_func.hpp"
|
2013-05-19 14:22:04 +00:00
|
|
|
#include "linkgraph/linkgraph.h"
|
2013-06-09 13:02:40 +00:00
|
|
|
#include "linkgraph/linkgraphschedule.h"
|
2015-07-24 00:21:31 +00:00
|
|
|
#include "tracerestrict.h"
|
2019-06-16 12:19:27 +00:00
|
|
|
#include "newgrf_debug.h"
|
2007-01-14 19:18:50 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2011-05-01 19:51:52 +00:00
|
|
|
/** The pool of stations. */
|
2009-05-22 15:13:50 +00:00
|
|
|
StationPool _station_pool("Station");
|
|
|
|
INSTANTIATE_POOL_METHODS(Station)
|
|
|
|
|
2021-07-17 19:54:10 +00:00
|
|
|
std::array<ExtraStationNameInfo, MAX_EXTRA_STATION_NAMES> _extra_station_names;
|
|
|
|
uint _extra_station_names_used;
|
|
|
|
|
2019-02-18 20:14:52 +00:00
|
|
|
|
|
|
|
StationKdtree _station_kdtree(Kdtree_StationXYFunc);
|
|
|
|
|
|
|
|
void RebuildStationKdtree()
|
|
|
|
{
|
|
|
|
std::vector<StationID> stids;
|
2019-12-15 04:55:59 +00:00
|
|
|
for (const Station *st : Station::Iterate()) {
|
2019-02-18 20:14:52 +00:00
|
|
|
stids.push_back(st->index);
|
|
|
|
}
|
|
|
|
_station_kdtree.Build(stids.begin(), stids.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-17 20:30:07 +00:00
|
|
|
BaseStation::~BaseStation()
|
|
|
|
{
|
|
|
|
free(this->speclist);
|
2010-06-11 00:18:28 +00:00
|
|
|
|
|
|
|
if (CleaningPool()) return;
|
|
|
|
|
2014-10-21 19:16:47 +00:00
|
|
|
DeleteWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).Pack());
|
|
|
|
DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).Pack());
|
|
|
|
DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).Pack());
|
|
|
|
DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack());
|
2015-12-04 01:39:40 +00:00
|
|
|
DeleteWindowById(WC_DEPARTURES_BOARD, this->index);
|
2021-06-23 06:21:29 +00:00
|
|
|
DeleteWindowById(WC_STATION_CARGO, this->index);
|
2010-06-11 00:20:24 +00:00
|
|
|
|
2020-02-17 23:23:15 +00:00
|
|
|
if (HasBit(_display_opt, Station::IsExpected(this) ? DO_SHOW_STATION_NAMES : DO_SHOW_WAYPOINT_NAMES) &&
|
|
|
|
!(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))) {
|
|
|
|
this->sign.MarkDirty(ZOOM_LVL_DRAW_SPR);
|
|
|
|
}
|
2009-07-17 20:30:07 +00:00
|
|
|
}
|
|
|
|
|
2009-06-23 20:32:51 +00:00
|
|
|
Station::Station(TileIndex tile) :
|
2009-07-18 18:39:17 +00:00
|
|
|
SpecializedStation<Station, false>(tile),
|
2009-12-02 16:20:44 +00:00
|
|
|
bus_station(INVALID_TILE, 0, 0),
|
|
|
|
truck_station(INVALID_TILE, 0, 0),
|
2019-03-11 10:37:47 +00:00
|
|
|
ship_station(INVALID_TILE, 0, 0),
|
2009-06-23 20:32:51 +00:00
|
|
|
indtype(IT_INVALID),
|
2021-07-17 19:54:10 +00:00
|
|
|
extra_name_index(UINT16_MAX),
|
2009-06-23 20:32:51 +00:00
|
|
|
time_since_load(255),
|
2021-06-23 06:21:29 +00:00
|
|
|
time_since_unload(255),
|
2021-06-29 17:09:49 +00:00
|
|
|
station_cargo_history_cargoes(0),
|
|
|
|
station_cargo_history_offset(0)
|
2007-01-14 19:18:50 +00:00
|
|
|
{
|
2009-06-23 20:32:51 +00:00
|
|
|
/* this->random_bits is set in Station::AddFacility() */
|
2007-01-14 19:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-19 14:22:04 +00:00
|
|
|
* Clean up a station by clearing vehicle orders, invalidating windows and
|
|
|
|
* removing link stats.
|
2007-04-04 01:35:16 +00:00
|
|
|
* Aircraft-Hangar orders need special treatment here, as the hangars are
|
|
|
|
* actually part of a station (tiletype is STATION), but the order type
|
|
|
|
* is OT_GOTO_DEPOT.
|
|
|
|
*/
|
2007-01-14 19:18:50 +00:00
|
|
|
Station::~Station()
|
|
|
|
{
|
2011-02-19 18:02:17 +00:00
|
|
|
if (CleaningPool()) {
|
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
|
|
|
this->goods[c].cargo.OnCleanPool();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2007-08-05 21:20:55 +00:00
|
|
|
|
2009-07-07 11:21:29 +00:00
|
|
|
while (!this->loading_vehicles.empty()) {
|
|
|
|
this->loading_vehicles.front()->LeaveStation();
|
2007-08-18 22:56:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 02:37:43 +00:00
|
|
|
for (Aircraft *a : Aircraft::Iterate()) {
|
2009-07-13 16:37:27 +00:00
|
|
|
if (!a->IsNormalAircraft()) continue;
|
2009-05-22 20:07:26 +00:00
|
|
|
if (a->targetairport == this->index) a->targetairport = INVALID_STATION;
|
2008-09-16 16:07:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-19 14:22:04 +00:00
|
|
|
for (CargoID c = 0; c < NUM_CARGO; ++c) {
|
|
|
|
LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
|
2019-04-10 21:07:06 +00:00
|
|
|
if (lg == nullptr) continue;
|
2013-06-23 08:29:28 +00:00
|
|
|
|
|
|
|
for (NodeID node = 0; node < lg->Size(); ++node) {
|
2014-01-29 19:55:29 +00:00
|
|
|
Station *st = Station::Get((*lg)[node].Station());
|
|
|
|
st->goods[c].flows.erase(this->index);
|
2013-06-23 08:29:28 +00:00
|
|
|
if ((*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) {
|
|
|
|
st->goods[c].flows.DeleteFlows(this->index);
|
|
|
|
RerouteCargo(st, c, this->index, st->index);
|
2013-05-19 14:22:04 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-23 08:29:28 +00:00
|
|
|
lg->RemoveNode(this->goods[c].node);
|
|
|
|
if (lg->Size() == 0) {
|
2015-03-07 18:27:01 +00:00
|
|
|
LinkGraphSchedule::instance.Unqueue(lg);
|
2013-06-23 08:29:28 +00:00
|
|
|
delete lg;
|
2013-06-09 12:49:47 +00:00
|
|
|
}
|
2013-05-19 14:22:04 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 02:37:43 +00:00
|
|
|
for (Vehicle *v : Vehicle::Iterate()) {
|
2009-05-31 09:33:12 +00:00
|
|
|
/* Forget about this station if this station is removed */
|
2009-05-31 09:34:40 +00:00
|
|
|
if (v->last_station_visited == this->index) {
|
2009-05-31 09:33:12 +00:00
|
|
|
v->last_station_visited = INVALID_STATION;
|
|
|
|
}
|
2013-05-19 14:22:04 +00:00
|
|
|
if (v->last_loading_station == this->index) {
|
|
|
|
v->last_loading_station = INVALID_STATION;
|
|
|
|
}
|
2009-05-31 09:33:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
/* Remove station from industries and towns that reference it. */
|
|
|
|
this->RemoveFromAllNearbyLists();
|
|
|
|
|
2011-06-12 20:47:45 +00:00
|
|
|
/* Clear the persistent storage. */
|
|
|
|
delete this->airport.psa;
|
|
|
|
|
2011-11-12 18:06:34 +00:00
|
|
|
if (this->owner == OWNER_NONE) {
|
|
|
|
/* Invalidate all in case of oil rigs. */
|
|
|
|
InvalidateWindowClassesData(WC_STATION_LIST, 0);
|
|
|
|
} else {
|
|
|
|
InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
|
|
|
|
}
|
2007-01-14 19:18:50 +00:00
|
|
|
|
|
|
|
DeleteWindowById(WC_STATION_VIEW, index);
|
2019-06-16 12:19:27 +00:00
|
|
|
DeleteNewGRFInspectWindow(GSF_FAKE_STATION_STRUCT, this->index);
|
2010-06-10 23:52:09 +00:00
|
|
|
|
2007-01-14 19:18:50 +00:00
|
|
|
/* Now delete all orders that go to the station */
|
2009-08-07 22:23:34 +00:00
|
|
|
RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index);
|
2007-01-14 19:18:50 +00:00
|
|
|
|
2015-07-24 00:21:31 +00:00
|
|
|
TraceRestrictRemoveDestinationID(TROCAF_STATION, this->index);
|
|
|
|
|
2008-09-13 10:19:51 +00:00
|
|
|
/* Remove all news items */
|
|
|
|
DeleteStationNews(this->index);
|
|
|
|
|
2007-06-22 11:58:59 +00:00
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
2013-02-17 14:10:15 +00:00
|
|
|
this->goods[c].cargo.Truncate();
|
2007-06-22 11:58:59 +00:00
|
|
|
}
|
2009-05-23 19:43:09 +00:00
|
|
|
|
2009-10-18 17:26:10 +00:00
|
|
|
CargoPacket::InvalidateAllFrom(this->index);
|
2019-02-18 20:14:52 +00:00
|
|
|
|
|
|
|
_station_kdtree.Remove(this->index);
|
2019-12-11 18:20:24 +00:00
|
|
|
if (_viewport_sign_kdtree_valid && this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeStation(this->index));
|
2007-08-01 23:49:06 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 19:19:18 +00:00
|
|
|
|
2009-07-05 13:20:05 +00:00
|
|
|
/**
|
|
|
|
* Invalidating of the JoinStation window has to be done
|
|
|
|
* after removing item from the pool.
|
|
|
|
* @param index index of deleted item
|
|
|
|
*/
|
2009-09-12 12:56:49 +00:00
|
|
|
void BaseStation::PostDestructor(size_t index)
|
2009-07-05 13:20:05 +00:00
|
|
|
{
|
|
|
|
InvalidateWindowData(WC_SELECT_STATION, 0, 0);
|
|
|
|
}
|
|
|
|
|
2007-08-24 19:19:18 +00:00
|
|
|
/**
|
|
|
|
* Get the primary road stop (the first road stop) that the given vehicle can load/unload.
|
|
|
|
* @param v the vehicle to get the first road stop for
|
|
|
|
* @return the first roadstop that this vehicle can load at
|
|
|
|
*/
|
2009-05-22 20:18:45 +00:00
|
|
|
RoadStop *Station::GetPrimaryRoadStop(const RoadVehicle *v) const
|
2007-08-24 19:19:18 +00:00
|
|
|
{
|
2009-12-02 17:37:02 +00:00
|
|
|
RoadStop *rs = this->GetPrimaryRoadStop(v->IsBus() ? ROADSTOP_BUS : ROADSTOP_TRUCK);
|
2007-08-24 19:19:18 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
for (; rs != nullptr; rs = rs->next) {
|
2007-08-24 19:19:18 +00:00
|
|
|
/* The vehicle cannot go to this roadstop (different roadtype) */
|
2019-04-06 06:46:15 +00:00
|
|
|
if (!HasTileAnyRoadType(rs->xy, v->compatible_roadtypes)) continue;
|
2012-12-01 13:12:39 +00:00
|
|
|
/* The vehicle is articulated and can therefore not go to a standard road stop. */
|
2009-07-02 09:06:15 +00:00
|
|
|
if (IsStandardRoadStopTile(rs->xy) && v->HasArticulatedPart()) continue;
|
2007-08-24 19:19:18 +00:00
|
|
|
|
|
|
|
/* The vehicle can actually go to this road stop. So, return it! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rs;
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Called when new facility is built on the station. If it is the first facility
|
2010-08-01 19:44:49 +00:00
|
|
|
* it initializes also 'xy' and 'random_bits' members
|
|
|
|
*/
|
2009-07-04 11:26:57 +00:00
|
|
|
void Station::AddFacility(StationFacility new_facility_bit, TileIndex facil_xy)
|
2007-01-18 09:34:44 +00:00
|
|
|
{
|
2009-07-07 11:21:29 +00:00
|
|
|
if (this->facilities == FACIL_NONE) {
|
2019-03-23 11:39:13 +00:00
|
|
|
this->MoveSign(facil_xy);
|
2009-07-07 11:21:29 +00:00
|
|
|
this->random_bits = Random();
|
2007-01-18 09:34:44 +00:00
|
|
|
}
|
2009-07-07 11:21:29 +00:00
|
|
|
this->facilities |= new_facility_bit;
|
|
|
|
this->owner = _current_company;
|
|
|
|
this->build_date = _date;
|
2007-01-18 09:34:44 +00:00
|
|
|
}
|
|
|
|
|
2011-01-18 23:09:43 +00:00
|
|
|
/**
|
|
|
|
* Marks the tiles of the station as dirty.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2007-06-08 09:35:39 +00:00
|
|
|
void Station::MarkTilesDirty(bool cargo_change) const
|
2007-01-14 19:18:50 +00:00
|
|
|
{
|
2009-07-25 08:54:19 +00:00
|
|
|
TileIndex tile = this->train_station.tile;
|
2007-01-14 19:18:50 +00:00
|
|
|
int w, h;
|
|
|
|
|
2008-12-26 18:01:15 +00:00
|
|
|
if (tile == INVALID_TILE) return;
|
2007-01-14 19:18:50 +00:00
|
|
|
|
2007-06-08 09:35:39 +00:00
|
|
|
/* cargo_change is set if we're refreshing the tiles due to cargo moving
|
|
|
|
* around. */
|
|
|
|
if (cargo_change) {
|
|
|
|
/* Don't waste time updating if there are no custom station graphics
|
|
|
|
* that might change. Even if there are custom graphics, they might
|
|
|
|
* not change. Unfortunately we have no way of telling. */
|
|
|
|
if (this->num_specs == 0) return;
|
|
|
|
}
|
|
|
|
|
2009-07-25 08:54:19 +00:00
|
|
|
for (h = 0; h < train_station.h; h++) {
|
|
|
|
for (w = 0; w < train_station.w; w++) {
|
2009-07-07 11:21:29 +00:00
|
|
|
if (this->TileBelongsToRailStation(tile)) {
|
2020-10-01 17:50:31 +00:00
|
|
|
MarkTileDirtyByTile(tile, VMDF_NOT_MAP_MODE);
|
2007-01-14 19:18:50 +00:00
|
|
|
}
|
|
|
|
tile += TileDiffXY(1, 0);
|
|
|
|
}
|
|
|
|
tile += TileDiffXY(-w, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-24 15:18:25 +00:00
|
|
|
/* virtual */ uint Station::GetPlatformLength(TileIndex tile) const
|
2007-02-13 16:36:38 +00:00
|
|
|
{
|
2018-07-26 18:13:35 +00:00
|
|
|
assert_tile(this->TileBelongsToRailStation(tile), tile);
|
2007-02-13 16:36:38 +00:00
|
|
|
|
2009-07-07 11:21:29 +00:00
|
|
|
TileIndexDiff delta = (GetRailStationAxis(tile) == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
2007-02-13 16:36:38 +00:00
|
|
|
|
2009-07-07 11:21:29 +00:00
|
|
|
TileIndex t = tile;
|
|
|
|
uint len = 0;
|
2007-02-13 16:36:38 +00:00
|
|
|
do {
|
|
|
|
t -= delta;
|
|
|
|
len++;
|
|
|
|
} while (IsCompatibleTrainStationTile(t, tile));
|
|
|
|
|
|
|
|
t = tile;
|
|
|
|
do {
|
|
|
|
t += delta;
|
|
|
|
len++;
|
|
|
|
} while (IsCompatibleTrainStationTile(t, tile));
|
|
|
|
|
|
|
|
return len - 1;
|
|
|
|
}
|
|
|
|
|
2009-07-24 15:18:25 +00:00
|
|
|
/* virtual */ uint Station::GetPlatformLength(TileIndex tile, DiagDirection dir) const
|
2007-02-13 16:36:38 +00:00
|
|
|
{
|
|
|
|
TileIndex start_tile = tile;
|
|
|
|
uint length = 0;
|
2018-07-26 18:13:35 +00:00
|
|
|
assert_tile(IsRailStationTile(tile), tile);
|
2007-02-13 16:36:38 +00:00
|
|
|
assert(dir < DIAGDIR_END);
|
|
|
|
|
|
|
|
do {
|
2009-07-24 15:18:25 +00:00
|
|
|
length++;
|
2007-02-13 16:36:38 +00:00
|
|
|
tile += TileOffsByDiagDir(dir);
|
|
|
|
} while (IsCompatibleTrainStationTile(tile, start_tile));
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
/**
|
|
|
|
* Get the catchment size of an individual station tile.
|
|
|
|
* @param tile Station tile to get catchment size of.
|
|
|
|
* @param st Associated station of station tile.
|
|
|
|
* @pre IsTileType(tile, MP_STATION)
|
|
|
|
* @return The catchment size of the station tile.
|
|
|
|
*/
|
|
|
|
static uint GetTileCatchmentRadius(TileIndex tile, const Station *st)
|
|
|
|
{
|
|
|
|
assert(IsTileType(tile, MP_STATION));
|
|
|
|
|
2019-03-12 18:00:36 +00:00
|
|
|
const int32 inc = _settings_game.station.catchment_increase;
|
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
if (_settings_game.station.modified_catchment) {
|
|
|
|
switch (GetStationType(tile)) {
|
2019-03-12 18:00:36 +00:00
|
|
|
case STATION_RAIL: return CA_TRAIN + inc;
|
|
|
|
case STATION_OILRIG: return CA_UNMODIFIED + inc;
|
|
|
|
case STATION_AIRPORT: return st->airport.GetSpec()->catchment + inc;
|
|
|
|
case STATION_TRUCK: return CA_TRUCK + inc;
|
|
|
|
case STATION_BUS: return CA_BUS + inc;
|
|
|
|
case STATION_DOCK: return CA_DOCK + inc;
|
2019-02-14 21:07:15 +00:00
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case STATION_BUOY:
|
|
|
|
case STATION_WAYPOINT: return CA_NONE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (GetStationType(tile)) {
|
2019-03-12 18:00:36 +00:00
|
|
|
default: return CA_UNMODIFIED + inc;
|
2019-02-14 21:07:15 +00:00
|
|
|
case STATION_BUOY:
|
|
|
|
case STATION_WAYPOINT: return CA_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Determines the catchment radius of the station
|
2008-10-25 14:19:09 +00:00
|
|
|
* @return The radius
|
|
|
|
*/
|
|
|
|
uint Station::GetCatchmentRadius() const
|
|
|
|
{
|
|
|
|
uint ret = CA_NONE;
|
|
|
|
|
|
|
|
if (_settings_game.station.modified_catchment) {
|
2021-01-08 10:16:18 +00:00
|
|
|
if (this->bus_stops != nullptr) ret = std::max<uint>(ret, CA_BUS);
|
|
|
|
if (this->truck_stops != nullptr) ret = std::max<uint>(ret, CA_TRUCK);
|
|
|
|
if (this->train_station.tile != INVALID_TILE) ret = std::max<uint>(ret, CA_TRAIN);
|
|
|
|
if (this->ship_station.tile != INVALID_TILE) ret = std::max<uint>(ret, CA_DOCK);
|
|
|
|
if (this->airport.tile != INVALID_TILE) ret = std::max<uint>(ret, this->airport.GetSpec()->catchment);
|
2008-10-25 14:19:09 +00:00
|
|
|
} else {
|
2019-03-11 10:37:47 +00:00
|
|
|
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) {
|
2008-10-25 14:19:09 +00:00
|
|
|
ret = CA_UNMODIFIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 01:49:10 +00:00
|
|
|
if (ret != CA_NONE) ret += _settings_game.station.catchment_increase;
|
|
|
|
|
2008-10-25 14:19:09 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-07 21:11:58 +00:00
|
|
|
/**
|
|
|
|
* Determines catchment rectangle of this station
|
|
|
|
* @return clamped catchment rectangle
|
|
|
|
*/
|
2015-11-01 16:07:55 +00:00
|
|
|
Rect Station::GetCatchmentRectUsingRadius(uint catchment_radius) const
|
2009-08-07 21:11:58 +00:00
|
|
|
{
|
|
|
|
assert(!this->rect.IsEmpty());
|
|
|
|
|
|
|
|
/* Compute acceptance rectangle */
|
|
|
|
Rect ret = {
|
2021-01-08 10:16:18 +00:00
|
|
|
std::max<int>(this->rect.left - catchment_radius, 0),
|
|
|
|
std::max<int>(this->rect.top - catchment_radius, 0),
|
|
|
|
std::min<int>(this->rect.right + catchment_radius, MapMaxX()),
|
|
|
|
std::min<int>(this->rect.bottom + catchment_radius, MapMaxY())
|
2009-08-07 21:11:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:08:30 +00:00
|
|
|
bool Station::IsWithinRangeOfDockingTile(TileIndex tile, uint max_distance) const
|
|
|
|
{
|
|
|
|
if (DistanceManhattan(this->xy, tile) > _settings_game.station.station_spread + max_distance) return false;
|
2019-07-13 19:34:52 +00:00
|
|
|
for (TileIndex dock_tile : this->docking_tiles) {
|
|
|
|
if (DistanceManhattan(dock_tile, tile) <= max_distance) return true;
|
2019-02-22 22:08:30 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-25 15:42:03 +00:00
|
|
|
/**
|
2019-02-14 21:07:15 +00:00
|
|
|
* Add nearby industry to station's industries_near list if it accepts cargo.
|
|
|
|
* @param ind Industry
|
2009-06-25 15:42:03 +00:00
|
|
|
*/
|
2020-05-11 22:36:28 +00:00
|
|
|
void Station::AddIndustryToDeliver(Industry *ind)
|
2009-06-25 15:42:03 +00:00
|
|
|
{
|
|
|
|
/* Don't check further if this industry is already in the list */
|
2020-05-11 22:36:28 +00:00
|
|
|
if (this->industries_near.find(ind) != this->industries_near.end()) return;
|
2009-06-25 15:42:03 +00:00
|
|
|
|
|
|
|
/* Include only industries that can accept cargo */
|
|
|
|
uint cargo_index;
|
|
|
|
for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
|
|
|
|
if (ind->accepts_cargo[cargo_index] != CT_INVALID) break;
|
|
|
|
}
|
2019-02-14 21:07:15 +00:00
|
|
|
if (cargo_index >= lengthof(ind->accepts_cargo)) return;
|
2009-06-25 15:42:03 +00:00
|
|
|
|
2020-05-11 22:36:28 +00:00
|
|
|
this->industries_near.insert(ind);
|
2019-02-14 21:07:15 +00:00
|
|
|
}
|
2009-06-25 15:42:03 +00:00
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
/**
|
|
|
|
* Remove this station from the nearby stations lists of all towns and industries.
|
|
|
|
*/
|
|
|
|
void Station::RemoveFromAllNearbyLists()
|
|
|
|
{
|
2019-12-17 21:04:09 +00:00
|
|
|
for (Town *t : Town::Iterate()) { t->stations_near.erase(this); }
|
2019-12-16 17:51:20 +00:00
|
|
|
for (Industry *i : Industry::Iterate()) { i->stations_near.erase(this); }
|
2019-02-14 21:07:15 +00:00
|
|
|
}
|
2009-06-25 15:42:03 +00:00
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
/**
|
|
|
|
* Test if the given town ID is covered by our catchment area.
|
|
|
|
* This is used when removing a house tile to determine if it was the last house tile
|
|
|
|
* within our catchment.
|
|
|
|
* @param t TownID to test.
|
|
|
|
* @return true if at least one house tile of TownID is covered.
|
|
|
|
*/
|
|
|
|
bool Station::CatchmentCoversTown(TownID t) const
|
|
|
|
{
|
|
|
|
BitmapTileIterator it(this->catchment_tiles);
|
|
|
|
for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
|
|
|
|
if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) == t) return true;
|
|
|
|
}
|
2009-06-25 15:42:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-14 21:07:15 +00:00
|
|
|
* Recompute tiles covered in our catchment area.
|
|
|
|
* This will additionally recompute nearby towns and industries.
|
2009-06-25 15:42:03 +00:00
|
|
|
*/
|
2019-09-23 17:45:37 +00:00
|
|
|
void Station::RecomputeCatchment(bool no_clear_nearby_lists)
|
2009-06-25 15:42:03 +00:00
|
|
|
{
|
2019-02-24 19:16:24 +00:00
|
|
|
this->industries_near.clear();
|
2019-09-23 17:45:37 +00:00
|
|
|
if (!no_clear_nearby_lists) this->RemoveFromAllNearbyLists();
|
2009-06-25 15:42:03 +00:00
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
if (this->rect.IsEmpty()) {
|
|
|
|
this->catchment_tiles.Reset();
|
|
|
|
return;
|
|
|
|
}
|
2009-06-25 15:42:03 +00:00
|
|
|
|
2019-04-10 21:07:06 +00:00
|
|
|
if (!_settings_game.station.serve_neutral_industries && this->industry != nullptr) {
|
2019-03-08 18:30:44 +00:00
|
|
|
/* Station is associated with an industry, so we only need to deliver to that industry. */
|
2019-04-16 19:30:07 +00:00
|
|
|
this->catchment_tiles.Initialize(this->industry->location);
|
2021-05-12 14:45:28 +00:00
|
|
|
for (TileIndex tile : this->industry->location) {
|
2019-02-14 21:07:15 +00:00
|
|
|
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->industry->index) {
|
|
|
|
this->catchment_tiles.SetTile(tile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* The industry's stations_near may have been computed before its neutral station was built so clear and re-add here. */
|
|
|
|
for (Station *st : this->industry->stations_near) {
|
|
|
|
st->industries_near.erase(this->industry);
|
|
|
|
}
|
|
|
|
this->industry->stations_near.clear();
|
|
|
|
this->industry->stations_near.insert(this);
|
2019-02-24 19:16:24 +00:00
|
|
|
this->industries_near.insert(this->industry);
|
2020-06-07 13:37:59 +00:00
|
|
|
|
|
|
|
/* Loop finding all station tiles */
|
|
|
|
TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom));
|
|
|
|
this->station_tiles = 0;
|
2021-09-22 20:49:32 +00:00
|
|
|
for (TileIndex tile : ta) {
|
2020-06-07 13:37:59 +00:00
|
|
|
if (!IsTileType(tile, MP_STATION) || GetStationIndex(tile) != this->index) continue;
|
|
|
|
this->station_tiles++;
|
|
|
|
}
|
2019-03-08 18:30:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-06-25 15:42:03 +00:00
|
|
|
|
2019-04-16 19:30:07 +00:00
|
|
|
this->catchment_tiles.Initialize(GetCatchmentRect());
|
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
/* Loop finding all station tiles */
|
|
|
|
TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom));
|
2020-06-07 13:37:59 +00:00
|
|
|
this->station_tiles = 0;
|
2021-05-12 14:45:28 +00:00
|
|
|
for (TileIndex tile : ta) {
|
2019-02-14 21:07:15 +00:00
|
|
|
if (!IsTileType(tile, MP_STATION) || GetStationIndex(tile) != this->index) continue;
|
|
|
|
|
2020-06-07 13:37:59 +00:00
|
|
|
this->station_tiles++;
|
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
uint r = GetTileCatchmentRadius(tile, this);
|
|
|
|
if (r == CA_NONE) continue;
|
|
|
|
|
|
|
|
/* This tile sub-loop doesn't need to test any tiles, they are simply added to the catchment set. */
|
2019-04-13 13:12:34 +00:00
|
|
|
TileArea ta2 = TileArea(tile, 1, 1).Expand(r);
|
2021-05-12 14:45:28 +00:00
|
|
|
for (TileIndex tile2 : ta2) this->catchment_tiles.SetTile(tile2);
|
2019-02-14 21:07:15 +00:00
|
|
|
}
|
2009-06-25 15:42:03 +00:00
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
/* Search catchment tiles for towns and industries */
|
|
|
|
BitmapTileIterator it(this->catchment_tiles);
|
|
|
|
for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
|
|
|
|
if (IsTileType(tile, MP_HOUSE)) {
|
|
|
|
Town *t = Town::GetByTile(tile);
|
|
|
|
t->stations_near.insert(this);
|
|
|
|
}
|
|
|
|
if (IsTileType(tile, MP_INDUSTRY)) {
|
|
|
|
Industry *i = Industry::GetByTile(tile);
|
|
|
|
|
|
|
|
/* Ignore industry if it has a neutral station. It already can't be this station. */
|
2019-04-10 21:07:06 +00:00
|
|
|
if (!_settings_game.station.serve_neutral_industries && i->neutral_station != nullptr) continue;
|
2019-02-14 21:07:15 +00:00
|
|
|
|
|
|
|
i->stations_near.insert(this);
|
2009-06-25 15:42:03 +00:00
|
|
|
|
2019-02-14 21:07:15 +00:00
|
|
|
/* Add if we can deliver to this industry as well */
|
2020-05-11 22:36:28 +00:00
|
|
|
this->AddIndustryToDeliver(i);
|
2019-02-14 21:07:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-25 15:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-14 21:07:15 +00:00
|
|
|
* Recomputes catchment of all stations.
|
|
|
|
* This will additionally recompute nearby stations for all towns and industries.
|
2009-06-25 15:42:03 +00:00
|
|
|
*/
|
2019-02-14 21:07:15 +00:00
|
|
|
/* static */ void Station::RecomputeCatchmentForAll()
|
2009-06-25 15:42:03 +00:00
|
|
|
{
|
2020-01-06 18:45:51 +00:00
|
|
|
for (Town *t : Town::Iterate()) { t->stations_near.clear(); }
|
|
|
|
for (Industry *i : Industry::Iterate()) { i->stations_near.clear(); }
|
|
|
|
for (Station *st : Station::Iterate()) { st->RecomputeCatchment(true); }
|
2009-06-25 15:42:03 +00:00
|
|
|
}
|
2007-01-14 23:02:12 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* StationRect implementation */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
StationRect::StationRect()
|
|
|
|
{
|
2009-07-07 11:21:29 +00:00
|
|
|
this->MakeEmpty();
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StationRect::MakeEmpty()
|
|
|
|
{
|
2009-07-07 11:21:29 +00:00
|
|
|
this->left = this->top = this->right = this->bottom = 0;
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
|
|
|
|
2007-02-02 16:51:10 +00:00
|
|
|
/**
|
|
|
|
* Determines whether a given point (x, y) is within a certain distance of
|
|
|
|
* the station rectangle.
|
|
|
|
* @note x and y are in Tile coordinates
|
|
|
|
* @param x X coordinate
|
|
|
|
* @param y Y coordinate
|
2013-01-08 22:46:42 +00:00
|
|
|
* @param distance The maximum distance a point may have (L1 norm)
|
2007-02-02 16:51:10 +00:00
|
|
|
* @return true if the point is within distance tiles of the station rectangle
|
|
|
|
*/
|
|
|
|
bool StationRect::PtInExtendedRect(int x, int y, int distance) const
|
2007-01-14 23:02:12 +00:00
|
|
|
{
|
2010-11-20 15:44:24 +00:00
|
|
|
return this->left - distance <= x && x <= this->right + distance &&
|
|
|
|
this->top - distance <= y && y <= this->bottom + distance;
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StationRect::IsEmpty() const
|
|
|
|
{
|
2009-07-07 11:21:29 +00:00
|
|
|
return this->left == 0 || this->left > this->right || this->top > this->bottom;
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 12:15:03 +00:00
|
|
|
CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
|
2007-01-14 23:02:12 +00:00
|
|
|
{
|
|
|
|
int x = TileX(tile);
|
|
|
|
int y = TileY(tile);
|
2010-03-06 11:54:59 +00:00
|
|
|
if (this->IsEmpty()) {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* we are adding the first station tile */
|
2008-10-15 21:10:43 +00:00
|
|
|
if (mode != ADD_TEST) {
|
2009-07-07 11:21:29 +00:00
|
|
|
this->left = this->right = x;
|
|
|
|
this->top = this->bottom = y;
|
2008-10-15 21:10:43 +00:00
|
|
|
}
|
2010-03-06 11:54:59 +00:00
|
|
|
} else if (!this->PtInExtendedRect(x, y)) {
|
2009-03-15 00:32:18 +00:00
|
|
|
/* current rect is not empty and new point is outside this rect
|
|
|
|
* make new spread-out rectangle */
|
2021-01-08 10:16:18 +00:00
|
|
|
Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
|
2007-01-14 23:36:25 +00:00
|
|
|
|
|
|
|
/* check new rect dimensions against preset max */
|
2007-01-14 23:02:12 +00:00
|
|
|
int w = new_rect.right - new_rect.left + 1;
|
|
|
|
int h = new_rect.bottom - new_rect.top + 1;
|
2008-05-29 15:13:28 +00:00
|
|
|
if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
|
2007-01-14 23:02:12 +00:00
|
|
|
assert(mode != ADD_TRY);
|
2010-03-06 12:15:03 +00:00
|
|
|
return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
2007-01-14 23:36:25 +00:00
|
|
|
|
|
|
|
/* spread-out ok, return true */
|
2007-01-14 23:02:12 +00:00
|
|
|
if (mode != ADD_TEST) {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* we should update the station rect */
|
2007-01-14 23:02:12 +00:00
|
|
|
*this = new_rect;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
; // new point is inside the rect, we don't need to do anything
|
|
|
|
}
|
2010-03-06 12:15:03 +00:00
|
|
|
return CommandCost();
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 13:23:33 +00:00
|
|
|
CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
|
2007-01-14 23:02:12 +00:00
|
|
|
{
|
2010-03-06 12:15:03 +00:00
|
|
|
if (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) {
|
|
|
|
/* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
|
|
|
|
CommandCost ret = this->BeforeAddTile(tile, mode);
|
|
|
|
if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
|
2010-03-06 13:23:33 +00:00
|
|
|
return ret;
|
2010-03-06 12:15:03 +00:00
|
|
|
}
|
2010-03-06 13:23:33 +00:00
|
|
|
return CommandCost();
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/**
|
|
|
|
* Check whether station tiles of the given station id exist in the given rectangle
|
|
|
|
* @param st_id Station ID to look for in the rectangle
|
|
|
|
* @param left_a Minimal tile X edge of the rectangle
|
|
|
|
* @param top_a Minimal tile Y edge of the rectangle
|
|
|
|
* @param right_a Maximal tile X edge of the rectangle (inclusive)
|
|
|
|
* @param bottom_a Maximal tile Y edge of the rectangle (inclusive)
|
|
|
|
* @return \c true if a station tile with the given \a st_id exists in the rectangle, \c false otherwise
|
|
|
|
*/
|
2009-03-15 00:32:18 +00:00
|
|
|
/* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
|
2007-01-14 23:02:12 +00:00
|
|
|
{
|
2010-12-12 17:36:34 +00:00
|
|
|
TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
|
2021-05-12 14:45:28 +00:00
|
|
|
for (TileIndex tile : ta) {
|
2007-01-14 23:02:12 +00:00
|
|
|
if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
|
2009-07-26 21:50:30 +00:00
|
|
|
}
|
2007-01-14 23:36:25 +00:00
|
|
|
|
2007-01-14 23:02:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-26 16:17:49 +00:00
|
|
|
bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
|
2007-01-14 23:02:12 +00:00
|
|
|
{
|
|
|
|
int x = TileX(tile);
|
|
|
|
int y = TileY(tile);
|
|
|
|
|
2007-01-14 23:36:25 +00:00
|
|
|
/* look if removed tile was on the bounding rect edge
|
|
|
|
* and try to reduce the rect by this edge
|
|
|
|
* do it until we have empty rect or nothing to do */
|
2007-01-14 23:02:12 +00:00
|
|
|
for (;;) {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* check if removed tile is on rect edge */
|
2009-07-07 11:21:29 +00:00
|
|
|
bool left_edge = (x == this->left);
|
|
|
|
bool right_edge = (x == this->right);
|
|
|
|
bool top_edge = (y == this->top);
|
|
|
|
bool bottom_edge = (y == this->bottom);
|
2007-01-14 23:36:25 +00:00
|
|
|
|
|
|
|
/* can we reduce the rect in either direction? */
|
2009-07-07 11:21:29 +00:00
|
|
|
bool reduce_x = ((left_edge || right_edge) && !ScanForStationTiles(st->index, x, this->top, x, this->bottom));
|
|
|
|
bool reduce_y = ((top_edge || bottom_edge) && !ScanForStationTiles(st->index, this->left, y, this->right, y));
|
2007-01-14 23:02:12 +00:00
|
|
|
if (!(reduce_x || reduce_y)) break; // nothing to do (can't reduce)
|
2007-01-14 23:36:25 +00:00
|
|
|
|
2007-01-14 23:02:12 +00:00
|
|
|
if (reduce_x) {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* reduce horizontally */
|
2007-01-14 23:02:12 +00:00
|
|
|
if (left_edge) {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* move left edge right */
|
2009-07-07 11:21:29 +00:00
|
|
|
this->left = x = x + 1;
|
2007-01-14 23:02:12 +00:00
|
|
|
} else {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* move right edge left */
|
2009-07-07 11:21:29 +00:00
|
|
|
this->right = x = x - 1;
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (reduce_y) {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* reduce vertically */
|
2007-01-14 23:02:12 +00:00
|
|
|
if (top_edge) {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* move top edge down */
|
2009-07-07 11:21:29 +00:00
|
|
|
this->top = y = y + 1;
|
2007-01-14 23:02:12 +00:00
|
|
|
} else {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* move bottom edge up */
|
2009-07-07 11:21:29 +00:00
|
|
|
this->bottom = y = y - 1;
|
2007-01-14 23:02:12 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-14 23:36:25 +00:00
|
|
|
|
2007-01-14 23:02:12 +00:00
|
|
|
if (left > right || top > bottom) {
|
2007-01-14 23:36:25 +00:00
|
|
|
/* can't continue, if the remaining rectangle is empty */
|
2009-07-07 11:21:29 +00:00
|
|
|
this->MakeEmpty();
|
2007-01-14 23:02:12 +00:00
|
|
|
return true; // empty remaining rect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false; // non-empty remaining rect
|
|
|
|
}
|
|
|
|
|
2010-03-06 13:38:46 +00:00
|
|
|
bool StationRect::AfterRemoveRect(BaseStation *st, TileArea ta)
|
2007-01-14 23:02:12 +00:00
|
|
|
{
|
2010-03-06 13:38:46 +00:00
|
|
|
assert(this->PtInExtendedRect(TileX(ta.tile), TileY(ta.tile)));
|
|
|
|
assert(this->PtInExtendedRect(TileX(ta.tile) + ta.w - 1, TileY(ta.tile) + ta.h - 1));
|
2007-01-14 23:36:25 +00:00
|
|
|
|
2010-03-06 13:38:46 +00:00
|
|
|
bool empty = this->AfterRemoveTile(st, ta.tile);
|
|
|
|
if (ta.w != 1 || ta.h != 1) empty = empty || this->AfterRemoveTile(st, TILE_ADDXY(ta.tile, ta.w - 1, ta.h - 1));
|
2007-01-14 23:02:12 +00:00
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
2010-03-06 11:54:59 +00:00
|
|
|
StationRect& StationRect::operator = (const Rect &src)
|
2007-01-14 23:02:12 +00:00
|
|
|
{
|
2009-07-07 11:21:29 +00:00
|
|
|
this->left = src.left;
|
|
|
|
this->top = src.top;
|
|
|
|
this->right = src.right;
|
|
|
|
this->bottom = src.bottom;
|
2007-01-14 23:02:12 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2011-12-03 23:40:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the maintenance cost of all airports of a company.
|
|
|
|
* @param owner Company.
|
|
|
|
* @return Total cost.
|
|
|
|
*/
|
|
|
|
Money AirportMaintenanceCost(Owner owner)
|
|
|
|
{
|
|
|
|
Money total_cost = 0;
|
|
|
|
|
2019-12-15 04:55:59 +00:00
|
|
|
for (const Station *st : Station::Iterate()) {
|
2011-12-03 23:40:46 +00:00
|
|
|
if (st->owner == owner && (st->facilities & FACIL_AIRPORT)) {
|
|
|
|
total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 3 bits fraction for the maintenance cost factor. */
|
|
|
|
return total_cost >> 3;
|
|
|
|
}
|
2019-02-24 18:52:15 +00:00
|
|
|
|
|
|
|
bool StationCompare::operator() (const Station *lhs, const Station *rhs) const
|
|
|
|
{
|
|
|
|
return lhs->index < rhs->index;
|
|
|
|
}
|