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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
#include "array_count.h"
#include "terminal.h"
#include "z_lib.h"
#include "printf.h"
#include "regs.h"
#include "translation.h"
#include "horse.h"
#include "play_state.h"
#include "player.h"
#include "save.h"
#include "overlays/actors/ovl_En_Horse/z_en_horse.h"
/**
* Tests if the player horse can be spawned
*
* @param sceneId the checked scene
* @return true if the player horse can appear in the scene, else false
*/
s32 Horse_CanSpawn(s32 sceneId) {
s32 validSceneIds[] = { SCENE_HYRULE_FIELD, SCENE_LAKE_HYLIA, SCENE_GERUDO_VALLEY, SCENE_GERUDOS_FORTRESS,
SCENE_LON_LON_RANCH };
s32 i;
for (i = 0; i < ARRAY_COUNT(validSceneIds); i++) {
if (sceneId == validSceneIds[i]) {
return true;
}
}
return false;
}
/**
* Sets horseData to a neutral spawn in Hyrule Field
*/
void Horse_ResetHorseData(PlayState* play) {
gSaveContext.save.info.horseData.sceneId = SCENE_HYRULE_FIELD;
gSaveContext.save.info.horseData.pos.x = -1840;
gSaveContext.save.info.horseData.pos.y = 72;
gSaveContext.save.info.horseData.pos.z = 5497;
gSaveContext.save.info.horseData.angle = -0x6AD9;
}
/**
* Forces the player horse to spawn in a safe spot if the current spawn is in Lake Hylia
* This prevents the horse from spawning underwater after obtaining the Water Medallion
*/
void Horse_FixLakeHyliaPosition(PlayState* play) {
if (gSaveContext.save.info.horseData.sceneId == SCENE_LAKE_HYLIA) {
gSaveContext.save.info.horseData.sceneId = SCENE_LAKE_HYLIA;
gSaveContext.save.info.horseData.pos.x = -2065;
gSaveContext.save.info.horseData.pos.y = -863;
gSaveContext.save.info.horseData.pos.z = 1839;
gSaveContext.save.info.horseData.angle = 0;
}
}
typedef struct HorseSpawn {
/* 0x00 */ s16 sceneId;
/* 0x02 */ Vec3s pos;
/* 0x08 */ s16 angle;
/* 0x0A */ s16 type;
} HorseSpawn;
void Horse_SetupInGameplay(PlayState* play, Player* player) {
s32 i;
HorseSpawn horseSpawns[] = {
{ SCENE_HYRULE_FIELD, -460, 100, 6640, 0, HORSE_PTYPE_INACTIVE },
{ SCENE_LAKE_HYLIA, -1929, -1025, 768, 0, HORSE_PTYPE_INACTIVE },
{ SCENE_GERUDO_VALLEY, 2566, -259, 767, 0, HORSE_PTYPE_INACTIVE },
{ SCENE_GERUDOS_FORTRESS, -328, 10, 953, 0, HORSE_PTYPE_INACTIVE },
{ SCENE_LON_LON_RANCH, 928, 0, -2280, 0, HORSE_PTYPE_INACTIVE },
};
if (R_EXITED_SCENE_RIDING_HORSE &&
(Flags_GetEventChkInf(EVENTCHKINF_EPONA_OBTAINED) || R_DEBUG_FORCE_EPONA_OBTAINED)) {
// Player entering scene on top of horse
player->rideActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, player->actor.world.pos.x, player->actor.world.pos.y,
player->actor.world.pos.z, player->actor.shape.rot.x, player->actor.shape.rot.y,
player->actor.shape.rot.z, HORSE_PTYPE_PLAYER_SPAWNED_RIDING);
ASSERT(player->rideActor != NULL, "player->ride.actor != NULL", "../z_horse.c", 343);
Actor_MountHorse(play, player, player->rideActor);
Actor_RequestHorseCameraSetting(play, player);
gSaveContext.save.info.horseData.sceneId = play->sceneId;
if (play->sceneId == SCENE_GERUDOS_FORTRESS) {
player->rideActor->room = -1;
}
} else if ((play->sceneId == SCENE_GERUDOS_FORTRESS) && (gSaveContext.minigameState == 3)) {
// Completed Horseback Archery Minigame
Actor* horseActor;
gSaveContext.minigameState = 0;
horseActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, 3586.0f, 1413.0f, -402.0f, 0, 0x4000, 0, HORSE_PTYPE_1);
horseActor->room = -1;
} else if ((gSaveContext.save.entranceIndex == ENTR_LON_LON_RANCH_7) &&
GET_EVENTCHKINF(EVENTCHKINF_EPONA_OBTAINED)) {
// Completed Horse Race
Actor* horseActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, -25.0f, 0.0f, -1600.0f, 0, -0x4000, 0, HORSE_PTYPE_1);
ASSERT(horseActor != NULL, "horse_actor != NULL", "../z_horse.c", 389);
} else if ((play->sceneId == gSaveContext.save.info.horseData.sceneId) &&
(Flags_GetEventChkInf(EVENTCHKINF_EPONA_OBTAINED) || R_DEBUG_FORCE_EPONA_OBTAINED)) {
// Player enters a scene where the horse was left previously
PRINTF(T("馬存在によるセット %d %d %d\n", "Set by existence of horse %d %d %d\n"),
gSaveContext.save.info.horseData.sceneId, Flags_GetEventChkInf(EVENTCHKINF_EPONA_OBTAINED),
R_DEBUG_FORCE_EPONA_OBTAINED);
if (Horse_CanSpawn(gSaveContext.save.info.horseData.sceneId)) {
Actor* horseActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, gSaveContext.save.info.horseData.pos.x,
gSaveContext.save.info.horseData.pos.y, gSaveContext.save.info.horseData.pos.z, 0,
gSaveContext.save.info.horseData.angle, 0, HORSE_PTYPE_1);
ASSERT(horseActor != NULL, "horse_actor != NULL", "../z_horse.c", 414);
if (play->sceneId == SCENE_GERUDOS_FORTRESS) {
horseActor->room = -1;
}
} else {
PRINTF_COLOR_ERROR();
PRINTF(
T("Horse_SetNormal():%d セットスポットまずいです。\n", "Horse_SetNormal():%d set spot is no good.\n"),
gSaveContext.save.info.horseData.sceneId);
PRINTF_RST();
Horse_ResetHorseData(play);
}
} else if ((play->sceneId == SCENE_LON_LON_RANCH) &&
!(Flags_GetEventChkInf(EVENTCHKINF_EPONA_OBTAINED) || R_DEBUG_FORCE_EPONA_OBTAINED)) {
// Player spawns in Lon-Lon Ranch without owning Epona
Actor* horseActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, 0.0f, 0.0f, -500.0f, 0, 0, 0, HORSE_PTYPE_1);
ASSERT(horseActor != NULL, "horse_actor != NULL", "../z_horse.c", 443);
} else if (Flags_GetEventChkInf(EVENTCHKINF_EPONA_OBTAINED) || R_DEBUG_FORCE_EPONA_OBTAINED) {
// Player owns Epona, but isn't riding her and the current scene is not the same as the horse's last location.
for (i = 0; i < ARRAY_COUNT(horseSpawns); i++) {
HorseSpawn* horseSpawn = &horseSpawns[i];
if (horseSpawn->sceneId == play->sceneId) {
Actor* horseActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, horseSpawn->pos.x, horseSpawn->pos.y,
horseSpawn->pos.z, 0, horseSpawn->angle, 0, horseSpawn->type);
ASSERT(horseActor != NULL, "horse_actor != NULL", "../z_horse.c", 466);
if (play->sceneId == SCENE_GERUDOS_FORTRESS) {
horseActor->room = -1;
}
break;
}
}
} else if (!(Flags_GetEventChkInf(EVENTCHKINF_EPONA_OBTAINED) || R_DEBUG_FORCE_EPONA_OBTAINED) &&
(play->sceneId == SCENE_LON_LON_BUILDINGS) && !IS_DAY) {
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, 0.0f, 0.0f, -60.0f, 0, 0x7360, 0, HORSE_PTYPE_1);
}
}
typedef struct HorseCutsceneSpawn {
/* 0x00 */ s16 sceneId;
/* 0x04 */ s32 cutsceneIndex;
/* 0x08 */ Vec3s pos;
/* 0x0E */ s16 angle;
/* 0x10 */ s16 type;
} HorseCutsceneSpawn;
void Horse_SetupInCutscene(PlayState* play, Player* player) {
static HorseCutsceneSpawn horseSpawns[] = {
{ SCENE_GERUDOS_FORTRESS, CS_INDEX_0, { 3600, 1413, 360 }, 0x8001, HORSE_PTYPE_HORSEBACK_ARCHERY },
{ SCENE_LON_LON_RANCH, CS_INDEX_0, { -250, 1, -1580 }, 0x4000, HORSE_PTYPE_6 }, // Horse Race
{ SCENE_LON_LON_RANCH, CS_INDEX_1, { 0, 0, 0 }, 0x0000, HORSE_PTYPE_5 }, // Learned Epona's Song
{ SCENE_LON_LON_RANCH, CS_INDEX_5, { 0, 0, 0 }, 0x0000, HORSE_PTYPE_7 }, // Credits
{ SCENE_HYRULE_FIELD, CS_INDEX_3, { -2961, 313, 7700 }, 0x0000, HORSE_PTYPE_7 }, // Title Screen
{ SCENE_HYRULE_FIELD, CS_INDEX_4, { -1900, 313, 7015 }, 0x0000, HORSE_PTYPE_7 },
{ SCENE_HYRULE_FIELD, CS_INDEX_5, { -4043, 313, 6933 }, 0x0000, HORSE_PTYPE_7 }, // Credits
{ SCENE_HYRULE_FIELD, CS_INDEX_6, { -4043, 313, 6933 }, 0x0000, HORSE_PTYPE_7 }, // Unused. Hopping Lon Lon
// Ranch North Gate
};
s32 pad;
s32 i;
if ((gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_11 ||
gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_12 ||
gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_13 ||
gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_15) &&
(gSaveContext.respawnFlag == 0)) {
// Epona hopping over one of the Lon Lon Ranch fences
Vec3s spawnPos;
Vec3s spawnPositions[] = {
// Note: The east and west positions are paired with the wrong entranceIndex. However, the subsequent
// cutscene repositions the horse will override these coordinates while the horse is still obstructed, so no
// visual glitch occurs.
{ -2961, 313, 7700 }, // South
{ -1900, 313, 7015 }, // East
{ -4043, 313, 6933 }, // West
{ -2313, 313, 5990 }, // North-East
};
// South of Lon Lon player spawn
if (gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_11) {
spawnPos = spawnPositions[0];
// West of Lon Lon player spawn
} else if (gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_12) {
spawnPos = spawnPositions[1];
// East of Lon Lon player spawn
} else if (gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_13) {
spawnPos = spawnPositions[2];
// Lon Lon exit player spawn
} else {
spawnPos = spawnPositions[3];
}
player->rideActor = Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, spawnPos.x, spawnPos.y, spawnPos.z, 0,
player->actor.world.rot.y, 0, HORSE_PTYPE_7);
ASSERT(player->rideActor != NULL, "player->ride.actor != NULL", "../z_horse.c", 561);
Actor_MountHorse(play, player, player->rideActor);
Actor_RequestHorseCameraSetting(play, player);
gSaveContext.save.info.horseData.sceneId = play->sceneId;
} else if ((play->sceneId == SCENE_LON_LON_RANCH) &&
(GET_EVENTINF_INGO_RACE_STATE() == INGO_RACE_STATE_TRAPPED_WIN_EPONA) &&
!(Flags_GetEventChkInf(EVENTCHKINF_EPONA_OBTAINED) || R_DEBUG_FORCE_EPONA_OBTAINED)) {
player->rideActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, 894.0f, 0.0f, -2084.0f, 0, -0x7FFF, 0, HORSE_PTYPE_5);
ASSERT(player->rideActor != NULL, "player->ride.actor != NULL", "../z_horse.c", 582);
Actor_MountHorse(play, player, player->rideActor);
Actor_RequestHorseCameraSetting(play, player);
gSaveContext.save.info.horseData.sceneId = play->sceneId;
if (play->sceneId == SCENE_GERUDOS_FORTRESS) {
player->rideActor->room = -1;
}
} else {
for (i = 0; i < ARRAY_COUNT(horseSpawns); i++) {
if ((play->sceneId == horseSpawns[i].sceneId) &&
(((void)0, gSaveContext.save.cutsceneIndex) == horseSpawns[i].cutsceneIndex)) {
if (horseSpawns[i].type == HORSE_PTYPE_7) {
if ((play->sceneId == SCENE_LON_LON_RANCH) &&
(((void)0, gSaveContext.save.cutsceneIndex) == CS_INDEX_1)) {
horseSpawns[i].pos.x = player->actor.world.pos.x;
horseSpawns[i].pos.y = player->actor.world.pos.y;
horseSpawns[i].pos.z = player->actor.world.pos.z;
}
player->rideActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, horseSpawns[i].pos.x, horseSpawns[i].pos.y,
horseSpawns[i].pos.z, 0, player->actor.world.rot.y, 0, horseSpawns[i].type);
ASSERT(player->rideActor != NULL, "player->ride.actor != NULL", "../z_horse.c", 628);
Actor_MountHorse(play, player, player->rideActor);
Actor_RequestHorseCameraSetting(play, player);
} else if ((horseSpawns[i].type == HORSE_PTYPE_5) || (horseSpawns[i].type == HORSE_PTYPE_6) ||
(horseSpawns[i].type == HORSE_PTYPE_HORSEBACK_ARCHERY)) {
Vec3f eye;
s32 paramFlag = 0;
if (GET_EVENTINF_INGO_RACE_HORSETYPE() != HORSE_EPONA && horseSpawns[i].type == HORSE_PTYPE_6) {
// HORSE_HNI
paramFlag = 0x8000;
}
player->rideActor =
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, horseSpawns[i].pos.x, horseSpawns[i].pos.y,
horseSpawns[i].pos.z, 0, horseSpawns[i].angle, 0, horseSpawns[i].type | paramFlag);
ASSERT(player->rideActor != NULL, "player->ride.actor != NULL", "../z_horse.c", 667);
player->actor.world.pos.x = horseSpawns[i].pos.x;
player->actor.world.pos.y = horseSpawns[i].pos.y;
player->actor.world.pos.z = horseSpawns[i].pos.z;
player->actor.shape.rot.x = player->actor.shape.rot.z = 0;
player->actor.shape.rot.y = horseSpawns[i].angle;
Actor_MountHorse(play, player, player->rideActor);
Actor_RequestHorseCameraSetting(play, player);
eye.x = player->actor.world.pos.x - 200.0f;
eye.y = player->actor.world.pos.y + 100.0f;
eye.z = player->actor.world.pos.z;
Play_SetCameraAtEye(play, play->activeCamId, &player->actor.world.pos, &eye);
} else {
Actor_Spawn(&play->actorCtx, play, ACTOR_EN_HORSE, horseSpawns[i].pos.x, horseSpawns[i].pos.y,
horseSpawns[i].pos.z, 0, horseSpawns[i].angle, 0, horseSpawns[i].type);
}
break;
}
}
}
}
/**
* Initializes the player's horse, but only if required.
*
* This function should be called during `Play_Init`.
*/
void Horse_InitPlayerHorse(PlayState* play, Player* player) {
if (LINK_IS_ADULT) {
if (!Horse_CanSpawn(gSaveContext.save.info.horseData.sceneId)) {
PRINTF_COLOR_ERROR();
PRINTF(
T("Horse_Set_Check():%d セットスポットまずいです。\n", "Horse_Set_Check():%d set spot is no good.\n"),
gSaveContext.save.info.horseData.sceneId);
PRINTF_RST();
Horse_ResetHorseData(play);
}
if (Horse_CanSpawn(play->sceneId)) {
if (IS_CUTSCENE_LAYER ||
// has hopped over one of the Lon-Lon Ranch fences
((gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_11 ||
gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_12 ||
gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_13 ||
gSaveContext.save.entranceIndex == ENTR_HYRULE_FIELD_15) &&
(gSaveContext.respawnFlag == 0)) ||
// trapped in Lon Lon Ranch
((play->sceneId == SCENE_LON_LON_RANCH) &&
(GET_EVENTINF_INGO_RACE_STATE() == INGO_RACE_STATE_TRAPPED_WIN_EPONA) &&
!(Flags_GetEventChkInf(EVENTCHKINF_EPONA_OBTAINED) || R_DEBUG_FORCE_EPONA_OBTAINED))) {
Horse_SetupInCutscene(play, player);
} else {
Horse_SetupInGameplay(play, player);
}
}
}
}
void Horse_RotateToPoint(Actor* actor, Vec3f* pos, s16 turnAmount) {
s16 x = Math_Vec3f_Yaw(&actor->world.pos, pos) - actor->world.rot.y;
if (x > turnAmount) {
actor->world.rot.y += turnAmount;
} else if (x < -turnAmount) {
actor->world.rot.y -= turnAmount;
} else {
actor->world.rot.y += x;
}
actor->shape.rot.y = actor->world.rot.y;
}
|