1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-02 22:14:33 +00:00

EnEncount2 and EnFireRock OK (#659)

* first two funcs done

* fixing struct var name due to external use

* func_80A07CA4 done

* started EnEncount2_Update

* EnEncount2_Update done

* Encount2 done!

* EnFireRock_Init done (but will only match once initvars are uncommented

* progress

* 4 funcs left

* Fully matching

* minor formatting

* renames

* change structs back to normal

* formatting

* removing unused comments

* even more formatting stuff

* removed unused asm

* pr stuff

* pr stuff

* added newline at end of file

* some merge suggestions

* more pr stuff

* review

Co-authored-by: fig02 <fig02srl@gmail.com>
This commit is contained in:
AdamKiddle 2021-03-14 14:39:41 +00:00 committed by GitHub
parent 8e0fa07a7e
commit ca5a9aa7d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 755 additions and 2752 deletions

View file

@ -1,16 +1,30 @@
#include "z_en_encount2.h"
#include "overlays/actors/ovl_En_Fire_Rock/z_en_fire_rock.h"
#include "vt.h"
#define FLAGS 0x00000030
#define THIS ((EnEncount2*)thisx)
typedef enum {
/* 0x0 */ ENCOUNT2_INACTIVE,
/* 0x1 */ ENCOUNT2_ACTIVE_DEATH_MOUNTAIN,
/* 0x2 */ ENCOUNT2_ACTIVE_GANONS_TOWER
} Encount2State;
void EnEncount2_Init(Actor* thisx, GlobalContext* globalCtx);
void EnEncount2_Update(Actor* thisx, GlobalContext* globalCtx);
void EnEncount2_Draw(Actor* thisx, GlobalContext* globalCtx);
extern UNK_TYPE D_06000DE0;
void EnEncount2_Wait(EnEncount2* this, GlobalContext* globalCtx);
void EnEncount2_SpawnRocks(EnEncount2* this, GlobalContext* globalCtx);
void EnEncount2_ParticleInit(EnEncount2* this, Vec3f* particlePos, f32 scale);
void EnEncount2_ParticleDraw(Actor* thisx, GlobalContext* globalCtx);
void EnEncount2_ParticleUpdate(EnEncount2* this, GlobalContext* globalCtx);
extern Gfx* D_06000DE0[];
/*
const ActorInit En_Encount2_InitVars = {
ACTOR_EN_ENCOUNT2,
ACTORCAT_ENEMY,
@ -22,19 +36,339 @@ const ActorInit En_Encount2_InitVars = {
(ActorFunc)EnEncount2_Update,
(ActorFunc)EnEncount2_Draw,
};
*/
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Encount2/EnEncount2_Init.s")
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Encount2/func_80A07A4C.s")
void EnEncount2_Init(Actor* thisx, GlobalContext* globalCtx) {
EnEncount2* this = THIS;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Encount2/func_80A07CA4.s")
if (globalCtx->sceneNum != SCENE_SPOT16) {
this->isNotDeathMountain = true;
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Encount2/EnEncount2_Update.s")
if (!this->isNotDeathMountain) {
osSyncPrintf("\n\n");
// "☆☆☆☆☆ Death Mountain Encount2 set ☆☆☆☆☆"
osSyncPrintf(VT_FGCOL(GREEN) "☆☆☆☆☆ デスマウンテンエンカウント2セットされました ☆☆☆☆☆ %d\n" VT_RST,
this->actor.params);
if (LINK_IS_ADULT && (gSaveContext.eventChkInf[4] & 0x200)) { // flag for having used fire temple blue warp
Actor_Kill(thisx);
}
} else {
osSyncPrintf("\n\n");
// "☆☆☆☆☆ Ganon Tower Escape Encount2 set ☆☆☆☆☆"
osSyncPrintf(VT_FGCOL(GREEN) "☆☆☆☆☆ ガノンタワー脱出エンカウント2セットされました ☆☆☆☆☆ %d\n" VT_RST,
this->actor.params);
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Encount2/EnEncount2_Draw.s")
this->actionFunc = EnEncount2_Wait;
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Encount2/func_80A08694.s")
void EnEncount2_Wait(EnEncount2* this, GlobalContext* globalCtx) {
s32 pad;
s16 quakeIndex;
s16 spawnerState;
Player* player = PLAYER;
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Encount2/func_80A08748.s")
spawnerState = ENCOUNT2_INACTIVE;
if (!this->isNotDeathMountain) {
if ((player->actor.world.pos.y > 1500.0f) && (player->actor.world.pos.x > -700.0f) &&
(player->actor.world.pos.x < 100.0f) && (player->actor.world.pos.z < -1290.0f) &&
(player->actor.world.pos.z > -3600.0f)) {
spawnerState = ENCOUNT2_ACTIVE_DEATH_MOUNTAIN;
}
} else if ((this->actor.xzDistToPlayer < 700.0f) && (Flags_GetSwitch(globalCtx, 0x37))) {
s16 scene = globalCtx->sceneNum;
if (((scene == SCENE_GANON_DEMO) || (scene == SCENE_GANON_FINAL) || (scene == SCENE_GANON_SONOGO) ||
(scene == SCENE_GANONTIKA_SONOGO)) &&
(!this->collapseSpawnerInactive)) {
spawnerState = ENCOUNT2_ACTIVE_GANONS_TOWER;
}
}
#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Encount2/func_80A0891C.s")
switch (spawnerState) {
case ENCOUNT2_INACTIVE:
this->isQuaking = false;
this->envEffectsTimer--;
if (this->envEffectsTimer <= 0) {
this->envEffectsTimer = 0;
}
break;
case ENCOUNT2_ACTIVE_DEATH_MOUNTAIN:
if ((this->deathMountainSpawnerTimer == 1) || (!this->isQuaking)) {
quakeIndex = Quake_Add(ACTIVE_CAM, 1);
Quake_SetSpeed(quakeIndex, 0x7FFF);
Quake_SetQuakeValues(quakeIndex, 50, 0, 0, 0);
Quake_SetCountdown(quakeIndex, 300);
this->isQuaking = true;
}
case ENCOUNT2_ACTIVE_GANONS_TOWER:
this->envEffectsTimer++;
if (this->envEffectsTimer > 60) {
this->envEffectsTimer = 60;
}
if (this->deathMountainSpawnerTimer == 0) {
this->deathMountainSpawnerTimer = 200;
this->numSpawnedRocks = 0;
this->actionFunc = EnEncount2_SpawnRocks;
}
break;
}
return;
}
void EnEncount2_SpawnRocks(EnEncount2* this, GlobalContext* globalCtx) {
Player* player = PLAYER;
EnFireRock* spawnedRock;
f32 tempVec1X;
f32 tempVec1Y;
f32 tempVec1Z;
f32 magnitude;
f32 tempVec2X;
f32 tempVec2Y;
f32 tempVec2Z;
f32 particleScale;
Vec3f particlePos;
s16 spawnedRockType;
s16 spawnerState;
s16 maxRocks;
this->envEffectsTimer++;
if (this->envEffectsTimer > 60) {
this->envEffectsTimer = 60;
}
spawnerState = ENCOUNT2_INACTIVE;
if (!this->isNotDeathMountain) {
if (this->deathMountainSpawnerTimer == 0) {
this->deathMountainSpawnerTimer = 100;
this->actionFunc = EnEncount2_Wait;
return;
}
if ((player->actor.world.pos.y > 1500.0f) && (player->actor.world.pos.x > -700.0f) &&
(player->actor.world.pos.x < 100.0f) && (player->actor.world.pos.z < -1290.0f) &&
(player->actor.world.pos.z > -3860.0f)) {
maxRocks = 2;
spawnerState = ENCOUNT2_ACTIVE_DEATH_MOUNTAIN;
}
Audio_PlayActorSound2(&this->actor, NA_SE_EV_VOLCANO - SFX_FLAG);
} else if ((this->actor.xzDistToPlayer < 700.0f) && (Flags_GetSwitch(globalCtx, 0x37) != 0)) {
s16 scene = globalCtx->sceneNum;
if (((scene == SCENE_GANON_DEMO) || (scene == SCENE_GANON_FINAL) || (scene == SCENE_GANON_SONOGO) ||
(scene == SCENE_GANONTIKA_SONOGO)) &&
(!this->collapseSpawnerInactive)) {
maxRocks = 1;
spawnerState = ENCOUNT2_ACTIVE_GANONS_TOWER;
}
}
if (spawnerState != ENCOUNT2_INACTIVE) {
// Direction vector for the direction the camera is facing
tempVec1X = globalCtx->view.lookAt.x - globalCtx->view.eye.x;
tempVec1Y = globalCtx->view.lookAt.y - globalCtx->view.eye.y;
tempVec1Z = globalCtx->view.lookAt.z - globalCtx->view.eye.z;
// Normalised direction vector for the direction the camera is facing
magnitude = sqrtf(SQ(tempVec1X) + SQ(tempVec1Y) + SQ(tempVec1Z));
tempVec2X = tempVec1X / magnitude;
tempVec2Y = tempVec1Y / magnitude;
tempVec2Z = tempVec1Z / magnitude;
// Position between 160 and 300 units ahead of camera depending on camera pitch, plus a 400 unit offset in +y
tempVec1X = globalCtx->view.eye.x + (tempVec2X * 300.0f);
tempVec1Y = globalCtx->view.eye.y + (tempVec2Y * 160.0f) + 400.0f;
tempVec1Z = globalCtx->view.eye.z + (tempVec2Z * 300.0f);
// Position between 160 and 200 units ahead of camera depending on camera pitch, plus a 400 unit offset in +y
// (plus some random variation)
particlePos.x = Rand_CenteredFloat(200.0f) + (globalCtx->view.eye.x + (tempVec2X * 200.0f));
particlePos.y = Rand_CenteredFloat(50.0f) + tempVec1Y;
particlePos.z = Rand_CenteredFloat(200.0f) + (globalCtx->view.eye.z + (tempVec2Z * 200.0f));
particleScale = Rand_CenteredFloat(0.005f) + 0.007f;
if (spawnerState == ENCOUNT2_ACTIVE_DEATH_MOUNTAIN) {
EnEncount2_ParticleInit(this, &particlePos, particleScale);
} else if (this->particleSpawnTimer == 0) {
EnEncount2_ParticleInit(this, &particlePos, particleScale);
this->particleSpawnTimer = 5;
}
if ((this->numSpawnedRocks < maxRocks) && (this->timerBetweenRockSpawns == 0)) {
if (spawnerState == ENCOUNT2_ACTIVE_DEATH_MOUNTAIN) {
this->timerBetweenRockSpawns = 4;
spawnedRockType = FIRE_ROCK_SPAWNED_FALLING1;
if ((Rand_ZeroFloat(1.99f) < 1.0f) && (LINK_IS_CHILD)) {
// rock spawn pos X, Z near player
tempVec2X = Rand_CenteredFloat(10.0f) + player->actor.world.pos.x;
tempVec2Z = Rand_CenteredFloat(10.0f) + player->actor.world.pos.z;
} else {
if (player->linearVelocity != 0.0f) {
// rock spawn pos is between 300 and 600 units from the camera depending on the camera yaw.
// Rocks will generally spawn closer to the camera in the X axis than in the Z axis.
tempVec2X = Rand_CenteredFloat(200.0f) + (globalCtx->view.eye.x + (tempVec2X * 300.0f));
tempVec2Z = Rand_CenteredFloat(50.0f) + (globalCtx->view.eye.z + (tempVec2Z * 600.0f));
} else {
// rock spawn pos X, Z near player
tempVec2X = Rand_CenteredFloat(10.0f) + player->actor.world.pos.x;
tempVec2Z = Rand_CenteredFloat(10.0f) + player->actor.world.pos.z;
}
spawnedRockType = FIRE_ROCK_SPAWNED_FALLING2;
}
} else {
this->timerBetweenRockSpawns = 50;
spawnedRockType = FIRE_ROCK_SPAWNED_FALLING2;
// rock spawn pos X,Z at a random position roughly 300 units ahead of camera
tempVec2X = Rand_CenteredFloat(100.0f) + tempVec1X;
tempVec2Z = Rand_CenteredFloat(100.0f) + tempVec1Z;
if (Rand_ZeroFloat(3.99f) < 1.0f) {
// rock spawn pos X,Z at a random position near player
tempVec2X = Rand_CenteredFloat(70.0f) + player->actor.world.pos.x;
tempVec2Z = Rand_CenteredFloat(70.0f) + player->actor.world.pos.z;
}
}
spawnedRock =
(EnFireRock*)Actor_SpawnAsChild(&globalCtx->actorCtx, &this->actor, globalCtx, ACTOR_EN_FIRE_ROCK,
tempVec2X, tempVec1Y, tempVec2Z, 0, 0, 0, spawnedRockType);
if (spawnedRock != NULL) {
spawnedRock->spawner = this;
this->numSpawnedRocks++;
return;
}
// "☆☆☆☆☆ Can't occur! ☆☆☆☆☆"
osSyncPrintf(VT_FGCOL(GREEN) "☆☆☆☆☆ 発生できません! ☆☆☆☆☆\n" VT_RST);
osSyncPrintf(VT_FGCOL(GREEN) "☆☆☆☆☆ 発生できません! ☆☆☆☆☆\n" VT_RST);
osSyncPrintf(VT_FGCOL(GREEN) "☆☆☆☆☆ 発生できません! ☆☆☆☆☆\n" VT_RST);
osSyncPrintf(VT_FGCOL(GREEN) "☆☆☆☆☆ 発生できません! ☆☆☆☆☆\n" VT_RST);
osSyncPrintf(VT_FGCOL(GREEN) "☆☆☆☆☆ 発生できません! ☆☆☆☆☆\n\n" VT_RST);
}
}
}
void EnEncount2_Update(Actor* thisx, GlobalContext* globalCtx2) {
EnEncount2* this = THIS;
GlobalContext* globalCtx = globalCtx2;
if (this->deathMountainSpawnerTimer != 0) {
this->deathMountainSpawnerTimer--;
}
if (this->timerBetweenRockSpawns != 0) {
this->timerBetweenRockSpawns--;
}
if (this->particleSpawnTimer != 0) {
this->particleSpawnTimer--;
}
this->actionFunc(this, globalCtx);
EnEncount2_ParticleUpdate(this, globalCtx);
if (!this->isNotDeathMountain) {
this->unk17C = this->envEffectsTimer / 60.0f;
this->unk160 = this->unk17C * -50.0f;
globalCtx->envCtx.unk_8C[0][0] = (s16)this->unk160 * -1.5f;
globalCtx->envCtx.unk_8C[0][1] = globalCtx->envCtx.unk_8C[0][2] = this->unk160;
this->unk168 = this->unk17C * -20.0f;
globalCtx->envCtx.unk_8C[1][0] = (s16)this->unk168 * -1.5f;
globalCtx->envCtx.unk_8C[1][1] = globalCtx->envCtx.unk_8C[1][2] = this->unk168;
this->unk170 = this->unk17C * -50.0f;
globalCtx->envCtx.unk_9E = this->unk170;
globalCtx->envCtx.unk_8C[2][0] = (u8)((160.0f - globalCtx->envCtx.unk_CF[0]) * this->unk17C);
globalCtx->envCtx.unk_8C[2][1] = (u8)((160.0f - globalCtx->envCtx.unk_CF[1]) * this->unk17C);
globalCtx->envCtx.unk_8C[2][2] = (u8)((150.0f - globalCtx->envCtx.unk_CF[2]) * this->unk17C);
}
}
void EnEncount2_Draw(Actor* thisx, GlobalContext* globalCtx) {
EnEncount2* this = THIS;
EnEncount2_ParticleDraw(&this->actor, globalCtx);
}
void EnEncount2_ParticleInit(EnEncount2* this, Vec3f* particlePos, f32 scale) {
EnEncount2Particle* particle = this->particles;
s16 i;
for (i = 0; i < ARRAY_COUNT(this->particles); i++, particle++) {
if (!particle->isAlive) {
particle->pos = *particlePos;
particle->scale = scale;
particle->rot.x = 0.0f;
particle->rot.y = 0.0f;
particle->rot.z = 0.0f;
particle->moveDirection.x = Rand_CenteredFloat(20.0f);
particle->moveDirection.y = -20.0f;
particle->moveDirection.z = Rand_CenteredFloat(20.0f);
particle->isAlive = 1;
break;
}
}
}
void EnEncount2_ParticleUpdate(EnEncount2* this, GlobalContext* globalCtx) {
s16 i;
EnEncount2Particle* particle = this->particles;
Player* player = PLAYER;
Vec3f targetPos;
for (i = 0; i < ARRAY_COUNT(this->particles); particle++, i++) {
if (particle->isAlive) {
particle->rot.x += Rand_ZeroOne() * 500.0f;
particle->rot.y += Rand_ZeroOne() * 500.0f;
particle->rot.z += Rand_ZeroOne() * 500.0f;
targetPos.x = particle->pos.x + particle->moveDirection.x;
targetPos.y = particle->pos.y + particle->moveDirection.y;
targetPos.z = particle->pos.z + particle->moveDirection.z;
Math_ApproachF(&particle->pos.x, targetPos.x, 0.3f, 30.0f);
Math_ApproachF(&particle->pos.y, targetPos.y, 0.8f, 250.0f);
Math_ApproachF(&particle->pos.z, targetPos.z, 0.3f, 30.0f);
Math_ApproachF(&particle->moveDirection.y, -20.0f, 0.9f, 1.0f);
if (globalCtx->sceneNum != SCENE_SPOT16) {
if (particle->pos.y < (player->actor.floorHeight - 50.0f)) {
particle->isAlive = 0;
}
} else if (particle->pos.y < 1500.0f) {
particle->isAlive = 0;
}
}
}
}
void EnEncount2_ParticleDraw(Actor* thisx, GlobalContext* globalCtx) {
EnEncount2* this = THIS;
EnEncount2Particle* particle = this->particles;
GraphicsContext* gfxCtx = globalCtx->state.gfxCtx;
s16 i;
s32 objBankIndex;
OPEN_DISPS(gfxCtx, "../z_en_encount2.c", 642);
objBankIndex = Object_GetIndex(&globalCtx->objectCtx, OBJECT_EFC_STAR_FIELD);
if (objBankIndex >= 0) {
gDPPipeSync(POLY_XLU_DISP++);
gSPSegment(POLY_OPA_DISP++, 0x06, globalCtx->objectCtx.status[objBankIndex].segment);
for (i = 0; i < ARRAY_COUNT(this->particles); particle++, i++) {
if (particle->isAlive) {
Matrix_Translate(particle->pos.x, particle->pos.y, particle->pos.z, MTXMODE_NEW);
Matrix_RotateX(particle->rot.x * (M_PI / 180), MTXMODE_APPLY);
Matrix_RotateY(particle->rot.y * (M_PI / 180), MTXMODE_APPLY);
Matrix_RotateZ(particle->rot.z * (M_PI / 180), MTXMODE_APPLY);
Matrix_Scale(particle->scale, particle->scale, particle->scale, MTXMODE_APPLY);
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 155, 55, 255);
gDPSetEnvColor(POLY_OPA_DISP++, 155, 255, 55, 255);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_en_encount2.c", 669),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_OPA_DISP++, D_06000DE0);
}
}
}
CLOSE_DISPS(gfxCtx, "../z_en_encount2.c", 678);
}

View file

@ -6,11 +6,36 @@
struct EnEncount2;
typedef void (*EnEncount2ActionFunc)(struct EnEncount2*, GlobalContext*);
typedef struct {
/* 0x0000 */ Vec3f pos;
/* 0x000C */ f32 scale;
/* 0x0010 */ u8 isAlive;
/* 0x0014 */ Vec3f moveDirection;
/* 0x0020 */ Vec3f rot;
} EnEncount2Particle; // size = 0x2C
typedef struct EnEncount2 {
/* 0x0000 */ Actor actor;
/* 0x014C */ char unk_14C[0x10];
/* 0x015C */ u16 unk_15C;
/* 0x015E */ char unk_15E[0x8C2];
/* 0x014C */ EnEncount2ActionFunc actionFunc;
/* 0x0150 */ char unk150[0x4];
/* 0x0154 */ s16 deathMountainSpawnerTimer;
/* 0x0156 */ s16 timerBetweenRockSpawns;
/* 0x0158 */ s16 numSpawnedRocks;
/* 0x015A */ s16 isNotDeathMountain;
/* 0x015C */ s16 collapseSpawnerInactive;
/* 0x015E */ s16 particleSpawnTimer;
/* 0x0160 */ f32 unk160;
/* 0x0164 */ char unk164[0x4];
/* 0x0168 */ f32 unk168;
/* 0x016C */ char unk16C[0x4];
/* 0x0178 */ f32 unk170;
/* 0x0174 */ char unk174[0x4];
/* 0x0178 */ s16 envEffectsTimer;
/* 0x017C */ f32 unk17C;
/* 0x0180 */ u64 isQuaking;
/* 0x0188 */ EnEncount2Particle particles[50];
} EnEncount2; // size = 0x0A20
extern const ActorInit En_Encount2_InitVars;