add auto read signposts

This commit is contained in:
ghoulslash 2021-04-01 09:45:17 -06:00
parent 6b070010b2
commit dfce7f1548
16 changed files with 206 additions and 4 deletions

View file

@ -690,6 +690,10 @@ EventScript_BackupMrBrineyLocation:: @ 8271E95
.include "data/scripts/rival_graphics.inc"
.include "data/scripts/set_gym_trainers.inc"
EventScript_CancelMessageBox::
release
end
Common_EventScript_ShowBagIsFull:: @ 8272054
msgbox gText_TooBadBagIsFull, MSGBOX_DEFAULT
release

View file

@ -30,7 +30,7 @@
#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_SIGNPOST 0x1D
#define MB_UNUSED_1E 0x1E
#define MB_UNUSED_1F 0x1F
#define MB_ICE 0x20

View file

@ -610,4 +610,6 @@ extern const u8 EventScript_TradeCenter_Chair0[];
extern const u8 EventScript_ConfirmLeaveTradeRoom[];
extern const u8 EventScript_TerminateLink[];
extern const u8 EventScript_CancelMessageBox[];
#endif // GUARD_EVENT_SCRIPTS_H

View file

@ -40,5 +40,6 @@ u8 TrySetDiveWarp(void);
const u8 *GetInteractedLinkPlayerScript(struct MapPosition *position, u8 metatileBehavior, u8 direction);
u8 *GetCoordEventScriptAtMapPosition(struct MapPosition *position);
void ClearPoisonStepCounter(void);
void FieldInput_HandleCancelSignpost(struct FieldInput *input);
#endif // GUARD_FIELDCONTROLAVATAR_H

View file

@ -19,4 +19,6 @@ u8 GetFieldMessageBoxMode(void);
void StopFieldMessage(void);
void InitFieldMessageBox(void);
extern u8 gWalkAwayFromSignInhibitTimer;
#endif // GUARD_FIELD_MESSAGE_BOX_H

View file

@ -145,5 +145,6 @@ bool8 MetatileBehavior_IsQuestionnaire(u8);
bool8 MetatileBehavior_IsLongGrass_Duplicate(u8);
bool8 MetatileBehavior_IsLongGrassSouthEdge(u8);
bool8 MetatileBehavior_IsTrainerHillTimer(u8);
bool8 MetatileBehavior_IsSignpost(u8 mb);
#endif // GUARD_METATILE_BEHAVIOR

View file

@ -62,4 +62,12 @@ void InitRamScript_NoObjectEvent(u8 *script, u16 scriptSize);
// srccmd.h
void SetMovingNpcId(u16 npcId);
// auto read signs
void SetWalkingIntoSignVars(void);
void MsgSetSignPost(void);
void ResetFacingNpcOrSignPostVars(void);
bool32 IsMsgSignPost(void);
bool32 CanWalkAwayToCancelMsgBox(void);
void ClearMsgBoxCancelableState(void);
#endif // GUARD_SCRIPT_H

View file

@ -23,5 +23,6 @@ void rbox_fill_rectangle(u8 windowId);
const u16 *GetTextWindowPalette(u8 id);
const u16 *GetOverworldTextboxPalettePtr(void);
void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset);
void LoadSignPostWindowFrameGfx(void);
#endif // GUARD_TEXT_WINDOW_H

View file

