diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2017-09-17 22:58:57 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2017-09-17 22:58:57 -0400 |
commit | 380858293e4597dd40390129a9a7bac713bdf080 (patch) | |
tree | 70aae164289d375eb72358935158253d282fd4a0 /src | |
parent | 052c9f0234a6034b9db8fce30f779b95b8869df5 (diff) | |
parent | 19d2d73c7064375e6cef64ced734052170d4361b (diff) |
Merge branch 'master' into sub_81700F8
Diffstat (limited to 'src')
-rw-r--r-- | src/berry.c | 1208 | ||||
-rw-r--r-- | src/decompress.c | 3 | ||||
-rw-r--r-- | src/item.c | 5 | ||||
-rw-r--r-- | src/pokemon_1.c | 66 | ||||
-rw-r--r-- | src/pokemon_2.c | 1368 | ||||
-rw-r--r-- | src/pokemon_3.c | 1753 |
6 files changed, 4399 insertions, 4 deletions
diff --git a/src/berry.c b/src/berry.c new file mode 100644 index 000000000..b6eaa14a0 --- /dev/null +++ b/src/berry.c @@ -0,0 +1,1208 @@ +#include "global.h" +#include "berry.h" +#include "main.h" +#include "item.h" +#include "items.h" +#include "text.h" +#include "rng.h" +#include "event_data.h" +#include "fieldmap.h" + +extern u8 FieldObjectGetBerryTreeId(u8 mapObjectId); +extern void sub_8092EF0(u8 mapId, u8 mapNumber, u8 mapGroup); +extern void CB2_ChooseBerry(void); +extern const u8* GetFieldObjectScriptPointerForComparison(void); +extern bool8 sub_8092E9C(u8, u8, u8); + +extern u16 gScriptItemId; + +extern const u8 BerryTreeScript[]; +extern const struct BerryTree gBlankBerryTree; + +#define BERRY_NAME_LENGTH 6 + +#define FIRST_BERRY ITEM_CHERI_BERRY +#define LAST_BERRY ITEM_ENIGMA_BERRY + + +static const u8 sBerryDescriptionPart1_Cheri[] = _("Blooms with delicate pretty flowers."); +static const u8 sBerryDescriptionPart2_Cheri[] = _("The bright red BERRY is very spicy."); +static const u8 sBerryDescriptionPart1_Chesto[] = _("The BERRY’s thick skin and fruit are"); +static const u8 sBerryDescriptionPart2_Chesto[] = _("very tough. It is dry-tasting all over."); +static const u8 sBerryDescriptionPart1_Pecha[] = _("Very sweet and delicious."); +static const u8 sBerryDescriptionPart2_Pecha[] = _("Also very tender - handle with care."); +static const u8 sBerryDescriptionPart1_Rawst[] = _("If the leaves grow long and curly,"); +static const u8 sBerryDescriptionPart2_Rawst[] = _("the BERRY seems to grow very bitter."); +static const u8 sBerryDescriptionPart1_Aspear[] = _("The hard BERRY is dense with a rich"); +static const u8 sBerryDescriptionPart2_Aspear[] = _("juice. It is quite sour."); +static const u8 sBerryDescriptionPart1_Leppa[] = _("Grows slower than CHERI and others."); +static const u8 sBerryDescriptionPart2_Leppa[] = _("The smaller the BERRY, the tastier."); +static const u8 sBerryDescriptionPart1_Oran[] = _("A peculiar BERRY with a mix of flavors."); +static const u8 sBerryDescriptionPart2_Oran[] = _("BERRIES grow in half a day."); +static const u8 sBerryDescriptionPart1_Persim[] = _("Loves sunlight. The BERRY’s color"); +static const u8 sBerryDescriptionPart2_Persim[] = _("grows vivid when exposed to the sun."); +static const u8 sBerryDescriptionPart1_Lum[] = _("Slow to grow. If raised with loving"); +static const u8 sBerryDescriptionPart2_Lum[] = _("care, it may grow two BERRIES."); +static const u8 sBerryDescriptionPart1_Sitrus[] = _("Closely related to ORAN. The large"); +static const u8 sBerryDescriptionPart2_Sitrus[] = _("BERRY has a well-rounded flavor."); +static const u8 sBerryDescriptionPart1_Figy[] = _("The BERRY, which looks chewed up,"); +static const u8 sBerryDescriptionPart2_Figy[] = _("brims with spicy substances."); +static const u8 sBerryDescriptionPart1_Wiki[] = _("The BERRY is said to have grown lumpy"); +static const u8 sBerryDescriptionPart2_Wiki[] = _("to help POKéMON grip it."); +static const u8 sBerryDescriptionPart1_Mago[] = _("The BERRY turns curvy as it grows."); +static const u8 sBerryDescriptionPart2_Mago[] = _("The curvier, the sweeter and tastier."); +static const u8 sBerryDescriptionPart1_Aguav[] = _("The flower is dainty. It is rare in its"); +static const u8 sBerryDescriptionPart2_Aguav[] = _("ability to grow without light."); +static const u8 sBerryDescriptionPart1_Iapapa[] = _("The BERRY is very big and sour."); +static const u8 sBerryDescriptionPart2_Iapapa[] = _("It takes at least a day to grow."); +static const u8 sBerryDescriptionPart1_Razz[] = _("The red BERRY tastes slightly spicy."); +static const u8 sBerryDescriptionPart2_Razz[] = _("It grows quickly in just four hours."); +static const u8 sBerryDescriptionPart1_Bluk[] = _("The BERRY is blue on the outside, but"); +static const u8 sBerryDescriptionPart2_Bluk[] = _("it blackens the mouth when eaten."); +static const u8 sBerryDescriptionPart1_Nanab[] = _("This BERRY was the seventh"); +static const u8 sBerryDescriptionPart2_Nanab[] = _("discovered in the world. It is sweet."); +static const u8 sBerryDescriptionPart1_Wepear[] = _("The flower is small and white. It has a"); +static const u8 sBerryDescriptionPart2_Wepear[] = _("delicate balance of bitter and sour."); +static const u8 sBerryDescriptionPart1_Pinap[] = _("Weak against wind and cold."); +static const u8 sBerryDescriptionPart2_Pinap[] = _("The fruit is spicy and the skin, sour."); +static const u8 sBerryDescriptionPart1_Pomeg[] = _("However much it is watered,"); +static const u8 sBerryDescriptionPart2_Pomeg[] = _("it only grows up to six BERRIES."); +static const u8 sBerryDescriptionPart1_Kelpsy[] = _("A rare variety shaped like a root."); +static const u8 sBerryDescriptionPart2_Kelpsy[] = _("Grows a very large flower."); +static const u8 sBerryDescriptionPart1_Qualot[] = _("Loves water. Grows strong even in"); +static const u8 sBerryDescriptionPart2_Qualot[] = _("locations with constant rainfall."); +static const u8 sBerryDescriptionPart1_Hondew[] = _("A BERRY that is very valuable and"); +static const u8 sBerryDescriptionPart2_Hondew[] = _("rarely seen. It is very delicious."); +static const u8 sBerryDescriptionPart1_Grepa[] = _("Despite its tenderness and round"); +static const u8 sBerryDescriptionPart2_Grepa[] = _("shape, the BERRY is unimaginably sour."); +static const u8 sBerryDescriptionPart1_Tamato[] = _("The BERRY is lip-bendingly spicy."); +static const u8 sBerryDescriptionPart2_Tamato[] = _("It takes time to grow."); +static const u8 sBerryDescriptionPart1_Cornn[] = _("A BERRY from an ancient era. May not"); +static const u8 sBerryDescriptionPart2_Cornn[] = _("grow unless planted in quantity."); +static const u8 sBerryDescriptionPart1_Magost[] = _("A BERRY that is widely said to have"); +static const u8 sBerryDescriptionPart2_Magost[] = _("a finely balanced flavor."); +static const u8 sBerryDescriptionPart1_Rabuta[] = _("A rare variety that is overgrown with"); +static const u8 sBerryDescriptionPart2_Rabuta[] = _("hair. It is quite bitter."); +static const u8 sBerryDescriptionPart1_Nomel[] = _("Quite sour. Just one bite makes it"); +static const u8 sBerryDescriptionPart2_Nomel[] = _("impossible to taste for three days."); +static const u8 sBerryDescriptionPart1_Spelon[] = _("The vividly red BERRY is very spicy."); +static const u8 sBerryDescriptionPart2_Spelon[] = _("Its warts secrete a spicy substance."); +static const u8 sBerryDescriptionPart1_Pamtre[] = _("Drifts on the sea from somewhere."); +static const u8 sBerryDescriptionPart2_Pamtre[] = _("It is thought to grow elsewhere."); +static const u8 sBerryDescriptionPart1_Watmel[] = _("A huge BERRY, with some over 20"); +static const u8 sBerryDescriptionPart2_Watmel[] = _("inches discovered. Exceedingly sweet."); +static const u8 sBerryDescriptionPart1_Durin[] = _("Bitter to even look at. It is so"); +static const u8 sBerryDescriptionPart2_Durin[] = _("bitter, no one has ever eaten it as is."); +static const u8 sBerryDescriptionPart1_Belue[] = _("It is glossy and looks delicious, but"); +static const u8 sBerryDescriptionPart2_Belue[] = _("it is awfully sour. Takes time to grow."); +static const u8 sBerryDescriptionPart1_Liechi[] = _("A mysterious BERRY. It is rumored to"); +static const u8 sBerryDescriptionPart2_Liechi[] = _("contain the power of the sea."); +static const u8 sBerryDescriptionPart1_Ganlon[] = _("A mysterious BERRY. It is rumored to"); +static const u8 sBerryDescriptionPart2_Ganlon[] = _("contain the power of the land."); +static const u8 sBerryDescriptionPart1_Salac[] = _("A mysterious BERRY. It is rumored to"); +static const u8 sBerryDescriptionPart2_Salac[] = _("contain the power of the sky."); +static const u8 sBerryDescriptionPart1_Petaya[] = _("A mysterious BERRY. It is rumored to"); +static const u8 sBerryDescriptionPart2_Petaya[] = _("contain the power of all living things."); +static const u8 sBerryDescriptionPart1_Apicot[] = _("A very mystifying BERRY. No telling"); +static const u8 sBerryDescriptionPart2_Apicot[] = _("what may happen or how it can be used."); +static const u8 sBerryDescriptionPart1_Lansat[] = _("Said to be a legendary BERRY."); +static const u8 sBerryDescriptionPart2_Lansat[] = _("Holding it supposedly brings joy."); +static const u8 sBerryDescriptionPart1_Starf[] = _("So strong, it was abandoned at the"); +static const u8 sBerryDescriptionPart2_Starf[] = _("world’s edge. Considered a mirage."); +static const u8 sBerryDescriptionPart1_Enigma[] = _("A completely enigmatic BERRY."); +static const u8 sBerryDescriptionPart2_Enigma[] = _("Appears to have the power of stars."); + +const struct Berry gBerries[] = +{ + { + .name = _("CHERI"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 20, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Cheri, + .description2 = sBerryDescriptionPart2_Cheri, + .stageDuration = 3, + .spicy = 10, + .dry = 0, + .sweet = 0, + .bitter = 0, + .sour = 0, + .smoothness = 25, + }, + { + .name = _("CHESTO"), + .firmness = BERRY_FIRMNESS_SUPER_HARD, + .size = 80, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Chesto, + .description2 = sBerryDescriptionPart2_Chesto, + .stageDuration = 3, + .spicy = 0, + .dry = 10, + .sweet = 0, + .bitter = 0, + .sour = 0, + .smoothness = 25, + }, + { + .name = _("PECHA"), + .firmness = BERRY_FIRMNESS_VERY_SOFT, + .size = 40, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Pecha, + .description2 = sBerryDescriptionPart2_Pecha, + .stageDuration = 3, + .spicy = 0, + .dry = 0, + .sweet = 10, + .bitter = 0, + .sour = 0, + .smoothness = 25, + }, + { + .name = _("RAWST"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 32, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Rawst, + .description2 = sBerryDescriptionPart2_Rawst, + .stageDuration = 3, + .spicy = 0, + .dry = 0, + .sweet = 0, + .bitter = 10, + .sour = 0, + .smoothness = 25, + }, + { + .name = _("ASPEAR"), + .firmness = BERRY_FIRMNESS_SUPER_HARD, + .size = 50, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Aspear, + .description2 = sBerryDescriptionPart2_Aspear, + .stageDuration = 3, + .spicy = 0, + .dry = 0, + .sweet = 0, + .bitter = 0, + .sour = 10, + .smoothness = 25, + }, + { + .name = _("LEPPA"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 28, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Leppa, + .description2 = sBerryDescriptionPart2_Leppa, + .stageDuration = 4, + .spicy = 10, + .dry = 0, + .sweet = 10, + .bitter = 10, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("ORAN"), + .firmness = BERRY_FIRMNESS_SUPER_HARD, + .size = 35, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Oran, + .description2 = sBerryDescriptionPart2_Oran, + .stageDuration = 3, + .spicy = 10, + .dry = 10, + .sweet = 10, + .bitter = 10, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("PERSIM"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 47, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Persim, + .description2 = sBerryDescriptionPart2_Persim, + .stageDuration = 3, + .spicy = 10, + .dry = 10, + .sweet = 10, + .bitter = 10, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("LUM"), + .firmness = BERRY_FIRMNESS_SUPER_HARD, + .size = 34, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Lum, + .description2 = sBerryDescriptionPart2_Lum, + .stageDuration = 12, + .spicy = 10, + .dry = 10, + .sweet = 10, + .bitter = 10, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("SITRUS"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 95, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Sitrus, + .description2 = sBerryDescriptionPart2_Sitrus, + .stageDuration = 6, + .spicy = 10, + .dry = 10, + .sweet = 10, + .bitter = 10, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("FIGY"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 100, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Figy, + .description2 = sBerryDescriptionPart2_Figy, + .stageDuration = 6, + .spicy = 10, + .dry = 0, + .sweet = 0, + .bitter = 0, + .sour = 0, + .smoothness = 25, + }, + { + .name = _("WIKI"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 115, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Wiki, + .description2 = sBerryDescriptionPart2_Wiki, + .stageDuration = 6, + .spicy = 0, + .dry = 10, + .sweet = 0, + .bitter = 0, + .sour = 0, + .smoothness = 25, + }, + { + .name = _("MAGO"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 126, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Mago, + .description2 = sBerryDescriptionPart2_Mago, + .stageDuration = 6, + .spicy = 0, + .dry = 0, + .sweet = 10, + .bitter = 0, + .sour = 0, + .smoothness = 25, + }, + { + .name = _("AGUAV"), + .firmness = BERRY_FIRMNESS_SUPER_HARD, + .size = 64, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Aguav, + .description2 = sBerryDescriptionPart2_Aguav, + .stageDuration = 6, + .spicy = 0, + .dry = 0, + .sweet = 0, + .bitter = 10, + .sour = 0, + .smoothness = 25, + }, + { + .name = _("IAPAPA"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 223, + .maxYield = 3, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Iapapa, + .description2 = sBerryDescriptionPart2_Iapapa, + .stageDuration = 6, + .spicy = 0, + .dry = 0, + .sweet = 0, + .bitter = 0, + .sour = 10, + .smoothness = 25, + }, + { + .name = _("RAZZ"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 120, + .maxYield = 6, + .minYield = 3, + .description1 = sBerryDescriptionPart1_Razz, + .description2 = sBerryDescriptionPart2_Razz, + .stageDuration = 1, + .spicy = 10, + .dry = 10, + .sweet = 0, + .bitter = 0, + .sour = 0, + .smoothness = 20, + }, + { + .name = _("BLUK"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 108, + .maxYield = 6, + .minYield = 3, + .description1 = sBerryDescriptionPart1_Bluk, + .description2 = sBerryDescriptionPart2_Bluk, + .stageDuration = 1, + .spicy = 0, + .dry = 10, + .sweet = 10, + .bitter = 0, + .sour = 0, + .smoothness = 20, + }, + { + .name = _("NANAB"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 77, + .maxYield = 6, + .minYield = 3, + .description1 = sBerryDescriptionPart1_Nanab, + .description2 = sBerryDescriptionPart2_Nanab, + .stageDuration = 1, + .spicy = 0, + .dry = 0, + .sweet = 10, + .bitter = 10, + .sour = 0, + .smoothness = 20, + }, + { + .name = _("WEPEAR"), + .firmness = BERRY_FIRMNESS_SUPER_HARD, + .size = 74, + .maxYield = 6, + .minYield = 3, + .description1 = sBerryDescriptionPart1_Wepear, + .description2 = sBerryDescriptionPart2_Wepear, + .stageDuration = 1, + .spicy = 0, + .dry = 0, + .sweet = 0, + .bitter = 10, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("PINAP"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 80, + .maxYield = 6, + .minYield = 3, + .description1 = sBerryDescriptionPart1_Pinap, + .description2 = sBerryDescriptionPart2_Pinap, + .stageDuration = 1, + .spicy = 10, + .dry = 0, + .sweet = 0, + .bitter = 0, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("POMEG"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 135, + .maxYield = 6, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Pomeg, + .description2 = sBerryDescriptionPart2_Pomeg, + .stageDuration = 3, + .spicy = 10, + .dry = 0, + .sweet = 10, + .bitter = 10, + .sour = 0, + .smoothness = 20, + }, + { + .name = _("KELPSY"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 150, + .maxYield = 6, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Kelpsy, + .description2 = sBerryDescriptionPart2_Kelpsy, + .stageDuration = 3, + .spicy = 0, + .dry = 10, + .sweet = 0, + .bitter = 10, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("QUALOT"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 110, + .maxYield = 6, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Qualot, + .description2 = sBerryDescriptionPart2_Qualot, + .stageDuration = 3, + .spicy = 10, + .dry = 0, + .sweet = 10, + .bitter = 0, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("HONDEW"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 162, + .maxYield = 6, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Hondew, + .description2 = sBerryDescriptionPart2_Hondew, + .stageDuration = 3, + .spicy = 10, + .dry = 10, + .sweet = 0, + .bitter = 10, + .sour = 0, + .smoothness = 20, + }, + { + .name = _("GREPA"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 149, + .maxYield = 6, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Grepa, + .description2 = sBerryDescriptionPart2_Grepa, + .stageDuration = 3, + .spicy = 0, + .dry = 10, + .sweet = 10, + .bitter = 0, + .sour = 10, + .smoothness = 20, + }, + { + .name = _("TAMATO"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 200, + .maxYield = 4, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Tamato, + .description2 = sBerryDescriptionPart2_Tamato, + .stageDuration = 6, + .spicy = 20, + .dry = 10, + .sweet = 0, + .bitter = 0, + .sour = 0, + .smoothness = 30, + }, + { + .name = _("CORNN"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 75, + .maxYield = 4, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Cornn, + .description2 = sBerryDescriptionPart2_Cornn, + .stageDuration = 6, + .spicy = 0, + .dry = 20, + .sweet = 10, + .bitter = 0, + .sour = 0, + .smoothness = 30, + }, + { + .name = _("MAGOST"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 140, + .maxYield = 4, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Magost, + .description2 = sBerryDescriptionPart2_Magost, + .stageDuration = 6, + .spicy = 0, + .dry = 0, + .sweet = 20, + .bitter = 10, + .sour = 0, + .smoothness = 30, + }, + { + .name = _("RABUTA"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 226, + .maxYield = 4, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Rabuta, + .description2 = sBerryDescriptionPart2_Rabuta, + .stageDuration = 6, + .spicy = 0, + .dry = 0, + .sweet = 0, + .bitter = 20, + .sour = 10, + .smoothness = 30, + }, + { + .name = _("NOMEL"), + .firmness = BERRY_FIRMNESS_SUPER_HARD, + .size = 285, + .maxYield = 4, + .minYield = 2, + .description1 = sBerryDescriptionPart1_Nomel, + .description2 = sBerryDescriptionPart2_Nomel, + .stageDuration = 6, + .spicy = 10, + .dry = 0, + .sweet = 0, + .bitter = 0, + .sour = 20, + .smoothness = 30, + }, + { + .name = _("SPELON"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 133, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Spelon, + .description2 = sBerryDescriptionPart2_Spelon, + .stageDuration = 18, + .spicy = 40, + .dry = 10, + .sweet = 0, + .bitter = 0, + .sour = 0, + .smoothness = 70, + }, + { + .name = _("PAMTRE"), + .firmness = BERRY_FIRMNESS_VERY_SOFT, + .size = 244, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Pamtre, + .description2 = sBerryDescriptionPart2_Pamtre, + .stageDuration = 18, + .spicy = 0, + .dry = 40, + .sweet = 10, + .bitter = 0, + .sour = 0, + .smoothness = 70, + }, + { + .name = _("WATMEL"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 250, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Watmel, + .description2 = sBerryDescriptionPart2_Watmel, + .stageDuration = 18, + .spicy = 0, + .dry = 0, + .sweet = 40, + .bitter = 10, + .sour = 0, + .smoothness = 70, + }, + { + .name = _("DURIN"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 280, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Durin, + .description2 = sBerryDescriptionPart2_Durin, + .stageDuration = 18, + .spicy = 0, + .dry = 0, + .sweet = 0, + .bitter = 40, + .sour = 10, + .smoothness = 70, + }, + { + .name = _("BELUE"), + .firmness = BERRY_FIRMNESS_VERY_SOFT, + .size = 300, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Belue, + .description2 = sBerryDescriptionPart2_Belue, + .stageDuration = 18, + .spicy = 10, + .dry = 0, + .sweet = 0, + .bitter = 0, + .sour = 40, + .smoothness = 70, + }, + { + .name = _("LIECHI"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 111, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Liechi, + .description2 = sBerryDescriptionPart2_Liechi, + .stageDuration = 24, + .spicy = 40, + .dry = 0, + .sweet = 40, + .bitter = 0, + .sour = 10, + .smoothness = 80, + }, + { + .name = _("GANLON"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 33, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Ganlon, + .description2 = sBerryDescriptionPart2_Ganlon, + .stageDuration = 24, + .spicy = 0, + .dry = 40, + .sweet = 0, + .bitter = 40, + .sour = 0, + .smoothness = 80, + }, + { + .name = _("SALAC"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 95, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Salac, + .description2 = sBerryDescriptionPart2_Salac, + .stageDuration = 24, + .spicy = 0, + .dry = 0, + .sweet = 40, + .bitter = 0, + .sour = 40, + .smoothness = 80, + }, + { + .name = _("PETAYA"), + .firmness = BERRY_FIRMNESS_VERY_HARD, + .size = 237, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Petaya, + .description2 = sBerryDescriptionPart2_Petaya, + .stageDuration = 24, + .spicy = 40, + .dry = 0, + .sweet = 0, + .bitter = 40, + .sour = 0, + .smoothness = 80, + }, + { + .name = _("APICOT"), + .firmness = BERRY_FIRMNESS_HARD, + .size = 75, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Apicot, + .description2 = sBerryDescriptionPart2_Apicot, + .stageDuration = 24, + .spicy = 0, + .dry = 40, + .sweet = 0, + .bitter = 0, + .sour = 40, + .smoothness = 80, + }, + { + .name = _("LANSAT"), + .firmness = BERRY_FIRMNESS_SOFT, + .size = 97, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Lansat, + .description2 = sBerryDescriptionPart2_Lansat, + .stageDuration = 24, + .spicy = 10, + .dry = 10, + .sweet = 10, + .bitter = 10, + .sour = 10, + .smoothness = 30, + }, + { + .name = _("STARF"), + .firmness = BERRY_FIRMNESS_SUPER_HARD, + .size = 153, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Starf, + .description2 = sBerryDescriptionPart2_Starf, + .stageDuration = 24, + .spicy = 10, + .dry = 10, + .sweet = 10, + .bitter = 10, + .sour = 10, + .smoothness = 30, + }, + { + .name = _("ENIGMA"), + .firmness = BERRY_FIRMNESS_UNKNOWN, + .size = 0, + .maxYield = 2, + .minYield = 1, + .description1 = sBerryDescriptionPart1_Enigma, + .description2 = sBerryDescriptionPart2_Enigma, + .stageDuration = 24, + .spicy = 40, + .dry = 40, + .sweet = 40, + .bitter = 40, + .sour = 40, + .smoothness = 40, + }, +}; + +// unused +void ClearEnigmaBerries(void) +{ + CpuFill16(0, &gSaveBlock1Ptr->enigmaBerry, sizeof(gSaveBlock1Ptr->enigmaBerry)); +} + +void SetEnigmaBerry(u8 *src) +{ + u32 i; + u8 *dest = (u8*)&gSaveBlock1Ptr->enigmaBerry; + + for (i = 0; i < sizeof(gSaveBlock1Ptr->enigmaBerry); i++) + dest[i] = src[i]; +} + +u32 GetEnigmaBerryChecksum(struct EnigmaBerry *enigmaBerry) +{ + u32 i; + u32 checksum; + u8 *dest; + + dest = (u8*)enigmaBerry; + checksum = 0; + for (i = 0; i < sizeof(gSaveBlock1Ptr->enigmaBerry) - sizeof(gSaveBlock1Ptr->enigmaBerry.checksum); i++) + { + checksum += dest[i]; + } + + return checksum; +} + +bool32 IsEnigmaBerryValid(void) +{ + if (!gSaveBlock1Ptr->enigmaBerry.berry.stageDuration) + return FALSE; + if (!gSaveBlock1Ptr->enigmaBerry.berry.maxYield) + return FALSE; + if (GetEnigmaBerryChecksum(&gSaveBlock1Ptr->enigmaBerry) != gSaveBlock1Ptr->enigmaBerry.checksum) + return FALSE; + return TRUE; +} + +const struct Berry *GetBerryInfo(u8 berry) +{ + if (berry == 0x2B && IsEnigmaBerryValid()) + return (struct Berry*)(&gSaveBlock1Ptr->enigmaBerry.berry); + else + { + if (berry == 0 || berry > 0x2B) + berry = 1; + return &gBerries[berry - 1]; + } +} + +struct BerryTree *GetBerryTreeInfo(u8 id) +{ + return &gSaveBlock1Ptr->berryTrees[id]; +} + +bool32 FieldObjectInteractionWaterBerryTree(void) +{ + struct BerryTree *tree = GetBerryTreeInfo(FieldObjectGetBerryTreeId(gSelectedMapObject)); + + switch (tree->stage) + { + case 1: + tree->watered1 = TRUE; + break; + case 2: + tree->watered2 = TRUE; + break; + case 3: + tree->watered3 = TRUE; + break; + case 4: + tree->watered4 = TRUE; + break; + default: + return FALSE; + } + return TRUE; +} + +bool8 IsPlayerFacingPlantedBerryTree(void) +{ + if (GetFieldObjectScriptPointerForComparison() == BerryTreeScript + && GetStageByBerryTreeId(FieldObjectGetBerryTreeId(gSelectedMapObject)) == 0) + return TRUE; + else + return FALSE; +} + +bool8 TryToWaterBerryTree(void) +{ + if (GetFieldObjectScriptPointerForComparison() != BerryTreeScript) + return FALSE; + else + return FieldObjectInteractionWaterBerryTree(); +} + +void ClearBerryTrees(void) +{ + int i; + + for (i = 0; i < BERRY_TREES_COUNT; i++) + gSaveBlock1Ptr->berryTrees[i] = gBlankBerryTree; +} + +bool32 BerryTreeGrow(struct BerryTree *tree) +{ + if (tree->growthSparkle) + return FALSE; + switch (tree->stage) + { + case 0: + return FALSE; + case 4: + tree->berryYield = CalcBerryYield(tree); + case 1: + case 2: + case 3: + tree->stage++; + break; + case 5: + tree->watered1 = 0; + tree->watered2 = 0; + tree->watered3 = 0; + tree->watered4 = 0; + tree->berryYield = 0; + tree->stage = 2; + if (++tree->regrowthCount == 10) + *tree = gBlankBerryTree; + break; + } + return TRUE; +} + +void BerryTreeTimeUpdate(s32 minutes) +{ + int i; + struct BerryTree *tree; + + for (i = 0; i < BERRY_TREES_COUNT; i++) + { + tree = &gSaveBlock1Ptr->berryTrees[i]; + + if (tree->berry && tree->stage && !tree->growthSparkle) + { + if (minutes >= GetStageDurationByBerryType(tree->berry) * 71) + { + *tree = gBlankBerryTree; + } + else + { + s32 time = minutes; + + while (time != 0) + { + if (tree->minutesUntilNextStage > time) + { + tree->minutesUntilNextStage -= time; + break; + } + time -= tree->minutesUntilNextStage; + tree->minutesUntilNextStage = GetStageDurationByBerryType(tree->berry); + if (!BerryTreeGrow(tree)) + break; + if (tree->stage == 5) + tree->minutesUntilNextStage *= 4; + } + } + } + } +} + +void PlantBerryTree(u8 id, u8 berry, u8 stage, bool8 sparkle) +{ + struct BerryTree *tree = GetBerryTreeInfo(id); + + *tree = gBlankBerryTree; + tree->berry = berry; + tree->minutesUntilNextStage = GetStageDurationByBerryType(berry); + tree->stage = stage; + if (stage == 5) + { + tree->berryYield = CalcBerryYield(tree); + tree->minutesUntilNextStage *= 4; + } + if (!sparkle) + { + tree->growthSparkle = TRUE; + } +} + +void RemoveBerryTree(u8 id) +{ + gSaveBlock1Ptr->berryTrees[id] = gBlankBerryTree; +} + +u8 GetBerryTypeByBerryTreeId(u8 id) +{ + return gSaveBlock1Ptr->berryTrees[id].berry; +} + +u8 GetStageByBerryTreeId(u8 id) +{ + return gSaveBlock1Ptr->berryTrees[id].stage; +} + +u8 ItemIdToBerryType(u16 item) +{ + u16 berry = item - FIRST_BERRY; + + if (berry > LAST_BERRY - FIRST_BERRY) + return 1; + else + return item - FIRST_BERRY + 1; +} + +u16 BerryTypeToItemId(u16 berry) +{ + u16 item = berry - 1; + + if (item > LAST_BERRY - FIRST_BERRY) + return FIRST_BERRY; + else + return berry + FIRST_BERRY - 1; +} + +void GetBerryNameByBerryType(u8 berry, u8 *string) +{ + memcpy(string, GetBerryInfo(berry)->name, BERRY_NAME_LENGTH); + string[BERRY_NAME_LENGTH] = EOS; +} + +void GetBerryCountStringByBerryType(u8 berry, u8* dest, u32 berryCount) +{ + GetBerryCountString(dest, GetBerryInfo(berry)->name, berryCount); +} + +void ResetBerryTreeSparkleFlag(u8 id) +{ + GetBerryTreeInfo(id)->growthSparkle = 0; +} + +u8 BerryTreeGetNumStagesWatered(struct BerryTree *tree) +{ + u8 count = 0; + + if (tree->watered1) + count++; + if (tree->watered2) + count++; + if (tree->watered3) + count++; + if (tree->watered4) + count++; + return count; +} + +u8 GetNumStagesWateredByBerryTreeId(u8 id) +{ + return BerryTreeGetNumStagesWatered(GetBerryTreeInfo(id)); +} + +u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) +{ + u32 randMin; + u32 randMax; + u32 rand; + u32 extraYield; + + if (water == 0) + return min; + else + { + randMin = (max - min) * (water - 1); + randMax = (max - min) * (water); + rand = randMin + Random() % (randMax - randMin + 1); + + if ((rand & 3) > 1) + extraYield = rand / 4 + 1; + else + extraYield = rand / 4; + return extraYield + min; + } +} + +u8 CalcBerryYield(struct BerryTree *tree) +{ + const struct Berry *berry = GetBerryInfo(tree->berry); + u8 min = berry->minYield; + u8 max = berry->maxYield; + + return CalcBerryYieldInternal(max, min, BerryTreeGetNumStagesWatered(tree)); +} + +u8 GetBerryCountByBerryTreeId(u8 id) +{ + return gSaveBlock1Ptr->berryTrees[id].berryYield; +} + +u16 GetStageDurationByBerryType(u8 berry) +{ + return GetBerryInfo(berry)->stageDuration * 60; +} + +void FieldObjectInteractionGetBerryTreeData(void) +{ + u8 id; + u8 berry; + u8 unk; + u8 group; + u8 num; + + id = FieldObjectGetBerryTreeId(gSelectedMapObject); + berry = GetBerryTypeByBerryTreeId(id); + ResetBerryTreeSparkleFlag(id); + unk = gScriptLastTalked; + num = gSaveBlock1Ptr->location.mapNum; + group = gSaveBlock1Ptr->location.mapGroup; + if (sub_8092E9C(unk, num, group)) + gSpecialVar_0x8004 = 0xFF; + else + gSpecialVar_0x8004 = GetStageByBerryTreeId(id); + gSpecialVar_0x8005 = GetNumStagesWateredByBerryTreeId(id); + gSpecialVar_0x8006 = GetBerryCountByBerryTreeId(id); + GetBerryCountStringByBerryType(berry, gStringVar1, gSpecialVar_0x8006); +} + +void FieldObjectInteractionGetBerryName(void) +{ + u8 berryType = GetBerryTypeByBerryTreeId(FieldObjectGetBerryTreeId(gSelectedMapObject)); + GetBerryNameByBerryType(berryType, gStringVar1); +} + +void FieldObjectInteractionGetBerryCountString(void) +{ + u8 treeId = FieldObjectGetBerryTreeId(gSelectedMapObject); + u8 berry = GetBerryTypeByBerryTreeId(treeId); + u8 count = GetBerryCountByBerryTreeId(treeId); + GetBerryCountStringByBerryType(berry, gStringVar1, count); +} + +void Bag_ChooseBerry(void) +{ + SetMainCallback2(CB2_ChooseBerry); +} + +void FieldObjectInteractionPlantBerryTree(void) +{ + u8 berry = ItemIdToBerryType(gScriptItemId); + + PlantBerryTree(FieldObjectGetBerryTreeId(gSelectedMapObject), berry, 1, TRUE); + FieldObjectInteractionGetBerryTreeData(); +} + +void FieldObjectInteractionPickBerryTree(void) +{ + u8 id = FieldObjectGetBerryTreeId(gSelectedMapObject); + u8 berry = GetBerryTypeByBerryTreeId(id); + + gSpecialVar_0x8004 = AddBagItem(BerryTypeToItemId(berry), GetBerryCountByBerryTreeId(id)); +} + +void FieldObjectInteractionRemoveBerryTree(void) +{ + RemoveBerryTree(FieldObjectGetBerryTreeId(gSelectedMapObject)); + sub_8092EF0(gScriptLastTalked, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); +} + +u8 PlayerHasBerries(void) +{ + return IsBagPocketNonEmpty(BAG_BERRIES); +} + +void ResetBerryTreeSparkleFlags(void) +{ + s16 cam_left; + s16 cam_top; + s16 left; + s16 top; + s16 right; + s16 bottom; + int i; + + GetCameraCoords(&cam_left, &cam_top); + left = cam_left; + top = cam_top + 3; + right = cam_left + 14; + bottom = top + 8; + for (i = 0; i < MAP_OBJECTS_COUNT; i++) + { + if (gMapObjects[i].active && gMapObjects[i].animPattern == 12) + { + cam_left = gMapObjects[i].coords2.x; + cam_top = gMapObjects[i].coords2.y; + if (left <= cam_left && cam_left <= right && top <= cam_top && cam_top <= bottom) + ResetBerryTreeSparkleFlag(gMapObjects[i].trainerRange_berryTreeId); + } + } +} diff --git a/src/decompress.c b/src/decompress.c index befdbaba2..2863ff1f5 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -3,14 +3,13 @@ #include "species.h" #include "text.h" #include "malloc.h" +#include "pokemon.h" EWRAM_DATA ALIGNED(4) u8 gDecompressionBuffer[0x4000] = {0}; extern const struct CompressedSpriteSheet gMonFrontPicTable[]; extern const struct CompressedSpriteSheet gMonBackPicTable[]; -extern void DrawSpindaSpots(u16 species, u32 personality, void* dest, bool8 isFrontPic); - static void DuplicateDeoxysTiles(void *pointer, s32 species); void LZDecompressWram(const void *src, void *dest) diff --git a/src/item.c b/src/item.c index 4ad70e11f..c85e2fe1f 100644 --- a/src/item.c +++ b/src/item.c @@ -1,5 +1,6 @@ #include "global.h" #include "item.h" +#include "items.h" #include "string_util.h" #include "text.h" #include "event_data.h" @@ -86,10 +87,10 @@ void CopyItemName(u16 itemId, u8 *string) void CopyItemNameHandlePlural(u16 itemId, u8 *string, u32 quantity) { - if (itemId == 4) + if (itemId == ITEM_POKE_BALL) { if (quantity < 2) - StringCopy(string, ItemId_GetItem(4)->name); + StringCopy(string, ItemId_GetItem(ITEM_POKE_BALL)->name); else StringCopy(string, gOtherText_PokeBalls); } diff --git a/src/pokemon_1.c b/src/pokemon_1.c index e28c56252..fe7809826 100644 --- a/src/pokemon_1.c +++ b/src/pokemon_1.c @@ -296,7 +296,73 @@ void sub_806819C(struct Pokemon *mon, struct UnknownPokemonStruct *src) StripExtCtrlCodes(nickname); } else + { language = GAME_LANGUAGE; + } + + SetMonData(mon, MON_DATA_LANGUAGE, &language); + SetMonData(mon, MON_DATA_NICKNAME, nickname); + SetMonData(mon, MON_DATA_HP_EV, &src->hpEV); + SetMonData(mon, MON_DATA_ATK_EV, &src->attackEV); + SetMonData(mon, MON_DATA_DEF_EV, &src->defenseEV); + SetMonData(mon, MON_DATA_SPD_EV, &src->speedEV); + SetMonData(mon, MON_DATA_SPATK_EV, &src->spAttackEV); + SetMonData(mon, MON_DATA_SPDEF_EV, &src->spDefenseEV); + value = src->altAbility; + SetMonData(mon, MON_DATA_ALT_ABILITY, &value); + value = src->hpIV; + SetMonData(mon, MON_DATA_HP_IV, &value); + value = src->attackIV; + SetMonData(mon, MON_DATA_ATK_IV, &value); + value = src->defenseIV; + SetMonData(mon, MON_DATA_DEF_IV, &value); + value = src->speedIV; + SetMonData(mon, MON_DATA_SPD_IV, &value); + value = src->spAttackIV; + SetMonData(mon, MON_DATA_SPATK_IV, &value); + value = src->spDefenseIV; + SetMonData(mon, MON_DATA_SPDEF_IV, &value); + MonRestorePP(mon); + CalculateMonStats(mon); +} + +u8 BattleFrontierGetOpponentLvl(u8); + +void sub_8068338(struct Pokemon *mon, struct UnknownPokemonStruct *src, bool8 lvl50) +{ + s32 i; + u8 nickname[30]; + u8 level; + u8 language; + u8 value; + + if (gSaveBlock2Ptr->frontierChosenLvl != 0) + level = BattleFrontierGetOpponentLvl(gSaveBlock2Ptr->frontierChosenLvl); + else if (lvl50) + level = 50; + else + level = src->level; + + CreateMon(mon, src->species, level, 0, 1, src->personality, 1, src->otId); + + for (i = 0; i < 4; i++) + SetMonMoveSlot(mon, src->moves[i], i); + + SetMonData(mon, MON_DATA_PP_BONUSES, &src->ppBonuses); + SetMonData(mon, MON_DATA_HELD_ITEM, &src->heldItem); + SetMonData(mon, MON_DATA_FRIENDSHIP, &src->friendship); + + StringCopy(nickname, src->nickname); + + if (nickname[0] == EXT_CTRL_CODE_BEGIN && nickname[1] == EXT_CTRL_CODE_JPN) + { + language = LANGUAGE_JAPANESE; + StripExtCtrlCodes(nickname); + } + else + { + language = GAME_LANGUAGE; + } SetMonData(mon, MON_DATA_LANGUAGE, &language); SetMonData(mon, MON_DATA_NICKNAME, nickname); diff --git a/src/pokemon_2.c b/src/pokemon_2.c index d50853383..9549a6dcd 100644 --- a/src/pokemon_2.c +++ b/src/pokemon_2.c @@ -1,4 +1,1372 @@ #include "global.h" #include "pokemon.h" +#include "battle.h" +#include "event_data.h" +#include "rng.h" +#include "sprite.h" +#include "species.h" +#include "text.h" +#include "string_util.h" +struct Unknown_020249B4 +{ + u8 unk0[0xC]; + struct SpriteTemplate* templates; +}; +extern u8 gAbsentBankFlags; +extern u8 gActiveBank; +extern u8 gBankAttacker; +extern u8 gBankTarget; +extern u8 gLastUsedAbility; +extern u16 gTrainerBattleOpponent_A; +extern u32 gBattleTypeFlags; +extern struct SpriteTemplate gUnknown_0202499C; +extern struct Unknown_020249B4* gUnknown_020249B4[2]; + +extern const u32 gBitTable[]; +extern const struct SpriteTemplate gUnknown_08329D98[]; +extern const struct SpriteTemplate gUnknown_08329DF8[]; +extern const union AnimCmd* gUnknown_082FF70C[]; +extern const union AnimCmd* const * const gUnknown_08309AAC[]; +extern const union AnimCmd* const * const gUnknown_08305D0C[]; +extern const union AnimCmd* const * const gUnknown_0830536C[]; +extern const u8 gBadEggNickname[]; +extern const u8 gEggNickname[]; + +extern u8 GetBankSide(u8 bank); +extern u8 GetBankByPlayerAI(u8 bank); +extern u8 GetBankIdentity(u8 bank); + +u8 CountAliveMonsInBattle(u8 caseId) +{ + s32 i; + u8 retVal = 0; + + switch (caseId) + { + case BATTLE_ALIVE_EXCEPT_ACTIVE: + for (i = 0; i < 4; i++) + { + if (i != gActiveBank && !(gAbsentBankFlags & gBitTable[i])) + retVal++; + } + break; + case BATTLE_ALIVE_ATK_SIDE: + for (i = 0; i < 4; i++) + { + if (GetBankSide(i) == GetBankSide(gBankAttacker) && !(gAbsentBankFlags & gBitTable[i])) + retVal++; + } + break; + case BATTLE_ALIVE_DEF_SIDE: + for (i = 0; i < 4; i++) + { + if (GetBankSide(i) == GetBankSide(gBankTarget) && !(gAbsentBankFlags & gBitTable[i])) + retVal++; + } + break; + } + + return retVal; +} + +bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 bank) +{ + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_x2000000 | BATTLE_TYPE_FRONTIER)) + return FALSE; + if (GetBankSide(bank) != SIDE_PLAYER) + return FALSE; + if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == SECRET_BASE_OPPONENT) + return FALSE; + if (FlagGet(badgeFlag)) + return TRUE; + return FALSE; +} + +u8 sub_8069F34(u8 bank) +{ + u8 status = GetBankIdentity(bank) & 1; + + status ^= 1; + if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) + return GetBankByPlayerAI(status); + if (CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_ACTIVE) > 1) + { + u8 val; + + if ((Random() & 1) == 0) + val = status ^ 2; + else + val = status; + return GetBankByPlayerAI(val); + } + else + { + if ((gAbsentBankFlags & gBitTable[status])) + return GetBankByPlayerAI(status ^ 2); + else + return GetBankByPlayerAI(status); + } +} + +u8 GetMonGender(struct Pokemon *mon) +{ + return GetBoxMonGender(&mon->box); +} + +u8 GetBoxMonGender(struct BoxPokemon *boxMon) +{ + u16 species = GetBoxMonData(boxMon, MON_DATA_SPECIES, NULL); + u32 personality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY, NULL); + + switch (gBaseStats[species].genderRatio) + { + case MON_MALE: + case MON_FEMALE: + case MON_GENDERLESS: + return gBaseStats[species].genderRatio; + } + + if (gBaseStats[species].genderRatio > (personality & 0xFF)) + return MON_FEMALE; + else + return MON_MALE; +} + +u8 GetGenderFromSpeciesAndPersonality(u16 species, u32 personality) +{ + switch (gBaseStats[species].genderRatio) + { + case MON_MALE: + case MON_FEMALE: + case MON_GENDERLESS: + return gBaseStats[species].genderRatio; + } + + if (gBaseStats[species].genderRatio > (personality & 0xFF)) + return MON_FEMALE; + else + return MON_MALE; +} + +void sub_806A068(u16 species, u8 bankIdentity) +{ + if (gBattleSpritesGfx != NULL) + gUnknown_0202499C = gBattleSpritesGfx->templates[bankIdentity]; + else if (gUnknown_020249B4[0]) + gUnknown_0202499C = gUnknown_020249B4[0]->templates[bankIdentity]; + else if (gUnknown_020249B4[1]) + gUnknown_0202499C = gUnknown_020249B4[1]->templates[bankIdentity]; + else + gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; + + gUnknown_0202499C.paletteTag = species; + if (bankIdentity == 0 || bankIdentity == 2) + gUnknown_0202499C.anims = gUnknown_082FF70C; + else if (species > 500) + gUnknown_0202499C.anims = gUnknown_08309AAC[species - 500]; + else + gUnknown_0202499C.anims = gUnknown_08309AAC[species]; +} + +void sub_806A12C(u16 trainerSpriteId, u8 bankIdentity) +{ + gUnknown_0202499C.paletteTag = trainerSpriteId; + if (bankIdentity == 0 || bankIdentity == 2) + { + gUnknown_0202499C = gUnknown_08329DF8[trainerSpriteId]; + gUnknown_0202499C.anims = gUnknown_08305D0C[trainerSpriteId]; + } + else + { + if (gBattleSpritesGfx != NULL) + gUnknown_0202499C = gBattleSpritesGfx->templates[bankIdentity]; + else + gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; + gUnknown_0202499C.anims = gUnknown_0830536C[trainerSpriteId]; + } +} + +void sub_806A1C0(u16 arg0, u8 bankIdentity) +{ + if (gBattleSpritesGfx != NULL) + gUnknown_0202499C = gBattleSpritesGfx->templates[bankIdentity]; + else + gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; + gUnknown_0202499C.paletteTag = arg0; + gUnknown_0202499C.anims = gUnknown_0830536C[arg0]; +} + +void EncryptBoxMon(struct BoxPokemon *boxMon) +{ + u32 i; + for (i = 0; i < 12; i++) + { + boxMon->secure.raw[i] ^= boxMon->personality; + boxMon->secure.raw[i] ^= boxMon->otId; + } +} + +void DecryptBoxMon(struct BoxPokemon *boxMon) +{ + u32 i; + for (i = 0; i < 12; i++) + { + boxMon->secure.raw[i] ^= boxMon->otId; + boxMon->secure.raw[i] ^= boxMon->personality; + } +} + +#define SUBSTRUCT_CASE(n, v1, v2, v3, v4) \ +case n: \ + { \ + union PokemonSubstruct *substructs0 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs1 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs2 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs3 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs4 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs5 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs6 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs7 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs8 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs9 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs10 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs11 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs12 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs13 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs14 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs15 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs16 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs17 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs18 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs19 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs20 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs21 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs22 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs23 = boxMon->secure.substructs; \ + \ + switch (substructType) \ + { \ + case 0: \ + substruct = &substructs ## n [v1]; \ + break; \ + case 1: \ + substruct = &substructs ## n [v2]; \ + break; \ + case 2: \ + substruct = &substructs ## n [v3]; \ + break; \ + case 3: \ + substruct = &substructs ## n [v4]; \ + break; \ + } \ + break; \ + } \ + + +union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u8 substructType) +{ + union PokemonSubstruct *substruct = NULL; + + switch (personality % 24) + { + SUBSTRUCT_CASE( 0,0,1,2,3) + SUBSTRUCT_CASE( 1,0,1,3,2) + SUBSTRUCT_CASE( 2,0,2,1,3) + SUBSTRUCT_CASE( 3,0,3,1,2) + SUBSTRUCT_CASE( 4,0,2,3,1) + SUBSTRUCT_CASE( 5,0,3,2,1) + SUBSTRUCT_CASE( 6,1,0,2,3) + SUBSTRUCT_CASE( 7,1,0,3,2) + SUBSTRUCT_CASE( 8,2,0,1,3) + SUBSTRUCT_CASE( 9,3,0,1,2) + SUBSTRUCT_CASE(10,2,0,3,1) + SUBSTRUCT_CASE(11,3,0,2,1) + SUBSTRUCT_CASE(12,1,2,0,3) + SUBSTRUCT_CASE(13,1,3,0,2) + SUBSTRUCT_CASE(14,2,1,0,3) + SUBSTRUCT_CASE(15,3,1,0,2) + SUBSTRUCT_CASE(16,2,3,0,1) + SUBSTRUCT_CASE(17,3,2,0,1) + SUBSTRUCT_CASE(18,1,2,3,0) + SUBSTRUCT_CASE(19,1,3,2,0) + SUBSTRUCT_CASE(20,2,1,3,0) + SUBSTRUCT_CASE(21,3,1,2,0) + SUBSTRUCT_CASE(22,2,3,1,0) + SUBSTRUCT_CASE(23,3,2,1,0) + } + + return substruct; +} + +extern u16 GetDeoxysStat(struct Pokemon *mon, s32 statId); + +u32 GetMonData(struct Pokemon *mon, s32 field, u8* data) +{ + u32 ret; + + switch (field) + { + case MON_DATA_STATUS: + ret = mon->status; + break; + case MON_DATA_LEVEL: + ret = mon->level; + break; + case MON_DATA_HP: + ret = mon->hp; + break; + case MON_DATA_MAX_HP: + ret = mon->maxHP; + break; + case MON_DATA_ATK: + ret = GetDeoxysStat(mon, STAT_ATK); + if (!ret) + ret = mon->attack; + break; + case MON_DATA_DEF: + ret = GetDeoxysStat(mon, STAT_DEF); + if (!ret) + ret = mon->defense; + break; + case MON_DATA_SPD: + ret = GetDeoxysStat(mon, STAT_SPD); + if (!ret) + ret = mon->speed; + break; + case MON_DATA_SPATK: + ret = GetDeoxysStat(mon, STAT_SPATK); + if (!ret) + ret = mon->spAttack; + break; + case MON_DATA_SPDEF: + ret = GetDeoxysStat(mon, STAT_SPDEF); + if (!ret) + ret = mon->spDefense; + break; + case MON_DATA_ATK2: + ret = mon->attack; + break; + case MON_DATA_DEF2: + ret = mon->defense; + break; + case MON_DATA_SPD2: + ret = mon->speed; + break; + case MON_DATA_SPATK2: + ret = mon->spAttack; + break; + case MON_DATA_SPDEF2: + ret = mon->spDefense; + break; + case MON_DATA_MAIL: + ret = mon->mail; + break; + default: + ret = GetBoxMonData(&mon->box, field, data); + break; + } + return ret; +} + +u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) +{ + s32 i; + u32 retVal = 0; + struct PokemonSubstruct0 *substruct0 = NULL; + struct PokemonSubstruct1 *substruct1 = NULL; + struct PokemonSubstruct2 *substruct2 = NULL; + struct PokemonSubstruct3 *substruct3 = NULL; + + if (field > MON_DATA_10) + { + substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); + substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); + substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2); + substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3); + + DecryptBoxMon(boxMon); + + if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum) + { + boxMon->isBadEgg = 1; + boxMon->isEgg = 1; + substruct3->isEgg = 1; + } + } + + switch (field) + { + case MON_DATA_PERSONALITY: + retVal = boxMon->personality; + break; + case MON_DATA_OT_ID: + retVal = boxMon->otId; + break; + case MON_DATA_NICKNAME: + { + if (boxMon->isBadEgg) + { + for (retVal = 0; + retVal < POKEMON_NAME_LENGTH && gBadEggNickname[retVal] != EOS; + data[retVal] = gBadEggNickname[retVal], retVal++) {} + + data[retVal] = EOS; + } + else if (boxMon->isEgg) + { + StringCopy(data, gEggNickname); + retVal = StringLength(data); + } + else if (boxMon->language == LANGUAGE_JAPANESE) + { + data[0] = EXT_CTRL_CODE_BEGIN; + data[1] = EXT_CTRL_CODE_JPN; + + for (retVal = 2, i = 0; + i < 5 && boxMon->nickname[i] != EOS; + data[retVal] = boxMon->nickname[i], retVal++, i++) {} + + data[retVal++] = EXT_CTRL_CODE_BEGIN; + data[retVal++] = EXT_CTRL_CODE_ENG; + data[retVal] = EOS; + } + else + { + for (retVal = 0; + retVal < POKEMON_NAME_LENGTH; + data[retVal] = boxMon->nickname[retVal], retVal++){} + + data[retVal] = EOS; + } + break; + } + case MON_DATA_LANGUAGE: + retVal = boxMon->language; + break; + case MON_DATA_SANITY_BIT1: + retVal = boxMon->isBadEgg; + break; + case MON_DATA_SANITY_BIT2: + retVal = boxMon->hasSpecies; + break; + case MON_DATA_SANITY_BIT3: + retVal = boxMon->isEgg; + break; + case MON_DATA_OT_NAME: + { + retVal = 0; + + while (retVal < OT_NAME_LENGTH) + { + data[retVal] = boxMon->otName[retVal]; + retVal++; + } + + data[retVal] = EOS; + break; + } + case MON_DATA_MARKINGS: + retVal = boxMon->markings; + break; + case MON_DATA_CHECKSUM: + retVal = boxMon->checksum; + break; + case MON_DATA_10: + retVal = boxMon->unknown; + break; + case MON_DATA_SPECIES: + retVal = boxMon->isBadEgg ? SPECIES_EGG : substruct0->species; + break; + case MON_DATA_HELD_ITEM: + retVal = substruct0->heldItem; + break; + case MON_DATA_EXP: + retVal = substruct0->experience; + break; + case MON_DATA_PP_BONUSES: + retVal = substruct0->ppBonuses; + break; + case MON_DATA_FRIENDSHIP: + retVal = substruct0->friendship; + break; + case MON_DATA_MOVE1: + case MON_DATA_MOVE2: + case MON_DATA_MOVE3: + case MON_DATA_MOVE4: + retVal = substruct1->moves[field - MON_DATA_MOVE1]; + break; + case MON_DATA_PP1: + case MON_DATA_PP2: + case MON_DATA_PP3: + case MON_DATA_PP4: + retVal = substruct1->pp[field - MON_DATA_PP1]; + break; + case MON_DATA_HP_EV: + retVal = substruct2->hpEV; + break; + case MON_DATA_ATK_EV: + retVal = substruct2->attackEV; + break; + case MON_DATA_DEF_EV: + retVal = substruct2->defenseEV; + break; + case MON_DATA_SPD_EV: + retVal = substruct2->speedEV; + break; + case MON_DATA_SPATK_EV: + retVal = substruct2->spAttackEV; + break; + case MON_DATA_SPDEF_EV: + retVal = substruct2->spDefenseEV; + break; + case MON_DATA_COOL: + retVal = substruct2->cool; + break; + case MON_DATA_BEAUTY: + retVal = substruct2->beauty; + break; + case MON_DATA_CUTE: + retVal = substruct2->cute; + break; + case MON_DATA_SMART: + retVal = substruct2->smart; + break; + case MON_DATA_TOUGH: + retVal = substruct2->tough; + break; + case MON_DATA_SHEEN: + retVal = substruct2->sheen; + break; + case MON_DATA_POKERUS: + retVal = substruct3->pokerus; + break; + case MON_DATA_MET_LOCATION: + retVal = substruct3->metLocation; + break; + case MON_DATA_MET_LEVEL: + retVal = substruct3->metLevel; + break; + case MON_DATA_MET_GAME: + retVal = substruct3->metGame; + break; + case MON_DATA_POKEBALL: + retVal = substruct3->pokeball; + break; + case MON_DATA_OT_GENDER: + retVal = substruct3->otGender; + break; + case MON_DATA_HP_IV: + retVal = substruct3->hpIV; + break; + case MON_DATA_ATK_IV: + retVal = substruct3->attackIV; + break; + case MON_DATA_DEF_IV: + retVal = substruct3->defenseIV; + break; + case MON_DATA_SPD_IV: + retVal = substruct3->speedIV; + break; + case MON_DATA_SPATK_IV: + retVal = substruct3->spAttackIV; + break; + case MON_DATA_SPDEF_IV: + retVal = substruct3->spDefenseIV; + break; + case MON_DATA_IS_EGG: + retVal = substruct3->isEgg; + break; + case MON_DATA_ALT_ABILITY: + retVal = substruct3->altAbility; + break; + case MON_DATA_COOL_RIBBON: + retVal = substruct3->coolRibbon; + break; + case MON_DATA_BEAUTY_RIBBON: + retVal = substruct3->beautyRibbon; + break; + case MON_DATA_CUTE_RIBBON: + retVal = substruct3->cuteRibbon; + break; + case MON_DATA_SMART_RIBBON: + retVal = substruct3->smartRibbon; + break; + case MON_DATA_TOUGH_RIBBON: + retVal = substruct3->toughRibbon; + break; + case MON_DATA_CHAMPION_RIBBON: + retVal = substruct3->championRibbon; + break; + case MON_DATA_WINNING_RIBBON: + retVal = substruct3->winningRibbon; + break; + case MON_DATA_VICTORY_RIBBON: + retVal = substruct3->victoryRibbon; + break; + case MON_DATA_ARTIST_RIBBON: + retVal = substruct3->artistRibbon; + break; + case MON_DATA_EFFORT_RIBBON: + retVal = substruct3->effortRibbon; + break; + case MON_DATA_GIFT_RIBBON_1: + retVal = substruct3->giftRibbon1; + break; + case MON_DATA_GIFT_RIBBON_2: + retVal = substruct3->giftRibbon2; + break; + case MON_DATA_GIFT_RIBBON_3: + retVal = substruct3->giftRibbon3; + break; + case MON_DATA_GIFT_RIBBON_4: + retVal = substruct3->giftRibbon4; + break; + case MON_DATA_GIFT_RIBBON_5: + retVal = substruct3->giftRibbon5; + break; + case MON_DATA_GIFT_RIBBON_6: + retVal = substruct3->giftRibbon6; + break; + case MON_DATA_GIFT_RIBBON_7: + retVal = substruct3->giftRibbon7; + break; + case MON_DATA_FATEFUL_ENCOUNTER: + retVal = substruct3->fatefulEncounter; + break; + case MON_DATA_OBEDIENCE: + retVal = substruct3->obedient; + break; + case MON_DATA_SPECIES2: + retVal = substruct0->species; + if (substruct0->species && (substruct3->isEgg || boxMon->isBadEgg)) + retVal = SPECIES_EGG; + break; + case MON_DATA_IVS: + retVal = substruct3->hpIV | (substruct3->attackIV << 5) | (substruct3->defenseIV << 10) | (substruct3->speedIV << 15) | (substruct3->spAttackIV << 20) | (substruct3->spDefenseIV << 25); + break; + case MON_DATA_KNOWN_MOVES: + if (substruct0->species && !substruct3->isEgg) + { + u16 *moves = (u16 *)data; + s32 i = 0; + + while (moves[i] != 355) + { + u16 move = moves[i]; + if (substruct1->moves[0] == move + || substruct1->moves[1] == move + || substruct1->moves[2] == move + || substruct1->moves[3] == move) + retVal |= gBitTable[i]; + i++; + } + } + break; + case MON_DATA_RIBBON_COUNT: + retVal = 0; + if (substruct0->species && !substruct3->isEgg) + { + retVal += substruct3->coolRibbon; + retVal += substruct3->beautyRibbon; + retVal += substruct3->cuteRibbon; + retVal += substruct3->smartRibbon; + retVal += substruct3->toughRibbon; + retVal += substruct3->championRibbon; + retVal += substruct3->winningRibbon; + retVal += substruct3->victoryRibbon; + retVal += substruct3->artistRibbon; + retVal += substruct3->effortRibbon; + retVal += substruct3->giftRibbon1; + retVal += substruct3->giftRibbon2; + retVal += substruct3->giftRibbon3; + retVal += substruct3->giftRibbon4; + retVal += substruct3->giftRibbon5; + retVal += substruct3->giftRibbon6; + retVal += substruct3->giftRibbon7; + } + break; + case MON_DATA_RIBBONS: + retVal = 0; + if (substruct0->species && !substruct3->isEgg) + { + retVal = substruct3->championRibbon + | (substruct3->coolRibbon << 1) + | (substruct3->beautyRibbon << 4) + | (substruct3->cuteRibbon << 7) + | (substruct3->smartRibbon << 10) + | (substruct3->toughRibbon << 13) + | (substruct3->winningRibbon << 16) + | (substruct3->victoryRibbon << 17) + | (substruct3->artistRibbon << 18) + | (substruct3->effortRibbon << 19) + | (substruct3->giftRibbon1 << 20) + | (substruct3->giftRibbon2 << 21) + | (substruct3->giftRibbon3 << 22) + | (substruct3->giftRibbon4 << 23) + | (substruct3->giftRibbon5 << 24) + | (substruct3->giftRibbon6 << 25) + | (substruct3->giftRibbon7 << 26); + } + break; + default: + break; + } + + if (field > MON_DATA_10) + EncryptBoxMon(boxMon); + + return retVal; +} + +#define SET8(lhs) (lhs) = *data +#define SET16(lhs) (lhs) = data[0] + (data[1] << 8) +#define SET32(lhs) (lhs) = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24) + +void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg) +{ + const u8* data = dataArg; + switch (field) + { + case MON_DATA_STATUS: + SET32(mon->status); + break; + case MON_DATA_LEVEL: + SET8(mon->level); + break; + case MON_DATA_HP: + SET16(mon->hp); + break; + case MON_DATA_MAX_HP: + SET16(mon->maxHP); + break; + case MON_DATA_ATK: + SET16(mon->attack); + break; + case MON_DATA_DEF: + SET16(mon->defense); + break; + case MON_DATA_SPD: + SET16(mon->speed); + break; + case MON_DATA_SPATK: + SET16(mon->spAttack); + break; + case MON_DATA_SPDEF: + SET16(mon->spDefense); + break; + case MON_DATA_MAIL: + SET8(mon->mail); + break; + case MON_DATA_SPECIES2: + break; + default: + SetBoxMonData(&mon->box, field, data); + break; + } +} + +void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) +{ + const u8* data = dataArg; + + struct PokemonSubstruct0 *substruct0 = NULL; + struct PokemonSubstruct1 *substruct1 = NULL; + struct PokemonSubstruct2 *substruct2 = NULL; + struct PokemonSubstruct3 *substruct3 = NULL; + + if (field > MON_DATA_10) + { + substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); + substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); + substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2); + substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3); + + DecryptBoxMon(boxMon); + + if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum) + { + boxMon->isBadEgg = 1; + boxMon->isEgg = 1; + substruct3->isEgg = 1; + EncryptBoxMon(boxMon); + return; + } + } + + switch (field) + { + case MON_DATA_PERSONALITY: + SET32(boxMon->personality); + break; + case MON_DATA_OT_ID: + SET32(boxMon->otId); + break; + case MON_DATA_NICKNAME: + { + s32 i; + for (i = 0; i < POKEMON_NAME_LENGTH; i++) + boxMon->nickname[i] = data[i]; + break; + } + case MON_DATA_LANGUAGE: + SET8(boxMon->language); + break; + case MON_DATA_SANITY_BIT1: + SET8(boxMon->isBadEgg); + break; + case MON_DATA_SANITY_BIT2: + SET8(boxMon->hasSpecies); + break; + case MON_DATA_SANITY_BIT3: + SET8(boxMon->isEgg); + break; + case MON_DATA_OT_NAME: + { + s32 i; + for (i = 0; i < OT_NAME_LENGTH; i++) + boxMon->otName[i] = data[i]; + break; + } + case MON_DATA_MARKINGS: + SET8(boxMon->markings); + break; + case MON_DATA_CHECKSUM: + SET16(boxMon->checksum); + break; + case MON_DATA_10: + SET16(boxMon->unknown); + break; + case MON_DATA_SPECIES: + { + SET16(substruct0->species); + if (substruct0->species) + boxMon->hasSpecies = 1; + else + boxMon->hasSpecies = 0; + break; + } + case MON_DATA_HELD_ITEM: + SET16(substruct0->heldItem); + break; + case MON_DATA_EXP: + SET32(substruct0->experience); + break; + case MON_DATA_PP_BONUSES: + SET8(substruct0->ppBonuses); + break; + case MON_DATA_FRIENDSHIP: + SET8(substruct0->friendship); + break; + case MON_DATA_MOVE1: + case MON_DATA_MOVE2: + case MON_DATA_MOVE3: + case MON_DATA_MOVE4: + SET16(substruct1->moves[field - MON_DATA_MOVE1]); + break; + case MON_DATA_PP1: + case MON_DATA_PP2: + case MON_DATA_PP3: + case MON_DATA_PP4: + SET8(substruct1->pp[field - MON_DATA_PP1]); + break; + case MON_DATA_HP_EV: + SET8(substruct2->hpEV); + break; + case MON_DATA_ATK_EV: + SET8(substruct2->attackEV); + break; + case MON_DATA_DEF_EV: + SET8(substruct2->defenseEV); + break; + case MON_DATA_SPD_EV: + SET8(substruct2->speedEV); + break; + case MON_DATA_SPATK_EV: + SET8(substruct2->spAttackEV); + break; + case MON_DATA_SPDEF_EV: + SET8(substruct2->spDefenseEV); + break; + case MON_DATA_COOL: + SET8(substruct2->cool); + break; + case MON_DATA_BEAUTY: + SET8(substruct2->beauty); + break; + case MON_DATA_CUTE: + SET8(substruct2->cute); + break; + case MON_DATA_SMART: + SET8(substruct2->smart); + break; + case MON_DATA_TOUGH: + SET8(substruct2->tough); + break; + case MON_DATA_SHEEN: + SET8(substruct2->sheen); + break; + case MON_DATA_POKERUS: + SET8(substruct3->pokerus); + break; + case MON_DATA_MET_LOCATION: + SET8(substruct3->metLocation); + break; + case MON_DATA_MET_LEVEL: + { + u8 metLevel = *data; + substruct3->metLevel = metLevel; + break; + } + case MON_DATA_MET_GAME: + SET8(substruct3->metGame); + break; + case MON_DATA_POKEBALL: + { + u8 pokeball = *data; + substruct3->pokeball = pokeball; + break; + } + case MON_DATA_OT_GENDER: + SET8(substruct3->otGender); + break; + case MON_DATA_HP_IV: + SET8(substruct3->hpIV); + break; + case MON_DATA_ATK_IV: + SET8(substruct3->attackIV); + break; + case MON_DATA_DEF_IV: + SET8(substruct3->defenseIV); + break; + case MON_DATA_SPD_IV: + SET8(substruct3->speedIV); + break; + case MON_DATA_SPATK_IV: + SET8(substruct3->spAttackIV); + break; + case MON_DATA_SPDEF_IV: + SET8(substruct3->spDefenseIV); + break; + case MON_DATA_IS_EGG: + SET8(substruct3->isEgg); + if (substruct3->isEgg) + boxMon->isEgg = 1; + else + boxMon->isEgg = 0; + break; + case MON_DATA_ALT_ABILITY: + SET8(substruct3->altAbility); + break; + case MON_DATA_COOL_RIBBON: + SET8(substruct3->coolRibbon); + break; + case MON_DATA_BEAUTY_RIBBON: + SET8(substruct3->beautyRibbon); + break; + case MON_DATA_CUTE_RIBBON: + SET8(substruct3->cuteRibbon); + break; + case MON_DATA_SMART_RIBBON: + SET8(substruct3->smartRibbon); + break; + case MON_DATA_TOUGH_RIBBON: + SET8(substruct3->toughRibbon); + break; + case MON_DATA_CHAMPION_RIBBON: + SET8(substruct3->championRibbon); + break; + case MON_DATA_WINNING_RIBBON: + SET8(substruct3->winningRibbon); + break; + case MON_DATA_VICTORY_RIBBON: + SET8(substruct3->victoryRibbon); + break; + case MON_DATA_ARTIST_RIBBON: + SET8(substruct3->artistRibbon); + break; + case MON_DATA_EFFORT_RIBBON: + SET8(substruct3->effortRibbon); + break; + case MON_DATA_GIFT_RIBBON_1: + SET8(substruct3->giftRibbon1); + break; + case MON_DATA_GIFT_RIBBON_2: + SET8(substruct3->giftRibbon2); + break; + case MON_DATA_GIFT_RIBBON_3: + SET8(substruct3->giftRibbon3); + break; + case MON_DATA_GIFT_RIBBON_4: + SET8(substruct3->giftRibbon4); + break; + case MON_DATA_GIFT_RIBBON_5: + SET8(substruct3->giftRibbon5); + break; + case MON_DATA_GIFT_RIBBON_6: + SET8(substruct3->giftRibbon6); + break; + case MON_DATA_GIFT_RIBBON_7: + SET8(substruct3->giftRibbon7); + break; + case MON_DATA_FATEFUL_ENCOUNTER: + SET8(substruct3->fatefulEncounter); + break; + case MON_DATA_OBEDIENCE: + SET8(substruct3->obedient); + break; + case MON_DATA_IVS: + { + u32 ivs = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); + substruct3->hpIV = ivs & 0x1F; + substruct3->attackIV = (ivs >> 5) & 0x1F; + substruct3->defenseIV = (ivs >> 10) & 0x1F; + substruct3->speedIV = (ivs >> 15) & 0x1F; + substruct3->spAttackIV = (ivs >> 20) & 0x1F; + substruct3->spDefenseIV = (ivs >> 25) & 0x1F; + break; + } + default: + break; + } + + if (field > MON_DATA_10) + { + boxMon->checksum = CalculateBoxMonChecksum(boxMon); + EncryptBoxMon(boxMon); + } +} + +void CopyMon(void *dest, void *src, size_t size) +{ + memcpy(dest, src, size); +} + +u8 GiveMonToPlayer(struct Pokemon *mon) +{ + s32 i; + + SetMonData(mon, MON_DATA_OT_NAME, gSaveBlock2Ptr->playerName); + SetMonData(mon, MON_DATA_OT_GENDER, &gSaveBlock2Ptr->playerGender); + SetMonData(mon, MON_DATA_OT_ID, gSaveBlock2Ptr->playerTrainerId); + + i = 0; + + while (i < 6 && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + i++; + + if (i >= 6) + return SendMonToPC(mon); + + CopyMon(&gPlayerParty[i], mon, sizeof(*mon)); + gPlayerPartyCount = i + 1; + return MON_GIVEN_TO_PARTY; +} + +extern u16 get_unknown_box_id(void); +extern u8 StorageGetCurrentBox(void); +extern void set_unknown_box_id(u8); +extern struct BoxPokemon* GetBoxedMonPtr(u8 boxNumber, u8 boxPosition); + +u8 SendMonToPC(struct Pokemon* mon) +{ + s32 boxNo, boxPos; + + set_unknown_box_id(VarGet(VAR_STORAGE_UNKNOWN)); + + boxNo = StorageGetCurrentBox(); + + do + { + for (boxPos = 0; boxPos < 30; boxPos++) + { + struct BoxPokemon* checkingMon = GetBoxedMonPtr(boxNo, boxPos); + if (GetBoxMonData(checkingMon, MON_DATA_SPECIES, NULL) == SPECIES_NONE) + { + MonRestorePP(mon); + CopyMon(checkingMon, &mon->box, sizeof(mon->box)); + gSpecialVar_0x8012 = boxNo; + gSpecialVar_0x8013 = boxPos; + if (get_unknown_box_id() != boxNo) + FlagReset(SYS_STORAGE_UNKNOWN_FLAG); + VarSet(VAR_STORAGE_UNKNOWN, boxNo); + return MON_GIVEN_TO_PC; + } + } + + boxNo++; + if (boxNo == 14) + boxNo = 0; + } while (boxNo != StorageGetCurrentBox()); + + return MON_CANT_GIVE; +} + +u8 CalculatePlayerPartyCount(void) +{ + gPlayerPartyCount = 0; + + while (gPlayerPartyCount < 6 + && GetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + { + gPlayerPartyCount++; + } + + return gPlayerPartyCount; +} + +u8 CalculateEnemyPartyCount(void) +{ + gEnemyPartyCount = 0; + + while (gEnemyPartyCount < 6 + && GetMonData(&gEnemyParty[gEnemyPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + { + gEnemyPartyCount++; + } + + return gEnemyPartyCount; +} + +u8 GetMonsStateToDoubles(void) +{ + s32 aliveCount = 0; + s32 i; + CalculatePlayerPartyCount(); + + if (gPlayerPartyCount == 1) + return gPlayerPartyCount; // PLAYER_HAS_ONE_MON + + for (i = 0; i < gPlayerPartyCount; i++) + { + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_EGG + && GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0 + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_NONE) + aliveCount++; + } + + return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON; +} + +u8 GetMonsStateToDoubles_2(void) +{ + s32 aliveCount = 0; + s32 i; + + for (i = 0; i < 6; i++) + { + u32 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL); + if (species != SPECIES_EGG && species != SPECIES_NONE + && GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0) + aliveCount++; + } + + if (aliveCount == 1) + return PLAYER_HAS_ONE_MON; // may have more than one, but only one is alive + + return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON; +} + +u8 GetAbilityBySpecies(u16 species, bool8 altAbility) +{ + if (altAbility) + gLastUsedAbility = gBaseStats[species].ability2; + else + gLastUsedAbility = gBaseStats[species].ability1; + + return gLastUsedAbility; +} + +u8 GetMonAbility(struct Pokemon *mon) +{ + u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); + u8 altAbility = GetMonData(mon, MON_DATA_ALT_ABILITY, NULL); + return GetAbilityBySpecies(species, altAbility); +} + +extern const struct BattleMove gBattleMoves[]; + +void CreateSecretBaseEnemyParty(struct SecretBaseRecord *secretBaseRecord) +{ + s32 i, j; + + ZeroEnemyPartyMons(); + *gBattleResources->secretBase = *secretBaseRecord; + + for (i = 0; i < PARTY_SIZE; i++) + { + if (gBattleResources->secretBase->partySpecies[i]) + { + CreateMon(&gEnemyParty[i], + gBattleResources->secretBase->partySpecies[i], + gBattleResources->secretBase->partyLevels[i], + 15, + 1, + gBattleResources->secretBase->partyPersonality[i], + 2, + 0); + + SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleResources->secretBase->partyHeldItems[i]); + + for (j = 0; j < 6; j++) + SetMonData(&gEnemyParty[i], MON_DATA_HP_EV + j, &gBattleResources->secretBase->partyEVs[i]); + + for (j = 0; j < 4; j++) + { + SetMonData(&gEnemyParty[i], MON_DATA_MOVE1 + j, &gBattleResources->secretBase->partyMoves[i * 4 + j]); + SetMonData(&gEnemyParty[i], MON_DATA_PP1 + j, &gBattleMoves[gBattleResources->secretBase->partyMoves[i * 4 + j]].pp); + } + } + } +} + +extern const u8 gUnknown_0831F578[]; +extern const u8 gTrainerClassToNameIndex[]; +extern const u8 gSecretBaseTrainerClasses[][5]; + +u8 GetSecretBaseTrainerPicIndex(void) +{ + u8 trainerClass = gSecretBaseTrainerClasses[gBattleResources->secretBase->gender][gBattleResources->secretBase->trainerId[0] % 5]; + return gUnknown_0831F578[trainerClass]; +} + +u8 GetSecretBaseTrainerNameIndex(void) +{ + u8 trainerClass = gSecretBaseTrainerClasses[gBattleResources->secretBase->gender][gBattleResources->secretBase->trainerId[0] % 5]; + return gTrainerClassToNameIndex[trainerClass]; +} + +bool8 IsPlayerPartyAndPokemonStorageFull(void) +{ + s32 i; + + for (i = 0; i < 6; i++) + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) == SPECIES_NONE) + return FALSE; + + return IsPokemonStorageFull(); +} + +extern u32 GetBoxMonDataFromAnyBox(u8 boxNo, u8 boxPos, s32 field); + +bool8 IsPokemonStorageFull(void) +{ + s32 i, j; + + for (i = 0; i < 14; i++) + for (j = 0; j < 30; j++) + if (GetBoxMonDataFromAnyBox(i, j, MON_DATA_SPECIES) == SPECIES_NONE) + return FALSE; + + return TRUE; +} + +extern const u8 gSpeciesNames[][POKEMON_NAME_LENGTH + 1]; + +void GetSpeciesName(u8 *name, u16 species) +{ + s32 i; + + for (i = 0; i <= POKEMON_NAME_LENGTH; i++) + { + if (species > NUM_SPECIES) + name[i] = gSpeciesNames[0][i]; + else + name[i] = gSpeciesNames[species][i]; + + if (name[i] == EOS) + break; + } + + name[i] = EOS; +} + +extern const u8 gUnknown_08329D22[]; +extern const u8 gUnknown_08329D26[]; + +u8 CalculatePPWithBonus(u16 move, u8 ppBonuses, u8 moveIndex) +{ + u8 basePP = gBattleMoves[move].pp; + return basePP + ((basePP * 20 * ((gUnknown_08329D22[moveIndex] & ppBonuses) >> (2 * moveIndex))) / 100); +} + +void RemoveMonPPBonus(struct Pokemon *mon, u8 moveIndex) +{ + u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES, NULL); + ppBonuses &= gUnknown_08329D26[moveIndex]; + SetMonData(mon, MON_DATA_PP_BONUSES, &ppBonuses); +} + +void RemoveBattleMonPPBonus(struct BattlePokemon *mon, u8 moveIndex) +{ + mon->ppBonuses &= gUnknown_08329D26[moveIndex]; +} + +void sub_803FA70(u8 bank); +void sub_805EF84(u8 bank, bool8); + +extern struct BattlePokemon gBattleMons[4]; + +/* + +void CopyPlayerPartyMonToBattleData(u8 bank, u8 partyIndex) +{ + s32 i; + u8 nickname[POKEMON_NAME_LENGTH * 2]; + + gBattleMons[bank].species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); + gBattleMons[bank].item = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HELD_ITEM, NULL); + + for (i = 0; i < 4; i++) + { + gBattleMons[bank].moves[i] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MOVE1 + i, NULL); + gBattleMons[bank].pp[i] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PP1 + i, NULL); + } + + gBattleMons[bank].ppBonuses = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PP_BONUSES, NULL); + gBattleMons[bank].friendship = GetMonData(&gPlayerParty[partyIndex], MON_DATA_FRIENDSHIP, NULL); + gBattleMons[bank].experience = GetMonData(&gPlayerParty[partyIndex], MON_DATA_EXP, NULL); + gBattleMons[bank].hpIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HP_IV, NULL); + gBattleMons[bank].attackIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ATK_IV, NULL); + gBattleMons[bank].defenseIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_DEF_IV, NULL); + gBattleMons[bank].speedIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPD_IV, NULL); + gBattleMons[bank].spAttackIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPATK_IV, NULL); + gBattleMons[bank].spDefenseIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPDEF_IV, NULL); + gBattleMons[bank].personality = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PERSONALITY, NULL); + gBattleMons[bank].status1 = GetMonData(&gPlayerParty[partyIndex], MON_DATA_STATUS, NULL); + gBattleMons[bank].level = GetMonData(&gPlayerParty[partyIndex], MON_DATA_LEVEL, NULL); + gBattleMons[bank].hp = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HP, NULL); + gBattleMons[bank].maxHP = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MAX_HP, NULL); + gBattleMons[bank].attack = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ATK, NULL); + gBattleMons[bank].defense = GetMonData(&gPlayerParty[partyIndex], MON_DATA_DEF, NULL); + gBattleMons[bank].speed = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPD, NULL); + gBattleMons[bank].spAttack = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPATK, NULL); + gBattleMons[bank].spDefense = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPDEF, NULL); + gBattleMons[bank].isEgg = GetMonData(&gPlayerParty[partyIndex], MON_DATA_IS_EGG, NULL); + gBattleMons[bank].altAbility = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ALT_ABILITY, NULL); + gBattleMons[bank].otId = GetMonData(&gPlayerParty[partyIndex], MON_DATA_OT_ID, NULL); + gBattleMons[bank].type1 = gBaseStats[gBattleMons[bank].species].type1; + gBattleMons[bank].type2 = gBaseStats[gBattleMons[bank].species].type2; + gBattleMons[bank].ability = GetAbilityBySpecies(gBattleMons[bank].species, gBattleMons[bank].altAbility); + GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, nickname); + StringCopy10(gBattleMons[bank].nickname, nickname); + GetMonData(&gPlayerParty[partyIndex], MON_DATA_OT_NAME, gBattleMons[bank].otName); + // ewram memes from Ruby return + #ifdef NONMATCHING + gBattleStruct->hpOnSwitchout[GetBankSide(bank)] = gBattleMons[bank].hp; + #else + { + u32 side = GetBankSide(bank); + *(u16*)((void*)(gBattleStruct) + side) = gBattleMons[bank].hp; + } + #endif // NONMATCHING + + for (i = 0; i < 8; i++) + gBattleMons[bank].statStages[i] = 6; + + gBattleMons[bank].status2 = 0; + sub_803FA70(bank); + sub_805EF84(bank, FALSE); +} +*/ diff --git a/src/pokemon_3.c b/src/pokemon_3.c new file mode 100644 index 000000000..2d1dfb8b7 --- /dev/null +++ b/src/pokemon_3.c @@ -0,0 +1,1753 @@ +#include "global.h" +#include "pokemon.h" +#include "main.h" +#include "items.h" +#include "string_util.h" +#include "battle_message.h" +#include "rtc.h" +#include "item.h" +#include "battle.h" +#include "species.h" +#include "link.h" +#include "hold_effects.h" +#include "rng.h" +#include "trainer_classes.h" +#include "trainer_ids.h" +#include "songs.h" +#include "sound.h" +#include "m4a.h" +#include "task.h" +#include "sprite.h" +#include "text.h" +#include "abilities.h" +#include "pokemon_animation.h" +#include "pokedex.h" + +extern struct BattlePokemon gBattleMons[4]; +extern struct BattleEnigmaBerry gEnigmaBerries[4]; +extern u8 gActiveBank; +extern u8 gBankInMenu; +extern u8 gBankTarget; +extern u8 gBankAttacker; +extern u8 gStringBank; +extern u16 gTrainerBattleOpponent_A; +extern u32 gBattleTypeFlags; +extern u8 gBattleMonForms[4]; +extern u16 gBattlePartyID[4]; +extern u8 gLastUsedAbility; +extern u16 gPartnerTrainerId; +extern u32 gHitMarker; + +extern const u16 gSpeciesToHoennPokedexNum[]; +extern const u16 gSpeciesToNationalPokedexNum[]; +extern const u16 gHoennToNationalOrder[]; +extern const u16 gSpeciesIdToCryId[]; +extern const struct SpindaSpot gSpindaSpotGraphics[]; +extern const u8* const gStatNamesTable[]; +extern const u8 gSpeciesNames[][11]; +extern const u8 gUnknown_08329EC8[]; +extern const u8 gUnknown_085CB38A[]; +extern const u8 gUnknown_085CB3AA[]; +extern const u8 gUnknown_085CA459[]; +extern const u8 gUnknown_085CA424[]; +extern const s8 gNatureStatTable[][5]; +extern const s8 gUnknown_08329ECE[][3]; +extern const u32 gBitTable[]; +extern const u32 gTMHMLearnsets[][2]; +extern const u8 BattleText_Wally[]; +extern const u8 BattleText_PreventedSwitch[]; +extern const struct CompressedSpritePalette gMonPaletteTable[]; +extern const struct CompressedSpritePalette gMonShinyPaletteTable[]; +extern const u16 gHMMoves[]; +extern const s8 gPokeblockFlavorCompatibilityTable[]; +extern const u8 gMonAnimationDelayTable[]; +extern const u8 gMonFrontAnimIdsTable[]; + +extern bool8 InBattlePyramid(void); +extern bool8 InBattlePike(void); +extern bool8 sub_81D5C18(void); +extern bool8 sub_806F104(void); +extern bool32 IsNationalPokedexEnabled(void); +extern u8 GetTrainerEncounterMusicIdInBattlePyramind(u16 trainerOpponentId); +extern u8 sub_81D63C8(u16 trainerOpponentId); +extern u8 sav1_map_get_name(void); +extern u8 GetFrontierOpponentClass(u16 trainerId); +extern u8 pokemon_order_func(u8 bankPartyId); +extern void GetFrontierTrainerName(u8* dest, u16 trainerId); +extern void sub_81C488C(u8); +extern void sub_817F578(struct Sprite*, u8 frontAnimId); +extern u8 GetSpeciesBackAnimId(u16 species); + +static void sub_806E6CC(u8 taskId); + +bool8 HealStatusConditions(struct Pokemon *mon, u32 battlePartyId, u32 healMask, u8 battleBank) +{ + u32 status = GetMonData(mon, MON_DATA_STATUS, 0); + + if (status & healMask) + { + status &= ~healMask; + SetMonData(mon, MON_DATA_STATUS, (u8 *)&status); + if (gMain.inBattle && battleBank != 4) + gBattleMons[battleBank].status1 &= ~healMask; + return FALSE; + } + else + { + return TRUE; + } +} + +u8 GetItemEffectParamOffset(u16 itemId, u8 effectByte, u8 effectBit) +{ + const u8 *temp; + const u8 *itemEffect; + u8 offset; + int i; + u8 j; + u8 val; + + offset = 6; + + temp = gItemEffectTable[itemId - 13]; + + if (!temp && itemId != ITEM_ENIGMA_BERRY) + return 0; + + if (itemId == ITEM_ENIGMA_BERRY) + { + temp = gEnigmaBerries[gActiveBank].itemEffect; + } + + itemEffect = temp; + + for (i = 0; i < 6; i++) + { + switch (i) + { + case 0: + case 1: + case 2: + case 3: + if (i == effectByte) + return 0; + break; + case 4: + val = itemEffect[4]; + if (val & 0x20) + val &= 0xDF; + j = 0; + while (val) + { + if (val & 1) + { + switch (j) + { + case 2: + if (val & 0x10) + val &= 0xEF; + case 0: + if (i == effectByte && (val & effectBit)) + return offset; + offset++; + break; + case 1: + if (i == effectByte && (val & effectBit)) + return offset; + offset++; + break; + case 3: + if (i == effectByte && (val & effectBit)) + return offset; + offset++; + break; + case 7: + if (i == effectByte) + return 0; + break; + } + } + j++; + val >>= 1; + if (i == effectByte) + effectBit >>= 1; + } + break; + case 5: + val = itemEffect[5]; + j = 0; + while (val) + { + if (val & 1) + { + switch (j) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + if (i == effectByte && (val & effectBit)) + return offset; + offset++; + break; + case 7: + if (i == effectByte) + return 0; + break; + } + } + j++; + val >>= 1; + if (i == effectByte) + effectBit >>= 1; + } + break; + } + } + + return offset; +} + +void sub_806CF24(s32 stat) +{ + gBankTarget = gBankInMenu; + StringCopy(gBattleTextBuff1, gStatNamesTable[gUnknown_08329EC8[stat]]); + StringCopy(gBattleTextBuff2, gUnknown_085CB38A); + StrCpyDecodeToDisplayedStringBattle(gUnknown_085CB3AA); +} + +u8 *sub_806CF78(u16 itemId) +{ + int i; + const u8 *itemEffect; + + if (itemId == ITEM_ENIGMA_BERRY) + { + if (gMain.inBattle) + itemEffect = gEnigmaBerries[gBankInMenu].itemEffect; + else + itemEffect = gSaveBlock1Ptr->enigmaBerry.itemEffect; + } + else + { + itemEffect = gItemEffectTable[itemId - 13]; + } + + gStringBank = gBankInMenu; + + for (i = 0; i < 3; i++) + { + if (itemEffect[i] & 0xF) + sub_806CF24(i * 2); + if (itemEffect[i] & 0xF0) + { + if (i) + { + sub_806CF24(i * 2 + 1); + } + else + { + gBankAttacker = gBankInMenu; + StrCpyDecodeToDisplayedStringBattle(gUnknown_085CA459); + } + } + } + + if (itemEffect[3] & 0x80) + { + gBankAttacker = gBankInMenu; + StrCpyDecodeToDisplayedStringBattle(gUnknown_085CA424); + } + + return gDisplayedStringBattle; +} + +u8 GetNature(struct Pokemon *mon) +{ + return GetMonData(mon, MON_DATA_PERSONALITY, 0) % 25; +} + +u8 GetNatureFromPersonality(u32 personality) +{ + return personality % 25; +} + +u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem) +{ + int i; + u16 targetSpecies = 0; + u16 species = GetMonData(mon, MON_DATA_SPECIES, 0); + u16 heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, 0); + u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, 0); + u8 level; + u16 friendship; + u8 beauty = GetMonData(mon, MON_DATA_BEAUTY, 0); + u16 upperPersonality = personality >> 16; + u8 holdEffect; + + if (heldItem == ITEM_ENIGMA_BERRY) + holdEffect = gSaveBlock1Ptr->enigmaBerry.holdEffect; + else + holdEffect = ItemId_GetHoldEffect(heldItem); + + if (holdEffect == 38 && type != 3) + return 0; + + switch (type) + { + case 0: + level = GetMonData(mon, MON_DATA_LEVEL, 0); + friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, 0); + + for (i = 0; i < 5; i++) + { + switch (gEvolutionTable[species].evolutions[i].method) + { + case EVO_FRIENDSHIP: + if (friendship >= 220) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_FRIENDSHIP_DAY: + RtcCalcLocalTime(); + if (gLocalTime.hours >= 12 && gLocalTime.hours < 24 && friendship >= 220) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_FRIENDSHIP_NIGHT: + RtcCalcLocalTime(); + if (gLocalTime.hours >= 0 && gLocalTime.hours < 12 && friendship >= 220) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_LEVEL: + if (gEvolutionTable[species].evolutions[i].param <= level) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_LEVEL_ATK_GT_DEF: + if (gEvolutionTable[species].evolutions[i].param <= level) + if (GetMonData(mon, MON_DATA_ATK, 0) > GetMonData(mon, MON_DATA_DEF, 0)) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_LEVEL_ATK_EQ_DEF: + if (gEvolutionTable[species].evolutions[i].param <= level) + if (GetMonData(mon, MON_DATA_ATK, 0) == GetMonData(mon, MON_DATA_DEF, 0)) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_LEVEL_ATK_LT_DEF: + if (gEvolutionTable[species].evolutions[i].param <= level) + if (GetMonData(mon, MON_DATA_ATK, 0) < GetMonData(mon, MON_DATA_DEF, 0)) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_LEVEL_SILCOON: + if (gEvolutionTable[species].evolutions[i].param <= level && (upperPersonality % 10) <= 4) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_LEVEL_CASCOON: + if (gEvolutionTable[species].evolutions[i].param <= level && (upperPersonality % 10) > 4) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_LEVEL_NINJASK: + if (gEvolutionTable[species].evolutions[i].param <= level) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_BEAUTY: + if (gEvolutionTable[species].evolutions[i].param <= beauty) + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + } + } + break; + case 1: + for (i = 0; i < 5; i++) + { + switch (gEvolutionTable[species].evolutions[i].method) + { + case EVO_TRADE: + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + case EVO_TRADE_ITEM: + if (gEvolutionTable[species].evolutions[i].param == heldItem) + { + heldItem = 0; + SetMonData(mon, MON_DATA_HELD_ITEM, (u8 *)&heldItem); + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + } + break; + } + } + break; + case 2: + case 3: + for (i = 0; i < 5; i++) + { + if (gEvolutionTable[species].evolutions[i].method == EVO_ITEM + && gEvolutionTable[species].evolutions[i].param == evolutionItem) + { + targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies; + break; + } + } + break; + } + + return targetSpecies; +} + +u16 HoennPokedexNumToSpecies(u16 hoennNum) +{ + u16 species; + + if (!hoennNum) + return 0; + + species = 0; + + while (species < 411 && gSpeciesToHoennPokedexNum[species] != hoennNum) + species++; + + if (species == 411) + return 0; + + return species + 1; +} + +u16 NationalPokedexNumToSpecies(u16 nationalNum) +{ + u16 species; + + if (!nationalNum) + return 0; + + species = 0; + + while (species < 411 && gSpeciesToNationalPokedexNum[species] != nationalNum) + species++; + + if (species == 411) + return 0; + + return species + 1; +} + +u16 NationalToHoennOrder(u16 nationalNum) +{ + u16 hoennNum; + + if (!nationalNum) + return 0; + + hoennNum = 0; + + while (hoennNum < 411 && gHoennToNationalOrder[hoennNum] != nationalNum) + hoennNum++; + + if (hoennNum == 411) + return 0; + + return hoennNum + 1; +} + +u16 SpeciesToNationalPokedexNum(u16 species) +{ + if (!species) + return 0; + + return gSpeciesToNationalPokedexNum[species - 1]; +} + +u16 SpeciesToHoennPokedexNum(u16 species) +{ + if (!species) + return 0; + + return gSpeciesToHoennPokedexNum[species - 1]; +} + +u16 HoennToNationalOrder(u16 hoennNum) +{ + if (!hoennNum) + return 0; + + return gHoennToNationalOrder[hoennNum - 1]; +} + +u16 SpeciesToCryId(u16 species) +{ + if (species <= 250) + return species; + + if (species < 276) + return 200; + + return gSpeciesIdToCryId[species - 276]; +} + +void sub_806D544(u16 species, u32 personality, u8 *dest) +{ + if (species == SPECIES_SPINDA + && dest != gBattleSpritesGfx->sprites[0] + && dest != gBattleSpritesGfx->sprites[2]) + { + int i; + for (i = 0; i < 4; i++) + { + int j; + u8 x = gSpindaSpotGraphics[i].x + ((personality & 0x0F) - 8); + u8 y = gSpindaSpotGraphics[i].y + (((personality & 0xF0) >> 4) - 8); + + for (j = 0; j < 16; j++) + { + int k; + s32 row = gSpindaSpotGraphics[i].image[j]; + + for (k = x; k < x + 16; k++) + { + u8 *val = dest + ((k / 8) * 32) + ((k % 8) / 2) + ((y >> 3) << 8) + ((y & 7) << 2); + + if (row & 1) + { + if (k & 1) + { + if ((u8)((*val & 0xF0) - 0x10) <= 0x20) + *val += 0x40; + } + else + { + if ((u8)((*val & 0xF) - 0x01) <= 0x02) + *val += 0x04; + } + } + + row >>= 1; + } + + y++; + } + + personality >>= 8; + } + } +} + +void DrawSpindaSpots(u16 species, u32 personality, u8 *dest, u8 a4) +{ + if (species == SPECIES_SPINDA && a4) + { + int i; + for (i = 0; i < 4; i++) + { + int j; + u8 x = gSpindaSpotGraphics[i].x + ((personality & 0x0F) - 8); + u8 y = gSpindaSpotGraphics[i].y + (((personality & 0xF0) >> 4) - 8); + + for (j = 0; j < 16; j++) + { + int k; + s32 row = gSpindaSpotGraphics[i].image[j]; + + for (k = x; k < x + 16; k++) + { + u8 *val = dest + ((k / 8) * 32) + ((k % 8) / 2) + ((y >> 3) << 8) + ((y & 7) << 2); + + if (row & 1) + { + if (k & 1) + { + if ((u8)((*val & 0xF0) - 0x10) <= 0x20) + *val += 0x40; + } + else + { + if ((u8)((*val & 0xF) - 0x01) <= 0x02) + *val += 0x04; + } + } + + row >>= 1; + } + + y++; + } + + personality >>= 8; + } + } +} + +void EvolutionRenameMon(struct Pokemon *mon, u16 oldSpecies, u16 newSpecies) +{ + u8 language; + GetMonData(mon, MON_DATA_NICKNAME, gStringVar1); + language = GetMonData(mon, MON_DATA_LANGUAGE, &language); + if (language == GAME_LANGUAGE && !StringCompare(gSpeciesNames[oldSpecies], gStringVar1)) + SetMonData(mon, MON_DATA_NICKNAME, gSpeciesNames[newSpecies]); +} + +bool8 sub_806D7EC(void) +{ + bool8 retVal = FALSE; + switch (gLinkPlayers[GetMultiplayerId()].lp_field_18) + { + case 0: + case 3: + retVal = FALSE; + break; + case 1: + case 2: + retVal = TRUE; + break; + } + return retVal; +} + +bool8 sub_806D82C(u8 id) +{ + bool8 retVal = FALSE; + switch (gLinkPlayers[id].lp_field_18) + { + case 0: + case 3: + retVal = FALSE; + break; + case 1: + case 2: + retVal = TRUE; + break; + } + return retVal; +} + +s32 sub_806D864(u16 a1) +{ + s32 id; + for (id = 0; id < MAX_LINK_PLAYERS; id++) + if (gLinkPlayers[id].lp_field_18 == a1) + break; + return id; +} + +u8 GetTrainerEncounterMusicId(u16 trainerOpponentId) +{ + if (InBattlePyramid()) + return GetTrainerEncounterMusicIdInBattlePyramind(trainerOpponentId); + if (sub_81D5C18()) + return sub_81D63C8(trainerOpponentId); + return TRAINER_ENCOUNTER_MUSIC(trainerOpponentId); +} + +u16 nature_stat_mod(u8 nature, u16 n, u8 statIndex) +{ + if (statIndex < 1 || statIndex > 5) + { + // should just be "return n", but it wouldn't match without this + u16 retVal = n; + retVal++; + retVal--; + return retVal; + } + + switch (gNatureStatTable[nature][statIndex - 1]) + { + case 1: + return (u16)(n * 110) / 100; + case -1: + return (u16)(n * 90) / 100; + } + + return n; +} + +void AdjustFriendship(struct Pokemon *mon, u8 event) +{ + u16 species, heldItem; + u8 holdEffect; + + if (sub_806F104()) + return; + + species = GetMonData(mon, MON_DATA_SPECIES2, 0); + heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, 0); + + if (heldItem == ITEM_ENIGMA_BERRY) + { + if (gMain.inBattle) + holdEffect = gEnigmaBerries[0].holdEffect; + else + holdEffect = gSaveBlock1Ptr->enigmaBerry.holdEffect; + } + else + { + holdEffect = ItemId_GetHoldEffect(heldItem); + } + + if (species && species != SPECIES_EGG) + { + u8 friendshipLevel = 0; + s16 friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, 0); + if (friendship > 99) + friendshipLevel++; + if (friendship > 199) + friendshipLevel++; + if ((event != 5 || !(Random() & 1)) + && (event != 3 + || ((gBattleTypeFlags & BATTLE_TYPE_TRAINER) + && (gTrainers[gTrainerBattleOpponent_A].trainerClass == CLASS_ELITE_FOUR + || gTrainers[gTrainerBattleOpponent_A].trainerClass == CLASS_LEADER + || gTrainers[gTrainerBattleOpponent_A].trainerClass == CLASS_CHAMPION)))) + { + s8 mod = gUnknown_08329ECE[event][friendshipLevel]; + if (mod > 0 && holdEffect == HOLD_EFFECT_HAPPINESS_UP) + mod = (150 * mod) / 100; + friendship += mod; + if (mod > 0) + { + if (GetMonData(mon, MON_DATA_POKEBALL, 0) == ITEM_LUXURY_BALL) + friendship++; + if (GetMonData(mon, MON_DATA_MET_LOCATION, 0) == sav1_map_get_name()) + friendship++; + } + if (friendship < 0) + friendship = 0; + if (friendship > 255) + friendship = 255; + SetMonData(mon, MON_DATA_FRIENDSHIP, &friendship); + } + } +} + +void MonGainEVs(struct Pokemon *mon, u16 defeatedSpecies) +{ + u8 evs[NUM_STATS]; + u16 evIncrease = 0; + u16 totalEVs = 0; + u16 heldItem; + u8 holdEffect; + int i; + + for (i = 0; i < NUM_STATS; i++) + { + evs[i] = GetMonData(mon, MON_DATA_HP_EV + i, 0); + totalEVs += evs[i]; + } + + for (i = 0; i < NUM_STATS; i++) + { + u8 hasHadPokerus; + int multiplier; + + if (totalEVs >= MAX_TOTAL_EVS) + break; + + hasHadPokerus = CheckPartyHasHadPokerus(mon, 0); + + if (hasHadPokerus) + multiplier = 2; + else + multiplier = 1; + + switch (i) + { + case 0: + evIncrease = gBaseStats[defeatedSpecies].evYield_HP * multiplier; + break; + case 1: + evIncrease = gBaseStats[defeatedSpecies].evYield_Attack * multiplier; + break; + case 2: + evIncrease = gBaseStats[defeatedSpecies].evYield_Defense * multiplier; + break; + case 3: + evIncrease = gBaseStats[defeatedSpecies].evYield_Speed * multiplier; + break; + case 4: + evIncrease = gBaseStats[defeatedSpecies].evYield_SpAttack * multiplier; + break; + case 5: + evIncrease = gBaseStats[defeatedSpecies].evYield_SpDefense * multiplier; + break; + } + + heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, 0); + + if (heldItem == ITEM_ENIGMA_BERRY) + { + if (gMain.inBattle) + holdEffect = gEnigmaBerries[0].holdEffect; + else + holdEffect = gSaveBlock1Ptr->enigmaBerry.holdEffect; + } + else + { + holdEffect = ItemId_GetHoldEffect(heldItem); + } + + if (holdEffect == HOLD_EFFECT_MACHO_BRACE) + evIncrease *= 2; + + if (totalEVs + (s16)evIncrease > MAX_TOTAL_EVS) + evIncrease = ((s16)evIncrease + MAX_TOTAL_EVS) - (totalEVs + evIncrease); + + if (evs[i] + (s16)evIncrease > 255) + { + int val1 = (s16)evIncrease + 255; + int val2 = evs[i] + evIncrease; + evIncrease = val1 - val2; + } + + evs[i] += evIncrease; + totalEVs += evIncrease; + SetMonData(mon, MON_DATA_HP_EV + i, &evs[i]); + } +} + +u16 GetMonEVCount(struct Pokemon *mon) +{ + int i; + u16 count = 0; + + for (i = 0; i < NUM_STATS; i++) + count += GetMonData(mon, MON_DATA_HP_EV + i, 0); + + return count; +} + +void RandomlyGivePartyPokerus(struct Pokemon *party) +{ + u16 rnd = Random(); + if (rnd == 0x4000 || rnd == 0x8000 || rnd == 0xC000) + { + struct Pokemon *mon; + + do + { + do + { + rnd = Random() % PARTY_SIZE; + mon = &party[rnd]; + } + while (!GetMonData(mon, MON_DATA_SPECIES, 0)); + } + while (GetMonData(mon, MON_DATA_IS_EGG, 0)); + + if (!(CheckPartyHasHadPokerus(party, gBitTable[rnd]))) + { + u8 rnd2; + + do + { + rnd2 = Random(); + } + while ((rnd2 & 0x7) == 0); + + if (rnd2 & 0xF0) + rnd2 &= 0x7; + + rnd2 |= (rnd2 << 4); + rnd2 &= 0xF3; + rnd2++; + + SetMonData(&party[rnd], MON_DATA_POKERUS, &rnd2); + } + } +} + +u8 CheckPartyPokerus(struct Pokemon *party, u8 selection) +{ + u8 retVal; + + int partyIndex = 0; + unsigned curBit = 1; + retVal = 0; + + if (selection) + { + do + { + if ((selection & 1) && (GetMonData(&party[partyIndex], MON_DATA_POKERUS, 0) & 0xF)) + retVal |= curBit; + partyIndex++; + curBit <<= 1; + selection >>= 1; + } + while (selection); + } + else if (GetMonData(&party[0], MON_DATA_POKERUS, 0) & 0xF) + { + retVal = 1; + } + + return retVal; +} + +u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection) +{ + u8 retVal; + + int partyIndex = 0; + unsigned curBit = 1; + retVal = 0; + + if (selection) + { + do + { + if ((selection & 1) && GetMonData(&party[partyIndex], MON_DATA_POKERUS, 0)) + retVal |= curBit; + partyIndex++; + curBit <<= 1; + selection >>= 1; + } + while (selection); + } + else if (GetMonData(&party[0], MON_DATA_POKERUS, 0)) + { + retVal = 1; + } + + return retVal; +} + +void UpdatePartyPokerusTime(u16 days) +{ + int i; + for (i = 0; i < PARTY_SIZE; i++) + { + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, 0)) + { + u8 pokerus = GetMonData(&gPlayerParty[i], MON_DATA_POKERUS, 0); + if (pokerus & 0xF) + { + if ((pokerus & 0xF) < days || days > 4) + pokerus &= 0xF0; + else + pokerus -= days; + + if (pokerus == 0) + pokerus = 0x10; + + SetMonData(&gPlayerParty[i], MON_DATA_POKERUS, &pokerus); + } + } + } +} + +void PartySpreadPokerus(struct Pokemon *party) +{ + if ((Random() % 3) == 0) + { + int i; + for (i = 0; i < PARTY_SIZE; i++) + { + if (GetMonData(&party[i], MON_DATA_SPECIES, 0)) + { + u8 pokerus = GetMonData(&party[i], MON_DATA_POKERUS, 0); + u8 curPokerus = pokerus; + if (pokerus) + { + if (pokerus & 0xF) + { + // spread to adjacent party members + if (i != 0 && !(GetMonData(&party[i - 1], MON_DATA_POKERUS, 0) & 0xF0)) + SetMonData(&party[i - 1], MON_DATA_POKERUS, &curPokerus); + if (i != (PARTY_SIZE - 1) && !(GetMonData(&party[i + 1], MON_DATA_POKERUS, 0) & 0xF0)) + { + SetMonData(&party[i + 1], MON_DATA_POKERUS, &curPokerus); + i++; + } + } + } + } + } + } +} + +bool8 TryIncrementMonLevel(struct Pokemon *mon) +{ + u16 species = GetMonData(mon, MON_DATA_SPECIES, 0); + u8 nextLevel = GetMonData(mon, MON_DATA_LEVEL, 0) + 1; + u32 expPoints = GetMonData(mon, MON_DATA_EXP, 0); + if (expPoints > gExperienceTables[gBaseStats[species].growthRate][MAX_MON_LEVEL]) + { + expPoints = gExperienceTables[gBaseStats[species].growthRate][MAX_MON_LEVEL]; + SetMonData(mon, MON_DATA_EXP, &expPoints); + } + if (nextLevel > MAX_MON_LEVEL || expPoints < gExperienceTables[gBaseStats[species].growthRate][nextLevel]) + { + return FALSE; + } + else + { + SetMonData(mon, MON_DATA_LEVEL, &nextLevel); + return TRUE; + } +} + +u32 CanMonLearnTMHM(struct Pokemon *mon, u8 tm) +{ + u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); + if (species == SPECIES_EGG) + { + return 0; + } + else if (tm < 32) + { + u32 mask = 1 << tm; + return gTMHMLearnsets[species][0] & mask; + } + else + { + u32 mask = 1 << (tm - 32); + return gTMHMLearnsets[species][1] & mask; + } +} + +u32 CanSpeciesLearnTMHM(u16 species, u8 tm) +{ + if (species == SPECIES_EGG) + { + return 0; + } + else if (tm < 32) + { + u32 mask = 1 << tm; + return gTMHMLearnsets[species][0] & mask; + } + else + { + u32 mask = 1 << (tm - 32); + return gTMHMLearnsets[species][1] & mask; + } +} + +u8 GetMoveRelearnerMoves(struct Pokemon *mon, u16 *moves) +{ + u16 learnedMoves[4]; + u8 numMoves = 0; + u16 species = GetMonData(mon, MON_DATA_SPECIES, 0); + u8 level = GetMonData(mon, MON_DATA_LEVEL, 0); + int i, j, k; + + for (i = 0; i < 4; i++) + learnedMoves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, 0); + + for (i = 0; i < 20; i++) + { + u16 moveLevel; + + if (gLevelUpLearnsets[species][i] == 0xFFFF) + break; + + moveLevel = gLevelUpLearnsets[species][i] & 0xFE00; + + if (moveLevel <= (level << 9)) + { + for (j = 0; j < 4 && learnedMoves[j] != (gLevelUpLearnsets[species][i] & 0x1FF); j++) + ; + + if (j == 4) + { + for (k = 0; k < numMoves && moves[k] != (gLevelUpLearnsets[species][i] & 0x1FF); k++) + ; + + if (k == numMoves) + moves[numMoves++] = gLevelUpLearnsets[species][i] & 0x1FF; + } + } + } + + return numMoves; +} + +u8 GetLevelUpMovesBySpecies(u16 species, u16 *moves) +{ + u8 numMoves = 0; + int i; + + for (i = 0; i < 20 && gLevelUpLearnsets[species][i] != 0xFFFF; i++) + moves[numMoves++] = gLevelUpLearnsets[species][i] & 0x1FF; + + return numMoves; +} + +u8 GetNumberOfRelearnableMoves(struct Pokemon *mon) +{ + u16 learnedMoves[4]; + u16 moves[20]; + u8 numMoves = 0; + u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); + u8 level = GetMonData(mon, MON_DATA_LEVEL, 0); + int i, j, k; + + if (species == SPECIES_EGG) + return 0; + + for (i = 0; i < 4; i++) + learnedMoves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, 0); + + for (i = 0; i < 20; i++) + { + u16 moveLevel; + + if (gLevelUpLearnsets[species][i] == 0xFFFF) + break; + + moveLevel = gLevelUpLearnsets[species][i] & 0xFE00; + + if (moveLevel <= (level << 9)) + { + for (j = 0; j < 4 && learnedMoves[j] != (gLevelUpLearnsets[species][i] & 0x1FF); j++) + ; + + if (j == 4) + { + for (k = 0; k < numMoves && moves[k] != (gLevelUpLearnsets[species][i] & 0x1FF); k++) + ; + + if (k == numMoves) + moves[numMoves++] = gLevelUpLearnsets[species][i] & 0x1FF; + } + } + } + + return numMoves; +} + +u16 SpeciesToPokedexNum(u16 species) +{ + if (IsNationalPokedexEnabled()) + { + return SpeciesToNationalPokedexNum(species); + } + else + { + species = SpeciesToHoennPokedexNum(species); + if (species <= 202) + return species; + return 0xFFFF; + } +} + +bool32 sub_806E3F8(u16 species) +{ + if (SpeciesToHoennPokedexNum(species) > 202) + return FALSE; + else + return TRUE; +} + +void ClearBattleMonForms(void) +{ + int i; + for (i = 0; i < 4; i++) + gBattleMonForms[i] = 0; +} + +u16 GetBattleBGM(void) +{ + if (gBattleTypeFlags & BATTLE_TYPE_KYOGRE_GROUDON) + return 0x1E0; + if (gBattleTypeFlags & BATTLE_TYPE_REGI) + return 0x1DF; + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + return 0x1DC; + if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) + { + u8 trainerClass; + if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) + trainerClass = GetFrontierOpponentClass(gTrainerBattleOpponent_A); + else if (gBattleTypeFlags & BATTLE_TYPE_x4000000) + trainerClass = CLASS_EXPERT; + else + trainerClass = gTrainers[gTrainerBattleOpponent_A].trainerClass; + switch (trainerClass) + { + case CLASS_AQUA_LEADER: + case CLASS_MAGMA_LEADER: + return 0x1E3; + case CLASS_TEAM_AQUA: + case CLASS_TEAM_MAGMA: + case CLASS_AQUA_ADMIN: + case CLASS_MAGMA_ADMIN: + return 0x1DB; + case CLASS_LEADER: + return 0x1DD; + case CLASS_CHAMPION: + return 0x1DE; + case CLASS_PKMN_TRAINER_RIVAL: + if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) + return 0x1E1; + if (!StringCompare(gTrainers[gTrainerBattleOpponent_A].trainerName, BattleText_Wally)) + return 0x1DC; + return 0x1E1; + case CLASS_ELITE_FOUR: + return 0x1E2; + case CLASS_SALON_MAIDEN: + case CLASS_DOME_ACE: + case CLASS_PALACE_MAVEN: + case CLASS_ARENA_TYCOON: + case CLASS_FACTORY_HEAD: + case CLASS_PIKE_QUEEN: + case CLASS_PYRAMID_KING: + return 0x1D7; + default: + return 0x1DC; + } + } + return 0x1DA; +} + +void PlayBattleBGM(void) +{ + ResetMapMusic(); + m4aMPlayAllStop(); + PlayBGM(GetBattleBGM()); +} + +void PlayMapChosenOrBattleBGM(u16 songId) +{ + ResetMapMusic(); + m4aMPlayAllStop(); + if (songId) + PlayNewMapMusic(songId); + else + PlayNewMapMusic(GetBattleBGM()); +} + +void sub_806E694(u16 songId) +{ + u8 taskId; + + ResetMapMusic(); + m4aMPlayAllStop(); + + taskId = CreateTask(sub_806E6CC, 0); + gTasks[taskId].data[0] = songId; +} + +static void sub_806E6CC(u8 taskId) +{ + if (gTasks[taskId].data[0]) + PlayNewMapMusic(gTasks[taskId].data[0]); + else + PlayNewMapMusic(GetBattleBGM()); + DestroyTask(taskId); +} + +const u8 *pokemon_get_pal(struct Pokemon *mon) +{ + u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); + u32 otId = GetMonData(mon, MON_DATA_OT_ID, 0); + u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, 0); + return species_and_otid_get_pal(species, otId, personality); +} + +// Extracts the upper 16 bits of a 32-bit number +#define HIHALF(n) (((n) & 0xFFFF0000) >> 16) + +// Extracts the lower 16 bits of a 32-bit number +#define LOHALF(n) ((n) & 0xFFFF) + +const u8 *species_and_otid_get_pal(u16 species, u32 otId, u32 personality) +{ + u32 shinyValue; + + if (species > SPECIES_EGG) + return gMonPaletteTable[0].data; + + shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); + if (shinyValue < 8) + return gMonShinyPaletteTable[species].data; + else + return gMonPaletteTable[species].data; +} + +const struct CompressedSpritePalette *sub_806E794(struct Pokemon *mon) +{ + u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0); + u32 otId = GetMonData(mon, MON_DATA_OT_ID, 0); + u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, 0); + return sub_806E7CC(species, otId, personality); +} + +const struct CompressedSpritePalette *sub_806E7CC(u16 species, u32 otId , u32 personality) +{ + u32 shinyValue; + + shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); + if (shinyValue < 8) + return &gMonShinyPaletteTable[species]; + else + return &gMonPaletteTable[species]; +} + +bool32 IsHMMove2(u16 move) +{ + int i = 0; + while (gHMMoves[i] != 0xFFFF) + { + if (gHMMoves[i++] == move) + return TRUE; + } + return FALSE; +} + +bool8 IsPokeSpriteNotFlipped(u16 species) +{ + return gBaseStats[species].noFlip; +} + +s8 GetMonFlavourRelation(struct Pokemon *mon, u8 a2) +{ + u8 nature = GetNature(mon); + return gPokeblockFlavorCompatibilityTable[nature * 5 + a2]; +} + +s8 GetFlavourRelationByPersonality(u32 personality, u8 a2) +{ + u8 nature = GetNatureFromPersonality(personality); + return gPokeblockFlavorCompatibilityTable[nature * 5 + a2]; +} + +bool8 IsTradedMon(struct Pokemon *mon) +{ + u8 otName[8]; + u32 otId; + GetMonData(mon, MON_DATA_OT_NAME, otName); + otId = GetMonData(mon, MON_DATA_OT_ID, 0); + return IsOtherTrainer(otId, otName); +} + +bool8 IsOtherTrainer(u32 otId, u8 *otName) +{ + if (otId == + (gSaveBlock2Ptr->playerTrainerId[0] + | (gSaveBlock2Ptr->playerTrainerId[1] << 8) + | (gSaveBlock2Ptr->playerTrainerId[2] << 16) + | (gSaveBlock2Ptr->playerTrainerId[3] << 24))) + { + int i; + + for (i = 0; otName[i] != EOS; i++) + if (otName[i] != gSaveBlock2Ptr->playerName[i]) + return TRUE; + return FALSE; + } + + return TRUE; +} + +void MonRestorePP(struct Pokemon *mon) +{ + BoxMonRestorePP(&mon->box); +} + +void BoxMonRestorePP(struct BoxPokemon *boxMon) +{ + int i; + + for (i = 0; i < 4; i++) + { + if (GetBoxMonData(boxMon, MON_DATA_MOVE1 + i, 0)) + { + u16 move = GetBoxMonData(boxMon, MON_DATA_MOVE1 + i, 0); + u16 bonus = GetBoxMonData(boxMon, MON_DATA_PP_BONUSES, 0); + u8 pp = CalculatePPWithBonus(move, bonus, i); + SetBoxMonData(boxMon, MON_DATA_PP1 + i, &pp); + } + } +} + +void sub_806E994(void) +{ + gLastUsedAbility = gBattleStruct->field_B0; + gBattleTextBuff1[0] = 0xFD; + gBattleTextBuff1[1] = 4; + gBattleTextBuff1[2] = gBattleStruct->field_49; + gBattleTextBuff1[4] = EOS; + if (!GetBankSide(gBattleStruct->field_49)) + gBattleTextBuff1[3] = pokemon_order_func(gBattlePartyID[gBattleStruct->field_49]); + else + gBattleTextBuff1[3] = gBattlePartyID[gBattleStruct->field_49]; + gBattleTextBuff2[0] = 0xFD; + gBattleTextBuff2[1] = 4; + gBattleTextBuff2[2] = gBankInMenu; + gBattleTextBuff2[3] = pokemon_order_func(gBattlePartyID[gBankInMenu]); + gBattleTextBuff2[4] = EOS; + StrCpyDecodeBattle(BattleText_PreventedSwitch, gStringVar4); +} + +struct PokeItem +{ + u16 species; + u16 item; +}; + +extern const struct PokeItem gAlteringCaveWildMonHeldItems[9]; + +static s32 GetWildMonTableIdInAlteringCave(u16 species) +{ + s32 i; + for (i = 0; i < 9; i++) + if (gAlteringCaveWildMonHeldItems[i].species == species) + return i; + return 0; +} + +void SetWildMonHeldItem(void) +{ + if (!(gBattleTypeFlags & (BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_TRAINER | BATTLE_TYPE_PYRAMID | BATTLE_TYPE_x100000))) + { + u16 rnd = Random() % 100; + u16 species = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, 0); + u16 var1 = 45; + u16 var2 = 95; + if (!GetMonData(&gPlayerParty[0], MON_DATA_SANITY_BIT3, 0) + && GetMonAbility(&gPlayerParty[0]) == ABILITY_COMPOUND_EYES) + { + var1 = 20; + var2 = 80; + } + if (gMapHeader.mapDataId == 0x1A4) + { + s32 alteringCaveId = GetWildMonTableIdInAlteringCave(species); + if (alteringCaveId != 0) + { + if (rnd < var2) + return; + SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &gAlteringCaveWildMonHeldItems[alteringCaveId].item); + } + else + { + if (rnd < var1) + return; + if (rnd < var2) + SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &gBaseStats[species].item1); + else + SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &gBaseStats[species].item2); + } + } + else + { + if (gBaseStats[species].item1 == gBaseStats[species].item2 && gBaseStats[species].item1 != 0) + { + SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &gBaseStats[species].item1); + } + else + { + if (rnd < var1) + return; + if (rnd < var2) + SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &gBaseStats[species].item1); + else + SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, &gBaseStats[species].item2); + } + } + } +} + +bool8 IsMonShiny(struct Pokemon *mon) +{ + u32 otId = GetMonData(mon, MON_DATA_OT_ID, 0); + u32 personality = GetMonData(mon, MON_DATA_PERSONALITY, 0); + return IsShinyOtIdPersonality(otId, personality); +} + +bool8 IsShinyOtIdPersonality(u32 otId, u32 personality) +{ + bool8 retVal = FALSE; + u32 shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); + if (shinyValue < 8) + retVal = TRUE; + return retVal; +} + +const u8* GetTrainerPartnerName(void) +{ + if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) + { + if (gPartnerTrainerId == STEVEN_PARTNER_ID) + return gTrainers[TRAINER_ID_STEVEN].trainerName; + else + { + GetFrontierTrainerName(gStringVar1, gPartnerTrainerId); + return gStringVar1; + } + } + else + { + u8 id = GetMultiplayerId(); + return gLinkPlayers[sub_806D864(gLinkPlayers[id].lp_field_18 ^ 2)].name; + } +} + +#define READ_PTR_FROM_TASK(taskId, dataId) \ + (void*)( \ + ((u16)(gTasks[taskId].data[dataId]) | \ + ((u16)(gTasks[taskId].data[dataId + 1]) << 0x10))) + +#define STORE_PTR_IN_TASK(ptr, taskId, dataId) \ +{ \ + gTasks[taskId].data[dataId] = (u32)(ptr); \ + gTasks[taskId].data[dataId + 1] = (u32)(ptr) >> 0x10; \ +} + +static void Task_AnimateAfterDelay(u8 taskId) +{ + if (--gTasks[taskId].data[3] == 0) + { + LaunchAnimationTaskForFrontSprite(READ_PTR_FROM_TASK(taskId, 0), gTasks[taskId].data[2]); + DestroyTask(taskId); + } +} + +static void Task_PokemonSummaryAnimateAfterDelay(u8 taskId) +{ + if (--gTasks[taskId].data[3] == 0) + { + sub_817F578(READ_PTR_FROM_TASK(taskId, 0), gTasks[taskId].data[2]); + sub_81C488C(0xFF); + DestroyTask(taskId); + } +} + +void DoMonFrontSpriteAnimation(struct Sprite* sprite, u16 species, bool8 noCry, u8 arg3); + +void BattleAnimateFrontSprite(struct Sprite* sprite, u16 species, bool8 noCry, u8 arg3) +{ + if (gHitMarker & HITMARKER_NO_ANIMATIONS && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))) + DoMonFrontSpriteAnimation(sprite, species, noCry, arg3 | 0x80); + else + DoMonFrontSpriteAnimation(sprite, species, noCry, arg3); +} + +bool8 HasTwoFramesAnimation(u16 species); + +extern void SpriteCallbackDummy_2(struct Sprite*); +extern void sub_817F60C(struct Sprite*); + +void DoMonFrontSpriteAnimation(struct Sprite* sprite, u16 species, bool8 noCry, u8 arg3) +{ + s8 pan; + switch (arg3 & 0x7F) + { + case 0: + pan = -25; + break; + case 1: + pan = 25; + break; + default: + pan = 0; + break; + } + if (arg3 & 0x80) + { + if (!noCry) + PlayCry1(species, pan); + sprite->callback = SpriteCallbackDummy; + } + else + { + if (!noCry) + { + PlayCry1(species, pan); + if (HasTwoFramesAnimation(species)) + StartSpriteAnim(sprite, 1); + } + if (gMonAnimationDelayTable[species - 1] != 0) + { + u8 taskId = CreateTask(Task_AnimateAfterDelay, 0); + STORE_PTR_IN_TASK(sprite, taskId, 0); + gTasks[taskId].data[2] = gMonFrontAnimIdsTable[species - 1]; + gTasks[taskId].data[3] = gMonAnimationDelayTable[species - 1]; + } + else + { + LaunchAnimationTaskForFrontSprite(sprite, gMonFrontAnimIdsTable[species - 1]); + } + sprite->callback = SpriteCallbackDummy_2; + } +} + +void PokemonSummaryDoMonAnimation(struct Sprite* sprite, u16 species, bool8 oneFrame) +{ + if (!oneFrame && HasTwoFramesAnimation(species)) + StartSpriteAnim(sprite, 1); + if (gMonAnimationDelayTable[species - 1] != 0) + { + u8 taskId = CreateTask(Task_PokemonSummaryAnimateAfterDelay, 0); + STORE_PTR_IN_TASK(sprite, taskId, 0); + gTasks[taskId].data[2] = gMonFrontAnimIdsTable[species - 1]; + gTasks[taskId].data[3] = gMonAnimationDelayTable[species - 1]; + sub_81C488C(taskId); + sub_817F60C(sprite); + } + else + { + sub_817F578(sprite, gMonFrontAnimIdsTable[species - 1]); + } +} + +void sub_806EE98(void) +{ + u8 delayTaskId = FindTaskIdByFunc(Task_PokemonSummaryAnimateAfterDelay); + if (delayTaskId != 0xFF) + DestroyTask(delayTaskId); +} + +void BattleAnimateBackSprite(struct Sprite* sprite, u16 species) +{ + if (gHitMarker & HITMARKER_NO_ANIMATIONS && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))) + { + sprite->callback = SpriteCallbackDummy; + } + else + { + LaunchAnimationTaskForBackSprite(sprite, GetSpeciesBackAnimId(species)); + sprite->callback = SpriteCallbackDummy_2; + } +} + +u8 sub_806EF08(u8 arg0) +{ + s32 i; + s32 var = 0; + u8 multiplayerId = GetMultiplayerId(); + switch (gLinkPlayers[multiplayerId].lp_field_18) + { + case 0: + case 2: + var = (arg0 != 0) ? 1 : 3; + break; + case 1: + case 3: + var = (arg0 != 0) ? 2 : 0; + break; + } + for (i = 0; i < 4; i++) + { + if (gLinkPlayers[i].lp_field_18 == (s16)(var)) + break; + } + return i; +} + +u8 sub_806EF84(u8 arg0, u8 arg1) +{ + s32 i; + s32 var = 0; + switch (gLinkPlayers[arg1].lp_field_18) + { + case 0: + case 2: + var = (arg0 != 0) ? 1 : 3; + break; + case 1: + case 3: + var = (arg0 != 0) ? 2 : 0; + break; + } + for (i = 0; i < 4; i++) + { + if (gLinkPlayers[i].lp_field_18 == (s16)(var)) + break; + } + return i; +} + +extern const u8 gUnknown_0831F578[]; + +u16 sub_806EFF0(u16 arg0) +{ + return gUnknown_0831F578[arg0]; +} + +u16 sub_806F000(u8 playerGender) +{ + if (playerGender) + return sub_806EFF0(0x3F); + else + return sub_806EFF0(0x3C); +} + +extern const u8 gTrainerClassNames[][13]; + +void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality) +{ + u8 getFlagCaseId = (caseId == FLAG_SET_SEEN) ? FLAG_GET_SEEN : FLAG_GET_CAUGHT; + if (!GetSetPokedexFlag(nationalNum, getFlagCaseId)) // don't set if it's already set + { + GetSetPokedexFlag(nationalNum, caseId); + if (NationalPokedexNumToSpecies(nationalNum) == SPECIES_UNOWN) + gSaveBlock2Ptr->pokedex.unownPersonality = personality; + if (NationalPokedexNumToSpecies(nationalNum) == SPECIES_SPINDA) + gSaveBlock2Ptr->pokedex.spindaPersonality = personality; + } +} + +const u8* GetTrainerClassNameFromId(u16 trainerId) +{ + if (trainerId > NO_OF_TRAINERS) + trainerId = 0; + return gTrainerClassNames[gTrainers[trainerId].trainerClass]; +} + +const u8* GetTrainerNameFromId(u16 trainerId) +{ + if (trainerId > NO_OF_TRAINERS) + trainerId = 0; + return gTrainers[trainerId].trainerName; +} + +bool8 HasTwoFramesAnimation(u16 species) +{ + return (species != SPECIES_CASTFORM + && species != SPECIES_DEOXYS + && species != SPECIES_SPINDA + && species != SPECIES_UNOWN); +} + +bool8 sub_806F104(void) +{ + if (gMain.inBattle && gBattleTypeFlags & (BATTLE_TYPE_FRONTIER)) + return TRUE; + if (!gMain.inBattle && (InBattlePike() || InBattlePyramid())) + return TRUE; + return FALSE; +} + +/* + +extern const struct SpriteTemplate gUnknown_08329D98[]; + +struct Unknown_806F160_Struct +{ + u8 field_0; + u8 field_1; + u8 field_2; + u8 field_3; + u8 field_4; + u8 field_5; + u8 field_6; + u8 field_7; + u8 field_8; + u8 field_9; + u8 field_A; + u8 field_B; + struct SpriteTemplate* templates; +}; + +void sub_806F160(struct Unknown_806F160_Struct* structPtr) +{ + u16 i, j; + for (i = 0; i < structPtr->field_0; i++) + { + structPtr->templates[i] = gUnknown_08329D98[i]; + for (j = 0; j < structPtr->field_1) + { + // no clue what the pointer in the struct point to :/ + } + } +} */ + |