diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2019-07-29 21:10:54 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2019-07-29 21:10:54 -0400 |
commit | e130a00cdf69c58dbff8e98a69559aeb33f87b60 (patch) | |
tree | e128e502a2229f5d934f0436a0eb31dc86350bbb /src/field_poison.c | |
parent | ef4c86fbfdd18b78700f61b629907a85579197c0 (diff) | |
parent | d4cc0e161bf103d3d3e01fefa02e867d4a2053c2 (diff) |
Merge branch 'master' into slot_machine
Diffstat (limited to 'src/field_poison.c')
-rw-r--r-- | src/field_poison.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/field_poison.c b/src/field_poison.c new file mode 100644 index 000000000..474fbcd69 --- /dev/null +++ b/src/field_poison.c @@ -0,0 +1,117 @@ +#include "global.h" +#include "strings.h" +#include "task.h" +#include "field_message_box.h" +#include "script.h" +#include "string_util.h" +#include "event_data.h" +#include "fldeff.h" +#include "party_menu.h" +#include "field_poison.h" +#include "constants/species.h" +#include "constants/battle.h" + +static bool32 IsMonValidSpecies(struct Pokemon *pokemon) +{ + u16 species = GetMonData(pokemon, MON_DATA_SPECIES2); + if (species == SPECIES_NONE || species == SPECIES_EGG) + return FALSE; + return TRUE; +} + +static bool32 AllMonsFainted(void) +{ + int i; + + struct Pokemon *pokemon = gPlayerParty; + for (i = 0; i < PARTY_SIZE; i++, pokemon++) + if (IsMonValidSpecies(pokemon) && GetMonData(pokemon, MON_DATA_HP)) + return FALSE; + return TRUE; +} + +static void FaintFromFieldPoison(u8 partyIdx) +{ + struct Pokemon *pokemon = gPlayerParty + partyIdx; + u32 status = STATUS1_NONE; + AdjustFriendship(pokemon, 8); + SetMonData(pokemon, MON_DATA_STATUS, &status); + GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1); + StringGetEnd10(gStringVar1); +} + +static bool32 MonFaintedFromPoison(u8 partyIdx) +{ + struct Pokemon *pokemon = gPlayerParty + partyIdx; + if (IsMonValidSpecies(pokemon) && !GetMonData(pokemon, MON_DATA_HP) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) + return TRUE; + return FALSE; +} + +static void Task_WhiteOut(u8 taskId) +{ + s16 *data = gTasks[taskId].data; + switch (data[0]) + { + case 0: + for (; data[1] < PARTY_SIZE; data[1]++) + { + if (MonFaintedFromPoison(data[1])) + { + FaintFromFieldPoison(data[1]); + ShowFieldMessage(gText_PkmnFainted3); + data[0]++; + return; + } + } + data[0] = 2; + break; + case 1: + if (IsFieldMessageBoxHidden()) + data[0]--; + break; + case 2: + if (AllMonsFainted()) + gSpecialVar_Result = 1; + else + gSpecialVar_Result = 0; + EnableBothScriptContexts(); + DestroyTask(taskId); + break; + } +} + +void ExecuteWhiteOut(void) +{ + CreateTask(Task_WhiteOut, 80); + ScriptContext1_Stop(); +} + +s32 DoPoisonFieldEffect(void) +{ + int i; + u32 hp; + + 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) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) + { + hp = GetMonData(pokemon, MON_DATA_HP); + if (hp == 0 || --hp == 0) + numFainted++; + SetMonData(pokemon, MON_DATA_HP, &hp); + numPoisoned++; + } + pokemon++; + } + if (numFainted || numPoisoned) + FldEffPoison_Start(); + if (numFainted) + return FLDPSN_FNT; + if (numPoisoned) + return FLDPSN_PSN; + return FLDPSN_NONE; +} |