creature: move Creature_Turn to trx

This commit is contained in:
Marcin Kurczewski 2025-04-08 17:26:02 +02:00
parent dbfb93cfd7
commit 4e03c39ffd
4 changed files with 25 additions and 57 deletions

View file

@ -396,3 +396,26 @@ void Creature_Mood(
}
Box_CalculateTarget(&creature->target, item, lot);
}
int16_t Creature_Turn(ITEM *const item, int16_t max_turn)
{
const CREATURE *const creature = item->data;
if (creature == nullptr || item->speed == 0 || max_turn == 0) {
return 0;
}
const int32_t dx = creature->target.x - item->pos.x;
const int32_t dz = creature->target.z - item->pos.z;
int16_t angle = Math_Atan(dz, dx) - item->rot.y;
if (angle > FRONT_ARC || angle < -FRONT_ARC) {
const int32_t range = (item->speed << 14) / max_turn;
if (SQUARE(dx) + SQUARE(dz) < SQUARE(range)) {
max_turn /= 2;
}
}
CLAMP(angle, -max_turn, max_turn);
item->rot.y += angle;
return angle;
}

View file

@ -10,10 +10,11 @@ bool Creature_EnsureHabitat(
int16_t item_num, int32_t *wh, const HYBRID_INFO *info);
void Creature_Mood(const ITEM *item, const AI_INFO *info, bool violent);
int16_t Creature_Turn(ITEM *item, int16_t max_turn);
extern bool Creature_IsHostile(const ITEM *item);
extern void Creature_Collision(
int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
extern int16_t Creature_Turn(ITEM *item, int16_t maximum_turn);
extern void Creature_Tilt(ITEM *item, int16_t angle);
extern void Creature_Head(ITEM *item, int16_t required);
extern bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt);

View file

@ -18,39 +18,6 @@
#include <libtrx/game/math.h>
#include <libtrx/log.h>
int16_t Creature_Turn(ITEM *item, int16_t maximum_turn)
{
CREATURE *creature = item->data;
if (!creature) {
return 0;
}
if (!item->speed || !maximum_turn) {
return 0;
}
int32_t x = creature->target.x - item->pos.x;
int32_t z = creature->target.z - item->pos.z;
int16_t angle = Math_Atan(z, x) - item->rot.y;
int32_t range = (item->speed << 14) / maximum_turn;
if (angle > FRONT_ARC || angle < -FRONT_ARC) {
if (SQUARE(x) + SQUARE(z) < SQUARE(range)) {
maximum_turn >>= 1;
}
}
if (angle > maximum_turn) {
angle = maximum_turn;
} else if (angle < -maximum_turn) {
angle = -maximum_turn;
}
item->rot.y += angle;
return angle;
}
void Creature_Tilt(ITEM *item, int16_t angle)
{
angle = angle * 4 - item->rot.z;

View file

@ -359,29 +359,6 @@ bool Creature_Animate(
return true;
}
int16_t Creature_Turn(ITEM *const item, int16_t max_turn)
{
const CREATURE *const creature = item->data;
if (creature == nullptr || item->speed == 0 || max_turn == 0) {
return 0;
}
const int32_t dx = creature->target.x - item->pos.x;
const int32_t dz = creature->target.z - item->pos.z;
int16_t angle = Math_Atan(dz, dx) - item->rot.y;
if (angle > FRONT_ARC || angle < -FRONT_ARC) {
const int32_t range = (item->speed << 14) / max_turn;
if (SQUARE(dx) + SQUARE(dz) < SQUARE(range)) {
max_turn /= 2;
}
}
CLAMP(angle, -max_turn, max_turn);
item->rot.y += angle;
return angle;
}
void Creature_Tilt(ITEM *const item, int16_t angle)
{
angle = 4 * angle - item->rot.z;