diff options
Diffstat (limited to 'src/autoreplace_cmd.cpp')
-rw-r--r-- | src/autoreplace_cmd.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index fe962cd73..8b395e6c1 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -19,6 +19,8 @@ #include "vehicle_func.h" #include "functions.h" #include "autoreplace_func.h" +#include "autoreplace_gui.h" +#include "group.h" #include "articulated_vehicles.h" #include "core/random_func.hpp" @@ -687,3 +689,43 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1 if (cost.Succeeded() && nothing_to_do) cost = CommandCost(STR_ERROR_AUTOREPLACE_NOTHING_TO_DO); return cost; } + +/** + * Change engine renewal parameters + * @param tile unused + * @param flags operation to perform + * @param p1 packed data + * - bits 16-31 = engine group + * @param p2 packed data + * - bits 0-15 = old engine type + * - bits 16-31 = new engine type + * @param text unused + * @return the cost of this operation or an error + */ +CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) +{ + Company *c = Company::GetIfValid(_current_company); + if (c == NULL) return CMD_ERROR; + + EngineID old_engine_type = GB(p2, 0, 16); + EngineID new_engine_type = GB(p2, 16, 16); + GroupID id_g = GB(p1, 16, 16); + 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); + } else { + cost = RemoveEngineReplacementForCompany(c, old_engine_type, id_g, flags); + } + + if ((flags & DC_EXEC) && IsLocalCompany()) InvalidateAutoreplaceWindow(old_engine_type, id_g); + + return cost; +} + |