MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AddEngineReplacement

Function AddEngineReplacement

src/autoreplace.cpp:96–116  ·  view source on GitHub ↗

* Add an engine replacement to the given renewlist. * @param erl The renewlist to add to. * @param old_engine The original engine type. * @param new_engine The replacement engine type. * @param group The group related to this replacement. * @param replace_when_old Replace when old or always? * @param flags The calling command flags. * @return 0 on success, CMD_ERROR on failure. */

Source from the content-addressed store, hash-verified

94 * @return 0 on success, CMD_ERROR on failure.
95 */
96CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlags flags)
97{
98 /* Check if the old vehicle is already in the list */
99 EngineRenew *er = GetEngineReplacement(*erl, old_engine, group);
100 if (er != nullptr) {
101 if (flags.Test(DoCommandFlag::Execute)) {
102 er->to = new_engine;
103 er->replace_when_old = replace_when_old;
104 }
105 return CommandCost();
106 }
107
108 if (!EngineRenew::CanAllocateItem()) return CMD_ERROR;
109
110 if (flags.Test(DoCommandFlag::Execute)) {
111 /* Insert before the first element */
112 *erl = new EngineRenew(old_engine, new_engine, group, replace_when_old, *erl);
113 }
114
115 return CommandCost();
116}
117
118/**
119 * Remove an engine replacement from a given renewlist.

Callers 1

Calls 3

GetEngineReplacementFunction · 0.85
CommandCostClass · 0.85
TestMethod · 0.80

Tested by

no test coverage detected