Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
port Bird_Control
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Apr 13, 2024
1 parent c949961 commit 07a802f
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 11 deletions.
16 changes: 8 additions & 8 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ typedef enum GAME_OBJECT_ID {

# game/bird.c
0040C880 00000089 + void __cdecl Bird_Initialise(int16_t item_num);
0040C910 00000200 - void __cdecl Bird_Control(int16_t item_num);
0040C910 00000200 + void __cdecl Bird_Control(int16_t item_num);

# game/boat.c
0040CB30 0000003C - void __cdecl Boat_Initialise(int16_t item_num);
Expand Down Expand Up @@ -3253,3 +3253,5 @@ typedef enum GAME_OBJECT_ID {
004D7EE0 - LPDIRECTDRAW3 g_DDraw;
004D8380 - int32_t g_GameWindowX;
00463150 - GUID g_IID_IDirectDrawSurface3;
004640A0 + struct BITE_INFO g_CrowBite;
00464090 + struct BITE_INFO g_BirdBite;
113 changes: 112 additions & 1 deletion src/game/objects/creatures/bird.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "game/objects/creatures/bird.h"

#include "global/const.h"
#include "global/funcs.h"
#include "global/types.h"
#include "global/vars.h"
#include "util.h"

typedef enum BIRD_ANIM {
BIRD_ANIM_EMPTY = 0,
Expand All @@ -15,13 +17,21 @@ typedef enum BIRD_ANIM {
BIRD_ANIM_EAT = 7,
} BIRD_ANIM;

static BITE_INFO m_BirdBite = { 15, 46, 21, 6 };
static BITE_INFO m_CrowBite = { 2, 10, 60, 14 };

#define BIRD_DAMAGE 20
#define BIRD_ATTACK_RANGE SQUARE(WALL_L / 2) // = 262144
#define BIRD_TURN (PHD_DEGREE * 3) // = 546
#define BIRD_START_ANIM 5
#define BIRD_DIE_ANIM 8
#define CROW_START_ANIM 14
#define CROW_DIE_ANIM 1

void __cdecl Bird_Initialise(const int16_t item_num)
{
Creature_Initialise(item_num);
struct ITEM_INFO *item = &g_Items[item_num];
struct ITEM_INFO *const item = &g_Items[item_num];
if (item->object_num == O_CROW) {
item->anim_num = g_Objects[O_CROW].anim_idx + CROW_START_ANIM;
item->frame_num = g_Anims[item->anim_num].frame_base;
Expand All @@ -34,3 +44,104 @@ void __cdecl Bird_Initialise(const int16_t item_num)
item->current_anim_state = BIRD_ANIM_STOP;
}
}

void __cdecl Bird_Control(const int16_t item_num)
{
if (!Creature_Activate(item_num)) {
return;
}

struct ITEM_INFO *const item = &g_Items[item_num];
struct CREATURE_INFO *const bird = (struct CREATURE_INFO *)item->data;

if (item->hit_points <= 0) {
switch (item->current_anim_state) {
case BIRD_ANIM_FALL:
if (item->pos.y > item->floor) {
item->pos.y = item->floor;
item->gravity = 0;
item->fall_speed = 0;
item->goal_anim_state = BIRD_ANIM_DEATH;
}
break;

case BIRD_ANIM_DEATH:
item->pos.y = item->floor;
break;

default:
if (item->object_num == O_CROW) {
item->anim_num = g_Objects[O_CROW].anim_idx + CROW_DIE_ANIM;
} else {
item->anim_num = g_Objects[O_EAGLE].anim_idx + BIRD_DIE_ANIM;
}
item->frame_num = g_Anims[item->anim_num].frame_base;
item->current_anim_state = BIRD_ANIM_FALL;
item->gravity = 1;
item->speed = 0;
break;
}
item->pos.x_rot = 0;
Creature_Animate(item_num, 0, 0);
return;
}

AI_INFO info;
Creature_AIInfo(item, &info);
CreatureMood(item, &info, MOOD_BORED);
const int16_t angle = Creature_Turn(item, BIRD_TURN);

switch (item->current_anim_state) {
case BIRD_ANIM_FLY:
bird->flags = 0;
if (item->required_anim_state != BIRD_ANIM_EMPTY) {
item->goal_anim_state = item->required_anim_state;
}
if (bird->mood == MOOD_BORED) {
item->goal_anim_state = BIRD_ANIM_STOP;
} else if (info.ahead && info.distance < BIRD_ATTACK_RANGE) {
item->goal_anim_state = BIRD_ANIM_ATTACK;
} else {
item->goal_anim_state = BIRD_ANIM_GLIDE;
}
break;

case BIRD_ANIM_STOP:
item->pos.y = item->floor;
if (bird->mood != MOOD_BORED) {
item->goal_anim_state = BIRD_ANIM_FLY;
}
break;

case BIRD_ANIM_GLIDE:
if (bird->mood == MOOD_BORED) {
item->required_anim_state = BIRD_ANIM_STOP;
item->goal_anim_state = BIRD_ANIM_FLY;
} else if (info.ahead && info.distance < BIRD_ATTACK_RANGE) {
item->goal_anim_state = BIRD_ANIM_ATTACK;
}
break;

case BIRD_ANIM_ATTACK:
if (!bird->flags && item->touch_bits) {
g_LaraItem->hit_points -= BIRD_DAMAGE;
g_LaraItem->hit_status = 1;
if (item->object_num == O_CROW) {
Creature_Effect(item, &m_CrowBite, DoBloodSplat);
} else {
Creature_Effect(item, &m_BirdBite, DoBloodSplat);
}
bird->flags = 1;
}
break;

case BIRD_ANIM_EAT:
item->pos.y = item->floor;
if (bird->mood != MOOD_BORED) {
item->goal_anim_state = BIRD_ANIM_FLY;
}
break;
}

Creature_Animate(item_num, angle, 0);
}
1 change: 1 addition & 0 deletions src/game/objects/creatures/bird.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#include <stdint.h>

void __cdecl Bird_Initialise(int16_t item_num);
void __cdecl Bird_Control(int16_t item_num);
1 change: 0 additions & 1 deletion src/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

// clang-format off
#define Output_InsertInventoryBackground ((void __cdecl (*)(const int16_t *obj_ptr))0x00401D50)
#define Bird_Control ((void __cdecl (*)(int16_t item_num))0x0040C910)
#define Boat_Initialise ((void __cdecl (*)(int16_t item_num))0x0040CB30)
#define Boat_CheckGeton ((int32_t __cdecl (*)(int16_t item_num, struct COLL_INFO *coll))0x0040CB70)
#define Boat_Collision ((void __cdecl (*)(int16_t item_num, struct ITEM_INFO *lara_item, struct COLL_INFO *coll))0x0040CCE0)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ static void Inject_Lara_Col(void)
static void Inject_Objects(void)
{
INJECT(1, 0x0040C880, Bird_Initialise);
INJECT(1, 0x0040C910, Bird_Control);
}

static void Inject_S_Audio_Sample(void)
Expand Down

0 comments on commit 07a802f

Please sign in to comment.