mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
creature: move Creature_Turn to trx
This commit is contained in:
parent
dbfb93cfd7
commit
4e03c39ffd
4 changed files with 25 additions and 57 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue