Skip to content

Commit

Permalink
Add Sideways Stairs (#4836)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassoonian authored Sep 29, 2024
2 parents 42c43a3 + c8afe9b commit 5a8a393
Show file tree
Hide file tree
Showing 14 changed files with 1,002 additions and 337 deletions.
1 change: 1 addition & 0 deletions include/config/overworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Movement config
#define OW_RUNNING_INDOORS GEN_LATEST // In Gen4+, players are allowed to run indoors.
#define OW_AUTO_SIGNPOST FALSE // When enabled, if the tile that the player is facing has MB_SIGNPOST, MB_POKEMART_SIGN, or MB_POKEMON_CENTER_SIGN, the player will automatically read the signpost, as seen in FRLG.
#define SLOW_MOVEMENT_ON_STAIRS FALSE // If enabled, the player will move slower up/down stairs like in FR

// Other settings
#define OW_POISON_DAMAGE GEN_LATEST // In Gen4, Pokémon no longer faint from Poison in the overworld. In Gen5+, they no longer take damage at all.
Expand Down
4 changes: 4 additions & 0 deletions include/constants/event_object_movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@
#define MOVEMENT_ACTION_EMOTE_DOUBLE_EXCL_MARK 0x9F
#define MOVEMENT_ACTION_EXIT_POKEBALL 0xA0
#define MOVEMENT_ACTION_ENTER_POKEBALL 0xA1
#define MOVEMENT_ACTION_RUN_DOWN_SLOW 0xA2 // slow running for rocky stairs
#define MOVEMENT_ACTION_RUN_UP_SLOW 0xA3
#define MOVEMENT_ACTION_RUN_LEFT_SLOW 0xA4
#define MOVEMENT_ACTION_RUN_RIGHT_SLOW 0xA5

#define MOVEMENT_ACTION_STEP_END 0xFE
#define MOVEMENT_ACTION_NONE 0xFF
Expand Down
14 changes: 7 additions & 7 deletions include/constants/metatile_behaviors.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@
#define MB_SLIDE_NORTH 0x46
#define MB_SLIDE_SOUTH 0x47
#define MB_TRICK_HOUSE_PUZZLE_8_FLOOR 0x48
#define MB_UNUSED_49 0x49
#define MB_UNUSED_4A 0x4A
#define MB_UNUSED_4B 0x4B
#define MB_UNUSED_4C 0x4C
#define MB_UNUSED_4D 0x4D
#define MB_UNUSED_4E 0x4E
#define MB_UNUSED_4F 0x4F
#define MB_SIDEWAYS_STAIRS_RIGHT_SIDE 0x49
#define MB_SIDEWAYS_STAIRS_LEFT_SIDE 0x4A
#define MB_SIDEWAYS_STAIRS_RIGHT_SIDE_TOP 0x4B
#define MB_SIDEWAYS_STAIRS_LEFT_SIDE_TOP 0x4C
#define MB_SIDEWAYS_STAIRS_RIGHT_SIDE_BOTTOM 0x4D
#define MB_SIDEWAYS_STAIRS_LEFT_SIDE_BOTTOM 0x4E
#define MB_ROCK_STAIRS 0x4F
#define MB_EASTWARD_CURRENT 0x50
#define MB_WESTWARD_CURRENT 0x51
#define MB_NORTHWARD_CURRENT 0x52
Expand Down
9 changes: 9 additions & 0 deletions include/event_object_movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ void SetVirtualObjectInvisibility(u8 virtualObjId, bool32 invisible);
bool32 IsVirtualObjectInvisible(u8 virtualObjId);
void SetVirtualObjectSpriteAnim(u8 virtualObjId, u8 animNum);
bool32 IsVirtualObjectAnimating(u8 virtualObjId);
u8 GetObjectEventIdByLocalId(u8 localId);
bool32 IsFollowerVisible(void);

// run slow
u8 GetPlayerRunSlowMovementAction(u32);
//sideways stairs
u8 GetSidewaysStairsToRightDirection(s16, s16, u8);
u8 GetSidewaysStairsToLeftDirection(s16, s16, u8);
u8 GetSidewaysStairsCollision(struct ObjectEvent *objectEvent, u8 dir, u8 currentBehavior, u8 nextBehavior, u8 collision);

bool8 MovementAction_EmoteX_Step0(struct ObjectEvent *, struct Sprite *);
bool8 MovementAction_EmoteDoubleExclamationMark_Step0(struct ObjectEvent *, struct Sprite *);
Expand Down
4 changes: 4 additions & 0 deletions include/field_player_avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,9 @@ bool32 IsPlayerSpinExitActive(void);
void SetPlayerInvisibility(bool8 invisible);
u8 player_get_pos_including_state_based_drift(s16 *x, s16 *y);
void StartFishing(u8 rod);
bool8 ObjectMovingOnRockStairs(struct ObjectEvent *objectEvent, u8 direction);
//sideways stairs
u8 GetRightSideStairsDirection(u8 direction);
u8 GetLeftSideStairsDirection(u8 direction);

#endif // GUARD_FIELD_PLAYER_AVATAR_H
5 changes: 4 additions & 1 deletion include/global.fieldmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ struct ObjectEvent
/*0x1D*/ u8 trainerRange_berryTreeId;
/*0x1E*/ u8 currentMetatileBehavior;
/*0x1F*/ u8 previousMetatileBehavior;
/*0x20*/ u8 previousMovementDirection;
/*0x20*/ u8 previousMovementDirection:4;
u8 directionOverwrite:4;
/*0x21*/ u8 directionSequenceIndex;
/*0x22*/ u8 playerCopyableMovement; // COPY_MOVE_*
/*0x23*/ u8 spriteId;
Expand Down Expand Up @@ -298,6 +299,8 @@ enum
COLLISION_VERTICAL_RAIL,
COLLISION_HORIZONTAL_RAIL,
COLLISION_STAIR_WARP,
COLLISION_SIDEWAYS_STAIRS_TO_RIGHT,
COLLISION_SIDEWAYS_STAIRS_TO_LEFT
};

