Skip to content

Commit

Permalink
tr2: port Switch_Trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 11, 2024
1 parent b66d317 commit bc8f6ce
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 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 @@ -3600,7 +3600,7 @@ typedef enum {
0x00438840 0x0223 -R void __cdecl KeyHoleCollision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
0x00438A80 0x0294 -R void __cdecl PuzzleHoleCollision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
0x00438D40 0x0039 + void __cdecl Switch_Control(int16_t item_num);
0x00438D80 0x00BD -R int32_t __cdecl SwitchTrigger(int16_t item_num, int16_t timer);
0x00438D80 0x00BD + int32_t __cdecl Switch_Trigger(int16_t item_num, int16_t timer);
0x00438E40 0x003D -R int32_t __cdecl KeyTrigger(int16_t item_num);
0x00438E80 0x0033 -R int32_t __cdecl PickupTrigger(int16_t item_num);
0x00438EC0 0x0023 -R void __cdecl SecretControl(int16_t item_num);
Expand Down
36 changes: 36 additions & 0 deletions src/tr2/game/objects/general/switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,39 @@ void __cdecl Switch_Control(const int16_t item_num)
}
Item_Animate(item);
}

int32_t __cdecl Switch_Trigger(const int16_t item_num, const int16_t timer)
{
ITEM *const item = Item_Get(item_num);

if (item->object_id == O_SWITCH_TYPE_AIRLOCK) {
if (item->status == IS_DEACTIVATED) {
Item_RemoveActive(item_num);
item->status = IS_INACTIVE;
return false;
} else if (
(item->flags & IF_ONE_SHOT)
|| item->current_anim_state == SWITCH_STATE_OFF) {
return false;
}

item->flags |= IF_ONE_SHOT;
return true;
}

if (item->status != IS_DEACTIVATED) {
return false;
}

if (item->current_anim_state == SWITCH_STATE_OFF && timer > 0) {
item->timer = timer;
if (timer != 1) {
item->timer = timer * FRAMES_PER_SECOND;
}
item->status = IS_ACTIVE;
} else {
Item_RemoveActive(item_num);
item->status = IS_INACTIVE;
}
return true;
}
2 changes: 2 additions & 0 deletions src/tr2/game/objects/general/switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ void __cdecl Switch_CollisionUW(
int16_t item_num, ITEM *lara_item, COLL_INFO *coll);

void __cdecl Switch_Control(int16_t item_num);

int32_t __cdecl Switch_Trigger(int16_t item_num, int16_t timer);
3 changes: 2 additions & 1 deletion src/tr2/game/room.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "game/lot.h"
#include "game/math.h"
#include "game/music.h"
#include "game/objects/general/switch.h"
#include "game/shell.h"
#include "global/const.h"
#include "global/funcs.h"
Expand Down Expand Up @@ -415,7 +416,7 @@ void __cdecl Room_TestTriggers(const int16_t *fd, bool heavy)

case TT_SWITCH: {
const int16_t value = TRIGGER_VALUE(*fd++);
if (!SwitchTrigger(value, timer)) {
if (!Switch_Trigger(value, timer)) {
return;
}
switch_off = g_Items[value].current_anim_state == LS_RUN;
Expand Down
1 change: 0 additions & 1 deletion src/tr2/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
#define DetonatorCollision ((void __cdecl (*)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll))0x00438600)
#define KeyHoleCollision ((void __cdecl (*)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll))0x00438840)
#define PuzzleHoleCollision ((void __cdecl (*)(int16_t item_num, ITEM *lara_item, COLL_INFO *coll))0x00438A80)
#define SwitchTrigger ((int32_t __cdecl (*)(int16_t item_num, int16_t timer))0x00438D80)
#define KeyTrigger ((int32_t __cdecl (*)(int16_t item_num))0x00438E40)
#define PickupTrigger ((int32_t __cdecl (*)(int16_t item_num))0x00438E80)
#define SecretControl ((void __cdecl (*)(int16_t item_num))0x00438EC0)
Expand Down
1 change: 1 addition & 0 deletions src/tr2/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ static void M_Objects(const bool enable)
INJECT(enable, 0x004382F0, Switch_Collision);
INJECT(enable, 0x00438500, Switch_CollisionUW);
INJECT(enable, 0x00438D40, Switch_Control);
INJECT(enable, 0x00438D80, Switch_Trigger);
INJECT(enable, 0x00442B30, FlameEmitter_Control);
INJECT(enable, 0x00442BC0, Flame_Control);
INJECT(enable, 0x00442E70, EmberEmitter_Control);
Expand Down

0 comments on commit bc8f6ce

Please sign in to comment.