summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPikalaxALT <pikalaxalt@gmail.com>2020-01-10 11:51:13 -0500
committerPikalaxALT <pikalaxalt@gmail.com>2020-01-10 11:51:13 -0500
commit3f54c7caa1c40692f3f8c2b7660b0459dac38c0e (patch)
tree98953676ecc3acea0fe02a7cc3813ffa3a20063e /src
parent5734043a202bb831609736802de615687531f7f3 (diff)
Port script_pokemon_util_80A0058
Diffstat (limited to 'src')
-rw-r--r--src/battle_setup.c2
-rw-r--r--src/post_battle_event_funcs.c2
-rw-r--r--src/script_pokemon_util_80A0058.c232
3 files changed, 234 insertions, 2 deletions
diff --git a/src/battle_setup.c b/src/battle_setup.c
index 17da53083..dee0c492b 100644
--- a/src/battle_setup.c
+++ b/src/battle_setup.c
@@ -901,7 +901,7 @@ static void CB2_EndTrainerBattle(void)
gSpecialVar_Result = 1;
if (gUnknown_20386CC & 1)
{
- sp000_heal_pokemon();
+ HealPlayerParty();
}
else
{
diff --git a/src/post_battle_event_funcs.c b/src/post_battle_event_funcs.c
index 6d4652f35..1e61b9b77 100644
--- a/src/post_battle_event_funcs.c
+++ b/src/post_battle_event_funcs.c
@@ -14,7 +14,7 @@ bool8 Special_HallOfFame(void)
bool8 *r7;
int i;
bool8 gaveAtLeastOneRibbon;
- sp000_heal_pokemon();
+ HealPlayerParty();
if (FlagGet(FLAG_SYS_GAME_CLEAR) == TRUE)
{
gHasHallOfFameRecords = TRUE;
diff --git a/src/script_pokemon_util_80A0058.c b/src/script_pokemon_util_80A0058.c
new file mode 100644
index 000000000..9a9fd37a5
--- /dev/null
+++ b/src/script_pokemon_util_80A0058.c
@@ -0,0 +1,232 @@
+#include "global.h"
+#include "battle.h"
+#include "battle_gfx_sfx_util.h"
+#include "berry.h"
+#include "data.h"
+#include "daycare.h"
+#include "decompress.h"
+#include "event_data.h"
+#include "event_object_movement.h"
+#include "link.h"
+#include "link_rfu.h"
+#include "load_save.h"
+#include "main.h"
+#include "malloc.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 "script_pokemon_util_80A0058.h"
+#include "sprite.h"
+#include "string_util.h"
+#include "constants/items.h"
+#include "constants/species.h"
+#include "constants/vars.h"
+
+static void CB2_ReturnFromChooseHalfParty(void);
+static void CB2_ReturnFromChooseBattleTowerParty(void);
+
+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++)
+ {
+ 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 = AllocZeroed(sizeof(struct Pokemon));
+
+ CreateMon(mon, species, level, 32, 0, 0, OT_ID_PLAYER_ID, 0);
+ 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);
+ break;
+ }
+
+ Free(mon);
+ return sentToPc;
+}
+
+u8 ScriptGiveEgg(u16 species)
+{
+ struct Pokemon *mon = AllocZeroed(sizeof(struct Pokemon));
+ u8 isEgg;
+ bool8 sentToPc;
+
+ CreateEgg(mon, species, TRUE);
+ isEgg = TRUE;
+ SetMonData(mon, MON_DATA_IS_EGG, &isEgg);
+
+ sentToPc = GiveMonToPlayer(mon);
+ Free(mon);
+ return sentToPc;
+}
+
+void HasEnoughMonsForDoubleBattle(void)
+{
+ switch (GetMonsStateToDoubles())
+ {
+ case PLAYER_HAS_TWO_USABLE_MONS:
+ gSpecialVar_Result = PLAYER_HAS_TWO_USABLE_MONS;
+ break;
+ case PLAYER_HAS_ONE_MON:
+ gSpecialVar_Result = PLAYER_HAS_ONE_MON;
+ break;
+ case PLAYER_HAS_ONE_USABLE_MON:
+ gSpecialVar_Result = PLAYER_HAS_ONE_USABLE_MON;
+ break;
+ }
+}
+
+static bool8 CheckPartyMonHasHeldItem(u16 item)
+{
+ 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;
+}
+
+bool8 GetNameOfEnigmaBerryInPlayerParty(void)
+{
+ 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();
+ CreateMon(&gEnemyParty[0], species, level, 32, 0, 0, OT_ID_PLAYER_ID, 0);
+ 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);
+}
+
+// Note: When control returns to the event script, gSpecialVar_Result will be
+// TRUE if the party selection was successful.
+void ChooseHalfPartyForBattle(void)
+{
+ gMain.savedCallback = CB2_ReturnFromChooseHalfParty;
+// VarSet(VAR_FRONTIER_FACILITY, FACILITY_MULTI_OR_EREADER);
+ InitChooseHalfPartyForBattle(0);
+}
+
+static void CB2_ReturnFromChooseHalfParty(void)
+{
+ switch (gSelectedOrderFromParty[0])
+ {
+ case 0:
+ gSpecialVar_Result = FALSE;
+ break;
+ default:
+ gSpecialVar_Result = TRUE;
+ break;
+ }
+
+ SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
+}
+
+void ChooseBattleTowerPlayerParty(void)
+{
+ gMain.savedCallback = CB2_ReturnFromChooseBattleTowerParty;
+ InitChooseHalfPartyForBattle(1);
+}
+
+static void CB2_ReturnFromChooseBattleTowerParty(void)
+{
+ switch (gSelectedOrderFromParty[0])
+ {
+ case 0:
+ LoadPlayerParty();
+ gSpecialVar_Result = FALSE;
+ break;
+ default:
+ ReducePlayerPartyToThree();
+ gSpecialVar_Result = TRUE;
+ break;
+ }
+
+ SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic);
+}
+
+void ReducePlayerPartyToThree(void)
+{
+ struct Pokemon * party = AllocZeroed(3 * sizeof(struct Pokemon));
+ int i;
+
+ // copy the selected pokemon according to the order.
+ for (i = 0; i < 3; i++)
+ 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
+
+ CpuFill32(0, gPlayerParty, sizeof gPlayerParty);
+
+ // overwrite the first 4 with the order copied to.
+ for (i = 0; i < 3; i++)
+ gPlayerParty[i] = party[i];
+
+ CalculatePlayerPartyCount();
+ Free(party);
+}