pokeemerald/src/event_object_lock.c

209 lines
5.8 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;
}
// Freeze player once their movement is finished
static void Task_FreezePlayer(u8 taskId)
2018-04-03 12:52:31 +02:00
{
2019-12-17 09:24:44 +01:00
if (IsPlayerStandingStill())
2018-04-03 12:52:31 +02:00
{
PlayerFreeze();
2018-04-03 12:52:31 +02:00
DestroyTask(taskId);
}
}
bool8 IsFreezePlayerFinished(void)
2018-04-03 12:52:31 +02:00
{
if (FuncIsActiveTask(Task_FreezePlayer))
2018-04-03 12:52:31 +02:00
{
return FALSE;
}
else
{
sub_808BCF4();
return TRUE;
}
}
2021-05-04 07:21:50 +02:00
void FreezeObjects_WaitForPlayer(void)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvents();
CreateTask(Task_FreezePlayer, 80);
2018-04-03 12:52:31 +02:00
}
#define tPlayerFrozen data[0]
#define tObjectFrozen data[1]
#define tObjectId data[2]
// Freeze selected object and player once their movement is finished
static void Task_FreezeSelectedObjectAndPlayer(u8 taskId)
2018-04-03 12:52:31 +02:00
{
struct Task *task = &gTasks[taskId];
if (!task->tPlayerFrozen && IsPlayerStandingStill() == TRUE)
2018-04-03 12:52:31 +02:00
{
PlayerFreeze();
task->tPlayerFrozen = TRUE;
2018-04-03 12:52:31 +02:00
}
if (!task->tObjectFrozen && !gObjectEvents[gSelectedObjectEvent].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[gSelectedObjectEvent]);
task->tObjectFrozen = TRUE;
2018-04-03 12:52:31 +02:00
}
if (task->tPlayerFrozen && task->tObjectFrozen)
2018-04-03 12:52:31 +02:00
DestroyTask(taskId);
}
bool8 IsFreezeSelectedObjectAndPlayerFinished(void)
2018-04-03 12:52:31 +02:00
{
if (FuncIsActiveTask(Task_FreezeSelectedObjectAndPlayer))
2018-04-03 12:52:31 +02:00
{
return FALSE;
}
else
{
sub_808BCF4();
return TRUE;
}
}
2021-05-04 07:21:50 +02:00
// Freeze all objects immediately except the selected object and the player.
// The selected object and player are frozen once their movement is finished.
void FreezeObjects_WaitForPlayerAndSelected(void)
2018-04-03 12:52:31 +02:00
{
u8 taskId;
FreezeObjectEventsExceptOne(gSelectedObjectEvent);
taskId = CreateTask(Task_FreezeSelectedObjectAndPlayer, 80);
if (!gObjectEvents[gSelectedObjectEvent].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[gSelectedObjectEvent]);
gTasks[taskId].tObjectFrozen = TRUE;
2018-04-03 12:52:31 +02:00
}
}
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
}
2020-05-30 10:09:21 +02:00
void UnionRoom_UnlockPlayerAndChatPartner(void)
2018-04-03 12:52:31 +02:00
{
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
}
// Freeze designated object and player once their movement is finished
static void Task_FreezeObjectAndPlayer(u8 taskId)
2018-04-03 12:52:31 +02:00
{
struct Task *task = &gTasks[taskId];
u8 objectEventId = task->tObjectId;
2018-04-03 12:52:31 +02:00
if (!task->tPlayerFrozen && IsPlayerStandingStill() == TRUE)
2018-04-03 12:52:31 +02:00
{
PlayerFreeze();
task->tPlayerFrozen = TRUE;
2018-04-03 12:52:31 +02:00
}
if (!task->tObjectFrozen && !gObjectEvents[objectEventId].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[objectEventId]);
task->tObjectFrozen = TRUE;
2018-04-03 12:52:31 +02:00
}
if (task->tPlayerFrozen && task->tObjectFrozen)
2018-04-03 12:52:31 +02:00
DestroyTask(taskId);
}
2021-05-04 07:21:50 +02:00
// Freeze all objects immediately except the player and the approaching trainers.
// The approaching trainers and player are frozen once their movement is finished
void FreezeForApproachingTrainers(void)
2018-04-03 12:52:31 +02:00
{
2018-04-12 19:06:07 +02:00
u8 trainerObjectId1, trainerObjectId2, taskId;
trainerObjectId1 = GetChosenApproachingTrainerObjectEventId(0);
if (gNoOfApproachingTrainers == 2)
2018-04-03 12:52:31 +02:00
{
// Get second trainer, freeze all other objects
trainerObjectId2 = GetChosenApproachingTrainerObjectEventId(1);
FreezeObjectEventsExceptTwo(trainerObjectId1, trainerObjectId2);
// Start task to freeze trainer 1 (and player) after movement
taskId = CreateTask(Task_FreezeObjectAndPlayer, 80);
gTasks[taskId].tObjectId = trainerObjectId1;
if (!gObjectEvents[trainerObjectId1].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId1]);
gTasks[taskId].tObjectFrozen = TRUE;
2018-04-03 12:52:31 +02:00
}
// Start task to freeze trainer 2 after movement
taskId = CreateTask(Task_FreezeObjectAndPlayer, 81);
gTasks[taskId].tObjectId = trainerObjectId2;
if (!gObjectEvents[trainerObjectId2].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId2]);
gTasks[taskId].tObjectFrozen = TRUE;
2018-04-03 12:52:31 +02:00
}
}
else
{
FreezeObjectEventsExceptOne(trainerObjectId1);
taskId = CreateTask(Task_FreezeObjectAndPlayer, 80);
gTasks[taskId].tObjectId = trainerObjectId1;
if (!gObjectEvents[trainerObjectId1].singleMovementActive)
2018-04-03 12:52:31 +02:00
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId1]);
gTasks[taskId].tObjectFrozen = TRUE;
2018-04-03 12:52:31 +02:00
}
}
}
bool8 IsFreezeObjectAndPlayerFinished(void)
2018-04-03 12:52:31 +02:00
{
if (FuncIsActiveTask(Task_FreezeObjectAndPlayer))
2018-04-03 12:52:31 +02:00
{
return FALSE;
}
else
{
sub_808BCF4();
return TRUE;
}
}
#undef tPlayerFrozen
#undef tObjectFrozen
#undef tObjectId