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
Box_EscapeBox
  • Loading branch information
rr- committed Apr 14, 2024
1 parent ee33f84 commit 29c6a64
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
20 changes: 10 additions & 10 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 @@ -1744,8 +1744,8 @@ 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, 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);
0040E7A0 000000F2 + int32_t __cdecl Box_StalkBox(const struct ITEM_INFO *item, const struct ITEM_INFO *enemy, int16_t box_num);
0040E8A0 000000A4 + int32_t __cdecl Box_EscapeBox(const struct ITEM_INFO *item, const 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);
0040EE70 00000459 - enum TARGET_TYPE __cdecl Box_CalculateTarget(struct XYZ_32 *target, struct ITEM_INFO *item, struct LOT_INFO *lot);
Expand Down
21 changes: 21 additions & 0 deletions src/game/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define BOX_END_BIT 0x8000
#define BOX_NUM_BITS (~BOX_END_BIT) // = 0x7FFF
#define BOX_STALK_DIST 3 // tiles
#define BOX_ESCAPE_DIST 5 // tiles

int32_t __cdecl Box_SearchLOT(
struct LOT_INFO *const lot, const int32_t expansion)
Expand Down Expand Up @@ -163,3 +164,23 @@ int32_t __cdecl Box_StalkBox(

return enemy_quad == baddie_quad && ABS(enemy_quad - box_quad) == 2;
}

int32_t __cdecl Box_EscapeBox(
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 x =
((box->bottom + box->top) << (WALL_SHIFT - 1)) - enemy->pos.x;
const int32_t z =
((box->left + box->right) << (WALL_SHIFT - 1)) - enemy->pos.z;

const int32_t x_range = BOX_ESCAPE_DIST << WALL_SHIFT;
const int32_t z_range = BOX_ESCAPE_DIST << WALL_SHIFT;
if (x > -x_range && x < x_range && z > -z_range && z < z_range) {
return false;
}

return ((z > 0) == (item->pos.z > enemy->pos.z))
|| ((x > 0) == (item->pos.x > enemy->pos.x));
}
3 changes: 3 additions & 0 deletions src/game/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ 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);
int32_t __cdecl Box_EscapeBox(
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_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)
#define Box_CalculateTarget ((enum TARGET_TYPE __cdecl (*)(struct XYZ_32 *target, struct ITEM_INFO *item, struct LOT_INFO *lot))0x0040EE70)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ static void Inject_Box(void)
INJECT(1, 0x0040E690, Box_UpdateLOT);
INJECT(1, 0x0040E700, Box_TargetBox);
INJECT(1, 0x0040E7A0, Box_StalkBox);
INJECT(1, 0x0040E8A0, Box_EscapeBox);
}

static void Inject_Objects(void)
Expand Down

0 comments on commit 29c6a64

Please sign in to comment.