2018-06-17 12:30:09 +02:00
|
|
|
#include "global.h"
|
2018-09-10 01:01:39 +02:00
|
|
|
#include "battle_tent.h"
|
2018-06-17 12:30:09 +02:00
|
|
|
#include "overworld.h"
|
|
|
|
#include "event_data.h"
|
|
|
|
#include "region_map.h"
|
|
|
|
#include "battle.h"
|
|
|
|
#include "battle_setup.h"
|
|
|
|
#include "battle_tower.h"
|
|
|
|
#include "random.h"
|
|
|
|
#include "item.h"
|
2018-11-11 16:44:27 +01:00
|
|
|
#include "battle_factory_screen.h"
|
2018-10-30 22:17:03 +01:00
|
|
|
#include "frontier_util.h"
|
2018-11-19 17:36:39 +01:00
|
|
|
#include "string_util.h"
|
2019-12-02 20:49:22 +01:00
|
|
|
#include "constants/battle_tent.h"
|
2020-01-08 07:07:53 +01:00
|
|
|
#include "constants/battle_tent_trainers.h"
|
|
|
|
#include "constants/battle_tent_mons.h"
|
2018-06-17 12:30:09 +02:00
|
|
|
#include "constants/items.h"
|
2019-01-31 22:51:20 +01:00
|
|
|
#include "constants/layouts.h"
|
2018-06-30 14:22:09 +02:00
|
|
|
#include "constants/region_map_sections.h"
|
2019-11-29 03:09:35 +01:00
|
|
|
#include "constants/trainers.h"
|
2018-06-17 12:30:09 +02:00
|
|
|
|
2018-08-25 18:46:15 +02:00
|
|
|
// This file's functions.
|
2019-11-29 03:09:35 +01:00
|
|
|
static void InitVerdanturfTentChallenge(void);
|
|
|
|
static void GetVerdanturfTentPrize(void);
|
|
|
|
static void SetVerdanturfTentPrize(void);
|
|
|
|
static void SetVerdanturfTentTrainerGfx(void);
|
|
|
|
static void BufferVerdanturfTentTrainerIntro(void);
|
|
|
|
static void SaveVerdanturfTentChallenge(void);
|
|
|
|
static void SetRandomVerdanturfTentPrize(void);
|
|
|
|
static void GiveVerdanturfTentPrize(void);
|
|
|
|
static void InitFallarborTentChallenge(void);
|
|
|
|
static void GetFallarborTentPrize(void);
|
|
|
|
static void SetFallarborTentPrize(void);
|
|
|
|
static void SaveFallarborTentChallenge(void);
|
|
|
|
static void SetRandomFallarborTentPrize(void);
|
|
|
|
static void GiveFallarborTentPrize(void);
|
|
|
|
static void BufferFallarborTentTrainerName(void);
|
|
|
|
static void InitSlateportTentChallenge(void);
|
|
|
|
static void GetSlateportTentPrize(void);
|
|
|
|
static void SetSlateportTentPrize(void);
|
|
|
|
static void SaveSlateportTentChallenge(void);
|
|
|
|
static void SetRandomSlateportTentPrize(void);
|
|
|
|
static void GiveSlateportTentPrize(void);
|
|
|
|
static void SelectInitialRentalMons(void);
|
|
|
|
static void SwapRentalMons(void);
|
2019-12-02 20:49:22 +01:00
|
|
|
static void GenerateOpponentMons(void);
|
|
|
|
static void GenerateInitialRentalMons(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Battle Tents are mini versions of particular Battle Frontier facilities
|
|
|
|
* As such they each share some scripts and functions with their counterpart
|
|
|
|
*
|
|
|
|
* Verdanturf Battle Tent: Battle Palace
|
|
|
|
* Fallarbor Battle Tent: Battle Arena
|
|
|
|
* Slateport Battle Tent: Battle Factory
|
|
|
|
*
|
|
|
|
*/
|
2018-09-10 01:01:39 +02:00
|
|
|
|
|
|
|
// IWRAM bss
|
2019-06-26 22:23:00 +02:00
|
|
|
static u16 sRandMonSetId;
|
2018-06-17 12:30:09 +02:00
|
|
|
|
|
|
|
// const rom data
|
2019-11-24 22:58:40 +01:00
|
|
|
void static (*const sVerdanturfTentFuncs[])(void) =
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-12-02 20:49:22 +01:00
|
|
|
[VERDANTURF_TENT_FUNC_INIT] = InitVerdanturfTentChallenge,
|
|
|
|
[VERDANTURF_TENT_FUNC_GET_PRIZE] = GetVerdanturfTentPrize,
|
|
|
|
[VERDANTURF_TENT_FUNC_SET_PRIZE] = SetVerdanturfTentPrize,
|
|
|
|
[VERDANTURF_TENT_FUNC_SET_OPPONENT_GFX] = SetVerdanturfTentTrainerGfx,
|
|
|
|
[VERDANTURF_TENT_FUNC_GET_OPPONENT_INTRO] = BufferVerdanturfTentTrainerIntro,
|
|
|
|
[VERDANTURF_TENT_FUNC_SAVE] = SaveVerdanturfTentChallenge,
|
|
|
|
[VERDANTURF_TENT_FUNC_SET_RANDOM_PRIZE] = SetRandomVerdanturfTentPrize,
|
|
|
|
[VERDANTURF_TENT_FUNC_GIVE_PRIZE] = GiveVerdanturfTentPrize
|
2018-06-17 12:30:09 +02:00
|
|
|
};
|
|
|
|
|
2018-08-26 15:27:06 +02:00
|
|
|
static const u16 sVerdanturfTentRewards[] = {ITEM_NEST_BALL};
|
2018-06-17 12:30:09 +02:00
|
|
|
|
2019-11-24 22:58:40 +01:00
|
|
|
void static (*const sFallarborTentFuncs[])(void) =
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-12-02 20:49:22 +01:00
|
|
|
[FALLARBOR_TENT_FUNC_INIT] = InitFallarborTentChallenge,
|
|
|
|
[FALLARBOR_TENT_FUNC_GET_PRIZE] = GetFallarborTentPrize,
|
|
|
|
[FALLARBOR_TENT_FUNC_SET_PRIZE] = SetFallarborTentPrize,
|
|
|
|
[FALLARBOR_TENT_FUNC_SAVE] = SaveFallarborTentChallenge,
|
|
|
|
[FALLARBOR_TENT_FUNC_SET_RANDOM_PRIZE] = SetRandomFallarborTentPrize,
|
|
|
|
[FALLARBOR_TENT_FUNC_GIVE_PRIZE] = GiveFallarborTentPrize,
|
|
|
|
[FALLARBOR_TENT_FUNC_GET_OPPONENT_NAME] = BufferFallarborTentTrainerName
|
2018-06-17 12:30:09 +02:00
|
|
|
};
|
|
|
|
|
2018-08-26 15:27:06 +02:00
|
|
|
static const u16 sFallarborTentRewards[] = {ITEM_HYPER_POTION};
|
2018-06-17 12:30:09 +02:00
|
|
|
|
2019-11-24 22:58:40 +01:00
|
|
|
void static (*const sSlateportTentFuncs[])(void) =
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-12-02 20:49:22 +01:00
|
|
|
[SLATEPORT_TENT_FUNC_INIT] = InitSlateportTentChallenge,
|
|
|
|
[SLATEPORT_TENT_FUNC_GET_PRIZE] = GetSlateportTentPrize,
|
|
|
|
[SLATEPORT_TENT_FUNC_SET_PRIZE] = SetSlateportTentPrize,
|
|
|
|
[SLATEPORT_TENT_FUNC_SAVE] = SaveSlateportTentChallenge,
|
|
|
|
[SLATEPORT_TENT_FUNC_SET_RANDOM_PRIZE] = SetRandomSlateportTentPrize,
|
|
|
|
[SLATEPORT_TENT_FUNC_GIVE_PRIZE] = GiveSlateportTentPrize,
|
|
|
|
[SLATEPORT_TENT_FUNC_SELECT_RENT_MONS] = SelectInitialRentalMons,
|
|
|
|
[SLATEPORT_TENT_FUNC_SWAP_RENT_MONS] = SwapRentalMons,
|
|
|
|
[SLATEPORT_TENT_FUNC_GENERATE_OPPONENT_MONS] = GenerateOpponentMons,
|
|
|
|
[SLATEPORT_TENT_FUNC_GENERATE_RENTAL_MONS] = GenerateInitialRentalMons
|
2018-06-17 12:30:09 +02:00
|
|
|
};
|
|
|
|
|
2018-08-26 15:27:06 +02:00
|
|
|
static const u16 sSlateportTentRewards[] = {ITEM_FULL_HEAL};
|
2018-06-17 12:30:09 +02:00
|
|
|
|
|
|
|
// code
|
2019-11-24 22:58:40 +01:00
|
|
|
void CallVerdanturfTentFunction(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
sVerdanturfTentFuncs[gSpecialVar_0x8004]();
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void InitVerdanturfTentChallenge(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengeStatus = 0;
|
2018-10-21 00:06:42 +02:00
|
|
|
gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengePaused = FALSE;
|
2018-12-27 23:30:47 +01:00
|
|
|
SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void GetVerdanturfTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSpecialVar_Result = gSaveBlock2Ptr->frontier.verdanturfTentPrize;
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SetVerdanturfTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSaveBlock2Ptr->frontier.verdanturfTentPrize = gSpecialVar_0x8006;
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SetVerdanturfTentTrainerGfx(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
|
|
|
gTrainerBattleOpponent_A = (u32)((Random() % 255) * 5) / 64;
|
2018-10-21 00:06:42 +02:00
|
|
|
SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0);
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void BufferVerdanturfTentTrainerIntro(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-12-21 00:52:29 +01:00
|
|
|
if (gTrainerBattleOpponent_A < FRONTIER_TRAINERS_COUNT)
|
2018-10-21 20:13:12 +02:00
|
|
|
FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore);
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SaveVerdanturfTentChallenge(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
|
2018-06-17 12:30:09 +02:00
|
|
|
VarSet(VAR_TEMP_0, 0);
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengePaused = TRUE;
|
|
|
|
SaveGameFrontier();
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SetRandomVerdanturfTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSaveBlock2Ptr->frontier.verdanturfTentPrize = sVerdanturfTentRewards[Random() % ARRAY_COUNT(sVerdanturfTentRewards)];
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void GiveVerdanturfTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
if (AddBagItem(gSaveBlock2Ptr->frontier.verdanturfTentPrize, 1) == TRUE)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
CopyItemName(gSaveBlock2Ptr->frontier.verdanturfTentPrize, gStringVar1);
|
|
|
|
gSaveBlock2Ptr->frontier.verdanturfTentPrize = ITEM_NONE;
|
2018-06-17 12:30:09 +02:00
|
|
|
gSpecialVar_Result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gSpecialVar_Result = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-24 22:58:40 +01:00
|
|
|
void CallFallarborTentFunction(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
sFallarborTentFuncs[gSpecialVar_0x8004]();
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void InitFallarborTentChallenge(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengeStatus = 0;
|
2018-10-21 00:06:42 +02:00
|
|
|
gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengePaused = FALSE;
|
2018-12-27 23:30:47 +01:00
|
|
|
SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void GetFallarborTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSpecialVar_Result = gSaveBlock2Ptr->frontier.fallarborTentPrize;
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SetFallarborTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSaveBlock2Ptr->frontier.fallarborTentPrize = gSpecialVar_0x8006;
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SaveFallarborTentChallenge(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
|
2018-06-17 12:30:09 +02:00
|
|
|
VarSet(VAR_TEMP_0, 0);
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengePaused = TRUE;
|
|
|
|
SaveGameFrontier();
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SetRandomFallarborTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSaveBlock2Ptr->frontier.fallarborTentPrize = sFallarborTentRewards[Random() % ARRAY_COUNT(sFallarborTentRewards)];
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void GiveFallarborTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
if (AddBagItem(gSaveBlock2Ptr->frontier.fallarborTentPrize, 1) == TRUE)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
CopyItemName(gSaveBlock2Ptr->frontier.fallarborTentPrize, gStringVar1);
|
|
|
|
gSaveBlock2Ptr->frontier.fallarborTentPrize = ITEM_NONE;
|
2018-06-17 12:30:09 +02:00
|
|
|
gSpecialVar_Result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gSpecialVar_Result = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void BufferFallarborTentTrainerName(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
|
|
|
GetFrontierTrainerName(gStringVar1, gTrainerBattleOpponent_A);
|
|
|
|
}
|
|
|
|
|
2019-11-24 22:58:40 +01:00
|
|
|
void CallSlateportTentFunction(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
sSlateportTentFuncs[gSpecialVar_0x8004]();
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void InitSlateportTentChallenge(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengeStatus = 0;
|
2018-10-21 00:06:42 +02:00
|
|
|
gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0;
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengePaused = FALSE;
|
2018-12-27 23:30:47 +01:00
|
|
|
SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1);
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void GetSlateportTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSpecialVar_Result = gSaveBlock2Ptr->frontier.slateportTentPrize;
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SetSlateportTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSaveBlock2Ptr->frontier.slateportTentPrize = gSpecialVar_0x8006;
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SaveSlateportTentChallenge(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengeStatus = gSpecialVar_0x8005;
|
2018-06-17 12:30:09 +02:00
|
|
|
VarSet(VAR_TEMP_0, 0);
|
2019-11-24 22:58:40 +01:00
|
|
|
gSaveBlock2Ptr->frontier.challengePaused = TRUE;
|
|
|
|
SaveGameFrontier();
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SetRandomSlateportTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
gSaveBlock2Ptr->frontier.slateportTentPrize = sSlateportTentRewards[Random() % ARRAY_COUNT(sSlateportTentRewards)];
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void GiveSlateportTentPrize(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
if (AddBagItem(gSaveBlock2Ptr->frontier.slateportTentPrize, 1) == TRUE)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-11-29 03:09:35 +01:00
|
|
|
CopyItemName(gSaveBlock2Ptr->frontier.slateportTentPrize, gStringVar1);
|
|
|
|
gSaveBlock2Ptr->frontier.slateportTentPrize = ITEM_NONE;
|
2018-06-17 12:30:09 +02:00
|
|
|
gSpecialVar_Result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gSpecialVar_Result = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SelectInitialRentalMons(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
|
|
|
ZeroPlayerPartyMons();
|
2018-09-10 01:01:39 +02:00
|
|
|
DoBattleFactorySelectScreen();
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 03:09:35 +01:00
|
|
|
static void SwapRentalMons(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2018-09-10 01:01:39 +02:00
|
|
|
DoBattleFactorySwapScreen();
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
|
|
|
|
2019-03-03 22:50:51 +01:00
|
|
|
bool8 InSlateportBattleTent(void)
|
2018-06-17 12:30:09 +02:00
|
|
|
{
|
2019-01-31 22:51:20 +01:00
|
|
|
return gMapHeader.regionMapSectionId == MAPSEC_SLATEPORT_CITY
|
|
|
|
&& (gMapHeader.mapLayoutId == LAYOUT_BATTLE_TENT_CORRIDOR || gMapHeader.mapLayoutId == LAYOUT_BATTLE_TENT_BATTLE_ROOM);
|
2018-06-17 12:30:09 +02:00
|
|
|
}
|
2018-08-26 15:27:06 +02:00
|
|
|
|
2019-12-02 20:49:22 +01:00
|
|
|
static void GenerateInitialRentalMons(void)
|
2018-08-26 15:27:06 +02:00
|
|
|
{
|
|
|
|
s32 i, j;
|
2018-11-11 16:44:27 +01:00
|
|
|
u8 firstMonId;
|
|
|
|
u16 monSetId;
|
|
|
|
u16 currSpecies;
|
2018-08-26 15:27:06 +02:00
|
|
|
u16 species[PARTY_SIZE];
|
|
|
|
u16 monIds[PARTY_SIZE];
|
|
|
|
u16 heldItems[PARTY_SIZE];
|
|
|
|
|
2018-11-11 16:44:27 +01:00
|
|
|
firstMonId = 0;
|
2018-08-26 15:27:06 +02:00
|
|
|
gFacilityTrainers = gSlateportBattleTentTrainers;
|
|
|
|
for (i = 0; i < PARTY_SIZE; i++)
|
|
|
|
{
|
|
|
|
species[i] = 0;
|
|
|
|
monIds[i] = 0;
|
|
|
|
heldItems[i] = 0;
|
|
|
|
}
|
|
|
|
gFacilityTrainerMons = gSlateportBattleTentMons;
|
2018-12-18 15:35:31 +01:00
|
|
|
currSpecies = SPECIES_NONE;
|
2018-11-11 16:44:27 +01:00
|
|
|
i = 0;
|
|
|
|
while (i != PARTY_SIZE)
|
2018-08-26 15:27:06 +02:00
|
|
|
{
|
|
|
|
// Cannot have two pokemon of the same species.
|
2020-01-08 07:07:53 +01:00
|
|
|
monSetId = Random() % NUM_SLATEPORT_TENT_MONS;
|
2018-11-11 16:44:27 +01:00
|
|
|
for (j = firstMonId; j < firstMonId + i; j++)
|
2018-08-26 15:27:06 +02:00
|
|
|
{
|
2018-11-11 16:44:27 +01:00
|
|
|
u16 monId = monIds[j];
|
|
|
|
if (monIds[j] == monSetId)
|
2018-08-29 20:38:54 +02:00
|
|
|
break;
|
2018-11-11 16:44:27 +01:00
|
|
|
if (species[j] == gFacilityTrainerMons[monSetId].species)
|
2018-08-26 15:27:06 +02:00
|
|
|
{
|
2018-12-18 15:35:31 +01:00
|
|
|
if (currSpecies == SPECIES_NONE)
|
2018-11-11 16:44:27 +01:00
|
|
|
currSpecies = gFacilityTrainerMons[monSetId].species;
|
2018-08-26 15:27:06 +02:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-11-11 16:44:27 +01:00
|
|
|
if (j != i + firstMonId)
|
2018-08-26 15:27:06 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Cannot have two same held items.
|
2018-11-11 16:44:27 +01:00
|
|
|
for (j = firstMonId; j < i + firstMonId; j++)
|
2018-08-26 15:27:06 +02:00
|
|
|
{
|
2018-11-11 16:44:27 +01:00
|
|
|
if (heldItems[j] != 0 && heldItems[j] == gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId])
|
2018-08-26 15:27:06 +02:00
|
|
|
{
|
2018-11-11 16:44:27 +01:00
|
|
|
if (gFacilityTrainerMons[monSetId].species == currSpecies)
|
2018-12-18 15:35:31 +01:00
|
|
|
currSpecies = SPECIES_NONE;
|
2018-11-11 16:44:27 +01:00
|
|
|
break;
|
2018-08-26 15:27:06 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-11 16:44:27 +01:00
|
|
|
if (j != i + firstMonId)
|
2018-08-26 15:27:06 +02:00
|
|
|
continue;
|
|
|
|
|
2019-02-07 19:58:09 +01:00
|
|
|
gSaveBlock2Ptr->frontier.rentalMons[i].monId = monSetId;
|
2018-11-11 16:44:27 +01:00
|
|
|
species[i] = gFacilityTrainerMons[monSetId].species;
|
|
|
|
heldItems[i] = gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId];
|
|
|
|
monIds[i] = monSetId;
|
2018-08-26 15:27:06 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2018-09-10 01:01:39 +02:00
|
|
|
|
2019-12-02 20:49:22 +01:00
|
|
|
static void GenerateOpponentMons(void)
|
2018-09-10 01:01:39 +02:00
|
|
|
{
|
|
|
|
u16 trainerId;
|
|
|
|
s32 i, j, k;
|
2020-08-18 14:11:25 +02:00
|
|
|
#ifndef NONMATCHING
|
|
|
|
register const u16 *monSet asm("r9"); // Fix me. Compiler insists on moving that variable into stack.
|
|
|
|
#else
|
|
|
|
const u16 *monSet;
|
|
|
|
#endif
|
2019-12-02 20:49:22 +01:00
|
|
|
u16 species[FRONTIER_PARTY_SIZE];
|
|
|
|
u16 heldItems[FRONTIER_PARTY_SIZE];
|
2020-01-05 16:50:32 +01:00
|
|
|
s32 monId = 0;
|
2018-09-10 01:01:39 +02:00
|
|
|
|
|
|
|
gFacilityTrainers = gSlateportBattleTentTrainers;
|
|
|
|
gFacilityTrainerMons = gSlateportBattleTentMons;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2020-01-08 07:07:53 +01:00
|
|
|
trainerId = Random() % NUM_BATTLE_TENT_TRAINERS;
|
2018-10-21 00:06:42 +02:00
|
|
|
for (i = 0; i < gSaveBlock2Ptr->frontier.curChallengeBattleNum; i++)
|
2018-09-10 01:01:39 +02:00
|
|
|
{
|
2019-02-07 18:37:28 +01:00
|
|
|
if (gSaveBlock2Ptr->frontier.trainerIds[i] == trainerId)
|
2018-09-10 01:01:39 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-10-21 00:06:42 +02:00
|
|
|
} while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum);
|
2018-09-10 01:01:39 +02:00
|
|
|
|
|
|
|
gTrainerBattleOpponent_A = trainerId;
|
2020-01-05 16:50:32 +01:00
|
|
|
while (gFacilityTrainers[gTrainerBattleOpponent_A].monSet[monId] != 0xFFFF)
|
|
|
|
monId++;
|
|
|
|
if (monId > 8)
|
2018-09-10 01:01:39 +02:00
|
|
|
break;
|
2020-01-05 16:50:32 +01:00
|
|
|
monId = 0;
|
2018-09-10 01:01:39 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 00:06:42 +02:00
|
|
|
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < 2)
|
2019-02-07 18:37:28 +01:00
|
|
|
gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A;
|
2018-09-10 01:01:39 +02:00
|
|
|
|
2020-01-05 16:50:32 +01:00
|
|
|
monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet;
|
2018-09-10 01:01:39 +02:00
|
|
|
i = 0;
|
2019-12-02 20:49:22 +01:00
|
|
|
while (i != FRONTIER_PARTY_SIZE)
|
2018-09-10 01:01:39 +02:00
|
|
|
{
|
2020-01-05 16:50:32 +01:00
|
|
|
sRandMonSetId = monSet[Random() % monId];
|
2018-09-10 01:01:39 +02:00
|
|
|
for (j = 0; j < 6; j++)
|
|
|
|
{
|
2019-02-07 19:58:09 +01:00
|
|
|
if (gFacilityTrainerMons[sRandMonSetId].species == gFacilityTrainerMons[gSaveBlock2Ptr->frontier.rentalMons[j].monId].species)
|
2018-09-10 01:01:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j != 6)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (k = 0; k < i; k++)
|
|
|
|
{
|
|
|
|
if (species[k] == gFacilityTrainerMons[sRandMonSetId].species)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (k != i)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (k = 0; k < i; k++)
|
|
|
|
{
|
|
|
|
if (heldItems[k] != 0 && heldItems[k] == gBattleFrontierHeldItems[gFacilityTrainerMons[sRandMonSetId].itemTableId])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (k != i)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
species[i] = gFacilityTrainerMons[sRandMonSetId].species;
|
|
|
|
heldItems[i] = gBattleFrontierHeldItems[gFacilityTrainerMons[sRandMonSetId].itemTableId];
|
2020-10-07 23:03:46 +02:00
|
|
|
gFrontierTempParty[i] = sRandMonSetId;
|
2018-09-10 01:01:39 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|