summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-01-27 20:54:05 +0000
committerfrosch <frosch@openttd.org>2010-01-27 20:54:05 +0000
commita3168269f9920e764669d7d63abff9ec5fe332d0 (patch)
tree6719dc9bf56f4b29ce383c943bddea7d6b91e631
parent7b237ee607ed12814e3a38f99d3dda33c34987ff (diff)
downloadopenttd-a3168269f9920e764669d7d63abff9ec5fe332d0.tar.xz
(svn r18931) -Fix: Disabling autoreplace rules might count invalid engines.
-rw-r--r--src/autoreplace_cmd.cpp4
-rw-r--r--src/company_cmd.cpp5
2 files changed, 5 insertions, 4 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index bb2cf0b02..26a92e519 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -50,9 +50,7 @@ static bool EnginesHaveCargoInCommon(EngineID engine_a, EngineID engine_b)
*/
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
{
- /* First we make sure that it's a valid type the user requested
- * check that it's an engine that is in the engine array */
- if (!Engine::IsValidID(from) || !Engine::IsValidID(to)) return false;
+ assert(Engine::IsValidID(from) && Engine::IsValidID(to));
/* we can't replace an engine into itself (that would be autorenew) */
if (from == to) return false;
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index e968108ea..dfe7478a6 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -663,7 +663,10 @@ CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
CommandCost cost;
if (!Group::IsValidID(id_g) && !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
+ if (!Engine::IsValidID(old_engine_type)) return CMD_ERROR;
+
if (new_engine_type != INVALID_ENGINE) {
+ if (!Engine::IsValidID(new_engine_type)) return CMD_ERROR;
if (!CheckAutoreplaceValidity(old_engine_type, new_engine_type, _current_company)) return CMD_ERROR;
cost = AddEngineReplacementForCompany(c, old_engine_type, new_engine_type, id_g, flags);
@@ -671,7 +674,7 @@ CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
cost = RemoveEngineReplacementForCompany(c, old_engine_type, id_g, flags);
}
- if (IsLocalCompany()) InvalidateAutoreplaceWindow(old_engine_type, id_g);
+ if ((flags & DC_EXEC) && IsLocalCompany()) InvalidateAutoreplaceWindow(old_engine_type, id_g);
return cost;
}