From 47e66d85dbb596845ecab4f55aa8db0a1ff424dc Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 11 Nov 2024 18:53:24 +0100 Subject: [PATCH] tr2: port Flare_Control --- docs/tr2/progress.svg | 16 ++++---- docs/tr2/progress.txt | 2 +- src/tr2/decomp/flares.c | 88 +++++++++++++++++++++++++++++++++++++++++ src/tr2/decomp/flares.h | 1 + src/tr2/global/funcs.h | 1 - src/tr2/inject_exec.c | 1 + 6 files changed, 99 insertions(+), 10 deletions(-) diff --git a/docs/tr2/progress.svg b/docs/tr2/progress.svg index 7cc18e6e5..18419dc90 100644 --- a/docs/tr2/progress.svg +++ b/docs/tr2/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -72.83% (906) · 24.76% (308) · 0% (0) · 2.41% (30) +72.91% (907) · 24.68% (307) · 0% (0) · 2.41% (30) - - + + @@ -634,7 +634,7 @@ void __cdecl Flare_DrawMeshes(void); void __cdecl Flare_UndrawMeshes(void); void __cdecl Flare_Ready(void); -void __cdecl Flare_Control(int16_t item_num); +void __cdecl Flare_Control(int16_t item_num); void __cdecl Lara_Control(int16_t item_num); void __cdecl Lara_Animate(ITEM *item); void __cdecl Lara_UseItem(GAME_OBJECT_ID object_id); @@ -1324,10 +1324,10 @@ Tomb2.exe progress according to the function sizes: -76.97% · 22.70% · 0% · 0.33% +77.15% · 22.52% · 0% · 0.33% - - + + @@ -1466,7 +1466,7 @@ void __cdecl Shark_Control(int16_t item_num); int32_t __cdecl DoShift(ITEM *skidoo, XYZ_32 *pos, XYZ_32 *old); int32_t __cdecl S_GetObjectBounds(const BOUNDS_16 *bounds); -void __cdecl Flare_Control(int16_t item_num); +void __cdecl Flare_Control(int16_t item_num); void __cdecl Output_Init(int16_t x, int16_t y, int32_t width, int32_t height, int32_t near_z, int32_t far_z, int16_t view_angle, int32_t screen_width, int32_t screen_height); int32_t __cdecl Room_GetHeight(const SECTOR *sector, int32_t x, int32_t y, int32_t z); BOOL __cdecl Level_LoadSamples(HANDLE handle); diff --git a/docs/tr2/progress.txt b/docs/tr2/progress.txt index 715136f8b..47421e2ac 100644 --- a/docs/tr2/progress.txt +++ b/docs/tr2/progress.txt @@ -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); diff --git a/src/tr2/decomp/flares.c b/src/tr2/decomp/flares.c index 18ccf93db..d65d1b8a3 100644 --- a/src/tr2/decomp/flares.c +++ b/src/tr2/decomp/flares.c @@ -13,6 +13,8 @@ #include "global/funcs.h" #include "global/vars.h" +#include + #define FLARE_INTENSITY 12 #define FLARE_FALL_OFF 11 #define MAX_FLARE_AGE (60 * FRAMES_PER_SECOND) // = 1800 @@ -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; +} diff --git a/src/tr2/decomp/flares.h b/src/tr2/decomp/flares.h index a1b641ff0..6c1fe161f 100644 --- a/src/tr2/decomp/flares.h +++ b/src/tr2/decomp/flares.h @@ -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); diff --git a/src/tr2/global/funcs.h b/src/tr2/global/funcs.h index 6ba7fdc30..b29e36311 100644 --- a/src/tr2/global/funcs.h +++ b/src/tr2/global/funcs.h @@ -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) diff --git a/src/tr2/inject_exec.c b/src/tr2/inject_exec.c index 8fab24d67..0aabb9244 100644 --- a/src/tr2/inject_exec.c +++ b/src/tr2/inject_exec.c @@ -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)