2017-09-09 15:45:50 +02:00
|
|
|
#include "global.h"
|
2018-12-03 17:31:34 +01:00
|
|
|
#include "battle.h"
|
2017-09-09 15:45:50 +02:00
|
|
|
#include "event_data.h"
|
2018-12-03 17:31:34 +01:00
|
|
|
#include "field_player_avatar.h"
|
|
|
|
#include "overworld.h"
|
2017-09-09 15:45:50 +02:00
|
|
|
#include "main.h"
|
2017-12-11 16:52:28 +01:00
|
|
|
#include "pokeblock.h"
|
2018-12-03 17:31:34 +01:00
|
|
|
#include "safari_zone.h"
|
|
|
|
#include "script.h"
|
|
|
|
#include "string_util.h"
|
|
|
|
#include "tv.h"
|
|
|
|
#include "constants/game_stat.h"
|
2019-03-02 04:32:50 +01:00
|
|
|
#include "field_screen_effect.h"
|
2017-09-09 15:45:50 +02:00
|
|
|
|
|
|
|
struct PokeblockFeeder
|
|
|
|
{
|
|
|
|
/*0x00*/ s16 x;
|
|
|
|
/*0x02*/ s16 y;
|
|
|
|
/*0x04*/ s8 mapNum;
|
|
|
|
/*0x05*/ u8 stepCounter;
|
|
|
|
/*0x08*/ struct Pokeblock pokeblock;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_POKEBLOCK_FEEDERS 10
|
|
|
|
|
2019-10-20 09:46:05 +02:00
|
|
|
extern const u8 SafariZone_EventScript_TimesUp[];
|
|
|
|
extern const u8 SafariZone_EventScript_RetirePrompt[];
|
|
|
|
extern const u8 SafariZone_EventScript_OutOfBallsMidBattle[];
|
|
|
|
extern const u8 SafariZone_EventScript_OutOfBalls[];
|
2017-09-09 15:45:50 +02:00
|
|
|
|
|
|
|
EWRAM_DATA u8 gNumSafariBalls = 0;
|
|
|
|
EWRAM_DATA static u16 sSafariZoneStepCounter = 0;
|
|
|
|
EWRAM_DATA static u8 sSafariZoneCaughtMons = 0;
|
2018-06-28 21:06:32 +02:00
|
|
|
EWRAM_DATA static u8 sSafariZonePkblkUses = 0;
|
2017-09-09 15:45:50 +02:00
|
|
|
EWRAM_DATA static struct PokeblockFeeder sPokeblockFeeders[NUM_POKEBLOCK_FEEDERS] = {0};
|
|
|
|
|
|
|
|
static void ClearAllPokeblockFeeders(void);
|
|
|
|
static void DecrementFeederStepCounters(void);
|
|
|
|
|
|
|
|
bool32 GetSafariZoneFlag(void)
|
|
|
|
{
|
2017-11-08 22:20:10 +01:00
|
|
|
return FlagGet(FLAG_SYS_SAFARI_MODE);
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetSafariZoneFlag(void)
|
|
|
|
{
|
2017-11-08 22:20:10 +01:00
|
|
|
FlagSet(FLAG_SYS_SAFARI_MODE);
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResetSafariZoneFlag(void)
|
|
|
|
{
|
2017-11-08 22:20:10 +01:00
|
|
|
FlagClear(FLAG_SYS_SAFARI_MODE);
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EnterSafariMode(void)
|
|
|
|
{
|
|
|
|
IncrementGameStat(GAME_STAT_ENTERED_SAFARI_ZONE);
|
|
|
|
SetSafariZoneFlag();
|
|
|
|
ClearAllPokeblockFeeders();
|
|
|
|
gNumSafariBalls = 30;
|
|
|
|
sSafariZoneStepCounter = 500;
|
|
|
|
sSafariZoneCaughtMons = 0;
|
2018-06-28 21:06:32 +02:00
|
|
|
sSafariZonePkblkUses = 0;
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExitSafariMode(void)
|
|
|
|
{
|
2021-04-25 23:22:45 +02:00
|
|
|
TryPutSafariFanClubOnAir(sSafariZoneCaughtMons, sSafariZonePkblkUses);
|
2017-09-09 15:45:50 +02:00
|
|
|
ResetSafariZoneFlag();
|
|
|
|
ClearAllPokeblockFeeders();
|
|
|
|
gNumSafariBalls = 0;
|
|
|
|
sSafariZoneStepCounter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool8 SafariZoneTakeStep(void)
|
|
|
|
{
|
|
|
|
if (GetSafariZoneFlag() == FALSE)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DecrementFeederStepCounters();
|
|
|
|
sSafariZoneStepCounter--;
|
|
|
|
if (sSafariZoneStepCounter == 0)
|
|
|
|
{
|
2022-08-15 21:18:12 +02:00
|
|
|
ScriptContext_SetupScript(SafariZone_EventScript_TimesUp);
|
2017-09-09 15:45:50 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SafariZoneRetirePrompt(void)
|
|
|
|
{
|
2022-08-15 21:18:12 +02:00
|
|
|
ScriptContext_SetupScript(SafariZone_EventScript_RetirePrompt);
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
2017-11-28 23:02:09 +01:00
|
|
|
void CB2_EndSafariBattle(void)
|
2017-09-09 15:45:50 +02:00
|
|
|
{
|
2018-06-28 21:06:32 +02:00
|
|
|
sSafariZonePkblkUses += gBattleResults.pokeblockThrows;
|
2018-02-08 00:35:13 +01:00
|
|
|
if (gBattleOutcome == B_OUTCOME_CAUGHT)
|
2017-09-09 15:45:50 +02:00
|
|
|
sSafariZoneCaughtMons++;
|
|
|
|
if (gNumSafariBalls != 0)
|
|
|
|
{
|
2018-02-14 00:58:22 +01:00
|
|
|
SetMainCallback2(CB2_ReturnToField);
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
2018-01-16 22:12:38 +01:00
|
|
|
else if (gBattleOutcome == B_OUTCOME_NO_SAFARI_BALLS)
|
2017-09-09 15:45:50 +02:00
|
|
|
{
|
2022-08-15 21:18:12 +02:00
|
|
|
RunScriptImmediately(SafariZone_EventScript_OutOfBallsMidBattle);
|
2018-09-05 00:31:37 +02:00
|
|
|
WarpIntoMap();
|
2021-01-01 23:02:03 +01:00
|
|
|
gFieldCallback = FieldCB_ReturnToFieldNoScriptCheckMusic;
|
2018-02-14 00:58:22 +01:00
|
|
|
SetMainCallback2(CB2_LoadMap);
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
2018-02-08 00:35:13 +01:00
|
|
|
else if (gBattleOutcome == B_OUTCOME_CAUGHT)
|
2017-09-09 15:45:50 +02:00
|
|
|
{
|
2022-08-15 21:18:12 +02:00
|
|
|
ScriptContext_SetupScript(SafariZone_EventScript_OutOfBalls);
|
|
|
|
ScriptContext_Stop();
|
2018-07-25 06:18:23 +02:00
|
|
|
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClearPokeblockFeeder(u8 index)
|
|
|
|
{
|
|
|
|
memset(&sPokeblockFeeders[index], 0, sizeof(struct PokeblockFeeder));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClearAllPokeblockFeeders(void)
|
|
|
|
{
|
|
|
|
memset(sPokeblockFeeders, 0, sizeof(sPokeblockFeeders));
|
|
|
|
}
|
|
|
|
|
2017-10-14 20:26:25 +02:00
|
|
|
void GetPokeblockFeederInFront(void)
|
2017-09-09 15:45:50 +02:00
|
|
|
{
|
|
|
|
s16 x, y;
|
|
|
|
u16 i;
|
|
|
|
|
|
|
|
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_POKEBLOCK_FEEDERS; i++)
|
|
|
|
{
|
|
|
|
if (gSaveBlock1Ptr->location.mapNum == sPokeblockFeeders[i].mapNum
|
|
|
|
&& sPokeblockFeeders[i].x == x
|
|
|
|
&& sPokeblockFeeders[i].y == y)
|
|
|
|
{
|
2017-11-11 01:12:18 +01:00
|
|
|
gSpecialVar_Result = i;
|
2017-09-09 15:45:50 +02:00
|
|
|
StringCopy(gStringVar1, gPokeblockNames[sPokeblockFeeders[i].pokeblock.color]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 01:12:18 +01:00
|
|
|
gSpecialVar_Result = -1;
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetPokeblockFeederWithinRange(void)
|
|
|
|
{
|
|
|
|
s16 x, y;
|
|
|
|
u16 i;
|
|
|
|
|
|
|
|
PlayerGetDestCoords(&x, &y);
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_POKEBLOCK_FEEDERS; i++)
|
|
|
|
{
|
|
|
|
if (gSaveBlock1Ptr->location.mapNum == sPokeblockFeeders[i].mapNum)
|
|
|
|
{
|
2018-06-28 21:06:32 +02:00
|
|
|
// Get absolute value of x and y distance from Pokeblock feeder on current map.
|
2017-09-09 15:45:50 +02:00
|
|
|
x -= sPokeblockFeeders[i].x;
|
|
|
|
y -= sPokeblockFeeders[i].y;
|
|
|
|
if (x < 0)
|
|
|
|
x *= -1;
|
|
|
|
if (y < 0)
|
|
|
|
y *= -1;
|
|
|
|
if ((x + y) <= 5)
|
|
|
|
{
|
2017-11-11 01:12:18 +01:00
|
|
|
gSpecialVar_Result = i;
|
2017-09-09 15:45:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 01:12:18 +01:00
|
|
|
gSpecialVar_Result = -1;
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// unused
|
|
|
|
struct Pokeblock *SafariZoneGetPokeblockInFront(void)
|
|
|
|
{
|
|
|
|
GetPokeblockFeederInFront();
|
|
|
|
|
2017-11-11 01:12:18 +01:00
|
|
|
if (gSpecialVar_Result == 0xFFFF)
|
2017-09-09 15:45:50 +02:00
|
|
|
return NULL;
|
|
|
|
else
|
2017-11-11 01:12:18 +01:00
|
|
|
return &sPokeblockFeeders[gSpecialVar_Result].pokeblock;
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Pokeblock *SafariZoneGetActivePokeblock(void)
|
|
|
|
{
|
|
|
|
GetPokeblockFeederWithinRange();
|
|
|
|
|
2017-11-11 01:12:18 +01:00
|
|
|
if (gSpecialVar_Result == 0xFFFF)
|
2017-09-09 15:45:50 +02:00
|
|
|
return NULL;
|
|
|
|
else
|
2017-11-11 01:12:18 +01:00
|
|
|
return &sPokeblockFeeders[gSpecialVar_Result].pokeblock;
|
2017-09-09 15:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SafariZoneActivatePokeblockFeeder(u8 pkblId)
|
|
|
|
{
|
|
|
|
s16 x, y;
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_POKEBLOCK_FEEDERS; i++)
|
|
|
|
{
|
|
|
|
// Find free entry in sPokeblockFeeders
|
|
|
|
if (sPokeblockFeeders[i].mapNum == 0
|
|
|
|
&& sPokeblockFeeders[i].x == 0
|
|
|
|
&& sPokeblockFeeders[i].y == 0)
|
|
|
|
{
|
|
|
|
// Initialize Pokeblock feeder
|
|
|
|
GetXYCoordsOneStepInFrontOfPlayer(&x, &y);
|
|
|
|
sPokeblockFeeders[i].mapNum = gSaveBlock1Ptr->location.mapNum;
|
|
|
|
sPokeblockFeeders[i].pokeblock = gSaveBlock1Ptr->pokeblocks[pkblId];
|
|
|
|
sPokeblockFeeders[i].stepCounter = 100;
|
|
|
|
sPokeblockFeeders[i].x = x;
|
|
|
|
sPokeblockFeeders[i].y = y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DecrementFeederStepCounters(void)
|
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_POKEBLOCK_FEEDERS; i++)
|
|
|
|
{
|
|
|
|
if (sPokeblockFeeders[i].stepCounter != 0)
|
|
|
|
{
|
|
|
|
sPokeblockFeeders[i].stepCounter--;
|
|
|
|
if (sPokeblockFeeders[i].stepCounter == 0)
|
|
|
|
ClearPokeblockFeeder(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// unused
|
|
|
|
bool8 GetInFrontFeederPokeblockAndSteps(void)
|
|
|
|
{
|
|
|
|
GetPokeblockFeederInFront();
|
|
|
|
|
2017-11-11 01:12:18 +01:00
|
|
|
if (gSpecialVar_Result == 0xFFFF)
|
2017-09-09 15:45:50 +02:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConvertIntToDecimalStringN(gStringVar2,
|
2017-11-11 01:12:18 +01:00
|
|
|
sPokeblockFeeders[gSpecialVar_Result].stepCounter,
|
2017-09-09 15:45:50 +02:00
|
|
|
STR_CONV_MODE_LEADING_ZEROS, 3);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|