1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-06 06:10:21 +00:00

EnWood02 OK (#578)

* OK, some documentation

* delete asm

* dists updated

* addressed review comments

* one more comment

* remove one comment

* addressed review comments
This commit is contained in:
EllipticEllipsis 2021-01-14 17:58:17 +00:00 committed by GitHub
parent d8f146519c
commit 3e5f6b3485
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 440 additions and 1229 deletions

View file

@ -1,7 +1,7 @@
/*
* File: z_en_wood02.c
* Overlay: ovl_En_Wood02
* Description: Trees & Bushes
* Description: Trees, bushes, leaves
*/
#include "z_en_wood02.h"
@ -15,9 +15,25 @@ void EnWood02_Destroy(Actor* thisx, GlobalContext* globalCtx);
void EnWood02_Update(Actor* thisx, GlobalContext* globalCtx);
void EnWood02_Draw(Actor* thisx, GlobalContext* globalCtx);
extern UNK_TYPE D_06000700;
/**
* WOOD_SPAWN_SPAWNER is also used by some individual trees: EnWood02_Update also checks for parent before running any
* despawning code.
* */
typedef enum {
/* 0 */ WOOD_SPAWN_NORMAL,
/* 1 */ WOOD_SPAWN_SPAWNED,
/* 2 */ WOOD_SPAWN_SPAWNER
} WoodSpawnType;
typedef enum {
/* 0 */ WOOD_DRAW_TREE_CONICAL,
/* 1 */ WOOD_DRAW_TREE_OVAL,
/* 2 */ WOOD_DRAW_TREE_KAKARIKO_ADULT,
/* 3 */ WOOD_DRAW_BUSH_GREEN,
/* 4 */ WOOD_DRAW_4, // Used for black bushes and green leaves
/* 5 */ WOOD_DRAW_LEAF_YELLOW
} WoodDrawType;
/*
const ActorInit En_Wood02_InitVars = {
ACTOR_EN_WOOD02,
ACTORTYPE_PROP,
@ -29,15 +45,393 @@ const ActorInit En_Wood02_InitVars = {
(ActorFunc)EnWood02_Update,
(ActorFunc)EnWood02_Draw,
};
*/
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Wood02/func_80B3AF70.s")
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Wood02/func_80B3B094.s")
static ColliderCylinderInit sCylinderInit = {
{ COLTYPE_UNK13, 0x00, 0x0D, 0x39, 0x10, COLSHAPE_CYLINDER },
{ 0x05, { 0x00000000, 0x00, 0x00 }, { 0x0FC0074A, 0x00, 0x00 }, 0x00, 0x01, 0x01 },
{ 18, 60, 0, { 0, 0, 0 } },
};
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Wood02/EnWood02_Init.s")
static f32 sSpawnDistance[] = { 707.0f, 525.0f, 510.0f, 500.0f, 566.0f, 141.0f };
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Wood02/EnWood02_Destroy.s")
static s16 sSpawnAngle[] = { 0x1FFF, 0x4C9E, 0x77F5, 0xA5C9, 0xD6C3, 0xA000 };
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Wood02/EnWood02_Update.s")
static InitChainEntry sInitChain[] = {
ICHAIN_F32(unk_4C, 5600, ICHAIN_STOP),
};
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Wood02/EnWood02_Draw.s")
static Gfx* D_80B3BF54[] = {
0x060078D0, 0x06007CA0, 0x060080D0, 0x06000090, 0x06000340, 0x06000340, 0x06000700,
};
static Gfx* D_80B3BF70[] = {
0x06007968, 0x06007D38, 0x060081A8, NULL, NULL, NULL,
0x06007AD0, 0x06007E20, 0x06008350, 0x06000160, 0x06000440, 0x06000700,
};
static f32 sSpawnCos;
static f32 sSpawnSin;
extern Gfx D_06000700[];
s32 EnWood02_SpawnZoneCheck(EnWood02* this, GlobalContext* globalCtx, Vec3f* pos) {
f32 phi_f12;
SkinMatrix_Vec3fMtxFMultXYZW(&globalCtx->mf_11D60, pos, &this->actor.projectedPos, &this->actor.projectedW);
phi_f12 = ((this->actor.projectedW == 0.0f) ? 1000.0f : fabsf(1.0f / this->actor.projectedW));
if ((-this->actor.uncullZoneScale < this->actor.projectedPos.z) &&
(this->actor.projectedPos.z < (this->actor.uncullZoneForward + this->actor.uncullZoneScale)) &&
(((fabsf(this->actor.projectedPos.x) - this->actor.uncullZoneScale) * phi_f12) < 1.0f) &&
(((this->actor.projectedPos.y + this->actor.uncullZoneDownward) * phi_f12) > -1.0f) &&
(((this->actor.projectedPos.y - this->actor.uncullZoneScale) * phi_f12) < 1.0f)) {
return true;
}
return false;
}
/** Spawns similar-looking trees or bushes only when the player is sufficiently close. Presumably done this way to keep
* memory usage down in Hyrule Field. */
void EnWood02_SpawnOffspring(EnWood02* this, GlobalContext* globalCtx) {
EnWood02* childWood;
s16* childSpawnAngle;
Vec3f childPos;
s16 extraRot;
s16 childParams;
s32 i;
for (i = 4; i >= 0; i--) {
if ((this->unk_14E[i] & 0x7F) == 0) {
extraRot = 0;
if (this->actor.params == WOOD_BUSH_GREEN_LARGE_SPAWNER) {
extraRot = 0x4000;
}
childSpawnAngle = &sSpawnAngle[i];
sSpawnCos = Math_CosS(*childSpawnAngle + this->actor.posRot.rot.y + extraRot);
sSpawnSin = Math_SinS(*childSpawnAngle + this->actor.posRot.rot.y + extraRot);
childPos.x = (sSpawnDistance[i] * sSpawnSin) + this->actor.initPosRot.pos.x;
childPos.y = this->actor.initPosRot.pos.y;
childPos.z = (sSpawnDistance[i] * sSpawnCos) + this->actor.initPosRot.pos.z;
if (EnWood02_SpawnZoneCheck(this, globalCtx, &childPos)) {
if ((this->unk_14E[i] & 0x80) != 0) {
childParams = (0xFF00 | (this->actor.params + 1));
} else {
childParams = (((this->drawType & 0xF0) << 4) | (this->actor.params + 1));
}
childWood = (EnWood02*)Actor_SpawnAsChild(&globalCtx->actorCtx, &this->actor, globalCtx,
ACTOR_EN_WOOD02, childPos.x, childPos.y, childPos.z,
this->actor.posRot.rot.x, *childSpawnAngle, 0, childParams);
if (childWood != NULL) {
childWood->unk_14E[0] = i;
this->unk_14E[i] |= 1;
childWood->actor.projectedPos = this->actor.projectedPos;
} else {
this->unk_14E[i] &= 0x80;
}
}
}
}
}
void EnWood02_Init(Actor* thisx, GlobalContext* globalCtx2) {
s16 spawnType;
f32 actorScale;
GlobalContext* globalCtx = globalCtx2;
EnWood02* this = THIS;
CollisionPoly* outPoly;
s32 bgId;
f32 floorY;
s16 extraRot;
spawnType = WOOD_SPAWN_NORMAL;
actorScale = 1.0f;
this->unk_14C = (this->actor.params >> 8) & 0xFF;
if (this->actor.initPosRot.rot.z != 0) {
this->actor.initPosRot.rot.z = (this->actor.initPosRot.rot.z << 8) | this->unk_14C;
this->unk_14C = -1;
this->actor.posRot.rot.z = this->actor.shape.rot.z = 0;
} else if (this->unk_14C & 0x80) {
this->unk_14C = -1;
}
this->actor.params &= 0xFF;
Actor_ProcessInitChain(&this->actor, sInitChain);
if (this->actor.params <= WOOD_TREE_KAKARIKO_ADULT) {
Collider_InitCylinder(globalCtx, &this->collider);
Collider_SetCylinder(globalCtx, &this->collider, &this->actor, &sCylinderInit);
}
switch (this->actor.params) {
case WOOD_BUSH_GREEN_LARGE_SPAWNER:
case WOOD_BUSH_BLACK_LARGE_SPAWNER:
spawnType = 1;
case WOOD_BUSH_GREEN_LARGE_SPAWNED:
case WOOD_BUSH_BLACK_LARGE_SPAWNED:
spawnType++;
case WOOD_TREE_CONICAL_LARGE:
case WOOD_BUSH_GREEN_LARGE:
case WOOD_BUSH_BLACK_LARGE:
actorScale = 1.5f;
this->actor.uncullZoneForward = 4000.0f;
this->actor.uncullZoneScale = 2000.0f;
this->actor.uncullZoneDownward = 2400.0f;
break;
case WOOD_TREE_CONICAL_SPAWNER:
case WOOD_TREE_OVAL_YELLOW_SPAWNER:
case WOOD_TREE_OVAL_GREEN_SPAWNER:
case WOOD_BUSH_GREEN_SMALL_SPAWNER:
case WOOD_BUSH_BLACK_SMALL_SPAWNER:
spawnType = 1;
case WOOD_TREE_CONICAL_SPAWNED:
case WOOD_TREE_OVAL_YELLOW_SPAWNED:
case WOOD_TREE_OVAL_GREEN_SPAWNED:
case WOOD_BUSH_GREEN_SMALL_SPAWNED:
case WOOD_BUSH_BLACK_SMALL_SPAWNED:
spawnType++;
case WOOD_TREE_CONICAL_MEDIUM:
case WOOD_TREE_OVAL_GREEN:
case WOOD_TREE_KAKARIKO_ADULT:
case WOOD_BUSH_GREEN_SMALL:
case WOOD_BUSH_BLACK_SMALL:
this->actor.uncullZoneForward = 4000.0f;
this->actor.uncullZoneScale = 800.0f;
this->actor.uncullZoneDownward = 1800.0f;
break;
case WOOD_TREE_CONICAL_SMALL:
actorScale = 0.6f;
this->actor.uncullZoneForward = 4000.0f;
this->actor.uncullZoneScale = 400.0f;
this->actor.uncullZoneDownward = 1000.0f;
break;
case WOOD_LEAF_GREEN:
case WOOD_LEAF_YELLOW:
this->unk_14E[0] = 0x4B;
actorScale = 0.02f;
this->actor.velocity.x = Rand_CenteredFloat(6.0f);
this->actor.velocity.z = Rand_CenteredFloat(6.0f);
this->actor.velocity.y = (Rand_ZeroOne() * 1.25f) + -3.1f;
}
if (this->actor.params <= WOOD_TREE_CONICAL_SPAWNED) {
this->drawType = WOOD_DRAW_TREE_CONICAL;
} else if (this->actor.params <= WOOD_TREE_OVAL_GREEN_SPAWNED) {
this->drawType = WOOD_DRAW_TREE_OVAL;
} else if (this->actor.params <= WOOD_TREE_KAKARIKO_ADULT) {
this->drawType = WOOD_DRAW_TREE_KAKARIKO_ADULT;
} else if (this->actor.params <= WOOD_BUSH_GREEN_LARGE_SPAWNED) {
this->drawType = WOOD_DRAW_BUSH_GREEN;
} else if (this->actor.params <= WOOD_LEAF_GREEN) { // Black bushes and green leaves
this->drawType = WOOD_DRAW_4;
} else {
this->drawType = WOOD_DRAW_LEAF_YELLOW;
}
Actor_SetScale(&this->actor, actorScale);
this->spawnType = spawnType;
if (spawnType != WOOD_SPAWN_NORMAL) {
extraRot = 0;
if (this->actor.params == WOOD_BUSH_GREEN_LARGE_SPAWNER) {
extraRot = 0x4000;
}
if (spawnType == WOOD_SPAWN_SPAWNER) {
this->drawType |= this->unk_14C << 4;
EnWood02_SpawnOffspring(this, globalCtx);
sSpawnCos = Math_CosS(sSpawnAngle[5] + this->actor.posRot.rot.y + extraRot);
sSpawnSin = Math_SinS(sSpawnAngle[5] + this->actor.posRot.rot.y + extraRot);
this->actor.posRot.pos.x += (sSpawnSin * sSpawnDistance[5]);
this->actor.posRot.pos.z += (sSpawnCos * sSpawnDistance[5]);
} else {
this->actor.flags |= 0x10;
}
// Snap to floor, or remove if over void
this->actor.posRot.pos.y += 200.0f;
floorY =
BgCheck_EntityRaycastFloor4(&globalCtx->colCtx, &outPoly, &bgId, &this->actor, &this->actor.posRot.pos);
if (floorY > BGCHECK_Y_MIN) {
this->actor.posRot.pos.y = floorY;
} else {
Actor_Kill(&this->actor);
return;
}
}
ActorShape_Init(&this->actor.shape, 0.0f, NULL, 0.0f);
this->actor.initPosRot.rot.y = 0;
this->actor.colChkInfo.mass = 0xFF;
}
void EnWood02_Destroy(Actor* thisx, GlobalContext* globalCtx) {
EnWood02* this = THIS;
if (this->actor.params <= WOOD_TREE_KAKARIKO_ADULT) {
Collider_DestroyCylinder(globalCtx, &this->collider);
}
}
void EnWood02_Update(Actor* thisx, GlobalContext* globalCtx2) {
GlobalContext* globalCtx = globalCtx2;
EnWood02* this = THIS;
f32 wobbleAmplitude;
u8 new_var;
u8 phi_v0;
s32 pad;
Vec3f dropsSpawnPt;
s32 i;
s32 leavesParams;
// Despawn extra trees in a group if out of range
if ((this->spawnType == WOOD_SPAWN_SPAWNED) && (this->actor.parent != NULL)) {
if (!(this->actor.flags & 0x40)) {
new_var = this->unk_14E[0];
phi_v0 = 0;
if (this->unk_14C < 0) {
phi_v0 = 0x80;
}
((EnWood02*)this->actor.parent)->unk_14E[new_var] = phi_v0;
Actor_Kill(&this->actor);
return;
}
} else if (this->spawnType == WOOD_SPAWN_SPAWNER) {
EnWood02_SpawnOffspring(this, globalCtx);
}
if (this->actor.params <= WOOD_TREE_KAKARIKO_ADULT) {
if (this->collider.base.acFlags & 2) {
this->collider.base.acFlags &= ~2;
Audio_PlayActorSound2(&this->actor, NA_SE_IT_REFLECTION_WOOD);
}
if (this->actor.initPosRot.rot.y != 0) {
dropsSpawnPt = this->actor.posRot.pos;
dropsSpawnPt.y += 200.0f;
if ((this->unk_14C >= 0) && (this->unk_14C < 0x64)) {
Item_DropCollectibleRandom(globalCtx, &this->actor, &dropsSpawnPt, this->unk_14C << 4);
} else {
if (this->actor.initPosRot.rot.z != 0) {
this->actor.initPosRot.rot.z &= 0x1FFF;
this->actor.initPosRot.rot.z |= 0xE000;
Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_SW, dropsSpawnPt.x, dropsSpawnPt.y,
dropsSpawnPt.z, 0, this->actor.posRot.rot.y, 0, this->actor.initPosRot.rot.z);
this->actor.initPosRot.rot.z = 0;
}
}
// Spawn falling leaves
if (this->unk_14C >= -1) {
leavesParams = WOOD_LEAF_GREEN;
if ((this->actor.params == WOOD_TREE_OVAL_YELLOW_SPAWNER) ||
(this->actor.params == WOOD_TREE_OVAL_YELLOW_SPAWNED)) {
leavesParams = WOOD_LEAF_YELLOW;
}
Audio_PlayActorSound2(&this->actor, NA_SE_EV_TREE_SWING);
for (i = 3; i >= 0; i--) {
Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_WOOD02, dropsSpawnPt.x, dropsSpawnPt.y,
dropsSpawnPt.z, 0, Rand_CenteredFloat(65535.0f), 0, leavesParams);
}
}
this->unk_14C = -0x15;
this->actor.initPosRot.rot.y = 0;
}
if (this->actor.xzDistToLink < 600.0f) {
Collider_CylinderUpdate(&this->actor, &this->collider);
CollisionCheck_SetAC(globalCtx, &globalCtx->colChkCtx, &this->collider.base);
CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->collider.base);
}
} else if (this->actor.params < 0x17) { // Bush
Player* player = PLAYER;
if (this->unk_14C >= -1) {
if (((player->rideActor == NULL) && (sqrt(this->actor.xyzDistToLinkSq) < 20.0) &&
(player->linearVelocity != 0.0f)) ||
((player->rideActor != NULL) && (sqrt(this->actor.xyzDistToLinkSq) < 60.0) &&
(player->rideActor->speedXZ != 0.0f))) {
if ((this->unk_14C >= 0) && (this->unk_14C < 0x64)) {
Item_DropCollectibleRandom(globalCtx, &this->actor, &this->actor.posRot.pos,
((this->unk_14C << 4) | 0x8000));
}
this->unk_14C = -0x15;
Audio_PlayActorSound2(&this->actor, NA_SE_EV_TREE_SWING);
}
}
} else { // Leaves
this->unk_14C++;
Math_ApproachF(&this->actor.velocity.x, 0.0f, 1.0f, 5 * 0.01f);
Math_ApproachF(&this->actor.velocity.z, 0.0f, 1.0f, 5 * 0.01f);
func_8002D7EC(&this->actor);
this->actor.shape.rot.z = Math_SinS(3000 * this->unk_14C) * 0x4000;
this->unk_14E[0]--;
if (this->unk_14E[0] == 0) {
Actor_Kill(&this->actor);
}
}
// Wobble from impact
if (this->unk_14C < -1) {
this->unk_14C++;
wobbleAmplitude = Math_SinS((this->unk_14C ^ 0xFFFF) * 0x3332) * 250.0f;
this->actor.shape.rot.x = (Math_CosS(this->actor.yawTowardsLink - this->actor.shape.rot.y) * wobbleAmplitude);
this->actor.shape.rot.z = (Math_SinS(this->actor.yawTowardsLink - this->actor.shape.rot.y) * wobbleAmplitude);
}
}
void EnWood02_Draw(Actor* thisx, GlobalContext* globalCtx) {
EnWood02* this = THIS;
s16 type;
GraphicsContext* gfxCtx = globalCtx->state.gfxCtx;
u8 red;
u8 green;
u8 blue;
OPEN_DISPS(gfxCtx, "../z_en_wood02.c", 775);
type = this->actor.params;
if ((type == WOOD_TREE_OVAL_GREEN_SPAWNER) || (type == WOOD_TREE_OVAL_GREEN_SPAWNED) ||
(type == WOOD_TREE_OVAL_GREEN) || (type == WOOD_LEAF_GREEN)) {
red = 50;
green = 170;
blue = 70;
} else if ((type == WOOD_TREE_OVAL_YELLOW_SPAWNER) || (type == WOOD_TREE_OVAL_YELLOW_SPAWNED) ||
(type == WOOD_LEAF_YELLOW)) {
red = 180;
green = 155;
blue = 0;
} else {
red = green = blue = 255;
}
func_80093D84(gfxCtx);
if ((this->actor.params == WOOD_LEAF_GREEN) || (this->actor.params == WOOD_LEAF_YELLOW)) {
func_80093D18(gfxCtx);
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, red, green, blue, 127);
Gfx_DrawDListOpa(globalCtx, D_06000700);
} else if (D_80B3BF70[this->drawType & 0xF] != NULL) {
Gfx_DrawDListOpa(globalCtx, D_80B3BF54[this->drawType & 0xF]);
gDPSetEnvColor(POLY_XLU_DISP++, red, green, blue, 0);
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx, "../z_en_wood02.c", 808),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_XLU_DISP++, D_80B3BF70[this->drawType & 0xF]);
} else {
func_80093D84(gfxCtx);
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(gfxCtx, "../z_en_wood02.c", 814),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_XLU_DISP++, D_80B3BF54[this->drawType & 0xF]);
}
CLOSE_DISPS(gfxCtx, "../z_en_wood02.c", 840);
}

View file

@ -8,9 +8,43 @@ struct EnWood02;
typedef struct EnWood02 {
/* 0x0000 */ Actor actor;
/* 0x014C */ char unk_14C[0x58];
/* 0x014C */ s16 unk_14C;
/* 0x014E */ u8 unk_14E[5];
/* 0x0153 */ u8 spawnType;
/* 0x0154 */ u8 drawType;
/* 0x0158 */ ColliderCylinder collider;
} EnWood02; // size = 0x01A4
extern const ActorInit En_Wood02_InitVars;
// Types with SPAWNED in the name are those that can be managed by a spawner, however the actor allows you to spawn them
// on their own without a spawner as well.
typedef enum {
/* 0x00 */ WOOD_TREE_CONICAL_LARGE,
/* 0x01 */ WOOD_TREE_CONICAL_MEDIUM,
/* 0x02 */ WOOD_TREE_CONICAL_SMALL,
/* 0x03 */ WOOD_TREE_CONICAL_SPAWNER,
/* 0x04 */ WOOD_TREE_CONICAL_SPAWNED,
/* 0x05 */ WOOD_TREE_OVAL_GREEN,
/* 0x06 */ WOOD_TREE_OVAL_YELLOW_SPAWNER,
/* 0x07 */ WOOD_TREE_OVAL_YELLOW_SPAWNED,
/* 0x08 */ WOOD_TREE_OVAL_GREEN_SPAWNER,
/* 0x09 */ WOOD_TREE_OVAL_GREEN_SPAWNED,
/* 0x0A */ WOOD_TREE_KAKARIKO_ADULT,
/* 0x0B */ WOOD_BUSH_GREEN_SMALL,
/* 0x0C */ WOOD_BUSH_GREEN_LARGE,
/* 0x0D */ WOOD_BUSH_GREEN_SMALL_SPAWNER,
/* 0x0E */ WOOD_BUSH_GREEN_SMALL_SPAWNED,
/* 0x0F */ WOOD_BUSH_GREEN_LARGE_SPAWNER,
/* 0x10 */ WOOD_BUSH_GREEN_LARGE_SPAWNED,
/* 0x11 */ WOOD_BUSH_BLACK_SMALL,
/* 0x12 */ WOOD_BUSH_BLACK_LARGE,
/* 0x13 */ WOOD_BUSH_BLACK_SMALL_SPAWNER,
/* 0x14 */ WOOD_BUSH_BLACK_SMALL_SPAWNED,
/* 0x15 */ WOOD_BUSH_BLACK_LARGE_SPAWNER,
/* 0x16 */ WOOD_BUSH_BLACK_LARGE_SPAWNED,
/* 0x17 */ WOOD_LEAF_GREEN,
/* 0x18 */ WOOD_LEAF_YELLOW
} WoodType;
#endif