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

Commit

Permalink
port Box_ValidBox
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Apr 14, 2024
1 parent 29c6a64 commit 23691ec
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 13 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 @@ -1746,7 +1746,7 @@ typedef enum GAME_OBJECT_ID {
0040E700 00000095 + void __cdecl Box_TargetBox(struct LOT_INFO *lot, 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);
0040E950 000000A7 + int32_t __cdecl Box_ValidBox(const 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);
0040F2D0 000000F8 - int32_t __cdecl Creature_CheckBaddieOverlap(int16_t item_num);
Expand Down
28 changes: 28 additions & 0 deletions src/game/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,31 @@ int32_t __cdecl Box_EscapeBox(
return ((z > 0) == (item->pos.z > enemy->pos.z))
|| ((x > 0) == (item->pos.x > enemy->pos.x));
}

int32_t __cdecl Box_ValidBox(
const struct ITEM_INFO *const item, const int16_t zone_num,
const int16_t box_num)
{
const CREATURE_INFO *const creature = item->data;
int16_t *zone;
if (creature->lot.fly) {
zone = g_FlyZone[g_FlipStatus];
} else {
zone = g_GroundZone[creature->lot.step / STEP_L][g_FlipStatus];
}

if (zone[box_num] != zone_num) {
return false;
}

const BOX_INFO *const box = &g_Boxes[box_num];
if ((creature->lot.block_mask & box->overlap_index) != 0) {
return false;
}

return !(
item->pos.z > (box->left << WALL_SHIFT)
&& item->pos.z < (box->right << WALL_SHIFT)
&& item->pos.x > (box->top << WALL_SHIFT)
&& item->pos.x < (box->bottom << WALL_SHIFT));
}
2 changes: 2 additions & 0 deletions src/game/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ int32_t __cdecl Box_StalkBox(
int32_t __cdecl Box_EscapeBox(
const struct ITEM_INFO *item, const struct ITEM_INFO *enemy,
int16_t box_num);
int32_t __cdecl Box_ValidBox(
const struct ITEM_INFO *item, int16_t zone_num, int16_t box_num);
4 changes: 1 addition & 3 deletions src/game/creature.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ void __cdecl Creature_Initialise(const int16_t item_num)

int32_t __cdecl Creature_Activate(const int16_t item_num)
{
int32_t result; // eax

struct ITEM_INFO *const item = &g_Items[item_num];
if (item->status != IS_INVISIBLE) {
return true;
Expand All @@ -38,7 +36,7 @@ int32_t __cdecl Creature_Activate(const int16_t item_num)
void __cdecl Creature_AIInfo(
struct ITEM_INFO *const item, struct AI_INFO *const info)
{
CREATURE_INFO *creature = (CREATURE_INFO *)item->data;
CREATURE_INFO *const creature = (CREATURE_INFO *)item->data;
if (creature == NULL) {
return;
}
Expand Down
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_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)
#define Creature_CheckBaddieOverlap ((int32_t __cdecl (*)(int16_t item_num))0x0040F2D0)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ static void Inject_Box(void)
INJECT(1, 0x0040E700, Box_TargetBox);
INJECT(1, 0x0040E7A0, Box_StalkBox);
INJECT(1, 0x0040E8A0, Box_EscapeBox);
INJECT(1, 0x0040E950, Box_ValidBox);
}

static void Inject_Objects(void)
Expand Down

0 comments on commit 23691ec

Please sign in to comment.