summaryrefslogtreecommitdiff
path: root/src/rail_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-05-31 20:22:57 +0000
committerfrosch <frosch@openttd.org>2010-05-31 20:22:57 +0000
commit9db3cde73af598852da13b748eef31a8207cfcf2 (patch)
tree996d3e9c49ce7c3611a70ed4fa6f03774b4cafe9 /src/rail_cmd.cpp
parent1d05fbebbef72722d400ab4f7693dde11205a7f4 (diff)
downloadopenttd-9db3cde73af598852da13b748eef31a8207cfcf2.tar.xz
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
Diffstat (limited to 'src/rail_cmd.cpp')
-rw-r--r--src/rail_cmd.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 0bf4aa892..59bc30e71 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -36,6 +36,7 @@
#include "town.h"
#include "pbs.h"
#include "company_base.h"
+#include "core/backup_type.hpp"
#include "table/strings.h"
#include "table/sprites.h"
@@ -641,9 +642,10 @@ bool FloodHalftile(TileIndex t)
TrackBits to_remove = lower_track & rail_bits;
if (to_remove != 0) {
- _current_company = OWNER_WATER;
- if (DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL).Failed()) return flooded; // not yet floodable
- flooded = true;
+ Backup<CompanyByte> cur_company(_current_company, OWNER_WATER);
+ flooded = DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL).Succeeded();
+ cur_company.Restore();
+ if (!flooded) return flooded; // not yet floodable
rail_bits = rail_bits & ~to_remove;
if (rail_bits == 0) {
MakeShore(t);