Skip to content

Commit

Permalink
Add OW_AUTO_SIGNPOST and associated metatile behaviors (#5044)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassoonian authored Sep 21, 2024
2 parents 4cd23a3 + f0bd3c5 commit 8ba96fd
Show file tree
Hide file tree
Showing 24 changed files with 337 additions and 11 deletions.
5 changes: 5 additions & 0 deletions data/event_scripts.s
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,11 @@ EventScript_BackupMrBrineyLocation::
.include "data/scripts/rival_graphics.inc"
.include "data/scripts/set_gym_trainers.inc"

EventScript_CancelMessageBox::
special UseBlankMessageToCancelPokemonPic
release
end

Common_EventScript_ShowBagIsFull::
msgbox gText_TooBadBagIsFull, MSGBOX_DEFAULT
release
Expand Down
1 change: 1 addition & 0 deletions data/specials.inc
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,4 @@ gSpecials::
def_special Script_GetChosenMonDefensiveEVs
def_special Script_GetChosenMonOffensiveIVs
def_special Script_GetChosenMonDefensiveIVs
def_special UseBlankMessageToCancelPokemonPic
Binary file added graphics/text_window/signpost.bin
Binary file not shown.
Binary file added graphics/text_window/signpost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions include/config/overworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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.

// 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
6 changes: 3 additions & 3 deletions include/constants/metatile_behaviors.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#define MB_UNUSED_SOOTOPOLIS_DEEP_WATER_2 0x1A
#define MB_STAIRS_OUTSIDE_ABANDONED_SHIP 0x1B
#define MB_SHOAL_CAVE_ENTRANCE 0x1C
#define MB_UNUSED_1D 0x1D
#define MB_UNUSED_1E 0x1E
#define MB_UNUSED_1F 0x1F
#define MB_SIGNPOST 0x1D
#define MB_POKEMON_CENTER_SIGN 0x1E
#define MB_POKEMART_SIGN 0x1F
#define MB_ICE 0x20
#define MB_SAND 0x21
#define MB_SEAWEED 0x22
Expand Down
4 changes: 4 additions & 0 deletions include/event_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,8 @@ extern const u8 EventScript_VsSeekerChargingDone[];
extern const u8 Common_Movement_FollowerSafeStart[];
extern const u8 Common_Movement_FollowerSafeEnd[];

extern const u8 EventScript_CancelMessageBox[];
extern const u8 Common_EventScript_ShowPokemonCenterSign[];
extern const u8 Common_EventScript_ShowPokemartSign[];

#endif // GUARD_EVENT_SCRIPTS_H
4 changes: 4 additions & 0 deletions include/field_control_avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ u8 TrySetDiveWarp(void);
const u8 *GetInteractedLinkPlayerScript(struct MapPosition *position, u8 metatileBehavior, u8 direction);
const u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position);
void ClearPoisonStepCounter(void);
void CancelSignPostMessageBox(struct FieldInput *input);

#define NOT_SIGNPOST 0
#define WALK_AWAY_SIGNPOST_FRAMES 6

#endif // GUARD_FIELDCONTROLAVATAR_H
2 changes: 2 additions & 0 deletions include/field_message_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ u8 GetFieldMessageBoxMode(void);
void StopFieldMessage(void);
void InitFieldMessageBox(void);

extern u8 gWalkAwayFromSignpostTimer;

#endif // GUARD_FIELD_MESSAGE_BOX_H
1 change: 1 addition & 0 deletions include/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define GUARD_GRAPHICS_H

// overworld
extern const u32 gSignpostWindow_Gfx[];
extern const u32 gMessageBox_Gfx[];
extern const u16 gMessageBox_Pal[];

Expand Down
6 changes: 6 additions & 0 deletions include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include "text.h"
#include "window.h"

#define DLG_WINDOW_PALETTE_NUM 15
#define DLG_WINDOW_BASE_TILE_NUM 0x200
#define STD_WINDOW_PALETTE_NUM 14
#define STD_WINDOW_PALETTE_SIZE PLTT_SIZEOF(10)
#define STD_WINDOW_BASE_TILE_NUM 0x214