// player running states
Expand Down
9 changes: 9 additions & 0 deletions include/metatile_behavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,14 @@ bool8 MetatileBehavior_IsDirectionalStairWarp(u8 metatileBehavior);
bool8 MetatileBehavior_IsSignpost(u32);
bool8 MetatileBehavior_IsPokemonCenterSign(u32);
bool8 MetatileBehavior_IsPokeMartSign(u32);
bool8 MetatileBehavior_IsRockStairs(u8);
bool8 MetatileBehavior_IsSidewaysStairsRightSide(u8);
bool8 MetatileBehavior_IsSidewaysStairsLeftSide(u8);
bool8 MetatileBehavior_IsSidewaysStairsRightSideTop(u8 metatileBehavior);
bool8 MetatileBehavior_IsSidewaysStairsLeftSideTop(u8 metatileBehavior);
bool8 MetatileBehavior_IsSidewaysStairsRightSideBottom(u8 metatileBehavior);
bool8 MetatileBehavior_IsSidewaysStairsLeftSideBottom(u8 metatileBehavior);
bool8 MetatileBehavior_IsSidewaysStairsRightSideAny(u8 metatileBehavior);
bool8 MetatileBehavior_IsSidewaysStairsLeftSideAny(u8 metatileBehavior);

#endif // GUARD_METATILE_BEHAVIOR_H
25 changes: 24 additions & 1 deletion src/bike.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ static u8 GetMachBikeTransition(u8 *dirTraveling)
{
// if the dir updated before this function, get the relevent new direction to check later.
u8 direction = GetPlayerMovementDirection();

// fix direction when moving on sideways stairs
switch (direction)
{
case DIR_SOUTHWEST:
case DIR_NORTHWEST:
direction = DIR_WEST;
break;
case DIR_SOUTHEAST:
case DIR_NORTHEAST:
direction = DIR_EAST;
break;
}

// is the player standing still?
if (*dirTraveling == 0)
Expand Down Expand Up @@ -234,6 +247,9 @@ static void MachBikeTransition_TrySpeedUp(u8 direction)
else
{
// we did not hit anything that can slow us down, so perform the advancement callback depending on the bikeFrameCounter and try to increase the mach bike's speed.
if (ObjectMovingOnRockStairs(playerObjEvent, direction) && gPlayerAvatar.bikeFrameCounter > 1)
gPlayerAvatar.bikeFrameCounter--;

sMachBikeSpeedCallbacks[gPlayerAvatar.bikeFrameCounter](direction);
gPlayerAvatar.bikeSpeed = gPlayerAvatar.bikeFrameCounter + (gPlayerAvatar.bikeFrameCounter >> 1); // same as dividing by 2, but compiler is insistent on >> 1
if (gPlayerAvatar.bikeFrameCounter < 2) // do not go faster than the last element in the mach bike array
Expand Down Expand Up @@ -368,6 +384,7 @@ static u8 AcroBikeHandleInputWheelieStanding(u8 *newDirection, u16 newKeys, u16
struct ObjectEvent *playerObjEvent;

direction = GetPlayerMovementDirection();

playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId];
gPlayerAvatar.runningState = NOT_MOVING;

Expand Down Expand Up @@ -563,7 +580,10 @@ static void AcroBikeTransition_Moving(u8 direction)
}
else
{
PlayerRideWaterCurrent(direction);
if (ObjectMovingOnRockStairs(playerObjEvent, direction))
PlayerWalkFast(direction);
else
PlayerRideWaterCurrent(direction);
}
}

Expand Down Expand Up @@ -696,6 +716,7 @@ static void AcroBikeTransition_WheelieMoving(u8 direction)
}
return;
}

PlayerWheelieMove(direction);
gPlayerAvatar.runningState = MOVING;
}
Expand Down Expand Up @@ -730,6 +751,7 @@ static void AcroBikeTransition_WheelieRisingMoving(u8 direction)
}
return;
}

PlayerPopWheelieWhileMoving(direction);
gPlayerAvatar.runningState = MOVING;
}
Expand All @@ -753,6 +775,7 @@ static void AcroBikeTransition_WheelieLoweringMoving(u8 direction)
PlayerEndWheelie(direction);
return;
}

