Mercurial > hg > openttd
changeset 14374:67a5b4d716b8 draft
(svn r18931) -Fix: Disabling autoreplace rules might count invalid engines.
author | frosch <frosch@openttd.org> |
---|---|
date | Wed, 27 Jan 2010 20:54:05 +0000 |
parents | 6703a8ed9c0c |
children | a73f5f267e1c |
files | src/autoreplace_cmd.cpp src/company_cmd.cpp |
diffstat | 2 files changed, 5 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -50,9 +50,7 @@ */ 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;
--- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -663,7 +663,10 @@ 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 @@ 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; }