Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "z_arms_hook.h"
- #define FLAGS 0x00000030
- #define THIS ((ArmsHook*)thisx)
- void ArmsHook_Init(Actor* thisx, GlobalContext* globalCtx);
- void ArmsHook_Destroy(Actor* thisx, GlobalContext* globalCtx);
- void ArmsHook_Update(Actor* thisx, GlobalContext* globalCtx);
- void ArmsHook_Draw(Actor* thisx, GlobalContext* globalCtx);
- void ArmsHook_Wait(ArmsHook* this, GlobalContext* globalCtx);
- void ArmsHook_Shoot(ArmsHook* this, GlobalContext* globalCtx);
- /*
- const ActorInit Arms_Hook_InitVars = {
- ACTOR_ARMS_HOOK,
- ACTORTYPE_ITEMACTION,
- FLAGS,
- GAMEPLAY_KEEP,
- sizeof(ArmsHook),
- (ActorFunc)ArmsHook_Init,
- (ActorFunc)ArmsHook_Destroy,
- (ActorFunc)ArmsHook_Update,
- (ActorFunc)ArmsHook_Draw
- };
- */
- extern ColQuadInit D_808C1BC0;
- extern Vec3f D_808C1C10;
- extern Vec3f D_808C1C28;
- extern Vec3f D_808C1C34;
- extern Vec3f D_808C1C1C;
- extern Vec3f D_808C1C40;
- extern Vec3f D_808C1C4C;
- extern Gfx D_0601D960[];
- extern Gfx D_040008D0[];
- void ArmsHook_SetupAction(ArmsHook* this, ArmsHookActionFunc actionFunc) {
- this->actionFunc = actionFunc;
- }
- void ArmsHook_Init(Actor* thisx, GlobalContext* globalCtx) {
- ArmsHook* this = THIS;
- Collision_InitQuadDefault(globalCtx, &this->collider);
- Collision_InitQuadWithData(globalCtx, &this->collider, &this->actor, &D_808C1BC0);
- ArmsHook_SetupAction(this, ArmsHook_Wait);
- this->unk_1E0 = this->actor.currPosRot.pos;
- }
- void ArmsHook_Destroy(Actor* thisx, GlobalContext* globalCtx) {
- ArmsHook* this = THIS;
- if (this->grabbed != NULL) {
- this->grabbed->flags &= ~0x2000;
- }
- Collision_FiniQuad(globalCtx, &this->collider);
- }
- void ArmsHook_Wait(ArmsHook* this, GlobalContext* globalCtx) {
- if (this->actor.parent == NULL) {
- ArmsHook_SetupAction(this, ArmsHook_Shoot);
- func_800B6C04(&this->actor, 20.0f);
- this->actor.parent = &PLAYER->base;
- this->timer = 26;
- }
- }
- void func_808C1154(ArmsHook* this) {
- this->actor.child = this->actor.parent;
- this->actor.parent->parent = &this->actor;
- }
- s32 ArmsHook_AttachToPlayer(ArmsHook* this, ActorPlayer* player) {
- player->base.child = &this->actor;
- player->heldActor = &this->actor;
- if (this->actor.child != NULL) {
- player->base.parent = this->actor.child = NULL;
- return 1;
- }
- return 0;
- }
- void ArmsHook_DetachHookFromActor(ArmsHook* this) {
- if (this->grabbed != NULL) {
- this->grabbed->flags &= ~0x2000;
- this->grabbed = NULL;
- }
- }
- s32 ArmsHook_CheckForCancel(ArmsHook* this) {
- ActorPlayer* player = (ActorPlayer*)this->actor.parent;
- if (func_801240C8(player)) {
- if ((player->heldItemActionParam != player->unk147) || ((player->base.flags & 0x100)) ||
- ((player->stateFlags1 & 0x4000080))) {
- this->timer = 0;
- ArmsHook_DetachHookFromActor(this);
- Math_Vec3f_Copy(&this->actor.currPosRot.pos, &player->unk368);
- return 1;
- }
- }
- return 0;
- }
- void ArmsHook_AttachHookToActor(ArmsHook* this, Actor* actor) {
- actor->flags |= 0x2000;
- this->grabbed = actor;
- Math_Vec3f_Diff(&actor->currPosRot.pos, &this->actor.currPosRot.pos, &this->unk_1FC);
- }
- void ArmsHook_Shoot(ArmsHook* this, GlobalContext* globalCtx) {
- ActorPlayer* player = PLAYER;
- if ((this->actor.parent == NULL) || (!func_801240C8(player))) {
- ArmsHook_DetachHookFromActor(this);
- Actor_MarkForDeath(&this->actor);
- return;
- }
- func_800B8F98(&player->base, 0x100B);
- ArmsHook_CheckForCancel(this);
- if (this->timer != 0 && (this->collider.base.flagsAT & 2) && (this->collider.body.unk20->unk14 != 4)) {
- Actor* touchedActor = this->collider.base.collisionAT;
- if ((touchedActor->update != NULL) && (touchedActor->flags & 0x600)) {
- if (this->collider.body.unk20->unk16 & 4) {
- ArmsHook_AttachHookToActor(this, touchedActor);
- if ((touchedActor->flags & 0x400) == 0x400) {
- func_808C1154(this);
- }
- }
- }
- this->timer = 0;
- func_8019F1C0(&this->actor.projectedPos, 0x1814);
- return;
- }
- if (DECR(this->timer) == 0) {
- Actor* grabbed;
- Vec3f bodyDistDiffVec;
- Vec3f newPos;
- f32 bodyDistDiff;
- f32 phi_f16;
- s32 pad;
- grabbed = this->grabbed;
- if (grabbed != NULL) {
- if ((grabbed->update == NULL) || (grabbed->flags & 0x2000) != 0x2000) {
- grabbed = NULL;
- this->grabbed = NULL;
- } else {
- if (this->actor.child != NULL) {
- f32 sp94 = Actor_DistanceBetweenActors(&this->actor, grabbed);
- f32 sp90 =
- sqrtf(SQ(this->unk_1FC.x) + SQ(this->unk_1FC.y) + SQ(this->unk_1FC.z));
- Math_Vec3f_Diff(&grabbed->currPosRot.pos, &this->unk_1FC, &this->actor.currPosRot.pos);
- if (50.0f < (sp94 - sp90)) {
- ArmsHook_DetachHookFromActor(this);
- grabbed = NULL;
- }
- }
- }
- }
- {
- f32 velocity;
- bodyDistDiff = Math_Vec3f_DistXYZAndStoreDiff(&player->unk368, &this->actor.currPosRot.pos, &bodyDistDiffVec);
- if (bodyDistDiff < 30.0f) {
- velocity = 0.0f;
- phi_f16 = 0.0f;
- } else {
- if (this->actor.child != NULL) {
- velocity = 30.0f;
- } else {
- if (grabbed != NULL) {
- velocity = 50.0f;
- } else {
- velocity = 200.0f;
- }
- }
- phi_f16 = bodyDistDiff - velocity;
- if (bodyDistDiff <= velocity) {
- phi_f16 = 0.0f;
- }
- velocity = phi_f16 / bodyDistDiff;
- }
- newPos.x = bodyDistDiffVec.x * velocity;
- newPos.y = bodyDistDiffVec.y * velocity;
- newPos.z = bodyDistDiffVec.z * velocity;
- }
- if (this->actor.child == NULL) {
- Math_Vec3f_Sum(&player->unk368, &newPos, &this->actor.currPosRot.pos);
- if (grabbed != NULL) {
- Math_Vec3f_Sum(&this->actor.currPosRot.pos, &this->unk_1FC, &grabbed->currPosRot.pos);
- }
- } else {
- Math_Vec3f_Diff(&bodyDistDiffVec, &newPos, &player->base.velocity);
- player->base.currPosRot.rot.x =
- atans_flip(sqrtf(SQ(bodyDistDiffVec.x) + SQ(bodyDistDiffVec.z)), -bodyDistDiffVec.y);
- }
- if (phi_f16 < 50.0f) {
- ArmsHook_DetachHookFromActor(this);
- if (phi_f16 == 0.0f) {
- ArmsHook_SetupAction(this, ArmsHook_Wait);
- if (ArmsHook_AttachToPlayer(this, player)) {
- Math_Vec3f_Diff(&this->actor.currPosRot.pos, &player->base.currPosRot.pos, &player->base.velocity);
- player->base.velocity.y -= 20.0f;
- }
- }
- }
- } else {
- BgPolygon* poly;
- u32 dynaPolyID;
- Vec3f sp78;
- Vec3f prevFrameDiff;
- Vec3f sp60;
- Actor_SetVelocityAndMoveYRotationAndGravity(&this->actor);
- Math_Vec3f_Diff(&this->actor.currPosRot.pos, &this->actor.lastPos, &prevFrameDiff);
- Math_Vec3f_Sum(&this->unk_1E0, &prevFrameDiff, &this->unk_1E0);
- this->actor.shape.rot.x = atans_flip(this->actor.speedXZ, -this->actor.velocity.y);
- sp60.x = this->unk_1EC.x - (this->unk_1E0.x - this->unk_1EC.x);
- sp60.y = this->unk_1EC.y - (this->unk_1E0.y - this->unk_1EC.y);
- sp60.z = this->unk_1EC.z - (this->unk_1E0.z - this->unk_1EC.z);
- if (func_800C55C4(&globalCtx->colCtx, &sp60, &this->unk_1E0, &sp78, &poly, 1, 1, 1, 1, &dynaPolyID) != 0 &&
- (func_800B90AC(globalCtx, &this->actor, poly, dynaPolyID, &sp78) == 0 || func_800C576C(&globalCtx->colCtx, &sp60, &this->unk_1E0, &sp78, &poly, 1, 1, 1, 1, &dynaPolyID) != 0)) {
- f32 sp5C = poly->normal.x * (1 / SHT_MAX);
- f32 sp58 = poly->normal.z * (1 / SHT_MAX);
- Math_Vec3f_Copy(&this->actor.currPosRot.pos, &sp78);
- this->actor.currPosRot.pos.x += 10.0f * sp5C;
- this->actor.currPosRot.pos.z += 10.0f * sp58;
- this->timer = 1;
- if (func_800C9CEC(&globalCtx->colCtx, poly, dynaPolyID)) {
- {
- DynaPolyActor* dynaPolyActor;
- if (dynaPolyID != 0x32 && (dynaPolyActor = BgCheck_GetActorOfMesh(&globalCtx->colCtx, dynaPolyID)) != NULL) {
- ArmsHook_AttachHookToActor(this, &dynaPolyActor->actor);
- }
- }
- func_808C1154(this);
- func_8019F1C0(&this->actor.projectedPos, 0x1829);
- } else {
- func_800E8668(globalCtx, &this->actor.currPosRot.pos);
- func_8019F1C0(&this->actor.projectedPos, 0x1813);
- }
- } else {
- if ((globalCtx->state.input[0].pressEdge.buttons & 0xC01F)) {
- s32 pad;
- this->timer = 1;
- }
- }
- }
- }
- void ArmsHook_Update(Actor* thisx, GlobalContext* globalCtx) {
- ArmsHook* this = THIS;
- this->actionFunc(this, globalCtx);
- this->unk_1EC = this->unk_1E0;
- }
- void ArmsHook_Draw(Actor *thisx, GlobalContext *globalCtx) {
- ArmsHook* this = THIS;
- s32 pad;
- ActorPlayer* player = PLAYER;
- Vec3f sp68;
- Vec3f sp5C;
- Vec3f sp50;
- f32 sp4C;
- f32 sp48;
- if (player->base.draw != NULL && player->unk151 == 0xB) {
- // OPEN_DISP macro
- {
- GraphicsContext *sp44 = globalCtx->state.gfxCtx;
- f32 f0;
- if ((ArmsHook_Shoot != this->actionFunc) || (this->timer <= 0)) {
- SysMatrix_MultiplyVector3fByState(&D_808C1C10, &this->unk_1E0);
- SysMatrix_MultiplyVector3fByState(&D_808C1C28, &sp5C);
- SysMatrix_MultiplyVector3fByState(&D_808C1C34, &sp50);
- this->unk_1C4 = 0;
- } else {
- SysMatrix_MultiplyVector3fByState(&D_808C1C1C, &this->unk_1E0);
- SysMatrix_MultiplyVector3fByState(&D_808C1C40, &sp5C);
- SysMatrix_MultiplyVector3fByState(&D_808C1C4C, &sp50);
- }
- func_80126440(globalCtx, &this->collider.base, &this->unk_1C4, &sp5C, &sp50);
- func_8012C28C(globalCtx->state.gfxCtx);
- func_80122868(globalCtx, player);
- gSPMatrix(sp44->polyOpa.p++, SysMatrix_AppendStateToPolyOpaDisp(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
- gSPDisplayList(sp44->polyOpa.p++, D_0601D960);
- SysMatrix_InsertTranslation(this->actor.currPosRot.pos.x, this->actor.currPosRot.pos.y, this->actor.currPosRot.pos.z, 0);
- Math_Vec3f_Diff(&player->unk368, &this->actor.currPosRot.pos, &sp68);
- sp48 = SQ(sp68.x) + SQ(sp68.z);
- sp4C = sqrtf(sp48);
- SysMatrix_InsertYRotation_s(atans(sp68.x, sp68.z), 1);
- SysMatrix_InsertXRotation_s(atans(-sp68.y, sp4C), 1);
- f0 = sqrtf(SQ(sp68.y) + sp48);
- SysMatrix_InsertScale(0.015f, 0.015f, f0 * 0.01f, 1);
- gSPMatrix(sp44->polyOpa.p++, SysMatrix_AppendStateToPolyOpaDisp(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
- gSPDisplayList(sp44->polyOpa.p++, D_040008D0);
- func_801229A0(globalCtx, player);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement