pokeemerald/src/script_pokemon_util_80F87D8.c

727 lines
18 KiB
C
Raw Normal View History

2018-11-25 22:32:22 +01:00
#include "global.h"
#include "battle.h"
#include "battle_gfx_sfx_util.h"
#include "berry.h"
#include "contest.h"
#include "contest_link_80F57C4.h"
#include "contest_painting.h"
2019-04-04 23:53:06 +02:00
#include "data.h"
2018-11-25 22:32:22 +01:00
#include "daycare.h"
#include "decompress.h"
#include "event_data.h"
#include "event_object_movement.h"
#include "international_string_util.h"
#include "link.h"
#include "link_rfu.h"
#include "main.h"
#include "menu.h"
#include "overworld.h"
#include "palette.h"
#include "party_menu.h"
#include "pokedex.h"
#include "pokemon.h"
#include "random.h"
#include "script.h"
#include "script_menu.h"
#include "sprite.h"
#include "string_util.h"
#include "tv.h"
#include "constants/event_objects.h"
#include "constants/items.h"
#include "constants/species.h"
2019-11-11 03:54:00 +01:00
#include "constants/tv.h"
2018-11-25 22:32:22 +01:00
#include "constants/vars.h"
#include "constants/battle_frontier.h"
2018-11-25 22:32:22 +01:00
extern const u16 gObjectEventPalette8[];
extern const u16 gObjectEventPalette17[];
extern const u16 gObjectEventPalette33[];
extern const u16 gObjectEventPalette34[];
2018-11-25 22:32:22 +01:00
2018-11-26 21:54:51 +01:00
static const u8 gUnknown_0858D8EC[] = { 3, 4, 5, 14 };
2018-11-25 22:32:22 +01:00
2019-11-11 03:54:00 +01:00
static void Task_ShowContestEntryMonPic(u8 taskId);
static void Task_LinkContestWaitForConnection(u8 taskId);
static void CB2_ReturnFromChooseHalfParty(void);
2019-11-26 23:20:08 +01:00
static void CB2_ReturnFromChooseBattleFrontierParty(void);
2018-11-25 22:32:22 +01:00
2018-11-25 22:50:54 +01:00
void SetContestTrainerGfxIds(void)
2018-11-25 22:32:22 +01:00
{
gSaveBlock1Ptr->vars[VAR_OBJ_GFX_ID_0 - VARS_START] = gContestMons[0].trainerGfxId;
gSaveBlock1Ptr->vars[VAR_OBJ_GFX_ID_1 - VARS_START] = gContestMons[1].trainerGfxId;
gSaveBlock1Ptr->vars[VAR_OBJ_GFX_ID_2 - VARS_START] = gContestMons[2].trainerGfxId;
}
// Unused
2018-11-25 22:32:22 +01:00
void sub_80F8814(void)
{
u16 var1;
u8 var0 = gSpecialVar_0x8005;
switch (var0)
{
case 0:
var1 = 3;
break;
case 1:
var1 = 4;
break;
case 2:
var1 = 5;
break;
default:
var1 = 100;
break;
}
gSpecialVar_0x8004 = var1;
}
2019-11-11 03:54:00 +01:00
void BufferContestTrainerAndMonNames(void)
2018-11-25 22:32:22 +01:00
{
2019-11-11 03:54:00 +01:00
BufferContestantTrainerName();
BufferContestantMonNickname();
BufferContestantMonSpecies();
2018-11-25 22:32:22 +01:00
}
// Unused
void DoesContestCategoryHaveWinner(void)
2018-11-25 22:32:22 +01:00
{
int contestWinner;
switch (gSpecialVar_ContestCategory)
{
case CONTEST_CATEGORY_COOL:
contestWinner = 8;
break;
case CONTEST_CATEGORY_BEAUTY:
contestWinner = 9;
break;
case CONTEST_CATEGORY_CUTE:
contestWinner = 10;
break;
case CONTEST_CATEGORY_SMART:
contestWinner = 11;
break;
case CONTEST_CATEGORY_TOUGH:
default:
contestWinner = 12;
break;
}
if (gSaveBlock1Ptr->contestWinners[contestWinner].species == SPECIES_NONE)
gSpecialVar_0x8004 = FALSE;
2018-11-25 22:32:22 +01:00
else
gSpecialVar_0x8004 = TRUE;
2018-11-25 22:32:22 +01:00
}
2019-11-11 03:54:00 +01:00
void SaveMuseumContestPainting(void)
2018-11-25 22:32:22 +01:00
{
sub_80DEDA8(0xFF);
}
2019-11-11 03:54:00 +01:00
void ShouldReadyContestArtist(void)
2018-11-25 22:32:22 +01:00
{
if (gContestFinalStandings[gContestPlayerMonIndex] == 0
2019-11-11 03:54:00 +01:00
&& gSpecialVar_ContestRank == CONTEST_RANK_MASTER
2018-11-25 22:32:22 +01:00
&& gUnknown_02039F08[gContestPlayerMonIndex] >= 800)
{
2019-11-11 03:54:00 +01:00
gSpecialVar_0x8004 = TRUE;
2018-11-25 22:32:22 +01:00
}
else
{
2019-11-11 03:54:00 +01:00
gSpecialVar_0x8004 = FALSE;
2018-11-25 22:32:22 +01:00
}
}
2019-01-19 23:04:33 +01:00
u8 CountPlayerContestPaintings(void)
2018-11-25 22:32:22 +01:00
{
int i;
2019-01-19 23:04:33 +01:00
u8 count = 0;
2018-11-25 22:32:22 +01:00
for (i = 0; i < 5; i++)
{
if (gSaveBlock1Ptr->contestWinners[8 + i].species)
2019-01-19 23:04:33 +01:00
count++;
2018-11-25 22:32:22 +01:00
}
2019-01-19 23:04:33 +01:00
return count;
2018-11-25 22:32:22 +01:00
}
// Unused
2018-11-25 22:32:22 +01:00
void sub_80F8970(void)
{
s16 conditions[CONTESTANT_COUNT];
2018-11-25 22:32:22 +01:00
int i, j;
s16 condition;
s8 var0;
2018-11-26 21:54:51 +01:00
u8 var2;
u8 r8;
2018-11-25 22:32:22 +01:00
u8 r7;
for (i = 0; i < CONTESTANT_COUNT; i++)
conditions[i] = gContestMonConditions[i];
2018-11-25 22:32:22 +01:00
for (i = 0; i < CONTESTANT_COUNT - 1; i++)
2018-11-25 22:32:22 +01:00
{
for (j = CONTESTANT_COUNT - 1; j > i; j--)
2018-11-25 22:32:22 +01:00
{
if (conditions[j - 1] < conditions[j])
2018-11-25 22:32:22 +01:00
{
int temp;
SWAP(conditions[j], conditions[j - 1], temp)
2018-11-25 22:32:22 +01:00
}
}
}
condition = conditions[gSpecialVar_0x8006];
2018-11-25 22:32:22 +01:00
var0 = 0;
2018-11-26 21:54:51 +01:00
r8 = 0;
for (i = 0; i < CONTESTANT_COUNT; i++)
2018-11-25 22:32:22 +01:00
{
if (conditions[i] == condition)
2018-11-25 22:32:22 +01:00
{
var0++;
if (i == gSpecialVar_0x8006)
2018-11-26 21:54:51 +01:00
r8 = var0;
2018-11-25 22:32:22 +01:00
}
}
for (i = 0; i < CONTESTANT_COUNT; i++)
2018-11-25 22:32:22 +01:00
{
if (conditions[i] == condition)
2018-11-25 22:32:22 +01:00
break;
}
r7 = i;
2018-11-26 21:54:51 +01:00
var2 = r8;
for (i = 0; i < CONTESTANT_COUNT; i++)
2018-11-25 22:32:22 +01:00
{
if (condition == gContestMonConditions[i])
{
if (var2 == 1)
break;
var2--;
}
}
StringCopy(gStringVar1, gContestMons[i].nickname);
StringCopy(gStringVar2, gContestMons[i].trainerName);
sub_81DB5AC(gStringVar2);
2018-11-26 21:54:51 +01:00
if (var0 == 1)
gSpecialVar_0x8006 = r7;
else if (r8 == var0)
2018-11-25 22:32:22 +01:00
gSpecialVar_0x8006 = r7;
else
gSpecialVar_0x8006 = r7 + 4;
}
2018-11-25 22:50:54 +01:00
static void ShowContestWinnerCleanup(void)
2018-11-25 22:32:22 +01:00
{
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
void ShowContestWinner(void)
{
2019-11-11 03:54:00 +01:00
/*
if(gUnknown_0203856C)
{
sub_80AAF30();
gBattleStruct->unk15DDF = 1;
gBattleStruct->unk15DDE = sub_80B2C4C(254, 0);
Contest_SaveWinner(3);
gUnknown_0203856C = 0;
}
*/
2018-12-15 20:07:07 +01:00
SetMainCallback2(CB2_ContestPainting);
2018-11-25 22:50:54 +01:00
gMain.savedCallback = ShowContestWinnerCleanup;
2018-11-25 22:32:22 +01:00
}
2019-11-11 03:54:00 +01:00
void SetLinkContestPlayerGfx(void)
2018-11-25 22:32:22 +01:00
{
int i;
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)
2018-11-25 22:32:22 +01:00
{
2019-01-03 18:54:22 +01:00
for (i = 0; i < gNumLinkContestPlayers; i++)
2018-11-25 22:32:22 +01:00
{
int version = (u8)gLinkPlayers[i].version;
if (version == VERSION_RUBY || version == VERSION_SAPPHIRE)
{
if (gLinkPlayers[i].gender == MALE)
gContestMons[i].trainerGfxId = OBJ_EVENT_GFX_LINK_RS_BRENDAN;
2018-11-25 22:32:22 +01:00
else
gContestMons[i].trainerGfxId = OBJ_EVENT_GFX_LINK_RS_MAY;
2018-11-25 22:32:22 +01:00
}
}
VarSet(VAR_OBJ_GFX_ID_0, gContestMons[0].trainerGfxId);
VarSet(VAR_OBJ_GFX_ID_1, gContestMons[1].trainerGfxId);
VarSet(VAR_OBJ_GFX_ID_2, gContestMons[2].trainerGfxId);
VarSet(VAR_OBJ_GFX_ID_3, gContestMons[3].trainerGfxId);
}
}
2019-11-11 03:54:00 +01:00
void LoadLinkContestPlayerPalettes(void)
2018-11-25 22:32:22 +01:00
{
int i;
u8 objectEventId;
2018-11-25 22:32:22 +01:00
int version;
struct Sprite *sprite;
gReservedSpritePaletteCount = 12;
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)
2018-11-25 22:32:22 +01:00
{
2019-01-03 18:54:22 +01:00
for (i = 0; i < gNumLinkContestPlayers; i++)
2018-11-25 22:32:22 +01:00
{
objectEventId = GetObjectEventIdByLocalIdAndMap(gUnknown_0858D8EC[i], gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);
sprite = &gSprites[gObjectEvents[objectEventId].spriteId];
2018-11-25 22:32:22 +01:00
sprite->oam.paletteNum = 6 + i;
version = (u8)gLinkPlayers[i].version;
if (version == VERSION_RUBY || version == VERSION_SAPPHIRE)
{
if (gLinkPlayers[i].gender == MALE)
LoadPalette(gObjectEventPalette33, 0x160 + i * 0x10, 0x20);
2018-11-25 22:32:22 +01:00
else
LoadPalette(gObjectEventPalette34, 0x160 + i * 0x10, 0x20);
2018-11-25 22:32:22 +01:00
}
else
{
if (gLinkPlayers[i].gender == MALE)
LoadPalette(gObjectEventPalette8, 0x160 + i * 0x10, 0x20);
2018-11-25 22:32:22 +01:00
else
LoadPalette(gObjectEventPalette17, 0x160 + i * 0x10, 0x20);
2018-11-25 22:32:22 +01:00
}
}
}
}
2018-11-25 22:50:54 +01:00
u8 GiveMonArtistRibbon(void)
2018-11-25 22:32:22 +01:00
{
u8 hasArtistRibbon;
2019-01-03 18:54:22 +01:00
hasArtistRibbon = GetMonData(&gPlayerParty[gContestMonPartyIndex], MON_DATA_ARTIST_RIBBON);
2019-11-11 03:54:00 +01:00
if (!hasArtistRibbon
&& gContestFinalStandings[gContestPlayerMonIndex] == 0
&& gSpecialVar_ContestRank == CONTEST_RANK_MASTER
&& gUnknown_02039F08[gContestPlayerMonIndex] >= 800)
2018-11-25 22:32:22 +01:00
{
hasArtistRibbon = 1;
2019-01-03 18:54:22 +01:00
SetMonData(&gPlayerParty[gContestMonPartyIndex], MON_DATA_ARTIST_RIBBON, &hasArtistRibbon);
2019-11-11 03:54:00 +01:00
if (GetRibbonCount(&gPlayerParty[gContestMonPartyIndex]) > NUM_CUTIES_RIBBONS)
TryPutSpotTheCutiesOnAir(&gPlayerParty[gContestMonPartyIndex], MON_DATA_ARTIST_RIBBON);
2018-11-26 21:54:51 +01:00
2018-11-25 22:32:22 +01:00
return 1;
}
else
{
return 0;
}
}
2019-11-11 03:54:00 +01:00
bool8 IsContestDebugActive(void)
2018-11-25 22:32:22 +01:00
{
2019-11-11 03:54:00 +01:00
return FALSE; // gUnknown_0203856C in pokeruby
2018-11-25 22:32:22 +01:00
}
2018-11-25 22:50:54 +01:00
void ShowContestEntryMonPic(void)
2018-11-25 22:32:22 +01:00
{
const struct CompressedSpritePalette *palette;
u32 personality, otId;
u16 species;
u8 spriteId;
u8 taskId;
u8 left, top;
2019-11-11 03:54:00 +01:00
if (FindTaskIdByFunc(Task_ShowContestEntryMonPic) == 0xFF)
2018-11-25 22:32:22 +01:00
{
AllocateMonSpritesGfx();
left = 10;
top = 3;
species = gContestMons[gSpecialVar_0x8006].species;
personality = gContestMons[gSpecialVar_0x8006].personality;
otId = gContestMons[gSpecialVar_0x8006].otId;
2019-11-11 03:54:00 +01:00
taskId = CreateTask(Task_ShowContestEntryMonPic, 0x50);
2018-11-25 22:32:22 +01:00
gTasks[taskId].data[0] = 0;
gTasks[taskId].data[1] = species;
if (gSpecialVar_0x8006 == gContestPlayerMonIndex)
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[1], species, personality);
else
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[species], gMonSpritesGfxPtr->sprites[1], species, personality);
palette = GetMonSpritePalStructFromOtIdPersonality(species, otId, personality);
2018-12-17 23:00:08 +01:00
LoadCompressedSpritePalette(palette);
2018-11-25 22:32:22 +01:00
SetMultiuseSpriteTemplateToPokemon(species, 1);
gMultiuseSpriteTemplate.paletteTag = palette->tag;
spriteId = CreateSprite(&gMultiuseSpriteTemplate, (left + 1) * 8 + 32, (top * 8) + 40, 0);
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)
2018-11-25 22:32:22 +01:00
{
if (!(gLinkContestFlags & LINK_CONTEST_FLAG_HAS_RS_PLAYER))
2018-11-25 22:32:22 +01:00
DoMonFrontSpriteAnimation(&gSprites[spriteId], species, FALSE, 0);
}
else
{
DoMonFrontSpriteAnimation(&gSprites[spriteId], species, FALSE, 0);
}
gTasks[taskId].data[2] = spriteId;
gTasks[taskId].data[3] = left;
gTasks[taskId].data[4] = top;
gSprites[spriteId].callback = SpriteCallbackDummy;
gSprites[spriteId].oam.priority = 0;
}
}
2019-11-11 03:54:00 +01:00
void HideContestEntryMonPic(void)
2018-11-25 22:32:22 +01:00
{
2019-11-11 03:54:00 +01:00
u8 taskId = FindTaskIdByFunc(Task_ShowContestEntryMonPic);
2018-11-25 22:32:22 +01:00
if (taskId != 0xFF)
{
gTasks[taskId].data[0]++;
FreeMonSpritesGfx();
}
}
2019-11-11 03:54:00 +01:00
static void Task_ShowContestEntryMonPic(u8 taskId)
2018-11-25 22:32:22 +01:00
{
struct Task *task = &gTasks[taskId];
struct Sprite *sprite;
switch(task->data[0])
{
case 0:
task->data[0]++;
break;
case 1:
task->data[5] = CreateWindowFromRect(10, 3, 8, 8);
SetStandardWindowBorderStyle(task->data[5], 1);
task->data[0]++;
break;
case 2:
break;
case 3:
sprite = &gSprites[task->data[2]];
FreeSpritePaletteByTag(GetSpritePaletteTagByPaletteNum(sprite->oam.paletteNum));
if(sprite->oam.affineMode)
FreeOamMatrix(sprite->oam.matrixNum);
DestroySprite(sprite);
task->data[0]++;
break;
case 4:
ClearToTransparentAndRemoveWindow(gTasks[taskId].data[5]);
2018-11-25 22:32:22 +01:00
DestroyTask(taskId);
break;
}
}
2018-11-25 22:50:54 +01:00
void ScriptGetMultiplayerId(void)
2018-11-25 22:32:22 +01:00
{
2019-11-11 03:54:00 +01:00
if ((gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)
&& gNumLinkContestPlayers == CONTESTANT_COUNT
&& !(gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS))
2018-11-25 22:32:22 +01:00
gSpecialVar_Result = GetMultiplayerId();
else
2019-11-11 03:54:00 +01:00
gSpecialVar_Result = MAX_LINK_PLAYERS;
2018-11-25 22:32:22 +01:00
}
2018-11-25 22:50:54 +01:00
void ScriptRandom(void)
2018-11-25 22:32:22 +01:00
{
u16 random;
u16 *scriptPtr;
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)
2018-11-25 22:32:22 +01:00
{
gContestRngValue = 1103515245 * gContestRngValue + 24691;
random = gContestRngValue >> 16;
scriptPtr = &gSpecialVar_Result;
}
else
{
scriptPtr = &gSpecialVar_Result;
random = Random();
}
*scriptPtr = random % *scriptPtr;
}
2019-11-11 03:54:00 +01:00
u16 GetContestRand(void)
2018-11-25 22:32:22 +01:00
{
gContestRngValue = 1103515245 * gContestRngValue + 24691;
return gContestRngValue >> 16;
}
2019-11-11 03:54:00 +01:00
bool8 LinkContestWaitForConnection(void)
2018-11-25 22:32:22 +01:00
{
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS)
2018-11-25 22:32:22 +01:00
{
2019-11-11 03:54:00 +01:00
CreateTask(Task_LinkContestWaitForConnection, 5);
return TRUE;
2018-11-25 22:32:22 +01:00
}
else
{
2019-11-11 03:54:00 +01:00
return FALSE;
2018-11-25 22:32:22 +01:00
}
}
2019-11-11 03:54:00 +01:00
static void Task_LinkContestWaitForConnection(u8 taskId)
2018-11-25 22:32:22 +01:00
{
switch (gTasks[taskId].data[0])
{
case 0:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished())
2018-11-25 22:32:22 +01:00
{
sub_800ADF8();
gTasks[taskId].data[0]++;
}
break;
case 1:
gTasks[taskId].data[0]++;
break;
default:
2018-12-31 09:22:21 +01:00
if (IsLinkTaskFinished() == 1)
2018-11-25 22:32:22 +01:00
{
EnableBothScriptContexts();
DestroyTask(taskId);
}
break;
}
}
2019-11-11 03:54:00 +01:00
void LinkContestTryShowWirelessIndicator(void)
2018-11-25 22:32:22 +01:00
{
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS)
2018-11-25 22:32:22 +01:00
{
if (gReceivedRemoteLinkPlayers)
{
2019-04-04 23:05:46 +02:00
LoadWirelessStatusIndicatorSpriteGfx();
2018-11-25 22:32:22 +01:00
CreateWirelessStatusIndicatorSprite(8, 8);
}
}
}
2019-11-11 03:54:00 +01:00
void LinkContestTryHideWirelessIndicator(void)
2018-11-25 22:32:22 +01:00
{
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS)
2018-11-25 22:32:22 +01:00
{
if (gReceivedRemoteLinkPlayers)
2019-04-01 00:59:52 +02:00
DestroyWirelessStatusIndicatorSprite();
2018-11-25 22:32:22 +01:00
}
}
2019-11-11 03:54:00 +01:00
bool8 IsContestWithRSPlayer(void)
2018-11-25 22:32:22 +01:00
{
if (gLinkContestFlags & LINK_CONTEST_FLAG_HAS_RS_PLAYER)
2019-11-11 03:54:00 +01:00
return TRUE;
2018-11-25 22:32:22 +01:00
else
2019-11-11 03:54:00 +01:00
return FALSE;
2018-11-25 22:32:22 +01:00
}
2019-11-11 03:54:00 +01:00
void ClearLinkContestFlags(void)
2018-11-25 22:32:22 +01:00
{
gLinkContestFlags = 0;
2018-11-25 22:32:22 +01:00
}
2019-11-11 03:54:00 +01:00
bool8 IsWirelessContest(void)
2018-11-25 22:32:22 +01:00
{
if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS)
2019-11-11 03:54:00 +01:00
return TRUE;
2018-11-25 22:32:22 +01:00
else
2019-11-11 03:54:00 +01:00
return FALSE;
2018-11-25 22:32:22 +01:00
}
void HealPlayerParty(void)
{
u8 i, j;
u8 ppBonuses;
u8 arg[4];
// restore HP.
for(i = 0; i < gPlayerPartyCount; i++)
{
u16 maxHP = GetMonData(&gPlayerParty[i], MON_DATA_MAX_HP);
arg[0] = maxHP;
arg[1] = maxHP >> 8;
SetMonData(&gPlayerParty[i], MON_DATA_HP, arg);
ppBonuses = GetMonData(&gPlayerParty[i], MON_DATA_PP_BONUSES);
// restore PP.
for(j = 0; j < MAX_MON_MOVES; j++)
2018-11-25 22:32:22 +01:00
{
arg[0] = CalculatePPWithBonus(GetMonData(&gPlayerParty[i], MON_DATA_MOVE1 + j), ppBonuses, j);
SetMonData(&gPlayerParty[i], MON_DATA_PP1 + j, arg);
}
// since status is u32, the four 0 assignments here are probably for safety to prevent undefined data from reaching SetMonData.
arg[0] = 0;
arg[1] = 0;
arg[2] = 0;
arg[3] = 0;
SetMonData(&gPlayerParty[i], MON_DATA_STATUS, arg);
}
}
u8 ScriptGiveMon(u16 species, u8 level, u16 item, u32 unused1, u32 unused2, u8 unused3)
{
u16 nationalDexNum;
int sentToPc;
u8 heldItem[2];
struct Pokemon mon;
2019-08-31 05:06:43 +02:00
CreateMon(&mon, species, level, 32, 0, 0, OT_ID_PLAYER_ID, 0);
2018-11-25 22:32:22 +01:00
heldItem[0] = item;
heldItem[1] = item >> 8;
SetMonData(&mon, MON_DATA_HELD_ITEM, heldItem);
sentToPc = GiveMonToPlayer(&mon);
nationalDexNum = SpeciesToNationalPokedexNum(species);
switch(sentToPc)
{
case 0:
case 1:
GetSetPokedexFlag(nationalDexNum, FLAG_SET_SEEN);
GetSetPokedexFlag(nationalDexNum, FLAG_SET_CAUGHT);
2018-11-25 22:32:22 +01:00
break;
}
return sentToPc;
}
u8 ScriptGiveEgg(u16 species)
{
struct Pokemon mon;
u8 isEgg;
CreateEgg(&mon, species, TRUE);
isEgg = TRUE;
SetMonData(&mon, MON_DATA_IS_EGG, &isEgg);
return GiveMonToPlayer(&mon);
}
void HasEnoughMonsForDoubleBattle(void)
{
switch (GetMonsStateToDoubles())
{
case PLAYER_HAS_TWO_USABLE_MONS:
gSpecialVar_Result = PLAYER_HAS_TWO_USABLE_MONS;
2018-11-25 22:32:22 +01:00
break;
case PLAYER_HAS_ONE_MON:
gSpecialVar_Result = PLAYER_HAS_ONE_MON;
2018-11-25 22:32:22 +01:00
break;
case PLAYER_HAS_ONE_USABLE_MON:
gSpecialVar_Result = PLAYER_HAS_ONE_USABLE_MON;
2018-11-25 22:32:22 +01:00
break;
}
}
2018-11-25 22:50:54 +01:00
static bool8 CheckPartyMonHasHeldItem(u16 item)
2018-11-25 22:32:22 +01:00
{
int i;
for(i = 0; i < PARTY_SIZE; i++)
{
u16 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
if (species != SPECIES_NONE && species != SPECIES_EGG && GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM) == item)
return TRUE;
}
return FALSE;
}
2019-10-11 10:14:09 +02:00
bool8 DoesPartyHaveEnigmaBerry(void)
2018-11-25 22:32:22 +01:00
{
bool8 hasItem = CheckPartyMonHasHeldItem(ITEM_ENIGMA_BERRY);
if (hasItem == TRUE)
GetBerryNameByBerryType(ItemIdToBerryType(ITEM_ENIGMA_BERRY), gStringVar1);
return hasItem;
}
void CreateScriptedWildMon(u16 species, u8 level, u16 item)
{
u8 heldItem[2];
ZeroEnemyPartyMons();
2019-11-24 22:58:40 +01:00
CreateMon(&gEnemyParty[0], species, level, 32, 0, 0, OT_ID_PLAYER_ID, 0);
2018-11-25 22:32:22 +01:00
if (item)
{
heldItem[0] = item;
heldItem[1] = item >> 8;
SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, heldItem);
}
}
void ScriptSetMonMoveSlot(u8 monIndex, u16 move, u8 slot)
{
if (monIndex > PARTY_SIZE)
monIndex = gPlayerPartyCount - 1;
SetMonMoveSlot(&gPlayerParty[monIndex], move, slot);
}
2019-02-18 07:03:44 +01:00
// Note: When control returns to the event script, gSpecialVar_Result will be
// TRUE if the party selection was successful.
2019-02-18 07:03:44 +01:00
void ChooseHalfPartyForBattle(void)
2018-11-25 22:32:22 +01:00
{
gMain.savedCallback = CB2_ReturnFromChooseHalfParty;
2019-10-18 01:22:03 +02:00
VarSet(VAR_FRONTIER_FACILITY, FACILITY_MULTI_OR_EREADER);
InitChooseHalfPartyForBattle(0);
2018-11-25 22:32:22 +01:00
}
static void CB2_ReturnFromChooseHalfParty(void)
2018-11-25 22:32:22 +01:00
{
2018-11-25 22:50:54 +01:00
switch (gSelectedOrderFromParty[0])
2018-11-25 22:32:22 +01:00
{
case 0:
gSpecialVar_Result = FALSE;
2018-11-25 22:32:22 +01:00
break;
default:
gSpecialVar_Result = TRUE;
2018-11-25 22:32:22 +01:00
break;
}
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
2019-11-26 23:20:08 +01:00
void ChoosePartyForBattleFrontier(void)
2018-11-25 22:32:22 +01:00
{
2019-11-26 23:20:08 +01:00
gMain.savedCallback = CB2_ReturnFromChooseBattleFrontierParty;
InitChooseHalfPartyForBattle(gSpecialVar_0x8004 + 1);
2018-11-25 22:32:22 +01:00
}
2019-11-26 23:20:08 +01:00
static void CB2_ReturnFromChooseBattleFrontierParty(void)
2018-11-25 22:32:22 +01:00
{
2018-11-25 22:50:54 +01:00
switch (gSelectedOrderFromParty[0])
2018-11-25 22:32:22 +01:00
{
case 0:
2019-11-26 23:20:08 +01:00
gSpecialVar_Result = FALSE;
2018-11-25 22:32:22 +01:00
break;
default:
2019-11-26 23:20:08 +01:00
gSpecialVar_Result = TRUE;
2018-11-25 22:32:22 +01:00
break;
}
SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
}
2018-11-25 22:50:54 +01:00
void ReducePlayerPartyToSelectedMons(void)
2018-11-25 22:32:22 +01:00
{
struct Pokemon party[MAX_FRONTIER_PARTY_SIZE];
2018-11-25 22:32:22 +01:00
int i;
CpuFill32(0, party, sizeof party);
// copy the selected pokemon according to the order.
for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++)
2018-11-25 22:50:54 +01:00
if (gSelectedOrderFromParty[i]) // as long as the order keeps going (did the player select 1 mon? 2? 3?), do not stop
party[i] = gPlayerParty[gSelectedOrderFromParty[i] - 1]; // index is 0 based, not literal
2018-11-25 22:32:22 +01:00
CpuFill32(0, gPlayerParty, sizeof gPlayerParty);
// overwrite the first 4 with the order copied to.
for (i = 0; i < MAX_FRONTIER_PARTY_SIZE; i++)
2018-11-25 22:32:22 +01:00
gPlayerParty[i] = party[i];
CalculatePlayerPartyCount();
}