Skip to content

Commit

Permalink
port DoorControl
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Mar 5, 2021
1 parent a0bec82 commit 756cfd2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
12 changes: 6 additions & 6 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,9 @@ NatlaGun ---------- ---------- x

# objects.cpp
ShutThatDoor ---------- ---------- +
OpenThatDoor ---------- ---------- -
OpenThatDoor ---------- ---------- +
InitialiseDoor 0x0042CA40 0x000004AE +
DoorControl 0x0042CEF0 0x0000023B *
DoorControl 0x0042CEF0 0x0000023B +
OnDrawBridge 0x0042D130 0x000000B1 -
DrawBridgeFloor 0x0042D1F0 0x0000003B *
DrawBridgeCeiling 0x0042D230 0x0000003F *
Expand Down
44 changes: 44 additions & 0 deletions src/game/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ void ShutThatDoor(DOORPOS_DATA* d)
}
}

void OpenThatDoor(DOORPOS_DATA* d)
{
FLOOR_INFO* floor = d->floor;
if (!floor) {
return;
}

*floor = d->data;

int16_t box_num = d->block;
if (box_num != NO_BOX) {
Boxes[box_num].overlap_index &= ~BLOCKED;
}
}

void InitialiseDoor(int16_t item_num)
{
ITEM_INFO* item = &Items[item_num];
Expand Down Expand Up @@ -147,7 +162,36 @@ void InitialiseDoor(int16_t item_num)
ShutThatDoor(&door->d2flip);
}

void DoorControl(int16_t item_num)
{
ITEM_INFO* item = &Items[item_num];
DOOR_DATA* door = item->data;

if (TriggerActive(item)) {
if (item->current_anim_state == DOOR_CLOSED) {
item->goal_anim_state = DOOR_OPEN;
} else {
OpenThatDoor(&door->d1);
OpenThatDoor(&door->d2);
OpenThatDoor(&door->d1flip);
OpenThatDoor(&door->d2flip);
}
} else {
if (item->current_anim_state == DOOR_OPEN) {
item->goal_anim_state = DOOR_CLOSED;
} else {
ShutThatDoor(&door->d1);
ShutThatDoor(&door->d2);
ShutThatDoor(&door->d1flip);
ShutThatDoor(&door->d2flip);
}
}

AnimateItem(item);
}

void T1MInjectGameObjects()
{
INJECT(0x0042CA40, InitialiseDoor);
INJECT(0x0042CEF0, DoorControl);
}
3 changes: 2 additions & 1 deletion src/game/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <stdint.h>

// clang-format off
#define DoorControl ((void (*)(int16_t item_num))0x0042CEF0)
#define DrawBridgeFloor ((void (*)(ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t *height))0x0042D1F0)
#define DrawBridgeCeiling ((void (*)(ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t *height))0x0042D230)
#define DrawBridgeCollision ((void (*)(int16_t item_num, ITEM_INFO* litem, COLL_INFO* coll))0x0042D270)
Expand Down Expand Up @@ -41,7 +40,9 @@
// clang-format on

void ShutThatDoor(DOORPOS_DATA* d);
void OpenThatDoor(DOORPOS_DATA* d);
void InitialiseDoor(int16_t item_num);
void DoorControl(int16_t item_num);

void T1MInjectGameObjects();

Expand Down
5 changes: 5 additions & 0 deletions src/game/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,11 @@ typedef enum {
IT_NUMBER_OF = 2,
} INV_TEXT;

typedef enum {
DOOR_CLOSED = 0,
DOOR_OPEN = 1,
} DOOR_ANIMS;

#pragma pack(push, 1)

typedef struct {
Expand Down

0 comments on commit 756cfd2

Please sign in to comment.