Skip to content

Commit

Permalink
tr2: port Flare_Control
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Nov 11, 2024
1 parent eb36409 commit 47e66d8
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 10 deletions.
16 changes: 8 additions & 8 deletions docs/tr2/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/tr2/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,7 @@ typedef enum {
0x0042FFF0 0x0018 + void __cdecl Flare_DrawMeshes(void);
0x00430010 0x0018 + void __cdecl Flare_UndrawMeshes(void);
0x00430030 0x003E + void __cdecl Flare_Ready(void);
0x00430070 0x026E - void __cdecl Flare_Control(int16_t item_num);
0x00430070 0x026E + void __cdecl Flare_Control(int16_t item_num);

# game/laramisc.c
0x004302E0 0x0668 + void __cdecl Lara_Control(int16_t item_num);
Expand Down
88 changes: 88 additions & 0 deletions src/tr2/decomp/flares.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "global/funcs.h"
#include "global/vars.h"

#include <libtrx/utils.h>

#define FLARE_INTENSITY 12
#define FLARE_FALL_OFF 11
#define MAX_FLARE_AGE (60 * FRAMES_PER_SECOND) // = 1800
Expand Down Expand Up @@ -335,3 +337,89 @@ void __cdecl Flare_Ready(void)
g_Lara.right_arm.lock = 0;
g_Lara.target = NULL;
}

void __cdecl Flare_Control(const int16_t item_num)
{
ITEM *const item = &g_Items[item_num];
if (item->fall_speed) {
item->rot.x += PHD_DEGREE * 3;
item->rot.z += PHD_DEGREE * 5;
} else {
item->rot.x = 0;
item->rot.z = 0;
}

const int32_t x = item->pos.x;
const int32_t y = item->pos.y;
const int32_t z = item->pos.z;
item->pos.z += (item->speed * Math_Cos(item->rot.y)) >> W2V_SHIFT;
item->pos.x += (item->speed * Math_Sin(item->rot.y)) >> W2V_SHIFT;

if (g_Rooms[item->room_num].flags & RF_UNDERWATER) {
item->fall_speed += (5 - item->fall_speed) / 2;
item->speed = item->speed + (5 - item->speed) / 2;
} else {
item->fall_speed += GRAVITY;
}
item->pos.y += item->fall_speed;

int16_t room_num = item->room_num;
const SECTOR *const sector =
Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num);

const int32_t height =
Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z);
if (item->pos.y < height) {
const int32_t ceiling =
Room_GetCeiling(sector, item->pos.x, item->pos.y, item->pos.z);
if (item->pos.y < ceiling) {
item->fall_speed = -item->fall_speed;
item->pos.y = ceiling;
}
} else {
if (y > height) {
item->pos.x = x;
item->pos.y = y;
item->pos.z = z;
item->rot.y += PHD_180;
item->speed /= 2;
room_num = item->room_num;
} else {
if (item->fall_speed > 40) {
item->fall_speed = 40 - item->fall_speed;
CLAMPL(item->fall_speed, -100);
} else {
item->fall_speed = 0;
item->speed -= 3;
CLAMPL(item->speed, 0);
}
item->pos.y = height;
}
}

if (room_num != item->room_num) {
Item_NewRoom(item_num, room_num);
}

int32_t flare_age = (int32_t)item->data & 0x7FFF;
if (flare_age < MAX_FLARE_AGE) {
flare_age++;
} else if (item->fall_speed == 0 && item->speed == 0) {
Item_Kill(item_num);
return;
}

if (Flare_DoLight(&item->pos, flare_age)) {
flare_age |= 0x8000u;
if ((g_Rooms[item->room_num].flags & RF_UNDERWATER)) {
Sound_Effect(SFX_LARA_FLARE_BURN, &item->pos, SPM_UNDERWATER);
if (Random_GetDraw() < 0x4000) {
CreateBubble(&item->pos, item->room_num);
}
} else {
Sound_Effect(SFX_LARA_FLARE_BURN, &item->pos, SPM_NORMAL);
}
}

item->data = (void *)flare_age;
}
1 change: 1 addition & 0 deletions src/tr2/decomp/flares.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ void __cdecl Flare_Undraw(void);
void __cdecl Flare_DrawMeshes(void);
void __cdecl Flare_UndrawMeshes(void);
void __cdecl Flare_Ready(void);
void __cdecl Flare_Control(int16_t item_num);
1 change: 0 additions & 1 deletion src/tr2/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
#define InitialiseHair ((void __cdecl (*)(void))0x00420EA0)
#define HairControl ((void __cdecl (*)(int32_t in_cutscene))0x00420F20)
#define DrawHair ((void __cdecl (*)(void))0x00421920)
#define Flare_Control ((void __cdecl (*)(int16_t item_num))0x00430070)
#define Missile_Control ((void __cdecl (*)(int16_t fx_num))0x00432FE0)
#define ShootAtLara ((void __cdecl (*)(FX *fx))0x004332B0)
#define Object_DrawUnclippedItem ((void __cdecl (*)(const ITEM *item))0x004341A0)
Expand Down
1 change: 1 addition & 0 deletions src/tr2/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ static void M_DecompFlares(const bool enable)
INJECT(enable, 0x0042FFF0, Flare_DrawMeshes);
INJECT(enable, 0x00430010, Flare_UndrawMeshes);
INJECT(enable, 0x00430030, Flare_Ready);
INJECT(enable, 0x00430070, Flare_Control);
}

static void M_GameBuf(bool enable)
Expand Down

0 comments on commit 47e66d8

Please sign in to comment.