* Helper to get the position of a vehicle within a chain of vehicles. * @param v the vehicle to get the position of. * @param consecutive whether to look at the whole chain or the vehicles * with the same 'engine type'. * @return the position in the chain from front and tail and chain length. */
| 394 | * @return the position in the chain from front and tail and chain length. |
| 395 | */ |
| 396 | static uint32_t PositionHelper(const Vehicle *v, bool consecutive) |
| 397 | { |
| 398 | const Vehicle *u; |
| 399 | uint8_t chain_before = 0; |
| 400 | uint8_t chain_after = 0; |
| 401 | |
| 402 | for (u = v->First(); u != v; u = u->Next()) { |
| 403 | chain_before++; |
| 404 | if (consecutive && u->engine_type != v->engine_type) chain_before = 0; |
| 405 | } |
| 406 | |
| 407 | while (u->Next() != nullptr && (!consecutive || u->Next()->engine_type == v->engine_type)) { |
| 408 | chain_after++; |
| 409 | u = u->Next(); |
| 410 | } |
| 411 | |
| 412 | return chain_before | chain_after << 8 | (chain_before + chain_after + consecutive) << 16; |
| 413 | } |
| 414 | |
| 415 | static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, uint8_t variable, uint32_t parameter, bool &available) |
| 416 | { |
no test coverage detected