Changeset - r26441:fbfcf787e54d
[Not reviewed]
master
0 4 0
SamuXarick - 2 years ago 2022-05-24 20:11:23
43006711+SamuXarick@users.noreply.github.com
Fix #9869: remove docking tile when doing a clear square

Terraforming through objects placed on water didn't properly remove docking tiles as expected.

By moving some logic regarding removal of docking tiles into DoClearSquare, the issue is solved, while also simplifying code, avoiding repetition elsewhere.
4 files changed with 3 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/landscape.cpp
Show inline comments
 
@@ -29,12 +29,13 @@
 
#include "object_base.h"
 
#include "company_func.h"
 
#include "pathfinder/npf/aystar.h"
 
#include "saveload/saveload.h"
 
#include "framerate_type.h"
 
#include "landscape_cmd.h"
 
#include "station_func.h"
 
#include <array>
 
#include <list>
 
#include <set>
 

	
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
@@ -571,14 +572,16 @@ void DrawFoundation(TileInfo *ti, Founda
 

	
 
void DoClearSquare(TileIndex tile)
 
{
 
	/* If the tile can have animation and we clear it, delete it from the animated tile list. */
 
	if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != nullptr) DeleteAnimatedTile(tile);
 

	
 
	bool remove = IsDockingTile(tile);
 
	MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
 
	MarkTileDirtyByTile(tile);
 
	if (remove) RemoveDockingTile(tile);
 
}
 

	
 
/**
 
 * Returns information about trackdirs and signal states.
 
 * If there is any trackbit at 'side', return all trackdirbits.
 
 * For TRANSPORT_ROAD, return no trackbits if there is no roadbit (of given subtype) at given side.
src/rail_cmd.cpp
Show inline comments
 
@@ -1816,15 +1816,13 @@ static CommandCost ClearTile_Track(TileI
 
			if (water_ground && !(flags & DC_BANKRUPT) && Company::IsValidID(_current_company)) {
 
				CommandCost ret = EnsureNoVehicleOnGround(tile);
 
				if (ret.Failed()) return ret;
 

	
 
				/* The track was removed, and left a coast tile. Now also clear the water. */
 
				if (flags & DC_EXEC) {
 
					bool remove = IsDockingTile(tile);
 
					DoClearSquare(tile);
 
					if (remove) RemoveDockingTile(tile);
 
				}
 
				cost.AddCost(_price[PR_CLEAR_WATER]);
 
			}
 

	
 
			return cost;
 
		}
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -965,34 +965,27 @@ static CommandCost DoClearBridge(TileInd
 

	
 
		if (rail && HasTunnelBridgeReservation(tile)) {
 
			v = GetTrainForReservation(tile, DiagDirToDiagTrack(direction));
 
			if (v != nullptr) FreeTrainTrackReservation(v);
 
		}
 

	
 
		bool removetile = false;
 
		bool removeendtile = false;
 

	
 
		/* Update company infrastructure counts. */
 
		if (rail) {
 
			if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
		} else if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
 
			/* A full diagonal road tile has two road bits. */
 
			UpdateCompanyRoadInfrastructure(GetRoadTypeRoad(tile), GetRoadOwner(tile, RTT_ROAD), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
 
			UpdateCompanyRoadInfrastructure(GetRoadTypeTram(tile), GetRoadOwner(tile, RTT_TRAM), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
 
		} else { // Aqueduct
 
			if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.water -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
 
			removetile    = IsDockingTile(tile);
 
			removeendtile = IsDockingTile(endtile);
 
		}
 
		DirtyCompanyInfrastructureWindows(owner);
 

	
 
		DoClearSquare(tile);
 
		DoClearSquare(endtile);
 

	
 
		if (removetile)    RemoveDockingTile(tile);
 
		if (removeendtile) RemoveDockingTile(endtile);
 
		for (TileIndex c = tile + delta; c != endtile; c += delta) {
 
			/* do not let trees appear from 'nowhere' after removing bridge */
 
			if (IsNormalRoadTile(c) && GetRoadside(c) == ROADSIDE_TREES) {
 
				int minz = GetTileMaxZ(c) + 3;
 
				if (height < minz) SetRoadside(c, ROADSIDE_PAVED);
 
			}
src/water_cmd.cpp
Show inline comments
 
@@ -545,16 +545,14 @@ static CommandCost ClearTile_Water(TileI
 

	
 
			if (flags & DC_EXEC) {
 
				if (IsCanal(tile) && Company::IsValidID(owner)) {
 
					Company::Get(owner)->infrastructure.water--;
 
					DirtyCompanyInfrastructureWindows(owner);
 
				}
 
				bool remove = IsDockingTile(tile);
 
				DoClearSquare(tile);
 
				MarkCanalsAndRiversAroundDirty(tile);
 
				if (remove) RemoveDockingTile(tile);
 
			}
 

	
 
			return CommandCost(EXPENSES_CONSTRUCTION, base_cost);
 
		}
 

	
 
		case WATER_TILE_COAST: {
 
@@ -562,16 +560,14 @@ static CommandCost ClearTile_Water(TileI
 

	
 
			/* Make sure no vehicle is on the tile */
 
			CommandCost ret = EnsureNoVehicleOnGround(tile);
 
			if (ret.Failed()) return ret;
 

	
 
			if (flags & DC_EXEC) {
 
				bool remove = IsDockingTile(tile);
 
				DoClearSquare(tile);
 
				MarkCanalsAndRiversAroundDirty(tile);
 
				if (remove) RemoveDockingTile(tile);
 
			}
 
			if (IsSlopeWithOneCornerRaised(slope)) {
 
				return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WATER]);
 
			} else {
 
				return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_ROUGH]);
 
			}
0 comments (0 inline, 0 general)