1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-14 21:40:03 +00:00
oot/src/code/z_en_a_keep.c

352 lines
11 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <ultra64.h>
#include <global.h>
2020-03-22 21:19:43 +00:00
typedef enum {
2020-03-17 04:31:30 +00:00
/* 0x00 */ A_OBJ_BLOCK_SMALL,
/* 0x01 */ A_OBJ_BLOCK_LARGE,
/* 0x02 */ A_OBJ_BLOCK_HUGE,
/* 0x03 */ A_OBJ_BLOCK_SMALL_ROT,
/* 0x04 */ A_OBJ_BLOCK_LARGE_ROT,
/* 0x05 */ A_OBJ_CUBE_SMALL,
/* 0x06 */ A_OBJ_UNKNOWN_6,
/* 0x07 */ A_OBJ_GRASS_CLUMP,
/* 0x08 */ A_OBJ_TREE_STUMP,
/* 0x09 */ A_OBJ_SIGNPOST_OBLONG,
/* 0x0A */ A_OBJ_SIGNPOST_ARROW,
/* 0x0B */ A_OBJ_KNOB
} AObjType;
2020-03-22 21:19:43 +00:00
typedef struct {
2020-03-17 04:31:30 +00:00
/* 0x000 */ Actor actor;
2020-03-22 21:19:43 +00:00
/* 0x14C */ u32 dynaPolyId;
/* 0x150 */ f32 unk_150;
/* 0x154 */ f32 unk_154;
/* 0x158 */ s16 unk_158;
/* 0x15C */ u32 unk_15C;
/* 0x160 */ u8 unk_160;
2020-03-17 04:31:30 +00:00
/* 0x164 */ ActorFunc updateFunc;
2020-03-22 21:19:43 +00:00
/* 0x168 */ s32 unk_168;
/* 0x16C */ s16 textId;
/* 0x16E */ s16 unk_16E;
/* 0x170 */ s16 unk_170;
/* 0x172 */ s16 unk_172;
/* 0x174 */ s16 unk_174;
/* 0x178 */ f32 unk_178;
2020-03-17 04:31:30 +00:00
/* 0x17C */ ColliderCylinderMain cylinderCollider;
} ActorEnAObj; // size = 0x1C8
void func_8001D204(ActorEnAObj* this, GlobalContext* globalCtx);
void func_8001D25C(ActorEnAObj* this, GlobalContext* globalCtx);
void func_8001D360(ActorEnAObj* this, GlobalContext* globalCtx);
void func_8001D4A8(ActorEnAObj* this, GlobalContext* globalCtx);
void func_8001D608(ActorEnAObj* this, GlobalContext* globalCtx);
void func_8001D234(ActorEnAObj* this, s16 params);
void func_8001D310(ActorEnAObj* this, s16 params);
void func_8001D480(ActorEnAObj* this, s16 params);
void func_8001D5C8(ActorEnAObj* this, s16 params);
// TODO: Define this part of code .data here and rename the symbols
extern ActorInit En_A_Obj_InitVars;
extern ColliderCylinderInit D_80115440;
extern u32 D_8011546C[];
extern u32 D_80115484[];
2020-03-22 21:19:43 +00:00
void En_A_Obj_SetNewUpdate(ActorEnAObj* this, ActorFunc newUpdateFunc) {
2020-03-17 04:31:30 +00:00
this->updateFunc = newUpdateFunc;
}
#ifdef NON_MATCHING
// minor ordering and regalloc differences
2020-03-22 21:19:43 +00:00
void En_A_Obj_Init(ActorEnAObj* this, GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
u32 sp34;
s16 type;
s16 initialParams;
s32 params;
f32 sp28;
sp34 = 0;
sp28 = 6.0f;
initialParams = this->actor.params;
type = initialParams & 0xFF;
this->textId = (initialParams >> 8) & 0xFF;
this->actor.params = type;
2020-03-22 21:19:43 +00:00
switch (type & 0xFFFF) {
2020-03-17 04:31:30 +00:00
case A_OBJ_BLOCK_SMALL:
Actor_SetScale(&this->actor, 0.025f);
break;
case A_OBJ_BLOCK_LARGE:
Actor_SetScale(&this->actor, 0.05f);
break;
case A_OBJ_BLOCK_HUGE:
case A_OBJ_CUBE_SMALL:
case A_OBJ_UNKNOWN_6:
Actor_SetScale(&this->actor, 0.1f);
break;
case A_OBJ_BLOCK_SMALL_ROT:
Actor_SetScale(&this->actor, 0.005f);
break;
case A_OBJ_BLOCK_LARGE_ROT:
default:
Actor_SetScale(&this->actor, 0.01f);
break;
}
if (this->actor.params >= 9)
sp28 = 12.0f;
ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawFunc_Circle, sp28);
this->dynaPolyId = -1;
this->unk_160 = 0;
this->unk_15C = 0;
this->actor.unk_FC = 1200.0f;
this->actor.unk_F8 = 200.0f;
params = this->actor.params;
this->actor.posRot2.pos = this->actor.posRot.pos;
2020-03-22 21:19:43 +00:00
switch (params) {
2020-03-17 04:31:30 +00:00
case A_OBJ_BLOCK_LARGE:
case A_OBJ_BLOCK_HUGE:
this->dynaPolyId = 1;
Actor_ChangeType(globalCtx, &globalCtx->actorCtx, &this->actor, ACTORTYPE_BG);
func_8001D5C8(this, this->actor.params);
break;
case A_OBJ_BLOCK_SMALL_ROT:
case A_OBJ_BLOCK_LARGE_ROT:
this->dynaPolyId = 3;
Actor_ChangeType(globalCtx, &globalCtx->actorCtx, &this->actor, ACTORTYPE_BG);
func_8001D310(this, this->actor.params);
break;
case A_OBJ_UNKNOWN_6:
this->actor.flags |= 0x1;
this->dynaPolyId = 5;
this->unk_178 = 10.0f;
this->actor.gravity = -2.0f;
func_8001D234(this, this->actor.params);
break;
case A_OBJ_GRASS_CLUMP:
case A_OBJ_TREE_STUMP:
this->dynaPolyId = 0;
func_8001D234(this, this->actor.params);
break;
case A_OBJ_SIGNPOST_OBLONG:
case A_OBJ_SIGNPOST_ARROW:
this->actor.textId = (this->textId & 0xFF) | 0x300;
this->actor.flags |= 0x8 | 0x1;
this->actor.unk_4C = 500.0f;
this->unk_178 = 45.0f;
func_8001D234(this, this->actor.params);
ActorCollider_AllocCylinder(globalCtx, &this->cylinderCollider);
ActorCollider_InitCylinder(globalCtx, &this->cylinderCollider, &this->actor, &D_80115440);
this->actor.sub_98.mass = 0xFF;
this->actor.unk_1F = 0;
break;
case A_OBJ_KNOB:
this->actor.gravity = -1.5f;
func_8001D480(this, params);
break;
default:
this->actor.gravity = -2.0f;
func_8001D234(this, params);
break;
}
2020-03-22 21:19:43 +00:00
2020-03-17 04:31:30 +00:00
if (this->actor.params < 5)
this->actor.sub_98.mass = 0xFF;
2020-03-22 21:19:43 +00:00
if (this->dynaPolyId != -1) {
2020-03-17 04:31:30 +00:00
DynaPolyInfo_Alloc(D_8011546C[this->dynaPolyId], &sp34);
this->dynaPolyId = DynaPolyInfo_RegisterActor(globalCtx, &globalCtx->colCtx.dyna, &this->actor, sp34);
}
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_en_a_keep/En_A_Obj_Init.s")
#endif
2020-03-22 21:19:43 +00:00
void En_A_Obj_Destroy(ActorEnAObj* this, GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
ColliderCylinderMain* cylinderCollider = &this->cylinderCollider;
DynaPolyInfo_Free(globalCtx, &globalCtx->colCtx.dyna, this->dynaPolyId);
2020-03-22 21:19:43 +00:00
switch (this->actor.params) {
2020-03-17 04:31:30 +00:00
case A_OBJ_SIGNPOST_OBLONG:
case A_OBJ_SIGNPOST_ARROW:
ActorCollider_FreeCylinder(globalCtx, cylinderCollider);
}
}
2020-03-22 21:19:43 +00:00
void func_8001D204(ActorEnAObj* this, GlobalContext* globalCtx) {
if (func_8002F334(&this->actor, globalCtx)) {
2020-03-17 04:31:30 +00:00
func_8001D234(this, this->actor.params);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
void func_8001D234(ActorEnAObj* this, s16 params) {
2020-03-17 04:31:30 +00:00
En_A_Obj_SetNewUpdate(this, (ActorFunc)func_8001D25C);
}
2020-03-22 21:19:43 +00:00
void func_8001D25C(ActorEnAObj* this, GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
s16 var;
2020-03-22 21:19:43 +00:00
if (this->actor.textId != 0) {
2020-03-17 04:31:30 +00:00
var = this->actor.rotTowardsLinkY - this->actor.shape.rot.y;
2020-03-22 21:19:43 +00:00
if ((ABS(var) < 0x2800) || ((this->actor.params == 0xA) && (ABS(var) > 0x5800))) {
if (func_8002F194(&this->actor, globalCtx)) {
2020-03-17 04:31:30 +00:00
En_A_Obj_SetNewUpdate(this, (ActorFunc)func_8001D204);
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
func_8002F2F4(&this->actor, globalCtx);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
}
}
2020-03-22 21:19:43 +00:00
void func_8001D310(ActorEnAObj* this, s16 params) {
2020-03-17 04:31:30 +00:00
this->unk_16E = 0;
this->unk_168 = 10;
this->actor.posRot.rot.y = 0;
this->actor.shape.rot = this->actor.posRot.rot;
En_A_Obj_SetNewUpdate(this, (ActorFunc)func_8001D360);
}
2020-03-22 21:19:43 +00:00
void func_8001D360(ActorEnAObj* this, GlobalContext* globalCtx) {
if (this->unk_16E == 0) {
if (this->unk_160 != 0) {
2020-03-17 04:31:30 +00:00
this->unk_16E++;
this->unk_170 = 20;
2020-03-22 21:19:43 +00:00
if ((s16)(this->actor.rotTowardsLinkY + 0x4000) < 0) {
2020-03-17 04:31:30 +00:00
this->unk_174 = -1000;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
this->unk_174 = 1000;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if (this->actor.rotTowardsLinkY < 0) {
2020-03-17 04:31:30 +00:00
this->unk_172 = -this->unk_174;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
this->unk_172 = this->unk_174;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
} else {
if (this->unk_168 != 0) {
2020-03-17 04:31:30 +00:00
this->unk_168--;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
this->actor.shape.rot.y += this->unk_172;
this->actor.shape.rot.x += this->unk_174;
this->unk_170--;
this->actor.gravity = -1.0f;
2020-03-22 21:19:43 +00:00
if (this->unk_170 == 0) {
2020-03-17 04:31:30 +00:00
this->actor.posRot.pos = this->actor.initPosRot.pos;
this->unk_16E = 0;
this->unk_168 = 10;
this->actor.velocity.y = 0.0f;
this->actor.gravity = 0.0f;
this->actor.shape.rot = this->actor.posRot.rot;
}
}
}
}
2020-03-22 21:19:43 +00:00
void func_8001D480(ActorEnAObj* this, s16 params) {
2020-03-17 04:31:30 +00:00
En_A_Obj_SetNewUpdate(this, (ActorFunc)func_8001D4A8);
}
2020-03-22 21:19:43 +00:00
void func_8001D4A8(ActorEnAObj* this, GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
Math_SmoothScaleMaxMinF(&this->actor.speedXZ, 1.0f, 1.0f, 0.5f, 0.0f);
this->actor.shape.rot.x = this->actor.shape.rot.x + (this->actor.posRot.rot.x >> 1);
this->actor.shape.rot.z = this->actor.shape.rot.z + (this->actor.posRot.rot.z >> 1);
2020-03-22 21:19:43 +00:00
if ((this->actor.speedXZ != 0.0f) && (this->actor.bgCheckFlags & 0x8)) {
if (1) { // Necessary to match
2020-03-17 04:31:30 +00:00
this->actor.posRot.rot.y = ((this->actor.unk_7E - this->actor.posRot.rot.y) + this->actor.unk_7E) - 0x8000;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
this->actor.bgCheckFlags &= ~0x8;
}
2020-03-22 21:19:43 +00:00
if (this->actor.bgCheckFlags & 0x2) {
if (this->actor.velocity.y < -8.0f) {
2020-03-17 04:31:30 +00:00
this->actor.velocity.y *= -0.6f;
this->actor.speedXZ *= 0.6f;
this->actor.bgCheckFlags &= ~0x3;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
Actor_Kill(&this->actor);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
}
2020-03-22 21:19:43 +00:00
void func_8001D5C8(ActorEnAObj* this, s16 params) {
2020-03-17 04:31:30 +00:00
this->actor.unk_FC = 1200.0f;
this->actor.unk_F8 = 720.0f;
En_A_Obj_SetNewUpdate(this, (ActorFunc)func_8001D608);
}
2020-03-22 21:19:43 +00:00
void func_8001D608(ActorEnAObj* this, GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
this->actor.speedXZ += this->unk_150;
this->actor.posRot.rot.y = this->unk_158;
2020-03-22 21:19:43 +00:00
this->actor.speedXZ =
(this->actor.speedXZ < -2.5f) ? -2.5f : ((this->actor.speedXZ > 2.5f) ? 2.5f : this->actor.speedXZ);
2020-03-17 04:31:30 +00:00
Math_SmoothScaleMaxMinF(&this->actor.speedXZ, 0.0f, 1.0f, 1.0f, 0.0f);
2020-03-22 21:19:43 +00:00
if (this->actor.speedXZ != 0.0f) {
2020-03-17 04:31:30 +00:00
Audio_PlayActorSound2(&this->actor, 0x200A);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
this->unk_154 = 0.0f;
this->unk_150 = 0.0f;
}
2020-03-22 21:19:43 +00:00
void En_A_Obj_Update(ActorEnAObj* this, GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
ColliderCylinderMain* cylinderCollider;
this->updateFunc(this, globalCtx);
Actor_MoveForward(&this->actor);
2020-03-22 21:19:43 +00:00
if (this->actor.gravity != 0.0f) {
if (this->actor.params != A_OBJ_KNOB) {
2020-03-17 04:31:30 +00:00
func_8002E4B4(globalCtx, &this->actor, 5.0f, 40.0f, 0.0f, 0x1D);
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
func_8002E4B4(globalCtx, &this->actor, 5.0f, 20.0f, 0.0f, 0x1D);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
this->actor.posRot2.pos = this->actor.posRot.pos;
this->actor.posRot2.pos.y += this->unk_178;
2020-03-22 21:19:43 +00:00
switch (this->actor.params) {
2020-03-17 04:31:30 +00:00
case A_OBJ_SIGNPOST_OBLONG:
case A_OBJ_SIGNPOST_ARROW:
cylinderCollider = &this->cylinderCollider;
ActorCollider_Cylinder_Update(&this->actor, cylinderCollider);
Actor_CollisionCheck_SetOT(globalCtx, &globalCtx->sub_11E60, cylinderCollider);
}
}
2020-03-22 21:19:43 +00:00
void En_A_Obj_Draw(ActorEnAObj* this, GlobalContext* globalCtx) {
2020-03-17 04:31:30 +00:00
s32 type = this->actor.params;
GraphicsContext* gfxCtx = globalCtx->state.gfxCtx;
Gfx* gfxArr[4];
func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_en_a_keep.c", 701);
func_80093D18(globalCtx->state.gfxCtx);
2020-03-22 21:19:43 +00:00
if (type > A_OBJ_KNOB) {
2020-03-17 04:31:30 +00:00
type = A_OBJ_KNOB;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if (this->actor.params == A_OBJ_KNOB) {
2020-03-17 04:31:30 +00:00
gDPSetPrimColor(gfxCtx->polyOpa.p++, 0, 1, 0x3C, 0x3C, 0x3C, 0x32);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
gSPMatrix(gfxCtx->polyOpa.p++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_en_a_keep.c", 712),
G_MTX_MODELVIEW | G_MTX_LOAD);
2020-03-17 04:31:30 +00:00
gSPDisplayList(gfxCtx->polyOpa.p++, D_80115484[type]);
func_800C6B54(gfxArr, globalCtx->state.gfxCtx, "../z_en_a_keep.c", 715);
}