movable_block: fix bugs with falling blocks

Resolves #723.
Changes Room_AlterFloorHeight.
This commit is contained in:
walkawayy 2023-10-09 23:03:07 -04:00
parent ed8f2bb20e
commit e06ea97375
7 changed files with 67 additions and 15 deletions

View file

@ -15,6 +15,7 @@
- fixed 3d pickups sometimes triggering z-buffer issues (#1015)
- fixed oversized passport in cinematic camera mode (eg when Lara steps on the Midas Hand) (#1009)
- fixed braid being disabled by default unless the player runs the config tool first (#1043)
- fixed various bugs with falling movable blocks (#723)
- improved frame scheduling to use less CPU (#985)
- improved and expanded gameflow documentation (#1018)
- rotated the Scion in Tomb of Qualopec to face the the main gate and Qualopec (#1007)

View file

@ -295,6 +295,7 @@ Not all options are turned on by default. Refer to `TR1X_ConfigTool.exe` for det
- **City of Khamoon**: incorrect trapdoor trigger types in rooms 31 and 34
- **Obelisk of Khamoon**: missing switch trigger type in room 66
- **Atlantean Stronghold**: fixed poorly configured portals between rooms 74 and 12
- fixed various bugs with falling movable blocks
#### Cheats
- added a fly cheat

View file

@ -260,6 +260,17 @@ void Item_UpdateRoom(ITEM_INFO *item, int32_t height)
}
}
int16_t Item_GetHeight(ITEM_INFO *item)
{
int16_t room_num = item->room_number;
FLOOR_INFO *floor =
Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num);
int32_t height =
Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z);
return height;
}
int16_t Item_GetWaterHeight(ITEM_INFO *item)
{
int16_t height = Room_GetWaterHeight(

View file

@ -18,6 +18,7 @@ void Item_RemoveDrawn(int16_t item_num);
void Item_AddActive(int16_t item_num);
void Item_NewRoom(int16_t item_num, int16_t room_num);
void Item_UpdateRoom(ITEM_INFO *item, int32_t height);
int16_t Item_GetHeight(ITEM_INFO *item);
int16_t Item_GetWaterHeight(ITEM_INFO *item);
int16_t Item_Spawn(ITEM_INFO *item, int16_t object_num);
int32_t Item_GlobalReplace(int32_t src_object_num, int32_t dst_object_num);

View file

@ -79,7 +79,8 @@ void MovableBlock_Setup(OBJECT_INFO *obj)
void MovableBlock_Initialise(int16_t item_num)
{
ITEM_INFO *item = &g_Items[item_num];
if (item->status != IS_INVISIBLE) {
if (item->status != IS_INVISIBLE && item->pos.y >= Item_GetHeight(item)) {
Room_AlterFloorHeight(item, -WALL_L);
}
}
@ -110,6 +111,11 @@ void MovableBlock_Control(int16_t item_num)
item->status = IS_DEACTIVATED;
FX_DinoStomp(item);
Sound_Effect(SFX_T_REX_FOOTSTOMP, &item->pos, SPM_NORMAL);
} else if (
item->pos.y >= height && !item->gravity_status
&& !(bool)(intptr_t)item->priv) {
item->status = IS_NOT_ACTIVE;
Item_RemoveActive(item_num);
}
if (item->room_number != room_num) {
@ -133,6 +139,10 @@ void MovableBlock_Collision(
{
ITEM_INFO *item = &g_Items[item_num];
if (item->current_anim_state == MBS_STILL) {
item->priv = (void *)false;
}
if (!g_Input.action || item->status == IS_ACTIVE
|| lara_item->gravity_status || lara_item->pos.y != item->pos.y) {
return;
@ -226,6 +236,7 @@ void MovableBlock_Collision(
item->status = IS_ACTIVE;
Item_Animate(item);
Lara_Animate(lara_item);
item->priv = (void *)true;
}
}

View file

@ -590,19 +590,42 @@ int16_t Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num)
void Room_AlterFloorHeight(ITEM_INFO *item, int32_t height)
{
int16_t room_num = item->room_number;
FLOOR_INFO *floor =
Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num);
FLOOR_INFO *ceiling = Room_GetFloor(
item->pos.x, item->pos.y + height - WALL_L, item->pos.z, &room_num);
if (!height) {
return;
}
if (floor->floor == NO_HEIGHT / 256) {
floor->floor = ceiling->ceiling + height / 256;
int16_t data;
FLOOR_INFO *floor;
ROOM_INFO *r = &g_RoomInfo[item->room_number];
do {
int32_t z_floor = (item->pos.z - r->z) >> WALL_SHIFT;
int32_t x_floor = (item->pos.x - r->x) >> WALL_SHIFT;
if (z_floor <= 0) {
z_floor = 0;
CLAMP(x_floor, 1, r->y_size - 2);
} else if (z_floor >= r->x_size - 1) {
z_floor = r->x_size - 1;
CLAMP(x_floor, 1, r->y_size - 2);
} else {
floor->floor += height / 256;
if (floor->floor == ceiling->ceiling && floor->sky_room == NO_ROOM) {
CLAMP(x_floor, 0, r->y_size - 1);
}
floor = &r->floor[z_floor + x_floor * r->x_size];
data = Room_GetDoor(floor);
if (data != NO_ROOM) {
r = &g_RoomInfo[data];
}
} while (data != NO_ROOM);
if (floor->floor != NO_HEIGHT / 256) {
floor->floor += height >> 8;
if (floor->floor == floor->ceiling && floor->sky_room == NO_ROOM) {
floor->floor = NO_HEIGHT / 256;
}
} else {
floor->floor = floor->ceiling + (height >> 8);
}
if (g_Boxes[floor->box].overlap_index & BLOCKABLE) {

View file

@ -114,10 +114,13 @@ static void Savegame_LoadPostprocess(void)
}
}
if (obj->control == MovableBlock_Control
&& item->status == IS_NOT_ACTIVE) {
if (obj->control == MovableBlock_Control) {
item->priv =
item->status == IS_ACTIVE ? (void *)true : (void *)false;
if (item->status == IS_NOT_ACTIVE) {
Room_AlterFloorHeight(item, -WALL_L);
}
}
if (obj->control == RollingBlock_Control
&& item->current_anim_state != RBS_MOVING) {
@ -179,7 +182,8 @@ void Savegame_PreprocessItems(void)
ITEM_INFO *item = &g_Items[i];
OBJECT_INFO *obj = &g_Objects[item->object_number];
if (obj->control == MovableBlock_Control) {
if (obj->control == MovableBlock_Control && item->status != IS_INVISIBLE
&& item->pos.y >= Item_GetHeight(item)) {
Room_AlterFloorHeight(item, WALL_L);
}
if (obj->control == RollingBlock_Control) {