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

Function GetIncompatibleRefitOrderIdForAutoreplace

src/autoreplace_cmd.cpp:205–220  ·  view source on GitHub ↗

* Gets the index of the first refit order that is incompatible with the requested engine type * @param v The vehicle to be replaced * @param engine_type The type we want to replace with * @return index of the incompatible order or -1 if none were found */

Source from the content-addressed store, hash-verified

203 * @return index of the incompatible order or -1 if none were found
204 */
205static int GetIncompatibleRefitOrderIdForAutoreplace(const Vehicle *v, EngineID engine_type)
206{
207 CargoTypes union_refit_mask = GetUnionOfArticulatedRefitMasks(engine_type, false);
208
209 const Vehicle *u = (v->type == VEH_TRAIN) ? v->First() : v;
210
211 const OrderList *orders = u->orders;
212 if (orders == nullptr) return -1;
213 for (VehicleOrderID i = 0; i < orders->GetNumOrders(); i++) {
214 const Order *o = orders->GetOrderAt(i);
215 if (!o->IsRefit()) continue;
216 if (!HasBit(union_refit_mask, o->GetRefitCargo())) return i;
217 }
218
219 return -1;
220}
221
222/**
223 * Function to find what type of cargo to refit to when autoreplacing

Callers 1

BuildReplacementVehicleFunction · 0.85

Calls 7

HasBitFunction · 0.85
GetOrderAtMethod · 0.80
IsRefitMethod · 0.80
GetRefitCargoMethod · 0.80
FirstMethod · 0.45
GetNumOrdersMethod · 0.45

Tested by

no test coverage detected