Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
port Box_StalkBox
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Apr 14, 2024
1 parent b5981f6 commit ee33f84
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
16 changes: 8 additions & 8 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.
2 changes: 1 addition & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ typedef enum GAME_OBJECT_ID {
0040E490 000001F3 + int32_t __cdecl Box_SearchLOT(struct LOT_INFO *lot, int32_t expansion);
0040E690 0000006F + int32_t __cdecl Box_UpdateLOT(struct LOT_INFO *lot, int32_t expansion);
0040E700 00000095 + void __cdecl Box_TargetBox(struct LOT_INFO *lot, int16_t box_num);
0040E7A0 000000F2 - int32_t __cdecl Box_StalkBox(struct ITEM_INFO *item, struct ITEM_INFO *enemy, int16_t box_num);
0040E7A0 000000F2 + int32_t __cdecl Box_StalkBox(struct ITEM_INFO *item, const struct ITEM_INFO *enemy, int16_t box_num);
0040E8A0 000000A4 - int32_t __cdecl Box_EscapeBox(struct ITEM_INFO *item, struct ITEM_INFO *enemy, int16_t box_num);
0040E950 000000A7 - int32_t __cdecl Box_ValidBox(struct ITEM_INFO *item, int16_t zone_num, int16_t box_num);
0040EA00 0000043F - void __cdecl CreatureMood(struct ITEM_INFO *item, struct AI_INFO *info, int32_t violent);
Expand Down
34 changes: 34 additions & 0 deletions src/game/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include "game/random.h"
#include "global/const.h"
#include "global/vars.h"
#include "util.h"

#define BOX_OVERLAP_INDEX 0x3FFF
#define BOX_SEARCH_NUM 0x7FFF
#define BOX_END_BIT 0x8000
#define BOX_NUM_BITS (~BOX_END_BIT) // = 0x7FFF
#define BOX_STALK_DIST 3 // tiles

int32_t __cdecl Box_SearchLOT(
struct LOT_INFO *const lot, const int32_t expansion)
Expand Down Expand Up @@ -129,3 +131,35 @@ void __cdecl Box_TargetBox(struct LOT_INFO *const lot, const int16_t box_num)
lot->target.y = box->height;
}
}

int32_t __cdecl Box_StalkBox(
const struct ITEM_INFO *const item, const struct ITEM_INFO *const enemy,
const int16_t box_num)
{
const struct BOX_INFO *const box = &g_Boxes[box_num];

const int32_t z =
((box->left + box->right) << (WALL_SHIFT - 1)) - enemy->pos.z;
const int32_t x =
((box->top + box->bottom) << (WALL_SHIFT - 1)) - enemy->pos.x;

const int32_t x_range = (box->bottom - box->top + BOX_STALK_DIST)
<< WALL_SHIFT;
const int32_t z_range = (box->right - box->left + BOX_STALK_DIST)
<< WALL_SHIFT;
if (x > x_range || x < -x_range || z > z_range || z < -z_range) {
return false;
}

const int32_t enemy_quad = (enemy->rot.y >> 14) + 2;
const int32_t box_quad = (z > 0) ? ((x > 0) ? 2 : 1) : ((x > 0) ? 3 : 0);
if (enemy_quad == box_quad) {
return false;
}

const int32_t baddie_quad = item->pos.z > enemy->pos.z
? (item->pos.x > x ? 2 : 1)
: (item->pos.x > x ? 3 : 0);

return enemy_quad == baddie_quad && ABS(enemy_quad - box_quad) == 2;
}
3 changes: 3 additions & 0 deletions src/game/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
int32_t __cdecl Box_SearchLOT(struct LOT_INFO *lot, int32_t expansion);
int32_t __cdecl Box_UpdateLOT(struct LOT_INFO *lot, int32_t expansion);
void __cdecl Box_TargetBox(struct LOT_INFO *lot, int16_t box_num);
int32_t __cdecl Box_StalkBox(
const struct ITEM_INFO *item, const struct ITEM_INFO *enemy,
int16_t box_num);
1 change: 0 additions & 1 deletion src/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define Boat_Animation ((void __cdecl (*)(struct ITEM_INFO *boat, int32_t collide))0x0040D950)
#define Boat_Control ((void __cdecl (*)(int16_t item_num))0x0040DAC0)
#define Gondola_Control ((void __cdecl (*)(int16_t item_num))0x0040E0F0)
#define Box_StalkBox ((int32_t __cdecl (*)(struct ITEM_INFO *item, struct ITEM_INFO *enemy, int16_t box_num))0x0040E7A0)
#define Box_EscapeBox ((int32_t __cdecl (*)(struct ITEM_INFO *item, struct ITEM_INFO *enemy, int16_t box_num))0x0040E8A0)
#define Box_ValidBox ((int32_t __cdecl (*)(struct ITEM_INFO *item, int16_t zone_num, int16_t box_num))0x0040E950)
#define CreatureMood ((void __cdecl (*)(struct ITEM_INFO *item, struct AI_INFO *info, int32_t violent))0x0040EA00)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ static void Inject_Box(void)
INJECT(1, 0x0040E490, Box_SearchLOT);
INJECT(1, 0x0040E690, Box_UpdateLOT);
INJECT(1, 0x0040E700, Box_TargetBox);
INJECT(1, 0x0040E7A0, Box_StalkBox);
}

static void Inject_Objects(void)
Expand Down

0 comments on commit ee33f84

Please sign in to comment.