* 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 */
| 180 | * @return true iff all refit orders stay valid |
| 181 | */ |
| 182 | static 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 |
no test coverage detected