pokeemerald/src/field_poison.c

151 lines
3.6 KiB
C
Raw Normal View History

2017-11-23 02:10:35 +01:00
#include "global.h"
2018-10-17 02:11:44 +02:00
#include "battle.h"
2017-11-23 02:10:35 +01:00
#include "event_data.h"
#include "field_message_box.h"
#include "field_poison.h"
2018-10-17 02:11:44 +02:00
#include "fldeff_80F9BCC.h"
2018-10-30 22:17:03 +01:00
#include "frontier_util.h"
2018-10-17 02:11:44 +02:00
#include "party_menu.h"
2017-11-23 02:10:35 +01:00
#include "pokenav.h"
2018-10-17 02:11:44 +02:00
#include "rom_818CFC8.h"
2017-11-23 02:10:35 +01:00
#include "script.h"
2018-10-17 02:11:44 +02:00
#include "string_util.h"
#include "strings.h"
#include "task.h"
2018-11-12 14:35:56 +01:00
#include "battle_pike.h"
2018-10-17 02:11:44 +02:00
#include "constants/species.h"
2018-11-01 21:31:10 +01:00
2018-10-17 02:11:44 +02:00
static bool32 IsMonValidSpecies(struct Pokemon *pokemon)
2017-11-23 02:10:35 +01:00
{
u16 species = GetMonData(pokemon, MON_DATA_SPECIES2);
if (species == SPECIES_NONE || species == SPECIES_EGG)
{
return FALSE;
}
return TRUE;
}
2018-10-17 02:11:44 +02:00
static bool32 AllMonsFainted(void)
2017-11-23 02:10:35 +01:00
{
int i;
2018-10-17 02:11:44 +02:00
struct Pokemon *pokemon = gPlayerParty;
2017-11-23 02:10:35 +01:00
2018-10-17 02:11:44 +02:00
for (i = 0; i < PARTY_SIZE; i++, pokemon++)
2017-11-23 02:10:35 +01:00
{
2018-10-17 02:11:44 +02:00
if (IsMonValidSpecies(pokemon) && GetMonData(pokemon, MON_DATA_HP) != 0)
2017-11-23 02:10:35 +01:00
{
return FALSE;
}
}
return TRUE;
}
2018-10-17 02:11:44 +02:00
static void FaintFromFieldPoison(u8 partyIdx)
2017-11-23 02:10:35 +01:00
{
struct Pokemon *pokemon = gPlayerParty + partyIdx;
2018-10-17 02:11:44 +02:00
u32 status = STATUS1_NONE;
2017-11-23 02:10:35 +01:00
AdjustFriendship(pokemon, 0x07);
SetMonData(pokemon, MON_DATA_STATUS, &status);
GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1);
StringGetEnd10(gStringVar1);
}
2018-10-17 02:11:44 +02:00
static bool32 MonFaintedFromPoison(u8 partyIdx)
2017-11-23 02:10:35 +01:00
{
struct Pokemon *pokemon = gPlayerParty + partyIdx;
2018-10-17 02:11:44 +02:00
if (IsMonValidSpecies(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN)
2017-11-23 02:10:35 +01:00
{
return TRUE;
}
return FALSE;
}
2018-10-17 02:11:44 +02:00
static void Task_WhiteOut(u8 taskId)
2017-11-23 02:10:35 +01:00
{
s16 *data = gTasks[taskId].data;
2017-11-23 02:10:35 +01:00
switch (data[0])
{
case 0:
for (; data[1] < PARTY_SIZE; data[1]++)
{
2018-10-17 02:11:44 +02:00
if (MonFaintedFromPoison(data[1]))
2017-11-23 02:10:35 +01:00
{
2018-10-17 02:11:44 +02:00
FaintFromFieldPoison(data[1]);
2017-11-23 02:10:35 +01:00
ShowFieldMessage(gText_PkmnFainted3);
data[0]++;
return;
}
}
data[0] = 2;
break;
case 1:
if (IsFieldMessageBoxHidden())
{
data[0]--;
}
break;
case 2:
2018-10-17 02:11:44 +02:00
if (AllMonsFainted())
2017-11-23 02:10:35 +01:00
{
if (InBattlePyramid() | InBattlePike() || sub_81D5C18())
{
gSpecialVar_Result = 2;
}
else
{
gSpecialVar_Result = 1;
}
}
else
{
gSpecialVar_Result = 0;
}
EnableBothScriptContexts();
DestroyTask(taskId);
break;
}
}
2018-10-17 02:11:44 +02:00
void ExecuteWhiteOut(void)
2017-11-23 02:10:35 +01:00
{
2018-10-17 02:11:44 +02:00
CreateTask(Task_WhiteOut, 80);
2017-11-23 02:10:35 +01:00
ScriptContext1_Stop();
}
s32 DoPoisonFieldEffect(void)
2017-11-23 02:10:35 +01:00
{
int i;
2018-10-17 02:11:44 +02:00
u32 hp;
struct Pokemon *pokemon = gPlayerParty;
2018-10-17 02:11:44 +02:00
u32 numPoisoned = 0;
u32 numFainted = 0;
2017-11-23 02:10:35 +01:00
for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(pokemon, MON_DATA_SANITY_BIT2) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN)
2017-11-23 02:10:35 +01:00
{
hp = GetMonData(pokemon, MON_DATA_HP);
if (hp == 0 || --hp == 0)
{
numFainted++;
2017-11-23 02:10:35 +01:00
}
SetMonData(pokemon, MON_DATA_HP, &hp);
numPoisoned++;
2017-11-23 02:10:35 +01:00
}
pokemon++;
}
if (numFainted != 0 || numPoisoned != 0)
2017-11-23 02:10:35 +01:00
{
2018-10-17 02:11:44 +02:00
FldeffPoison_Start();
2017-11-23 02:10:35 +01:00
}
if (numFainted != 0)
2017-11-23 02:10:35 +01:00
{
return FLDPSN_FNT;
2017-11-23 02:10:35 +01:00
}
if (numPoisoned != 0)
2017-11-23 02:10:35 +01:00
{
return FLDPSN_PSN;
2017-11-23 02:10:35 +01:00
}
return FLDPSN_NONE;
2017-11-23 02:10:35 +01:00
}