MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / swapAdjacentOrders

Function swapAdjacentOrders

src/OpenLoco/src/Vehicles/OrderManager.cpp:474–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472 }
473
474 uint8_t swapAdjacentOrders(Order& a, Order& b)
475 {
476 // Currently the use of std:: algorithms is not feasible due to variable order lengths
477 // TODO: simplify this after the changing the data structure for the order table
478
479 const auto rawOrderA = a.getRaw();
480 const auto rawOrderB = b.getRaw();
481 const auto lengthOrderA = kOrderSizes[enumValue(a.getType())];
482 const auto lengthOrderB = kOrderSizes[enumValue(b.getType())];
483
484 // Ensure the two orders are indeed adjacent
485 assert(&a + lengthOrderA == &b);
486
487 // Copy B over A, and append B right after
488 const auto dest = reinterpret_cast<uint8_t*>(&a);
489 std::memcpy(dest, &rawOrderB, lengthOrderB);
490 std::memcpy(dest + lengthOrderB, &rawOrderA, lengthOrderA);
491
492 // Return the length with which to offset
493 return lengthOrderB;
494 }
495
496 // 0x0047062B
497 void removeOrdersForStation(const StationId stationId)

Callers 2

vehicleOrderUpFunction · 0.85
vehicleOrderDownFunction · 0.85

Calls 3

enumValueFunction · 0.85
getRawMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected