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

Function VerifyAutoreplaceRefitForOrders

src/autoreplace_cmd.cpp:182–197  ·  view source on GitHub ↗

* Tests whether refit orders that applied to v will also apply to the new vehicle type * @param v The vehicle to be replaced * @param engine_type The type we want to replace with * @return true iff all refit orders stay valid */

Source from the content-addressed store, hash-verified

180 * @return true iff all refit orders stay valid
181 */
182static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, EngineID engine_type)
183{
184 CargoTypes union_refit_mask_a = GetUnionOfArticulatedRefitMasks(v->engine_type, false);
185 CargoTypes union_refit_mask_b = GetUnionOfArticulatedRefitMasks(engine_type, false);
186
187 const Vehicle *u = (v->type == VEH_TRAIN) ? v->First() : v;
188 for (const Order &o : u->Orders()) {
189 if (!o.IsRefit() || o.IsAutoRefit()) continue;
190 CargoType cargo_type = o.GetRefitCargo();
191
192 if (!HasBit(union_refit_mask_a, cargo_type)) continue;
193 if (!HasBit(union_refit_mask_b, cargo_type)) return false;
194 }
195
196 return true;
197}
198
199/**
200 * Gets the index of the first refit order that is incompatible with the requested engine type

Callers 1

Calls 7

HasBitFunction · 0.85
OrdersMethod · 0.80
IsRefitMethod · 0.80
IsAutoRefitMethod · 0.80
GetRefitCargoMethod · 0.80
FirstMethod · 0.45

Tested by

no test coverage detected