@ -9,6 +9,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"
@ -41,6 +42,13 @@ static EWRAM_DATA u16 sPreviousPlayerMetatileBehavior = 0;
u8 gSelectedObjectEvent;
#define SIGNPOST_POKECENTER 0
#define SIGNPOST_POKEMART 1
#define SIGNPOST_INDIGO_1 2
#define SIGNPOST_INDIGO_2 3
#define SIGNPOST_SCRIPTED 240
#define SIGNPOST_NA 255
static void GetPlayerPosition(struct MapPosition *);
static void GetInFrontOfPlayerPosition(struct MapPosition *);
static u16 GetPlayerCurMetatileBehavior(int);
@ -69,6 +77,10 @@ static bool8 TryStartMiscWalkingScripts(u16);
static bool8 TryStartStepCountScript(u16);
static void UpdateFriendshipStepCounter(void);
static bool8 UpdatePoisonStepCounter(void);
static bool8 TrySetUpWalkIntoSignpostScript(struct MapPosition * position, u16 metatileBehavior, u8 playerDirection);
static void SetUpWalkIntoSignScript(const u8 *script, u8 playerDirection);
static u8 GetFacingSignpostType(u16 metatileBehvaior, u8 direction);
static const u8 *GetSignpostScriptAtMapPosition(struct MapPosition * position);
void FieldClearPlayerInput(struct FieldInput *input)
{
@ -140,7 +152,8 @@ int ProcessPlayerFieldInput(struct FieldInput *input)
gSpecialVar_LastTalked = 0;
gSelectedObjectEvent = 0;
ResetFacingNpcOrSignPostVars();
playerDirection = GetPlayerFacingDirection();
GetPlayerPosition(&position);
metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y);
@ -160,6 +173,20 @@ int ProcessPlayerFieldInput(struct FieldInput *input)
if (TryStartStepBasedScript(&position, metatileBehavior, playerDirection) == TRUE)
return TRUE;
}
if (input->checkStandardWildEncounter)
{
if (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)
@ -170,6 +197,13 @@ int ProcessPlayerFieldInput(struct FieldInput *input)
GetInFrontOfPlayerPosition(&position);
metatileBehavior = MapGridGetMetatileBehaviorAt(position.x, position.y);
if (input->heldDirection && input->dpadDirection == playerDirection)
{
if (TrySetUpWalkIntoSignpostScript(&position, metatileBehavior, playerDirection) == TRUE)
return TRUE;
}
if (input->pressedAButton && TryStartInteractionScript(&position, metatileBehavior, playerDirection) == TRUE)
return TRUE;
@ -1005,3 +1039,91 @@ int SetCableClubWarp(void)
SetupWarp(&gMapHeader, GetWarpEventAtMapPosition(&gMapHeader, &position), &position);
return 0;
}
// auto read signposts
// signposts
static bool8 TrySetUpWalkIntoSignpostScript(struct MapPosition *position, u16 metatileBehavior, u8 playerDirection)
{
u8 signpostType;
const u8 *script;
if (JOY_HELD(DPAD_LEFT | DPAD_RIGHT))
return FALSE;
if (playerDirection != DIR_NORTH)
return FALSE;
switch (GetFacingSignpostType(metatileBehavior, playerDirection))
{
/* leaving this commented out for examples of custom signpost types
case SIGNPOST_POKECENTER:
SetUpWalkIntoSignScript(EventScript_PokecenterSign, playerDirection);
return TRUE;
case SIGNPOST_POKEMART:
SetUpWalkIntoSignScript(EventScript_PokemartSign, playerDirection);
return TRUE;*/
case SIGNPOST_SCRIPTED:
script = GetSignpostScriptAtMapPosition(position);
if (script == NULL)
return FALSE;
SetUpWalkIntoSignScript(script, playerDirection);
return TRUE;
default:
return FALSE;
}
}
static u8 GetFacingSignpostType(u16 metatileBehavior, u8 playerDirection)
{
/*if (MetatileBehavior_IsPlayerFacingPokemonCenterSign(metatileBehavior, playerDirection) == TRUE)
return SIGNPOST_POKECENTER;
if (MetatileBehavior_IsPlayerFacingPokeMartSign(metatileBehavior, playerDirection) == TRUE)
return SIGNPOST_POKEMART;*/
if (MetatileBehavior_IsSignpost(metatileBehavior) == TRUE)
return SIGNPOST_SCRIPTED;
return SIGNPOST_NA;
}
static void SetUpWalkIntoSignScript(const u8 *script, u8 playerDirection)
{
gSpecialVar_Facing = playerDirection;
ScriptContext1_SetupScript(script);
SetWalkingIntoSignVars();
MsgSetSignPost();
}
static const u8 *GetSignpostScriptAtMapPosition(struct MapPosition *position)
{
const struct BgEvent *event = GetBackgroundEventAtPosition(&gMapHeader, position->x - 7, position->y - 7, position->height);
if (event == NULL)
return NULL;
if (event->bgUnion.script != NULL)
return event->bgUnion.script;
return EventScript_TestSignpostMsg;
}
void FieldInput_HandleCancelSignpost(struct FieldInput *input)
{
if (ScriptContext1_IsScriptSetUp() == TRUE)
{
if (gWalkAwayFromSignInhibitTimer != 0)
{
gWalkAwayFromSignInhibitTimer--;
}
else if (CanWalkAwayToCancelMsgBox() == TRUE)
{
//ClearMsgBoxCancelableState();
if (input->dpadDirection != 0 && GetPlayerFacingDirection() != input->dpadDirection)
{
ScriptContext1_SetupScript(EventScript_CancelMessageBox);
ScriptContext2_Enable();
}
else if (input->pressedStartButton)
{
ScriptContext1_SetupScript(EventScript_CancelMessageBox);
ScriptContext2_Enable();
}
}
}
}

View file

