summaryrefslogtreecommitdiff
path: root/src/industry_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/industry_cmd.cpp')
-rw-r--r--src/industry_cmd.cpp43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 304f9bd27..f425daf34 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -43,6 +43,7 @@
#include "ai/ai.hpp"
#include "core/pool_func.hpp"
#include "subsidy_func.h"
+#include "core/backup_type.hpp"
#include "table/strings.h"
#include "table/industry_land.h"
@@ -1040,17 +1041,17 @@ void PlantRandomFarmField(const Industry *i)
static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
{
if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
- CompanyID old_company = _current_company;
/* found a tree */
- _current_company = OWNER_NONE;
+ Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
+
_industry_sound_ctr = 1;
_industry_sound_tile = tile;
SndPlayTileFx(SND_38_CHAINSAW, tile);
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
- _current_company = old_company;
+ cur_company.Restore();
return true;
}
return false;
@@ -1371,10 +1372,9 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil
}
/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
- CompanyID old_company = _current_company;
- _current_company = OWNER_TOWN;
+ Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN);
CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
- _current_company = old_company;
+ cur_company.Restore();
if (ret.Failed()) return ret;
} else {
@@ -1484,8 +1484,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
/* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry.
* Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */
- CompanyID old_company = _current_company;
- _current_company = OWNER_TOWN;
+ Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN);
TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
curh = TileHeight(tile_walk);
@@ -1493,13 +1492,13 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
/* This tile needs terraforming. Check if we can do that without
* damaging the surroundings too much. */
if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
- _current_company = old_company;
+ cur_company.Restore();
return false;
}
/* This is not 100% correct check, but the best we can do without modifying the map.
* What is missing, is if the difference in height is more than 1.. */
if (DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND).Failed()) {
- _current_company = old_company;
+ cur_company.Restore();
return false;
}
}
@@ -1519,7 +1518,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
}
}
- _current_company = old_company;
+ cur_company.Restore();
return true;
}
@@ -1789,8 +1788,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
if (flags & DC_EXEC) {
/* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */
- CompanyID founder = _current_company;
- _current_company = OWNER_TOWN;
+ Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN);
/* Prospecting has a chance to fail, however we cannot guarantee that something can
* be built on the map, so the chance gets lower when the map is fuller, but there
* is nothing we can really do about that. */
@@ -1800,11 +1798,11 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
* because parameter evaluation order is not guaranteed in the c++ standard
*/
tile = RandomTile();
- CommandCost ret = CreateNewIndustryHelper(tile, it, flags, indspec, RandomRange(indspec->num_table), random_var8f, random_initial_bits, founder, &ind);
+ CommandCost ret = CreateNewIndustryHelper(tile, it, flags, indspec, RandomRange(indspec->num_table), random_var8f, random_initial_bits, cur_company.GetOriginalValue(), &ind);
if (ret.Succeeded()) break;
}
}
- _current_company = founder;
+ cur_company.Restore();
}
} else {
int count = indspec->num_table;
@@ -1892,8 +1890,7 @@ static const byte _numof_industry_table[]= {
*/
static void PlaceInitialIndustry(IndustryType type, bool try_hard)
{
- CompanyID old_company = _current_company;
- _current_company = OWNER_NONE;
+ Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
IncreaseGeneratingWorldProgress(GWP_INDUSTRY);
@@ -1901,7 +1898,7 @@ static void PlaceInitialIndustry(IndustryType type, bool try_hard)
if (CreateNewIndustry(RandomTile(), type) != NULL) break;
}
- _current_company = old_company;
+ cur_company.Restore();
}
/**
@@ -2417,8 +2414,7 @@ void IndustryDailyLoop()
return; // Nothing to do? get out
}
- CompanyID old_company = _current_company;
- _current_company = OWNER_NONE;
+ Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
/* perform the required industry changes for the day */
for (uint16 j = 0; j < change_loop; j++) {
@@ -2434,7 +2430,7 @@ void IndustryDailyLoop()
}
}
- _current_company = old_company;
+ cur_company.Restore();
/* production-change */
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);
@@ -2443,8 +2439,7 @@ void IndustryDailyLoop()
void IndustryMonthlyLoop()
{
Industry *i;
- CompanyID old_company = _current_company;
- _current_company = OWNER_NONE;
+ Backup<CompanyByte> cur_company(_current_company, OWNER_NONE);
FOR_ALL_INDUSTRIES(i) {
UpdateIndustryStatistics(i);
@@ -2456,7 +2451,7 @@ void IndustryMonthlyLoop()
}
}
- _current_company = old_company;
+ cur_company.Restore();
/* production-change */
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);