mirror of
https://github.com/pret/pokeemerald.git
synced 2026-09-28 21:08:36 -05:00
Generate encounter slot total constants
This commit is contained in:
@@ -3,12 +3,6 @@
|
||||
|
||||
{{ doNotModifyHeader }}
|
||||
|
||||
// TODO: Generate these as well
|
||||
#define LAND_WILD_COUNT 12
|
||||
#define WATER_WILD_COUNT 5
|
||||
#define ROCK_WILD_COUNT 5
|
||||
#define FISH_WILD_COUNT 10
|
||||
|
||||
#define NUM_ALTERING_CAVE_TABLES 9
|
||||
|
||||
## for wild_encounter_group in wild_encounter_groups
|
||||
@@ -21,12 +15,16 @@
|
||||
#define ENCOUNTER_CHANCE_{{ upper(wild_encounter_field.type) }}_TOTAL (ENCOUNTER_CHANCE_{{ upper(wild_encounter_field.type) }}_SLOT_{{ getVar(wild_encounter_field.type) }})
|
||||
{% else %}
|
||||
## for field_subgroup_key, field_subgroup_subarray in wild_encounter_field.groups
|
||||
{{ setVar("field_name", concat(concat(upper(wild_encounter_field.type), "_"), upper(field_subgroup_key))) }}
|
||||
## for field_subgroup_index in field_subgroup_subarray
|
||||
#define ENCOUNTER_CHANCE_{{ upper(wild_encounter_field.type) }}_{{ upper(field_subgroup_key) }}_SLOT_{{ field_subgroup_index }} ({% if loop.index == 0 %}{{ at(wild_encounter_field.encounter_rates, field_subgroup_index) }}{% else %}ENCOUNTER_CHANCE_{{ upper(wild_encounter_field.type) }}_{{ upper(field_subgroup_key) }}_SLOT_{{ getVar("previous_slot") }} + {{ at(wild_encounter_field.encounter_rates, field_subgroup_index) }}{% endif %}){{ setVarInt(concat(wild_encounter_field.type, field_subgroup_key), field_subgroup_index) }}{{ setVarInt("previous_slot", field_subgroup_index) }}
|
||||
#define ENCOUNTER_CHANCE_{{ getVar("field_name") }}_SLOT_{{ field_subgroup_index }} ({% if loop.index == 0 %}{{ at(wild_encounter_field.encounter_rates, field_subgroup_index) }}{% else %}ENCOUNTER_CHANCE_{{ getVar("field_name") }}_SLOT_{{ getVar("previous_slot") }} + {{ at(wild_encounter_field.encounter_rates, field_subgroup_index) }}{% endif %}){{ setVarInt(concat(wild_encounter_field.type, field_subgroup_key), field_subgroup_index) }}{{ setVarInt("previous_slot", field_subgroup_index) }}
|
||||
## endfor
|
||||
#define ENCOUNTER_CHANCE_{{ upper(wild_encounter_field.type) }}_{{ upper(field_subgroup_key) }}_TOTAL (ENCOUNTER_CHANCE_{{ upper(wild_encounter_field.type) }}_{{ upper(field_subgroup_key) }}_SLOT_{{ getVar(concat(wild_encounter_field.type, field_subgroup_key)) }})
|
||||
#define ENCOUNTER_CHANCE_{{ getVar("field_name") }}_TOTAL (ENCOUNTER_CHANCE_{{ getVar("field_name") }}_SLOT_{{ getVar(concat(wild_encounter_field.type, field_subgroup_key)) }})
|
||||
#define NUM_{{ getVar("field_name") }}_ENCOUNTER_SLOTS ({{ length(field_subgroup_subarray) }})
|
||||
## endfor
|
||||
{% endif %}
|
||||
#define NUM_{{ upper(wild_encounter_field.type) }}_ENCOUNTER_SLOTS ({{ length(wild_encounter_field.encounter_rates) }})
|
||||
|
||||
## endfor
|
||||
{% endif %}
|
||||
## endfor
|
||||
|
||||
@@ -1697,45 +1697,51 @@ static void PopulateMapName(int matchCallId, u8 *destStr)
|
||||
GetMapName(destStr, GetRematchTrainerLocation(matchCallId), 0);
|
||||
}
|
||||
|
||||
// Equivalent to ChooseWildMonIndex_Land
|
||||
// NUM_LAND_MONS_ENCOUNTER_SLOTS
|
||||
static u8 GetLandEncounterSlot(void)
|
||||
{
|
||||
int rand = Random() % 100;
|
||||
if (rand < 20)
|
||||
int rand = Random() % ENCOUNTER_CHANCE_LAND_MONS_TOTAL;
|
||||
|
||||
if (rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_0)
|
||||
return 0;
|
||||
else if (rand >= 20 && rand < 40)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_0 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_1)
|
||||
return 1;
|
||||
else if (rand >= 40 && rand < 50)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_1 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_2)
|
||||
return 2;
|
||||
else if (rand >= 50 && rand < 60)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_2 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_3)
|
||||
return 3;
|
||||
else if (rand >= 60 && rand < 70)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_3 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_4)
|
||||
return 4;
|
||||
else if (rand >= 70 && rand < 80)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_4 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_5)
|
||||
return 5;
|
||||
else if (rand >= 80 && rand < 85)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_5 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_6)
|
||||
return 6;
|
||||
else if (rand >= 85 && rand < 90)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_6 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_7)
|
||||
return 7;
|
||||
else if (rand >= 90 && rand < 94)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_7 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_8)
|
||||
return 8;
|
||||
else if (rand >= 94 && rand < 98)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_8 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_9)
|
||||
return 9;
|
||||
else if (rand >= 98 && rand < 99)
|
||||
else if (rand >= ENCOUNTER_CHANCE_LAND_MONS_SLOT_9 && rand < ENCOUNTER_CHANCE_LAND_MONS_SLOT_10)
|
||||
return 10;
|
||||
else
|
||||
return 11;
|
||||
}
|
||||
|
||||
// Equivalent to ChooseWildMonIndex_WaterRock
|
||||
// NUM_WATER_MONS_ENCOUNTER_SLOTS
|
||||
static u8 GetWaterEncounterSlot(void)
|
||||
{
|
||||
int rand = Random() % 100;
|
||||
if (rand < 60)
|
||||
int rand = Random() % ENCOUNTER_CHANCE_WATER_MONS_TOTAL;
|
||||
|
||||
if (rand < ENCOUNTER_CHANCE_WATER_MONS_SLOT_0)
|
||||
return 0;
|
||||
else if (rand >= 60 && rand < 90)
|
||||
else if (rand >= ENCOUNTER_CHANCE_WATER_MONS_SLOT_0 && rand < ENCOUNTER_CHANCE_WATER_MONS_SLOT_1)
|
||||
return 1;
|
||||
else if (rand >= 90 && rand < 95)
|
||||
else if (rand >= ENCOUNTER_CHANCE_WATER_MONS_SLOT_1 && rand < ENCOUNTER_CHANCE_WATER_MONS_SLOT_2)
|
||||
return 2;
|
||||
else if (rand >= 95 && rand < 99)
|
||||
else if (rand >= ENCOUNTER_CHANCE_WATER_MONS_SLOT_2 && rand < ENCOUNTER_CHANCE_WATER_MONS_SLOT_3)
|
||||
return 3;
|
||||
else
|
||||
return 4;
|
||||
|
||||
@@ -385,19 +385,19 @@ static bool8 MapHasSpecies(const struct WildPokemonHeader *info, u16 species)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (MonListHasSpecies(info->landMonsInfo, species, LAND_WILD_COUNT))
|
||||
if (MonListHasSpecies(info->landMonsInfo, species, NUM_LAND_MONS_ENCOUNTER_SLOTS))
|
||||
return TRUE;
|
||||
if (MonListHasSpecies(info->waterMonsInfo, species, WATER_WILD_COUNT))
|
||||
if (MonListHasSpecies(info->waterMonsInfo, species, NUM_WATER_MONS_ENCOUNTER_SLOTS))
|
||||
return TRUE;
|
||||
// When searching the fishing encounters, this incorrectly uses the size of the land encounters.
|
||||
// As a result it's reading out of bounds of the fishing encounters tables.
|
||||
#ifdef BUGFIX
|
||||
if (MonListHasSpecies(info->fishingMonsInfo, species, FISH_WILD_COUNT))
|
||||
if (MonListHasSpecies(info->fishingMonsInfo, species, NUM_FISHING_MONS_ENCOUNTER_SLOTS))
|
||||
#else
|
||||
if (MonListHasSpecies(info->fishingMonsInfo, species, LAND_WILD_COUNT))
|
||||
if (MonListHasSpecies(info->fishingMonsInfo, species, NUM_LAND_MONS_ENCOUNTER_SLOTS))
|
||||
#endif
|
||||
return TRUE;
|
||||
if (MonListHasSpecies(info->rockSmashMonsInfo, species, ROCK_WILD_COUNT))
|
||||
if (MonListHasSpecies(info->rockSmashMonsInfo, species, NUM_ROCK_SMASH_MONS_ENCOUNTER_SLOTS))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ static void FeebasSeedRng(u16 seed)
|
||||
sFeebasRngValue = seed;
|
||||
}
|
||||
|
||||
// LAND_WILD_COUNT
|
||||
// NUM_LAND_MONS_ENCOUNTER_SLOTS
|
||||
static u8 ChooseWildMonIndex_Land(void)
|
||||
{
|
||||
u8 rand = Random() % ENCOUNTER_CHANCE_LAND_MONS_TOTAL;
|
||||
@@ -209,7 +209,7 @@ static u8 ChooseWildMonIndex_Land(void)
|
||||
return 11;
|
||||
}
|
||||
|
||||
// ROCK_WILD_COUNT / WATER_WILD_COUNT
|
||||
// NUM_ROCK_SMASH_MONS_ENCOUNTER_SLOTS / NUM_WATER_MONS_ENCOUNTER_SLOTS
|
||||
static u8 ChooseWildMonIndex_WaterRock(void)
|
||||
{
|
||||
u8 rand = Random() % ENCOUNTER_CHANCE_WATER_MONS_TOTAL;
|
||||
@@ -226,7 +226,7 @@ static u8 ChooseWildMonIndex_WaterRock(void)
|
||||
return 4;
|
||||
}
|
||||
|
||||
// FISH_WILD_COUNT
|
||||
// NUM_FISHING_MONS_ENCOUNTER_SLOTS
|
||||
static u8 ChooseWildMonIndex_Fishing(u8 rod)
|
||||
{
|
||||
u8 wildMonIndex = 0;
|
||||
@@ -427,15 +427,15 @@ static bool8 TryGenerateWildMon(const struct WildPokemonInfo *wildMonInfo, u8 ar
|
||||
switch (area)
|
||||
{
|
||||
case WILD_AREA_LAND:
|
||||
if (TRY_GET_ABILITY_INFLUENCED_WILD_MON_INDEX(wildMonInfo->wildPokemon, TYPE_STEEL, ABILITY_MAGNET_PULL, &wildMonIndex, LAND_WILD_COUNT))
|
||||
if (TRY_GET_ABILITY_INFLUENCED_WILD_MON_INDEX(wildMonInfo->wildPokemon, TYPE_STEEL, ABILITY_MAGNET_PULL, &wildMonIndex, NUM_LAND_MONS_ENCOUNTER_SLOTS))
|
||||
break;
|
||||
if (TRY_GET_ABILITY_INFLUENCED_WILD_MON_INDEX(wildMonInfo->wildPokemon, TYPE_ELECTRIC, ABILITY_STATIC, &wildMonIndex, LAND_WILD_COUNT))
|
||||
if (TRY_GET_ABILITY_INFLUENCED_WILD_MON_INDEX(wildMonInfo->wildPokemon, TYPE_ELECTRIC, ABILITY_STATIC, &wildMonIndex, NUM_LAND_MONS_ENCOUNTER_SLOTS))
|
||||
break;
|
||||
|
||||
wildMonIndex = ChooseWildMonIndex_Land();
|
||||
break;
|
||||
case WILD_AREA_WATER:
|
||||
if (TRY_GET_ABILITY_INFLUENCED_WILD_MON_INDEX(wildMonInfo->wildPokemon, TYPE_ELECTRIC, ABILITY_STATIC, &wildMonIndex, WATER_WILD_COUNT))
|
||||
if (TRY_GET_ABILITY_INFLUENCED_WILD_MON_INDEX(wildMonInfo->wildPokemon, TYPE_ELECTRIC, ABILITY_STATIC, &wildMonIndex, NUM_WATER_MONS_ENCOUNTER_SLOTS))
|
||||
break;
|
||||
|
||||
wildMonIndex = ChooseWildMonIndex_WaterRock();
|
||||
@@ -948,7 +948,7 @@ static bool8 TryGetAbilityInfluencedWildMonIndex(const struct WildPokemon *wildM
|
||||
#ifdef BUGFIX
|
||||
return TryGetRandomWildMonIndexByType(wildMon, type, size, monIndex);
|
||||
#else
|
||||
return TryGetRandomWildMonIndexByType(wildMon, type, LAND_WILD_COUNT, monIndex);
|
||||
return TryGetRandomWildMonIndexByType(wildMon, type, NUM_LAND_MONS_ENCOUNTER_SLOTS, monIndex);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user