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

Function createWave

src/OpenLoco/src/Map/WaveManager.cpp:38–89  ·  view source on GitHub ↗

0x0046956E

Source from the content-addressed store, hash-verified

36 }
37 // 0x0046956E
38 void createWave(SurfaceElement& surface, const World::Pos2& pos)
39 {
40 const auto waveIndex = getWaveIndex(World::toTileSpace(pos));
41 auto& wave = rawWaves()[waveIndex];
42 if (!wave.empty())
43 {
44 return;
45 }
46 auto vpPoint = gameToScreen(Pos3(pos.x + 16, pos.y + 16, surface.waterHeight()), WindowManager::getCurrentRotation());
47 auto w = WindowManager::findWindowShowing(vpPoint);
48 if (w == nullptr)
49 {
50 return;
51 }
52
53 uint16_t dx2 = gPrng2().randNext() & 0xFFFF;
54 if (dx2 > 0x1745)
55 {
56 return;
57 }
58
59 // Check whether surrounding tiles are water
60 for (const auto& offset : _offsets)
61 {
62 auto searchLoc = pos + offset;
63 if (!World::validCoords(searchLoc))
64 {
65 return;
66 }
67
68 const auto tile = TileManager::get(searchLoc);
69 if (tile.isNull())
70 {
71 return;
72 }
73 const auto* nearbySurface = tile.surface();
74 if (nearbySurface == nullptr)
75 {
76 return;
77 }
78 if (nearbySurface->water() == 0)
79 {
80 return;
81 }
82 }
83
84 wave.loc = pos;
85 wave.frame = 0;
86 surface.setFlag6(true);
87
88 ViewportManager::invalidate(pos, surface.waterHeight(), surface.waterHeight(), ZoomLevel::full);
89 }
90
91 const Wave& getWave(const uint8_t waveIndex)
92 {

Callers 1

updateSurfaceFunction · 0.85

Calls 15

getWaveIndexFunction · 0.85
toTileSpaceFunction · 0.85
gameToScreenFunction · 0.85
getCurrentRotationFunction · 0.85
findWindowShowingFunction · 0.85
validCoordsFunction · 0.85
waterHeightMethod · 0.80
isNullMethod · 0.80
surfaceMethod · 0.80
waterMethod · 0.80
setFlag6Method · 0.80
getFunction · 0.70

Tested by

no test coverage detected