MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / EarthquakeControl

Function EarthquakeControl

TombEngine/Objects/Generic/Object/objects.cpp:280–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278}
279
280void EarthquakeControl(short itemNumber)
281{
282 auto& item = g_Level.Items[itemNumber];
283
284 if (!TriggerActive(&item))
285 return;
286
287 if (item.TriggerFlags)
288 {
289 // OCB 333 and 888 are legacy modes for TR4 compatibility.
290 // Any other positive OCB value triggers an earthquake for specified amount of seconds.
291 // Any negative OCB value triggers a rumble sound effect for specified amount of seconds.
292
293 bool legacyMode888 = (item.TriggerFlags == 888);
294 bool legacyMode333 = (item.TriggerFlags == 333);
295
296 int timeout = (legacyMode888 ? 5 : (legacyMode333 ? 16 : abs(item.TriggerFlags))) * FPS;
297 float volume = std::clamp((float)(timeout - item.ItemFlags[0]) / (float)FPS, 0.01f, 1.0f); // Fadeout for the last second.
298
299 if (!legacyMode333 && item.TriggerFlags > 0)
300 Camera.bounce = -64 - (GetRandomControl() & 0x1F);
301
302 SoundEffect(SFX_TR4_EARTHQUAKE_LOOP, nullptr, SoundEnvironment::Always, 1.0f, volume);
303
304 item.ItemFlags[0]++;
305
306 if (item.ItemFlags[0] >= timeout)
307 KillItem(itemNumber);
308 }
309 else
310 {
311 if (!item.ItemFlags[1])
312 item.ItemFlags[1] = 100;
313
314 if (!item.ItemFlags[2])
315 {
316 if (abs(item.ItemFlags[0] - item.ItemFlags[1]) < 16)
317 {
318 if (item.ItemFlags[1] == 20)
319 {
320 item.ItemFlags[1] = 100;
321 item.ItemFlags[2] = (GetRandomControl() & 0x7F) + 90;
322 }
323 else
324 {
325 item.ItemFlags[1] = 20;
326 item.ItemFlags[2] = (GetRandomControl() & 0x7F) + 30;
327 }
328 }
329 }
330
331 if (item.ItemFlags[2])
332 item.ItemFlags[2]--;
333
334 if (item.ItemFlags[0] <= item.ItemFlags[1])
335 item.ItemFlags[0] += (GetRandomControl() & 7) + 2;
336 else
337 item.ItemFlags[0] -= (GetRandomControl() & 7) + 2;

Callers

nothing calls this directly

Calls 4

TriggerActiveFunction · 0.85
GetRandomControlFunction · 0.85
SoundEffectFunction · 0.85
KillItemFunction · 0.85

Tested by

no test coverage detected