creature: move Creature_CanTargetEnemy to trx

This commit is contained in:
Marcin Kurczewski 2025-04-08 22:54:51 +02:00
parent 5afcc59d04
commit 16b5b389f5
11 changed files with 48 additions and 61 deletions

View file

@ -1,5 +1,6 @@
#include "game/creature.h"
#include "game/lara/common.h"
#include "game/los.h"
#include "game/objects/vars.h"
#include "game/random.h"
#include "game/rooms.h"
@ -464,6 +465,30 @@ void Creature_Neck(ITEM *const item, const int16_t required)
CLAMP(creature->neck_rotation, -M_HEAD_ARC, M_HEAD_ARC);
}
bool Creature_CanTargetEnemy(const ITEM *const item, const AI_INFO *const info)
{
const CREATURE *const creature = item->data;
const ITEM *const enemy =
creature->enemy != nullptr ? creature->enemy : Lara_GetItem();
if (!info->ahead || info->distance >= CREATURE_SHOOT_RANGE) {
return false;
}
GAME_VECTOR start;
start.pos.x = item->pos.x;
start.pos.y = item->pos.y - STEP_L * 3;
start.pos.z = item->pos.z;
start.room_num = item->room_num;
GAME_VECTOR target;
target.pos.x = enemy->pos.x;
target.pos.y = enemy->pos.y - STEP_L * 3;
target.pos.z = enemy->pos.z;
target.room_num = enemy->room_num;
return LOS_Check(&start, &target);
}
bool Creature_CheckBaddieOverlap(const int16_t item_num)
{
const ITEM *item = Item_Get(item_num);

View file

@ -15,6 +15,7 @@ void Creature_Tilt(ITEM *item, int16_t angle);
void Creature_Head(ITEM *item, int16_t required);
void Creature_Neck(ITEM *item, int16_t required);
bool Creature_CanTargetEnemy(const ITEM *item, const AI_INFO *info);
bool Creature_CheckBaddieOverlap(int16_t item_num);
void Creature_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt);

View file

@ -1,8 +1,17 @@
#pragma once
#include "../../utils.h"
#define FRONT_ARC DEG_90
#define UNIT_SHADOW 256
#define CREATURE_STALK_DIST (3 * WALL_L) // = 3072
#define CREATURE_ESCAPE_DIST (5 * WALL_L) // = 5120
#define CREATURE_TARGET_DIST (4 * WALL_L) // = 4096
#define CREATURE_MISS_CHANCE 0x2000
#if TR_VERSION >= 2
#define CREATURE_SHOOT_RANGE SQUARE(WALL_L * 8) // = 0x4000000 = 67108864
#else
#define CREATURE_SHOOT_RANGE SQUARE(WALL_L * 7) // = 51380224
#endif

View file

@ -0,0 +1,5 @@
#pragma once
#include "./types.h"
bool LOS_Check(const GAME_VECTOR *start, GAME_VECTOR *target);

View file

@ -28,26 +28,6 @@ void Creature_Die(const int16_t item_num, const bool explode)
Carrier_TestItemDrops(item_num);
}
bool Creature_CanTargetEnemy(ITEM *item, AI_INFO *info)
{
if (!info->ahead || info->distance >= CREATURE_SHOOT_RANGE) {
return false;
}
GAME_VECTOR start;
start.x = item->pos.x;
start.y = item->pos.y - STEP_L * 3;
start.z = item->pos.z;
start.room_num = item->room_num;
GAME_VECTOR target;
target.x = g_LaraItem->pos.x;
target.y = g_LaraItem->pos.y - STEP_L * 3;
target.z = g_LaraItem->pos.z;
return LOS_Check(&start, &target);
}
bool Creature_ShootAtLara(
ITEM *item, int32_t distance, BITE *gun, int16_t extra_rotation,
int16_t damage)

View file

@ -6,10 +6,6 @@
#include <libtrx/game/creature.h>
#include <libtrx/utils.h>
#define CREATURE_SHOOT_RANGE SQUARE(WALL_L * 7) // = 51380224
#define CREATURE_MISS_CHANCE 0x2000
bool Creature_CanTargetEnemy(ITEM *item, AI_INFO *info);
bool Creature_ShootAtLara(
ITEM *item, int32_t distance, BITE *gun, int16_t extra_rotation,
int16_t damage);

