mirror of https://github.com/OpenTTD/OpenTTD
(svn r18931) -Fix: Disabling autoreplace rules might count invalid engines.
parent
7b237ee607
commit
a3168269f9
|
@ -50,9 +50,7 @@ static bool EnginesHaveCargoInCommon(EngineID engine_a, EngineID engine_b)
|
||||||
*/
|
*/
|
||||||
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
|
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company)
|
||||||
{
|
{
|
||||||
/* First we make sure that it's a valid type the user requested
|
assert(Engine::IsValidID(from) && Engine::IsValidID(to));
|
||||||
* check that it's an engine that is in the engine array */
|
|
||||||
if (!Engine::IsValidID(from) || !Engine::IsValidID(to)) return false;
|
|
||||||
|
|
||||||
/* we can't replace an engine into itself (that would be autorenew) */
|
/* we can't replace an engine into itself (that would be autorenew) */
|
||||||
if (from == to) return false;
|
if (from == to) return false;
|
||||||
|
|
|
@ -663,7 +663,10 @@ CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
||||||
CommandCost cost;
|
CommandCost cost;
|
||||||
|
|
||||||
if (!Group::IsValidID(id_g) && !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
|
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 (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;
|
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);
|
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);
|
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;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue