Skip to content

Commit 7da3aad

Browse files
committed
#368 GBA add Raptor AI, disable free cam for the inventory & title screen
1 parent c3ce34a commit 7da3aad

File tree

2 files changed

+136
-28
lines changed

2 files changed

+136
-28
lines changed

src/fixed/enemy.h

Lines changed: 135 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#include "common.h"
55
#include "item.h"
66

7-
#define ENEMY_TURN_FAST ANGLE(5)
8-
#define ENEMY_TURN_SLOW ANGLE(2)
7+
#define ENEMY_TURN_1 ANGLE(1)
8+
#define ENEMY_TURN_2 ANGLE(2)
9+
#define ENEMY_TURN_4 ANGLE(4)
10+
#define ENEMY_TURN_5 ANGLE(5)
911

1012
EWRAM_DATA ExtraInfoEnemy enemiesExtra[MAX_ENEMIES];
1113

@@ -126,20 +128,32 @@ struct Enemy : ItemObj
126128
{
127129
tinfo.target = getLara(pos);
128130

129-
if (tinfo.target->health <= 0) {
130-
hitMask = 0;
131-
}
132-
133131
tinfo.tilt = 0;
134132
tinfo.turn = 0;
135133
tinfo.pos = pos;
136134

135+
tinfo.dist = 16 * 1024;
136+
tinfo.angle = 0;
137+
tinfo.aim = false;
138+
tinfo.canAttack = false;
139+
tinfo.rotHead = 0;
140+
137141
if (health <= 0)
142+
return;
143+
144+
// update navigation target
145+
const uint16* zones = getZones();
146+
147+
tinfo.boxIndex = room->getSector(pos.x, pos.z)->boxIndex;
148+
tinfo.boxIndexTarget = tinfo.target->room->getSector(tinfo.target->pos.x, tinfo.target->pos.z)->boxIndex;
149+
tinfo.zoneIndex = zones[tinfo.boxIndex];
150+
tinfo.zoneIndexTarget = zones[tinfo.boxIndexTarget];
151+
152+
//@TODO blocking
153+
154+
if (tinfo.target->health <= 0)
138155
{
139-
tinfo.angle = 0;
140-
tinfo.rotHead = 0;
141-
tinfo.aim = false;
142-
tinfo.rotHead = 0;
156+
hitMask = 0;
143157
return;
144158
}
145159

@@ -161,16 +175,6 @@ struct Enemy : ItemObj
161175
tinfo.aim = (tinfo.angle > -ANGLE_90) && (tinfo.angle < ANGLE_90);
162176
tinfo.canAttack = tinfo.aim && (abs(tinfo.target->pos.y - pos.y) < 256);
163177
tinfo.rotHead = (tinfo.aim && mood != MOOD_SLEEP) ? tinfo.angle : 0;
164-
165-
// update navigation target
166-
const uint16* zones = getZones();
167-
168-
tinfo.boxIndex = room->getSector(pos.x, pos.z)->boxIndex;
169-
tinfo.boxIndexTarget = tinfo.target->room->getSector(tinfo.target->pos.x, tinfo.target->pos.z)->boxIndex;
170-
tinfo.zoneIndex = zones[tinfo.boxIndex];
171-
tinfo.zoneIndexTarget = zones[tinfo.boxIndexTarget];
172-
173-
//@TODO blocking
174178
}
175179

176180
void updateMood()
@@ -780,7 +784,7 @@ struct Wolf : Enemy
780784
return (nextState != STATE_NONE) ? nextState : STATE_WALK;
781785
}
782786
case STATE_WALK: {
783-
extraE->maxTurn = ENEMY_TURN_SLOW;
787+
extraE->maxTurn = ENEMY_TURN_2;
784788
tinfo.tilt = tinfo.turn >> 1;
785789

786790
if (mood != MOOD_SLEEP) {
@@ -794,7 +798,7 @@ struct Wolf : Enemy
794798
break;
795799
}
796800
case STATE_RUN: {
797-
extraE->maxTurn = ENEMY_TURN_FAST;
801+
extraE->maxTurn = ENEMY_TURN_5;
798802
tinfo.tilt = tinfo.turn;
799803

800804
if (tinfo.aim && tinfo.dist < DIST_ATTACK)
@@ -817,7 +821,7 @@ struct Wolf : Enemy
817821
break;
818822
}
819823
case STATE_STALK: {
820-
extraE->maxTurn = ENEMY_TURN_SLOW;
824+
extraE->maxTurn = ENEMY_TURN_2;
821825

822826
if (mood == MOOD_ESCAPE)
823827
return STATE_RUN;
@@ -861,14 +865,14 @@ struct Wolf : Enemy
861865
case STATE_ATTACK: {
862866
tinfo.tilt = tinfo.turn;
863867

864-
if (nextState == STATE_NONE && (hitMask & HIT_MASK)) {
868+
if ((nextState == STATE_NONE) && (hitMask & HIT_MASK)) {
865869
bite(6, _vec3i(0, -14, 174), 50);
866870
nextState = STATE_RUN;
867871
}
868872
return STATE_RUN;
869873
}
870874
case STATE_BITE: {
871-
if (nextState == STATE_NONE && (hitMask & HIT_MASK)) {
875+
if ((nextState == STATE_NONE) && (hitMask & HIT_MASK)) {
872876
bite(6, _vec3i(0, -14, 174), 100);
873877
nextState = STATE_GROWL;
874878
}
@@ -958,7 +962,7 @@ struct Bear : Enemy
958962
switch (state)
959963
{
960964
case STATE_WALK: {
961-
extraE->maxTurn = ENEMY_TURN_SLOW;
965+
extraE->maxTurn = ENEMY_TURN_2;
962966

963967
if (tinfo.target->health <= 0 && tinfo.aim && (hitMask & HIT_MASK))
964968
return nextState = STATE_STOP; // eat lara! >:E
@@ -1007,7 +1011,7 @@ struct Bear : Enemy
10071011
return STATE_HOWL;
10081012
}
10091013
case STATE_RUN: {
1010-
extraE->maxTurn = ENEMY_TURN_FAST;
1014+
extraE->maxTurn = ENEMY_TURN_5;
10111015

10121016
if (hitMask & HIT_MASK) {
10131017
tinfo.target->hit(3, pos, 0);
@@ -1209,7 +1213,111 @@ struct Rex : Enemy
12091213

12101214
struct Raptor : Enemy
12111215
{
1216+
enum {
1217+
HIT_MASK = 0xFF7C00, // hands and head
1218+
DIST_BITE = 680,
1219+
DIST_ATTACK = 1536
1220+
};
1221+
1222+
enum {
1223+
ANIM_DEATH_1 = 9,
1224+
ANIM_DEATH_2 = 10
1225+
};
1226+
1227+
enum {
1228+
STATE_NONE = 0,
1229+
STATE_DEATH = 0,
1230+
STATE_STOP,
1231+
STATE_WALK,
1232+
STATE_RUN,
1233+
STATE_ATTACK_1,
1234+
STATE_UNUSED,
1235+
STATE_ROAR,
1236+
STATE_ATTACK_2,
1237+
STATE_BITE
1238+
};
1239+
12121240
Raptor(Room* room) : Enemy(room, 20, 341, 400, AGGRESSION_LVL_3) {}
1241+
1242+
virtual void hit(int32 damage, const vec3i& point, int32 soundId)
1243+
{
1244+
Enemy::hit(damage, point, 0);
1245+
1246+
if (health <= 0) {
1247+
animSet(level.models[type].animIndex + ANIM_DEATH_1 + RAND_LOGIC(2), true);
1248+
}
1249+
}
1250+
1251+
virtual int32 updateState()
1252+
{
1253+
if (health <= 0)
1254+
return goalState;
1255+
1256+
switch (state)
1257+
{
1258+
case STATE_STOP: {
1259+
if (nextState != STATE_NONE)
1260+
return nextState;
1261+
if ((hitMask & HIT_MASK) || (tinfo.canAttack && tinfo.dist < DIST_BITE))
1262+
return STATE_BITE;
1263+
if (tinfo.canAttack && tinfo.dist < DIST_ATTACK)
1264+
return STATE_ATTACK_1;
1265+
if (mood == MOOD_SLEEP)
1266+
return STATE_WALK;
1267+
return STATE_RUN;
1268+
}
1269+
case STATE_WALK: {
1270+
extraE->maxTurn = ENEMY_TURN_1;
1271+
tinfo.tilt = tinfo.turn >> 1;
1272+
1273+
if (mood != MOOD_SLEEP)
1274+
return STATE_STOP;
1275+
1276+
if (rand_logic() < 0x100) {
1277+
nextState = STATE_ROAR;
1278+
return STATE_STOP;
1279+
}
1280+
break;
1281+
}
1282+
case STATE_RUN: {
1283+
extraE->maxTurn = ENEMY_TURN_4;
1284+
tinfo.tilt = tinfo.turn;
1285+
1286+
if (hitMask & HIT_MASK)
1287+
return STATE_STOP;
1288+
1289+
if (tinfo.canAttack && tinfo.dist < DIST_ATTACK)
1290+
{
1291+
if (goalState != STATE_RUN)
1292+
break;
1293+
return (rand_logic() < 0x2000) ? STATE_STOP : STATE_ATTACK_2;
1294+
}
1295+
1296+
if (tinfo.aim && (mood != MOOD_ESCAPE) && (rand_logic() < 0x100))
1297+
{
1298+
nextState = STATE_ROAR;
1299+
return STATE_STOP;
1300+
}
1301+
1302+
if (mood == MOOD_SLEEP)
1303+
return STATE_STOP;
1304+
break;
1305+
}
1306+
case STATE_ATTACK_1:
1307+
case STATE_ATTACK_2:
1308+
case STATE_BITE:
1309+
{
1310+
tinfo.tilt = tinfo.turn;
1311+
if ((nextState == STATE_NONE) && tinfo.aim && (hitMask & HIT_MASK)) {
1312+
bite(22, _vec3i(0, 66, 318), 100);
1313+
nextState = (state == STATE_ATTACK_2) ? STATE_RUN : STATE_STOP;
1314+
}
1315+
break;
1316+
}
1317+
}
1318+
1319+
return goalState;
1320+
}
12131321
};
12141322

12151323

src/fixed/lara.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2807,7 +2807,7 @@ struct Lara : ItemObj
28072807

28082808
if (keys & IK_START) input |= IN_START;
28092809

2810-
if (isKeyHit(IN_START))
2810+
if (isKeyHit(IN_START) && (inventory.state == INV_STATE_NONE))
28112811
{
28122812
if (extraL->camera.mode != CAMERA_MODE_FREE) {
28132813
extraL->camera.mode = CAMERA_MODE_FREE;

0 commit comments

Comments
 (0)