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

Function PositionHelper

src/newgrf_engine.cpp:396–413  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

394 * @return the position in the chain from front and tail and chain length.
395 */
396static 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
415static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, uint8_t variable, uint32_t parameter, bool &available)
416{

Callers 1

VehicleGetVariableFunction · 0.85

Calls 2

FirstMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected