Skip to content

Commit

Permalink
Merge pull request #57 from TeamAquasHideout/thepit_v2
Browse files Browse the repository at this point in the history
Thepit v2
  • Loading branch information
wiz1989 authored Dec 27, 2024
2 parents 62309fd + 31133f7 commit 1182dde
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 69 deletions.
Binary file modified data/layouts/PitArenaBeach03/map.bin
Binary file not shown.
Binary file modified data/layouts/PitArenaWater04/map.bin
Binary file not shown.
14 changes: 7 additions & 7 deletions data/maps/PitArenaBeach03/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"object_events": [
{
"graphics_id": "OBJ_EVENT_GFX_VAR_0",
"x": 12,
"x": 14,
"y": 14,
"elevation": 0,
"movement_type": "MOVEMENT_TYPE_WANDER_UP_AND_DOWN",
"movement_range_x": 0,
"movement_range_y": 3,
"movement_type": "MOVEMENT_TYPE_WANDER_LEFT_AND_RIGHT",
"movement_range_x": 3,
"movement_range_y": 0,
"trainer_type": "TRAINER_TYPE_NORMAL",
"trainer_sight_or_berry_tree_id": "3",
"script": "PitArena_TrainerBattle",
Expand Down Expand Up @@ -68,7 +68,7 @@
},
{
"graphics_id": "OBJ_EVENT_GFX_VAR_0",
"x": 12,
"x": 14,
"y": 14,
"elevation": 0,
"movement_type": "MOVEMENT_TYPE_WANDER_LEFT_AND_RIGHT",
Expand Down Expand Up @@ -159,8 +159,8 @@
},
{
"graphics_id": "OBJ_EVENT_GFX_ZIGZAGOON_2",
"x": 9,
"y": 16,
"x": 12,
"y": 10,
"elevation": 0,
"movement_type": "MOVEMENT_TYPE_WANDER_AROUND",
"movement_range_x": 2,
Expand Down
8 changes: 4 additions & 4 deletions data/maps/PitArenaWater04/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
},
{
"graphics_id": "OBJ_EVENT_GFX_VAR_3",
"x": 7,
"y": 6,
"x": 8,
"y": 7,
"elevation": 0,
"movement_type": "MOVEMENT_TYPE_WANDER_LEFT_AND_RIGHT",
"movement_range_x": 3,
Expand Down Expand Up @@ -107,8 +107,8 @@
},
{
"graphics_id": "OBJ_EVENT_GFX_VAR_3",
"x": 7,
"y": 6,
"x": 8,
"y": 7,
"elevation": 0,
"movement_type": "MOVEMENT_TYPE_WANDER_LEFT_AND_RIGHT",
"movement_range_x": 3,
Expand Down
2 changes: 1 addition & 1 deletion include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ struct SaveBlock2
// end of u16
u16 mode50Floors:1;
u16 modeBossHeal:1;
u16 modeChoiceEvoStage:2; //0 = All, 1 = basic pokemon, 2 = fully evolved
u16 modeChoiceEvoStage:3; //0 = All, 1 = basic pokemon, 2 = fully evolved, 3 = prog
u16 modeChoiceItemReward:2; //0 = Random, 1 = always 1, 2 = always 3
u16 modeSpeciesArray:1; //0 = Random, 1 = progressive
u16 padding2:9; // uncommented because its free padding space
Expand Down
10 changes: 9 additions & 1 deletion include/pit.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ void Task_PokemonAvatar_HandleBob(u8 taskId);
u32 GetMaxNumberOfSpeciesAvatars(void);
void ClearAllRandomBossEncounters(void);

u32 GetSpeciesFromRandomArray(u16 index, bool8 forceAllSpecies);
u32 GetTrainerSpeciesFromRandomArray(u16 index, bool8 forceAllSpecies);
u32 GetPlayerSpeciesFromRandomArray(u16 index, bool8 forceAllSpecies);
u32 GetMaxPlayerNumberOfSpecies(bool8 forceAllSpecies);
void ClearGeneratedMons(void);

struct RandomTrainerNPC
{
Expand Down Expand Up @@ -91,12 +94,17 @@ struct RandomTrainerNPC
#define EVOSTAGE_ALL 0
#define EVOSTAGE_BASIC 1
#define EVOSTAGE_FULL 2
#define EVOSTAGE_PROG 3
#define ARRAY_RANDOM 0
#define ARRAY_PROG 1
#define ITEM_DROPS_RAND 0
#define ITEM_DROPS_1 1
#define ITEM_DROPS_3 2

#define TRAINER_MONS 0
#define PLAYER_MONS 1
#define ALL_MONS 2

//Autosave defines
#define SAVE_NO 0
#define SAVE_5_FLOORS 1
Expand Down
6 changes: 3 additions & 3 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -897,16 +897,16 @@ u16 GetRandomMoveNotSeeded(u16 move, u16 species);
u8 GetRandomType(void);
u8 EvolutionBlockedByEvoLimit(u16 species);
u16 GetSpeciesRandomSeeded(u16 species);
u16 GetSpeciesRandomNotSeeded(u16 species);
u16 GetSpeciesRandomNotSeeded(u16 monType);
u8 GetNumberOfEggMoves(struct Pokemon *mon);
u8 GetEggMoveTutorMoves(struct Pokemon *mon, u16 *moves);
u8 GetNumberOfTutorMoves(struct Pokemon *mon);
u8 GetTutorMoves(struct Pokemon *mon, u16 *moves);
u8 GetStaticTutorMoves(u16 *moves);
u16 GetMegaStone(u32 species);
u32 GetMaxNumberOfSpecies(bool8 forceAllSpecies);
u32 GetMaxTrainerNumberOfSpecies(bool8 forceAllSpecies);
void DebugTestRandomness(void);
u16 GetRandomSpeciesFlattenedCurve(void);
u16 GetRandomSpeciesFlattenedCurve(u16 monType);
u16 GetAverageEVsFromParty(void);
void ForceIncrementMonLevel(struct Pokemon *mon);
u16 GetRandomValidMovesCount(void);
Expand Down
4 changes: 2 additions & 2 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ u8 CreateNPCTrainerPartyFromTrainer(struct Pokemon *party, const struct Trainer
else if (monLevel == 100 || monLevel % 25 == 0)
{
// = fully evolved mons for every trainer from Floor 100 on and for bosses!
u16 newSpecies = GetRandomSpeciesFlattenedCurve();
u16 newSpecies = GetRandomSpeciesFlattenedCurve(ALL_MONS);
const struct Evolution *evolutions = GetSpeciesEvolutions(newSpecies);
while (evolutions != NULL)
{
Expand All @@ -2130,7 +2130,7 @@ u8 CreateNPCTrainerPartyFromTrainer(struct Pokemon *party, const struct Trainer
}
else
{
CreateMon(&party[i], GetRandomSpeciesFlattenedCurve(), monLevel, 0, TRUE, personalityValue, otIdType, fixedOtId);
CreateMon(&party[i], GetRandomSpeciesFlattenedCurve(TRAINER_MONS), monLevel, 0, TRUE, personalityValue, otIdType, fixedOtId);
//test line below for forced test encounters
//CreateMon(&party[i], SPECIES_RAYQUAZA, monLevel, 0, TRUE, personalityValue, otIdType, fixedOtId);
}
Expand Down
75 changes: 37 additions & 38 deletions src/pit_randomizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,14 +1374,14 @@ bool8 IsSpeciesParadoxMon(u16 species)

u16 AccessValidSpeciesArrayIndex(u16 index)
{
return GetSpeciesFromRandomArray(index % GetMaxNumberOfSpecies(FALSE), FALSE);
return GetTrainerSpeciesFromRandomArray(index % GetMaxTrainerNumberOfSpecies(TRUE), TRUE);
}

u16 GetIndexOfSpeciesInValidSpeciesArray(u16 species)
{
for(int i = 0; i < GetMaxNumberOfSpecies(FALSE); i++)
for(int i = 0; i < GetMaxTrainerNumberOfSpecies(TRUE); i++)
{
if(GetSpeciesFromRandomArray(i, FALSE) == species)
if(GetTrainerSpeciesFromRandomArray(i, TRUE) == species)
{
return i;
}
Expand All @@ -1391,57 +1391,56 @@ u16 GetIndexOfSpeciesInValidSpeciesArray(u16 species)

u16 GetSpeciesRandomSeeded(u16 species)
{
return GetSpeciesFromRandomArray(RandomSeededModulo2(species, GetMaxNumberOfSpecies(FALSE)), FALSE);
return GetTrainerSpeciesFromRandomArray(RandomSeededModulo2(species, GetMaxTrainerNumberOfSpecies(TRUE)), TRUE);
}

u16 GetSpeciesRandomNotSeeded(u16 species)
u16 GetSpeciesRandomNotSeeded(u16 monType)
{
return GetSpeciesFromRandomArray(RandomModulo(species, GetMaxNumberOfSpecies(FALSE)), FALSE);
}
switch(monType)
{
case TRAINER_MONS:
return GetTrainerSpeciesFromRandomArray(RandomModulo(0, GetMaxTrainerNumberOfSpecies(FALSE)), FALSE);
case PLAYER_MONS:
return GetPlayerSpeciesFromRandomArray(RandomModulo(0, GetMaxPlayerNumberOfSpecies(FALSE)), FALSE);
case ALL_MONS:
return GetTrainerSpeciesFromRandomArray(RandomModulo(0, GetMaxTrainerNumberOfSpecies(TRUE)), TRUE);
}

u8 GetCurrentMaxMonGeneratedCount(void)
{
u32 speciesCountReduced = ((GetMaxNumberOfSpecies(FALSE) * 15) / 16);
return (gSaveBlock3Ptr->monsGeneratedCount / (speciesCountReduced)) + 1;
// Default Should Never Reach
return GetTrainerSpeciesFromRandomArray(RandomModulo(0, GetMaxTrainerNumberOfSpecies(FALSE)), FALSE);
}

u16 GetRandomSpeciesFlattenedCurve(void)
u16 GetRandomSpeciesFlattenedCurve(u16 monType)
{
u16 randomSpecies = 0;
u16 largestMonCount = gSaveBlock3Ptr->largestMonCount;
u16 notChosen = TRUE;
u8 maxChosenNumber = 0;
u16 breakOut = 0;

gSaveBlock3Ptr->monsGeneratedCount += 1;
maxChosenNumber = GetCurrentMaxMonGeneratedCount();

//SeedRngWithRtc();

while(notChosen)
{
randomSpecies = GetSpeciesRandomNotSeeded(0);
if(gSaveBlock3Ptr->monRolledCounts[randomSpecies] < maxChosenNumber)
randomSpecies = GetSpeciesRandomNotSeeded(monType);
if(gSaveBlock3Ptr->monRolledCounts[randomSpecies] == 0)
notChosen = FALSE;

breakOut++;
if(breakOut > 100000)
notChosen = FALSE;
if(breakOut > 700)
{
// Looping too much is intentionally used as the new Clear method because the arrays are broken apart, looping through this function is very fast,
// it will maybe slow down a trainer generation by 0.2 seconds every now and then, but thats not a big deal imo,
// the alternative is very complicated logic and thousands of bytes more of save space
ClearGeneratedMons();
breakOut = 0;
}
}

gSaveBlock3Ptr->monRolledCounts[randomSpecies] += 1;
if(gSaveBlock3Ptr->monRolledCounts[randomSpecies] > largestMonCount)
gSaveBlock3Ptr->largestMonCount = gSaveBlock3Ptr->monRolledCounts[randomSpecies] + 1;

return randomSpecies;

}

void ClearGeneratedMons(void)
{
u16 i = 0;
gSaveBlock3Ptr->monsGeneratedCount = 0;
for(i = 0; i < GetMaxNumberOfSpecies(FALSE); i++)
for(i = 0; i < GetMaxTrainerNumberOfSpecies(TRUE); i++)
{
gSaveBlock3Ptr->monRolledCounts[i] = 0;
}
Expand All @@ -1463,7 +1462,7 @@ void GenerateRandomSpeciesRewards(u16 *sRolledSpeciesPtr)
{
counter = 0;
counter2 = 0;
species = GetRandomSpeciesFlattenedCurve();
species = GetRandomSpeciesFlattenedCurve(PLAYER_MONS);

do
{
Expand All @@ -1472,9 +1471,9 @@ void GenerateRandomSpeciesRewards(u16 *sRolledSpeciesPtr)
//legendary check
if (gSaveBlock2Ptr->modeLegendaries == OPTIONS_OFF || (sRolledLegendAlready && (Random() % 10))) //reroll in case any legendaries, mythics or ultra beasts are determined
{
while (((IsSpeciesLegendary(species) || IsSpeciesMythical(species) || IsSpeciesUltraBeast(species) || IsSpeciesParadoxMon(species))) && counter < 30)
while (((IsSpeciesLegendary(species) || IsSpeciesMythical(species) || IsSpeciesUltraBeast(species) || IsSpeciesParadoxMon(species))) && counter < 100)
{
species = GetRandomSpeciesFlattenedCurve();
species = GetRandomSpeciesFlattenedCurve(PLAYER_MONS);
counter++;
}
}
Expand Down Expand Up @@ -1545,7 +1544,7 @@ void GenerateRandomSpeciesRewards(u16 *sRolledSpeciesPtr)
}


if (counter2 == 20) //exit in case of infinite loop
if (counter2 == 100) //exit in case of infinite loop
{
rerollMon = FALSE;
//DebugPrintf("no valid species found. Default: %d", species);
Expand All @@ -1554,7 +1553,7 @@ void GenerateRandomSpeciesRewards(u16 *sRolledSpeciesPtr)
if (rerollMon)
{
counter2++;
species = GetRandomSpeciesFlattenedCurve();
species = GetRandomSpeciesFlattenedCurve(PLAYER_MONS);
counter = 0;
}
}
Expand Down Expand Up @@ -1587,15 +1586,15 @@ void DebugTestRandomness(void)
{
for(partyNum = 0; partyNum < 5; partyNum++)
{
GetRandomSpeciesFlattenedCurve();
GetRandomSpeciesFlattenedCurve(ALL_MONS);
}
}
}
i++;
}

//DebugPrintf("\n\n\nDebugTestRandomness New");
for(i = 0; i < GetMaxNumberOfSpecies(TRUE); i++)
for(i = 0; i < GetMaxTrainerNumberOfSpecies(TRUE); i++)
{
StringCopy(gStringVar1, GetSpeciesName(i));
//DebugPrintf("Species %S: %d", &gStringVar1, gSaveBlock3Ptr->monRolledCounts[i]);
Expand Down Expand Up @@ -1931,11 +1930,11 @@ u16 RandomItemId(u16 itemId)
else if (ItemId_GetPocket(itemId) != POCKET_KEY_ITEMS)
{
randomItemCategory = Random32() % 1000;
if(randomItemCategory < 100)
if(randomItemCategory < 70)
itemId = sRandomXItems[RandomModulo(itemId + VarGet(VAR_PIT_FLOOR) + gSaveBlock1Ptr->pos.x, RANDOM_X_ITEM_COUNT)];
else if(randomItemCategory < 700)
itemId = sRandomConsumableValidItems[RandomModulo(itemId + VarGet(VAR_PIT_FLOOR) + gSaveBlock1Ptr->pos.x, RANDOM_CONSUMABLE_ITEM_COUNT)];
else if(randomItemCategory < 900)
else if(randomItemCategory < 920)
itemId = sRandomHeldValidItems[RandomModulo(itemId + VarGet(VAR_PIT_FLOOR) + gSaveBlock1Ptr->pos.x, RANDOM_HELD_ITEM_COUNT)];
else
itemId = sRandomBerryValidItems[RandomModulo(itemId + VarGet(VAR_PIT_FLOOR) + gSaveBlock1Ptr->pos.x, RANDOM_BERRY_ITEM_COUNT)];
Expand Down
36 changes: 34 additions & 2 deletions src/pit_species_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -5271,7 +5271,7 @@ static const u16 sRandomDynamicSpecies_76_100[] =
#endif
};

u32 GetMaxNumberOfSpecies(bool8 forceAllSpecies)
u32 GetMaxTrainerNumberOfSpecies(bool8 forceAllSpecies)
{
u8 floor = VarGet(VAR_PIT_FLOOR);

Expand All @@ -5294,7 +5294,7 @@ u32 GetMaxNumberOfSpecies(bool8 forceAllSpecies)
}
}

u32 GetSpeciesFromRandomArray(u16 index, bool8 forceAllSpecies)
u32 GetTrainerSpeciesFromRandomArray(u16 index, bool8 forceAllSpecies)
{
u8 floor = VarGet(VAR_PIT_FLOOR);

Expand All @@ -5316,3 +5316,35 @@ u32 GetSpeciesFromRandomArray(u16 index, bool8 forceAllSpecies)
return sRandomDynamicSpecies_76_100[index];
}
}

u32 GetMaxPlayerNumberOfSpecies(bool8 forceAllSpecies)
{
u8 floor = VarGet(VAR_PIT_FLOOR);

if (gSaveBlock2Ptr->modeChoiceEvoStage != EVOSTAGE_PROG || forceAllSpecies)
return RANDOM_DYNAMIC_SPECIES_COUNT_76_100;
else
{ // The Player Only Gets 4 Mon Options So They're Weighted Better Than Opponents Slightly. Can Update if you Want.
if (floor <= 25)
return RANDOM_DYNAMIC_SPECIES_COUNT_16_25;
if (floor <= 50)
return RANDOM_DYNAMIC_SPECIES_COUNT_51_75;
return RANDOM_DYNAMIC_SPECIES_COUNT_76_100;
}
}

u32 GetPlayerSpeciesFromRandomArray(u16 index, bool8 forceAllSpecies)
{
u8 floor = VarGet(VAR_PIT_FLOOR);

if (gSaveBlock2Ptr->modeChoiceEvoStage != EVOSTAGE_PROG || forceAllSpecies) // If Not Prog, The Evo Stage Basic/Evolved Is Handled By Rerolls In GenerateRandomSpeciesRewards()
return sRandomDynamicSpecies_76_100[index];
else
{ // The Player Only Gets 4 Mon Options So They're Weighted Better Than Opponents Slightly. Can Update if you Want.
if (floor <= 25)
return sRandomDynamicSpecies_16_25[index];
if (floor <= 50)
return sRandomDynamicSpecies_51_75[index];
return sRandomDynamicSpecies_76_100[index];
}
}
4 changes: 2 additions & 2 deletions src/pokedex_plus_hgss.c
Original file line number Diff line number Diff line change
Expand Up @@ -8904,7 +8904,7 @@ bool8 isDexCompleted(u8 mode)
{
u16 i, k;
u16 maxSpecies = NUM_SPECIES;
u16 maxSpeciesPit = GetMaxNumberOfSpecies(TRUE);
u16 maxSpeciesPit = GetMaxTrainerNumberOfSpecies(TRUE);
u16 invalidSpecies = 0;
u8 baseSpeciesHandled[NATIONAL_DEX_COUNT] = {0};

Expand Down Expand Up @@ -8948,7 +8948,7 @@ bool8 isDexCompleted(u8 mode)
// void printNatDex(void)
// {
// u16 i;
// u16 maxSpeciesPit = GetMaxNumberOfSpecies(TRUE);
// u16 maxSpeciesPit = GetMaxTrainerNumberOfSpecies(TRUE);

// for (i = 0; i < maxSpeciesPit; i++)
// DebugPrintf("i=%d, %d, %S, %d", i, SpeciesToNationalPokedexNum(AccessValidSpeciesArrayIndex(i)), gSpeciesInfo[AccessValidSpeciesArrayIndex(i)].speciesName, AccessValidSpeciesArrayIndex(i));
Expand Down
2 changes: 1 addition & 1 deletion src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -5195,7 +5195,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, s

if (gSaveBlock2Ptr->randomEvos == OPTIONS_ON && (targetSpecies != SPECIES_NONE))
{
targetSpecies = GetSpeciesRandomNotSeeded(targetSpecies);
targetSpecies = GetRandomSpeciesFlattenedCurve(ALL_MONS);
}

return targetSpecies;
Expand Down
Loading

0 comments on commit 1182dde

Please sign in to comment.