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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/**
* @file smith.c
* @ingroup NPCs
*
* @brief Smith NPC
*/
#include "physics.h"
#include "npc.h"
#include "sound.h"
#include "save.h"
#include "flags.h"
#include "effects.h"
#include "message.h"
#include "script.h"
#include "asm.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 fusionOffer;
/*0x69*/ u8 unused[23];
/*0x80*/ u16 unk_80;
} SmithEntity;
static const SpriteLoadData gUnk_08110354[] = {
{ 0x4d, 0x38, 0x4 },
{ 0x4004, 0x38, 0x4 },
{ 0, 0, 0 },
};
void sub_080660EC(SmithEntity*);
void sub_08066118(SmithEntity*);
void sub_08066170(SmithEntity*);
void sub_08066178(SmithEntity*);
void sub_080661B0(SmithEntity*);
void sub_080661BC(SmithEntity*);
void sub_08066200(SmithEntity*);
void sub_08066218(SmithEntity*);
void Smith(SmithEntity* this) {
static void (*const actionFuncs[])(SmithEntity*) = {
sub_080660EC,
sub_08066118,
sub_08066170,
};
static void (*const scriptedActionFuncs[])(SmithEntity*) = {
sub_08066178, sub_080661B0, sub_080661BC, sub_08066200, sub_08066218,
};
static const u16 gUnk_08110380[] = {
0xdc, 0xdd, 0xde, 0xdc, 0xdd, 0xde, 0xdc, 0xdd,
};
u32 index;
if ((super->flags & ENT_SCRIPTED) != 0) {
if (super->interactType == INTERACTION_FUSE) {
super->action = 4;
super->interactType = INTERACTION_NONE;
index = (super->animIndex == 0xc) ? 8 : 0;
index += GetAnimationStateForDirection4(GetFacingDirection(super, &gPlayerEntity.base));
InitAnimationForceUpdate(super, index);
InitializeNPCFusion(super);
}
scriptedActionFuncs[super->action](this);
} else {
actionFuncs[super->action](this);
sub_0806ED78(super);
}
if (super->animIndex == 0xc) {
super->spritePriority.b1 = 0;
} else {
super->spritePriority.b1 = 1;
}
if ((super->frame & 1) != 0) {
super->frame &= 0xfe;
CreateFx(super, FX_STARS2, 0x20);
SoundReq(gUnk_08110380[(Random() & 7)]);
}
}
void Smith_Head(Entity* this) {
u8 bVar1;
bVar1 = this->frame;
SetExtraSpriteFrame(this, 0, this->frameIndex);
if ((bVar1 & 0x40) != 0) {
SetExtraSpriteFrame(this, 1, 0x16);
} else {
SetExtraSpriteFrame(this, 1, 0xff);
}
SetSpriteSubEntryOffsetData1(this, 0, 1);
sub_0807000C(this);
}
void sub_080660EC(SmithEntity* this) {
if (LoadExtraSpriteData(super, gUnk_08110354)) {
super->action = 1;
this->fusionOffer = GetFusionToOffer(super);
InitAnimationForceUpdate(super, 2);
}
}
void sub_08066118(SmithEntity* this) {
s32 uVar1;
uVar1 = GetAnimationStateInRectRadius(super, 0x28, 0x28);
if (uVar1 < 0) {
uVar1 = 2;
} else {
if (super->subtimer == 0) {
super->subtimer = 16;
} else {
--super->subtimer;
uVar1 = super->animIndex;
}
}
if (sub_0806F078(super, uVar1) == 0) {
UpdateAnimationSingleFrame(super);
}
if (super->interactType != INTERACTION_NONE) {
super->action = 2;
MessageFromTarget(0);
}
}
void sub_08066170(SmithEntity* this) {
super->action = 1;
}
void sub_08066178(SmithEntity* this) {
if (LoadExtraSpriteData(super, gUnk_08110354)) {
super->action = 1;
super->spriteSettings.draw = 1;
this->fusionOffer = GetFusionToOffer(super);
InitScriptForNPC(super);
}
}
void sub_080661B0(SmithEntity* this) {
ExecuteScriptAndHandleAnimation(super, NULL);
}
void sub_080661BC(SmithEntity* this) {
if (super->animIndex == 0xc) {
UpdateAnimationSingleFrame(super);
if (super->frame & ANIM_DONE) {
this->unk_80 = GetAnimationState(super) + 8;
InitAnimationForceUpdate(super, this->unk_80);
}
} else {
ExecuteScriptAndHandleAnimation(super, NULL);
}
}
void sub_08066200(SmithEntity* this) {
ExecuteScriptForEntity(super, NULL);
HandleEntity0x82Actions(super);
UpdateAnimationSingleFrame(super);
}
void sub_08066218(SmithEntity* this) {
if (UpdateFuseInteraction(super) != 0) {
super->action = 1;
}
}
void sub_0806622C(Entity* this) {
static const Dialog dialogs[] = {
{ TABIDACHI,
DIALOG_GLOBAL_FLAG,
DIALOG_CHECK_FLAG,
1,
{ TEXT_INDEX(TEXT_SMITH, 0x01), TEXT_INDEX(TEXT_PROLOGUE, 0x0e) } },
{ TABIDACHI,
DIALOG_GLOBAL_FLAG,
DIALOG_CHECK_FLAG,
1,
{ TEXT_INDEX(TEXT_SMITH, 0x01), TEXT_INDEX(TEXT_PROLOGUE, 0x0e) } },
{ TABIDACHI,
DIALOG_GLOBAL_FLAG,
DIALOG_CHECK_FLAG,
1,
{ TEXT_INDEX(TEXT_SMITH, 0x02), TEXT_INDEX(TEXT_PROLOGUE, 0x0e) } },
{ TABIDACHI,
DIALOG_GLOBAL_FLAG,
DIALOG_CHECK_FLAG,
1,
{ TEXT_INDEX(TEXT_SMITH, 0x03), TEXT_INDEX(TEXT_PROLOGUE, 0x0e) } },
{ TABIDACHI,
DIALOG_GLOBAL_FLAG,
DIALOG_CHECK_FLAG,
1,
{ TEXT_INDEX(TEXT_SMITH, 0x04), TEXT_INDEX(TEXT_PROLOGUE, 0x0e) } },
{ TABIDACHI,
DIALOG_GLOBAL_FLAG,
DIALOG_CHECK_FLAG,
1,
{ TEXT_INDEX(TEXT_SMITH, 0x05), TEXT_INDEX(TEXT_PROLOGUE, 0x0e) } },
{ TABIDACHI,
DIALOG_GLOBAL_FLAG,
DIALOG_CHECK_FLAG,
1,
{ TEXT_INDEX(TEXT_SMITH, 0x06), TEXT_INDEX(TEXT_PROLOGUE, 0x0e) } },
{ TABIDACHI,
DIALOG_GLOBAL_FLAG,
DIALOG_CHECK_FLAG,
1,
{ TEXT_INDEX(TEXT_SMITH, 0x06), TEXT_INDEX(TEXT_PROLOGUE, 0x0e) } },
};
u32 index;
if (gSave.global_progress - 2 < 0) {
index = 0;
} else {
index = gSave.global_progress - 2;
}
ShowNPCDialogue(this, &dialogs[index]);
}
void nullsub_501(Entity* this) {
}
void sub_08066258(void) {
static const u16 hammerSounds[] = {
SFX_HAMMER4, SFX_HAMMER5, SFX_HAMMER6, SFX_HAMMER4, SFX_HAMMER5, SFX_HAMMER6, SFX_HAMMER4, SFX_HAMMER5,
};
SoundReq(hammerSounds[Random() & 7]);
}
void Smith_ChangeInteractableHitbox(Entity* this) {
static const Rect gUnk_081103E0 = { 0, 6, 8, 12 };
SetInteractableObjectCollision(this, 1, 0, &gUnk_081103E0);
}
void Smith_MakeInteractable(SmithEntity* this) {
AddInteractableWhenBigFuser(super, this->fusionOffer);
}
void Smith_Fusion(Entity* this) {
if (this->action == 0) {
if (LoadExtraSpriteData(this, gUnk_08110354)) {
this->action++;
this->spriteSettings.draw = 1;
InitAnimationForceUpdate(this, 6);
}
} else {
UpdateAnimationSingleFrame(this);
}
}
|