Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Player Knockback related functions #1601

Merged
merged 18 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,11 @@ void Actor_SetClosestSecretDistance(Actor* actor, PlayState* play);
s32 Actor_IsMounted(PlayState* play, Actor* horse);
u32 Actor_SetRideActor(PlayState* play, Actor* horse, s32 mountSide);
s32 Actor_NotMounted(PlayState* play, Actor* horse);
void func_8002F698(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4, u32 arg5, u32 arg6);
void func_8002F6D4(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4, u32 arg5);
void func_8002F71C(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4);
void func_8002F758(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4, u32 arg5);
void func_8002F7A0(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4);
void Actor_SetPlayerKnockback(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity, u32 type, u32 damage);
void Actor_SetPlayerKnockbackLarge(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity, u32 damage);
void Actor_SetPlayerKnockbackLargeNoDamage(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity);
void Actor_SetPlayerKnockbackSmall(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity, u32 damage);
void Actor_SetPlayerKnockbackSmallNoDamage(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity);
void Player_PlaySfx(Player* player, u16 sfxId);
void Actor_PlaySfx(Actor* actor, u16 sfxId);
void func_8002F850(PlayState* play, Actor* actor);
Expand Down
31 changes: 23 additions & 8 deletions include/z64player.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,21 @@ typedef enum {
/* 4 */ PLAYER_LEDGE_CLIMB_4
} PlayerLedgeClimbType;

typedef enum {
/* 0 */ PLAYER_KNOCKBACK_NONE,
/* 1 */ PLAYER_KNOCKBACK_SMALL,
/* 2 */ PLAYER_KNOCKBACK_LARGE,
/* 3 */ PLAYER_KNOCKBACK_LARGE_SHOCK
mzxrules marked this conversation as resolved.
Show resolved Hide resolved
} PlayerKnockbackType;

typedef enum {
/* 0 */ PLAYER_DAMAGE_RESPONSE_NONE,
/* 1 */ PLAYER_DAMAGE_RESPONSE_KNOCKBACK_LARGE,
/* 2 */ PLAYER_DAMAGE_RESPONSE_KNOCKBACK_SMALL,
/* 3 */ PLAYER_DAMAGE_RESPONSE_ICE_TRAP,
/* 4 */ PLAYER_DAMAGE_RESPONSE_ELECTRIC_SHOCK
} PlayerDamageResponseType;
fig02 marked this conversation as resolved.
Show resolved Hide resolved