View file

@ -1,5 +1,3 @@
#pragma once
#include "global/types.h"
bool LOS_Check(const GAME_VECTOR *start, GAME_VECTOR *target);
#include <libtrx/game/los.h>

View file

@ -25,7 +25,6 @@
#define TARGET_TOLERANCE 0x400000
#define CREATURE_SHOOT_TARGETING_SPEED 300
#define CREATURE_SHOOT_RANGE SQUARE(WALL_L * 8) // = 0x4000000 = 67108864
#define CREATURE_SHOOT_HIT_CHANCE 0x2000
void Creature_Die(const int16_t item_num, const bool explode)
@ -277,31 +276,6 @@ void Creature_GetBaddieTarget(const int16_t item_num, const bool goody)
}
}
int32_t Creature_CanTargetEnemy(
const ITEM *const item, const AI_INFO *const info)
{
const CREATURE *const creature = item->data;
const ITEM *const enemy = creature->enemy;
if (enemy->hit_points <= 0 || !info->ahead
|| info->distance >= CREATURE_SHOOT_RANGE) {
return 0;
}
GAME_VECTOR start;
start.pos.x = item->pos.x;
start.pos.y = item->pos.y - STEP_L * 3;
start.pos.z = item->pos.z;
start.room_num = item->room_num;
GAME_VECTOR target;
target.pos.x = enemy->pos.x;
target.pos.y = enemy->pos.y - STEP_L * 3;
target.pos.z = enemy->pos.z;
target.room_num = enemy->room_num;
return LOS_Check(&start, &target);
}
bool Creature_IsHostile(const ITEM *const item)
{
return Object_IsType(item->object_id, g_EnemyObjects)

View file

@ -11,7 +11,6 @@ int32_t Creature_Vault(
void Creature_Kill(
ITEM *item, int32_t kill_anim, int32_t kill_state, int32_t lara_kill_state);
void Creature_GetBaddieTarget(int16_t item_num, bool goody);
int32_t Creature_CanTargetEnemy(const ITEM *item, const AI_INFO *info);
bool Creature_IsAlly(const ITEM *item);
int32_t Creature_ShootAtLara(
ITEM *item, const AI_INFO *info, const BITE *gun, int16_t extra_rotation,

View file

@ -253,7 +253,7 @@ int32_t LOS_ClipTarget(
return 1;
}
int32_t LOS_Check(const GAME_VECTOR *const start, GAME_VECTOR *const target)
bool LOS_Check(const GAME_VECTOR *const start, GAME_VECTOR *const target)
{
int32_t los1;
int32_t los2;
@ -270,7 +270,7 @@ int32_t LOS_Check(const GAME_VECTOR *const start, GAME_VECTOR *const target)
}
if (!los2) {
return 0;
return false;
}
if (dx == 0 && dz == 0) {
@ -281,12 +281,12 @@ int32_t LOS_Check(const GAME_VECTOR *const start, GAME_VECTOR *const target)
Room_GetSector(target->x, target->y, target->z, &target->room_num);
if (!LOS_ClipTarget(start, target, sector)) {
return 0;
return false;
}
if (los1 == 1 && los2 == 1) {
return 1;
return true;
}
return 0;
return false;
}
int32_t LOS_CheckSmashable(

View file

@ -1,10 +1,10 @@
#pragma once
#include "global/types.h"
#include <libtrx/game/los.h>
#include <libtrx/game/rooms/types.h>
int32_t LOS_CheckX(const GAME_VECTOR *start, GAME_VECTOR *target);
int32_t LOS_CheckZ(const GAME_VECTOR *start, GAME_VECTOR *target);
int32_t LOS_ClipTarget(
const GAME_VECTOR *start, GAME_VECTOR *target, const SECTOR *sector);
int32_t LOS_Check(const GAME_VECTOR *start, GAME_VECTOR *target);
int32_t LOS_CheckSmashable(const GAME_VECTOR *start, const GAME_VECTOR *target);