summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pokemon_3.c297
-rw-r--r--src/sound.c3
2 files changed, 298 insertions, 2 deletions
diff --git a/src/pokemon_3.c b/src/pokemon_3.c
index 8ea6841f7..104b2404c 100644
--- a/src/pokemon_3.c
+++ b/src/pokemon_3.c
@@ -8,6 +8,20 @@
#include "main.h"
#include "sprite.h"
#include "flag.h"
+#include "rtc.h"
+#include "item.h"
+
+struct Evolution
+{
+ u16 method;
+ u16 param;
+ u16 targetSpecies;
+};
+
+struct EvolutionData
+{
+ struct Evolution evolutions[5];
+};
extern void get_battle_strings_(u8 *);
@@ -19,14 +33,24 @@ extern struct BattlePokemon gBattleMons[4];
extern u8 * const gItemEffectTable[];
extern u8 gUnknown_02024A60;
extern struct BattleEnigmaBerry gEnigmaBerries[];
+extern struct EvolutionData gEvolutionTable[];
+extern u16 gSpeciesToHoennPokedexNum[];
+extern u16 gSpeciesToNationalPokedexNum[];
+extern u16 gHoennToNationalOrder[];
+extern u16 gSpeciesIdToCryId[];
extern u8 gUnknown_030041C0[];
extern u8 gUnknown_03004290[];
+extern u8 gUnknown_020238CC[];
+extern u8 gUnknown_02024C07;
extern u8 gUnknown_02024C08;
+extern u8 gUnknown_02024C0B;
extern u8 gUnknown_02024E6C;
extern u8 gUnknown_082082F8[];
extern u8 gUnknown_083FFDB3[];
extern u8 gUnknown_083FFDD3[];
+extern u8 gUnknown_083FEE5D[];
+extern u8 gUnknown_083FEE92[];
extern u8 *gUnknown_08400F58[];
bool8 HealStatusConditions(struct Pokemon *mon, u32 unused, u32 healMask, u8 battleId)
@@ -160,10 +184,279 @@ u8 GetItemEffectParamOffset(u16 itemId, u8 effectByte, u8 effectBit)
return offset;
}
-void sub_803F324(int a1)
+void sub_803F324(int stat)
{
gUnknown_02024C08 = gUnknown_02024E6C;
- StringCopy(gUnknown_030041C0, gUnknown_08400F58[gUnknown_082082F8[a1]]);
+ StringCopy(gUnknown_030041C0, gUnknown_08400F58[gUnknown_082082F8[stat]]);
StringCopy(gUnknown_03004290, gUnknown_083FFDB3);
get_battle_strings_(gUnknown_083FFDD3);
}
+
+u8 *sub_803F378(u16 itemId)
+{
+ int i;
+ u8 *itemEffect;
+
+ if (itemId == 175)
+ {
+ if (gMain.inBattle)
+ {
+ itemEffect = gEnigmaBerries[gUnknown_02024E6C].itemEffect;
+ }
+ else
+ {
+ itemEffect = gSaveBlock1.enigmaBerry.itemEffect;
+ }
+ }
+ else
+ {
+ itemEffect = gItemEffectTable[itemId - 13];
+ }
+
+ gUnknown_02024C0B = gUnknown_02024E6C;
+
+ for (i = 0; i < 3; i++)
+ {
+ if (itemEffect[i] & 0xF)
+ sub_803F324(i * 2);
+ if (itemEffect[i] & 0xF0)
+ {
+ if (i)
+ {
+ sub_803F324(i * 2 + 1);
+ }
+ else
+ {
+ gUnknown_02024C07 = gUnknown_02024E6C;
+ get_battle_strings_(gUnknown_083FEE92);
+ }
+ }
+ }
+
+ if (itemEffect[3] & 0x80)
+ {
+ gUnknown_02024C07 = gUnknown_02024E6C;
+ get_battle_strings_(gUnknown_083FEE5D);
+ }
+
+ return gUnknown_020238CC;
+}
+
+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 == 175)
+ holdEffect = gSaveBlock1.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 1:
+ if (friendship >= 220)
+ targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies;
+ break;
+ case 2:
+ RtcCalcLocalTime();
+ if (gLocalTime.hours >= 12 && gLocalTime.hours < 24 && friendship >= 220)
+ targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies;
+ break;
+ case 3:
+ RtcCalcLocalTime();
+ if (gLocalTime.hours >= 0 && gLocalTime.hours < 12 && friendship >= 220)
+ targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies;
+ break;
+ case 4:
+ if (gEvolutionTable[species].evolutions[i].param <= level)
+ targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies;
+ break;
+ case 8:
+ 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 9:
+ 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 10:
+ 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 11:
+ if (gEvolutionTable[species].evolutions[i].param <= level && (upperPersonality % 10) <= 4)
+ targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies;
+ break;
+ case 12:
+ if (gEvolutionTable[species].evolutions[i].param <= level && (upperPersonality % 10) > 4)
+ targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies;
+ break;
+ case 13:
+ if (gEvolutionTable[species].evolutions[i].param <= level)
+ targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies;
+ break;
+ case 15:
+ 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 5:
+ targetSpecies = gEvolutionTable[species].evolutions[i].targetSpecies;
+ break;
+ case 6:
+ 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 == 7
+ && 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];
+}
+
+u32 SpeciesToCryId(u16 species)
+{
+ if (species <= 250)
+ return species;
+
+ if (species < 276)
+ return 200;
+
+ return gSpeciesIdToCryId[species - 276];
+
+}
diff --git a/src/sound.c b/src/sound.c
index 56719aa08..69accd1c2 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -12,6 +12,9 @@ struct Fanfare
u16 duration;
};
+// Hack: different prototype than definition
+u32 SpeciesToCryId(u32);
+
extern u16 gUnknown_020239F8;
extern struct MusicPlayerInfo *gMPlay_PokemonCry;
extern u8 gPokemonCryBGMDuckingCounter;