Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document z_horse.c and related actors #2278

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ void CutsceneFlags_UnsetAll(PlayState* play);
void CutsceneFlags_Set(PlayState* play, s16 flag);
void CutsceneFlags_Unset(PlayState* play, s16 flag);
s32 CutsceneFlags_Get(PlayState* play, s16 flag);
s32 func_8006CFC0(s32 sceneId);
void func_8006D074(PlayState* play);
void func_8006D0AC(PlayState* play);
void func_8006D0EC(PlayState* play, Player* player);
void func_8006D684(PlayState* play, Player* player);
void func_8006DC68(PlayState* play, Player* player);
void func_8006DD9C(Actor* actor, Vec3f* arg1, s16 arg2);

s32 Kanji_OffsetFromShiftJIS(s32 character);
void Font_LoadCharWide(Font* font, u16 character, u16 codePointIndex);
Expand Down
2 changes: 2 additions & 0 deletions include/regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
#define R_MESSAGE_DEBUGGER_TEXTID YREG(79)
#define R_C_UP_ICON_X YREG(88)
#define R_C_UP_ICON_Y YREG(89)
#define R_ENTER_RIDING_HORSE AREG(6)
#define R_DEBUG_FORCE_EPONA_OBTAINED DREG(1) //If set, overrides EVENTCHKINF_EPONA_OBTAINED state giving Epona
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space between // and If

#define R_EPONAS_SONG_PLAYED DREG(53)
#define R_MAGIC_FILL_COLOR(i) ZREG(0 + (i))
#define R_PAUSE_PAGE_SWITCH_FRAME_ADVANCE_ON ZREG(13)
Expand Down
4 changes: 2 additions & 2 deletions include/z64actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,10 @@ int func_8002DD78(struct Player* player);
s32 func_8002DDE4(struct PlayState* play);
s32 func_8002DDF4(struct PlayState* play);
void func_8002DE04(struct PlayState* play, Actor* actorA, Actor* actorB);
void func_8002DE74(struct PlayState* play, struct Player* player);
void Actor_SetCameraHorseSetting(struct PlayState* play, struct Player* player);
void Actor_MountHorse(struct PlayState* play, struct Player* player, Actor* horse);
int func_8002DEEC(struct Player* player);
void func_8002DF18(struct PlayState* play, struct Player* player);
void Actor_InitPlayerHorse(struct PlayState* play, struct Player* player);
s32 Player_SetCsAction(struct PlayState* play, Actor* csActor, u8 csAction);
s32 Player_SetCsActionWithHaltedActors(struct PlayState* play, Actor* csActor, u8 csAction);
void func_8002DF90(DynaPolyActor* dynaActor);
Expand Down
16 changes: 16 additions & 0 deletions include/z64horse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef Z64HORSE_H
#define Z64HORSE_H

#include "ultra64.h"
#include "z64math.h"

struct PlayState;
struct Actor;
struct Player;

void Horse_ResetHorseData(struct PlayState* play);
void Horse_FixLakeHyliaPosition(struct PlayState* play);
void Horse_Set(struct PlayState* play, struct Player* player);
void Horse_RotateToPoint(struct Actor* actor, Vec3f* pos, s16 turnAmount);

