Skip to content

Commit

Permalink
tr2: port SpikeCeiling_Control
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Nov 12, 2024
1 parent ee8ecd9 commit 5d4ec50
Show file tree
Hide file tree
Showing 7 changed files with 76 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 @@ -3742,7 +3742,7 @@ typedef enum {
# game/traps.c
0x00440F10 0x01F4 + void __cdecl Mine_Control(int16_t mine_num);
0x00441110 0x0138 + void __cdecl SpikeWall_Control(int16_t item_num);
0x00441250 0x0115 - void __cdecl CeilingSpikes_Control(int16_t item_num);
0x00441250 0x0115 + void __cdecl SpikeCeiling_Control(int16_t item_num);
0x00441370 0x0086 - void __cdecl Hook_Control(int16_t item_num);
0x00441400 0x0190 - void __cdecl Propeller_Control(int16_t item_num);
0x00441590 0x017B - void __cdecl SpinningBlade_Control(int16_t item_num);
Expand Down
58 changes: 58 additions & 0 deletions src/tr2/game/objects/traps/spike_ceiling.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "game/objects/traps/spike_ceiling.h"

#include "game/items.h"
#include "game/lara/control.h"
#include "game/room.h"
#include "game/sound.h"
#include "global/funcs.h"
#include "global/vars.h"

#define SPIKE_CEILING_DAMAGE 20
#define SPIKE_CEILING_SPEED 1

static void M_Move(int16_t item_num);
static void M_HitLara(ITEM *item);

static void M_Move(const int16_t item_num)
{
ITEM *const item = Item_Get(item_num);
const int32_t y = item->pos.y + 5;
int16_t room_num = item->room_num;
const SECTOR *const sector =
Room_GetSector(item->pos.x, y, item->pos.z, &room_num);
if (Room_GetHeight(sector, item->pos.x, y, item->pos.z) < y + WALL_L) {
item->status = IS_DEACTIVATED;
} else {
item->pos.y = y;
if (room_num != item->room_num) {
Item_NewRoom(item_num, room_num);
}
}
Sound_Effect(SFX_DOOR_SLIDE, &item->pos, SPM_NORMAL);
}

static void M_HitLara(ITEM *const item)
{
Lara_TakeDamage(SPIKE_CEILING_DAMAGE, true);

DoLotsOfBlood(
g_LaraItem->pos.x, item->pos.y + LARA_HEIGHT, g_LaraItem->pos.z,
SPIKE_CEILING_SPEED, item->rot.y, g_LaraItem->room_num, 3);
item->touch_bits = 0;

Sound_Effect(SFX_LARA_FLESH_WOUND, &item->pos, SPM_NORMAL);
}

void __cdecl SpikeCeiling_Control(const int16_t item_num)
{
ITEM *const item = Item_Get(item_num);

const bool is_trigger_active = Item_IsTriggerActive(item);
if (is_trigger_active && item->status != IS_DEACTIVATED) {
M_Move(item_num);
}

if (item->touch_bits) {
M_HitLara(item);
}
}
5 changes: 5 additions & 0 deletions src/tr2/game/objects/traps/spike_ceiling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "global/types.h"

void __cdecl SpikeCeiling_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 @@ -134,7 +134,6 @@
#define Spider_Leap ((void __cdecl (*)(int16_t item_num, int16_t angle))0x0043FFC0)
#define Spider_Control ((void __cdecl (*)(int16_t item_num))0x00440070)
#define BigSpider_Control ((void __cdecl (*)(int16_t item_num))0x00440290)
#define CeilingSpikes_Control ((void __cdecl (*)(int16_t item_num))0x00441250)
#define Hook_Control ((void __cdecl (*)(int16_t item_num))0x00441370)
#define Propeller_Control ((void __cdecl (*)(int16_t item_num))0x00441400)
#define SpinningBlade_Control ((void __cdecl (*)(int16_t item_num))0x00441590)
Expand Down
3 changes: 3 additions & 0 deletions src/tr2/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "game/objects/traps/flame_emitter.h"
#include "game/objects/traps/mine.h"
#include "game/objects/traps/rolling_ball.h"
#include "game/objects/traps/spike_ceiling.h"
#include "game/objects/traps/spike_wall.h"
#include "game/objects/vehicles/boat.h"
#include "game/objects/vehicles/skidoo_armed.h"
Expand Down Expand Up @@ -1097,6 +1098,8 @@ static void M_Objects(const bool enable)
INJECT(enable, 0x0043F2F0, SkidooArmed_Collision);
INJECT(enable, 0x00440F10, Mine_Control);
INJECT(enable, 0x00441110, SpikeWall_Control);
INJECT(enable, 0x00441250, SpikeCeiling_Control);
INJECT(enable, 0x00441250, SpikeCeiling_Control);
INJECT(enable, 0x00441B30, RollingBall_Initialise);
INJECT(enable, 0x00441B70, RollingBall_Control);
INJECT(enable, 0x00441EC0, RollingBall_Collision);
Expand Down
1 change: 1 addition & 0 deletions src/tr2/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ dll_sources = [
'game/objects/traps/flame_emitter.c',
'game/objects/traps/mine.c',
'game/objects/traps/rolling_ball.c',
'game/objects/traps/spike_ceiling.c',
'game/objects/traps/spike_wall.c',
'game/objects/vars.c',
'game/objects/vehicles/boat.c',
Expand Down

0 comments on commit 5d4ec50

Please sign in to comment.