From 88ed3e7ff3b4879555093b6857b135553c1f1dc7 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 16 Feb 2026 23:41:28 -0500 Subject: [PATCH] Document pass on WaterBox code --- include/bgcheck.h | 35 +++-- src/code/z_actor.c | 4 +- src/code/z_bgcheck.c | 123 +++++++++++------- src/code/z_camera.c | 7 +- src/code/z_play.c | 4 +- .../actors/ovl_En_Bom_Chu/z_en_bom_chu.c | 4 +- src/overlays/actors/ovl_En_Fr/z_en_fr.c | 2 +- .../actors/ovl_En_Goroiwa/z_en_goroiwa.c | 2 +- src/overlays/actors/ovl_En_Horse/z_en_horse.c | 6 +- src/overlays/actors/ovl_En_Okuta/z_en_okuta.c | 5 +- src/overlays/actors/ovl_En_Tite/z_en_tite.c | 8 +- .../actors/ovl_En_Weiyer/z_en_weiyer.c | 2 +- .../actors/ovl_Obj_Syokudai/z_obj_syokudai.c | 2 +- .../actors/ovl_player_actor/z_player.c | 31 ++--- .../ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c | 2 +- .../z_eff_ss_g_ripple.c | 2 +- .../extase_oot64/collision_resources.py | 4 +- 17 files changed, 134 insertions(+), 109 deletions(-) diff --git a/include/bgcheck.h b/include/bgcheck.h index 13b85705822..9b6543d92cb 100644 --- a/include/bgcheck.h +++ b/include/bgcheck.h @@ -30,7 +30,6 @@ typedef struct ScaleRotPos { } ScaleRotPos; // size = 0x20 // Macros for `CollisionPoly` - #define COLPOLY_NORMAL_FRAC (1.0f / SHT_MAX) #define COLPOLY_SNORMAL(x) ((s16)((x) * SHT_MAX)) #define COLPOLY_GET_NORMAL(n) ((n)*COLPOLY_NORMAL_FRAC) @@ -39,14 +38,14 @@ typedef struct ScaleRotPos { #define COLPOLY_VTX_INDEX(vI) ((vI) & 0x1FFF) #define COLPOLY_VTX(vtxId, flags) ((((flags) & 7) << 13) | ((vtxId) & 0x1FFF)) -// flags for flags_vIA +// flags for variable flags_vIA // poly exclusion flags (xpFlags) #define COLPOLY_IGNORE_NONE 0 #define COLPOLY_IGNORE_CAMERA (1 << 0) #define COLPOLY_IGNORE_ENTITY (1 << 1) #define COLPOLY_IGNORE_PROJECTILES (1 << 2) -// flags for flags_vIB +// flags for variable flags_vIB #define COLPOLY_IS_FLOOR_CONVEYOR (1 << 0) typedef struct CollisionPoly { @@ -87,23 +86,23 @@ typedef struct BgCamFuncData { } BgCamFuncData; // size = 0x12 // Macros for `WaterBox.properties` +#define WATERBOX_PROPERTIES(bgCamIndex, lightIndex, roomIndex, isDisabled) \ + ((((bgCamIndex) & 0xFF) << 0) | \ + (((lightIndex) & 0x1F) << 8) | \ + (((roomIndex) & 0x3F) << 13) | \ + (((isDisabled) & 1) << 19)) -#define WATERBOX_LIGHT_INDEX_NONE 0x1F // warns and defaults to 0 - -#define WATERBOX_ROOM(properties) (((properties) >> 13) & 0x3F) +#define WATERBOX_LIGHT_INDEX_NONE 0x1F // Generates warning when built for debug and defaults to 0 +#define WATERBOX_ROOM(properties) (((properties) >> 13) & 0x3F) // retrieves the room the waterbox is active in #define WATERBOX_ROOM_ALL 0x3F // value for "room index" indicating "all rooms" -#define WATERBOX_FLAG_19 (1 << 19) - -#define WATERBOX_PROPERTIES(bgCamIndex, lightIndex, room, setFlag19) \ - ((((bgCamIndex) & 0xFF) << 0) | \ - (((lightIndex) & 0x1F) << 8) | \ - (((room) & 0x3F) << 13) | \ - (((setFlag19) & 1) << 19)) +/* The true purpose of the flag is unknown. The state is never enabled on any waterbox, and functions that + * pass on flag enabled are never called, so there is no direct usecase context. */ +#define WATERBOX_IS_DISABLED (1 << 19) // Disables waterbox collision typedef struct WaterBox { /* 0x00 */ s16 xMin; - /* 0x02 */ s16 ySurface; + /* 0x02 */ s16 ySurface; // Water is effectively infinitely deep. /* 0x04 */ s16 zMin; /* 0x06 */ s16 xLength; /* 0x08 */ s16 zLength; @@ -458,11 +457,11 @@ s32 SurfaceType_IsFloorConveyor(CollisionContext* colCtx, CollisionPoly* poly, s u32 SurfaceType_GetConveyorSpeed(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); u32 SurfaceType_GetConveyorDirection(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); u32 func_80042108(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); -s32 WaterBox_GetSurface1(struct PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, - WaterBox** outWaterBox); -s32 WaterBox_GetSurface2(struct PlayState* play, CollisionContext* colCtx, Vec3f* pos, f32 surfaceChkDist, +s32 BgCheck_GetWaterSurfaceAllHack(struct PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* y, + WaterBox** outWaterBox); +s32 BgCheck_FindWaterBox(struct PlayState* play, CollisionContext* colCtx, Vec3f* pos, f32 surfaceChkDist, WaterBox** outWaterBox); -s32 WaterBox_GetSurfaceImpl(struct PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, +s32 BgCheck_GetWaterSurface(struct PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* outWaterSurface, WaterBox** outWaterBox); u32 WaterBox_GetBgCamIndex(CollisionContext* colCtx, WaterBox* waterBox); u16 WaterBox_GetBgCamSetting(CollisionContext* colCtx, WaterBox* waterBox); diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 7501925080f..7439d252638 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1484,8 +1484,8 @@ void Actor_UpdateBgCheckInfo(PlayState* play, Actor* actor, f32 wallCheckHeight, sp64.y = actor->prevPos.y; func_8002E2AC(play, actor, &sp64, flags); waterBoxYSurface = actor->world.pos.y; - if (WaterBox_GetSurface1(play, &play->colCtx, actor->world.pos.x, actor->world.pos.z, &waterBoxYSurface, - &waterBox)) { + if (BgCheck_GetWaterSurfaceAllHack(play, &play->colCtx, actor->world.pos.x, actor->world.pos.z, + &waterBoxYSurface, &waterBox)) { actor->depthInWater = waterBoxYSurface - actor->world.pos.y; if (actor->depthInWater < 0.0f) { actor->bgCheckFlags &= ~(BGCHECKFLAG_WATER | BGCHECKFLAG_WATER_TOUCH); diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 656bb04b5ba..7831e241703 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -4247,7 +4247,14 @@ u32 func_80042108(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { /** * Zora's Domain WaterBox in King Zora's Room */ -WaterBox sZorasDomainWaterBox = { -348, 877, -1746, 553, 780, 0x2104 }; +WaterBox sZorasDomainWaterBox = { + -348, // xMin + 877, // ySurface + -1746, // zMin + 553, // xLength + 780, // zLength + WATERBOX_PROPERTIES(/* bgCamIndex */ 4, /* lightIndex */ 1, /* roomIndex */ 1, /* isDisabled */ false), +}; /** * WaterBox's effective bounding box @@ -4260,31 +4267,38 @@ f32 sZorasDomainWaterBoxMaxY = 977.0f; f32 sZorasDomainWaterBoxMaxZ = -967.0f; /** - * Public. Get the water surface at point (`x`, `ySurface`, `z`). `ySurface` doubles as position y input - * returns true if point is within the xz boundaries of an active water box, else false - * `ySurface` returns the water box's surface, while `outWaterBox` returns a pointer to the WaterBox + * Get the water surface at point (`x`, `y`, `z`). `y` doubles as `outWaterSurface` result + * returns true if point is within the xz boundaries of an active WaterBox, else false + * `y` returns the WaterBox's surface + * `outWaterBox` returns a pointer to the WaterBox + * + * This performs a special case check on a custom waterbox in Zora's Domain that has a finite depth + * Otherwise, the search performed assumes waterboxes cannot overlap, as water has effectively infinite depth */ -s32 WaterBox_GetSurface1(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, - WaterBox** outWaterBox) { +s32 BgCheck_GetWaterSurfaceAllHack(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* y, + WaterBox** outWaterBox) { if (play->sceneId == SCENE_ZORAS_DOMAIN) { s32 pad; - if (sZorasDomainWaterBoxMinX < x && x < sZorasDomainWaterBoxMaxX && sZorasDomainWaterBoxMinY < *ySurface && - *ySurface < sZorasDomainWaterBoxMaxY && sZorasDomainWaterBoxMinZ < z && z < sZorasDomainWaterBoxMaxZ) { + if (sZorasDomainWaterBoxMinX < x && x < sZorasDomainWaterBoxMaxX && sZorasDomainWaterBoxMinY < *y && + *y < sZorasDomainWaterBoxMaxY && sZorasDomainWaterBoxMinZ < z && z < sZorasDomainWaterBoxMaxZ) { *outWaterBox = &sZorasDomainWaterBox; - *ySurface = sZorasDomainWaterBox.ySurface; + *y = sZorasDomainWaterBox.ySurface; return true; } } - return WaterBox_GetSurfaceImpl(play, colCtx, x, z, ySurface, outWaterBox); + return BgCheck_GetWaterSurface(play, colCtx, x, z, y, outWaterBox); } /** - * Internal. Get the water surface at point (`x`, `ySurface`, `z`). `ySurface` doubles as position y input - * returns true if point is within the xz boundaries of an active water box, else false - * `ySurface` returns the water box's surface, while `outWaterBox` returns a pointer to the WaterBox + * Get the water surface at point (`x`, `z`). + * returns true if point is within the xz boundaries of an active WaterBox, else false + * `outWaterSurface` returns the WaterBox's surface + * `outWaterBox` returns a pointer to the WaterBox + * + * The search performed assumes waterboxes cannot overlap, as water has effectively infinite depth */ -s32 WaterBox_GetSurfaceImpl(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, +s32 BgCheck_GetWaterSurface(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* outWaterSurface, WaterBox** outWaterBox) { CollisionHeader* colHeader = colCtx->colHeader; s32 room; @@ -4296,15 +4310,18 @@ s32 WaterBox_GetSurfaceImpl(PlayState* play, CollisionContext* colCtx, f32 x, f3 for (waterBox = colHeader->waterBoxes; waterBox < colHeader->waterBoxes + colHeader->numWaterBoxes; waterBox++) { room = WATERBOX_ROOM(waterBox->properties); - if (room == play->roomCtx.curRoom.num || room == WATERBOX_ROOM_ALL) { - if (!(waterBox->properties & WATERBOX_FLAG_19)) { - if (waterBox->xMin < x && x < waterBox->xMin + waterBox->xLength) { - if (waterBox->zMin < z && z < waterBox->zMin + waterBox->zLength) { - *outWaterBox = waterBox; - *ySurface = waterBox->ySurface; - return true; - } - } + if (room != play->roomCtx.curRoom.num && room != WATERBOX_ROOM_ALL) { + continue; + } + if (waterBox->properties & WATERBOX_IS_DISABLED) { + continue; + } + //! @bug: WaterBox bounds check issue. + if (waterBox->xMin < x && x < waterBox->xMin + waterBox->xLength) { + if (waterBox->zMin < z && z < waterBox->zMin + waterBox->zLength) { + *outWaterBox = waterBox; + *outWaterSurface = waterBox->ySurface; + return true; } } } @@ -4312,12 +4329,12 @@ s32 WaterBox_GetSurfaceImpl(PlayState* play, CollisionContext* colCtx, f32 x, f3 } /** - * Gets the first active WaterBox at `pos` with WATERBOX_FLAG_19 not set + * Gets the first active WaterBox at `pos`, within +- `surfaceChkDist` * `surfaceChkDist` is the absolute y distance from the water surface to check * returns the index of the waterbox found, or -1 if no waterbox is found * `outWaterBox` returns the pointer to the waterbox found, or NULL if none is found */ -s32 WaterBox_GetSurface2(PlayState* play, CollisionContext* colCtx, Vec3f* pos, f32 surfaceChkDist, +s32 BgCheck_FindWaterBox(PlayState* play, CollisionContext* colCtx, Vec3f* pos, f32 surfaceChkDist, WaterBox** outWaterBox) { CollisionHeader* colHeader = colCtx->colHeader; s32 room; @@ -4334,16 +4351,18 @@ s32 WaterBox_GetSurface2(PlayState* play, CollisionContext* colCtx, Vec3f* pos, waterBox = &colHeader->waterBoxes[i]; room = WATERBOX_ROOM(waterBox->properties); - if (room == play->roomCtx.curRoom.num || room == WATERBOX_ROOM_ALL) { - if (!(waterBox->properties & WATERBOX_FLAG_19)) { - if (waterBox->xMin < pos->x && pos->x < waterBox->xMin + waterBox->xLength) { - if (waterBox->zMin < pos->z && pos->z < waterBox->zMin + waterBox->zLength) { - if (pos->y - surfaceChkDist < waterBox->ySurface && - waterBox->ySurface < pos->y + surfaceChkDist) { - *outWaterBox = waterBox; - return i; - } - } + if (room != play->roomCtx.curRoom.num && room != WATERBOX_ROOM_ALL) { + continue; + } + if (waterBox->properties & WATERBOX_IS_DISABLED) { + continue; + } + //! @bug: WaterBox bounds check issue. See BgCheck_GetWaterSurface for more details. + if ((waterBox->xMin < pos->x) && (pos->x < waterBox->xMin + waterBox->xLength)) { + if ((waterBox->zMin < pos->z) && (pos->z < waterBox->zMin + waterBox->zLength)) { + if (pos->y - surfaceChkDist < waterBox->ySurface && waterBox->ySurface < pos->y + surfaceChkDist) { + *outWaterBox = waterBox; + return i; } } } @@ -4386,12 +4405,15 @@ u32 WaterBox_GetLightIndex(CollisionContext* colCtx, WaterBox* waterBox) { } /** - * Get the water surface at point (`x`, `ySurface`, `z`). `ySurface` doubles as position y input - * same as WaterBox_GetSurfaceImpl, but tests if WATERBOX_FLAG_19 is set - * returns true if point is within the xz boundaries of an active water box, else false - * `ySurface` returns the water box's surface, while `outWaterBox` returns a pointer to the WaterBox + * Unused. Gets the water surface? at point (`x`, `z`) for disabled? waterboxes only. + * returns true if point is within the xz boundaries of a disabled? WaterBox, else false + * `outWaterSurface` returns the WaterBox's surface + * `outWaterBox` returns a pointer to the WaterBox + * + * The search performed assumes waterboxes cannot overlap */ -s32 func_800425B0(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface, WaterBox** outWaterBox) { +s32 func_800425B0(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* outWaterSurface, + WaterBox** outWaterBox) { CollisionHeader* colHeader = colCtx->colHeader; s32 room; WaterBox* waterBox; @@ -4402,15 +4424,18 @@ s32 func_800425B0(PlayState* play, CollisionContext* colCtx, f32 x, f32 z, f32* for (waterBox = colHeader->waterBoxes; waterBox < colHeader->waterBoxes + colHeader->numWaterBoxes; waterBox++) { room = WATERBOX_ROOM(waterBox->properties); - if ((room == play->roomCtx.curRoom.num) || (room == WATERBOX_ROOM_ALL)) { - if (waterBox->properties & WATERBOX_FLAG_19) { - if (waterBox->xMin < x && x < (waterBox->xMin + waterBox->xLength)) { - if (waterBox->zMin < z && z < (waterBox->zMin + waterBox->zLength)) { - *outWaterBox = waterBox; - *ySurface = waterBox->ySurface; - return true; - } - } + if ((room != play->roomCtx.curRoom.num) && (room != WATERBOX_ROOM_ALL)) { + continue; + } + if (!(waterBox->properties & WATERBOX_IS_DISABLED)) { + continue; + } + //! @bug: WaterBox bounds check issue. See BgCheck_GetWaterSurface for more details. + if (waterBox->xMin < x && x < (waterBox->xMin + waterBox->xLength)) { + if (waterBox->zMin < z && z < (waterBox->zMin + waterBox->zLength)) { + *outWaterBox = waterBox; + *outWaterSurface = waterBox->ySurface; + return true; } } } diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 803a89400fb..f7921a57ef8 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -685,8 +685,8 @@ s32 Camera_GetWaterBoxBgCamIndex(Camera* camera, f32* waterY) { playerPosRot = Actor_GetWorldPosShapeRot(&camera->player->actor); *waterY = playerPosRot.pos.y; - if (!WaterBox_GetSurface1(camera->play, &camera->play->colCtx, playerPosRot.pos.x, playerPosRot.pos.z, waterY, - &waterBox)) { + if (!BgCheck_GetWaterSurfaceAllHack(camera->play, &camera->play->colCtx, playerPosRot.pos.x, playerPosRot.pos.z, + waterY, &waterBox)) { // player's position is not within the x/z boundaries of a water box. *waterY = BGCHECK_Y_MIN; return -1; @@ -722,7 +722,8 @@ f32 Camera_GetWaterSurface(Camera* camera, Vec3f* chkPos, s32* lightIndex) { playerPosRot = Actor_GetWorldPosShapeRot(&camera->player->actor); waterY = playerPosRot.pos.y; - if (!WaterBox_GetSurface1(camera->play, &camera->play->colCtx, chkPos->x, chkPos->z, &waterY, &waterBox)) { + if (!BgCheck_GetWaterSurfaceAllHack(camera->play, &camera->play->colCtx, chkPos->x, chkPos->z, &waterY, + &waterBox)) { // chkPos is not within the x/z boundaries of a water box. return BGCHECK_Y_MIN; } diff --git a/src/code/z_play.c b/src/code/z_play.c index 8d73e9e5658..ee70318def7 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -1974,8 +1974,8 @@ s32 func_800C0DB4(PlayState* this, Vec3f* pos) { waterSurfacePos = *pos; - if (WaterBox_GetSurface1(this, &this->colCtx, waterSurfacePos.x, waterSurfacePos.z, &waterSurfacePos.y, - &waterBox) == true && + if (BgCheck_GetWaterSurfaceAllHack(this, &this->colCtx, waterSurfacePos.x, waterSurfacePos.z, &waterSurfacePos.y, + &waterBox) == true && pos->y < waterSurfacePos.y && BgCheck_EntityRaycastDown3(&this->colCtx, &poly, &bgId, &waterSurfacePos) != BGCHECK_Y_MIN) { return true; diff --git a/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c b/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c index 8467c4e5a66..abaa141aaae 100644 --- a/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c +++ b/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c @@ -465,8 +465,8 @@ void EnBomChu_Update(Actor* thisx, PlayState* play2) { waterY = this->actor.world.pos.y; - if (WaterBox_GetSurface1(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &waterY, - &waterBox)) { + if (BgCheck_GetWaterSurfaceAllHack(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + &waterY, &waterBox)) { this->actor.depthInWater = waterY - this->actor.world.pos.y; if (this->actor.depthInWater < 0.0f) { diff --git a/src/overlays/actors/ovl_En_Fr/z_en_fr.c b/src/overlays/actors/ovl_En_Fr/z_en_fr.c index 17889ad5680..b413f39078c 100644 --- a/src/overlays/actors/ovl_En_Fr/z_en_fr.c +++ b/src/overlays/actors/ovl_En_Fr/z_en_fr.c @@ -360,7 +360,7 @@ void EnFr_IsDivingIntoWater(EnFr* this, PlayState* play) { WaterBox* waterBox; f32 waterSurface; - if (WaterBox_GetSurfaceImpl(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &waterSurface, + if (BgCheck_GetWaterSurface(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &waterSurface, &waterBox)) { this->isBelowWaterSurfacePrevious = this->isBelowWaterSurfaceCurrent; this->isBelowWaterSurfaceCurrent = this->actor.world.pos.y <= waterSurface ? true : false; diff --git a/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c b/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c index 7d587313653..94e6dad0355 100644 --- a/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c +++ b/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c @@ -436,7 +436,7 @@ s32 EnGoroiwa_MoveDownToNextWaypoint(EnGoroiwa* this, PlayState* play) { this->actor.world.pos.y = nextPointY - ((this->actor.world.pos.y - nextPointY) * 0.3f); } if (this->bounceCount == 0 && - WaterBox_GetSurfaceImpl(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &ySurface, + BgCheck_GetWaterSurface(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &ySurface, &waterBox) && this->actor.world.pos.y <= ySurface) { this->stateFlags |= ENGOROIWA_IN_WATER; diff --git a/src/overlays/actors/ovl_En_Horse/z_en_horse.c b/src/overlays/actors/ovl_En_Horse/z_en_horse.c index 4dbf4ada35f..af09e9cb389 100644 --- a/src/overlays/actors/ovl_En_Horse/z_en_horse.c +++ b/src/overlays/actors/ovl_En_Horse/z_en_horse.c @@ -2853,7 +2853,7 @@ s32 EnHorse_CalcFloorHeight(EnHorse* this, PlayState* play, Vec3f* pos, Collisio return 1; // No floor } - if (WaterBox_GetSurfaceImpl(play, &play->colCtx, pos->x, pos->z, &waterY, &waterBox) == 1 && + if (BgCheck_GetWaterSurface(play, &play->colCtx, pos->x, pos->z, &waterY, &waterBox) == true && *floorHeight < waterY) { return 2; // Water } @@ -2922,8 +2922,8 @@ void EnHorse_CheckFloors(EnHorse* this, PlayState* play) { WaterBox* waterBox; s32 pad; - if (WaterBox_GetSurfaceImpl(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &waterHeight, - &waterBox) == 1 && + if (BgCheck_GetWaterSurface(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &waterHeight, + &waterBox) == true && this->actor.floorHeight < waterHeight) { EnHorse_ObstructMovement(this, play, 1, galloping); return; diff --git a/src/overlays/actors/ovl_En_Okuta/z_en_okuta.c b/src/overlays/actors/ovl_En_Okuta/z_en_okuta.c index b8cd31b2ce1..0ad0aca6c69 100644 --- a/src/overlays/actors/ovl_En_Okuta/z_en_okuta.c +++ b/src/overlays/actors/ovl_En_Okuta/z_en_okuta.c @@ -148,8 +148,7 @@ void EnOkuta_Init(Actor* thisx, PlayState* play) { } thisx->floorHeight = BgCheck_EntityRaycastDown4(&play->colCtx, &thisx->floorPoly, &floorBgId, thisx, &thisx->world.pos); - //! @bug calls WaterBox_GetSurfaceImpl directly - if (!WaterBox_GetSurfaceImpl(play, &play->colCtx, thisx->world.pos.x, thisx->world.pos.z, &ySurface, + if (!BgCheck_GetWaterSurface(play, &play->colCtx, thisx->world.pos.x, thisx->world.pos.z, &ySurface, &outWaterBox) || (ySurface <= thisx->floorHeight)) { Actor_Kill(thisx); @@ -595,7 +594,7 @@ void EnOkuta_Update(Actor* thisx, PlayState* play2) { if (!(player->stateFlags1 & (PLAYER_STATE1_TALKING | PLAYER_STATE1_DEAD | PLAYER_STATE1_28 | PLAYER_STATE1_29))) { if (this->actor.params == 0) { EnOkuta_ColliderCheck(this, play); - if (!WaterBox_GetSurfaceImpl(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + if (!BgCheck_GetWaterSurface(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &ySurface, &outWaterBox) || (ySurface < this->actor.floorHeight)) { if (this->actor.colChkInfo.health != 0) { diff --git a/src/overlays/actors/ovl_En_Tite/z_en_tite.c b/src/overlays/actors/ovl_En_Tite/z_en_tite.c index 08fad96d3cf..20842395d33 100644 --- a/src/overlays/actors/ovl_En_Tite/z_en_tite.c +++ b/src/overlays/actors/ovl_En_Tite/z_en_tite.c @@ -925,28 +925,28 @@ void EnTite_Update(Actor* thisx, PlayState* play) { if ((this->actor.params == TEKTITE_BLUE) && (thisx->bgCheckFlags & BGCHECKFLAG_WATER)) { floorPoly = thisx->floorPoly; if ((((play->gameplayFrames % 8) == 0) || (thisx->velocity.y < 0.0f)) && - (WaterBox_GetSurfaceImpl(play, &play->colCtx, this->backRightFootPos.x, this->backRightFootPos.z, + (BgCheck_GetWaterSurface(play, &play->colCtx, this->backRightFootPos.x, this->backRightFootPos.z, &waterSurfaceY, &waterBox)) && (this->backRightFootPos.y <= waterSurfaceY)) { this->backRightFootPos.y = waterSurfaceY; EffectSsGRipple_Spawn(play, &this->backRightFootPos, 0, 220, 0); } if (((((play->gameplayFrames + 2) % 8) == 0) || (thisx->velocity.y < 0.0f)) && - (WaterBox_GetSurfaceImpl(play, &play->colCtx, this->backLeftFootPos.x, this->backLeftFootPos.z, + (BgCheck_GetWaterSurface(play, &play->colCtx, this->backLeftFootPos.x, this->backLeftFootPos.z, &waterSurfaceY, &waterBox)) && (this->backLeftFootPos.y <= waterSurfaceY)) { this->backLeftFootPos.y = waterSurfaceY; EffectSsGRipple_Spawn(play, &this->backLeftFootPos, 0, 220, 0); } if (((((play->gameplayFrames + 4) % 8) == 0) || (thisx->velocity.y < 0.0f)) && - (WaterBox_GetSurfaceImpl(play, &play->colCtx, this->frontLeftFootPos.x, this->frontLeftFootPos.z, + (BgCheck_GetWaterSurface(play, &play->colCtx, this->frontLeftFootPos.x, this->frontLeftFootPos.z, &waterSurfaceY, &waterBox)) && (this->frontLeftFootPos.y <= waterSurfaceY)) { this->frontLeftFootPos.y = waterSurfaceY; EffectSsGRipple_Spawn(play, &this->frontLeftFootPos, 0, 220, 0); } if (((((play->gameplayFrames + 1) % 8) == 0) || (thisx->velocity.y < 0.0f)) && - (WaterBox_GetSurfaceImpl(play, &play->colCtx, this->frontRightFootPos.x, this->frontRightFootPos.z, + (BgCheck_GetWaterSurface(play, &play->colCtx, this->frontRightFootPos.x, this->frontRightFootPos.z, &waterSurfaceY, &waterBox)) && (this->frontRightFootPos.y <= waterSurfaceY)) { this->frontRightFootPos.y = waterSurfaceY; diff --git a/src/overlays/actors/ovl_En_Weiyer/z_en_weiyer.c b/src/overlays/actors/ovl_En_Weiyer/z_en_weiyer.c index 919eb6bd75d..3f076adf973 100644 --- a/src/overlays/actors/ovl_En_Weiyer/z_en_weiyer.c +++ b/src/overlays/actors/ovl_En_Weiyer/z_en_weiyer.c @@ -232,7 +232,7 @@ void func_80B32804(EnWeiyer* this, PlayState* play) { this->actor.floorHeight = BgCheck_EntityRaycastDown4(&play->colCtx, &this->actor.floorPoly, &bgId, &this->actor, &this->actor.world.pos); - if (!WaterBox_GetSurfaceImpl(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, + if (!BgCheck_GetWaterSurface(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &this->actor.home.pos.y, &waterBox) || ((this->actor.home.pos.y - 5.0f) <= this->actor.floorHeight)) { Actor_Kill(&this->actor); diff --git a/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c b/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c index a75c504b6f5..a8cff036db2 100644 --- a/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c +++ b/src/overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.c @@ -152,7 +152,7 @@ void ObjSyokudai_Update(Actor* thisx, PlayState* play2) { if (torchCount == 10) { torchCount = 24; } - if (WaterBox_GetSurfaceImpl(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &waterSurface, + if (BgCheck_GetWaterSurface(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &waterSurface, &dummy) && ((waterSurface - this->actor.world.pos.y) > 52.0f)) { this->litTimer = 0; diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index 0fe5048f20a..e226595ab97 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -5821,10 +5821,10 @@ void func_8083AA10(Player* this, PlayState* play) { s32 sp5C; CollisionPoly* sp58; s32 sp54; - WaterBox* sp50; + WaterBox* waterBox; Vec3f sp44; f32 sp40; - f32 sp3C; + f32 waterSurfaceY; this->fallDistance = this->fallStartHeight - (s32)this->actor.world.pos.y; @@ -5869,10 +5869,11 @@ void func_8083AA10(Player* this, PlayState* play) { !(this->stateFlags1 & PLAYER_STATE1_CARRYING_ACTOR)) { sp40 = func_808396F4(play, this, &D_8085451C, &sp44, &sp58, &sp54); - sp3C = this->actor.world.pos.y; + waterSurfaceY = this->actor.world.pos.y; - if (WaterBox_GetSurface1(play, &play->colCtx, sp44.x, sp44.z, &sp3C, &sp50) && - ((sp3C - sp40) > 50.0f)) { + if (BgCheck_GetWaterSurfaceAllHack(play, &play->colCtx, sp44.x, sp44.z, &waterSurfaceY, + &waterBox) && + ((waterSurfaceY - sp40) > 50.0f)) { func_808389E8(this, &gPlayerAnim_link_normal_run_jump_water_fall, 6.0f, play); Player_SetupAction(play, this, Player_Action_80844A44, 0); return; @@ -6679,12 +6680,12 @@ void func_8083C8DC(Player* this, PlayState* play, s16 arg2) { } s32 Player_SetStartingMovement(PlayState* play, Player* this, f32 arg2) { - WaterBox* sp2C; + WaterBox* waterBox; f32 sp28; sp28 = this->actor.world.pos.y; - if (WaterBox_GetSurface1(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &sp28, &sp2C) != - 0) { + if (BgCheck_GetWaterSurfaceAllHack(play, &play->colCtx, this->actor.world.pos.x, this->actor.world.pos.z, &sp28, + &waterBox)) { sp28 -= this->actor.world.pos.y; if (this->ageProperties->unk_24 <= sp28) { Player_SetupAction(play, this, Player_Action_8084D7C4, 0); @@ -6815,24 +6816,24 @@ void func_8083CF5C(Player* this, PlayState* play) { s32 func_8083CFA8(PlayState* play, Player* this, f32 arg2, s32 splashScale) { f32 sp3C = fabsf(arg2); - WaterBox* sp38; - f32 sp34; + WaterBox* waterBox; + f32 waterSurfaceY; Vec3f splashPos; s32 splashType; if (sp3C > 2.0f) { splashPos.x = this->bodyPartsPos[PLAYER_BODYPART_WAIST].x; splashPos.z = this->bodyPartsPos[PLAYER_BODYPART_WAIST].z; - sp34 = this->actor.world.pos.y; - if (WaterBox_GetSurface1(play, &play->colCtx, splashPos.x, splashPos.z, &sp34, &sp38)) { + waterSurfaceY = this->actor.world.pos.y; + if (BgCheck_GetWaterSurfaceAllHack(play, &play->colCtx, splashPos.x, splashPos.z, &waterSurfaceY, &waterBox)) { #if OOT_VERSION < PAL_1_0 - if ((sp34 - this->actor.world.pos.y) < 80.0f) + if ((waterSurfaceY - this->actor.world.pos.y) < 80.0f) #else - if ((sp34 - this->actor.world.pos.y) < 100.0f) + if ((waterSurfaceY - this->actor.world.pos.y) < 100.0f) #endif { splashType = (sp3C <= 10.0f) ? 0 : 1; - splashPos.y = sp34; + splashPos.y = waterSurfaceY; EffectSsGSplash_Spawn(play, &splashPos, NULL, NULL, splashType, splashScale); return 1; } diff --git a/src/overlays/effects/ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c b/src/overlays/effects/ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c index 49f3ace0c18..3ba6aa03862 100644 --- a/src/overlays/effects/ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c +++ b/src/overlays/effects/ovl_Effect_Ss_Bubble/z_eff_ss_bubble.c @@ -70,7 +70,7 @@ void EffectSsBubble_Update(PlayState* play, u32 index, EffectSs* this) { f32 waterSurfaceY = this->pos.y; // kill bubble if it's out of range of a water box - if (!WaterBox_GetSurface1(play, &play->colCtx, this->pos.x, this->pos.z, &waterSurfaceY, &waterBox)) { + if (!BgCheck_GetWaterSurfaceAllHack(play, &play->colCtx, this->pos.x, this->pos.z, &waterSurfaceY, &waterBox)) { this->life = -1; return; } diff --git a/src/overlays/effects/ovl_Effect_Ss_G_Ripple/z_eff_ss_g_ripple.c b/src/overlays/effects/ovl_Effect_Ss_G_Ripple/z_eff_ss_g_ripple.c index ef0565c8f81..9ae7c395ad3 100644 --- a/src/overlays/effects/ovl_Effect_Ss_G_Ripple/z_eff_ss_g_ripple.c +++ b/src/overlays/effects/ovl_Effect_Ss_G_Ripple/z_eff_ss_g_ripple.c @@ -63,7 +63,7 @@ u32 EffectSsGRipple_Init(PlayState* play, u32 index, EffectSs* this, void* initP this->rEnvColorG = 255; this->rEnvColorB = 255; this->rEnvColorA = 255; - this->rWaterBoxNum = WaterBox_GetSurface2(play, &play->colCtx, &initParams->pos, 3.0f, &waterBox); + this->rWaterBoxNum = BgCheck_FindWaterBox(play, &play->colCtx, &initParams->pos, 3.0f, &waterBox); return 1; } diff --git a/tools/assets/extract/extase_oot64/collision_resources.py b/tools/assets/extract/extase_oot64/collision_resources.py index d8005ba446b..1a261cd33c0 100644 --- a/tools/assets/extract/extase_oot64/collision_resources.py +++ b/tools/assets/extract/extase_oot64/collision_resources.py @@ -441,8 +441,8 @@ def write_properties(v): bgCamIndex = (v >> 0) & 0xFF lightIndex = (v >> 8) & 0x1F room = (v >> 13) & 0x3F - setFlag19 = (v >> 19) & 1 - return f"WATERBOX_PROPERTIES(/* bgCamIndex */ {bgCamIndex}, /* lightIndex */ {lightIndex}, /* room */ {room}, /* setFlag19 */ {'true' if setFlag19 else 'false'})" + isDisabled = (v >> 19) & 1 + return f"WATERBOX_PROPERTIES(/* bgCamIndex */ {bgCamIndex}, /* lightIndex */ {lightIndex}, /* room */ {room}, /* isDisabled */ {'true' if isDisabled else 'false'})" elem_cdata_ext = CDataExt_Struct( (