summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoïc Guilloux <glx22@users.noreply.github.com>2021-07-10 14:59:17 +0200
committerGitHub <noreply@github.com>2021-07-10 14:59:17 +0200
commitddb6024bc69c63e3dafec61b3f642eedc57555cc (patch)
treea10cdfd3bd372f8b86636392013fef4bb1739f18
parent85faa218ffe3cc8eab9c8822a9f5a5117937d8b6 (diff)
downloadopenttd-ddb6024bc69c63e3dafec61b3f642eedc57555cc.tar.xz
Codechange: Don't explicitly unset _generating_world outside of genworld.cpp (#9418)
-rw-r--r--src/industry_gui.cpp8
-rw-r--r--src/terraform_cmd.cpp7
-rw-r--r--src/terraform_gui.cpp9
-rw-r--r--src/town_gui.cpp8
4 files changed, 18 insertions, 14 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 5757a3048..d3e3d2a16 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -608,9 +608,9 @@ public:
ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_INDUSTRIES, STR_ERROR_MUST_FOUND_TOWN_FIRST, WL_INFO);
} else {
extern void GenerateIndustries();
- _generating_world = true;
+ Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
GenerateIndustries();
- _generating_world = false;
+ old_generating_world.Restore();
}
}
@@ -712,15 +712,15 @@ public:
}
Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
- _generating_world = true;
+ Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
_ignore_restrictions = true;
DoCommandP(tile, (layout_index << 8) | this->selected_type, seed,
CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY), &CcBuildIndustry);
cur_company.Restore();
+ old_generating_world.Restore();
_ignore_restrictions = false;
- _generating_world = false;
} else {
success = DoCommandP(tile, (layout_index << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY));
}
diff --git a/src/terraform_cmd.cpp b/src/terraform_cmd.cpp
index f23ba78c6..eaed9e71c 100644
--- a/src/terraform_cmd.cpp
+++ b/src/terraform_cmd.cpp
@@ -16,6 +16,7 @@
#include "object_base.h"
#include "company_base.h"
#include "company_func.h"
+#include "core/backup_type.hpp"
#include "table/strings.h"
@@ -279,8 +280,8 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
bool indirectly_cleared = coa != nullptr && coa->first_tile != t;
/* Check tiletype-specific things, and add extra-cost */
- const bool curr_gen = _generating_world;
- if (_game_mode == GM_EDITOR) _generating_world = true; // used to create green terraformed land
+ Backup<bool> old_generating_world(_generating_world, FILE_LINE);
+ if (_game_mode == GM_EDITOR) old_generating_world.Change(true); // used to create green terraformed land
DoCommandFlag tile_flags = flags | DC_AUTO | DC_FORCE_CLEAR_TILE;
if (pass == 0) {
tile_flags &= ~DC_EXEC;
@@ -292,7 +293,7 @@ CommandCost CmdTerraformLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
} else {
cost = _tile_type_procs[GetTileType(t)]->terraform_tile_proc(t, tile_flags, z_min, tileh);
}
- _generating_world = curr_gen;
+ old_generating_world.Restore();
if (cost.Failed()) {
_terraform_err_tile = t;
return cost;
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index 6094c710f..f710cecc5 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -8,6 +8,7 @@
/** @file terraform_gui.cpp GUI related to terraforming the map. */
#include "stdafx.h"
+#include "core/backup_type.hpp"
#include "clear_map.h"
#include "company_func.h"
#include "company_base.h"
@@ -54,7 +55,7 @@ static void GenerateDesertArea(TileIndex end, TileIndex start)
{
if (_game_mode != GM_EDITOR) return;
- _generating_world = true;
+ Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
TileArea ta(start, end);
for (TileIndex tile : ta) {
@@ -62,7 +63,7 @@ static void GenerateDesertArea(TileIndex end, TileIndex start)
DoCommandP(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
MarkTileDirtyByTile(tile);
}
- _generating_world = false;
+ old_generating_world.Restore();
InvalidateWindowClassesData(WC_TOWN_VIEW, 0);
}
@@ -497,7 +498,7 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
if (confirmed) {
/* Set generating_world to true to get instant-green grass after removing
* company property. */
- _generating_world = true;
+ Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
/* Delete all companies */
for (Company *c : Company::Iterate()) {
@@ -505,7 +506,7 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
delete c;
}
- _generating_world = false;
+ old_generating_world.Restore();
/* Delete all station signs */
for (BaseStation *st : BaseStation::Iterate()) {
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index ec44b246b..a4bb24063 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -27,6 +27,7 @@
#include "querystring_gui.h"
#include "window_func.h"
#include "townname_func.h"
+#include "core/backup_type.hpp"
#include "core/geometry_func.hpp"
#include "genworld.h"
#include "stringfilter_type.h"
@@ -1184,15 +1185,16 @@ public:
this->SetFocusedWidget(WID_TF_TOWN_NAME_EDITBOX);
break;
- case WID_TF_MANY_RANDOM_TOWNS:
- _generating_world = true;
+ case WID_TF_MANY_RANDOM_TOWNS: {
+ Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
UpdateNearestTownForRoadTiles(true);
if (!GenerateTowns(this->town_layout)) {
ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_TOWN, STR_ERROR_NO_SPACE_FOR_TOWN, WL_INFO);
}
UpdateNearestTownForRoadTiles(false);
- _generating_world = false;
+ old_generating_world.Restore();
break;
+ }
case WID_TF_SIZE_SMALL: case WID_TF_SIZE_MEDIUM: case WID_TF_SIZE_LARGE: case WID_TF_SIZE_RANDOM:
this->town_size = (TownSize)(widget - WID_TF_SIZE_SMALL);