From 9db3cde73af598852da13b748eef31a8207cfcf2 Mon Sep 17 00:00:00 2001 From: frosch Date: Mon, 31 May 2010 20:22:57 +0000 Subject: (svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration. --- src/town_cmd.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/town_cmd.cpp') diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index f6a2f0d4f..8cc3c59d9 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -45,6 +45,7 @@ #include "townname_func.h" #include "townname_type.h" #include "core/random_func.hpp" +#include "core/backup_type.hpp" #include "table/strings.h" #include "table/town_land.h" @@ -515,7 +516,7 @@ static void TileLoop_Town(TileIndex tile) } } - _current_company = OWNER_TOWN; + Backup cur_company(_current_company, OWNER_TOWN); if ((hs->building_flags & BUILDING_HAS_1_TILE) && HasBit(t->flags, TOWN_IS_FUNDED) && @@ -530,7 +531,7 @@ static void TileLoop_Town(TileIndex tile) if (GB(r, 24, 8) >= 12) BuildTownHouse(t, tile); } - _current_company = OWNER_NONE; + cur_company.Restore(); } static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags) @@ -1296,8 +1297,7 @@ static bool GrowTown(Town *t) }; /* Current "company" is a town */ - CompanyID old_company = _current_company; - _current_company = OWNER_TOWN; + Backup cur_company(_current_company, OWNER_TOWN); TileIndex tile = t->xy; // The tile we are working with ATM @@ -1306,7 +1306,7 @@ static bool GrowTown(Town *t) for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) { if (GetTownRoadBits(tile) != ROAD_NONE) { int r = GrowTownAtRoad(t, tile); - _current_company = old_company; + cur_company.Restore(); return r != 0; } tile = TILE_ADD(tile, ToTileIndexDiff(*ptr)); @@ -1321,7 +1321,7 @@ static bool GrowTown(Town *t) if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) { if (DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded()) { DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD); - _current_company = old_company; + cur_company.Restore(); return true; } } @@ -1329,7 +1329,7 @@ static bool GrowTown(Town *t) } } - _current_company = old_company; + cur_company.Restore(); return false; } @@ -2383,10 +2383,9 @@ static bool DoBuildStatueOfCompany(TileIndex tile, TownID town_id) return false; } - CompanyID old = _current_company; - _current_company = OWNER_NONE; + Backup cur_company(_current_company, OWNER_NONE); CommandCost r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); - _current_company = old; + cur_company.Restore(); if (r.Failed()) return false; -- cgit v1.2.3-54-g00ecf