Clean up field_poison.c

This commit is contained in:
GriffinR 2022-07-06 21:04:54 -04:00
parent 06c9e0eb99
commit 06dc93fc2f
4 changed files with 44 additions and 40 deletions

View File

@ -179,7 +179,7 @@ extern const u8 gText_EmptyString2[];
extern const u8 gText_Confirm3[];
extern const u8 gText_Cancel4[];
extern const u8 gText_IsThisTheCorrectTime[];
extern const u8 gText_PkmnFainted3[];
extern const u8 gText_PkmnFainted_FldPsn[];
extern const u8 gText_Coins[];
extern const u8 gText_Silver[];
extern const u8 gText_Gold[];

View File

@ -21,9 +21,8 @@ static bool32 IsMonValidSpecies(struct Pokemon *pokemon)
{
u16 species = GetMonData(pokemon, MON_DATA_SPECIES2);
if (species == SPECIES_NONE || species == SPECIES_EGG)
{
return FALSE;
}
return TRUE;
}
@ -35,16 +34,14 @@ static bool32 AllMonsFainted(void)
for (i = 0; i < PARTY_SIZE; i++, pokemon++)
{
if (IsMonValidSpecies(pokemon) && GetMonData(pokemon, MON_DATA_HP) != 0)
{
return FALSE;
}
}
return TRUE;
}
static void FaintFromFieldPoison(u8 partyIdx)
{
struct Pokemon *pokemon = gPlayerParty + partyIdx;
struct Pokemon *pokemon = &gPlayerParty[partyIdx];
u32 status = STATUS1_NONE;
AdjustFriendship(pokemon, FRIENDSHIP_EVENT_FAINT_FIELD_PSN);
@ -55,49 +52,47 @@ static void FaintFromFieldPoison(u8 partyIdx)
static bool32 MonFaintedFromPoison(u8 partyIdx)
{
struct Pokemon *pokemon = gPlayerParty + partyIdx;
struct Pokemon *pokemon = &gPlayerParty[partyIdx];
if (IsMonValidSpecies(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && GetAilmentFromStatus(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN)
{
return TRUE;
}
return FALSE;
}
#define tState data[0]
#define tPartyIdx data[1]
static void Task_TryFieldPoisonWhiteOut(u8 taskId)
{
s16 *data = gTasks[taskId].data;
switch (data[0])
switch (tState)
{
case 0:
for (; data[1] < PARTY_SIZE; data[1]++)
for (; tPartyIdx < PARTY_SIZE; tPartyIdx++)
{
if (MonFaintedFromPoison(data[1]))
if (MonFaintedFromPoison(tPartyIdx))
{
FaintFromFieldPoison(data[1]);
ShowFieldMessage(gText_PkmnFainted3);
data[0]++;
FaintFromFieldPoison(tPartyIdx);
ShowFieldMessage(gText_PkmnFainted_FldPsn);
tState++;
return;
}
}
data[0] = 2;
tState = 2; // Finished checking party
break;
case 1:
// Wait for "{mon} fainted" message, then return to party loop
if (IsFieldMessageBoxHidden())
{
data[0]--;
}
tState--;
break;
case 2:
if (AllMonsFainted())
{
// Battle facilities have their own white out script to handle the challenge loss
if (InBattlePyramid() | InBattlePike() || InTrainerHillChallenge())
{
gSpecialVar_Result = FLDPSN_FRONTIER_WHITEOUT;
}
else
{
gSpecialVar_Result = FLDPSN_WHITEOUT;
}
}
else
{
@ -109,6 +104,9 @@ static void Task_TryFieldPoisonWhiteOut(u8 taskId)
}
}
#undef tState
#undef tPartyIdx
void TryFieldPoisonWhiteOut(void)
{
CreateTask(Task_TryFieldPoisonWhiteOut, 80);
@ -122,31 +120,31 @@ s32 DoPoisonFieldEffect(void)
struct Pokemon *pokemon = gPlayerParty;
u32 numPoisoned = 0;
u32 numFainted = 0;
for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(pokemon, MON_DATA_SANITY_HAS_SPECIES) && GetAilmentFromStatus(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN)
{
// Apply poison damage
hp = GetMonData(pokemon, MON_DATA_HP);
if (hp == 0 || --hp == 0)
{
numFainted++;
}
SetMonData(pokemon, MON_DATA_HP, &hp);
numPoisoned++;
}
pokemon++;
}
// Do screen flash effect
if (numFainted != 0 || numPoisoned != 0)
{
FldEffPoison_Start();
}
if (numFainted != 0)
{
return FLDPSN_FNT;
}
if (numPoisoned != 0)
{
return FLDPSN_PSN;
}
return FLDPSN_NONE;
}

View File

@ -1200,29 +1200,35 @@ bool8 IsLargeBreakableDecoration(u16 metatileId, bool8 checkBase)
return FALSE;
}
#define tState data[0]
#define tMosaic data[1]
static void Task_FieldPoisonEffect(u8 taskId)
{
s16 *data = gTasks[taskId].data;
switch (data[0])
switch (tState)
{
case 0:
data[1] += 2;
if (data[1] > 8)
data[0]++;
tMosaic += 2;
if (tMosaic > 8)
tState++;
break;
case 1:
data[1] -= 2;
if (data[1] == 0)
data[0]++;
tMosaic -= 2;
if (tMosaic == 0)
tState++;
break;
case 2:
DestroyTask(taskId);
return;
}
SetGpuReg(REG_OFFSET_MOSAIC, (data[1] << 4) | data[1]);
SetGpuReg(REG_OFFSET_MOSAIC, (tMosaic << 4) | tMosaic);
}
#undef tState
#undef tMosaic
void FldEffPoison_Start(void)
{
PlaySE(SE_FIELD_POISON);

View File

@ -1186,7 +1186,7 @@ const u8 gText_PsychUp48BP[] = _("PSYCH UP{CLEAR_TO 0x4E}48BP");
const u8 gText_IcePunch48BP[] = _("ICE PUNCH{CLEAR_TO 0x4E}48BP");
const u8 gText_ThunderPunch48BP[] = _("THUNDERPUNCH{CLEAR_TO 0x4E}48BP");
const u8 gText_FirePunch48BP[] = _("FIRE PUNCH{CLEAR_TO 0x4E}48BP");
const u8 gText_PkmnFainted3[] = _("{STR_VAR_1} fainted…\p\n");
const u8 gText_PkmnFainted_FldPsn[] = _("{STR_VAR_1} fainted…\p\n");
const u8 gText_Marco[] = _("MARCO");
const u8 gText_TrainerCardName[] = _("NAME: ");
const u8 gText_TrainerCardIDNo[] = _("IDNo.");