diff --git a/src/libtrx/game/creature/common.c b/src/libtrx/game/creature/common.c index 2eafa450e..a986359d1 100644 --- a/src/libtrx/game/creature/common.c +++ b/src/libtrx/game/creature/common.c @@ -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); diff --git a/src/libtrx/include/libtrx/game/creature/common.h b/src/libtrx/include/libtrx/game/creature/common.h index 8c7ddbdb6..d3b421958 100644 --- a/src/libtrx/include/libtrx/game/creature/common.h +++ b/src/libtrx/include/libtrx/game/creature/common.h @@ -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); diff --git a/src/libtrx/include/libtrx/game/creature/const.h b/src/libtrx/include/libtrx/game/creature/const.h index be8287728..c9052d0ff 100644 --- a/src/libtrx/include/libtrx/game/creature/const.h +++ b/src/libtrx/include/libtrx/game/creature/const.h @@ -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 diff --git a/src/libtrx/include/libtrx/game/los.h b/src/libtrx/include/libtrx/game/los.h new file mode 100644 index 000000000..91b83d02d --- /dev/null +++ b/src/libtrx/include/libtrx/game/los.h @@ -0,0 +1,5 @@ +#pragma once + +#include "./types.h" + +bool LOS_Check(const GAME_VECTOR *start, GAME_VECTOR *target); diff --git a/src/tr1/game/creature.c b/src/tr1/game/creature.c index af830655f..64f25ceb1 100644 --- a/src/tr1/game/creature.c +++ b/src/tr1/game/creature.c @@ -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) diff --git a/src/tr1/game/creature.h b/src/tr1/game/creature.h index b36c41b81..c28c9a19e 100644 --- a/src/tr1/game/creature.h +++ b/src/tr1/game/creature.h @@ -6,10 +6,6 @@ #include #include -#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); diff --git a/src/tr1/game/los.h b/src/tr1/game/los.h index 0a5981260..96041ee31 100644 --- a/src/tr1/game/los.h +++ b/src/tr1/game/los.h @@ -1,5 +1,3 @@ #pragma once -#include "global/types.h" - -bool LOS_Check(const GAME_VECTOR *start, GAME_VECTOR *target); +#include diff --git a/src/tr2/game/creature.c b/src/tr2/game/creature.c index 449b64b69..affb81da5 100644 --- a/src/tr2/game/creature.c +++ b/src/tr2/game/creature.c @@ -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) diff --git a/src/tr2/game/creature.h b/src/tr2/game/creature.h index b3f1f80c4..8377315fe 100644 --- a/src/tr2/game/creature.h +++ b/src/tr2/game/creature.h @@ -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, diff --git a/src/tr2/game/los.c b/src/tr2/game/los.c index 12d38ffa4..caba2eb80 100644 --- a/src/tr2/game/los.c +++ b/src/tr2/game/los.c @@ -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( diff --git a/src/tr2/game/los.h b/src/tr2/game/los.h index 7db997536..23d48a723 100644 --- a/src/tr2/game/los.h +++ b/src/tr2/game/los.h @@ -1,10 +1,10 @@ #pragma once -#include "global/types.h" +#include +#include 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);