diff --git a/docs/progress.svg b/docs/progress.svg
index f98a64fe..0f9e8f2b 100644
--- a/docs/progress.svg
+++ b/docs/progress.svg
@@ -69,10 +69,10 @@
Tomb2.exe progress according to the physical function order:
-34.48% (420) · 63.05% (768) · 0.41% (5) · 2.05% (25)
+34.56% (421) · 62.97% (767) · 0.41% (5) · 2.05% (25)
-
-
+
+
@@ -183,7 +183,7 @@
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);
-int32_t __cdecl Box_ValidBox(struct ITEM_INFO *item, int16_t zone_num, int16_t box_num);
+int32_t __cdecl Box_ValidBox(const struct ITEM_INFO *item, int16_t zone_num, int16_t box_num);
void __cdecl CreatureMood(struct ITEM_INFO *item, struct AI_INFO *info, int32_t violent);
enum TARGET_TYPE __cdecl Box_CalculateTarget(struct XYZ_32 *target, struct ITEM_INFO *item, struct LOT_INFO *lot);
int32_t __cdecl Creature_CheckBaddieOverlap(int16_t item_num);
@@ -1299,10 +1299,10 @@
Tomb2.exe progress according to the function sizes:
-30.56% · 69.12% · 0% · 0.32%
+30.61% · 69.07% · 0% · 0.32%
-
-
+
+
@@ -1824,7 +1824,7 @@
void __cdecl Creature_Float(int16_t item_num);
void __cdecl XianDamage(struct ITEM_INFO *item, CREATURE_INFO *xian, int32_t damage);
void __cdecl Output_InsertSprite(int32_t z, int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t sprite_idx, int16_t shade);
-int32_t __cdecl Box_ValidBox(struct ITEM_INFO *item, int16_t zone_num, int16_t box_num);
+int32_t __cdecl Box_ValidBox(const struct ITEM_INFO *item, int16_t zone_num, int16_t box_num);
void __cdecl ShootAtLara(struct FX_INFO *fx);
int16_t __cdecl GunMiss(int32_t x, int32_t y, int32_t z, int16_t speed, PHD_ANGLE yrot, int16_t room_num);
bool __cdecl ShowDDrawGameWindow(bool active);
diff --git a/docs/progress.txt b/docs/progress.txt
index 938f43a7..2d098bd5 100644
--- a/docs/progress.txt
+++ b/docs/progress.txt
@@ -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);
diff --git a/src/game/box.c b/src/game/box.c
index 9d758370..37118fdf 100644
--- a/src/game/box.c
+++ b/src/game/box.c
@@ -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));
+}
diff --git a/src/game/box.h b/src/game/box.h
index 61ef49a7..30db17f2 100644
--- a/src/game/box.h
+++ b/src/game/box.h
@@ -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);
diff --git a/src/game/creature.c b/src/game/creature.c
index 4728a787..10c1f6ad 100644
--- a/src/game/creature.c
+++ b/src/game/creature.c
@@ -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;
@@ -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;
}
diff --git a/src/global/funcs.h b/src/global/funcs.h
index 043201dd..1f338564 100644
--- a/src/global/funcs.h
+++ b/src/global/funcs.h
@@ -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)
diff --git a/src/inject_exec.c b/src/inject_exec.c
index 133cfc00..51a008c9 100644
--- a/src/inject_exec.c
+++ b/src/inject_exec.c
@@ -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)