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
|
/**
* @file zelda.c
* @ingroup NPCs
*
* @brief Zelda NPC
*/
#include "npc/zelda.h"
#include "entity.h"
#include "flags.h"
#include "script.h"
#include "physics.h"
#include "npc.h"
#include "sound.h"
#include "tiles.h"
#include "asm.h"
#include "room.h"
#include "player.h"
#include "map.h"
void ZeldaFollower_Hide(Entity*, Entity*);
void ZeldaFollower_Show(Entity*, Entity*);
extern Entity* GetEntityByType(u32, u32);
extern void sub_080686C4(Entity*, Entity*);
void sub_08066CCC(Entity*);
void sub_08066CF8(Entity*);
void Zelda(Entity* this) {
static void (*const gUnk_08110BD8[])(Entity * ent) = {
sub_08066CCC,
sub_08066CF8,
};
gUnk_08110BD8[this->action](this);
}
void sub_08066CCC(Entity* this) {
this->action = 1;
this->spriteSettings.draw = 1;
PrependEntityToList(this, 7);
SetEntityPriority(this, PRIO_MESSAGE);
InitScriptForNPC(this);
}
void sub_08066CF8(Entity* this) {
ExecuteScriptAndHandleAnimation(this, NULL);
}
void sub_08066D04(Entity* this) {
this->parent = DeepFindEntityByID(NPC, ZELDA_FOLLOWER);
}
void sub_08066D14(Entity* this, ScriptExecutionContext* context) {
Entity* parent;
parent = this->parent;
if (parent != NULL) {
this->animationState = parent->animationState;
this->spriteSettings.draw = 1;
CopyPosition(parent, this);
ZeldaFollower_Hide(this, this->parent);
context->condition = 1;
} else {
context->condition = 0;
}
}
void sub_08066D4C(Entity* this, ScriptExecutionContext* context) {
Entity* parent = this->parent;
if (this->parent != NULL) {
CopyPosition(this, parent);
this->parent->spriteSettings.draw = 1;
this->parent->animationState = this->animationState;
this->spriteSettings.draw = 0;
this->followerFlag &= 0xFE;
ZeldaFollower_Show(this, this->parent);
context->condition = 1;
} else {
context->condition = 0;
}
}
void sub_08066D94(Entity* this) {
u32 room;
ZeldaFollowerEntity* npc;
SetGlobalFlag(ZELDA_CHASE);
npc = (ZeldaFollowerEntity*)CreateNPC(ZELDA_FOLLOWER, 0, 0);
if (npc != NULL) {
npc->base.animationState = gPlayerEntity.base.animationState;
npc->base.flags |= ENT_PERSIST;
npc->base.animationState = GetAnimationState(this);
room = gRoomControls.room;
npc->unk_74 = room;
CopyPosition(this, &npc->base);
}
DeleteThisEntity();
}
void SetZeldaFollowTarget(Entity* target) {
Entity* follower = DeepFindEntityByID(NPC, ZELDA_FOLLOWER);
if (follower != NULL) {
CopyPosition(target, follower);
sub_080686C4(target, follower);
}
}
void sub_08066E08(ZeldaEntity* this) {
InitAnimationForceUpdate(super, 0x50);
this->unk_80 = super->animIndex;
}
void sub_08066E20(ZeldaEntity* this) {
InitAnimationForceUpdate(super, 0x44);
this->unk_80 = super->animIndex;
}
void sub_08066E38(ZeldaEntity* this) {
InitAnimationForceUpdate(super, 0x48);
this->unk_80 = super->animIndex;
}
void sub_08066E50(ZeldaEntity* this) {
InitAnimationForceUpdate(super, 0x4C);
this->unk_80 = super->animIndex;
}
void sub_08066E68(ZeldaEntity* this) {
InitAnimationForceUpdate(super, 0x54);
this->unk_80 = super->animIndex;
}
void sub_08066E80(Entity* this, ScriptExecutionContext* context) {
switch (context->unk_18) {
case 0:
context->unk_18++;
InitAnimationForceUpdate(this, 0x16);
break;
case 1:
UpdateAnimationSingleFrame(this);
if (this->frame & 1) {
context->unk_18++;
this->zVelocity = Q_16_16(2.0);
this->frame &= 0xFE;
SoundReq(SFX_PLY_JUMP);
}
break;
case 2:
LinearMoveAngle(this, 0x100, 0x80);
GravityUpdate(this, Q_8_8(32.0));
if (!(this->frame & 1)) {
UpdateAnimationSingleFrame(this);
}
if (this->zVelocity < 0) {
context->unk_18++;
}
break;
case 3:
LinearMoveAngle(this, 0x100, 0x80);
UpdateAnimationSingleFrame(this);
if (GravityUpdate(this, Q_8_8(32.0)) == 0) {
context->unk_18++;
InitAnimationForceUpdate(this, 0x1E);
}
break;
case 4:
UpdateAnimationSingleFrame(this);
if (this->frame & ANIM_DONE) {
gActiveScriptInfo.flags |= 1;
return;
}
}
((ZeldaEntity*)this)->unk_80 = this->animIndex;
gActiveScriptInfo.commandSize = 0;
}
static const u16 gUnk_08110BE0[] = {
0x81c, 0x85c, 0x89c, 0x8dc, 0x91c, 0x95c, 0x99c, 0x9dc, 0x9dd, 0x9de, 0x9df, 0x9e0, 0x9e1, 0x9e2, 0x0, 0x0,
};
void sub_08066F94(void) {
u16 tilePos;
const u16* puVar2;
puVar2 = gUnk_08110BE0;
while (*puVar2 != 0) {
tilePos = *puVar2;
puVar2++;
SetTileType(SPECIAL_TILE_114, tilePos, LAYER_BOTTOM);
}
}
void sub_08066FB8(void) {
u16 uVar1;
const u16* puVar2;
puVar2 = gUnk_08110BE0;
while (*puVar2 != 0) {
uVar1 = *puVar2;
puVar2++;
RestorePrevTileEntity(uVar1, 1);
}
}
|