pokeemerald/src/event_obj_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_movement.h"
2018-04-03 12:52:31 +02:00
#include "field_player_avatar.h"
#include "event_obj_lock.h"
2018-04-03 12:52:31 +02:00
#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
bool8 walkrun_is_standing_still(void)
{
if (gPlayerAvatar.tileTransitionState == T_TILE_TRANSITION)
return FALSE;
else
return TRUE;
}
static void sub_80983A4(u8 taskId)
{
if (walkrun_is_standing_still())
{
sub_808B864();
DestroyTask(taskId);
}
}
bool8 sub_80983C4(void)
{
if (FuncIsActiveTask(sub_80983A4))
{
return FALSE;
}
else
{
sub_808BCF4();
return TRUE;
}
}
void ScriptFreezeEventObjects(void)
2018-04-03 12:52:31 +02:00
{
FreezeEventObjects();
2018-04-03 12:52:31 +02:00
CreateTask(sub_80983A4, 80);
}
static void sub_8098400(u8 taskId)
{
struct Task *task = &gTasks[taskId];
if (!task->data[0] && walkrun_is_standing_still() == TRUE)
{
sub_808B864();
task->data[0] = 1;
}
if (!task->data[1] && !gEventObjects[gSelectedEventObject].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeEventObject(&gEventObjects[gSelectedEventObject]);
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 LockSelectedEventObject(void)
2018-04-03 12:52:31 +02:00
{
u8 taskId;
FreezeEventObjectsExceptOne(gSelectedEventObject);
2018-04-03 12:52:31 +02:00
taskId = CreateTask(sub_8098400, 80);
if (!gEventObjects[gSelectedEventObject].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeEventObject(&gEventObjects[gSelectedEventObject]);
2018-04-03 12:52:31 +02:00
gTasks[taskId].data[1] = 1;
}
}
void ScriptUnfreezeEventObjects(void)
2018-04-03 12:52:31 +02:00
{
2018-12-28 19:29:21 +01:00
u8 playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0);
EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]);
2019-09-16 06:22:50 +02:00
ScriptMovement_UnfreezeEventObjects();
UnfreezeEventObjects();
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 (gEventObjects[gSelectedEventObject].active)
EventObjectClearHeldMovementIfFinished(&gEventObjects[gSelectedEventObject]);
2018-12-28 19:29:21 +01:00
playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0);
EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]);
2019-09-16 06:22:50 +02:00
ScriptMovement_UnfreezeEventObjects();
UnfreezeEventObjects();
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
{
EventObjectFaceOppositeDirection(&gEventObjects[gSelectedEventObject], 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
{
EventObjectClearHeldMovementIfActive(&gEventObjects[gSelectedEventObject]);
2018-04-03 12:52:31 +02:00
}
static void sub_80985BC(u8 taskId)
{
struct Task *task = &gTasks[taskId];
u8 eventObjectId = task->data[2];
2018-04-03 12:52:31 +02:00
if (!task->data[0] && walkrun_is_standing_still() == TRUE)
{
sub_808B864();
task->data[0] = 1;
}
if (!task->data[1] && !gEventObjects[eventObjectId].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeEventObject(&gEventObjects[eventObjectId]);
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 = GetChosenApproachingTrainerEventObjectId(0);
2018-04-03 12:52:31 +02:00
if(gNoOfApproachingTrainers == 2)
{
trainerObjectId2 = GetChosenApproachingTrainerEventObjectId(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(!gEventObjects[trainerObjectId1].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeEventObject(&gEventObjects[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(!gEventObjects[trainerObjectId2].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeEventObject(&gEventObjects[trainerObjectId2]);
2018-04-03 12:52:31 +02:00
gTasks[taskId].data[1] = 1;
}
}
else
{
FreezeEventObjectsExceptOne(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(!gEventObjects[trainerObjectId1].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeEventObject(&gEventObjects[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;
}
}