2017-09-23 04:45:47 +02:00
|
|
|
#include "global.h"
|
2018-09-11 03:04:03 +02:00
|
|
|
#include "event_data.h"
|
2018-06-11 15:34:19 +02:00
|
|
|
#include "event_object_movement.h"
|
2018-12-27 23:30:47 +01:00
|
|
|
#include "field_camera.h"
|
|
|
|
#include "field_screen_effect.h"
|
|
|
|
#include "field_specials.h"
|
|
|
|
#include "fieldmap.h"
|
2018-09-11 03:04:03 +02:00
|
|
|
#include "main.h"
|
2018-12-27 23:30:47 +01:00
|
|
|
#include "overworld.h"
|
2017-09-23 04:45:47 +02:00
|
|
|
#include "palette.h"
|
|
|
|
#include "script.h"
|
2018-09-11 03:04:03 +02:00
|
|
|
#include "script_movement.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "sprite.h"
|
|
|
|
#include "task.h"
|
2019-05-25 21:26:29 +02:00
|
|
|
#include "constants/event_objects.h"
|
2019-11-08 09:37:46 +01:00
|
|
|
#include "constants/event_object_movement_constants.h"
|
|
|
|
#include "constants/field_specials.h"
|
2018-09-11 03:04:03 +02:00
|
|
|
#include "constants/songs.h"
|
2017-12-11 19:27:51 +01:00
|
|
|
#include "constants/vars.h"
|
2019-06-12 02:57:42 +02:00
|
|
|
#include "constants/metatile_labels.h"
|
2017-09-23 04:45:47 +02:00
|
|
|
|
|
|
|
#define SECONDS(value) ((signed) (60.0 * value + 0.5))
|
|
|
|
|
|
|
|
// porthole states
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
INIT_PORTHOLE,
|
|
|
|
IDLE_CHECK,
|
|
|
|
EXECUTE_MOVEMENT,
|
|
|
|
EXIT_PORTHOLE,
|
|
|
|
};
|
|
|
|
|
2018-09-11 03:04:03 +02:00
|
|
|
//. rodata
|
|
|
|
static const s8 gTruckCamera_HorizontalTable[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, -1, -1, -1, 0};
|
2019-11-08 09:37:46 +01:00
|
|
|
|
|
|
|
static const u8 sSSTidalSailEastMovementScript[] =
|
|
|
|
{
|
2019-11-15 00:58:33 +01:00
|
|
|
MOVEMENT_ACTION_WALK_FAST_RIGHT,
|
2019-11-08 09:37:46 +01:00
|
|
|
MOVEMENT_ACTION_STEP_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u8 sSSTidalSailWestMovementScript[] =
|
|
|
|
{
|
2019-11-15 00:58:33 +01:00
|
|
|
MOVEMENT_ACTION_WALK_FAST_LEFT,
|
2019-11-08 09:37:46 +01:00
|
|
|
MOVEMENT_ACTION_STEP_END
|
|
|
|
};
|
2017-09-23 04:45:47 +02:00
|
|
|
|
2018-09-11 03:04:03 +02:00
|
|
|
// .text
|
2018-12-27 23:30:47 +01:00
|
|
|
static void Task_Truck3(u8);
|
2017-09-23 04:45:47 +02:00
|
|
|
|
2017-09-23 18:06:23 +02:00
|
|
|
s16 GetTruckCameraBobbingY(int a1)
|
2017-09-23 04:45:47 +02:00
|
|
|
{
|
|
|
|
if (!(a1 % 120))
|
|
|
|
return -1;
|
|
|
|
else if ((a1 % 10) <= 4)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-23 18:06:23 +02:00
|
|
|
s16 GetTruckBoxMovement(int a1) // for the box movement?
|
2017-09-23 04:45:47 +02:00
|
|
|
{
|
|
|
|
if (!((a1 + 120) % 180))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Task_Truck1(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
2018-08-16 03:50:56 +02:00
|
|
|
s16 cameraXpan = 0, cameraYpan = 0;
|
|
|
|
s16 box1, box2, box3;
|
2017-09-23 04:45:47 +02:00
|
|
|
|
|
|
|
box1 = GetTruckBoxMovement(data[0] + 30) * 4; // top box.
|
2018-08-16 03:50:56 +02:00
|
|
|
sub_808E82C(1, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, 3 - cameraXpan, box1 + 3);
|
2017-09-23 04:45:47 +02:00
|
|
|
box2 = GetTruckBoxMovement(data[0]) * 2; // bottom left box.
|
2018-08-16 03:50:56 +02:00
|
|
|
sub_808E82C(2, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, -cameraXpan, box2 - 3);
|
2017-09-23 04:45:47 +02:00
|
|
|
box3 = GetTruckBoxMovement(data[0]) * 4; // bottom right box.
|
2018-08-16 03:50:56 +02:00
|
|
|
sub_808E82C(3, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, -3 - cameraXpan, box3);
|
2017-09-23 04:45:47 +02:00
|
|
|
|
2017-09-23 18:42:06 +02:00
|
|
|
if (++data[0] == SECONDS(500)) // this will never run
|
2018-08-16 03:50:56 +02:00
|
|
|
data[0] = 0; // reset the timer if it gets stuck.
|
2017-09-23 04:45:47 +02:00
|
|
|
|
|
|
|
cameraYpan = GetTruckCameraBobbingY(data[0]);
|
2018-08-16 03:50:56 +02:00
|
|
|
SetCameraPanning(cameraXpan, cameraYpan);
|
2017-09-23 04:45:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Task_Truck2(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
s16 cameraYpan;
|
|
|
|
s16 cameraXpan;
|
|
|
|
s16 box1;
|
|
|
|
s16 box2;
|
|
|
|
s16 box3;
|
|
|
|
|
|
|
|
data[0]++;
|
|
|
|
data[2]++;
|
|
|
|
|
|
|
|
if (data[0] > 5)
|
|
|
|
{
|
|
|
|
data[0] = 0;
|
|
|
|
data[1]++;
|
|
|
|
}
|
|
|
|
if ((u16)data[1] == 19)
|
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gTruckCamera_HorizontalTable[data[1]] == 2)
|
|
|
|
gTasks[taskId].func = Task_Truck3;
|
|
|
|
|
|
|
|
cameraXpan = gTruckCamera_HorizontalTable[data[1]];
|
|
|
|
cameraYpan = GetTruckCameraBobbingY(data[2]);
|
|
|
|
SetCameraPanning(cameraXpan, cameraYpan);
|
|
|
|
box1 = GetTruckBoxMovement(data[2] + 30) * 4;
|
|
|
|
sub_808E82C(1, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, 3 - cameraXpan, box1 + 3);
|
|
|
|
box2 = GetTruckBoxMovement(data[2]) * 2;
|
|
|
|
sub_808E82C(2, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, -cameraXpan, box2 - 3);
|
|
|
|
box3 = GetTruckBoxMovement(data[2]) * 4;
|
|
|
|
sub_808E82C(3, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, -3 - cameraXpan, box3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 23:30:47 +01:00
|
|
|
static void Task_Truck3(u8 taskId)
|
2017-09-23 04:45:47 +02:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
s16 cameraXpan;
|
|
|
|
s16 cameraYpan;
|
|
|
|
|
|
|
|
data[0]++;
|
|
|
|
|
|
|
|
if (data[0] > 5)
|
|
|
|
{
|
|
|
|
data[0] = 0;
|
|
|
|
data[1]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((u16)data[1] == 19)
|
|
|
|
{
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cameraXpan = gTruckCamera_HorizontalTable[data[1]];
|
|
|
|
cameraYpan = 0;
|
|
|
|
SetCameraPanning(cameraXpan, 0);
|
|
|
|
sub_808E82C(1, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, 3 - cameraXpan, cameraYpan + 3);
|
|
|
|
sub_808E82C(2, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, -cameraXpan, cameraYpan - 3);
|
|
|
|
sub_808E82C(3, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, -3 - cameraXpan, cameraYpan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Task_HandleTruckSequence(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
switch (data[0])
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Each case has a timer which is handled with data[1], incrementing
|
|
|
|
until it reaches the if function's condition, which sets the next task up.
|
|
|
|
*/
|
|
|
|
case 0:
|
|
|
|
data[1]++;
|
|
|
|
if (data[1] == SECONDS(1.5))
|
|
|
|
{
|
|
|
|
SetCameraPanningCallback(NULL);
|
|
|
|
data[1] = 0; // reset the timer.
|
|
|
|
data[2] = CreateTask(Task_Truck1, 0xA);
|
|
|
|
data[0] = 1; // run the next case.
|
|
|
|
PlaySE(SE_TRACK_MOVE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
data[1]++;
|
|
|
|
if (data[1] == SECONDS(2.5))
|
|
|
|
{
|
|
|
|
pal_fill_black();
|
|
|
|
data[1] = 0;
|
|
|
|
data[0] = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
data[1]++;
|
|
|
|
if (!gPaletteFade.active && data[1] > SECONDS(5))
|
|
|
|
{
|
|
|
|
data[1] = 0;
|
|
|
|
DestroyTask(data[2]);
|
|
|
|
data[3] = CreateTask(Task_Truck2, 0xA);
|
|
|
|
data[0] = 3;
|
|
|
|
PlaySE(SE_TRACK_STOP);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (!gTasks[data[3]].isActive) // is Truck2 no longer active (is Truck3 active?)
|
|
|
|
{
|
|
|
|
InstallCameraPanAheadCallback();
|
|
|
|
data[1] = 0;
|
|
|
|
data[0] = 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
data[1]++;
|
|
|
|
if (data[1] == 90)
|
|
|
|
{
|
2017-12-22 08:46:19 +01:00
|
|
|
PlaySE(SE_TRACK_HAIKI);
|
2017-09-23 04:45:47 +02:00
|
|
|
data[1] = 0;
|
|
|
|
data[0] = 5;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
data[1]++;
|
|
|
|
if (data[1] == 120)
|
|
|
|
{
|
2019-06-12 02:57:42 +02:00
|
|
|
MapGridSetMetatileIdAt(11, 8, METATILE_ID(InsideOfTruck, ExitLight_Top));
|
|
|
|
MapGridSetMetatileIdAt(11, 9, METATILE_ID(InsideOfTruck, ExitLight_Mid));
|
|
|
|
MapGridSetMetatileIdAt(11, 10, METATILE_ID(InsideOfTruck, ExitLight_Bottom));
|
2017-09-23 04:45:47 +02:00
|
|
|
DrawWholeMapView();
|
|
|
|
PlaySE(SE_TRACK_DOOR);
|
|
|
|
DestroyTask(taskId);
|
|
|
|
ScriptContext2_Disable();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExecuteTruckSequence(void)
|
|
|
|
{
|
2019-06-12 02:57:42 +02:00
|
|
|
MapGridSetMetatileIdAt(11, 8, METATILE_ID(InsideOfTruck, DoorClosedFloor_Top));
|
|
|
|
MapGridSetMetatileIdAt(11, 9, METATILE_ID(InsideOfTruck, DoorClosedFloor_Mid));
|
|
|
|
MapGridSetMetatileIdAt(11, 10, METATILE_ID(InsideOfTruck, DoorClosedFloor_Bottom));
|
2017-09-23 04:45:47 +02:00
|
|
|
DrawWholeMapView();
|
|
|
|
ScriptContext2_Enable();
|
|
|
|
CpuFastFill(0, gPlttBufferFaded, 0x400);
|
|
|
|
CreateTask(Task_HandleTruckSequence, 0xA);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndTruckSequence(u8 taskId)
|
|
|
|
{
|
|
|
|
if (!FuncIsActiveTask(Task_HandleTruckSequence))
|
|
|
|
{
|
|
|
|
sub_808E82C(1, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, 3, 3);
|
|
|
|
sub_808E82C(2, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, 0, -3);
|
|
|
|
sub_808E82C(3, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, -3, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 sub_80FB59C(void)
|
|
|
|
{
|
|
|
|
s8 mapGroup, mapNum;
|
|
|
|
s16 x, y;
|
|
|
|
|
|
|
|
if (GetSSTidalLocation(&mapGroup, &mapNum, &x, &y))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-27 23:30:47 +01:00
|
|
|
SetWarpDestination(mapGroup, mapNum, -1, x, y);
|
2017-09-23 04:45:47 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Task_HandlePorthole(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
2019-11-08 09:37:46 +01:00
|
|
|
u16 *cruiseState = GetVarPointer(VAR_SS_TIDAL_STATE);
|
2017-09-23 04:45:47 +02:00
|
|
|
struct WarpData *location = &gSaveBlock1Ptr->location;
|
|
|
|
|
|
|
|
switch (data[0])
|
|
|
|
{
|
|
|
|
case INIT_PORTHOLE: // finish fading before making porthole finish.
|
|
|
|
if (!gPaletteFade.active)
|
|
|
|
{
|
|
|
|
data[1] = 0;
|
|
|
|
data[0] = EXECUTE_MOVEMENT; // execute movement before checking if should be exited. strange?
|
|
|
|
}
|
|
|
|
break;
|
2019-11-08 09:37:46 +01:00
|
|
|
case IDLE_CHECK:
|
2017-09-23 04:45:47 +02:00
|
|
|
if (gMain.newKeys & A_BUTTON)
|
|
|
|
data[1] = 1;
|
2019-11-08 09:37:46 +01:00
|
|
|
if (!ScriptMovement_IsObjectMovementFinished(EVENT_OBJ_ID_PLAYER, location->mapNum, location->mapGroup))
|
2017-09-23 04:45:47 +02:00
|
|
|
return;
|
|
|
|
if (CountSSTidalStep(1) == TRUE)
|
|
|
|
{
|
2019-11-08 09:37:46 +01:00
|
|
|
if (*cruiseState == SS_TIDAL_DEPART_SLATEPORT)
|
|
|
|
*cruiseState = SS_TIDAL_EXIT_CURRENTS_RIGHT;
|
2017-09-23 04:45:47 +02:00
|
|
|
else
|
2019-11-08 09:37:46 +01:00
|
|
|
*cruiseState = SS_TIDAL_EXIT_CURRENTS_LEFT;
|
|
|
|
data[0] = EXIT_PORTHOLE;
|
2017-09-23 04:45:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-11-08 09:37:46 +01:00
|
|
|
data[0] = EXECUTE_MOVEMENT;
|
|
|
|
//fallthrough
|
|
|
|
case EXECUTE_MOVEMENT:
|
2017-09-23 04:45:47 +02:00
|
|
|
if (data[1])
|
|
|
|
{
|
2019-11-08 09:37:46 +01:00
|
|
|
data[0] = EXIT_PORTHOLE;
|
2017-09-23 04:45:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-11-08 09:37:46 +01:00
|
|
|
|
|
|
|
if (*cruiseState == SS_TIDAL_DEPART_SLATEPORT)
|
2017-09-23 04:45:47 +02:00
|
|
|
{
|
2019-11-08 09:37:46 +01:00
|
|
|
ScriptMovement_StartObjectMovementScript(EVENT_OBJ_ID_PLAYER, location->mapNum, location->mapGroup, sSSTidalSailEastMovementScript);
|
|
|
|
data[0] = IDLE_CHECK;
|
2017-09-23 04:45:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-08 09:37:46 +01:00
|
|
|
ScriptMovement_StartObjectMovementScript(EVENT_OBJ_ID_PLAYER, location->mapNum, location->mapGroup, sSSTidalSailWestMovementScript);
|
|
|
|
data[0] = IDLE_CHECK;
|
2017-09-23 04:45:47 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-11-08 09:37:46 +01:00
|
|
|
case EXIT_PORTHOLE:
|
2019-10-15 10:58:52 +02:00
|
|
|
FlagClear(FLAG_DONT_TRANSITION_MUSIC);
|
2019-03-10 13:10:59 +01:00
|
|
|
FlagClear(FLAG_HIDE_MAP_NAME_POPUP);
|
2018-12-27 23:30:47 +01:00
|
|
|
SetWarpDestinationToDynamicWarp(0);
|
2018-12-28 22:11:15 +01:00
|
|
|
DoDiveWarp();
|
2017-09-23 04:45:47 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 09:37:46 +01:00
|
|
|
static void ShowSSTidalWhileSailing(void)
|
2017-09-23 04:45:47 +02:00
|
|
|
{
|
2019-05-25 21:26:29 +02:00
|
|
|
u8 spriteId = AddPseudoEventObject(EVENT_OBJ_GFX_SS_TIDAL, SpriteCallbackDummy, 112, 80, 0);
|
2017-09-23 04:45:47 +02:00
|
|
|
|
|
|
|
gSprites[spriteId].coordOffsetEnabled = FALSE;
|
|
|
|
|
2019-11-08 09:37:46 +01:00
|
|
|
if (VarGet(VAR_SS_TIDAL_STATE) == SS_TIDAL_DEPART_SLATEPORT)
|
|
|
|
StartSpriteAnim(&gSprites[spriteId], GetFaceDirectionAnimNum(DIR_EAST));
|
2017-09-23 04:45:47 +02:00
|
|
|
else
|
2019-11-08 09:37:46 +01:00
|
|
|
StartSpriteAnim(&gSprites[spriteId], GetFaceDirectionAnimNum(DIR_WEST));
|
2017-09-23 04:45:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sub_80FB768(void)
|
|
|
|
{
|
2019-11-08 09:37:46 +01:00
|
|
|
ShowSSTidalWhileSailing();
|
2018-06-12 02:11:48 +02:00
|
|
|
gEventObjects[gPlayerAvatar.eventObjectId].invisible = TRUE;
|
2017-09-23 04:45:47 +02:00
|
|
|
pal_fill_black();
|
|
|
|
CreateTask(Task_HandlePorthole, 80);
|
|
|
|
ScriptContext2_Enable();
|
|
|
|
}
|
|
|
|
|
2019-11-08 09:37:46 +01:00
|
|
|
void LookThroughPorthole(void)
|
2017-09-23 04:45:47 +02:00
|
|
|
{
|
2017-11-08 22:20:10 +01:00
|
|
|
FlagSet(FLAG_SYS_CRUISE_MODE);
|
2019-10-15 10:58:52 +02:00
|
|
|
FlagSet(FLAG_DONT_TRANSITION_MUSIC);
|
2019-03-10 13:10:59 +01:00
|
|
|
FlagSet(FLAG_HIDE_MAP_NAME_POPUP);
|
2018-12-27 23:30:47 +01:00
|
|
|
SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
|
2017-09-23 04:45:47 +02:00
|
|
|
sub_80FB59C();
|
|
|
|
sub_80AF8B8();
|
|
|
|
}
|