Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void EnBoom_Fly(EnBoom* this, GlobalContext* globalCtx)
- {
- Actor* target;
- Player* player;
- s32 collided;
- s16 yawTarget;
- s16 yawDiff;
- s16 pitchTarget;
- s16 pitchDiff;
- s32 pad1;
- f32 distXYZScale;
- f32 distFromLink;
- DynaPolyActor* hitActor;
- u32 hitDynaID;
- Vec3f hitPoint;
- s32 pad2;
- player = PLAYER;
- target = this->moveTo;
- // If the boomerang is moving toward a targeted actor, handle setting the proper x and y angle to fly toward it.
- if (target != NULL)
- {
- yawTarget = func_8002DAC0(&this->actor, &target->posRot2.pos);
- yawDiff = this->actor.posRot.rot.y - yawTarget;
- pitchTarget = func_8002DB28(&this->actor, &target->posRot2.pos);
- pitchDiff = this->actor.posRot.rot.x - pitchTarget;
- distXYZScale = ((200.0f - Math_Vec3f_DistXYZ(&this->actor.posRot.pos, &target->posRot2.pos)) * 0.005f);
- if (distXYZScale < 0.12f)
- distXYZScale = 0.12f;
- if ((target != (Actor*)player) && ((target->update == NULL) || (ABS(yawDiff) > 0x4000)))
- {
- // BUG: This condition is why the boomerang will randomly fly off in a the down left direction sometimes.
- // If the actor targetted is not Link and the difference between the 2 y angles is greater than 0x4000,
- // the moveTo pointer is nulled and it flies off in a seemingly random direction.
- this->moveTo = NULL;
- }
- else
- {
- Math_ApproxUpdateScaledS(&this->actor.posRot.rot.y, yawTarget, (s16)(ABS(yawDiff) * distXYZScale));
- Math_ApproxUpdateScaledS(&this->actor.posRot.rot.x, pitchTarget, (s16)(ABS(pitchDiff) * distXYZScale));
- }
- }
- // Set xyz speed, move forward, and play the boomerang sound
- func_8002D9A4(&this->actor, 12.0f);
- Actor_MoveForward(&this->actor);
- func_8002F974(this, 0x1010);
- // If the boomerang collides with EnItem00 or a Skulltula token, set grabbed pointer to pick it up
- collided = (this->collider.colliderFlags & 0x2);
- collided = (!!(collided));
- if (collided)
- {
- if (((this->collider.at->id == ACTOR_EN_ITEM00) || (this->collider.at->id == ACTOR_EN_SI)))
- {
- this->grabbed = this->collider.at;
- if (this->collider.at->id == ACTOR_EN_SI)
- {
- this->collider.at->flags |= 0x2000;
- }
- }
- }
- // Decrement the return timer and check if its 0. If it is, check if Link can catch it and handle accordingly.
- // Otherwise handle grabbing and colliding.
- if (DECR(this->returnTimer) == 0)
- {
- distFromLink = Math_Vec3f_DistXYZ(&this->actor.posRot.pos, &player->actor.posRot2.pos);
- this->moveTo = player;
- //If the boomerang is less than 40 units away from Link, he can catch it.
- if (distFromLink < 40.0f)
- {
- target = this->grabbed;
- if (target != NULL)
- {
- // Copy Link's position to the grabbed actor.
- Math_Vec3f_Copy(&target->posRot.pos, &player->actor.posRot.pos);
- // If the grabbed actor is EnItem00 (HP/Key etc) set gravity and flags so it falls in front of Link.
- // Otherwise if its a Skulltula Token, just set flags so he collides with it to collect it.
- if (target->id == ACTOR_EN_ITEM00)
- {
- target->gravity = -0.9f;
- target->bgCheckFlags &= ~0x03;
- }
- else
- {
- target->flags &= ~0x2000;
- }
- }
- //Set player flags and kill the boomerang beacause Link caught it.
- player->stateFlags1 &= ~0x02000000;
- Actor_Kill(&this->actor);
- }
- }
- else
- {
- collided = (this->collider.colliderFlags & 0x2);
- collided = (!!(collided));
- if (collided)
- {
- // Copy the position from the prevous frame to the boomerang to start the bounce back.
- Math_Vec3f_Copy(&this->actor.posRot.pos, &this->actor.pos4);
- }
- else
- {
- collided = func_8003DE84(&globalCtx->colCtx, &this->actor.pos4, &this->actor.posRot.pos, &hitPoint,
- &this->actor.wallPoly, 1, 1, 1, 1, &hitDynaID);
- if (collided != 0)
- {
- // If the boomerang coolides with something and its is a Jabu Object actor with params equal to 0, then
- // set collided to 0 so that the boomerang will go through the wall.
- // Otherwise play a clank sound and keep collided set to bounce back.
- if ((func_8002F9EC(globalCtx, &this->actor, this->actor.wallPoly, hitDynaID, &hitPoint) != 0) ||
- ((hitDynaID != 0x32) && ((hitActor = DynaPolyInfo_GetActor(&globalCtx->colCtx, hitDynaID)) != NULL) && (hitActor->actor.id == ACTOR_BG_BDAN_OBJECTS) && (hitActor->actor.params == 0)))
- {
- collided = 0;
- }
- else
- {
- func_80062D60(globalCtx, &hitPoint);
- }
- }
- }
- // If the boomerang collided with something, set angle properly so it can bounce back.
- // Set timer to 0 and set return actor to player so it goes back to Link.
- if (collided != 0)
- {
- this->actor.posRot.rot.x = -this->actor.posRot.rot.x;
- this->actor.posRot.rot.y += 0x8000;
- this->moveTo = player;
- this->returnTimer = 0;
- }
- }
- // If the actor the boomerang is holding has a null update function, set grabbed to null.
- // Otherwise, copy the position from the boomerang to the actor to move it.
- target = this->grabbed;
- if (target != NULL)
- {
- if (target->update == NULL)
- {
- this->grabbed = NULL;
- }
- else
- {
- // SRM ;)
- Math_Vec3f_Copy(&target->posRot.pos, &this->actor.posRot.pos);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement