Advertisement
fggkyle

hookshot decomp

Sep 27th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.66 KB | None | 0 0
  1. #include "z_arms_hook.h"
  2.  
  3. #define FLAGS 0x00000030
  4.  
  5. #define THIS ((ArmsHook*)thisx)
  6.  
  7. void ArmsHook_Init(Actor* thisx, GlobalContext* globalCtx);
  8. void ArmsHook_Destroy(Actor* thisx, GlobalContext* globalCtx);
  9. void ArmsHook_Update(Actor* thisx, GlobalContext* globalCtx);
  10. void ArmsHook_Draw(Actor* thisx, GlobalContext* globalCtx);
  11.  
  12. void ArmsHook_Wait(ArmsHook* this, GlobalContext* globalCtx);
  13. void ArmsHook_Shoot(ArmsHook* this, GlobalContext* globalCtx);
  14.  
  15. /*
  16. const ActorInit Arms_Hook_InitVars = {
  17. ACTOR_ARMS_HOOK,
  18. ACTORTYPE_ITEMACTION,
  19. FLAGS,
  20. GAMEPLAY_KEEP,
  21. sizeof(ArmsHook),
  22. (ActorFunc)ArmsHook_Init,
  23. (ActorFunc)ArmsHook_Destroy,
  24. (ActorFunc)ArmsHook_Update,
  25. (ActorFunc)ArmsHook_Draw
  26. };
  27. */
  28.  
  29. extern ColQuadInit D_808C1BC0;
  30.  
  31. extern Vec3f D_808C1C10;
  32. extern Vec3f D_808C1C28;
  33. extern Vec3f D_808C1C34;
  34. extern Vec3f D_808C1C1C;
  35. extern Vec3f D_808C1C40;
  36. extern Vec3f D_808C1C4C;
  37.  
  38. extern Gfx D_0601D960[];
  39. extern Gfx D_040008D0[];
  40.  
  41. void ArmsHook_SetupAction(ArmsHook* this, ArmsHookActionFunc actionFunc) {
  42. this->actionFunc = actionFunc;
  43. }
  44.  
  45. void ArmsHook_Init(Actor* thisx, GlobalContext* globalCtx) {
  46. ArmsHook* this = THIS;
  47.  
  48. Collision_InitQuadDefault(globalCtx, &this->collider);
  49. Collision_InitQuadWithData(globalCtx, &this->collider, &this->actor, &D_808C1BC0);
  50. ArmsHook_SetupAction(this, ArmsHook_Wait);
  51. this->unk_1E0 = this->actor.currPosRot.pos;
  52. }
  53.  
  54. void ArmsHook_Destroy(Actor* thisx, GlobalContext* globalCtx) {
  55. ArmsHook* this = THIS;
  56.  
  57. if (this->grabbed != NULL) {
  58. this->grabbed->flags &= ~0x2000;
  59. }
  60. Collision_FiniQuad(globalCtx, &this->collider);
  61. }
  62.  
  63. void ArmsHook_Wait(ArmsHook* this, GlobalContext* globalCtx) {
  64. if (this->actor.parent == NULL) {
  65. ArmsHook_SetupAction(this, ArmsHook_Shoot);
  66. func_800B6C04(&this->actor, 20.0f);
  67. this->actor.parent = &PLAYER->base;
  68. this->timer = 26;
  69. }
  70. }
  71.  
  72. void func_808C1154(ArmsHook* this) {
  73. this->actor.child = this->actor.parent;
  74. this->actor.parent->parent = &this->actor;
  75. }
  76.  
  77. s32 ArmsHook_AttachToPlayer(ArmsHook* this, ActorPlayer* player) {
  78. player->base.child = &this->actor;
  79. player->heldActor = &this->actor;
  80. if (this->actor.child != NULL) {
  81. player->base.parent = this->actor.child = NULL;
  82. return 1;
  83. }
  84. return 0;
  85. }
  86.  
  87. void ArmsHook_DetachHookFromActor(ArmsHook* this) {
  88. if (this->grabbed != NULL) {
  89. this->grabbed->flags &= ~0x2000;
  90. this->grabbed = NULL;
  91. }
  92. }
  93.  
  94. s32 ArmsHook_CheckForCancel(ArmsHook* this) {
  95. ActorPlayer* player = (ActorPlayer*)this->actor.parent;
  96. if (func_801240C8(player)) {
  97. if ((player->heldItemActionParam != player->unk147) || ((player->base.flags & 0x100)) ||
  98. ((player->stateFlags1 & 0x4000080))) {
  99. this->timer = 0;
  100. ArmsHook_DetachHookFromActor(this);
  101. Math_Vec3f_Copy(&this->actor.currPosRot.pos, &player->unk368);
  102. return 1;
  103. }
  104. }
  105. return 0;
  106. }
  107.  
  108. void ArmsHook_AttachHookToActor(ArmsHook* this, Actor* actor) {
  109. actor->flags |= 0x2000;
  110. this->grabbed = actor;
  111. Math_Vec3f_Diff(&actor->currPosRot.pos, &this->actor.currPosRot.pos, &this->unk_1FC);
  112. }
  113.  
  114. void ArmsHook_Shoot(ArmsHook* this, GlobalContext* globalCtx) {
  115. ActorPlayer* player = PLAYER;
  116.  
  117. if ((this->actor.parent == NULL) || (!func_801240C8(player))) {
  118. ArmsHook_DetachHookFromActor(this);
  119. Actor_MarkForDeath(&this->actor);
  120. return;
  121. }
  122.  
  123. func_800B8F98(&player->base, 0x100B);
  124. ArmsHook_CheckForCancel(this);
  125.  
  126. if (this->timer != 0 && (this->collider.base.flagsAT & 2) && (this->collider.body.unk20->unk14 != 4)) {
  127. Actor* touchedActor = this->collider.base.collisionAT;
  128. if ((touchedActor->update != NULL) && (touchedActor->flags & 0x600)) {
  129. if (this->collider.body.unk20->unk16 & 4) {
  130. ArmsHook_AttachHookToActor(this, touchedActor);
  131. if ((touchedActor->flags & 0x400) == 0x400) {
  132. func_808C1154(this);
  133. }
  134. }
  135. }
  136. this->timer = 0;
  137. func_8019F1C0(&this->actor.projectedPos, 0x1814);
  138.  
  139. return;
  140. }
  141.  
  142. if (DECR(this->timer) == 0) {
  143. Actor* grabbed;
  144. Vec3f bodyDistDiffVec;
  145. Vec3f newPos;
  146. f32 bodyDistDiff;
  147. f32 phi_f16;
  148. s32 pad;
  149.  
  150. grabbed = this->grabbed;
  151. if (grabbed != NULL) {
  152. if ((grabbed->update == NULL) || (grabbed->flags & 0x2000) != 0x2000) {
  153. grabbed = NULL;
  154. this->grabbed = NULL;
  155. } else {
  156. if (this->actor.child != NULL) {
  157. f32 sp94 = Actor_DistanceBetweenActors(&this->actor, grabbed);
  158. f32 sp90 =
  159. sqrtf(SQ(this->unk_1FC.x) + SQ(this->unk_1FC.y) + SQ(this->unk_1FC.z));
  160. Math_Vec3f_Diff(&grabbed->currPosRot.pos, &this->unk_1FC, &this->actor.currPosRot.pos);
  161. if (50.0f < (sp94 - sp90)) {
  162. ArmsHook_DetachHookFromActor(this);
  163. grabbed = NULL;
  164. }
  165. }
  166. }
  167. }
  168.  
  169. {
  170. f32 velocity;
  171.  
  172. bodyDistDiff = Math_Vec3f_DistXYZAndStoreDiff(&player->unk368, &this->actor.currPosRot.pos, &bodyDistDiffVec);
  173. if (bodyDistDiff < 30.0f) {
  174. velocity = 0.0f;
  175. phi_f16 = 0.0f;
  176. } else {
  177. if (this->actor.child != NULL) {
  178. velocity = 30.0f;
  179. } else {
  180. if (grabbed != NULL) {
  181. velocity = 50.0f;
  182. } else {
  183. velocity = 200.0f;
  184. }
  185. }
  186. phi_f16 = bodyDistDiff - velocity;
  187. if (bodyDistDiff <= velocity) {
  188. phi_f16 = 0.0f;
  189. }
  190. velocity = phi_f16 / bodyDistDiff;
  191. }
  192.  
  193. newPos.x = bodyDistDiffVec.x * velocity;
  194. newPos.y = bodyDistDiffVec.y * velocity;
  195. newPos.z = bodyDistDiffVec.z * velocity;
  196. }
  197.  
  198. if (this->actor.child == NULL) {
  199. Math_Vec3f_Sum(&player->unk368, &newPos, &this->actor.currPosRot.pos);
  200. if (grabbed != NULL) {
  201. Math_Vec3f_Sum(&this->actor.currPosRot.pos, &this->unk_1FC, &grabbed->currPosRot.pos);
  202. }
  203. } else {
  204. Math_Vec3f_Diff(&bodyDistDiffVec, &newPos, &player->base.velocity);
  205. player->base.currPosRot.rot.x =
  206. atans_flip(sqrtf(SQ(bodyDistDiffVec.x) + SQ(bodyDistDiffVec.z)), -bodyDistDiffVec.y);
  207. }
  208. if (phi_f16 < 50.0f) {
  209. ArmsHook_DetachHookFromActor(this);
  210. if (phi_f16 == 0.0f) {
  211. ArmsHook_SetupAction(this, ArmsHook_Wait);
  212. if (ArmsHook_AttachToPlayer(this, player)) {
  213. Math_Vec3f_Diff(&this->actor.currPosRot.pos, &player->base.currPosRot.pos, &player->base.velocity);
  214. player->base.velocity.y -= 20.0f;
  215. }
  216. }
  217. }
  218. } else {
  219. BgPolygon* poly;
  220. u32 dynaPolyID;
  221. Vec3f sp78;
  222. Vec3f prevFrameDiff;
  223. Vec3f sp60;
  224.  
  225. Actor_SetVelocityAndMoveYRotationAndGravity(&this->actor);
  226. Math_Vec3f_Diff(&this->actor.currPosRot.pos, &this->actor.lastPos, &prevFrameDiff);
  227. Math_Vec3f_Sum(&this->unk_1E0, &prevFrameDiff, &this->unk_1E0);
  228. this->actor.shape.rot.x = atans_flip(this->actor.speedXZ, -this->actor.velocity.y);
  229. sp60.x = this->unk_1EC.x - (this->unk_1E0.x - this->unk_1EC.x);
  230. sp60.y = this->unk_1EC.y - (this->unk_1E0.y - this->unk_1EC.y);
  231. sp60.z = this->unk_1EC.z - (this->unk_1E0.z - this->unk_1EC.z);
  232. if (func_800C55C4(&globalCtx->colCtx, &sp60, &this->unk_1E0, &sp78, &poly, 1, 1, 1, 1, &dynaPolyID) != 0 &&
  233. (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)) {
  234. f32 sp5C = poly->normal.x * (1 / SHT_MAX);
  235. f32 sp58 = poly->normal.z * (1 / SHT_MAX);
  236.  
  237. Math_Vec3f_Copy(&this->actor.currPosRot.pos, &sp78);
  238. this->actor.currPosRot.pos.x += 10.0f * sp5C;
  239. this->actor.currPosRot.pos.z += 10.0f * sp58;
  240. this->timer = 1;
  241. if (func_800C9CEC(&globalCtx->colCtx, poly, dynaPolyID)) {
  242. {
  243. DynaPolyActor* dynaPolyActor;
  244. if (dynaPolyID != 0x32 && (dynaPolyActor = BgCheck_GetActorOfMesh(&globalCtx->colCtx, dynaPolyID)) != NULL) {
  245. ArmsHook_AttachHookToActor(this, &dynaPolyActor->actor);
  246. }
  247. }
  248. func_808C1154(this);
  249. func_8019F1C0(&this->actor.projectedPos, 0x1829);
  250. } else {
  251. func_800E8668(globalCtx, &this->actor.currPosRot.pos);
  252. func_8019F1C0(&this->actor.projectedPos, 0x1813);
  253. }
  254. } else {
  255. if ((globalCtx->state.input[0].pressEdge.buttons & 0xC01F)) {
  256. s32 pad;
  257. this->timer = 1;
  258. }
  259. }
  260. }
  261. }
  262.  
  263. void ArmsHook_Update(Actor* thisx, GlobalContext* globalCtx) {
  264. ArmsHook* this = THIS;
  265.  
  266. this->actionFunc(this, globalCtx);
  267. this->unk_1EC = this->unk_1E0;
  268. }
  269.  
  270. void ArmsHook_Draw(Actor *thisx, GlobalContext *globalCtx) {
  271. ArmsHook* this = THIS;
  272. s32 pad;
  273. ActorPlayer* player = PLAYER;
  274. Vec3f sp68;
  275. Vec3f sp5C;
  276. Vec3f sp50;
  277. f32 sp4C;
  278. f32 sp48;
  279.  
  280. if (player->base.draw != NULL && player->unk151 == 0xB) {
  281. // OPEN_DISP macro
  282. {
  283. GraphicsContext *sp44 = globalCtx->state.gfxCtx;
  284. f32 f0;
  285.  
  286. if ((ArmsHook_Shoot != this->actionFunc) || (this->timer <= 0)) {
  287. SysMatrix_MultiplyVector3fByState(&D_808C1C10, &this->unk_1E0);
  288. SysMatrix_MultiplyVector3fByState(&D_808C1C28, &sp5C);
  289. SysMatrix_MultiplyVector3fByState(&D_808C1C34, &sp50);
  290. this->unk_1C4 = 0;
  291. } else {
  292. SysMatrix_MultiplyVector3fByState(&D_808C1C1C, &this->unk_1E0);
  293. SysMatrix_MultiplyVector3fByState(&D_808C1C40, &sp5C);
  294. SysMatrix_MultiplyVector3fByState(&D_808C1C4C, &sp50);
  295. }
  296. func_80126440(globalCtx, &this->collider.base, &this->unk_1C4, &sp5C, &sp50);
  297. func_8012C28C(globalCtx->state.gfxCtx);
  298. func_80122868(globalCtx, player);
  299.  
  300. gSPMatrix(sp44->polyOpa.p++, SysMatrix_AppendStateToPolyOpaDisp(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
  301. gSPDisplayList(sp44->polyOpa.p++, D_0601D960);
  302. SysMatrix_InsertTranslation(this->actor.currPosRot.pos.x, this->actor.currPosRot.pos.y, this->actor.currPosRot.pos.z, 0);
  303. Math_Vec3f_Diff(&player->unk368, &this->actor.currPosRot.pos, &sp68);
  304. sp48 = SQ(sp68.x) + SQ(sp68.z);
  305. sp4C = sqrtf(sp48);
  306. SysMatrix_InsertYRotation_s(atans(sp68.x, sp68.z), 1);
  307. SysMatrix_InsertXRotation_s(atans(-sp68.y, sp4C), 1);
  308. f0 = sqrtf(SQ(sp68.y) + sp48);
  309. SysMatrix_InsertScale(0.015f, 0.015f, f0 * 0.01f, 1);
  310. gSPMatrix(sp44->polyOpa.p++, SysMatrix_AppendStateToPolyOpaDisp(globalCtx->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
  311. gSPDisplayList(sp44->polyOpa.p++, D_040008D0);
  312. func_801229A0(globalCtx, player);
  313. }
  314. }
  315. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement