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

Add OW_AUTO_SIGNPOST and associated metatile behaviors #5044

Merged
merged 47 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
dfce7f1
add auto read signposts
Apr 1, 2021
7bb8115
add start menu funcs, credit deokishisu
Mar 3, 2023
5657f83
merge w pret
May 11, 2023
28183ec
first merge of ghoul's branch
pkmnsnfrn Jul 16, 2024
b43e0e0
Add config to disable OW_AUTO_SIGNPOST
pkmnsnfrn Jul 16, 2024
8445d44
Renamed DoPicboxCancel to UseBlankMessageToCancelPokemonPic
pkmnsnfrn Jul 16, 2024
b54cf22
Renamed and refactored FieldInput_HandleCancelSignpost into CancelSig…
pkmnsnfrn Jul 16, 2024
1ae6156
Renamed gWalkAwayFromSignInhibitTimer to gWalkAwayFromSignpostTimer
pkmnsnfrn Jul 16, 2024
61eff23
Moved menu defines to header file
pkmnsnfrn Jul 16, 2024
a0c5e55
Added gSignPostWindow_Gfx
pkmnsnfrn Jul 25, 2024
389f4e4
Worked with ShinyDragonHunter to get signpost working
pkmnsnfrn Jul 25, 2024
614b7f8
Working version of interactable signpost msgbox
pkmnsnfrn Jul 25, 2024
fd69ef3
Got pokemart and pokecenter changes working
pkmnsnfrn Jul 26, 2024
b5c58e5
Removed all comments
pkmnsnfrn Jul 26, 2024
c6f89d1
Removed swap file
pkmnsnfrn Jul 26, 2024
2a5f384
Added metatile behaviors to mart and center signs
pkmnsnfrn Jul 26, 2024
bf11e0c
Revert metatile behavior
pkmnsnfrn Jul 26, 2024
7717812
Clean up files
pkmnsnfrn Jul 26, 2024
02cdbb3
Cleaned up field_control_avatar
pkmnsnfrn Jul 26, 2024
f362f6e
Cleaned up metatile behavior
pkmnsnfrn Jul 26, 2024
59c2eea
Default signpost config is off
pkmnsnfrn Jul 27, 2024
587ffee
Fixed tabs
pkmnsnfrn Jul 27, 2024
31fc497
Removed preproc from src/metatile_behavior.c per https://github.com/r…
pkmnsnfrn Jul 27, 2024
1ad3ba1
Fixed compilations errors with abgcc
pkmnsnfrn Jul 27, 2024
0a997fa
Moved follower scripts back to original position https://github.com/r…
pkmnsnfrn Jul 27, 2024
d21d23b
Removed extra spaces per https://github.com/rh-hideout/pokeemerald-e…
pkmnsnfrn Jul 27, 2024
b666782
Nested conditions per https://github.com/rh-hideout/pokeemerald-expan…
pkmnsnfrn Jul 27, 2024
e360d3b
Removed extra newline per https://github.com/rh-hideout/pokeemerald-e…
pkmnsnfrn Jul 27, 2024
3c4aaf5
Removed unneeded preproc per https://github.com/rh-hideout/pokeemeral…
pkmnsnfrn Jul 27, 2024
fccecf0
Removed extra newline per https://github.com/rh-hideout/pokeemerald-e…
pkmnsnfrn Jul 27, 2024
4f03ba9
Removed extra newline per https://github.com/rh-hideout/pokeemerald-e…
pkmnsnfrn Jul 27, 2024
5bb1730
Fixed if statement compilation
pkmnsnfrn Jul 27, 2024
1ac4d19
Changed mb to MetatileBehavior per https://github.com/rh-hideout/poke…
pkmnsnfrn Jul 27, 2024
fb53297
Added documentation around OW_AUTO_SIGNPOST
pkmnsnfrn Jul 27, 2024
91255a6
Removed mb labels
pkmnsnfrn Jul 27, 2024
0a55a7f
Combined if statements per https://github.com/rh-hideout/pokeemerald-…
pkmnsnfrn Aug 12, 2024
cb77949
Fixed identation per https://github.com/rh-hideout/pokeemerald-expans…
pkmnsnfrn Aug 12, 2024
b39258e
Combined conditions per https://github.com/rh-hideout/pokeemerald-exp…
pkmnsnfrn Aug 12, 2024
846e8a2
Removed IsMsgSignPost per https://github.com/rh-hideout/pokeemerald-e…
pkmnsnfrn Aug 12, 2024
c3c4334
Removed ClearMsgBoxCancelableState per https://github.com/rh-hideout/…
pkmnsnfrn Aug 12, 2024
4387b6e
Removed SetWalkingIntoSignVars per https://github.com/rh-hideout/poke…
pkmnsnfrn Aug 12, 2024
30cc067
Fixed global variable naming conventions
pkmnsnfrn Aug 12, 2024
23134ce
Merge branch 'upcoming' into signpost
pkmnsnfrn Aug 28, 2024
9516793
Merge branch 'upcoming' into signpost
pkmnsnfrn Aug 31, 2024
0e1b62c
Merge branch 'upcoming' into signpost
pkmnsnfrn Sep 6, 2024
1ba8e7d
Merge branch 'upcoming' into signpost
pkmnsnfrn Sep 12, 2024
f0bd3c5
Fixed spacing per https://github.com/rh-hideout/pokeemerald-expansion…
pkmnsnfrn Sep 19, 2024
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
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
Loading