pokeemerald/src/event_object_lock.c

188 lines
4.5 KiB
C
Raw Normal View History

2018-04-03 12:52:31 +02:00
#include "global.h"
#include "event_data.h"
#include "event_object_lock.h"
#include "event_object_movement.h"
2018-04-03 12:52:31 +02:00
#include "field_player_avatar.h"
#include "script_movement.h"
#include "task.h"
#include "trainer_see.h"
2018-12-28 19:29:21 +01:00
#include "constants/event_objects.h"
2018-04-03 12:52:31 +02:00
2019-12-17 09:24:44 +01:00
bool8 IsPlayerStandingStill(void)
2018-04-03 12:52:31 +02:00
{
if (gPlayerAvatar.tileTransitionState == T_TILE_TRANSITION)
return FALSE;
else
return TRUE;
}
static void sub_80983A4(u8 taskId)
{
2019-12-17 09:24:44 +01:00
if (IsPlayerStandingStill())
2018-04-03 12:52:31 +02:00
{
sub_808B864();
DestroyTask(taskId);
}
}
bool8 sub_80983C4(void)
{
if (FuncIsActiveTask(sub_80983A4))
{
return FALSE;
}
else
{
sub_808BCF4();
return TRUE;
}
}
void ScriptFreezeObjectEvents(void)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvents();
2018-04-03 12:52:31 +02:00
CreateTask(sub_80983A4, 80);
}
static void sub_8098400(u8 taskId)
{
struct Task *task = &gTasks[taskId];
2019-12-17 09:24:44 +01:00
if (!task->data[0] && IsPlayerStandingStill() == TRUE)
2018-04-03 12:52:31 +02:00
{
sub_808B864();
task->data[0] = 1;
}
if (!task->data[1] && !gObjectEvents[gSelectedObjectEvent].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[gSelectedObjectEvent]);
2018-04-03 12:52:31 +02:00
task->data[1] = 1;
}
if (task->data[0] && task->data[1])
DestroyTask(taskId);
}
bool8 sub_809847C(void)
{
if (FuncIsActiveTask(sub_8098400))
{
return FALSE;
}
else
{
sub_808BCF4();
return TRUE;
}
}
void LockSelectedObjectEvent(void)
2018-04-03 12:52:31 +02:00
{
u8 taskId;
FreezeObjectEventsExceptOne(gSelectedObjectEvent);
2018-04-03 12:52:31 +02:00
taskId = CreateTask(sub_8098400, 80);
if (!gObjectEvents[gSelectedObjectEvent].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[gSelectedObjectEvent]);
2018-04-03 12:52:31 +02:00
gTasks[taskId].data[1] = 1;
}
}
void ScriptUnfreezeObjectEvents(void)
2018-04-03 12:52:31 +02:00
{
u8 playerObjectId = GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0);
ObjectEventClearHeldMovementIfFinished(&gObjectEvents[playerObjectId]);
ScriptMovement_UnfreezeObjectEvents();
UnfreezeObjectEvents();
2018-04-03 12:52:31 +02:00
}
void sub_8098524(void)
{
2018-12-28 19:29:21 +01:00
u8 playerObjectId;
2018-04-03 12:52:31 +02:00
if (gObjectEvents[gSelectedObjectEvent].active)
ObjectEventClearHeldMovementIfFinished(&gObjectEvents[gSelectedObjectEvent]);
playerObjectId = GetObjectEventIdByLocalIdAndMap(OBJ_EVENT_ID_PLAYER, 0, 0);
ObjectEventClearHeldMovementIfFinished(&gObjectEvents[playerObjectId]);
ScriptMovement_UnfreezeObjectEvents();
UnfreezeObjectEvents();
2018-04-03 12:52:31 +02:00
}
2019-10-11 10:14:09 +02:00
void Script_FacePlayer(void)
2018-04-03 12:52:31 +02:00
{
ObjectEventFaceOppositeDirection(&gObjectEvents[gSelectedObjectEvent], gSpecialVar_Facing);
2018-04-03 12:52:31 +02:00
}
2019-10-11 10:14:09 +02:00
void Script_ClearHeldMovement(void)
2018-04-03 12:52:31 +02:00
{
ObjectEventClearHeldMovementIfActive(&gObjectEvents[gSelectedObjectEvent]);
2018-04-03 12:52:31 +02:00
}
static void sub_80985BC(u8 taskId)
{
struct Task *task = &gTasks[taskId];
u8 objectEventId = task->data[2];
2018-04-03 12:52:31 +02:00
2019-12-17 09:24:44 +01:00
if (!task->data[0] && IsPlayerStandingStill() == TRUE)
2018-04-03 12:52:31 +02:00
{
sub_808B864();
task->data[0] = 1;
}
if (!task->data[1] && !gObjectEvents[objectEventId].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[objectEventId]);
2018-04-03 12:52:31 +02:00
task->data[1] = 1;
}
if (task->data[0] && task->data[1])
DestroyTask(taskId);
}
void sub_8098630(void)
{
2018-04-12 19:06:07 +02:00
u8 trainerObjectId1, trainerObjectId2, taskId;
trainerObjectId1 = GetChosenApproachingTrainerObjectEventId(0);
2018-04-03 12:52:31 +02:00
if(gNoOfApproachingTrainers == 2)
{
trainerObjectId2 = GetChosenApproachingTrainerObjectEventId(1);
2018-04-12 19:06:07 +02:00
sub_8098074(trainerObjectId1, trainerObjectId2);
2018-04-03 12:52:31 +02:00
taskId = CreateTask(sub_80985BC, 80);
2018-04-12 19:06:07 +02:00
gTasks[taskId].data[2] = trainerObjectId1;
if(!gObjectEvents[trainerObjectId1].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId1]);
2018-04-03 12:52:31 +02:00
gTasks[taskId].data[1] = 1;
}
taskId = CreateTask(sub_80985BC, 81);
2018-04-12 19:06:07 +02:00
gTasks[taskId].data[2] = trainerObjectId2;
if(!gObjectEvents[trainerObjectId2].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId2]);
2018-04-03 12:52:31 +02:00
gTasks[taskId].data[1] = 1;
}
}
else
{
FreezeObjectEventsExceptOne(trainerObjectId1);
2018-04-03 12:52:31 +02:00
taskId = CreateTask(sub_80985BC, 80);
2018-04-12 19:06:07 +02:00
gTasks[taskId].data[2] = trainerObjectId1;
if(!gObjectEvents[trainerObjectId1].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId1]);
2018-04-03 12:52:31 +02:00
gTasks[taskId].data[1] = 1;
}
}
}
bool8 sub_8098734(void)
{
if (FuncIsActiveTask(sub_80985BC))
{
return FALSE;
}
else
{
sub_808BCF4();
return TRUE;
}
}