From 71c3dbcb1195742b568298a06d3add08fce3185a Mon Sep 17 00:00:00 2001 From: isghj Date: Sat, 15 Nov 2025 21:57:04 -0800 Subject: [PATCH] Pr2: more docs, format --- .../actors/ovl_En_Encount1/z_en_encount1.c | 2 +- .../actors/ovl_En_Encount1/z_en_encount1.h | 2 +- src/overlays/actors/ovl_En_Pr2/z_en_pr2.c | 49 +++++++++---------- src/overlays/actors/ovl_En_Pr2/z_en_pr2.h | 16 +++--- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/overlays/actors/ovl_En_Encount1/z_en_encount1.c b/src/overlays/actors/ovl_En_Encount1/z_en_encount1.c index 16079531d1..5031473492 100644 --- a/src/overlays/actors/ovl_En_Encount1/z_en_encount1.c +++ b/src/overlays/actors/ovl_En_Encount1/z_en_encount1.c @@ -54,7 +54,7 @@ void EnEncount1_Init(Actor* thisx, PlayState* play) { this->spawnActiveMax = ENENCOUNT1_GET_SPAWN_ACTIVE_MAX(&this->actor); this->spawnTotalMax = ENENCOUNT1_GET_SPAWN_TOTAL_MAX(&this->actor); this->spawnTimeMin = ENENCOUNT1_GET_SPAWN_TIME_MIN(&this->actor); - this->spawnDropTable = ENENCOUNT1_GET_SPAWN_DROP_TABLE(&this->actor); + this->spawnDropTable = ENENCOUNT1_GET_SPAWN_DROP_ID(&this->actor); this->spawnDistanceMax = (ENENCOUNT1_GET_SPAWN_DISTANCE_MAX(&this->actor) * 40.0f) + 120.0f; if (this->spawnTotalMax >= ENENCOUNT1_SPAWNS_TOTAL_MAX_INFINITE) { diff --git a/src/overlays/actors/ovl_En_Encount1/z_en_encount1.h b/src/overlays/actors/ovl_En_Encount1/z_en_encount1.h index bff4fc084e..d60b271245 100644 --- a/src/overlays/actors/ovl_En_Encount1/z_en_encount1.h +++ b/src/overlays/actors/ovl_En_Encount1/z_en_encount1.h @@ -13,7 +13,7 @@ #define ENENCOUNT1_PATH_INDEX_NONE 0x3F #define ENENCOUNT1_GET_SPAWN_TIME_MIN(thisx) ((thisx)->world.rot.x) // Time to wait between spawning -#define ENENCOUNT1_GET_SPAWN_DROP_TABLE(thisx) ((thisx)->world.rot.y) // Read from EnPr2 +#define ENENCOUNT1_GET_SPAWN_DROP_ID(thisx) ((thisx)->world.rot.y) // Read from EnPr2, index to drop table array #define ENENCOUNT1_GET_SPAWN_DISTANCE_MAX(thisx) ((thisx)->world.rot.z) // Negative means infinite distance typedef enum EnEncount1Enemy { diff --git a/src/overlays/actors/ovl_En_Pr2/z_en_pr2.c b/src/overlays/actors/ovl_En_Pr2/z_en_pr2.c index 3c9a78e3f0..6bac6d442b 100644 --- a/src/overlays/actors/ovl_En_Pr2/z_en_pr2.c +++ b/src/overlays/actors/ovl_En_Pr2/z_en_pr2.c @@ -153,12 +153,12 @@ void EnPr2_Init(Actor* thisx, PlayState* play) { Actor* encount1 = this->actor.parent; if (encount1->update != NULL) { - if (ENPR2_GETY_PARENT_DROPID(encount1) != 0) { - this->dropID = ENPR2_GETY_PARENT_DROPID(encount1) - 1; + if (ENPR2_GETY_PARENT_DROP_ID(encount1) != 0) { + this->dropID = ENPR2_GETY_PARENT_DROP_ID(encount1) - 1; } } - } else if (ENPR2_GETZ_DROPID(thisx) != 0) { - this->dropID = ENPR2_GETZ_DROPID(thisx) - 1; + } else if (ENPR2_GETZ_DROP_ID(thisx) != 0) { + this->dropID = ENPR2_GETZ_DROP_ID(thisx) - 1; this->actor.world.rot.z = 0; } @@ -333,7 +333,7 @@ void EnPr2_FollowPath(EnPr2* this, PlayState* play) { void EnPr2_SetupIdle(EnPr2* this) { EnPr2_ChangeAnim(this, PR2_ANIM_SWIM); - this->waypointTimer = 2; + this->idleTimer = 2; this->mainTimer = 0; Math_Vec3f_Copy(&this->waypointPos, &this->newHome); this->state = PR2_STATE_IDLE; @@ -347,7 +347,7 @@ void EnPr2_Idle(EnPr2* this, PlayState* play) { f32 sqrtXZ; s32 changingCourse = false; s32 swimmingStraight = false; - Vec3f currentPos; // this describes where it starts, not what its doing, rename + Vec3f targetPos; Math_ApproachF(&this->scale, 0.02f, 0.1f, 0.005f); Actor_PlaySfx(&this->actor, NA_SE_EN_PIRANHA_EXIST - SFX_FLAG); @@ -371,7 +371,7 @@ void EnPr2_Idle(EnPr2* this, PlayState* play) { EnPr2_SetupAttack(this, play); } else if (!EnPr2_IsOnScreen(this, play) && (this->alpha == 255)) { // despawn if not on screen - this->alpha = 254; // triggers actor kill + this->alpha = 254; // triggers actor kill above } break; @@ -410,27 +410,27 @@ void EnPr2_Idle(EnPr2* this, PlayState* play) { // if we already plan to change behavior, ignore this expensive maintanence code if (!changingCourse) { this->waypointPos.y = this->actor.world.pos.y; - if (this->waypointTimer != 0) { + if (this->idleTimer != 0) { if ((Rand_ZeroOne() < 0.3f) && !this->bubbleToggle) { this->bubbleToggle = true; } Math_ApproachZeroF(&this->actor.speed, 0.1f, 0.2f); - if (this->waypointTimer == 1) { + if (this->idleTimer == 1) { this->mainTimer = Rand_S16Offset(100, 100); - Math_Vec3f_Copy(¤tPos, &this->newHome); - currentPos.x += Rand_CenteredFloat(300.0f); - currentPos.z += Rand_CenteredFloat(300.0f); - Math_Vec3f_Copy(&this->waypointPos, ¤tPos); + Math_Vec3f_Copy(&targetPos, &this->newHome); + targetPos.x += Rand_CenteredFloat(300.0f); + targetPos.z += Rand_CenteredFloat(300.0f); + Math_Vec3f_Copy(&this->waypointPos, &targetPos); } } else { Math_ApproachF(&this->actor.speed, 2.0f, 0.3f, 0.2f); - Math_Vec3f_Copy(¤tPos, &this->actor.world.pos); - currentPos.x += Math_SinS(this->actor.world.rot.y) * 20.0f; - currentPos.z += Math_CosS(this->actor.world.rot.y) * 20.0f; + Math_Vec3f_Copy(&targetPos, &this->actor.world.pos); + targetPos.x += Math_SinS(this->actor.world.rot.y) * 20.0f; + targetPos.z += Math_CosS(this->actor.world.rot.y) * 20.0f; if (fabsf(this->actor.world.rot.y - this->yawTowardsWaypoint) < 100.0f) { - if (BgCheck_SphVsFirstPoly(&play->colCtx, ¤tPos, 20.0f) || + if (BgCheck_SphVsFirstPoly(&play->colCtx, &targetPos, 20.0f) || (this->actor.bgCheckFlags & BGCHECKFLAG_WALL)) { this->targetingTimer = 0; this->wallCollisionCounter++; @@ -446,12 +446,12 @@ void EnPr2_Idle(EnPr2* this, PlayState* play) { if ((this->mainTimer == 0) || ((fabsf(this->waypointPos.x - this->actor.world.pos.x) < 10.0f) && (fabsf(this->waypointPos.z - this->actor.world.pos.z) < 10.0f))) { - this->waypointTimer = Rand_S16Offset(20, 30); + this->idleTimer = Rand_S16Offset(20, 30); } } } - if (this->waypointTimer == 0) { + if (this->idleTimer == 0) { this->yawTowardsWaypoint = Math_Vec3f_Yaw(&this->actor.world.pos, &this->waypointPos) + this->wallCollisionAngleAdjustment; EnPr2_HandleYaw(this, this->yawTowardsWaypoint); @@ -531,7 +531,7 @@ void EnPr2_Attack(EnPr2* this, PlayState* play) { if ((this->type == PR2_TYPE_SPAWNED) && !EnPr2_IsOnScreen(this, play)) { if (this->alpha == 255) { - this->alpha = 254; // triggers actor kill + this->alpha = 254; // triggers actor kill at top of this function } } else { if (this->collider.base.atFlags & AT_HIT) { @@ -586,7 +586,7 @@ void EnPr2_Die(EnPr2* this, PlayState* play) { curFrame = this->skelAnime.curFrame; - if (curFrame >= this->animEndFrame) { // death animation done + if (curFrame >= this->animEndFrame) { // spawn LIMB_COUNT EnPr2, one for each limb, to draw floating pieces for (i = 0; i < ARRAY_COUNT(this->limbPos); i++) { Actor_Spawn(&play->actorCtx, play, ACTOR_EN_PR2, this->limbPos[i].x, this->limbPos[i].y, @@ -660,7 +660,7 @@ void EnPr2_ApplyDamage(EnPr2* this, PlayState* play) { } } - // against mikau shild? + // against mikau shield? if (this->collider.base.atFlags & AT_BOUNCED) { this->actor.speed = -10.0f; } @@ -674,7 +674,7 @@ void EnPr2_Update(Actor* thisx, PlayState* play) { this->actionFunc(this, play); - DECR(this->waypointTimer); + DECR(this->idleTimer); DECR(this->mainTimer); DECR(this->targetingTimer); DECR(this->returnHomeTimer); @@ -721,7 +721,7 @@ s32 EnPr2_OverrideLimbDrawOpa(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f EnPr2* this = (EnPr2*)thisx; if (this->type < PR2_TYPE_BROKEN) { - if (limbIndex == OBJECT_PR_2_LIMB_02) { + if (limbIndex == OBJECT_PR_2_LIMB_02) { // jaw rot->y += TRUNCF_BINANG(this->slowLimbYaw) * -1; } } else if (this->type != limbIndex + PR2_TYPE_BROKEN) { @@ -743,7 +743,6 @@ void EnPr2_PostLimbDrawOpa(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* r Matrix_MultZero(&this->limbJawPos); } - // store current limbPos Matrix_MultZero(&this->limbPos[limbIndex]); } } diff --git a/src/overlays/actors/ovl_En_Pr2/z_en_pr2.h b/src/overlays/actors/ovl_En_Pr2/z_en_pr2.h index 02e755ff94..711dba2b19 100644 --- a/src/overlays/actors/ovl_En_Pr2/z_en_pr2.h +++ b/src/overlays/actors/ovl_En_Pr2/z_en_pr2.h @@ -16,9 +16,10 @@ typedef void (*EnPr2ActionFunc)(struct EnPr2*, PlayState*); #define ENPR2_GET_AGRO_DISTANCE(thisx) (((thisx)->params >> 4) & 0xFF) // only if we are NOT spawned by a parent actor -#define ENPR2_GETZ_DROPID(thisx) ((thisx)->world.rot.z) +// where dropID is an index to an array of droptables +#define ENPR2_GETZ_DROP_ID(thisx) ((thisx)->world.rot.z) // only if we are spawned by En_Encount1 -#define ENPR2_GETY_PARENT_DROPID(parent) ((parent)->world.rot.y) +#define ENPR2_GETY_PARENT_DROP_ID(parent) ((parent)->world.rot.y) // agro distance is 1/20th of final distance #define ENPR2_GETZ_PARENT_AGRO_DISTANCE(parent) ((parent)->world.rot.z) @@ -31,6 +32,7 @@ typedef enum EnPr2Type { /* 02 */ PR2_TYPE_RESIDENT, // regular spawn and remain in the world /* 03 */ PR2_TYPE_PATHING, // spawned by Encount1 in GBT so they swim out of a waterway // all types above 10 are limb based, for drawing the dead fish parts after being broken + // where each type is 10 + limb number /* 10 */ PR2_TYPE_BROKEN = 10 } EnPr2Type; @@ -53,7 +55,7 @@ typedef struct EnPr2 { /* 0x1D4 */ s16 state; /* 0x1D6 */ s16 bubbleToggle; /* 0x1D8 */ s16 mainTimer; - /* 0x1DA */ s16 waypointTimer; // path related, maybe rename + /* 0x1DA */ s16 idleTimer; // control some idle behaviors, like when to change directions /* 0x1DC */ s16 targetingTimer; // on zero, attack attempt on player /* 0x1DE */ s16 returnHomeTimer; // frames until attacking player acceptable again /* 0x1E0 */ s16 type; @@ -61,17 +63,17 @@ typedef struct EnPr2 { /* 0x1E4 */ s16 targetZRot; /* 0x1E6 */ s16 targetYRot; /* 0x1E8 */ UNK_TYPE1 unk1E8[4]; - /* 0x1EC */ s16 primColor; // r and g and b, all same var, think this is to force the actor black + /* 0x1EC */ s16 primColor; // r and g and b, all same var, set to all black on death /* 0x1EE */ s16 yawTowardsWaypoint; /* 0x1F0 */ s16 wallCollisionAngleAdjustment; /* 0x1F2 */ s16 wallCollisionCounter; /* 0x1F4 */ s16 alpha; /* 0x1F8 */ f32 animEndFrame; - /* 0x1FC */ f32 slowLimbYaw; // think this is related to swimming animation, for head turning + /* 0x1FC */ f32 slowLimbYaw; /* 0x200 */ f32 waterSurfaceHeight; /* 0x204 */ f32 scale; - /* 0x208 */ f32 agroDistance; // might be incorrect - /* 0x20C */ f32 randomTargetHeightOffset; // recheck name, might not be target + /* 0x208 */ f32 agroDistance; + /* 0x20C */ f32 randomTargetHeightOffset; // causes him to bob up and down as he attacks /* 0x210 */ s32 animIndex; /* 0x214 */ UNK_TYPE1 unk214[4]; /* 0x218 */ s32 dropID;