Skip to content

Commit

Permalink
Merge pull request #617 from octorock/projectiles
Browse files Browse the repository at this point in the history
Create new entity structs for Projectiles
  • Loading branch information
hytopoulos authored Aug 1, 2023
2 parents 91a5a67 + 591563f commit a443cb5
Show file tree
Hide file tree
Showing 44 changed files with 1,544 additions and 1,135 deletions.
8 changes: 8 additions & 0 deletions include/enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
#include "projectile.h"

bool32 EnemyInit(Entity* this);
/**
* 0: _OnTick
* 1: _OnCollision
* 2: _OnKnockback
* 3: _OnDeath
* 4: _OnConfused
* 5: _OnGrabbed
*/
u32 GetNextFunction(Entity*);
void EnemyFunctionHandler(Entity*, EntityActionArray);
void EnemyFunctionHandlerAfterCollision(Entity*, void (*const[])());
Expand Down
24 changes: 12 additions & 12 deletions include/projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@ void DirtBallProjectile(Entity*);
void WindProjectile(Entity*);
void FireProjectile(Entity*);
void IceProjectile(Entity*);
void GleerokProjectile(Entity*);
void GleerokProjectile();
void KeatonDagger(Entity*);
void GuardLineOfSight(Entity*);
void ArrowProjectile(Entity*);
void MazaalEnergyBeam(Entity*);
void OctorokBossProjectile(Entity*);
void OctorokBossProjectile();
void StalfosProjectile(Entity*);
void LakituCloudProjectile(Entity*);
void LakituLightning(Entity*);
void MandiblesProjectile(Entity*);
void RemovableDust(Entity*);
void SpiderWeb(Entity*);
void MandiblesProjectile();
void RemovableDust();
void SpiderWeb();
void TorchTrapProjectile(Entity*);
void GuruguruBarProjectile(Entity*);
void V1DarkMagicProjectile(Entity*);
void BallAndChain(Entity*);
void V1FireProjectile(Entity*);
void V1DarkMagicProjectile();
void BallAndChain();
void V1FireProjectile();
void CannonballProjectile(Entity*);
void V1EyeLaser(Entity*);
void V1EyeLaser();
void Winder(Entity*);
void SpikedRollers(Entity*);
void V2Projectile(Entity*);
void V2Projectile();
void V3HandProjectile(Entity*);
void V3ElectricProjectile(Entity*);
void GyorgTail(Entity*);
void V3ElectricProjectile();
void GyorgTail();
void GyorgMaleEnergyProjectile(Entity*);
void V3TennisBallProjectile(Entity*);

Expand Down
4 changes: 2 additions & 2 deletions include/projectile/winder.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#define WINDER_NUM_SEGMENTS 8

typedef struct {
Entity base;
s16 positions[2 * WINDER_NUM_SEGMENTS];
/*0x00*/ Entity base;
/*0x68*/ s16 positions[2 * WINDER_NUM_SEGMENTS];
} WinderEntity;

