Skip to content

Commit

Permalink
room: refactor lava and trigger interpretation
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 committed Aug 8, 2024
1 parent 3405e8c commit 131d553
Show file tree
Hide file tree
Showing 18 changed files with 276 additions and 396 deletions.
27 changes: 9 additions & 18 deletions src/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,20 +782,14 @@ void Camera_UpdateCutscene(void)
Viewport_SetFOV(ref->fov);
}

void Camera_RefreshFromTrigger(int16_t type, int16_t *data)
void Camera_RefreshFromTrigger(const TRIGGER *const trigger)
{
int16_t trigger;
int16_t target_ok = 2;
do {
trigger = *data++;
int16_t value = trigger & VALUE_BITS;

switch (TRIG_BITS(trigger)) {
case TO_CAMERA:
trigger = *data++;

if (value == g_Camera.last) {
g_Camera.number = value;
for (int32_t i = 0; i < trigger->command_count; i++) {
const TRIGGER_CMD *const cmd = &trigger->commands[i];
if (cmd->type == TO_CAMERA) {
if (cmd->parameter == g_Camera.last) {
g_Camera.number = cmd->parameter;

if (g_Camera.timer < 0 || g_Camera.type == CAM_LOOK
|| g_Camera.type == CAM_COMBAT) {
Expand All @@ -808,15 +802,12 @@ void Camera_RefreshFromTrigger(int16_t type, int16_t *data)
} else {
target_ok = 0;
}
break;

case TO_TARGET:
} else if (cmd->type == TO_TARGET) {
if (g_Camera.type != CAM_LOOK && g_Camera.type != CAM_COMBAT) {
g_Camera.item = &g_Items[value];
g_Camera.item = &g_Items[cmd->parameter];
}
break;
}
} while (!(trigger & END_BIT));
}

if (g_Camera.item != NULL) {
if (!target_ok
Expand Down
2 changes: 1 addition & 1 deletion src/game/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ void Camera_Fixed(void);
void Camera_Update(void);
void Camera_UpdateCutscene(void);
void Camera_OffsetReset(void);
void Camera_RefreshFromTrigger(int16_t type, int16_t *data);
void Camera_RefreshFromTrigger(const TRIGGER *trigger);
void Camera_MoveManual(void);
void Camera_Apply(void);
12 changes: 6 additions & 6 deletions src/game/collide.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ void Collide_GetCollisionInfo(
&& coll->front_floor > 0) {
coll->front_floor = 512;
} else if (
coll->lava_is_pit && coll->front_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->lava_is_pit && coll->front_floor > 0
&& Room_GetPitSector(sector, x, z)->is_death_sector) {
coll->front_floor = 512;
}
}
Expand Down Expand Up @@ -170,8 +170,8 @@ void Collide_GetCollisionInfo(
&& coll->left_floor > 0) {
coll->left_floor = 512;
} else if (
coll->lava_is_pit && coll->left_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->lava_is_pit && coll->left_floor > 0
&& Room_GetPitSector(sector, x, z)->is_death_sector) {
coll->left_floor = 512;
}
}
Expand Down Expand Up @@ -205,8 +205,8 @@ void Collide_GetCollisionInfo(
&& coll->right_floor > 0) {
coll->right_floor = 512;
} else if (
coll->lava_is_pit && coll->right_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->lava_is_pit && coll->right_floor > 0
&& Room_GetPitSector(sector, x, z)->is_death_sector) {
coll->right_floor = 512;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/game/lara/lara_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void Lara_HandleAboveWater(ITEM_INFO *item, COLL_INFO *coll)
g_LaraCollisionRoutines[item->current_anim_state](item, coll);
Item_UpdateRoom(item, -LARA_HEIGHT / 2);
Gun_Control();
Room_TestTriggers(coll->trigger, false);
Room_TestTriggers(item);
}

void Lara_HandleSurface(ITEM_INFO *item, COLL_INFO *coll)
Expand Down Expand Up @@ -307,7 +307,7 @@ void Lara_HandleSurface(ITEM_INFO *item, COLL_INFO *coll)
g_LaraCollisionRoutines[item->current_anim_state](item, coll);
Item_UpdateRoom(item, 100);
Gun_Control();
Room_TestTriggers(coll->trigger, false);
Room_TestTriggers(item);
}

void Lara_HandleUnderwater(ITEM_INFO *item, COLL_INFO *coll)
Expand Down Expand Up @@ -397,5 +397,5 @@ void Lara_HandleUnderwater(ITEM_INFO *item, COLL_INFO *coll)
g_LaraCollisionRoutines[item->current_anim_state](item, coll);
Item_UpdateRoom(item, 0);
Gun_Control();
Room_TestTriggers(coll->trigger, false);
Room_TestTriggers(item);
}
2 changes: 1 addition & 1 deletion src/game/lara/lara_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ bool Lara_LandedBad(ITEM_INFO *item, COLL_INFO *coll)

item->floor = height;
item->pos.y = height;
Room_TestTriggers(g_TriggerIndex, false);
Room_TestTriggers(item);
item->pos.y = old_y;

int landspeed = item->fall_speed - DAMAGE_START;
Expand Down
6 changes: 2 additions & 4 deletions src/game/objects/creatures/bacon_lara.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,11 @@ void BaconLara_Control(int16_t item_num)
const int32_t h = Room_GetHeight(sector, x, y, z);
item->floor = h;

Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);
if (item->pos.y >= h) {
item->floor = h;
item->pos.y = h;
sector = Room_GetSector(x, h, z, &room_num);
Room_GetHeight(sector, x, h, z);
Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);
item->gravity_status = 0;
item->fall_speed = 0;
item->goal_anim_state = LS_DEATH;
Expand Down
5 changes: 1 addition & 4 deletions src/game/objects/creatures/torso.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ void Torso_Control(int16_t item_num)
if (item->status == IS_DEACTIVATED) {
Sound_Effect(SFX_ATLANTEAN_DEATH, &item->pos, SPM_NORMAL);
Effect_ExplodingDeath(item_num, -1, TORSO_PART_DAMAGE);
const SECTOR_INFO *const sector = Room_GetSector(
item->pos.x, item->pos.y, item->pos.z, &item->room_number);
Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z);
Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);