#endif
93 changes: 46 additions & 47 deletions include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,66 +890,66 @@ typedef enum LinkAge {
* SaveContext.eventInf
*/

// 0x00-0x0F
// horses related
// EVENTINF 0x00-0x0F
// Ingo Race, Lon Lon Ranch minigames, and Horseback Archery minigame flags
#define EVENTINF_HORSES_INDEX 0
#define EVENTINF_HORSES_STATE_SHIFT 0
#define EVENTINF_HORSES_HORSETYPE_SHIFT 4
#define EVENTINF_HORSES_05_SHIFT 5
#define EVENTINF_HORSES_06_SHIFT 6
#define EVENTINF_HORSES_08_SHIFT 8
#define EVENTINF_HORSES_0A_SHIFT 10
#define EVENTINF_HORSES_0F_SHIFT 15 // unused?
#define EVENTINF_HORSES_STATE_MASK (0xF << EVENTINF_HORSES_STATE_SHIFT)
#define EVENTINF_HORSES_HORSETYPE_MASK (1 << EVENTINF_HORSES_HORSETYPE_SHIFT)
#define EVENTINF_HORSES_05_MASK (1 << EVENTINF_HORSES_05_SHIFT)
#define EVENTINF_HORSES_06_MASK (1 << EVENTINF_HORSES_06_SHIFT)
#define EVENTINF_HORSES_0F_MASK (1 << EVENTINF_HORSES_0F_SHIFT)
#define EVENTINF_HORSES_05 ((EVENTINF_HORSES_INDEX << 4) | EVENTINF_HORSES_05_SHIFT)
#define EVENTINF_HORSES_06 ((EVENTINF_HORSES_INDEX << 4) | EVENTINF_HORSES_06_SHIFT)
// EVENTINF 0x00-0x03 reserved for IngoRaceState
#define EVENTINF_INGORACE_STATE_MASK (0xF << 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe INGORACE -> INGO_RACE since I think of it as two words (and could remove STATE if it's getting long)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INGORACE matches the pre-existing spellings INGORACE and MALONRACE used in z_en_horse_game.c, which I mostly left untouched.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inconsistency between IngoRaceState and INGORACE_STATE still bugs me but it's whatever

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change it now with the understanding that horse_game will also change later. INGORACE as one word is just worse.

typedef enum IngoRaceState {
/* 0 */ INGORACE_STATE_OFFER_RENTAL,
/* 1 */ INGORACE_STATE_HORSE_RENTAL_PERIOD,
/* 2 */ INGORACE_STATE_RACING,
/* 3 */ INGORACE_STATE_PLAYER_LOSE,
/* 4 */ INGORACE_STATE_FIRST_WIN,
/* 5 */ INGORACE_STATE_TRAPPED_WIN_UNUSED,
/* 6 */ INGORACE_STATE_TRAPPED_WIN_EPONA, // Ingo Traps you in Lon Lon
/* 7 */ INGORACE_STATE_REMATCH
} IngoRaceState;

#define EVENTINF_INGORACE_HORSETYPE 4
#define EVENTINF_INGORACE_HORSETYPE_MASK (1 << EVENTINF_INGORACE_HORSETYPE)
#define EVENTINF_INGORACE_LOST_ONCE 5
#define EVENTINF_INGORACE_LOST_ONCE_MASK (1 << EVENTINF_INGORACE_LOST_ONCE)
#define EVENTINF_INGORACE_SECOND_RACE 6
#define EVENTINF_INGORACE_SECOND_RACE_MASK (1 << EVENTINF_INGORACE_SECOND_RACE)
// Used in z_en_ta (Talon) to store Cucco game winning status
// and in z_en_ge1 (Gerudo) to store archery in-progress status
#define EVENTINF_HORSES_08 ((EVENTINF_HORSES_INDEX << 4) | EVENTINF_HORSES_08_SHIFT)
#define EVENTINF_HORSES_08 8
#define EVENTINF_CUCCO_GAME_WON EVENTINF_HORSES_08
// Used in z_en_ta (Talon) and z_en_ma3 (Malon) to store minigame finishing status
#define EVENTINF_HORSES_0A ((EVENTINF_HORSES_INDEX << 4) | EVENTINF_HORSES_0A_SHIFT)
#define EVENTINF_HORSES_0A 10
#define EVENTINF_CUCCO_GAME_FINISHED EVENTINF_HORSES_0A

typedef enum EventInfHorsesState {
/* 0 */ EVENTINF_HORSES_STATE_0,
/* 1 */ EVENTINF_HORSES_STATE_1,
/* 2 */ EVENTINF_HORSES_STATE_2,
/* 3 */ EVENTINF_HORSES_STATE_3,
/* 4 */ EVENTINF_HORSES_STATE_4,
/* 5 */ EVENTINF_HORSES_STATE_5,
/* 6 */ EVENTINF_HORSES_STATE_6,
/* 7 */ EVENTINF_HORSES_STATE_7
} EventInfHorsesState;
#define EVENTINF_INGORACE_0F 15 // unused?
#define EVENTINF_INGORACE_0F_MASK (1 << EVENTINF_INGORACE_0F)

// "InRaceSeq"
#define GET_EVENTINF_HORSES_STATE() \
((gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & EVENTINF_HORSES_STATE_MASK) >> EVENTINF_HORSES_STATE_SHIFT)
#define SET_EVENTINF_HORSES_STATE(v) \
gSaveContext.eventInf[EVENTINF_HORSES_INDEX] = \
(gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & ~EVENTINF_HORSES_STATE_MASK) | \
((v) << EVENTINF_HORSES_STATE_SHIFT)

#define GET_EVENTINF_HORSES_HORSETYPE() \
((gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & EVENTINF_HORSES_HORSETYPE_MASK) >> EVENTINF_HORSES_HORSETYPE_SHIFT)
#define SET_EVENTINF_HORSES_HORSETYPE(v) \
gSaveContext.eventInf[EVENTINF_HORSES_INDEX] = \
(gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & ~EVENTINF_HORSES_HORSETYPE_MASK) | \
((v) << EVENTINF_HORSES_HORSETYPE_SHIFT)

#define SET_EVENTINF_HORSES_0F(v) \
#define GET_EVENTINF_INGORACE_STATE() \
(gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & EVENTINF_INGORACE_STATE_MASK)

#define SET_EVENTINF_INGORACE_STATE(v) \
gSaveContext.eventInf[EVENTINF_HORSES_INDEX] = \
(gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & ~EVENTINF_HORSES_0F_MASK) | ((v) << EVENTINF_HORSES_0F_SHIFT)
(gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & ~EVENTINF_INGORACE_STATE_MASK) | (v)

#define GET_EVENTINF_INGORACE_FLAG(flag) \
((gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & (1 << ((flag) & 0xF))) >> ((flag) & 0xF))

#define SET_EVENTINF_INGORACE_FLAG(flag) \
gSaveContext.eventInf[EVENTINF_HORSES_INDEX] = \
(gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & 0xFFFF) | (1 << ((flag) & 0xF))

#define WRITE_EVENTINF_INGORACE_FLAG(flag, v) \
gSaveContext.eventInf[EVENTINF_HORSES_INDEX] = \
(gSaveContext.eventInf[EVENTINF_HORSES_INDEX] & ~(1 << ((flag) & 0xF))) | ((v) << ((flag) & 0xF))

#define GET_EVENTINF_INGORACE_HORSETYPE() GET_EVENTINF_INGORACE_FLAG(EVENTINF_INGORACE_HORSETYPE)
#define WRITE_EVENTINF_INGORACE_HORSETYPE(v) WRITE_EVENTINF_INGORACE_FLAG(EVENTINF_INGORACE_HORSETYPE, v)

#define WRITE_EVENTINF_INGORACE_0F(v) WRITE_EVENTINF_INGORACE_FLAG(EVENTINF_INGORACE_0F, v)

// Is the running man race active
#define EVENTINF_MARATHON_ACTIVE 0x10

// 0x20-0x24
// EVENTINF 0x20-0x24
#define EVENTINF_20_21_22_23_24_INDEX 2
#define EVENTINF_20_MASK (1 << 0)
#define EVENTINF_21_MASK (1 << 1)
Expand All @@ -959,7 +959,6 @@ typedef enum EventInfHorsesState {

#define EVENTINF_30 0x30


#define GET_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] & (1 << ((flag) & 0xF)))
#define SET_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] |= (1 << ((flag) & 0xF)))
#define CLEAR_EVENTINF(flag) (gSaveContext.eventInf[(flag) >> 4] &= ~(1 << ((flag) & 0xF)))
Expand Down
7 changes: 4 additions & 3 deletions src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "rand.h"
#include "terminal.h"
#include "versions.h"
#include "z64horse.h"

#include "overlays/actors/ovl_Arms_Hook/z_arms_hook.h"
#include "overlays/actors/ovl_En_Part/z_en_part.h"
Expand Down Expand Up @@ -1130,7 +1131,7 @@ void func_8002DE04(PlayState* play, Actor* actorA, Actor* actorB) {
actorA->flags &= ~ACTOR_FLAG_13;
}

void func_8002DE74(PlayState* play, Player* player) {
void Actor_SetCameraHorseSetting(PlayState* play, Player* player) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the wording of this function name awkward ("set" appears twice, and what's a "camera horse"?). Some suggestions:

Actor_SetHorseCamera
Actor_RequestHorseCamera
Actor_RequestHorseCameraSetting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Player_SetCameraHorseSetting is the MM name for the function, but the MM Camera system names seem out of date.

Actor_RequestHorseCameraSetting might be best, but I'm not confident on word ordering.

if ((play->roomCtx.curRoom.type != ROOM_TYPE_4) && Play_CamIsNotFixed(play)) {
Camera_RequestSetting(Play_GetCamera(play, CAM_ID_MAIN), CAM_SET_HORSE);
}
Expand All @@ -1147,8 +1148,8 @@ int func_8002DEEC(Player* player) {
(player->csAction != PLAYER_CSACTION_NONE);
}

void func_8002DF18(PlayState* play, Player* player) {
func_8006DC68(play, player);
void Actor_InitPlayerHorse(PlayState* play, Player* player) {
Horse_Set(play, player);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/code/z_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -3639,7 +3639,7 @@ s32 Camera_KeepOn3(Camera* camera) {
}

#pragma increment_block_number "gc-eu:128 gc-eu-mq:128 gc-jp:128 gc-jp-ce:128 gc-jp-mq:128 gc-us:128 gc-us-mq:128" \
"ntsc-1.2:93 pal-1.0:91 pal-1.1:91"
"ntsc-1.2:90 pal-1.0:88 pal-1.1:88"

s32 Camera_KeepOn4(Camera* camera) {
static Vec3f D_8015BD50;
Expand Down
Loading