Skip to content

Commit

Permalink
tr2: port Diver_GetWaterSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 26, 2024
1 parent 88c0d4f commit 535a502
Show file tree
Hide file tree
Showing 6 changed files with 52 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 @@ -3094,7 +3094,7 @@ typedef enum {

# game/diver.c
0x00416C20 0x007A + int16_t __cdecl Diver_Harpoon(int32_t x, int32_t y, int32_t z, int16_t speed, PHD_ANGLE y_rot, int16_t room_num);
0x00416CA0 0x0106 - int32_t __cdecl Diver_GetWaterSurface(int32_t x, int32_t y, int32_t z, int16_t room_num);
0x00416CA0 0x0106 + int32_t __cdecl Diver_GetWaterSurface(int32_t x, int32_t y, int32_t z, int16_t room_num);
0x00416DB0 0x0389 + void __cdecl Diver_Control(int16_t item_num);

# game/dog.c
Expand Down
39 changes: 39 additions & 0 deletions src/tr2/game/objects/creatures/diver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "game/creature.h"
#include "game/effects.h"
#include "game/los.h"
#include "game/room.h"
#include "global/const.h"
#include "global/funcs.h"
#include "global/vars.h"
Expand All @@ -29,6 +30,44 @@ typedef enum {
DIVER_ANIM_DEATH = 9,
} DIVER_ANIM;

static const SECTOR *M_GetRelSector(const ROOM *r, int32_t x, int32_t z);

static const SECTOR *M_GetRelSector(
const ROOM *const r, const int32_t x, const int32_t z)
{
const XZ_32 sector_pos = {
.x = (x - r->pos.x) >> WALL_SHIFT,
.z = (z - r->pos.z) >> WALL_SHIFT,
};
return &r->sectors[sector_pos.z + r->size.z * sector_pos.x];
}

int32_t __cdecl Diver_GetWaterSurface(
const int32_t x, const int32_t y, const int32_t z, const int16_t room_num)
{
const ROOM *r = Room_Get(room_num);
const SECTOR *sector = M_GetRelSector(r, x, z);

if ((r->flags & RF_UNDERWATER)) {
while (sector->sky_room != NO_ROOM) {
r = Room_Get(sector->sky_room);
if (!(r->flags & RF_UNDERWATER)) {
return sector->ceiling << 8;
}
sector = M_GetRelSector(r, x, z);
}
} else {
while (sector->pit_room != NO_ROOM) {
r = Room_Get(sector->pit_room);
if ((r->flags & RF_UNDERWATER)) {
return sector->floor << 8;
}
sector = M_GetRelSector(r, x, z);
}
}
return NO_HEIGHT;
}

void Diver_Setup(void)
{
OBJECT *const obj = &g_Objects[O_DIVER];
Expand Down
3 changes: 3 additions & 0 deletions src/tr2/game/objects/creatures/diver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <stdint.h>

int32_t __cdecl Diver_GetWaterSurface(
int32_t x, int32_t y, int32_t z, int16_t room_num);

void Diver_Setup(void);

void __cdecl Diver_Control(int16_t item_num);
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 @@ -6,7 +6,6 @@

// clang-format off
#define Output_InsertInventoryBackground ((void __cdecl (*)(const int16_t *obj_ptr))0x00401D50)
#define Diver_GetWaterSurface ((int32_t __cdecl (*)(int32_t x, int32_t y, int32_t z, int16_t room_num))0x00416CA0)
#define Dog_Control ((void __cdecl (*)(int16_t item_num))0x00417160)
#define Tiger_Control ((void __cdecl (*)(int16_t item_num))0x00417510)
#define TRex_Control ((void __cdecl (*)(int16_t item_num))0x004186A0)
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 @@ -1018,6 +1018,7 @@ static void M_Objects(const bool enable)
INJECT(enable, 0x00413940, Door_Collision);
INJECT(enable, 0x004139C0, Object_Collision_Trap);
INJECT(enable, 0x00416C20, Diver_Harpoon);
INJECT(enable, 0x00416CA0, Diver_GetWaterSurface);
INJECT(enable, 0x00416DB0, Diver_Control);
INJECT(enable, 0x004177B0, Twinkle_Control);
INJECT(enable, 0x00417AC0, Dragon_Collision);
Expand Down

0 comments on commit 535a502

Please sign in to comment.