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

Function updateLevelCrossingAnimation

src/OpenLoco/src/Map/RoadElement.cpp:126–194  ·  view source on GitHub ↗

0x00479413

Source from the content-addressed store, hash-verified

124
125 // 0x00479413
126 bool updateLevelCrossingAnimation(const Animation& anim)
127 {
128 auto tile = TileManager::get(anim.pos);
129 bool shouldInvalidate = false;
130 bool hasAnimation = false;
131
132 // It's possible to have multiple level crossing elements on the same tile/baseZ
133 // this happens if you have tram tracks on road on track.
134 for (auto& el : tile)
135 {
136 auto* elRoad = el.as<RoadElement>();
137 if (elRoad == nullptr)
138 {
139 continue;
140 }
141 if (elRoad->baseZ() != anim.baseZ)
142 {
143 continue;
144 }
145 if (!elRoad->hasLevelCrossing())
146 {
147 continue;
148 }
149
150 const auto* levelCrossingObj = ObjectManager::get<LevelCrossingObject>(elRoad->levelCrossingObjectId());
151
152 if (ScenarioManager::getScenarioTicks() & levelCrossingObj->var_0A)
153 {
154 hasAnimation = true;
155 }
156 else
157 {
158 shouldInvalidate = true;
159 auto newFrame = elRoad->unk6l();
160 if (elRoad->hasUnk7_10())
161 {
162 if (newFrame != 15)
163 {
164 newFrame++;
165 if (newFrame > levelCrossingObj->closedFrames)
166 {
167 newFrame = 15;
168 }
169 }
170 hasAnimation = true;
171 }
172 else
173 {
174 if (newFrame != 0)
175 {
176 newFrame--;
177 if (newFrame == 14)
178 {
179 newFrame = levelCrossingObj->closedFrames;
180 }
181 hasAnimation = true;
182 }
183 // Doesn't set hasAnimation = true on else branch!

Callers 1

callUpdateFunctionFunction · 0.85

Calls 9

getScenarioTicksFunction · 0.85
baseZMethod · 0.80
levelCrossingObjectIdMethod · 0.80
unk6lMethod · 0.80
hasUnk7_10Method · 0.80
setUnk6lMethod · 0.80
getFunction · 0.70
invalidateFunction · 0.50
hasLevelCrossingMethod · 0.45

Tested by

no test coverage detected