* 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 */
| 203 | * @return index of the incompatible order or -1 if none were found |
| 204 | */ |
| 205 | static 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 |
no test coverage detected