Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Jade Dragon disappearance in Bartoli's Hideout #2538

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/tr2/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3121,11 +3121,11 @@ typedef enum {
0x00414B70 0x0198 SECTOR *__cdecl Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num);
0x00414D10 0x0168 int32_t __cdecl Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num);
0x00414E80 0x0265 int32_t __cdecl Room_GetHeight(const SECTOR *sector, int32_t x, int32_t y, int32_t z);
0x00415100 0x00E7 void __cdecl Camera_Legacy_RefreshFromTrigger(int16_t type, const int16_t *data);
0x004151F0 0x0690 void __cdecl Room_Legacy_TestTriggers(int16_t *data, int32_t heavy);
0x00415100 0x00E7 void __cdecl Camera_RefreshFromTrigger(int16_t type, const int16_t *data);
0x004151F0 0x0690 void __cdecl Room_TestTriggers(int16_t *data, int32_t heavy);
0x004158D0 0x0055 int32_t __cdecl Item_IsTriggerActive(ITEM *item);
0x00415930 0x023D int32_t __cdecl Room_GetCeiling(const SECTOR *sector, int32_t x, int32_t y, int32_t z);
0x00415B90 0x004E int16_t __cdecl Room_Legacy_GetDoor(const SECTOR *sector);
0x00415B90 0x004E int16_t __cdecl Room_GetDoor(const SECTOR *sector);
0x00415BE0 0x00A0 int32_t __cdecl LOS_Check(const GAME_VECTOR *start, GAME_VECTOR *target);
0x00415C80 0x02EB int32_t __cdecl LOS_CheckZ(const GAME_VECTOR *start, GAME_VECTOR *target);
0x00415F70 0x02EC int32_t __cdecl LOS_CheckX(const GAME_VECTOR *start, GAME_VECTOR *target);
Expand All @@ -3134,7 +3134,7 @@ typedef enum {
0x00416640 0x00B3 void __cdecl Room_FlipMap(void);
0x00416700 0x0096 void __cdecl Room_RemoveFlipItems(ROOM *r);
0x004167A0 0x005C void __cdecl Room_AddFlipItems(ROOM *r);
0x00416800 0x0024 void __cdecl Room_Legacy_TriggerMusicTrack(int16_t value, int16_t flags, int16_t type);
0x00416800 0x0024 void __cdecl Room_TriggerMusicTrack(int16_t value, int16_t flags, int16_t type);
0x00416830 0x00DA void __cdecl Room_TriggerMusicTrackImpl(int16_t value, int16_t flags, int16_t type);

# game/demo.c
Expand Down Expand Up @@ -4171,7 +4171,7 @@ typedef enum {
0x004553C0 0x001F BOOL __cdecl S_Audio_Sample_OutIsTrackPlaying(int32_t track_id);
0x004553E0 0x0077 bool __cdecl Music_Init(void);
0x00455460 0x0051 void __cdecl Music_Shutdown(void);
0x00455500 0x006F void __cdecl Music_Legacy_Play(int16_t track_id, bool is_looped);
0x00455500 0x006F void __cdecl Music_Play(int16_t track_id, bool is_looped);
0x00455570 0x0039 void __cdecl Music_Stop(void);
0x004555B0 0x0084 bool __cdecl Music_PlaySynced(int32_t track_id);
0x00455640 0x0061 int32_t __cdecl Music_GetFrames(void);
Expand Down Expand Up @@ -4550,7 +4550,7 @@ typedef enum {
0x00526188 MATRIX *g_IMMatrixPtr;
0x0052618C ROOM *g_Rooms;
0x00526240 int32_t g_FlipStatus;
0x00526288 int16_t *g_Legacy_TriggerIndex;
0x00526288 int16_t *g_TriggerIndex;
0x005262A0 int32_t g_LOSRooms[20];
0x005262F0 ITEM *g_Items;
0x005262F6 int16_t g_NumCineFrames;
Expand Down Expand Up @@ -4631,7 +4631,7 @@ typedef enum {
0x00466BDC int32_t g_PaletteIndex;
0x00519F78 int32_t g_HWR_TexturePageIndexes[32]; // MAX_TEXTURE_PAGES
0x004D7790 int32_t g_HeightType;
0x004D9D94 int16_t *g_Legacy_FloorData;
0x004D9D94 int16_t *g_FloorData;
0x00525B08 int16_t *g_AnimCommands;
0x0052617C ANIM_CHANGE *g_AnimChanges;
0x00525B04 ANIM_RANGE *g_AnimRanges;
Expand Down
43 changes: 9 additions & 34 deletions src/libtrx/game/rooms/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,11 @@ static void M_AddFlipItems(const ROOM *const room)
{
int16_t item_num = room->item_num;
while (item_num != NO_ITEM) {
const ITEM *const item = Item_Get(item_num);

switch (item->object_id) {
case O_MOVABLE_BLOCK_1:
case O_MOVABLE_BLOCK_2:
case O_MOVABLE_BLOCK_3:
case O_MOVABLE_BLOCK_4:
Room_AlterFloorHeight(item, -WALL_L);
break;
#if TR_VERSION == 1
case O_SLIDING_PILLAR:
Room_AlterFloorHeight(item, -WALL_L * 2);
break;
#endif
default:
break;
ITEM *const item = Item_Get(item_num);
const OBJECT *const obj = Object_Get(item->object_id);

if (obj->handle_flip_func != nullptr) {
obj->handle_flip_func(item, RFS_FLIPPED);
}

item_num = item->next_item;
Expand All @@ -138,33 +127,19 @@ static void M_RemoveFlipItems(const ROOM *const room)
int16_t item_num = room->item_num;
while (item_num != NO_ITEM) {
ITEM *const item = Item_Get(item_num);
const OBJECT *const obj = Object_Get(item->object_id);

switch (item->object_id) {
case O_MOVABLE_BLOCK_1:
case O_MOVABLE_BLOCK_2:
case O_MOVABLE_BLOCK_3:
case O_MOVABLE_BLOCK_4:
Room_AlterFloorHeight(item, WALL_L);
break;
#if TR_VERSION == 1
case O_SLIDING_PILLAR:
Room_AlterFloorHeight(item, WALL_L * 2);
break;
#endif
default:
break;
if (obj->handle_flip_func != nullptr) {
obj->handle_flip_func(item, RFS_UNFLIPPED);
}

#if TR_VERSION == 2
// TR2 does not have land/water objects like crocodile/alligator in TR1,
// so avoid instances of floating water creatures in drained rooms.
if (item->flags & IF_ONE_SHOT
&& Object_Get(item->object_id)->intelligent
if (TR_VERSION == 2 && (item->flags & IF_ONE_SHOT) && obj->intelligent
&& item->hit_points <= 0) {
Item_RemoveDrawn(item_num);
item->flags |= IF_KILLED;
}
#endif

item_num = item->next_item;
}
Expand Down
3 changes: 1 addition & 2 deletions src/libtrx/include/libtrx/game/items/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ typedef struct {
uint16_t flags;

SHADE shade;
#if TR_VERSION == 1
void *data;
#if TR_VERSION == 1
void *priv;
CARRIED_ITEM *carried_item;
bool enable_shadow;
#elif TR_VERSION == 2
int16_t carried_item;
void *data;
#endif

XYZ_32 pos;
Expand Down
3 changes: 3 additions & 0 deletions src/libtrx/include/libtrx/game/objects/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../anims/types.h"
#include "../collision.h"
#include "../items/types.h"
#include "../rooms/enum.h"
#include "../savegame.h"
#include "../types.h"

Expand Down Expand Up @@ -60,6 +61,8 @@ typedef struct OBJECT {
const ITEM *item, int32_t x, int32_t y, int32_t z, int16_t height);
int16_t (*ceiling_height_func)(
const ITEM *item, int32_t x, int32_t y, int32_t z, int16_t height);
void (*activate_func)(ITEM *item);
void (*handle_flip_func)(ITEM *item, ROOM_FLIP_STATUS flip_status);
void (*handle_save_func)(ITEM *item, SAVEGAME_STAGE stage);
#if TR_VERSION == 1
const OBJECT_BOUNDS *(*bounds_func)(void);
Expand Down
2 changes: 0 additions & 2 deletions src/libtrx/include/libtrx/game/objects/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ extern const GAME_OBJECT_ID g_PickupObjects[];
extern const GAME_OBJECT_ID g_AnimObjects[];
extern const GAME_OBJECT_ID g_NullObjects[];
extern const GAME_OBJECT_ID g_InvObjects[];
extern const GAME_OBJECT_ID g_MovableBlockObjects[];
extern const GAME_OBJECT_ID g_PuzzleHoleObjects[];

extern const GAME_OBJECT_PAIR g_ItemToInvObjectMap[];
extern const GAME_OBJECT_PAIR g_KeyItemToReceptacleMap[];
Expand Down
18 changes: 18 additions & 0 deletions src/tr1/game/objects/general/pickup.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static void M_GetAllAtLaraPos(ITEM *item, ITEM *lara_item);
static void M_Setup(OBJECT *obj);
static void M_Initialise(int16_t item_num);
static void M_HandleSave(ITEM *item, SAVEGAME_STAGE stage);
static void M_Activate(ITEM *item);
static void M_Control(int16_t item_num);
static const OBJECT_BOUNDS *M_Bounds(void);
static void M_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
Expand Down Expand Up @@ -104,9 +105,12 @@ static void M_GetItem(int16_t item_num, ITEM *item, ITEM *lara_item)
{
Overlay_AddPickup(item->object_id);
Inv_AddItem(item->object_id);

item->status = IS_INVISIBLE;
item->flags |= IF_KILLED;
Item_RemoveDrawn(item_num);
Item_RemoveActive(item_num);

Savegame_GetCurrentInfo(Game_GetCurrentLevel())->stats.pickup_count++;
g_Lara.interact_target.is_moving = false;
}
Expand All @@ -133,6 +137,7 @@ static void M_Setup(OBJECT *const obj)
obj->bounds_func = M_Bounds;
obj->initialise_func = M_Initialise;
obj->handle_save_func = M_HandleSave;
obj->activate_func = M_Activate;
obj->control_func = M_Control;
}

Expand All @@ -155,6 +160,19 @@ static void M_HandleSave(ITEM *const item, const SAVEGAME_STAGE stage)
}
}

static void M_Activate(ITEM *const item)
{
if (item->status == IS_INVISIBLE) {
item->touch_bits = 0;
item->status = IS_ACTIVE;
const int16_t item_num = Item_GetIndex(item);
Item_AddActive(item_num);
} else {
item->status = IS_INVISIBLE;
item->flags |= IF_KILLED;
}
}

static void M_Control(int16_t item_num)
{
ITEM *const item = Item_Get(item_num);
Expand Down
11 changes: 11 additions & 0 deletions src/tr1/game/objects/traps/movable_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static bool M_TestDeathCollision(ITEM *item, const ITEM *lara);
static void M_KillLara(const ITEM *item, ITEM *lara);
static void M_Setup(OBJECT *obj);
static void M_Initialise(int16_t item_num);
static void M_HandleFlip(ITEM *item, ROOM_FLIP_STATUS flip_status);
static void M_HandleSave(ITEM *item, SAVEGAME_STAGE stage);
static void M_Control(int16_t item_num);
static void M_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
Expand Down Expand Up @@ -271,6 +272,7 @@ static void M_KillLara(const ITEM *const item, ITEM *const lara)
static void M_Setup(OBJECT *const obj)
{
obj->initialise_func = M_Initialise;
obj->handle_flip_func = M_HandleFlip;
obj->handle_save_func = M_HandleSave;
obj->control_func = M_Control;
obj->draw_func = M_Draw;
Expand All @@ -289,6 +291,15 @@ static void M_Initialise(const int16_t item_num)
}
}

static void M_HandleFlip(ITEM *const item, const ROOM_FLIP_STATUS flip_status)
{
if (flip_status == RFS_FLIPPED) {
Room_AlterFloorHeight(item, -WALL_L);
} else {
Room_AlterFloorHeight(item, WALL_L);
}
}

static void M_HandleSave(ITEM *const item, const SAVEGAME_STAGE stage)
{
switch (stage) {
Expand Down
11 changes: 11 additions & 0 deletions src/tr1/game/objects/traps/sliding_pillar.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include "global/const.h"

static void M_Setup(OBJECT *obj);
static void M_HandleFlip(ITEM *item, ROOM_FLIP_STATUS flip_status);
static void M_HandleSave(ITEM *item, SAVEGAME_STAGE stage);
static void M_Initialise(int16_t item_num);
static void M_Control(int16_t item_num);

static void M_Setup(OBJECT *const obj)
{
obj->initialise_func = M_Initialise;
obj->handle_flip_func = M_HandleFlip;
obj->handle_save_func = M_HandleSave;
obj->control_func = M_Control;
obj->save_position = 1;
Expand All @@ -23,6 +25,15 @@ static void M_Initialise(const int16_t item_num)
Room_AlterFloorHeight(item, -WALL_L * 2);
}

static void M_HandleFlip(ITEM *const item, const ROOM_FLIP_STATUS flip_status)
{
if (flip_status == RFS_FLIPPED) {
Room_AlterFloorHeight(item, -WALL_L * 2);
} else {
Room_AlterFloorHeight(item, WALL_L * 2);
}
}

static void M_HandleSave(ITEM *const item, const SAVEGAME_STAGE stage)
{
switch (stage) {
Expand Down
5 changes: 4 additions & 1 deletion src/tr1/game/room.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,10 @@ void Room_TestSectorTrigger(const ITEM *const item, const SECTOR *const sector)
}

if (!item->active) {
if (Object_Get(item->object_id)->intelligent) {
const OBJECT *const obj = Object_Get(item->object_id);
if (obj->activate_func != nullptr) {
obj->activate_func(item);
} else if (obj->intelligent) {
if (item->status == IS_INACTIVE) {
item->touch_bits = 0;
item->status = IS_ACTIVE;
Expand Down
11 changes: 11 additions & 0 deletions src/tr2/game/objects/general/movable_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static bool M_TestPull(

static void M_Setup(OBJECT *obj);
static void M_Initialise(int16_t item_num);
static void M_HandleFlip(ITEM *item, ROOM_FLIP_STATUS flip_status);
static void M_HandleSave(ITEM *item, SAVEGAME_STAGE stage);
static void M_Draw(const ITEM *item);
static void M_Control(int16_t item_num);
Expand Down Expand Up @@ -204,6 +205,7 @@ static void M_Initialise(const int16_t item_num)
static void M_Setup(OBJECT *const obj)
{
obj->initialise_func = M_Initialise;
obj->handle_flip_func = M_HandleFlip;
obj->handle_save_func = M_HandleSave;
obj->control_func = M_Control;
obj->collision_func = M_Collision;
Expand All @@ -213,6 +215,15 @@ static void M_Setup(OBJECT *const obj)
obj->save_anim = 1;
}

static void M_HandleFlip(ITEM *const item, const ROOM_FLIP_STATUS flip_status)
{
if (flip_status == RFS_FLIPPED) {
Room_AlterFloorHeight(item, -WALL_L);
} else {
Room_AlterFloorHeight(item, WALL_L);
}
}

static void M_HandleSave(ITEM *const item, const SAVEGAME_STAGE stage)
{
switch (stage) {
Expand Down
26 changes: 26 additions & 0 deletions src/tr2/game/objects/general/pickup.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static void M_DoAboveWater(int16_t item, ITEM *lara_item);
static void M_DoUnderwater(int16_t item, ITEM *lara_item);
static void M_Setup(OBJECT *obj);
static void M_HandleSave(ITEM *item, SAVEGAME_STAGE stage);
static void M_Activate(ITEM *item);
static void M_Draw(const ITEM *item);

static void M_DoPickup(const int16_t item_num)
Expand All @@ -89,7 +90,9 @@ static void M_DoPickup(const int16_t item_num)
}

item->status = IS_INVISIBLE;
item->flags |= IF_KILLED;
Item_RemoveDrawn(item_num);
Item_RemoveActive(item_num);
}

static void M_DoFlarePickup(const int16_t item_num)
Expand Down Expand Up @@ -221,6 +224,7 @@ static void M_DoUnderwater(const int16_t item_num, ITEM *const lara_item)
static void M_Setup(OBJECT *const obj)
{
obj->handle_save_func = M_HandleSave;
obj->activate_func = M_Activate;
obj->collision_func = Pickup_Collision;
obj->draw_func = M_Draw;
obj->save_position = 1;
Expand All @@ -237,8 +241,25 @@ static void M_HandleSave(ITEM *const item, const SAVEGAME_STAGE stage)
}
}

static void M_Activate(ITEM *const item)
{
if (item->status == IS_INVISIBLE) {
item->touch_bits = 0;
item->status = IS_ACTIVE;
const int16_t item_num = Item_GetIndex(item);
Item_AddActive(item_num);
} else {
item->status = IS_INVISIBLE;
item->flags |= IF_KILLED;
}
}

static void M_Draw(const ITEM *const item)
{
if (item->flags & IF_INVISIBLE) {
return;
}

if (!g_Config.visuals.enable_3d_pickups) {
Object_DrawSpriteItem(item);
return;
Expand Down Expand Up @@ -327,6 +348,11 @@ static void M_Draw(const ITEM *const item)
void Pickup_Collision(
const int16_t item_num, ITEM *const lara_item, COLL_INFO *const coll)
{
const ITEM *const item = Item_Get(item_num);
if (item->flags & IF_INVISIBLE) {
return;
}

if (g_Lara.water_status == LWS_ABOVE_WATER
|| g_Lara.water_status == LWS_WADE) {
M_DoAboveWater(item_num, lara_item);
Expand Down
Loading