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

Function insertElementRoad

src/OpenLoco/src/Map/TileManager.cpp:313–356  ·  view source on GitHub ↗

0x0046166C

Source from the content-addressed store, hash-verified

311
312 // 0x0046166C
313 RoadElement* insertElementRoad(const Pos2& pos, uint8_t baseZ, uint8_t occupiedQuads)
314 {
315 checkFreeElementsAndReorganise();
316
317 auto [source, dest] = insertElementPrepareDest(toTileSpace(pos));
318 if (source == nullptr)
319 {
320 return nullptr;
321 }
322
323 bool lastFound = false;
324 auto isRoadStation = [](const TileElement* source, SmallZ baseZ) {
325 if (baseZ != source->baseZ())
326 {
327 return false;
328 }
329 auto* srcStation = source->as<StationElement>();
330 if (srcStation == nullptr)
331 {
332 return false;
333 }
334 return srcStation->stationType() == StationType::roadStation;
335 };
336
337 // Copy all of the elements that are underneath the new tile (or till end)
338 while (baseZ >= source->baseZ() && !isRoadStation(source, baseZ))
339 {
340 *dest = *source;
341 source->setBaseZ(0xFFU);
342 source++;
343 if (dest->isLast())
344 {
345 // The new element will become the last
346 // so we are clearing the flag
347 dest->setLastFlag(false);
348 dest++;
349 lastFound = true;
350 break;
351 }
352 dest++;
353 }
354
355 return insertElementEnd(ElementType::road, baseZ, occupiedQuads, source, dest, lastFound)->as<RoadElement>();
356 }
357
358 // 0x00461578
359 TileElement* insertElementAfterNoReorg(TileElement* after, ElementType type, const Pos2& pos, uint8_t baseZ, uint8_t occupiedQuads)

Callers 1

createRoadFunction · 0.85

Calls 9

insertElementPrepareDestFunction · 0.85
toTileSpaceFunction · 0.85
insertElementEndFunction · 0.85
baseZMethod · 0.80
stationTypeMethod · 0.80
setBaseZMethod · 0.80
setLastFlagMethod · 0.80
isLastMethod · 0.45

Tested by

no test coverage detected