Item_Kill(item_num);
item->status = IS_DEACTIVATED;
Expand Down
6 changes: 1 addition & 5 deletions src/game/objects/general/scion.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ void Scion_Control3(int16_t item_num)
if (counter == 0) {
item->status = IS_INVISIBLE;
item->hit_points = DONT_TARGET;
int16_t room_num = item->room_number;
const SECTOR_INFO *const sector =
Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num);
Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z);
Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);
Item_RemoveDrawn(item_num);
}

Expand Down
44 changes: 8 additions & 36 deletions src/game/objects/traps/lava.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define LAVA_EMBER_DAMAGE 10
#define LAVA_WEDGE_SPEED 25

bool Lava_TestFloor(ITEM_INFO *item)
bool Lava_TestFloor(const ITEM_INFO *const item)
{
if (item->hit_points < 0 || g_Lara.water_status == LWS_CHEAT
|| (g_Lara.water_status == LWS_ABOVE_WATER
Expand All @@ -25,40 +25,11 @@ bool Lava_TestFloor(ITEM_INFO *item)
// OG fix: check if floor index has lava
int16_t room_num = item->room_number;
const SECTOR_INFO *const sector =
Room_GetSector(item->pos.x, 32000, item->pos.z, &room_num);

int16_t *data = &g_FloorData[sector->index];
int16_t type;
do {
type = *data++;

switch (type & DATA_TYPE) {
case FT_TILT: {
data++;
break;
}

case FT_ROOF:
case FT_DOOR:
data++;
break;

case FT_LAVA:
return true;

case FT_TRIGGER:
data++;
break;

default:
break;
}
} while (!(type & END_BIT));

return false;
Room_GetSector(item->pos.x, MAX_HEIGHT, item->pos.z, &room_num);
return sector->is_death_sector;
}

void Lava_Burn(ITEM_INFO *item)
void Lava_Burn(ITEM_INFO *const item)
{
if (g_Lara.water_status == LWS_CHEAT) {
return;
Expand All @@ -70,8 +41,9 @@ void Lava_Burn(ITEM_INFO *item)

int16_t room_num = item->room_number;
const SECTOR_INFO *const sector =
Room_GetSector(item->pos.x, 32000, item->pos.z, &room_num);
int16_t height = Room_GetHeight(sector, item->pos.x, 32000, item->pos.z);
Room_GetSector(item->pos.x, MAX_HEIGHT, item->pos.z, &room_num);
const int16_t height =
Room_GetHeight(sector, item->pos.x, MAX_HEIGHT, item->pos.z);

if (item->floor != height) {
return;
Expand All @@ -84,7 +56,7 @@ void Lava_Burn(ITEM_INFO *item)
}

for (int i = 0; i < 10; i++) {
int16_t fx_num = Effect_Create(item->room_number);
const int16_t fx_num = Effect_Create(item->room_number);
if (fx_num != NO_ITEM) {
FX_INFO *fx = &g_Effects[fx_num];
fx->object_number = O_FLAME;
Expand Down
2 changes: 1 addition & 1 deletion src/game/objects/traps/lava.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdbool.h>
#include <stdint.h>

bool Lava_TestFloor(ITEM_INFO *item);
bool Lava_TestFloor(const ITEM_INFO *item);
void Lava_Burn(ITEM_INFO *item);

void Lava_Setup(OBJECT_INFO *obj);
Expand Down
7 changes: 1 addition & 6 deletions src/game/objects/traps/movable_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,7 @@ void MovableBlock_Control(int16_t item_num)
item->status = IS_NOT_ACTIVE;
Item_RemoveActive(item_num);
Room_AlterFloorHeight(item, -WALL_L);

room_num = item->room_number;
sector =
Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num);
Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z);
Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/objects/traps/rolling_ball.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void RollingBall_Control(int16_t item_num)
item->floor =
Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z);

Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);

if (item->pos.y >= item->floor - STEP_L) {
item->gravity_status = 0;
Expand Down
6 changes: 1 addition & 5 deletions src/game/objects/traps/thors_hammer.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ void ThorsHandle_Control(int16_t item_num)
int32_t old_x = x;
int32_t old_z = z;

int16_t room_num = item->room_number;
const SECTOR_INFO *const sector =
Room_GetSector(x, item->pos.y, z, &room_num);
Room_GetHeight(sector, x, item->pos.y, z);
Room_TestTriggers(g_TriggerIndex, true);
Room_TestTriggers(item);

switch (item->rot.y) {
case 0:
Expand Down
Loading

0 comments on commit 131d553

Please sign in to comment.