Skip to content

Commit 201955e

Browse files
committed
create enemy struct and enemy flags
1 parent 3771464 commit 201955e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+375
-345
lines changed

asm/src/code_08003FC4.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,17 @@ _08004162:
258258
ands r2, r4
259259
pop {r4, pc}
260260

261-
thumb_func_start sub_08004168
262-
sub_08004168: @ 0x08004168
261+
thumb_func_start SnapToTile
262+
SnapToTile: @ 0x08004168
263263
ldr r3, _08004384 @ =0x000FFFFF
264264
ldr r1, _08004388 @ =0x00080000
265-
ldr r2, [r0, #0x2c]
266-
bics r2, r3
267-
adds r2, r2, r1
265+
ldr r2, [r0, #0x2c] // x
266+
bics r2, r3 // align to grid
267+
adds r2, r1 // add half of a tile
268268
str r2, [r0, #0x2c]
269-
ldr r2, [r0, #0x30]
269+
ldr r2, [r0, #0x30] // y
270270
bics r2, r3
271-
adds r2, r2, r1
271+
adds r2, r1
272272
str r2, [r0, #0x30]
273273
bx lr
274274

asm/src/enemy.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ GenericConfused: @ 0x08001242
105105
cmp r2, #0x1c
106106
bne _08001282
107107
push {r0}
108-
bl sub_0804AA1C
108+
bl EnemyDetachFX
109109
pop {r0}
110110
_08001282:
111111
ldr r1, _08001364 @ =0x00001800

include/enemy.h

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,35 @@
1212
#include "entity.h"
1313
#include "projectile.h"
1414

15-
bool32 EnemyInit(Entity* this);
15+
#define EM_FLAG_BOSS (1 << 0)
16+
#define EM_FLAG_BOSS_KILLED (1 << 1)
17+
#define EM_FLAG_HAS_HOME (1 << 2)
18+
#define EM_FLAG_NO_DEATH_FX (1 << 3)
19+
#define EM_FLAG_SUPPORT (1 << 4)
20+
#define EM_FLAG_CAPTAIN (1 << 5)
21+
#define EM_FLAG_MONITORED (1 << 6)
22+
23+
typedef struct {
24+
Entity base;
25+
Entity* child;
26+
u8 idx;
27+
u8 enemyFlags;
28+
u8 rangeX;
29+
u8 rangeY;
30+
s16 homeX;
31+
s16 homeY;
32+
/*0x74*/ union SplitHWord field_0x74;
33+
/*0x76*/ union SplitHWord field_0x76;
34+
/*0x78*/ union SplitHWord field_0x78;
35+
/*0x7a*/ union SplitHWord field_0x7a;
36+
/*0x7c*/ union SplitWord field_0x7c;
37+
/*0x80*/ union SplitHWord field_0x80;
38+
/*0x82*/ union SplitHWord field_0x82;
39+
/*0x84*/ union SplitHWord cutsceneBeh;
40+
/*0x86*/ union SplitHWord field_0x86;
41+
} Enemy;
42+
43+
bool32 EnemyInit(Enemy* this);
1644
/**
1745
* 0: _OnTick
1846
* 1: _OnCollision
@@ -25,13 +53,13 @@ u32 GetNextFunction(Entity*);
2553
void EnemyFunctionHandler(Entity*, EntityActionArray);
2654
void EnemyFunctionHandlerAfterCollision(Entity*, void (*const[])());
2755
void GenericKnockback(Entity*);
28-
Entity* CreateDeathFx(Entity*, u32, u32);
56+
void EnemyCreateDeathFX(Enemy*, u32, u32);
2957
void sub_0804A720(Entity*);
3058
bool32 sub_08049FDC(Entity*, u32);
3159

32-
Entity* Create0x68FX(Entity*, u32);
33-
void SetChildOffset(Entity*, s32, s32, s32);
34-
Entity* CreateProjectileWithParent(Entity*, u8, u8);
60+
Entity* EnemyCreateFX(Entity*, u32);
61+
void EnemySetFXOffset(Entity*, s32, s32, s32);
62+
Entity* EnemyCreateProjectile(Entity*, u32, u32);
3563

3664
void GenericDeath(Entity*);
3765
void sub_08002724(void*, u8*);
@@ -44,13 +72,13 @@ Entity* sub_08049DF4(u32);
4472
u32 sub_0804A044(Entity*, Entity*, u32);
4573
s32 sub_080012DC(Entity*);
4674

47-
void sub_0804AA1C(Entity*);
75+
void EnemyDetachFX(Entity*);
4876
bool32 sub_08049F1C(Entity*, Entity*, s32);
4977
bool32 PlayerInRange(Entity*, u32, s32);
50-
void sub_0804A4E4(Entity*, Entity*);
78+
void EnemyCopyParams(Entity*, Entity*);
5179
void GenericKnockback2(Entity*);
5280

53-
typedef enum {
81+
enum {
5482
/*0x00*/ OCTOROK,
5583
/*0x01*/ CHUCHU,
5684
/*0x02*/ LEEVER,
@@ -154,7 +182,7 @@ typedef enum {
154182
/*0x64*/ ENEMY_64,
155183
/*0x65*/ TREE_ITEM,
156184
/*0x66*/ ENEMY_66
157-
} Enemy;
185+
};
158186

159187
void Octorok();
160188
void Chuchu();

include/functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern void sub_080027EA(Entity*, u32, u32);
6161
extern void sub_080028E0(Entity*);
6262
extern u32 sub_080040A2(Entity*);
6363
extern u32 sub_080040D8(Entity*, u8*, s32, s32);
64-
extern void sub_08004168(Entity*);
64+
extern void SnapToTile(Entity*);
6565
extern u32 sub_0800419C(Entity*, Entity*, u32, u32);
6666
extern u32 sub_080041DC(Entity*, u32, u32);
6767
extern void sub_080042BA(Entity*, u32);
@@ -81,7 +81,7 @@ extern void UpdateUIElements(void);
8181
extern void sub_0801E104(void);
8282
extern void sub_08030118(u32);
8383
extern void sub_0803C0AC(Entity*);
84-
extern void sub_08049CF4(Entity*);
84+
extern void EnemyDisableRespawn(Entity*);
8585
extern u32 sub_0804A024(Entity*, u32, u32);
8686
extern u32 IsMinishItem(u32);
8787
extern void DisableRandomDrops();

include/room.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ typedef struct {
8888
u8 area;
8989
u8 room;
9090
u16 unk_02;
91-
u32 unk_04;
91+
u32 enemyBits;
9292
} RoomMemory;
9393

94-
extern RoomMemory* gUnk_020354B0;
94+
extern RoomMemory* gCurrentRoomMemory;
9595
extern RoomMemory gRoomMemory[];
9696

9797
// Packets used to store which entities to load in a room

linker.ld

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ SECTIONS {
8888
. = 0x000344A0; gUnk_020344A0 = .;
8989
. = 0x000344B0; gBG2Buffer = .;
9090
. = 0x00034CB0; gBG0Buffer = .;
91-
. = 0x000354B0; gUnk_020354B0 = .;
91+
. = 0x000354B0; gCurrentRoomMemory = .;
9292
. = 0x000354B4; gManagerCount = .;
9393
. = 0x000354C0; gUnk_020354C0 = .;
9494
. = 0x00035540; gzHeap = .;
@@ -386,7 +386,6 @@ SECTIONS {
386386
src/code_08049CD4.o(.text); /* enemyUtils.c */
387387
src/code_08049DF4.o(.text);
388388
src/enemyUtils.o(.text);
389-
src/createEnemy.o(.text);
390389
src/enterPortalSubtask.o(.text);
391390
src/room.o(.text);
392391
src/roomInit.o(.text);

src/code_08049CD4.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "global.h"
22
#include "room.h"
3+
#include "enemy.h"
34

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

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

910
void ClearRoomMemory(void) {
1011
MemFill32(0xFFFFFFFF, gRoomMemory, 0x40);
11-
gUnk_020354B0 = gRoomMemory;
12+
gCurrentRoomMemory = gRoomMemory;
1213
}
1314

14-
void sub_08049CF4(GenericEntity* ent) {
15-
u8 field_0x6c = ent->field_0x6c.HALF.LO;
16-
if (field_0x6c & 0x80) {
17-
gUnk_020354B0->unk_04 |= 1 << (field_0x6c & 0x1f);
15+
void EnemyDisableRespawn(Enemy* ent) {
16+
u8 idx = ent->idx;
17+
if (idx & 0x80) {
18+
gCurrentRoomMemory->enemyBits |= 1 << (idx & 0x1f);
1819
}
1920
}
2021

21-
u32 sub_08049D1C(u32 arg0) {
22-
u32 bitmask = gUnk_020354B0->unk_04 >> arg0;
22+
u32 EnemyEnableRespawn(u32 arg0) {
23+
u32 bitmask = gCurrentRoomMemory->enemyBits >> arg0;
2324
u32 output = 1;
2425
output &= ~bitmask;
2526
return output;
2627
}
2728

2829
void UpdateRoomTracker(void) {
29-
gUnk_020354B0 = gRoomMemory;
30+
gCurrentRoomMemory = gRoomMemory;
3031

3132
do {
32-
if (gUnk_020354B0->area == gRoomControls.area && gUnk_020354B0->room == gRoomControls.room) {
33-
sub_08049DCC(gUnk_020354B0);
33+
if (gCurrentRoomMemory->area == gRoomControls.area && gCurrentRoomMemory->room == gRoomControls.room) {
34+
sub_08049DCC(gCurrentRoomMemory);
3435
return;
3536
}
36-
gUnk_020354B0++;
37+
gCurrentRoomMemory++;
3738

38-
} while (gUnk_020354B0 < gRoomMemory + 8);
39-
gUnk_020354B0 = sub_08049D88();
39+
} while (gCurrentRoomMemory < gRoomMemory + 8);
40+
gCurrentRoomMemory = sub_08049D88();
4041
}
4142

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

5657
rm->unk_02 = 0xFFFF;
57-
rm->unk_04 = 0;
58+
rm->enemyBits = 0;
5859

5960
sub_08049DCC(rm);
6061

src/code_08049DF4.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
extern Entity* gUnk_020000B0;
1111
extern Entity* (*const gUnk_080D3BE8[])(void);
1212

13-
extern void ReplaceMonitoredEntity(Entity*, Entity*);
14-
1513
Entity* sub_08049DF4(u32 arg0) {
1614
if (gUnk_020000B0 != NULL) {
1715
return gUnk_020000B0;
@@ -311,21 +309,3 @@ bool32 sub_0804A4BC(u8* arg0, u8* arg1, s32 arg2, u32 arg3) {
311309

312310
return TRUE;
313311
}
314-
315-
void sub_0804A4E4(Entity* entA, Entity* entB) {
316-
GenericEntity* r5 = (GenericEntity*)entA;
317-
GenericEntity* r6 = (GenericEntity*)entB;
318-
319-
r6->field_0x6c.HALF.HI = (r5->field_0x6c.HALF.HI & 0x40) | 4;
320-
r6->field_0x6c.HALF.LO = r5->field_0x6c.HALF.LO;
321-
r6->field_0x70.HALF.LO = r5->field_0x70.HALF.LO;
322-
r6->field_0x70.HALF.HI = r5->field_0x70.HALF.HI;
323-
r6->field_0x6e.HALF.LO = r5->field_0x6e.HALF.LO;
324-
r6->field_0x6e.HALF.HI = r5->field_0x6e.HALF.HI;
325-
326-
CopyPositionAndSpriteOffset(&r5->base, &r6->base);
327-
328-
if (r5->field_0x6c.HALF.HI & 0x40) {
329-
ReplaceMonitoredEntity(&r5->base, &r6->base);
330-
}
331-
}

src/collision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ s32 CalculateDamage(Entity* org, Entity* tgt) {
247247
}
248248
health = org->health - damage;
249249
if (org->kind == ENEMY) {
250-
if ((((GenericEntity*)org)->field_0x6c.HALF.HI & 1) != 0)
250+
if (((Enemy*)org)->enemyFlags & EM_FLAG_BOSS)
251251
SoundReqClipped(org, SFX_BOSS_HIT);
252252
else
253253
SoundReqClipped(org, SFX_HIT);

src/createEnemy.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/enemy/acroBandits.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void AcroBandit(AcroBanditEntity* this) {
8181
gUnk_080012C8[index](super);
8282
} else {
8383
AcroBandit_Functions[GetNextFunction(super)](this);
84-
SetChildOffset(super, 0, 1, -0x10);
84+
EnemySetFXOffset(super, 0, 1, -0x10);
8585
}
8686
}
8787

@@ -150,7 +150,7 @@ void AcroBandit_OnCollision(AcroBanditEntity* this) {
150150
}
151151

152152
if (super->confusedTime)
153-
Create0x68FX(super, FX_STARS);
153+
EnemyCreateFX(super, FX_STARS);
154154

155155
EnemyFunctionHandlerAfterCollision(super, AcroBandit_Functions);
156156
}

src/enemy/armos.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void sub_08030150(ArmosEntity* this) {
8383

8484
void Armos(ArmosEntity* this) {
8585
EnemyFunctionHandler(super, (EntityActionArray)&gUnk_080CE124);
86-
SetChildOffset(super, 0, 1, -0x10);
86+
EnemySetFXOffset(super, 0, 1, -0x10);
8787
sub_08030150(this);
8888
}
8989

@@ -101,7 +101,7 @@ void sub_080301D4(ArmosEntity* this) {
101101
sub_080309E8(this);
102102
}
103103
if (super->confusedTime != 0) {
104-
Create0x68FX(super, 0x1c);
104+
EnemyCreateFX(super, 0x1c);
105105
}
106106
this->unk_81 = super->health;
107107
EnemyFunctionHandlerAfterCollision(super, gUnk_080CE124);

src/enemy/ballChainSoldier.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void BallChainSoldier_OnKnockback(BallChainSoldierEntity* this) {
5555
}
5656

5757
void BallChainSoldier_OnDeath(BallChainSoldierEntity* this) {
58-
CreateDeathFx(super, 0xff, 0x57);
58+
EnemyCreateDeathFX((Enemy*)super, 0xff, 0x57);
5959
}
6060

6161
void BallChainSoldier_OnGrabbed(BallChainSoldierEntity* this) {
@@ -64,7 +64,7 @@ void BallChainSoldier_OnGrabbed(BallChainSoldierEntity* this) {
6464
void BallChainSoldier_Init(BallChainSoldierEntity* this) {
6565
Entity* entity;
6666
sub_0804A720(super);
67-
entity = CreateProjectileWithParent(super, BALL_AND_CHAIN, 0);
67+
entity = EnemyCreateProjectile(super, BALL_AND_CHAIN, 0);
6868
if (entity == NULL)
6969
return;
7070

src/enemy/beetle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void Beetle_OnDeath(BeetleEntity* this) {
7070
entity->subtimer--;
7171
super->parent = NULL;
7272
}
73-
CreateDeathFx(super, 0xf0, 0);
73+
EnemyCreateDeathFX((Enemy*)super, 0xf0, 0);
7474
}
7575
}
7676

src/enemy/bowMoblin.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const s8 gUnk_080CFFC4[8];
4242

4343
void BowMoblin(Entity* this) {
4444
EnemyFunctionHandler(this, BowMoblin_Functions);
45-
SetChildOffset(this, 0, 1, -0x18);
45+
EnemySetFXOffset(this, 0, 1, -0x18);
4646
}
4747

4848
void BowMoblin_OnTick(BowMoblinEntity* this) {
@@ -53,7 +53,7 @@ void BowMoblin_OnCollision(BowMoblinEntity* this) {
5353
Entity* pEVar1;
5454

5555
if (super->confusedTime != 0) {
56-
Create0x68FX(super, FX_STARS);
56+
EnemyCreateFX(super, FX_STARS);
5757
}
5858
EnemyFunctionHandlerAfterCollision(super, (EntityActionArray)BowMoblin_Functions);
5959
if ((super->contactFlags & 0x80) != 0) {
@@ -213,7 +213,7 @@ void sub_0803C400(BowMoblinEntity* this) {
213213
switch (++super->timer) {
214214
case 1:
215215
super->direction = super->animationState << 2;
216-
projectile = CreateProjectileWithParent(super, ARROW_PROJECTILE, super->animationState >> 1);
216+
projectile = EnemyCreateProjectile(super, ARROW_PROJECTILE, super->animationState >> 1);
217217
if (projectile) {
218218
super->child = projectile;
219219
projectile->direction = (super->direction + 4) & 0x18;

0 commit comments

Comments
 (0)