Skip to content

Commit

Permalink
Merge pull request #681 from notyourav/em
Browse files Browse the repository at this point in the history
create enemy struct and enemy flags
  • Loading branch information
hytopoulos authored Dec 31, 2023
2 parents 3771464 + 201955e commit bd1be09
Show file tree
Hide file tree
Showing 88 changed files with 375 additions and 345 deletions.
14 changes: 7 additions & 7 deletions asm/src/code_08003FC4.s
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@ _08004162:
ands r2, r4
pop {r4, pc}

thumb_func_start sub_08004168
sub_08004168: @ 0x08004168
thumb_func_start SnapToTile
SnapToTile: @ 0x08004168
ldr r3, _08004384 @ =0x000FFFFF
ldr r1, _08004388 @ =0x00080000
ldr r2, [r0, #0x2c]
bics r2, r3
adds r2, r2, r1
ldr r2, [r0, #0x2c] // x
bics r2, r3 // align to grid
adds r2, r1 // add half of a tile
str r2, [r0, #0x2c]
ldr r2, [r0, #0x30]
ldr r2, [r0, #0x30] // y
bics r2, r3
adds r2, r2, r1
adds r2, r1
str r2, [r0, #0x30]
bx lr

Expand Down
2 changes: 1 addition & 1 deletion asm/src/enemy.s
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ GenericConfused: @ 0x08001242
cmp r2, #0x1c
bne _08001282
push {r0}
bl sub_0804AA1C
bl EnemyDetachFX
pop {r0}
_08001282:
ldr r1, _08001364 @ =0x00001800
Expand Down
46 changes: 37 additions & 9 deletions include/enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,35 @@
#include "entity.h"
#include "projectile.h"

bool32 EnemyInit(Entity* this);
#define EM_FLAG_BOSS (1 << 0)
#define EM_FLAG_BOSS_KILLED (1 << 1)
#define EM_FLAG_HAS_HOME (1 << 2)
#define EM_FLAG_NO_DEATH_FX (1 << 3)
#define EM_FLAG_SUPPORT (1 << 4)
#define EM_FLAG_CAPTAIN (1 << 5)
#define EM_FLAG_MONITORED (1 << 6)

typedef struct {
Entity base;
Entity* child;
u8 idx;
u8 enemyFlags;
u8 rangeX;
u8 rangeY;
s16 homeX;
s16 homeY;
/*0x74*/ union SplitHWord field_0x74;
/*0x76*/ union SplitHWord field_0x76;
/*0x78*/ union SplitHWord field_0x78;
/*0x7a*/ union SplitHWord field_0x7a;
/*0x7c*/ union SplitWord field_0x7c;
/*0x80*/ union SplitHWord field_0x80;
/*0x82*/ union SplitHWord field_0x82;
/*0x84*/ union SplitHWord cutsceneBeh;
/*0x86*/ union SplitHWord field_0x86;
} Enemy;

bool32 EnemyInit(Enemy* this);
/**
* 0: _OnTick
* 1: _OnCollision
Expand All @@ -25,13 +53,13 @@ u32 GetNextFunction(Entity*);
void EnemyFunctionHandler(Entity*, EntityActionArray);
void EnemyFunctionHandlerAfterCollision(Entity*, void (*const[])());
void GenericKnockback(Entity*);
Entity* CreateDeathFx(Entity*, u32, u32);
void EnemyCreateDeathFX(Enemy*, u32, u32);
void sub_0804A720(Entity*);
bool32 sub_08049FDC(Entity*, u32);

Entity* Create0x68FX(Entity*, u32);
void SetChildOffset(Entity*, s32, s32, s32);
Entity* CreateProjectileWithParent(Entity*, u8, u8);
Entity* EnemyCreateFX(Entity*, u32);
void EnemySetFXOffset(Entity*, s32, s32, s32);
Entity* EnemyCreateProjectile(Entity*, u32, u32);

void GenericDeath(Entity*);
void sub_08002724(void*, u8*);
Expand All @@ -44,13 +72,13 @@ Entity* sub_08049DF4(u32);
u32 sub_0804A044(Entity*, Entity*, u32);
s32 sub_080012DC(Entity*);

void sub_0804AA1C(Entity*);
void EnemyDetachFX(Entity*);
bool32 sub_08049F1C(Entity*, Entity*, s32);
bool32 PlayerInRange(Entity*, u32, s32);
void sub_0804A4E4(Entity*, Entity*);
void EnemyCopyParams(Entity*, Entity*);
void GenericKnockback2(Entity*);

typedef enum {
enum {
/*0x00*/ OCTOROK,
/*0x01*/ CHUCHU,
/*0x02*/ LEEVER,
Expand Down Expand Up @@ -154,7 +182,7 @@ typedef enum {
/*0x64*/ ENEMY_64,
/*0x65*/ TREE_ITEM,
/*0x66*/ ENEMY_66
} Enemy;
};

void Octorok();
void Chuchu();
Expand Down
4 changes: 2 additions & 2 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern void sub_080027EA(Entity*, u32, u32);
extern void sub_080028E0(Entity*);
extern u32 sub_080040A2(Entity*);
extern u32 sub_080040D8(Entity*, u8*, s32, s32);
extern void sub_08004168(Entity*);
extern void SnapToTile(Entity*);
extern u32 sub_0800419C(Entity*, Entity*, u32, u32);
extern u32 sub_080041DC(Entity*, u32, u32);
extern void sub_080042BA(Entity*, u32);
Expand All @@ -81,7 +81,7 @@ extern void UpdateUIElements(void);
extern void sub_0801E104(void);
extern void sub_08030118(u32);
extern void sub_0803C0AC(Entity*);
extern void sub_08049CF4(Entity*);
extern void EnemyDisableRespawn(Entity*);
extern u32 sub_0804A024(Entity*, u32, u32);
extern u32 IsMinishItem(u32);
extern void DisableRandomDrops();
Expand Down
4 changes: 2 additions & 2 deletions include/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ typedef struct {
u8 area;
u8 room;
u16 unk_02;
u32 unk_04;
u32 enemyBits;
} RoomMemory;

extern RoomMemory* gUnk_020354B0;
extern RoomMemory* gCurrentRoomMemory;
extern RoomMemory gRoomMemory[];

// Packets used to store which entities to load in a room
Expand Down
3 changes: 1 addition & 2 deletions linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ SECTIONS {
. = 0x000344A0; gUnk_020344A0 = .;
. = 0x000344B0; gBG2Buffer = .;
. = 0x00034CB0; gBG0Buffer = .;
. = 0x000354B0; gUnk_020354B0 = .;
. = 0x000354B0; gCurrentRoomMemory = .;
. = 0x000354B4; gManagerCount = .;
. = 0x000354C0; gUnk_020354C0 = .;
. = 0x00035540; gzHeap = .;
Expand Down Expand Up @@ -386,7 +386,6 @@ SECTIONS {
src/code_08049CD4.o(.text); /* enemyUtils.c */
src/code_08049DF4.o(.text);
src/enemyUtils.o(.text);
src/createEnemy.o(.text);
src/enterPortalSubtask.o(.text);
src/room.o(.text);
src/roomInit.o(.text);
Expand Down
29 changes: 15 additions & 14 deletions src/code_08049CD4.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "global.h"
#include "room.h"
#include "enemy.h"

extern void MemFill32(u32, void*, u32);

Expand All @@ -8,35 +9,35 @@ RoomMemory* sub_08049D88(void);

void ClearRoomMemory(void) {
MemFill32(0xFFFFFFFF, gRoomMemory, 0x40);
gUnk_020354B0 = gRoomMemory;
gCurrentRoomMemory = gRoomMemory;
}

void sub_08049CF4(GenericEntity* ent) {
u8 field_0x6c = ent->field_0x6c.HALF.LO;
if (field_0x6c & 0x80) {
gUnk_020354B0->unk_04 |= 1 << (field_0x6c & 0x1f);
void EnemyDisableRespawn(Enemy* ent) {
u8 idx = ent->idx;
if (idx & 0x80) {
gCurrentRoomMemory->enemyBits |= 1 << (idx & 0x1f);
}
}

u32 sub_08049D1C(u32 arg0) {
u32 bitmask = gUnk_020354B0->unk_04 >> arg0;
u32 EnemyEnableRespawn(u32 arg0) {
u32 bitmask = gCurrentRoomMemory->enemyBits >> arg0;
u32 output = 1;
output &= ~bitmask;
return output;
}

void UpdateRoomTracker(void) {
gUnk_020354B0 = gRoomMemory;
gCurrentRoomMemory = gRoomMemory;

do {
if (gUnk_020354B0->area == gRoomControls.area && gUnk_020354B0->room == gRoomControls.room) {
sub_08049DCC(gUnk_020354B0);
if (gCurrentRoomMemory->area == gRoomControls.area && gCurrentRoomMemory->room == gRoomControls.room) {
sub_08049DCC(gCurrentRoomMemory);
return;
}
gUnk_020354B0++;
gCurrentRoomMemory++;

} while (gUnk_020354B0 < gRoomMemory + 8);
gUnk_020354B0 = sub_08049D88();
} while (gCurrentRoomMemory < gRoomMemory + 8);
gCurrentRoomMemory = sub_08049D88();
}

RoomMemory* sub_08049D88(void) {
Expand All @@ -54,7 +55,7 @@ RoomMemory* sub_08049D88(void) {
rm->room = gRoomControls.room;

rm->unk_02 = 0xFFFF;
rm->unk_04 = 0;
rm->enemyBits = 0;

sub_08049DCC(rm);

Expand Down
20 changes: 0 additions & 20 deletions src/code_08049DF4.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
extern Entity* gUnk_020000B0;
extern Entity* (*const gUnk_080D3BE8[])(void);

extern void ReplaceMonitoredEntity(Entity*, Entity*);

Entity* sub_08049DF4(u32 arg0) {
if (gUnk_020000B0 != NULL) {
return gUnk_020000B0;
Expand Down Expand Up @@ -311,21 +309,3 @@ bool32 sub_0804A4BC(u8* arg0, u8* arg1, s32 arg2, u32 arg3) {

return TRUE;
}

void sub_0804A4E4(Entity* entA, Entity* entB) {
GenericEntity* r5 = (GenericEntity*)entA;
GenericEntity* r6 = (GenericEntity*)entB;

r6->field_0x6c.HALF.HI = (r5->field_0x6c.HALF.HI & 0x40) | 4;
r6->field_0x6c.HALF.LO = r5->field_0x6c.HALF.LO;
r6->field_0x70.HALF.LO = r5->field_0x70.HALF.LO;
r6->field_0x70.HALF.HI = r5->field_0x70.HALF.HI;
r6->field_0x6e.HALF.LO = r5->field_0x6e.HALF.LO;
r6->field_0x6e.HALF.HI = r5->field_0x6e.HALF.HI;

CopyPositionAndSpriteOffset(&r5->base, &r6->base);

if (r5->field_0x6c.HALF.HI & 0x40) {
ReplaceMonitoredEntity(&r5->base, &r6->base);
}
}
2 changes: 1 addition & 1 deletion src/collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ s32 CalculateDamage(Entity* org, Entity* tgt) {
}
health = org->health - damage;
if (org->kind == ENEMY) {
if ((((GenericEntity*)org)->field_0x6c.HALF.HI & 1) != 0)
if (((Enemy*)org)->enemyFlags & EM_FLAG_BOSS)
SoundReqClipped(org, SFX_BOSS_HIT);
else
SoundReqClipped(org, SFX_HIT);
Expand Down
23 changes: 0 additions & 23 deletions src/createEnemy.c

This file was deleted.

4 changes: 2 additions & 2 deletions src/enemy/acroBandits.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void AcroBandit(AcroBanditEntity* this) {
gUnk_080012C8[index](super);
} else {
AcroBandit_Functions[GetNextFunction(super)](this);
SetChildOffset(super, 0, 1, -0x10);
EnemySetFXOffset(super, 0, 1, -0x10);
}
}

Expand Down Expand Up @@ -150,7 +150,7 @@ void AcroBandit_OnCollision(AcroBanditEntity* this) {
}

if (super->confusedTime)
Create0x68FX(super, FX_STARS);
EnemyCreateFX(super, FX_STARS);

EnemyFunctionHandlerAfterCollision(super, AcroBandit_Functions);
}
Expand Down
4 changes: 2 additions & 2 deletions src/enemy/armos.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void sub_08030150(ArmosEntity* this) {

void Armos(ArmosEntity* this) {
EnemyFunctionHandler(super, (EntityActionArray)&gUnk_080CE124);
SetChildOffset(super, 0, 1, -0x10);
EnemySetFXOffset(super, 0, 1, -0x10);
sub_08030150(this);
}

Expand All @@ -101,7 +101,7 @@ void sub_080301D4(ArmosEntity* this) {
sub_080309E8(this);
}
if (super->confusedTime != 0) {
Create0x68FX(super, 0x1c);
EnemyCreateFX(super, 0x1c);
}
this->unk_81 = super->health;
EnemyFunctionHandlerAfterCollision(super, gUnk_080CE124);
Expand Down
4 changes: 2 additions & 2 deletions src/enemy/ballChainSoldier.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void BallChainSoldier_OnKnockback(BallChainSoldierEntity* this) {
}

void BallChainSoldier_OnDeath(BallChainSoldierEntity* this) {
CreateDeathFx(super, 0xff, 0x57);
EnemyCreateDeathFX((Enemy*)super, 0xff, 0x57);
}

void BallChainSoldier_OnGrabbed(BallChainSoldierEntity* this) {
Expand All @@ -64,7 +64,7 @@ void BallChainSoldier_OnGrabbed(BallChainSoldierEntity* this) {
void BallChainSoldier_Init(BallChainSoldierEntity* this) {
Entity* entity;
sub_0804A720(super);
entity = CreateProjectileWithParent(super, BALL_AND_CHAIN, 0);
entity = EnemyCreateProjectile(super, BALL_AND_CHAIN, 0);
if (entity == NULL)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/enemy/beetle.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void Beetle_OnDeath(BeetleEntity* this) {
entity->subtimer--;
super->parent = NULL;
}
CreateDeathFx(super, 0xf0, 0);
EnemyCreateDeathFX((Enemy*)super, 0xf0, 0);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/enemy/bowMoblin.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const s8 gUnk_080CFFC4[8];

void BowMoblin(Entity* this) {
EnemyFunctionHandler(this, BowMoblin_Functions);
SetChildOffset(this, 0, 1, -0x18);
EnemySetFXOffset(this, 0, 1, -0x18);
}

void BowMoblin_OnTick(BowMoblinEntity* this) {
Expand All @@ -53,7 +53,7 @@ void BowMoblin_OnCollision(BowMoblinEntity* this) {
Entity* pEVar1;

if (super->confusedTime != 0) {
Create0x68FX(super, FX_STARS);
EnemyCreateFX(super, FX_STARS);
}
EnemyFunctionHandlerAfterCollision(super, (EntityActionArray)BowMoblin_Functions);
if ((super->contactFlags & 0x80) != 0) {
Expand Down Expand Up @@ -213,7 +213,7 @@ void sub_0803C400(BowMoblinEntity* this) {
switch (++super->timer) {
case 1:
super->direction = super->animationState << 2;
projectile = CreateProjectileWithParent(super, ARROW_PROJECTILE, super->animationState >> 1);
projectile = EnemyCreateProjectile(super, ARROW_PROJECTILE, super->animationState >> 1);
if (projectile) {
super->child = projectile;
projectile->direction = (super->direction + 4) & 0x18;
Expand Down
Loading

0 comments on commit bd1be09

Please sign in to comment.