#define MENU_NOTHING_CHOSEN -2
#define MENU_B_PRESSED -1

Expand Down
3 changes: 3 additions & 0 deletions include/metatile_behavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,8 @@ bool8 MetatileBehavior_IsQuestionnaire(u8);
bool8 MetatileBehavior_IsLongGrass_Duplicate(u8);
bool8 MetatileBehavior_IsLongGrassSouthEdge(u8);
bool8 MetatileBehavior_IsTrainerHillTimer(u8);
bool32 MetatileBehavior_IsSignpost(u32);
bool32 MetatileBehavior_IsPokemonCenterSign(u32);
bool32 MetatileBehavior_IsPokeMartSign(u32);

#endif // GUARD_METATILE_BEHAVIOR_H
3 changes: 3 additions & 0 deletions include/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ void InitRamScript_NoObjectEvent(u8 *script, u16 scriptSize);
// srccmd.h
void SetMovingNpcId(u16 npcId);

extern u8 gMsgIsSignPost;
extern u8 gMsgBoxIsCancelable;

#endif // GUARD_SCRIPT_H
2 changes: 2 additions & 0 deletions include/text_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern const u16 gTextWindowFrame1_Pal[];

const struct TilesPal *GetWindowFrameTilesPal(u8 id);
void LoadMessageBoxGfx(u8 windowId, u16 destOffset, u8 palOffset);
void LoadSignBoxGfx(u8 windowId, u16 destOffset, u8 palOffset);
void LoadWindowGfx(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset);
void LoadUserWindowBorderGfx(u8 windowId, u16 destOffset, u8 palOffset);
void LoadUserWindowBorderGfx_(u8 windowId, u16 destOffset, u8 palOffset);
Expand All @@ -23,5 +24,6 @@ void DrawTextBorderInner(u8 windowId, u16 tileNum, u8 palNum);
void rbox_fill_rectangle(u8 windowId);
const u16 *GetTextWindowPalette(u8 id);
const u16 *GetOverworldTextboxPalettePtr(void);
void LoadSignPostWindowFrameGfx(void);

#endif // GUARD_TEXT_WINDOW_H
136 changes: 136 additions & 0 deletions src/field_control_avatar.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "event_scripts.h"
#include "fieldmap.h"
#include "field_control_avatar.h"
#include "field_message_box.h"
#include "field_player_avatar.h"
#include "field_poison.h"
#include "field_screen_effect.h"
Expand All @@ -34,6 +35,7 @@
#include "constants/event_objects.h"
#include "constants/field_poison.h"
#include "constants/map_types.h"
#include "constants/metatile_behaviors.h"
#include "constants/songs.h"
#include "constants/trainer_hill.h"

Expand Down Expand Up @@ -73,6 +75,11 @@ static void UpdateFollowerStepCounter(void);
#if OW_POISON_DAMAGE < GEN_5
static bool8 UpdatePoisonStepCounter(void);
#endif // OW_POISON_DAMAGE
static bool32 TrySetUpWalkIntoSignpostScript(struct MapPosition * position, u32 metatileBehavior, u32 playerDirection);
static void SetMsgSignPostAndVarFacing(u32 playerDirection);
static void SetUpWalkIntoSignScript(const u8 *script, u32 playerDirection);
static u32 GetFacingSignpostType(u16 metatileBehvaior, u32 direction);
static const u8 *GetSignpostScriptAtMapPosition(struct MapPosition * position);

void FieldClearPlayerInput(struct FieldInput *input)
{
Expand Down Expand Up @@ -154,6 +161,7 @@ int ProcessPlayerFieldInput(struct FieldInput *input)
gSpecialVar_LastTalked = 0;
gSelectedObjectEvent = 0;

gMsgIsSignPost = FALSE;
playerDirection = GetPlayerFacingDirection();
GetPlayerPosition(&position);
metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y);
Expand All @@ -173,6 +181,17 @@ int ProcessPlayerFieldInput(struct FieldInput *input)
if (TryStartStepBasedScript(&position, metatileBehavior, playerDirection) == TRUE)
return TRUE;
}

