pokeemerald/src/rom6.c

213 lines
5.6 KiB
C
Raw Normal View History

2018-04-10 08:47:29 +02:00
#include "global.h"
#include "braille_puzzles.h"
#include "event_data.h"
2018-10-17 02:11:44 +02:00
#include "event_object_movement.h"
2018-04-10 08:47:29 +02:00
#include "event_scripts.h"
#include "field_effect.h"
#include "field_player_avatar.h"
#include "item_use.h"
#include "overworld.h"
2018-10-17 02:11:44 +02:00
#include "party_menu.h"
#include "rom6.h"
2018-04-10 08:47:29 +02:00
#include "script.h"
#include "sound.h"
#include "sprite.h"
#include "task.h"
2018-10-17 02:11:44 +02:00
#include "constants/event_object_movement_constants.h"
#include "constants/event_objects.h"
2018-11-13 15:19:04 +01:00
#include "constants/field_effects.h"
2018-07-13 05:39:38 +02:00
#include "constants/map_types.h"
2018-10-17 02:11:44 +02:00
#include "constants/songs.h"
2018-04-10 08:47:29 +02:00
// static functions
static void task08_080C9820(u8 taskId);
static void sub_8135578(u8 taskId);
static void sub_813552C(u8 taskId);
static void sub_813561C(u8 taskId);
static void sub_81356C4(void);
static void sub_8135714(void);
static void hm2_dig(void);
static void sub_8135780(void);
// extern RAM loc
2018-06-16 00:45:48 +02:00
extern struct MapPosition gPlayerFacingPosition;
2018-04-10 08:47:29 +02:00
// text
2018-10-17 02:11:44 +02:00
bool8 CheckObjectGraphicsInFrontOfPlayer(u8 graphicsId)
2018-04-10 08:47:29 +02:00
{
u8 eventObjId;
2018-04-10 08:47:29 +02:00
2018-06-16 00:45:48 +02:00
GetXYCoordsOneStepInFrontOfPlayer(&gPlayerFacingPosition.x, &gPlayerFacingPosition.y);
gPlayerFacingPosition.height = PlayerGetZCoord();
eventObjId = GetEventObjectIdByXYZ(gPlayerFacingPosition.x, gPlayerFacingPosition.y, gPlayerFacingPosition.height);
2018-10-17 02:11:44 +02:00
if (gEventObjects[eventObjId].graphicsId != graphicsId)
2018-04-10 08:47:29 +02:00
{
return FALSE;
}
else
{
gSpecialVar_LastTalked = gEventObjects[eventObjId].localId;
2018-04-10 08:47:29 +02:00
return TRUE;
}
}
u8 oei_task_add(void)
{
2018-06-16 00:45:48 +02:00
GetXYCoordsOneStepInFrontOfPlayer(&gPlayerFacingPosition.x, &gPlayerFacingPosition.y);
2018-04-10 08:47:29 +02:00
return CreateTask(task08_080C9820, 8);
}
static void task08_080C9820(u8 taskId)
{
u8 eventObjId;
2018-04-10 08:47:29 +02:00
ScriptContext2_Enable();
gPlayerAvatar.preventStep = TRUE;
eventObjId = gPlayerAvatar.eventObjectId;
if (!EventObjectIsMovementOverridden(&gEventObjects[eventObjId])
|| EventObjectClearHeldMovementIfFinished(&gEventObjects[eventObjId]))
2018-04-10 08:47:29 +02:00
{
if (gMapHeader.mapType == MAP_TYPE_UNDERWATER)
{
FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT);
gTasks[taskId].func = sub_8135578;
}
else
{
sub_808C114();
2018-10-17 02:11:44 +02:00
EventObjectSetHeldMovement(&gEventObjects[eventObjId], MOVEMENT_ACTION_START_ANIM_IN_DIRECTION);
2018-04-10 08:47:29 +02:00
gTasks[taskId].func = sub_813552C;
}
}
}
static void sub_813552C(u8 taskId)
{
if (EventObjectCheckHeldMovementStatus(&gEventObjects[gPlayerAvatar.eventObjectId]) == TRUE)
2018-04-10 08:47:29 +02:00
{
FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT);
gTasks[taskId].func = sub_8135578;
}
}
static void sub_8135578(u8 taskId)
{
2018-10-17 02:11:44 +02:00
if (!FieldEffectActiveListContains(FLDEFF_FIELD_MOVE_SHOW_MON))
2018-04-10 08:47:29 +02:00
{
gFieldEffectArguments[1] = GetPlayerFacingDirection();
2018-04-10 08:47:29 +02:00
if (gFieldEffectArguments[1] == 1)
gFieldEffectArguments[2] = 0;
if (gFieldEffectArguments[1] == 2)
gFieldEffectArguments[2] = 1;
if (gFieldEffectArguments[1] == 3)
gFieldEffectArguments[2] = 2;
if (gFieldEffectArguments[1] == 4)
gFieldEffectArguments[2] = 3;
EventObjectSetGraphicsId(&gEventObjects[gPlayerAvatar.eventObjectId], GetPlayerAvatarGraphicsIdByCurrentState());
2018-04-10 08:47:29 +02:00
StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], gFieldEffectArguments[2]);
FieldEffectActiveListRemove(6);
gTasks[taskId].func = sub_813561C;
}
}
static void sub_813561C(u8 taskId)
{
void (*func)(void) = (void (*)(void))(((u16)gTasks[taskId].data[8] << 16) | (u16)gTasks[taskId].data[9]);
func();
gPlayerAvatar.preventStep = FALSE;
DestroyTask(taskId);
}
bool8 SetUpFieldMove_RockSmash(void)
{
2018-06-17 12:39:58 +02:00
if (ShouldDoBrailleStrengthEffect())
2018-04-10 08:47:29 +02:00
{
gSpecialVar_Result = GetCursorSelectionMonId();
2018-06-16 00:45:48 +02:00
gFieldCallback2 = FieldCallback_PrepareFadeInFromMenu;
gPostMenuFieldCallback = sub_8179834;
2018-04-10 08:47:29 +02:00
return TRUE;
}
else if (CheckObjectGraphicsInFrontOfPlayer(EVENT_OBJ_GFX_BREAKABLE_ROCK) == TRUE)
2018-04-10 08:47:29 +02:00
{
2018-06-16 00:45:48 +02:00
gFieldCallback2 = FieldCallback_PrepareFadeInFromMenu;
gPostMenuFieldCallback = sub_81356C4;
2018-04-10 08:47:29 +02:00
return TRUE;
}
else
{
return FALSE;
}
}
static void sub_81356C4(void)
{
gFieldEffectArguments[0] = GetCursorSelectionMonId();
ScriptContext1_SetupScript(Route111_EventScript_2907F0);
}
bool8 FldEff_UseRockSmash(void)
{
u8 taskId = oei_task_add();
gTasks[taskId].data[8] = (u32)sub_8135714 >> 16;
gTasks[taskId].data[9] = (u32)sub_8135714;
IncrementGameStat(GAME_STAT_USED_ROCK_SMASH);
return FALSE;
}
static void sub_8135714(void)
{
PlaySE(SE_W088);
FieldEffectActiveListRemove(FLDEFF_USE_ROCK_SMASH);
EnableBothScriptContexts();
}
bool8 SetUpFieldMove_Dig(void)
{
if (CanUseEscapeRopeOnCurrMap() == TRUE)
{
2018-06-16 00:45:48 +02:00
gFieldCallback2 = FieldCallback_PrepareFadeInFromMenu;
gPostMenuFieldCallback = hm2_dig;
2018-04-10 08:47:29 +02:00
return TRUE;
}
else
{
return FALSE;
}
}
static void hm2_dig(void)
{
Overworld_ResetStateAfterDigEscRope();
FieldEffectStart(FLDEFF_USE_DIG);
gFieldEffectArguments[0] = GetCursorSelectionMonId();
}
bool8 FldEff_UseDig(void)
{
u8 taskId = oei_task_add();
gTasks[taskId].data[8] = (u32)sub_8135780 >> 16;
gTasks[taskId].data[9] = (u32)sub_8135780;
if (!ShouldDoBrailleDigEffect())
2018-10-17 02:11:44 +02:00
SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT);
2018-04-10 08:47:29 +02:00
return FALSE;
}
static void sub_8135780(void)
{
u8 taskId;
FieldEffectActiveListRemove(FLDEFF_USE_DIG);
if (ShouldDoBrailleDigEffect())
{
DoBrailleDigEffect();
}
else
{
taskId = CreateTask(task08_080A1C44, 8);
gTasks[taskId].data[0] = 0;
}
}