PlayerEndWheelieWhileMoving(direction);
}

Expand Down
37 changes: 37 additions & 0 deletions src/data/object_events/movement_action_func_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ u8 MovementAction_FlyUp_Step1(struct ObjectEvent *, struct Sprite *);
u8 MovementAction_Fly_Finish(struct ObjectEvent *, struct Sprite *);
u8 MovementAction_FlyDown_Step0(struct ObjectEvent *, struct Sprite *);
u8 MovementAction_FlyDown_Step1(struct ObjectEvent *, struct Sprite *);
u8 MovementActionFunc_RunSlowDown_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite);
u8 MovementActionFunc_RunSlowUp_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite);
u8 MovementActionFunc_RunSlowLeft_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite);
u8 MovementActionFunc_RunSlowRight_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite);
u8 MovementActionFunc_RunSlow_Step1(struct ObjectEvent *objectEvent, struct Sprite *sprite);

u8 (*const gMovementActionFuncs_FaceDown[])(struct ObjectEvent *, struct Sprite *);
u8 (*const gMovementActionFuncs_FaceUp[])(struct ObjectEvent *, struct Sprite *);
Expand Down Expand Up @@ -429,6 +434,10 @@ u8 (*const gMovementActionFuncs_FlyUp[])(struct ObjectEvent *, struct Sprite *);
u8 (*const gMovementActionFuncs_FlyDown[])(struct ObjectEvent *, struct Sprite *);
u8 (*const gMovementActionFuncs_EmoteX[])(struct ObjectEvent *, struct Sprite *);
u8 (*const gMovementActionFuncs_EmoteDoubleExclMark[])(struct ObjectEvent *, struct Sprite *);
u8 (*const gMovementActionFuncs_RunDownSlow[])(struct ObjectEvent *, struct Sprite *);
u8 (*const gMovementActionFuncs_RunUpSlow[])(struct ObjectEvent *, struct Sprite *);
u8 (*const gMovementActionFuncs_RunLeftSlow[])(struct ObjectEvent *, struct Sprite *);
u8 (*const gMovementActionFuncs_RunRightSlow[])(struct ObjectEvent *, struct Sprite *);

u8 (*const *const gMovementActionFuncs[])(struct ObjectEvent *, struct Sprite *) = {
[MOVEMENT_ACTION_FACE_DOWN] = gMovementActionFuncs_FaceDown,
Expand Down Expand Up @@ -593,6 +602,10 @@ u8 (*const *const gMovementActionFuncs[])(struct ObjectEvent *, struct Sprite *)
[MOVEMENT_ACTION_EMOTE_DOUBLE_EXCL_MARK] = gMovementActionFuncs_EmoteDoubleExclMark,
[MOVEMENT_ACTION_EXIT_POKEBALL] = gMovementActionFuncs_ExitPokeball,
[MOVEMENT_ACTION_ENTER_POKEBALL] = gMovementActionFuncs_EnterPokeball,
[MOVEMENT_ACTION_RUN_DOWN_SLOW] = gMovementActionFuncs_RunDownSlow,
[MOVEMENT_ACTION_RUN_UP_SLOW] = gMovementActionFuncs_RunUpSlow,
[MOVEMENT_ACTION_RUN_LEFT_SLOW] = gMovementActionFuncs_RunLeftSlow,
[MOVEMENT_ACTION_RUN_RIGHT_SLOW] = gMovementActionFuncs_RunRightSlow,
};

u8 (*const gMovementActionFuncs_FaceDown[])(struct ObjectEvent *, struct Sprite *) = {
Expand Down Expand Up @@ -1554,3 +1567,27 @@ u8 (*const gMovementActionFuncs_EmoteDoubleExclMark[])(struct ObjectEvent *, str
MovementAction_EmoteDoubleExclamationMark_Step0,
MovementAction_Finish,
};

u8 (*const gMovementActionFuncs_RunDownSlow[])(struct ObjectEvent *, struct Sprite *) = {
MovementActionFunc_RunSlowDown_Step0,
MovementActionFunc_RunSlow_Step1,
MovementAction_PauseSpriteAnim,
};

u8 (*const gMovementActionFuncs_RunUpSlow[])(struct ObjectEvent *, struct Sprite *) = {
MovementActionFunc_RunSlowUp_Step0,
MovementActionFunc_RunSlow_Step1,
MovementAction_PauseSpriteAnim,
};

u8 (*const gMovementActionFuncs_RunLeftSlow[])(struct ObjectEvent *, struct Sprite *) = {
MovementActionFunc_RunSlowLeft_Step0,
MovementActionFunc_RunSlow_Step1,
MovementAction_PauseSpriteAnim,
};

u8 (*const gMovementActionFuncs_RunRightSlow[])(struct ObjectEvent *, struct Sprite *) = {
MovementActionFunc_RunSlowRight_Step0,
MovementActionFunc_RunSlow_Step1,
MovementAction_PauseSpriteAnim,
};
Loading

0 comments on commit 5a8a393

Please sign in to comment.