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

Function LionControl

TombEngine/Objects/TR5/Entity/tr5_lion.cpp:80–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 }
79
80 void LionControl(short itemNumber)
81 {
82 if (!CreatureActive(itemNumber))
83 return;
84
85 auto* item = &g_Level.Items[itemNumber];
86 auto* object = &Objects[item->ObjectNumber];
87 auto* creature = GetCreatureInfo(item);
88
89 short headingAngle = 0;
90 short tiltAngle = 0;
91 short joint0 = 0;
92 short joint1 = 0;
93
94 bool isTargetAhead = false;
95
96 if (item->HitPoints <= 0)
97 {
98 item->HitPoints = 0;
99
100 if (item->Animation.ActiveState != LION_STATE_DEATH)
101 SetAnimation(item, LionDeathAnims[Random::GenerateInt(0, (int)LionDeathAnims.size() - 1)]);
102 }
103 else
104 {
105 AI_INFO ai;
106 CreatureAIInfo(item, &ai);
107
108 // NOTE: Because the lion is quite big, AI.ahead doesn't calculate the lion's head angle properly.
109 // Calculate manually like with tr1_giant_mutant.
110
111 auto forwardVector = Vector3(
112 cos(item->Pose.Orientation.x) * sin(item->Pose.Orientation.y),
113 -sin(item->Pose.Orientation.x),
114 cos(item->Pose.Orientation.x) * cos(item->Pose.Orientation.y));
115 forwardVector.Normalize();
116 forwardVector *= LION_HEAD_DISTANCE;
117
118 short headAngle = (short)phd_atan(
119 creature->Target.z - item->Pose.Position.z + forwardVector.z,
120 creature->Target.x - item->Pose.Position.x + forwardVector.x) -
121 item->Pose.Orientation.y;
122 isTargetAhead = (headAngle > -FRONT_ARC && headAngle < FRONT_ARC);
123
124 if (isTargetAhead)
125 joint1 = headAngle;
126
127 GetCreatureMood(item, &ai, true);
128 CreatureMood(item, &ai, true);
129
130 headingAngle = CreatureTurn(item, creature->MaxTurn);
131 joint0 = headingAngle * -16;
132
133 switch (item->Animation.ActiveState)
134 {
135 case LION_STATE_IDLE:
136 creature->MaxTurn = 0;
137 creature->Flags = 0;

Callers

nothing calls this directly

Calls 15

CreatureActiveFunction · 0.85
GetCreatureInfoFunction · 0.85
SetAnimationFunction · 0.85
GenerateIntFunction · 0.85
CreatureAIInfoFunction · 0.85
phd_atanFunction · 0.85
GetCreatureMoodFunction · 0.85
CreatureMoodFunction · 0.85
CreatureTurnFunction · 0.85
TestProbabilityFunction · 0.85
DoDamageFunction · 0.85
CreatureEffect2Function · 0.85

Tested by

no test coverage detected