|
@@ -102,13 +102,13 @@ bool IsHangar(TileIndex t)
|
|
|
template <class T>
|
|
|
CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID company, T **st)
|
|
|
{
|
|
|
ta.Expand(1);
|
|
|
|
|
|
/* check around to see if there are any stations there owned by the company */
|
|
|
TILE_AREA_LOOP(tile_cur, ta) {
|
|
|
for (TileIndex tile_cur : ta) {
|
|
|
if (IsTileType(tile_cur, MP_STATION)) {
|
|
|
StationID t = GetStationIndex(tile_cur);
|
|
|
if (!T::IsValidID(t) || Station::Get(t)->owner != company) continue;
|
|
|
if (closest_station == INVALID_STATION) {
|
|
|
closest_station = t;
|
|
|
} else if (closest_station != t) {
|
|
@@ -508,13 +508,13 @@ CargoArray GetProductionAroundTiles(Tile
|
|
|
CargoArray produced;
|
|
|
std::set<IndustryID> industries;
|
|
|
TileArea ta = TileArea(tile, w, h).Expand(rad);
|
|
|
|
|
|
/* Loop over all tiles to get the produced cargo of
|
|
|
* everything except industries */
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
|
|
for (TileIndex tile : ta) {
|
|
|
if (IsTileType(tile, MP_INDUSTRY)) industries.insert(GetIndustryIndex(tile));
|
|
|
AddProducedCargo(tile, produced);
|
|
|
}
|
|
|
|
|
|
/* Loop over the seen industries. They produce cargo for
|
|
|
* anything that is within 'rad' of any one of their tiles.
|
|
@@ -546,13 +546,13 @@ CargoArray GetAcceptanceAroundTiles(Tile
|
|
|
{
|
|
|
CargoArray acceptance;
|
|
|
if (always_accepted != nullptr) *always_accepted = 0;
|
|
|
|
|
|
TileArea ta = TileArea(tile, w, h).Expand(rad);
|
|
|
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
|
|
for (TileIndex tile : ta) {
|
|
|
/* Ignore industry if it has a neutral station. */
|
|
|
if (!_settings_game.station.serve_neutral_industries && IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile)->neutral_station != nullptr) continue;
|
|
|
|
|
|
AddAcceptedCargo(tile, acceptance, always_accepted);
|
|
|
}
|
|
|
|
|
@@ -869,13 +869,13 @@ static CommandCost CheckFlatLandRailStat
|
|
|
int allowed_z = -1;
|
|
|
uint invalid_dirs = 5 << axis;
|
|
|
|
|
|
const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
|
|
|
bool slope_cb = statspec != nullptr && HasBit(statspec->callback_mask, CBM_STATION_SLOPE_CHECK);
|
|
|
|
|
|
TILE_AREA_LOOP(tile_cur, tile_area) {
|
|
|
for (TileIndex tile_cur : tile_area) {
|
|
|
CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false);
|
|
|
if (ret.Failed()) return ret;
|
|
|
cost.AddCost(ret);
|
|
|
|
|
|
if (slope_cb) {
|
|
|
/* Do slope check if requested. */
|
|
@@ -951,13 +951,13 @@ static CommandCost CheckFlatLandRailStat
|
|
|
*/
|
|
|
static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, bool is_drive_through, bool is_truck_stop, Axis axis, StationID *station, RoadType rt)
|
|
|
{
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
|
int allowed_z = -1;
|
|
|
|
|
|
TILE_AREA_LOOP(cur_tile, tile_area) {
|
|
|
for (TileIndex cur_tile : tile_area) {
|
|
|
CommandCost ret = CheckBuildableTile(cur_tile, invalid_dirs, allowed_z, !is_drive_through);
|
|
|
if (ret.Failed()) return ret;
|
|
|
cost.AddCost(ret);
|
|
|
|
|
|
/* If station is set, then we have special handling to allow building on top of already existing stations.
|
|
|
* Station points to INVALID_STATION if we can build on any station.
|
|
@@ -1432,13 +1432,13 @@ CommandCost CmdBuildRailStation(TileInde
|
|
|
if (axis == AXIS_X) {
|
|
|
update_reservation_area = TileArea(tile_org, 1, numtracks_orig);
|
|
|
} else {
|
|
|
update_reservation_area = TileArea(tile_org, numtracks_orig, 1);
|
|
|
}
|
|
|
|
|
|
TILE_AREA_LOOP(tile, update_reservation_area) {
|
|
|
for (TileIndex tile : update_reservation_area) {
|
|
|
/* Don't even try to make eye candy parts reserved. */
|
|
|
if (IsStationTileBlocked(tile)) continue;
|
|
|
|
|
|
DiagDirection dir = AxisToDiagDir(axis);
|
|
|
TileIndexDiff tile_offset = TileOffsByDiagDir(dir);
|
|
|
TileIndex platform_begin = tile;
|
|
@@ -1560,13 +1560,13 @@ CommandCost RemoveFromRailBaseStation(Ti
|
|
|
/* Accumulator for the errors seen during clearing. If no errors happen,
|
|
|
* and the quantity is 0 there is no station. Otherwise it will be one
|
|
|
* of the other error that got accumulated. */
|
|
|
CommandCost error;
|
|
|
|
|
|
/* Do the action for every tile into the area */
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
|
|
for (TileIndex tile : ta) {
|
|
|
/* Make sure the specified tile is a rail station */
|
|
|
if (!HasStationTileRail(tile)) continue;
|
|
|
|
|
|
/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
|
|
|
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
|
|
error.AddCost(ret);
|
|
@@ -1726,13 +1726,13 @@ CommandCost RemoveRailStation(T *st, DoC
|
|
|
TileArea ta = st->train_station;
|
|
|
|
|
|
assert(ta.w != 0 && ta.h != 0);
|
|
|
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
|
/* clear all areas of the station */
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
|
|
for (TileIndex tile : ta) {
|
|
|
/* only remove tiles that are actually train station tiles */
|
|
|
if (st->TileBelongsToRailStation(tile)) {
|
|
|
std::vector<T*> affected_stations; // dummy
|
|
|
CommandCost ret = RemoveFromRailBaseStation(TileArea(tile, 1, 1), affected_stations, flags, removal_cost, false);
|
|
|
if (ret.Failed()) return ret;
|
|
|
cost.AddCost(ret);
|
|
@@ -1891,13 +1891,13 @@ CommandCost CmdBuildRoadStop(TileIndex t
|
|
|
|
|
|
ret = BuildStationPart(&st, flags, reuse, roadstop_area, STATIONNAMING_ROAD);
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
/* Check every tile in the area. */
|
|
|
TILE_AREA_LOOP(cur_tile, roadstop_area) {
|
|
|
for (TileIndex cur_tile : roadstop_area) {
|
|
|
/* Get existing road types and owners before any tile clearing */
|
|
|
RoadType road_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_ROAD) : INVALID_ROADTYPE;
|
|
|
RoadType tram_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_TRAM) : INVALID_ROADTYPE;
|
|
|
Owner road_owner = road_rt != INVALID_ROADTYPE ? GetRoadOwner(cur_tile, RTT_ROAD) : _current_company;
|
|
|
Owner tram_owner = tram_rt != INVALID_ROADTYPE ? GetRoadOwner(cur_tile, RTT_TRAM) : _current_company;
|
|
|
|
|
@@ -2098,13 +2098,13 @@ CommandCost CmdRemoveRoadStop(TileIndex
|
|
|
TileArea roadstop_area(tile, width, height);
|
|
|
|
|
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
|
|
CommandCost last_error(STR_ERROR_THERE_IS_NO_STATION);
|
|
|
bool had_success = false;
|
|
|
|
|
|
TILE_AREA_LOOP(cur_tile, roadstop_area) {
|
|
|
for (TileIndex cur_tile : roadstop_area) {
|
|
|
/* Make sure the specified tile is a road stop of the correct type */
|
|
|
if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || (uint32)GetRoadStopType(cur_tile) != GB(p2, 0, 1)) continue;
|
|
|
|
|
|
/* Save information on to-be-restored roads before the stop is removed. */
|
|
|
RoadBits road_bits = ROAD_NONE;
|
|
|
RoadType road_type[] = { INVALID_ROADTYPE, INVALID_ROADTYPE };
|
|
@@ -2406,13 +2406,13 @@ static CommandCost RemoveAirport(TileInd
|
|
|
AirportTileIterator it(st);
|
|
|
uint dist;
|
|
|
Town *nearest = AirportGetNearestTown(as, it, dist);
|
|
|
nearest->noise_reached -= GetAirportNoiseLevelForDistance(as, dist);
|
|
|
}
|
|
|
|
|
|
TILE_AREA_LOOP(tile_cur, st->airport) {
|
|
|
for (TileIndex tile_cur : st->airport) {
|
|
|
if (!st->TileBelongsToAirport(tile_cur)) continue;
|
|
|
|
|
|
CommandCost ret = EnsureNoVehicleOnGround(tile_cur);
|
|
|
if (ret.Failed()) return ret;
|
|
|
|
|
|
cost.AddCost(_price[PR_CLEAR_STATION_AIRPORT]);
|
|
@@ -4117,13 +4117,13 @@ void UpdateStationDockingTiles(Station *
|
|
|
int x1 = std::max<int>(x - 1, 0);
|
|
|
|
|
|
int y2 = std::min<int>(y + area->h + 1, MapSizeY());
|
|
|
int y1 = std::max<int>(y - 1, 0);
|
|
|
|
|
|
TileArea ta(TileXY(x1, y1), TileXY(x2 - 1, y2 - 1));
|
|
|
TILE_AREA_LOOP(tile, ta) {
|
|
|
for (TileIndex tile : ta) {
|
|
|
if (IsValidTile(tile) && IsPossibleDockingTile(tile)) CheckForDockingTile(tile);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void BuildOilRig(TileIndex tile)
|
|
|
{
|