if ((input->checkStandardWildEncounter) && ((input->dpadDirection == 0) || input->dpadDirection == playerDirection))
{
GetInFrontOfPlayerPosition(&position);
metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y);
if (TrySetUpWalkIntoSignpostScript(&position, metatileBehavior, playerDirection) == TRUE)
return TRUE;
GetPlayerPosition(&position);
metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y);
}

if (input->checkStandardWildEncounter && CheckStandardWildEncounter(metatileBehavior) == TRUE)
return TRUE;
if (input->heldDirection && input->dpadDirection == playerDirection)
Expand All @@ -183,6 +202,10 @@ int ProcessPlayerFieldInput(struct FieldInput *input)

GetInFrontOfPlayerPosition(&position);
metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y);

if (input->heldDirection && (input->dpadDirection == playerDirection) && (TrySetUpWalkIntoSignpostScript(&position, metatileBehavior, playerDirection) == TRUE))
return TRUE;

if (input->pressedAButton && TryStartInteractionScript(&position, metatileBehavior, playerDirection) == TRUE)
return TRUE;

Expand Down Expand Up @@ -344,6 +367,9 @@ static const u8 *GetInteractedBackgroundEventScript(struct MapPosition *position
if (bgEvent->bgUnion.script == NULL)
return EventScript_TestSignpostMsg;

if (GetFacingSignpostType(metatileBehavior, direction) != NOT_SIGNPOST)
SetMsgSignPostAndVarFacing(direction);

switch (bgEvent->kind)
{
case BG_EVENT_PLAYER_FACING_ANY:
Expand Down Expand Up @@ -1053,3 +1079,113 @@ int SetCableClubWarp(void)
SetupWarp(&gMapHeader, GetWarpEventAtMapPosition(&gMapHeader, &position), &position);
return 0;
}

static bool32 TrySetUpWalkIntoSignpostScript(struct MapPosition *position, u32 metatileBehavior, u32 playerDirection)
{
const u8 *script;

if ((JOY_HELD(DPAD_LEFT | DPAD_RIGHT)) || (playerDirection != DIR_NORTH))
return FALSE;

switch (GetFacingSignpostType(metatileBehavior, playerDirection))
{
case MB_POKEMON_CENTER_SIGN:
SetUpWalkIntoSignScript(Common_EventScript_ShowPokemonCenterSign, playerDirection);
return TRUE;
case MB_POKEMART_SIGN:
SetUpWalkIntoSignScript(Common_EventScript_ShowPokemartSign, playerDirection);
return TRUE;
case MB_SIGNPOST:
script = GetSignpostScriptAtMapPosition(position);
if (script == NULL)
return FALSE;
SetUpWalkIntoSignScript(script, playerDirection);
return TRUE;
default:
return FALSE;
}
}

static u32 GetFacingSignpostType(u16 metatileBehavior, u32 playerDirection)
{
if (MetatileBehavior_IsPokemonCenterSign(metatileBehavior) == TRUE)
return MB_POKEMON_CENTER_SIGN;
if (MetatileBehavior_IsPokeMartSign(metatileBehavior) == TRUE)
return MB_POKEMART_SIGN;
if (MetatileBehavior_IsSignpost(metatileBehavior) == TRUE)
return MB_SIGNPOST;

return NOT_SIGNPOST;
}

static void SetMsgSignPostAndVarFacing(u32 playerDirection)
{
gWalkAwayFromSignpostTimer = WALK_AWAY_SIGNPOST_FRAMES;
gMsgBoxIsCancelable = TRUE;
gMsgIsSignPost = TRUE;
gSpecialVar_Facing = playerDirection;
}

static void SetUpWalkIntoSignScript(const u8 *script, u32 playerDirection)
{
ScriptContext_SetupScript(script);
SetMsgSignPostAndVarFacing(playerDirection);
}

static const u8 *GetSignpostScriptAtMapPosition(struct MapPosition *position)
{
const struct BgEvent *event = GetBackgroundEventAtPosition(&gMapHeader, position->x - 7, position->y - 7, position->elevation);
if (event == NULL)
return NULL;
if (event->bgUnion.script != NULL)
return event->bgUnion.script;
return EventScript_TestSignpostMsg;
}

static void Task_OpenStartMenu(u8 taskId)
{
if (ArePlayerFieldControlsLocked())
return;

PlaySE(SE_WIN_OPEN);
ShowStartMenu();
DestroyTask(taskId);
}

bool32 IsDpadPushedToTurnOrMovePlayer(struct FieldInput *input)
{
return (input->dpadDirection != 0 && GetPlayerFacingDirection() != input->dpadDirection);
}

void CancelSignPostMessageBox(struct FieldInput *input)
{
if (!ScriptContext_IsEnabled())
return;

if (gWalkAwayFromSignpostTimer)
{
gWalkAwayFromSignpostTimer--;
return;
}

if (!gMsgBoxIsCancelable)
return;

if (IsDpadPushedToTurnOrMovePlayer(input))
{
ScriptContext_SetupScript(EventScript_CancelMessageBox);
LockPlayerFieldControls();
return;
}

if (!input->pressedStartButton)
return;

ScriptContext_SetupScript(EventScript_CancelMessageBox);
LockPlayerFieldControls();

if (FuncIsActiveTask(Task_OpenStartMenu))
return;

CreateTask(Task_OpenStartMenu, 8);
}
10 changes: 9 additions & 1 deletion src/field_message_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
#include "text.h"
#include "match_call.h"
#include "field_message_box.h"
#include "text_window.h"
#include "script.h"

static EWRAM_DATA u8 sFieldMessageBoxMode = 0;
EWRAM_DATA u8 gWalkAwayFromSignpostTimer = 0;

static void ExpandStringAndStartDrawFieldMessage(const u8 *, bool32);
static void StartDrawFieldMessage(void);
Expand All @@ -29,7 +32,12 @@ static void Task_DrawFieldMessage(u8 taskId)
switch (task->tState)
{
case 0:
LoadMessageBoxAndBorderGfx();
if (gMsgIsSignPost)
LoadSignPostWindowFrameGfx();
else
LoadMessageBoxAndBorderGfx();
task->tState++;
break;
task->tState++;
break;
case 1:
Expand Down
7 changes: 7 additions & 0 deletions src/field_specials.c
Original file line number Diff line number Diff line change
Expand Up @@ -4276,3 +4276,10 @@ void PreparePartyForSkyBattle(void)
VarSet(B_VAR_SKY_BATTLE,participatingPokemonSlot);
CompactPartySlots();
}

void UseBlankMessageToCancelPokemonPic(void)
{
u8 t = EOS;
AddTextPrinterParameterized(0, FONT_NORMAL, &t, 0, 1, 0, NULL);
ScriptMenu_HidePokemonPic();
}
1 change: 1 addition & 0 deletions src/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,7 @@ const u16 gTradeMenuMonBox_Tilemap[] = INCBIN_U16("graphics/trade/menu_mon_box.b

const u16 gMessageBox_Pal[] = INCBIN_U16("graphics/text_window/message_box.gbapal");
const u8 gMessageBox_Gfx[] = INCBIN_U8("graphics/text_window/message_box.4bpp");
const u8 gSignpostWindow_Gfx[] = INCBIN_U8("graphics/text_window/signpost.4bpp");

const u32 gWallpaperIcon_Cross[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/icons/cross.4bpp.lz");
const u32 gWallpaperIcon_Bolt[] = INCBIN_U32("graphics/pokemon_storage/wallpapers/icons/bolt.4bpp.lz");
Expand Down
Loading

0 comments on commit 8ba96fd

Please sign in to comment.