Index: src/water_cmd.cpp =================================================================== --- src/water_cmd.cpp (revision 27196) +++ src/water_cmd.cpp (working copy) @@ -123,6 +123,8 @@ CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_DEPOT_SHIP]); bool add_cost = !IsWaterTile(tile); + bool river1 = HasBit(_me[tile].m6, 0); + bool river2 = HasBit(_me[tile2].m6, 0); CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR); if (ret.Failed()) return ret; if (add_cost) { @@ -145,7 +147,8 @@ } Company::Get(_current_company)->infrastructure.water += 2 * LOCK_DEPOT_TILE_FACTOR; DirtyCompanyInfrastructureWindows(_current_company); - + if (river1) SB(_me[tile].m6, 0, 1, 1); + if (river2) SB(_me[tile2].m6, 0, 1, 1); MakeShipDepot(tile, _current_company, depot->index, DEPOT_PART_NORTH, axis, wc1); MakeShipDepot(tile2, _current_company, depot->index, DEPOT_PART_SOUTH, axis, wc2); MarkTileDirtyByTile(tile); @@ -209,13 +212,16 @@ static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags) { + TileIndex tile2 = GetOtherShipDepotTile(tile); + bool river1 = HasBit(_me[tile].m6, 0); + bool river2 = HasBit(_me[tile2].m6, 0); if (!IsShipDepot(tile)) return CMD_ERROR; CommandCost ret = CheckTileOwnership(tile); if (ret.Failed()) return ret; - TileIndex tile2 = GetOtherShipDepotTile(tile); + /* do not check for ship on tile when company goes bankrupt */ if (!(flags & DC_BANKRUPT)) { CommandCost ret = EnsureNoVehicleOnGround(tile); @@ -231,7 +237,8 @@ c->infrastructure.water -= 2 * LOCK_DEPOT_TILE_FACTOR; DirtyCompanyInfrastructureWindows(c->index); } - + if (river1) SB(_me[tile].m6, 0, 1, 1); + if (river2) SB(_me[tile2].m6, 0, 1, 1); MakeWaterKeepingClass(tile, GetTileOwner(tile)); MakeWaterKeepingClass(tile2, GetTileOwner(tile2)); } @@ -264,7 +271,7 @@ /* lower tile */ WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL; - + if (!IsWaterTile(tile - delta)) { ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); if (ret.Failed()) return ret; @@ -277,7 +284,7 @@ /* upper tile */ WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL; - + if (!IsWaterTile(tile + delta)) { ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR); if (ret.Failed()) return ret; @@ -291,7 +298,8 @@ if (IsBridgeAbove(tile) || IsBridgeAbove(tile - delta) || IsBridgeAbove(tile + delta)) { return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); } - + bool river_lower = HasBit(_me[tile - delta].m6, 0); + bool river_upper = HasBit(_me[tile + delta].m6, 0); if (flags & DC_EXEC) { /* Update company infrastructure counts. */ Company *c = Company::GetIfValid(_current_company); @@ -303,7 +311,8 @@ c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // Lock is three tiles. DirtyCompanyInfrastructureWindows(_current_company); } - + if (river_lower) SB(_me[tile - delta].m6, 0, 1, 1); + if (river_upper) SB(_me[tile + delta].m6, 0, 1, 1); MakeLock(tile, _current_company, dir, wc_lower, wc_upper, wc_middle); MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile - delta); @@ -336,7 +345,8 @@ if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta); if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta); if (ret.Failed()) return ret; - + bool river_lower = HasBit(_me[tile - delta].m6, 0); + bool river_upper = HasBit(_me[tile + delta].m6, 0); if (flags & DC_EXEC) { /* Remove middle part from company infrastructure count. */ Company *c = Company::GetIfValid(GetTileOwner(tile)); @@ -352,6 +362,8 @@ } MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta)); MakeWaterKeepingClass(tile - delta, GetTileOwner(tile - delta)); + if (river_lower) SB(_me[tile - delta].m6, 0, 1, 1); + if (river_upper) SB(_me[tile + delta].m6, 0, 1, 1); MarkCanalsAndRiversAroundDirty(tile); MarkCanalsAndRiversAroundDirty(tile - delta); MarkCanalsAndRiversAroundDirty(tile + delta); @@ -419,6 +431,7 @@ if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || wc == WATER_CLASS_SEA)) continue; bool water = IsWaterTile(tile); + bool river = HasTileWaterClass(tile) && GetWaterClass(tile) == WATER_CLASS_RIVER; ret = DoCommand(tile, 0, 0, flags | DC_FORCE_CLEAR_TILE, CMD_LANDSCAPE_CLEAR); if (ret.Failed()) return ret; @@ -442,6 +455,7 @@ /* FALL THROUGH */ default: + if (river) SB(_me[tile].m6, 0, 1, 1); MakeCanal(tile, _current_company, Random()); if (Company::IsValidID(_current_company)) { Company::Get(_current_company)->infrastructure.water++; @@ -465,6 +479,7 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags) { + bool river = HasBit(_me[tile].m6, 0); switch (GetWaterTileType(tile)) { case WATER_TILE_CLEAR: { if (flags & DC_NO_WATER) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); @@ -485,7 +500,6 @@ CommandCost ret = CheckTileOwnership(tile); if (ret.Failed()) return ret; } - if (flags & DC_EXEC) { if (IsCanal(tile) && Company::IsValidID(owner)) { Company::Get(owner)->infrastructure.water--; @@ -492,9 +506,9 @@ DirtyCompanyInfrastructureWindows(owner); } DoClearSquare(tile); + if (river) MakeRiver(tile, Random()); MarkCanalsAndRiversAroundDirty(tile); } - return CommandCost(EXPENSES_CONSTRUCTION, base_cost); }