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

Function GuardControl

TombEngine/Objects/TR5/Entity/tr5_guard.cpp:317–1034  ·  view source on GitHub ↗

TODO: Deal with LaraItem global.

Source from the content-addressed store, hash-verified

315
316 // TODO: Deal with LaraItem global.
317 void GuardControl(short itemNumber)
318 {
319 if (!CreatureActive(itemNumber))
320 return;
321
322 auto* item = &g_Level.Items[itemNumber];
323 auto* creature = GetCreatureInfo(item);
324
325 short angle = 0;
326 short torsoX = 0;
327 short torsoY = 0;
328 short headY = 0;
329
330 bool canJump1block = CanCreatureJump(*item, JumpDistance::Block1);
331 bool canJump2blocks = !canJump1block && CanCreatureJump(*item, JumpDistance::Block2);
332
333 if (item->AIBits)
334 GetAITarget(creature);
335 else
336 creature->Enemy = LaraItem;
337
338 if (creature->MuzzleFlash[0].Delay != 0)
339 creature->MuzzleFlash[0].Delay--;
340
341 AI_INFO AI;
342 CreatureAIInfo(item, &AI);
343
344 AI_INFO laraAI;
345 if (creature->Enemy == LaraItem)
346 {
347 laraAI.angle = AI.angle;
348 laraAI.distance = AI.distance;
349 }
350 else
351 {
352 int dx = LaraItem->Pose.Position.x - item->Pose.Position.x;
353 int dz = LaraItem->Pose.Position.z - item->Pose.Position.z;
354 laraAI.angle = phd_atan(dz, dx) - item->Pose.Orientation.y;
355 laraAI.distance = SQUARE(dz) + SQUARE(dx);
356 }
357
358 if (item->HitPoints <= 0)
359 {
360 if (item->Animation.ActiveState != GUARD_STATE_DEATH_1 &&
361 item->Animation.ActiveState != GUARD_STATE_DEATH_2)
362 {
363 if (laraAI.angle >= GUARD_LARA_ANGLE_FOR_DEATH2 || laraAI.angle <= -GUARD_LARA_ANGLE_FOR_DEATH2)
364 {
365 SetAnimation(item, GUARD_ANIM_DEATH_2);
366 item->Pose.Orientation.y += laraAI.angle + ANGLE(-180.0f);
367 }
368 else
369 {
370 SetAnimation(item, GUARD_ANIM_DEATH_1);
371 item->Pose.Orientation.y += laraAI.angle;
372 }
373
374 item->Animation.FrameNumber = 0;

Callers

nothing calls this directly

Calls 15

CreatureActiveFunction · 0.85
GetCreatureInfoFunction · 0.85
CanCreatureJumpFunction · 0.85
GetAITargetFunction · 0.85
CreatureAIInfoFunction · 0.85
phd_atanFunction · 0.85
SetAnimationFunction · 0.85
ANGLEFunction · 0.85
GetCreatureMoodFunction · 0.85
TestEnvironmentFunction · 0.85
TestProbabilityFunction · 0.85
SoundEffectFunction · 0.85

Tested by

no test coverage detected