1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/**
* @file slime.c
* @ingroup Enemies
*
* @brief Slime enemy
*/
#include "enemy.h"
#include "physics.h"
#include "room.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 unused1[28];
/*0x84*/ u8 unk_84;
} SlimeEntity;
typedef struct {
s8 h, v;
} PACKED PosOffset;
void sub_08044FF8(SlimeEntity* this);
void Slime_OnTick(SlimeEntity* this);
void Slime_OnCollision(SlimeEntity* this);
void Slime_OnGrabbed(SlimeEntity* this);
void sub_08044FC8(SlimeEntity* this);
void sub_08044FF8(SlimeEntity* this);
void sub_08045018(SlimeEntity* this);
void sub_08045088(SlimeEntity* this);
void sub_080450A8(SlimeEntity* this);
void sub_08045178(SlimeEntity* this, Entity*, int, int);
static void (*const Slime_Functions[])(SlimeEntity*) = {
Slime_OnTick,
Slime_OnCollision,
(void (*)(SlimeEntity*))GenericKnockback,
(void (*)(SlimeEntity*))GenericDeath,
(void (*)(SlimeEntity*))GenericConfused,
Slime_OnGrabbed,
};
void Slime(SlimeEntity* this) {
EnemyFunctionHandler(super, (EntityActionArray)Slime_Functions);
EnemySetFXOffset(super, 0, 1, -12);
}
void Slime_OnTick(SlimeEntity* this) {
static void (*const actionFuncs[])(SlimeEntity*) = {
sub_08044FC8, sub_08044FF8, sub_08045018, sub_08045088, sub_080450A8,
};
actionFuncs[super->action](this);
}
void Slime_OnCollision(SlimeEntity* this) {
if ((super->health != 0) && (this->unk_84 != super->health)) {
super->action = 4;
} else {
EnemyFunctionHandlerAfterCollision(super, Slime_Functions);
}
if (super->confusedTime != 0) {
EnemyCreateFX(super, FX_STARS);
}
}
void Slime_OnGrabbed(SlimeEntity* this) {
}
void sub_08044FC8(SlimeEntity* this) {
super->action = 1;
super->spriteSettings.draw = 1;
super->speed = 128;
sub_0804A720(super);
InitializeAnimation(super, 0);
sub_08044FF8(this);
}
void sub_08044FF8(SlimeEntity* this) {
super->action = 2;
super->timer = (Random() & 0x1F) + 30;
this->unk_84 = super->health;
}
void sub_08045018(SlimeEntity* this) {
GetNextFrame(super);
if (--super->timer == 0) {
super->action = 3;
super->timer = 1;
if (0 < super->speed) {
super->timer = FixedDiv(0x1000, super->speed) >> 8;
}
if (sub_08049FA0(super) == 0 && (Random() & 3)) {
super->direction = (sub_08049EE4(super) + 0xfc + (Random() & 8)) & 24;
return;
}
super->direction = Random() & 24;
}
}
void sub_08045088(SlimeEntity* this) {
ProcessMovement0(super);
GetNextFrame(super);
if (--super->timer == 0) {
super->action = 1;
}
}
/* Split slime into new ones */
void sub_080450A8(SlimeEntity* this) {
Entity* entities[4];
Entity* entity;
s32 count, i;
const PosOffset* off;
static const u8 typeEntityCount[4] = { 2, 2, 4, 2 };
static const PosOffset gUnk_080D16D4[4] = { { 6, 0 }, { -6, 0 }, { 0, 6 }, { 0, -6 } };
/* Can we create enough new entities? */
count = typeEntityCount[super->type];
if (MAX_ENTITIES - count <= gEntCount)
return;
/* Create 2-4 new MiniSlime */
for (i = 0; i < count; i++)
entities[i] = CreateEnemy(MINI_SLIME, super->type);
off = gUnk_080D16D4;
for (i = 0; i < count; i++) {
entity = entities[i];
entity->child = entities[(i + 1) % count];
entity->parent = entities[(i + count - 1) % count];
entity->type2 = 1;
entity->z.HALF.HI = 0;
entity->iframes = -0x10;
/* Set MiniSlime offset relative to killed slime. */
sub_08045178(this, entity, off->h, off->v);
off++;
}
entity = CreateFx(super, FX_DEATH, 0);
if (entity != NULL)
CopyPosition(super, entity);
DeleteEntity(super);
}
void sub_08045178(SlimeEntity* this, Entity* child, int offsetX, int offsetY) {
int x, y;
if (child == NULL)
return;
EnemyCopyParams(super, child);
if (GetCollisionDataRelativeTo(child, offsetX, offsetY))
return;
x = child->x.HALF.HI + offsetX;
if (0 <= x && x < (gRoomControls.origin_x + gRoomControls.width))
child->x.HALF.HI = x;
y = child->y.HALF.HI + offsetY;
if (0 <= y && y < (gRoomControls.origin_y + gRoomControls.height))
child->y.HALF.HI = y;
}
|