summaryrefslogtreecommitdiff
path: root/src/engine
diff options
context:
space:
mode:
authorKiloku <mateus.sateles@protonmail.com>2024-12-30 01:47:42 -0300
committerLywx <kiritodev01@gmail.com>2025-01-03 16:56:49 -0600
commit9506a4297bc159fe3c3ef5f2c0cd04b500e5477e (patch)
treedcaa0ff54fa71ac430774af0691c37212fd5112b /src/engine
parentc4c324fdc63d54ae9ba6e9fab173c662100b325e (diff)
Player action hooks (#93)
* Create Player Action and Player Movement event types * Call Boost/Brake events * Change some event types * Make Boost/Brake events cancellable * Use new dynamic hooks * Use separate events for each player action * Add shoot events * Return early on cancel * Add Bomb and Charged Shot Events * Remove movement event hooks, add player param to action hooks * Fix whitespace * Register player action events
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/fox_play.c213
-rw-r--r--src/engine/fox_tank.c53
2 files changed, 152 insertions, 114 deletions
diff --git a/src/engine/fox_play.c b/src/engine/fox_play.c
index 9d9e031c..844ddad1 100644
--- a/src/engine/fox_play.c
+++ b/src/engine/fox_play.c
@@ -3145,14 +3145,19 @@ void Player_SetupTankShot(Player* player, PlayerShot* shot, PlayerShotId shotId,
void Player_TankCannon(Player* player) {
s32 i;
- for (i = 0; i < ARRAY_COUNT(gPlayerShots) - 1; i++) {
- if (gPlayerShots[i].obj.status == SHOT_FREE) {
- Player_SetupTankShot(player, &gPlayerShots[i], PLAYERSHOT_TANK, 100.0f);
- Player_PlaySfx(player->sfxSource, NA_SE_TANK_SHOT, player->num);
- player->unk_1A0 = 2;
- break;
+ CALL_CANCELLABLE_EVENT(PlayerActionPreShootEvent, player, gLaserStrength[gPlayerNum]) {
+ for (i = 0; i < ARRAY_COUNT(gPlayerShots) - 1; i++) {
+ if (gPlayerShots[i].obj.status == SHOT_FREE) {
+ Player_SetupTankShot(player, &gPlayerShots[i], PLAYERSHOT_TANK, 100.0f);
+ Player_PlaySfx(player->sfxSource, NA_SE_TANK_SHOT, player->num);
+ player->unk_1A0 = 2;
+ break;
+ }
}
}
+ if (!PlayerActionPreShootEvent_.event.cancelled){
+ CALL_EVENT(PlayerActionPostShootEvent, player, gLaserStrength[gPlayerNum]);
+ }
}
void Player_ArwingLaser(Player* player) {
@@ -3164,24 +3169,30 @@ void Player_ArwingLaser(Player* player) {
laser = LASERS_SINGLE;
}
+ CALL_EVENT(PlayerActionPreShootEvent, player, laser);
+ if (PlayerActionPreShootEvent_.event.cancelled){
+ return;
+ }
+
switch (laser) {
case LASERS_SINGLE:
for (i = 0; i < ARRAY_COUNT(gPlayerShots) - 1; i++) {
if (gPlayerShots[i].obj.status == SHOT_FREE) {
Player_SetupArwingShot(player, &gPlayerShots[i], 0.0f, 0.0f, PLAYERSHOT_SINGLE_LASER,
- 400.0f / 3.0f);
+ 400.0f / 3.0f);
Player_PlaySfx(player->sfxSource, NA_SE_ARWING_SHOT, player->num);
gMuzzleFlashScale[player->num] = 0.5f;
break;
}
}
+
break;
case LASERS_TWIN:
case LASERS_HYPER:
for (i = 0; i < ARRAY_COUNT(gPlayerShots) - 1; i++) {
if (gPlayerShots[i].obj.status == SHOT_FREE) {
Player_SetupArwingShot(player, &gPlayerShots[i], 0.0f, -10.0f, PLAYERSHOT_TWIN_LASER,
- 400.0f / 3.0f);
+ 400.0f / 3.0f);
if (laser == LASERS_TWIN) {
Player_PlaySfx(player->sfxSource, NA_SE_ARWING_TWIN_LASER, player->num);
gMuzzleFlashScale[player->num] = 0.5f;
@@ -3194,11 +3205,19 @@ void Player_ArwingLaser(Player* player) {
}
break;
}
+ CALL_EVENT(PlayerActionPostShootEvent, player, laser);
}
void Player_SmartBomb(Player* player) {
+
if ((gBombCount[player->num] != 0) && (gBombButton[player->num] & gInputPress->button) &&
(gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].obj.status == SHOT_FREE)) {
+ CALL_EVENT(PlayerActionPreBombEvent, player);
+ if (PlayerActionPreBombEvent_.event.cancelled)
+ {
+ return;
+ }
+
if (gVersusMode) {
gBombCount[player->num] = 0;
} else {
@@ -3218,6 +3237,7 @@ void Player_SmartBomb(Player* player) {
gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].unk_60 = 0;
Audio_InitBombSfx(player->num, 1);
Audio_PlayBombFlightSfx(player->num, gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].sfxSource);
+ CALL_EVENT(PlayerActionPostBombEvent, player);
}
}
@@ -3350,15 +3370,18 @@ bool Player_UpdateLockOn(Player* player) {
(gPlayerShots[14 - player->num].obj.id != PLAYERSHOT_LOCK_ON) ||
((gPlayerShots[14 - player->num].obj.id == PLAYERSHOT_LOCK_ON) &&
(gPlayerShots[14 - player->num].unk_60 != 0))) {
- if (player->form == FORM_ARWING) {
- Player_SetupArwingShot(player, &gPlayerShots[14 - player->num], 0.0f, 0.0f, PLAYERSHOT_LOCK_ON,
- 70.0f);
- } else {
- Player_SetupTankShot(player, &gPlayerShots[14 - player->num], PLAYERSHOT_LOCK_ON, 70.0f);
+ CALL_CANCELLABLE_EVENT(PlayerActionPreShootChargedEvent, player){
+ if (player->form == FORM_ARWING) {
+ Player_SetupArwingShot(player, &gPlayerShots[14 - player->num], 0.0f, 0.0f, PLAYERSHOT_LOCK_ON,
+ 70.0f);
+ } else {
+ Player_SetupTankShot(player, &gPlayerShots[14 - player->num], PLAYERSHOT_LOCK_ON, 70.0f);
+ }
+ Object_PlayerSfx(player->sfxSource, NA_SE_LOCK_ON_LASER, player->num);
+ gControllerRumbleTimers[player->num] = 5;
+ return true;
}
- Object_PlayerSfx(player->sfxSource, NA_SE_LOCK_ON_LASER, player->num);
- gControllerRumbleTimers[player->num] = 5;
- return true;
+ CALL_EVENT(PlayerActionPostShootChargedEvent, player);
}
break;
}
@@ -3369,17 +3392,20 @@ bool Player_UpdateLockOn(Player* player) {
(gPlayerShots[14 - player->num].obj.id != PLAYERSHOT_LOCK_ON) ||
((gPlayerShots[14 - player->num].obj.id == PLAYERSHOT_LOCK_ON) &&
(gPlayerShots[14 - player->num].scale > 1.0f))) {
- if (player->form == FORM_ARWING) {
- Player_SetupArwingShot(player, &gPlayerShots[14 - player->num], 0.0f, 0.0f, PLAYERSHOT_LOCK_ON,
- 70.0f);
- } else {
- Player_SetupTankShot(player, &gPlayerShots[14 - player->num], PLAYERSHOT_LOCK_ON, 70.0f);
+ CALL_CANCELLABLE_EVENT(PlayerActionPreShootChargedEvent, player){
+ if (player->form == FORM_ARWING) {
+ Player_SetupArwingShot(player, &gPlayerShots[14 - player->num], 0.0f, 0.0f, PLAYERSHOT_LOCK_ON,
+ 70.0f);
+ } else {
+ Player_SetupTankShot(player, &gPlayerShots[14 - player->num], PLAYERSHOT_LOCK_ON, 70.0f);
+ }
+ Object_PlayerSfx(player->sfxSource, NA_SE_LOCK_ON_LASER, player->num);
+ gChargeTimers[player->num] = 0;
+ gControllerRumbleTimers[player->num] = 5;
+ return true;
}
- Object_PlayerSfx(player->sfxSource, NA_SE_LOCK_ON_LASER, player->num);
- gChargeTimers[player->num] = 0;
- gControllerRumbleTimers[player->num] = 5;
- return true;
}
+ CALL_EVENT(PlayerActionPostShootChargedEvent, player);
}
gChargeTimers[player->num] = 0;
}
@@ -3401,18 +3427,21 @@ bool Player_UpdateLockOn(Player* player) {
}
if (hasBombTarget && (gBombCount[player->num] != 0) &&
(gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].obj.status == SHOT_FREE)) {
- gBombCount[player->num]--;
- if (player->form == FORM_ARWING) {
- Player_SetupArwingShot(player, &gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1], 0.0f, 0.0f,
- PLAYERSHOT_LOCK_ON, 60.0f);
- } else {
- Player_SetupTankShot(player, &gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1], PLAYERSHOT_LOCK_ON, 60.0f);
+ CALL_CANCELLABLE_EVENT(PlayerActionPreBombEvent, player){
+ gBombCount[player->num]--;
+ if (player->form == FORM_ARWING) {
+ Player_SetupArwingShot(player, &gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1], 0.0f, 0.0f,
+ PLAYERSHOT_LOCK_ON, 60.0f);
+ } else {
+ Player_SetupTankShot(player, &gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1], PLAYERSHOT_LOCK_ON, 60.0f);
+ }
+ gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].unk_48 = 30.0f;
+ gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].unk_60 = 0;
+ Audio_InitBombSfx(player->num, 1);
+ Audio_PlayBombFlightSfx(player->num, gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].sfxSource);
+ return true;
}
- gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].unk_48 = 30.0f;
- gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].unk_60 = 0;
- Audio_InitBombSfx(player->num, 1);
- Audio_PlayBombFlightSfx(player->num, gPlayerShots[ARRAY_COUNT(gPlayerShots) - 1].sfxSource);
- return true;
+ CALL_EVENT(PlayerActionPostBombEvent, player);
}
}
return false;
@@ -5137,38 +5166,40 @@ void Player_ArwingBoost(Player* player) {
}
if ((gInputHold->button & gBoostButton[player->num]) && !(gInputHold->button & gBrakeButton[player->num]) &&
(player->state != PLAYERSTATE_U_TURN) && !player->boostCooldown) {
- if (player->boostMeter == 0.0f) {
- Player_PlaySfx(player->sfxSource, NA_SE_ARWING_BOOST, player->num);
- player->unk_194 = 5.0f;
- player->unk_190 = 5.0f;
- if (gBoostButton[player->num] & gInputPress->button) {
- gLoopBoostTimers[gPlayerNum] = 5;
+ CALL_CANCELLABLE_EVENT(PlayerActionBoostEvent, player) {
+ if (player->boostMeter == 0.0f) {
+ Player_PlaySfx(player->sfxSource, NA_SE_ARWING_BOOST, player->num);
+ player->unk_194 = 5.0f;
+ player->unk_190 = 5.0f;
+ if (gBoostButton[player->num] & gInputPress->button) {
+ gLoopBoostTimers[gPlayerNum] = 5;
+ }
}
+ if (gLevelType == LEVELTYPE_PLANET) {
+ player->arwing.unk_28 += (35.0f - player->arwing.unk_28) * 0.1f;
+ Math_SmoothStepToF(&player->arwing.upperRightFlapYrot, 0.0f, 0.5f, 100.0f, 0.0f);
+ Math_SmoothStepToF(&player->arwing.bottomRightFlapYrot, 0.0f, 0.5f, 100.0f, 0.0f);
+ Math_SmoothStepToF(&player->arwing.upperLeftFlapYrot, 0.0f, 0.5f, 100.0f, 0.0f);
+ Math_SmoothStepToF(&player->arwing.bottomLeftFlapYrot, 0.0f, 0.5f, 100.0f, 0.0f);
+ }
+ player->boostMeter += sp28;
+ if (player->boostMeter > 90.0f) {
+ player->boostMeter = 90.0f;
+ player->boostCooldown = true;
+ }
+ player->contrailScale += 0.04f;
+ if (player->contrailScale > 0.6f) {
+ player->contrailScale = 0.6f;
+ }
+ player->unk_190 = 2.0f;
+ player->boostSpeed += 2.0f;
+ if (player->boostSpeed > 30.0f) {
+ player->boostSpeed = 30.0f;
+ }
+ Math_SmoothStepToF(&player->camDist, -400.0f, 0.1f, 30.0f, 0.0f);
+ player->sfx.boost = 1;
+ Math_SmoothStepToF(&D_ctx_801779A8[player->num], 50.0f, 1.0f, 10.0f, 0.0f);
}
- if (gLevelType == LEVELTYPE_PLANET) {
- player->arwing.unk_28 += (35.0f - player->arwing.unk_28) * 0.1f;
- Math_SmoothStepToF(&player->arwing.upperRightFlapYrot, 0.0f, 0.5f, 100.0f, 0.0f);
- Math_SmoothStepToF(&player->arwing.bottomRightFlapYrot, 0.0f, 0.5f, 100.0f, 0.0f);
- Math_SmoothStepToF(&player->arwing.upperLeftFlapYrot, 0.0f, 0.5f, 100.0f, 0.0f);
- Math_SmoothStepToF(&player->arwing.bottomLeftFlapYrot, 0.0f, 0.5f, 100.0f, 0.0f);
- }
- player->boostMeter += sp28;
- if (player->boostMeter > 90.0f) {
- player->boostMeter = 90.0f;
- player->boostCooldown = true;
- }
- player->contrailScale += 0.04f;
- if (player->contrailScale > 0.6f) {
- player->contrailScale = 0.6f;
- }
- player->unk_190 = 2.0f;
- player->boostSpeed += 2.0f;
- if (player->boostSpeed > 30.0f) {
- player->boostSpeed = 30.0f;
- }
- Math_SmoothStepToF(&player->camDist, -400.0f, 0.1f, 30.0f, 0.0f);
- player->sfx.boost = 1;
- Math_SmoothStepToF(&D_ctx_801779A8[player->num], 50.0f, 1.0f, 10.0f, 0.0f);
} else {
if (player->boostMeter > 0.0f) {
player->boostMeter -= sp2C;
@@ -5240,34 +5271,36 @@ void Player_ArwingBrake(Player* player) {
if ((gInputHold->button & gBrakeButton[player->num]) && !(gInputHold->button & gBoostButton[player->num]) &&
(player->state != PLAYERSTATE_U_TURN) && !player->boostCooldown) {
- if (player->boostMeter == 0.0f) {
- Player_PlaySfx(player->sfxSource, NA_SE_ARWING_BRAKE, player->num);
- if ((gLevelMode == LEVELMODE_ALL_RANGE) && (gInputPress->button & gBrakeButton[player->num])) {
- gUturnBrakeTimers[gPlayerNum] = 5;
+ CALL_CANCELLABLE_EVENT(PlayerActionBrakeEvent, player) {
+ if (player->boostMeter == 0.0f) {
+ Player_PlaySfx(player->sfxSource, NA_SE_ARWING_BRAKE, player->num);
+ if ((gLevelMode == LEVELMODE_ALL_RANGE) && (gInputPress->button & gBrakeButton[player->num])) {
+ gUturnBrakeTimers[gPlayerNum] = 5;
+ }
}
- }
- if (gLevelType == LEVELTYPE_PLANET) {
- Math_SmoothStepToF(&player->arwing.upperRightFlapYrot, 90.0f, 0.2f, 100.0f, 0.0f);
- Math_SmoothStepToF(&player->arwing.bottomRightFlapYrot, -90.0f, 0.2f, 100.0f, 0.0f);
- Math_SmoothStepToF(&player->arwing.upperLeftFlapYrot, 90.0f, 0.2f, 100.0f, 0.0f);
- Math_SmoothStepToF(&player->arwing.bottomLeftFlapYrot, -90.0f, 0.2f, 100.0f, 0.0f);
- }
- player->boostMeter += sp30;
- if (player->boostMeter > 90.0f) {
- player->boostCooldown = true;
- player->boostMeter = 90.0f;
- }
+ if (gLevelType == LEVELTYPE_PLANET) {
+ Math_SmoothStepToF(&player->arwing.upperRightFlapYrot, 90.0f, 0.2f, 100.0f, 0.0f);
+ Math_SmoothStepToF(&player->arwing.bottomRightFlapYrot, -90.0f, 0.2f, 100.0f, 0.0f);
+ Math_SmoothStepToF(&player->arwing.upperLeftFlapYrot, 90.0f, 0.2f, 100.0f, 0.0f);
+ Math_SmoothStepToF(&player->arwing.bottomLeftFlapYrot, -90.0f, 0.2f, 100.0f, 0.0f);
+ }
+ player->boostMeter += sp30;
+ if (player->boostMeter > 90.0f) {
+ player->boostCooldown = true;
+ player->boostMeter = 90.0f;
+ }
- player->unk_190 = 0.3f;
- player->boostSpeed -= 1.0f;
- if (player->boostSpeed < -20.0f) {
- player->boostSpeed = -20.0f;
- }
+ player->unk_190 = 0.3f;
+ player->boostSpeed -= 1.0f;
+ if (player->boostSpeed < -20.0f) {
+ player->boostSpeed = -20.0f;
+ }
- Math_SmoothStepToF(&player->camDist, 180.0f, 0.1f, 10.0f, 0.0f);
- player->sfx.brake = true;
- Math_SmoothStepToF(&D_ctx_801779A8[player->num], 25.0f, 1.0f, 5.0f, 0.0f);
+ Math_SmoothStepToF(&player->camDist, 180.0f, 0.1f, 10.0f, 0.0f);
+ player->sfx.brake = true;
+ Math_SmoothStepToF(&D_ctx_801779A8[player->num], 25.0f, 1.0f, 5.0f, 0.0f);
+ }
} else if (player->boostMeter > 0.0f) {
player->boostMeter -= sp34;
if (player->boostMeter <= 0.0f) {
diff --git a/src/engine/fox_tank.c b/src/engine/fox_tank.c
index 2f7df198..671c7cf1 100644
--- a/src/engine/fox_tank.c
+++ b/src/engine/fox_tank.c
@@ -1,6 +1,7 @@
#include "global.h"
#include "assets/ast_landmaster.h"
#include "assets/ast_titania.h"
+#include "port/hooks/Events.h"
void func_tank_80047754(Player* player);
void func_tank_80047D38(Player* player, f32);
@@ -550,35 +551,39 @@ void func_tank_80045348(Player* player) {
if (player->unk_19C >= 0) {
if ((gBoostButton[player->num] & gInputHold->button) && !player->boostCooldown) {
- D_800C9F14++;
- sp2E = true;
- if (D_800C9F24 == 0.0f) {
- player->unk_190 = player->unk_194 = 4.0f;
- AUDIO_PLAY_SFX(NA_SE_TANK_DASH, player->sfxSource, 0);
- } else {
- player->unk_190 = 2.0f;
- }
- baseSpeedTarget = 25.0f;
- sp40 = -200.0f;
- sp3C = 0.2f;
- sp38 = 6.0f;
-
- D_800C9F24 += 1.0f;
- if (D_ctx_801779A8[player->num] < 25.0f) {
- D_ctx_801779A8[player->num] = 25.0f;
- }
+ CALL_CANCELLABLE_EVENT(PlayerActionBoostEvent, player) {
+ D_800C9F14++;
+ sp2E = true;
+ if (D_800C9F24 == 0.0f) {
+ player->unk_190 = player->unk_194 = 4.0f;
+ AUDIO_PLAY_SFX(NA_SE_TANK_DASH, player->sfxSource, 0);
+ } else {
+ player->unk_190 = 2.0f;
+ }
+ baseSpeedTarget = 25.0f;
+ sp40 = -200.0f;
+ sp3C = 0.2f;
+ sp38 = 6.0f;
+
+ D_800C9F24 += 1.0f;
+ if (D_ctx_801779A8[player->num] < 25.0f) {
+ D_ctx_801779A8[player->num] = 25.0f;
+ }
- Math_SmoothStepToF(&D_ctx_801779A8[player->num], 50.0f, 1.0f, 10.0f, 0.0f);
+ Math_SmoothStepToF(&D_ctx_801779A8[player->num], 50.0f, 1.0f, 10.0f, 0.0f);
+ }
} else {
D_800C9F24 = 0.0f;
}
if ((gBrakeButton[player->num] & gInputHold->button) && !player->boostCooldown && !sp2E) {
- D_800C9F14++;
- baseSpeedTarget = 5.0f;
- sp40 = 100.0f;
- sp3C = 0.2f;
- D_800C9F28 += 1.0f;
- Math_SmoothStepToF(&D_ctx_801779A8[player->num], 25.0f, 1.0f, 5.0f, 0.0f);
+ CALL_CANCELLABLE_EVENT(PlayerActionBrakeEvent, player) {
+ D_800C9F14++;
+ baseSpeedTarget = 5.0f;
+ sp40 = 100.0f;
+ sp3C = 0.2f;
+ D_800C9F28 += 1.0f;
+ Math_SmoothStepToF(&D_ctx_801779A8[player->num], 25.0f, 1.0f, 5.0f, 0.0f);
+ }
} else {
D_800C9F28 = 0.0f;
}