diff options
author | frosch <frosch@openttd.org> | 2010-05-31 20:22:57 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2010-05-31 20:22:57 +0000 |
commit | 9db3cde73af598852da13b748eef31a8207cfcf2 (patch) | |
tree | 996d3e9c49ce7c3611a70ed4fa6f03774b4cafe9 /src/vehicle.cpp | |
parent | 1d05fbebbef72722d400ab4f7693dde11205a7f4 (diff) | |
download | openttd-9db3cde73af598852da13b748eef31a8207cfcf2.tar.xz |
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index e14d4979c..30bd2f74b 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -50,6 +50,7 @@ #include "core/random_func.hpp" #include "engine_base.h" #include "newgrf.h" +#include "core/backup_type.hpp" #include "table/sprites.h" #include "table/strings.h" @@ -772,10 +773,11 @@ void CallVehicleTicks() } } + Backup<CompanyByte> cur_company(_current_company); for (AutoreplaceMap::iterator it = _vehicles_to_autoreplace.Begin(); it != _vehicles_to_autoreplace.End(); it++) { v = it->first; /* Autoreplace needs the current company set as the vehicle owner */ - _current_company = v->owner; + cur_company.Change(v->owner); /* Start vehicle if we stopped them in VehicleEnteredDepotThisTick() * We need to stop them between VehicleEnteredDepotThisTick() and here or we risk that @@ -816,7 +818,7 @@ void CallVehicleTicks() AddVehicleNewsItem(message, NS_ADVICE, v->index); } - _current_company = OWNER_NONE; + cur_company.Restore(); } static void DoDrawVehicle(const Vehicle *v) @@ -1110,8 +1112,9 @@ void VehicleEnterDepot(Vehicle *v) } if (t.IsRefit()) { - _current_company = v->owner; + Backup<CompanyByte> cur_company(_current_company, v->owner); CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v)); + cur_company.Restore(); if (cost.Failed()) { _vehicles_to_autoreplace[v] = false; |