@ -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 gWalkAwayFromSignInhibitTimer = 0;
static void ExpandStringAndStartDrawFieldMessage(const u8*, bool32);
static void StartDrawFieldMessage(void);
@ -29,7 +32,12 @@ static void Task_DrawFieldMessage(u8 taskId)
switch (task->tState)
{
case 0:
LoadMessageBoxAndBorderGfx();
if (IsMsgSignPost())
LoadSignPostWindowFrameGfx();
else
LoadMessageBoxAndBorderGfx();
task->tState++;
break;
task->tState++;
break;
case 1:

View file

@ -39,7 +39,7 @@ static const u8 sTileBitAttributes[] =
[MB_UNUSED_SOOTOPOLIS_DEEP_WATER_2] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_STAIRS_OUTSIDE_ABANDONED_SHIP] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_SHOAL_CAVE_ENTRANCE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
[MB_UNUSED_1D] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_SIGNPOST] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_UNUSED_1E] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_UNUSED_1F] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE),
[MB_ICE] = TILE_ATTRIBUTES(TRUE, FALSE, FALSE),
@ -1495,3 +1495,9 @@ bool8 MetatileBehavior_IsTrainerHillTimer(u8 metatileBehavior)
else
return FALSE;
}
bool8 MetatileBehavior_IsSignpost(u8 mb)
{
return (mb == MB_SIGNPOST);
}

View file

@ -1422,6 +1422,7 @@ static void DoCB1_Overworld(u16 newKeys, u16 heldKeys)
UpdatePlayerAvatarTransitionState();
FieldClearPlayerInput(&inputStruct);
FieldGetPlayerInput(&inputStruct, newKeys, heldKeys);
FieldInput_HandleCancelSignpost(&inputStruct);
if (!ScriptContext2_IsEnabled())
{
if (ProcessPlayerFieldInput(&inputStruct) == 1)

View file

@ -1248,6 +1248,7 @@ bool8 ScrCmd_releaseall(struct ScriptContext *ctx)
ObjectEventClearHeldMovementIfFinished(&gObjectEvents[playerObjectId]);
ScriptMovement_UnfreezeObjectEvents();
UnfreezeObjectEvents();
ClearMsgBoxCancelableState();
return FALSE;
}
@ -1262,6 +1263,7 @@ bool8 ScrCmd_release(struct ScriptContext *ctx)
ObjectEventClearHeldMovementIfFinished(&gObjectEvents[playerObjectId]);
ScriptMovement_UnfreezeObjectEvents();
UnfreezeObjectEvents();
ClearMsgBoxCancelableState();
return FALSE;
}

View file

@ -3,6 +3,7 @@
#include "event_data.h"
#include "mevent.h"
#include "util.h"
#include "field_message_box.h"
#include "constants/map_scripts.h"
#define RAM_SCRIPT_MAGIC 51
@ -19,6 +20,8 @@ static u8 sScriptContext1Status;
static struct ScriptContext sScriptContext1;
static struct ScriptContext sScriptContext2;
static bool8 sScriptContext2Enabled;
static u8 sMsgIsSignPost;
static u8 sMsgBoxIsCancelable;
extern ScrCmdFunc gScriptCmdTable[];
extern ScrCmdFunc gScriptCmdTableEnd[];
@ -444,3 +447,35 @@ void InitRamScript_NoObjectEvent(u8 *script, u16 scriptSize)
scriptSize = sizeof(gSaveBlock1Ptr->ramScript.data.script);
InitRamScript(script, scriptSize, 0xFF, 0xFF, 0xFF);
}
// auto read signposts
void SetWalkingIntoSignVars(void)
{
gWalkAwayFromSignInhibitTimer = 6;
sMsgBoxIsCancelable = TRUE;
}
bool32 IsMsgSignPost(void)
{
return sMsgIsSignPost;
}
void ResetFacingNpcOrSignPostVars(void)
{
sMsgIsSignPost = FALSE;
}
void MsgSetSignPost(void)
{
sMsgIsSignPost = TRUE;
}
void ClearMsgBoxCancelableState(void)
{
sMsgBoxIsCancelable = FALSE;
}
bool32 CanWalkAwayToCancelMsgBox(void)
{
return sMsgBoxIsCancelable;
}

View file

@ -5,6 +5,7 @@
#include "palette.h"
#include "bg.h"
#include "graphics.h"
#include "menu.h"
// const rom data
const u8 gTextWindowFrame1_Gfx[] = INCBIN_U8("graphics/text_window/1.4bpp");
@ -195,3 +196,11 @@ void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset)
LoadBgTiles(bg, sWindowFrames[gSaveBlock2Ptr->optionsWindowFrameType].tiles, 0x120, destOffset);
LoadPalette(GetWindowFrameTilesPal(gSaveBlock2Ptr->optionsWindowFrameType)->pal, palOffset, 0x20);
}
void LoadSignPostWindowFrameGfx(void)
{
// TODO signpost msgbox frames
//LoadBgTiles(GetWindowAttribute(windowId, WINDOW_BG), gUnknown_8470B0C, 0x260, destOffset);
//LoadPalette(GetWindowFrameTilesPal(1), palIdx, 32);
LoadMessageBoxAndBorderGfx();
}