#endif // WINDER_H
16 changes: 8 additions & 8 deletions src/enemy/dust.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ typedef struct {
#define DUST_SPRITE_INDEX 0x1eb
#endif

void sub_08044134(DustEntity*);
void sub_0804414C(DustEntity*);
void sub_0804415C(DustEntity*);
void Dust_OnTick(DustEntity*);
void Dust_OnCollision(DustEntity*);
void Dust_OnGrabbed(DustEntity*);
void sub_080441E0(DustEntity*);
void sub_080442A0(DustEntity*);
void sub_080441CC(DustEntity*);
Expand All @@ -56,27 +56,27 @@ extern void* sub_080AD8F0(u32, u32);
extern const s8 gUnk_08126EE4[];

void (*const Dust_Functions[])(Entity*) = {
(EntityActionPtr)sub_08044134, (EntityActionPtr)sub_0804414C, GenericKnockback, GenericDeath, GenericConfused,
(EntityActionPtr)sub_0804415C,
(EntityActionPtr)Dust_OnTick, (EntityActionPtr)Dust_OnCollision, GenericKnockback, GenericDeath, GenericConfused,
(EntityActionPtr)Dust_OnGrabbed,
};

void Dust(Entity* this) {
Dust_Functions[GetNextFunction(this)](this);
}

void sub_08044134(DustEntity* this) {
void Dust_OnTick(DustEntity* this) {
static void (*const Dust_Actions[])(DustEntity*) = {
sub_080441E0,
sub_080442A0,
};
Dust_Actions[super->action](this);
}

void sub_0804414C(DustEntity* this) {
void Dust_OnCollision(DustEntity* this) {
EnemyFunctionHandlerAfterCollision(super, Dust_Functions);
}

void sub_0804415C(DustEntity* this) {
void Dust_OnGrabbed(DustEntity* this) {
static void (*const Dust_SubActions[])(DustEntity*) = {
sub_080441BC,
sub_080441C4,
Expand Down
11 changes: 6 additions & 5 deletions src/enemy/enemy50.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void Enemy50_OnTick(Enemy50Entity* this) {
Enemy50_Actions[super->action](this);
}

void sub_08040B9C(Enemy50Entity* this) {
void Enemy50_OnCollision(Enemy50Entity* this) {
if (super->action == 8 || super->action == 9) {
super->animationState = 0xff;
InitializeAnimation(super, (super->knockbackDirection >> 4 ^ 1) + 1);
Expand Down Expand Up @@ -119,7 +119,7 @@ void sub_08040B9C(Enemy50Entity* this) {
EnemyFunctionHandlerAfterCollision(super, Enemy50_Functions);
}

void sub_08040CAC(Enemy50Entity* this) {
void Enemy50_OnKnockback(Enemy50Entity* this) {
GetNextFrame(super);
GenericKnockback2(super);
if (super->type == 0) {
Expand All @@ -137,7 +137,7 @@ void sub_08040CAC(Enemy50Entity* this) {
}
}

void sub_08040D30(Enemy50Entity* this) {
void Enemy50_OnConfused(Enemy50Entity* this) {
if (super->animIndex != 7 && super->animIndex != 8) {
InitializeAnimation(super, super->animationState + 7);
}
Expand All @@ -153,7 +153,7 @@ void sub_08040D30(Enemy50Entity* this) {
}
}

void sub_08040D90(Enemy50Entity* this) {
void Enemy50_OnGrabbed(Enemy50Entity* this) {
if (sub_0806F520(super)) {
Enemy50_SubActions[super->subAction](this);
} else {
Expand Down Expand Up @@ -436,7 +436,8 @@ bool32 sub_08041300(Enemy50Entity* this) {
#endif

void (*const Enemy50_Functions[])(Enemy50Entity*) = {
Enemy50_OnTick, sub_08040B9C, sub_08040CAC, (void (*)(Enemy50Entity*))GenericDeath, sub_08040D30, sub_08040D90,
Enemy50_OnTick, Enemy50_OnCollision, Enemy50_OnKnockback, (void (*)(Enemy50Entity*))GenericDeath,
Enemy50_OnConfused, Enemy50_OnGrabbed,
};
void (*const Enemy50_Actions[])(Enemy50Entity*) = {
Enemy50_Init, Enemy50_Action1, Enemy50_Action2, Enemy50_Action3, Enemy50_Action4, Enemy50_Action5,
Expand Down
12 changes: 6 additions & 6 deletions src/enemy/mulldozer.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Mulldozer_OnInit(MulldozerEntity* this) {
Mulldozer_Actions[super->action](this);
}

void sub_08032CAC(MulldozerEntity* this) {
void Mulldozer_OnCollision(MulldozerEntity* this) {
if (super->confusedTime != 0) {
Create0x68FX(super, 0x1c);
}
Expand All @@ -80,7 +80,7 @@ void sub_08032CAC(MulldozerEntity* this) {
}
}

void sub_08032D3C(MulldozerEntity* this) {
void Mulldozer_OnKnockback(MulldozerEntity* this) {
if (--super->subtimer == 0) {
super->subtimer = 2;
super->animationState = (super->animationState + 1) & 7;
Expand All @@ -90,7 +90,7 @@ void sub_08032D3C(MulldozerEntity* this) {
GenericKnockback(super);
}

void nullsub_157(MulldozerEntity* this) {
void Mulldozer_OnGrabbed(MulldozerEntity* this) {
}

void Mulldozer_Init(MulldozerEntity* this) {
Expand Down Expand Up @@ -465,11 +465,11 @@ bool32 sub_08033364(MulldozerEntity* this) {

void (*const Mulldozer_Functions[])(MulldozerEntity*) = {
Mulldozer_OnInit,
sub_08032CAC,
sub_08032D3C,
Mulldozer_OnCollision,
Mulldozer_OnKnockback,
(void (*)(MulldozerEntity*))GenericDeath,
(void (*)(MulldozerEntity*))GenericConfused,
nullsub_157,
Mulldozer_OnGrabbed,
};
void (*const Mulldozer_Actions[])(MulldozerEntity*) = {
Mulldozer_Init, Mulldozer_Action1, Mulldozer_Action2, Mulldozer_Action3,
Expand Down
12 changes: 6 additions & 6 deletions src/enemy/stalfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void Stalfos_OnTick(StalfosEntity* this) {
}
}

void sub_0803933C(StalfosEntity* this) {
void Stalfos_OnCollision(StalfosEntity* this) {
Entity* r0;
Entity* r1;
u32 r2;
Expand Down Expand Up @@ -120,15 +120,15 @@ void sub_0803933C(StalfosEntity* this) {
EnemyFunctionHandlerAfterCollision(super, Stalfos_Functions);
}

void sub_08039418(StalfosEntity* this) {
void Stalfos_OnDeath(StalfosEntity* this) {
if (super->type == 0) {
CreateDeathFx(super, 0xf3, 0);
} else {
GenericDeath(super);
}
}

void sub_08039438(StalfosEntity* this) {
void Stalfos_OnGrabbed(StalfosEntity* this) {
if (sub_0806F520(super)) {
Stalfos_SubActions[super->subAction](this);
}
Expand Down Expand Up @@ -475,11 +475,11 @@ u32 sub_08039B28(StalfosEntity* this) {

void (*const Stalfos_Functions[])(StalfosEntity*) = {
Stalfos_OnTick,
sub_0803933C,
Stalfos_OnCollision,
(void (*)(StalfosEntity*))GenericKnockback,
sub_08039418,
Stalfos_OnDeath,
(void (*)(StalfosEntity*))GenericConfused,
sub_08039438,
Stalfos_OnGrabbed,
};
void (*const Stalfos_Actions[])(StalfosEntity*) = {
Stalfos_Init, Stalfos_Action1, Stalfos_Action2, Stalfos_Action3, Stalfos_Action4, Stalfos_Action5,
Expand Down
25 changes: 16 additions & 9 deletions src/projectile/arrowProjectile.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#include "entity.h"
/**
* @file arrowProjectile.c
* @ingroup Projectiles
*
* @brief Arrow Projectile
*/
#define NENT_DEPRECATED
#include "collision.h"
#include "enemy.h"
#include "entity.h"
#include "functions.h"
#include "object.h"

extern void (*const gArrowProjectile[])(Entity*);
extern void (*const gArrowProjectileActions[])(Entity*);
extern void (*const ArrowProjectile_Functions[])(Entity*);
extern void (*const ArrowProjectile_Actions[])(Entity*);

typedef struct {
u8 flipX;
Expand All @@ -20,14 +27,14 @@ void sub_080A9488(Entity*);
void sub_080A94C0(Entity*, u32);

void ArrowProjectile(Entity* this) {
gArrowProjectile[GetNextFunction(this)](this);
ArrowProjectile_Functions[GetNextFunction(this)](this);
}

void ArrowProjectile_OnTick(Entity* this) {
gArrowProjectileActions[this->action](this);
ArrowProjectile_Actions[this->action](this);
}

void sub_080A9334(Entity* this) {
void ArrowProjectile_OnCollision(Entity* this) {
if ((this->contactFlags & 0x80) != 0) {
if ((this->contactFlags & 0x3f) != 0) {
ModHealth(-2);
Expand Down Expand Up @@ -119,10 +126,10 @@ void sub_080A94C0(Entity* this, u32 animationState) {
InitializeAnimation(this, this->animIndex);
}

void (*const gArrowProjectile[])(Entity*) = {
ArrowProjectile_OnTick, sub_080A9334, DeleteEntity, DeleteEntity, DeleteEntity,
void (*const ArrowProjectile_Functions[])(Entity*) = {
ArrowProjectile_OnTick, ArrowProjectile_OnCollision, DeleteEntity, DeleteEntity, DeleteEntity,
};
void (*const gArrowProjectileActions[])(Entity*) = {
void (*const ArrowProjectile_Actions[])(Entity*) = {
ArrowProjectile_Init, ArrowProjectile_Action1, ArrowProjectile_Action2,
ArrowProjectile_Action3, ArrowProjectile_Action4,
};
Expand Down
Loading

0 comments on commit a443cb5

Please sign in to comment.