typedef struct {
/* 0x00 */ f32 ceilingCheckHeight;
/* 0x04 */ f32 unk_04;
Expand Down Expand Up @@ -731,7 +746,7 @@ typedef struct Player {
/* 0x0450 */ Vec3f unk_450;
/* 0x045C */ Vec3f unk_45C;
/* 0x0468 */ char unk_468[0x002];
/* 0x046A */ union {
/* 0x046A */ union {
s16 haltActorsDuringCsAction; // If true, halt actors belonging to certain categories during a `csAction`
s16 slidingDoorBgCamIndex; // `BgCamIndex` used during a sliding door cutscene
} cv; // "Cutscene Variable": context dependent variable that has different meanings depending on what function is called
Expand Down Expand Up @@ -793,11 +808,11 @@ typedef struct Player {
/* 0x0847 */ s8 unk_847[4];
/* 0x084B */ s8 unk_84B[4];

/* 0x084F */ union {
/* 0x084F */ union {
s8 actionVar1;
} av1; // "Action Variable 1": context dependent variable that has different meanings depending on what action is currently running

/* 0x0850 */ union {
/* 0x0850 */ union {
s16 actionVar2;
} av2; // "Action Variable 2": context dependent variable that has different meanings depending on what action is currently running

Expand Down Expand Up @@ -831,11 +846,11 @@ typedef struct Player {
/* 0x089A */ s16 floorPitchAlt; // the calculation for this value is bugged and doesn't represent anything meaningful
/* 0x089C */ s16 unk_89C;
/* 0x089E */ u16 floorSfxOffset;
/* 0x08A0 */ u8 unk_8A0;
/* 0x08A1 */ u8 unk_8A1;
/* 0x08A2 */ s16 unk_8A2;
/* 0x08A4 */ f32 unk_8A4;
/* 0x08A8 */ f32 unk_8A8;
/* 0x08A0 */ u8 knockbackDamage;
/* 0x08A1 */ u8 knockbackType;
/* 0x08A2 */ s16 knockbackRot;
/* 0x08A4 */ f32 knockbackSpeed;
/* 0x08A8 */ f32 knockbackYVelocity;
/* 0x08AC */ f32 pushedSpeed; // Pushing player, examples include water currents, floor conveyors, climbing sloped surfaces
/* 0x08B0 */ s16 pushedYaw; // Yaw direction of player being pushed
/* 0x08B4 */ WeaponInfo meleeWeaponInfo[3];
Expand Down
77 changes: 63 additions & 14 deletions src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1768,30 +1768,79 @@ s32 Actor_NotMounted(PlayState* play, Actor* horse) {
}
}

void func_8002F698(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4, u32 arg5, u32 arg6) {
/**
* Sets the player's knockback properties
*
* @param play
* @param actor source actor applying knockback damage
* @param speed
* @param rot the direction the player will be pushed
* @param yVelocity
* @param type PlayerKnockbackType
* @param damage additional amount of damage to deal to the player
*/
void Actor_SetPlayerKnockback(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity, u32 type, u32 damage) {
Player* player = GET_PLAYER(play);

player->unk_8A0 = arg6;
player->unk_8A1 = arg5;
player->unk_8A2 = arg3;
player->unk_8A4 = arg2;
player->unk_8A8 = arg4;
player->knockbackDamage = damage;
player->knockbackType = type;
player->knockbackRot = rot;
player->knockbackSpeed = speed;
player->knockbackYVelocity = yVelocity;
}

void func_8002F6D4(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4, u32 arg5) {
func_8002F698(play, actor, arg2, arg3, arg4, 2, arg5);
/**
* Knocks the player to the ground
*
* @param play
* @param actor source actor applying knockback damage
* @param speed
* @param rot the direction the player will be pushed
* @param yVelocity
* @param damage additional amount of damage to deal to the player
*/
void Actor_SetPlayerKnockbackLarge(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity, u32 damage) {
Actor_SetPlayerKnockback(play, actor, speed, rot, yVelocity, PLAYER_KNOCKBACK_LARGE, damage);
}

void func_8002F71C(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4) {
func_8002F6D4(play, actor, arg2, arg3, arg4, 0);
/**
* Knocks the player to the ground, without applying additional damage
*
* @param play
* @param actor source actor applying knockback damage
* @param speed
* @param rot the direction the player will be pushed
* @param yVelocity
*/
void Actor_SetPlayerKnockbackLargeNoDamage(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity) {
Actor_SetPlayerKnockbackLarge(play, actor, speed, rot, yVelocity, 0);
}

void func_8002F758(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4, u32 arg5) {
func_8002F698(play, actor, arg2, arg3, arg4, 1, arg5);
/**
* Knocks the player back while keeping them on their feet
*
* @param play
* @param actor
* @param speed overridden
* @param rot the direction the player will be pushed
* @param yVelocity overridden
* @param damage additional amount of damage to deal to the player
*/
void Actor_SetPlayerKnockbackSmall(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity, u32 damage) {
Actor_SetPlayerKnockback(play, actor, speed, rot, yVelocity, PLAYER_KNOCKBACK_SMALL, damage);
}

void func_8002F7A0(PlayState* play, Actor* actor, f32 arg2, s16 arg3, f32 arg4) {
func_8002F758(play, actor, arg2, arg3, arg4, 0);
/**
* Knocks the player back while keeping them on their feet, without applying additional damage
*
* @param play
* @param actor
* @param speed overridden
* @param rot the direction the player will be pushed
* @param yVelocity overridden
*/
void Actor_SetPlayerKnockbackSmallNoDamage(PlayState* play, Actor* actor, f32 speed, s16 rot, f32 yVelocity) {
Actor_SetPlayerKnockbackSmall(play, actor, speed, rot, yVelocity, 0);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/code/z_collision_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -2807,8 +2807,7 @@ void CollisionCheck_OC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co
continue;
}
if (Math3D_SphVsSphOverlap(&leftJntSphElem->dim.worldSphere, &rightJntSphElem->dim.worldSphere,
&overlapSize) ==
true) {
&overlapSize) == true) {
Vec3f leftPos;
Vec3f rightPos;

Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Haka_Tubo/z_bg_haka_tubo.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void BgHakaTubo_Idle(BgHakaTubo* this, PlayState* play) {
// Colliding with flame circle
if (this->flamesCollider.base.atFlags & AT_HIT) {
this->flamesCollider.base.atFlags &= ~AT_HIT;
func_8002F71C(play, &this->dyna.actor, 5.0f, this->dyna.actor.yawTowardsPlayer, 5.0f);
Actor_SetPlayerKnockbackLargeNoDamage(play, &this->dyna.actor, 5.0f, this->dyna.actor.yawTowardsPlayer, 5.0f);
}
// Colliding with collider inside the pot
if (this->potCollider.base.acFlags & AC_HIT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void BgHidanCurtain_Update(Actor* thisx, PlayState* play2) {
} else {
if (this->collider.base.atFlags & AT_HIT) {
this->collider.base.atFlags &= ~AT_HIT;
func_8002F71C(play, &this->actor, 5.0f, this->actor.yawTowardsPlayer, 1.0f);
Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 5.0f, this->actor.yawTowardsPlayer, 1.0f);
}
if ((this->type == 4) || (this->type == 5)) {
this->actor.world.pos.y = (2.0f * this->actor.home.pos.y) - hcParams->riseDist - this->actor.world.pos.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void BgHidanFirewall_Collide(BgHidanFirewall* this, PlayState* play) {
phi_a3 = this->actor.shape.rot.y + 0x8000;
}

func_8002F71C(play, &this->actor, 5.0f, phi_a3, 1.0f);
Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 5.0f, phi_a3, 1.0f);
}

void BgHidanFirewall_ColliderFollowPlayer(BgHidanFirewall* this, PlayState* play) {
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Hidan_Fwbig/z_bg_hidan_fwbig.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void BgHidanFwbig_Update(Actor* thisx, PlayState* play) {

if (this->collider.base.atFlags & AT_HIT) {
this->collider.base.atFlags &= ~AT_HIT;
func_8002F71C(play, &this->actor, 5.0f, this->actor.world.rot.y, 1.0f);
Actor_SetPlayerKnockbackLargeNoDamage(play, &this->actor, 5.0f, this->actor.world.rot.y, 1.0f);
if (this->direction != 0) {
this->actionFunc = BgHidanFwbig_Lower;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void func_8088D750(BgHidanSekizou* this, PlayState* play) {
phi_a3 = -0x4000;
}
}
func_8002F71C(play, &this->dyna.actor, 5.0f, phi_a3, 1.0f);
Actor_SetPlayerKnockbackLargeNoDamage(play, &this->dyna.actor, 5.0f, phi_a3, 1.0f);
}

void BgHidanSekizou_Update(Actor* thisx, PlayState* play2) {
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Jya_Goroiwa/z_bg_jya_goroiwa.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void BgJyaGoroiwa_Move(BgJyaGoroiwa* this, PlayState* play) {
thisx->world.rot.y += 0x8000;
}

func_8002F6D4(play, thisx, 2.0f, thisx->yawTowardsPlayer, 0.0f, 0);
Actor_SetPlayerKnockbackLarge(play, thisx, 2.0f, thisx->yawTowardsPlayer, 0.0f, 0);
Player_PlaySfx(GET_PLAYER(play), NA_SE_PL_BODY_HIT);

this->yOffsetSpeed = 10.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ void func_8089B4C8(BgJyaZurerukabe* this, PlayState* play) {
case 3:
case 5:
if (fabsf(D_8089B9C0[D_8089BA30[i]]) > 1.0f) {
func_8002F6D4(play, &this->dyna.actor, 1.5f, this->dyna.actor.shape.rot.y, 0.0f, 0);
Actor_SetPlayerKnockbackLarge(play, &this->dyna.actor, 1.5f, this->dyna.actor.shape.rot.y, 0.0f, 0);
}
break;
case 1:
case 4:
if (fabsf(D_8089B9C0[D_8089BA30[i]] - D_8089B9C0[D_8089BA30[i + 1]]) > 1.0f) {
func_8002F6D4(play, &this->dyna.actor, 1.5f, this->dyna.actor.shape.rot.y, 0.0f, 0);
Actor_SetPlayerKnockbackLarge(play, &this->dyna.actor, 1.5f, this->dyna.actor.shape.rot.y, 0.0f, 0);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Ydan_Maruta/z_bg_ydan_maruta.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void BgYdanMaruta_Destroy(Actor* thisx, PlayState* play) {

void func_808BEFF4(BgYdanMaruta* this, PlayState* play) {
if (this->collider.base.atFlags & AT_HIT) {
func_8002F71C(play, &this->dyna.actor, 7.0f, this->dyna.actor.shape.rot.y, 6.0f);
Actor_SetPlayerKnockbackLargeNoDamage(play, &this->dyna.actor, 7.0f, this->dyna.actor.shape.rot.y, 6.0f);
}
this->dyna.actor.shape.rot.x += 0x360;
CollisionCheck_SetAT(play, &play->colChkCtx, &this->collider.base);
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Boss_Fd/z_boss_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ void BossFd_UpdateEffects(BossFd* this, PlayState* play) {
diff.z = player->actor.world.pos.z - effect->pos.z;
if ((this->timers[3] == 0) && (sqrtf(SQ(diff.x) + SQ(diff.y) + SQ(diff.z)) < 20.0f)) {
this->timers[3] = 50;
func_8002F6D4(play, NULL, 5.0f, effect->kbAngle, 0.0f, 0x30);
Actor_SetPlayerKnockbackLarge(play, NULL, 5.0f, effect->kbAngle, 0.0f, 0x30);
if (!player->bodyIsBurning) {
for (i2 = 0; i2 < PLAYER_BODYPART_MAX; i2++) {
player->bodyFlameTimers[i2] = Rand_S16Offset(0, 200);
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Boss_Fd2/z_boss_fd2.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void BossFd2_Emerge(BossFd2* this, PlayState* play) {
case 2:
Math_ApproachS(&this->actor.shape.rot.y, this->actor.yawTowardsPlayer, 3, 0x7D0);
if ((this->timers[0] == 1) && (this->actor.xzDistToPlayer < 120.0f)) {
func_8002F6D4(play, &this->actor, 3.0f, this->actor.yawTowardsPlayer, 2.0f, 0x20);
Actor_SetPlayerKnockbackLarge(play, &this->actor, 3.0f, this->actor.yawTowardsPlayer, 2.0f, 0x20);
Actor_PlaySfx(&player->actor, NA_SE_PL_BODY_HIT);
}
if (Animation_OnFrame(&this->skelAnime, this->fwork[FD2_END_FRAME])) {
Expand Down
7 changes: 4 additions & 3 deletions src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c
Original file line number Diff line number Diff line change
Expand Up @@ -3978,7 +3978,7 @@ void BossGanon_LightBall_Update(Actor* thisx, PlayState* play2) {
} else {
if (sqrtf(SQ(xDistFromLink) + SQ(yDistFromLink) + SQ(zDistFromLink)) <= 25.0f) {
spBA = 5;
func_8002F6D4(play, &this->actor, 3.0f, this->actor.world.rot.y, 0.0f, 0x30);
Actor_SetPlayerKnockbackLarge(play, &this->actor, 3.0f, this->actor.world.rot.y, 0.0f, 0x30);
SfxSource_PlaySfxAtFixedWorldPos(play, &this->actor.world.pos, 40, NA_SE_EN_GANON_HIT_THUNDER);
ganondorf->timers[2] = 20;

Expand Down Expand Up @@ -4455,7 +4455,7 @@ void func_808E2544(Actor* thisx, PlayState* play) {
this->actor.speed = 0.0f;

if (dorf->timers[2] == 0) {
func_8002F6D4(play, &this->actor, 3.0f, this->actor.world.rot.y, 0.0f, 0x50);
Actor_SetPlayerKnockbackLarge(play, &this->actor, 3.0f, this->actor.world.rot.y, 0.0f, 0x50);
SfxSource_PlaySfxAtFixedWorldPos(play, &this->actor.world.pos, 40, NA_SE_EN_GANON_HIT_THUNDER);
dorf->timers[2] = 20;

Expand Down Expand Up @@ -4774,7 +4774,8 @@ void BossGanon_UpdateEffects(PlayState* play) {

if (((eff->scale * 150.0f) < distToPlayer) && (distToPlayer < (eff->scale * 300.0f))) {
eff->timer = 150;
func_8002F6D4(play, &sGanondorf->actor, 7.0f, sGanondorf->actor.yawTowardsPlayer, 0.0f, 0x20);
Actor_SetPlayerKnockbackLarge(play, &sGanondorf->actor, 7.0f,
sGanondorf->actor.yawTowardsPlayer, 0.0f, 0x20);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/overlays/actors/ovl_Boss_Ganon2/z_boss_ganon2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,8 @@ void func_80902348(BossGanon2* this, PlayState* play) {
phi_v0_2 = 0;
}

func_8002F6D4(play, &this->actor, 15.0f, this->actor.yawTowardsPlayer + phi_v0_2, 2.0f, 0);
Actor_SetPlayerKnockbackLarge(play, &this->actor, 15.0f, this->actor.yawTowardsPlayer + phi_v0_2, 2.0f,
0);
sZelda->unk_3C8 = 8;
this->unk_316 = 10;
break;
Expand All @@ -1872,7 +1873,7 @@ void func_80902348(BossGanon2* this, PlayState* play) {
}

player->bodyIsBurning = true;
func_8002F6D4(play, &this->actor, 10.0f, Math_Atan2S(temp_f12, temp_f2), 0.0f, 0x10);
Actor_SetPlayerKnockbackLarge(play, &this->actor, 10.0f, Math_Atan2S(temp_f12, temp_f2), 0.0f, 0x10);
sZelda->unk_3C8 = 8;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/overlays/actors/ovl_Boss_Mo/z_boss_mo.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,8 @@ void BossMo_Tentacle(BossMo* this, PlayState* play) {
player->actor.parent = NULL;
player->csAction = PLAYER_CSACTION_NONE;
if (this->timers[0] == 0) {
func_8002F6D4(play, &this->actor, 20.0f, this->actor.shape.rot.y + 0x8000, 10.0f, 0);
Actor_SetPlayerKnockbackLarge(play, &this->actor, 20.0f, this->actor.shape.rot.y + 0x8000,
10.0f, 0);
}
}
this->timers[0] = 75;
Expand Down
Loading