From eff1ad330031633b2a28f2b9e8bc8f5e5258826a Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 22 Nov 2017 20:10:35 -0500 Subject: Decompile field poison --- src/field_poison.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/field_poison.c (limited to 'src') diff --git a/src/field_poison.c b/src/field_poison.c new file mode 100644 index 000000000..f9d7b1609 --- /dev/null +++ b/src/field_poison.c @@ -0,0 +1,157 @@ +#include "global.h" +#include "string_util.h" +#include "party_menu.h" +#include "species.h" +#include "task.h" +#include "field_message_box.h" +#include "strings.h" +#include "rom_818CFC8.h" +#include "battle_frontier_2.h" +#include "pokenav.h" +#include "event_data.h" +#include "script.h" +#include "fldeff_80F9BCC.h" + +static bool32 sub_80F9568(struct Pokemon *pokemon) +{ + u16 species = GetMonData(pokemon, MON_DATA_SPECIES2); + if (species == SPECIES_NONE || species == SPECIES_EGG) + { + return FALSE; + } + return TRUE; +} + +static bool32 sub_80F958C(void) +{ + int i; + struct Pokemon *pokemon; + + for (pokemon = gPlayerParty, i = 0; i < PARTY_SIZE; i++, pokemon++) + { + if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) != 0) + { + return FALSE; + } + } + return TRUE; +} + +static void sub_80F95C0(u8 partyIdx) +{ + struct Pokemon *pokemon; + unsigned status; + + pokemon = &gPlayerParty[partyIdx]; + status = 0; + AdjustFriendship(pokemon, 0x07); + SetMonData(pokemon, MON_DATA_STATUS, &status); + GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1); + StringGetEnd10(gStringVar1); +} + +static bool32 sub_80F960C(u8 partyIdx) +{ + struct Pokemon *pokemon; + + pokemon = &gPlayerParty[partyIdx]; + if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == 1) + { + return TRUE; + } + return FALSE; +} + +static void sub_80F9654(u8 taskId) +{ + s16 *data; + + data = gTasks[taskId].data; + switch (data[0]) + { + case 0: + for (; data[1] < PARTY_SIZE; data[1]++) + { + if (sub_80F960C(data[1])) + { + sub_80F95C0(data[1]); + ShowFieldMessage(gText_PkmnFainted3); + data[0]++; + return; + } + } + data[0] = 2; + break; + case 1: + if (IsFieldMessageBoxHidden()) + { + data[0]--; + } + break; + case 2: + if (sub_80F958C()) + { + if (InBattlePyramid() | InBattlePike() || sub_81D5C18()) + { + gSpecialVar_Result = 2; + } + else + { + gSpecialVar_Result = 1; + } + } + else + { + gSpecialVar_Result = 0; + } + EnableBothScriptContexts(); + DestroyTask(taskId); + break; + } +} + +void sub_80F972C(void) +{ + CreateTask(sub_80F9654, 80); + ScriptContext1_Stop(); +} + +unsigned overworld_poison(void) +{ + int i; + unsigned cnt1; + unsigned cnt2; + unsigned hp; + struct Pokemon *pokemon; + + pokemon = gPlayerParty; + cnt2 = 0; + cnt1 = 0; + for (i = 0; i < PARTY_SIZE; i++) + { + if (GetMonData(pokemon, MON_DATA_SANITY_BIT2) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == 1) + { + hp = GetMonData(pokemon, MON_DATA_HP); + if (hp == 0 || --hp == 0) + { + cnt1++; + } + SetMonData(pokemon, MON_DATA_HP, &hp); + cnt2++; + } + pokemon++; + } + if (cnt1 != 0 || cnt2 != 0) + { + overworld_poison_effect(); + } + if (cnt1 != 0) + { + return 2; + } + if (cnt2 != 0) + { + return 1; + } + return 0; +} -- cgit v1.2.3 From 921011592cbe9018f558b7977525e49252274947 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 29 Nov 2017 08:30:18 -0500 Subject: unsigned -> unsigned int; create header --- src/field_poison.c | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/field_poison.c b/src/field_poison.c index f9d7b1609..d953ab29c 100644 --- a/src/field_poison.c +++ b/src/field_poison.c @@ -10,7 +10,9 @@ #include "pokenav.h" #include "event_data.h" #include "script.h" +#include "battle.h" #include "fldeff_80F9BCC.h" +#include "field_poison.h" static bool32 sub_80F9568(struct Pokemon *pokemon) { @@ -39,11 +41,8 @@ static bool32 sub_80F958C(void) static void sub_80F95C0(u8 partyIdx) { - struct Pokemon *pokemon; - unsigned status; - - pokemon = &gPlayerParty[partyIdx]; - status = 0; + struct Pokemon *pokemon = gPlayerParty + partyIdx; + unsigned int status = STATUS_NONE; AdjustFriendship(pokemon, 0x07); SetMonData(pokemon, MON_DATA_STATUS, &status); GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1); @@ -52,10 +51,8 @@ static void sub_80F95C0(u8 partyIdx) static bool32 sub_80F960C(u8 partyIdx) { - struct Pokemon *pokemon; - - pokemon = &gPlayerParty[partyIdx]; - if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == 1) + struct Pokemon *pokemon = gPlayerParty + partyIdx; + if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) { return TRUE; } @@ -64,9 +61,7 @@ static bool32 sub_80F960C(u8 partyIdx) static void sub_80F9654(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; switch (data[0]) { case 0: @@ -116,42 +111,38 @@ void sub_80F972C(void) ScriptContext1_Stop(); } -unsigned overworld_poison(void) +unsigned int overworld_poison(void) { int i; - unsigned cnt1; - unsigned cnt2; - unsigned hp; - struct Pokemon *pokemon; - - pokemon = gPlayerParty; - cnt2 = 0; - cnt1 = 0; + unsigned int hp; + struct Pokemon *pokemon = gPlayerParty; + unsigned int numPoisoned = 0; + unsigned int numFainted = 0; for (i = 0; i < PARTY_SIZE; i++) { - if (GetMonData(pokemon, MON_DATA_SANITY_BIT2) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == 1) + if (GetMonData(pokemon, MON_DATA_SANITY_BIT2) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) { hp = GetMonData(pokemon, MON_DATA_HP); if (hp == 0 || --hp == 0) { - cnt1++; + numFainted++; } SetMonData(pokemon, MON_DATA_HP, &hp); - cnt2++; + numPoisoned++; } pokemon++; } - if (cnt1 != 0 || cnt2 != 0) + if (numFainted != 0 || numPoisoned != 0) { overworld_poison_effect(); } - if (cnt1 != 0) + if (numFainted != 0) { - return 2; + return FLDPSN_FNT; } - if (cnt2 != 0) + if (numPoisoned != 0) { - return 1; + return FLDPSN_PSN; } - return 0; + return FLDPSN_NONE; } -- cgit v1.2.3