Skip to content

Commit

Permalink
cleaned up [ov6_02240C9C.c](src/overlay006/ov6_02240C9C.c)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanDoesProgramming664 committed Jan 18, 2025
1 parent af5fe44 commit 63d8937
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 102 deletions.
1 change: 1 addition & 0 deletions include/constants/wild_encounters.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define MAX_RADAR_ENCOUNTERS 4
#define MAX_DUAL_SLOT_ENCOUNTERS 2
#define MAX_WATER_ENCOUNTERS 5
#define NUM_RODS 3

enum ENCOUNTER_TYPE {
ENCOUNTER_TYPE_GRASS = 0,
Expand Down
159 changes: 57 additions & 102 deletions src/overlay006/ov6_02240C9C.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,37 @@ static const UnkStruct_ov6_02248FF0 WildEncounters_UnownTables[] = {
{ 0x2, UnownOnlyExcQue }
};

static const u8 sGroundEncounterSlotRates[MAX_GRASS_ENCOUNTERS] = {
20,
20,
10,
10,
10,
10,
10,
10,
5,
5,
4,
4,
1,
1
};

static const u8 sWaterEncounterSlotRates[MAX_WATER_ENCOUNTERS] = {
60,
30,
5,
4,
1
};

static const u8 sRodEncounterSlotRates[NUM_RODS][MAX_WATER_ENCOUNTERS] = {
{60, 30, 5, 4, 1}, //Old Rod
{40, 40, 15, 4, 1}, // Good Rod
{40, 40, 15, 4, 1}, // Super Rod
};

void WildEncounters_ReplaceTimedEncounters(const WildEncounters *encounterData, int *timedSlot1, int *timedSlot2)
{
int timeOfDay = GetTimeOfDay();
Expand Down Expand Up @@ -812,129 +843,53 @@ static BOOL ov6_022418DC(FieldSystem *fieldSystem, u32 encounterRate)

static u8 GetGroundEncounterSlot(void)
{
u8 roll = inline_020564D0(100); // a common rng function

if (roll < 20) {
return 0;
}

if (roll >= 20 && roll < 40) {
return 1;
}

if (roll >= 40 && roll < 50) {
return 2;
}

if (roll >= 50 && roll < 60) {
return 3;
}
u8 encounterSlot;

if (roll >= 60 && roll < 70) {
return 4;
}

if (roll >= 70 && roll < 80) {
return 5;
}

if (roll >= 80 && roll < 85) {
return 6;
}

if (roll >= 85 && roll < 90) {
return 7;
}

if (roll >= 90 && roll < 94) {
return 8;
}

if (roll >= 94 && roll < 98) {
return 9;
}
u8 roll = inline_020564D0(100); // a common rng function

if (roll == 98) {
return 10;
u8 hit = 0;
for (encounterSlot = 0; encounterSlot < MAX_GRASS_ENCOUNTERS; encounterSlot++) {
hit += sGroundEncounterSlotRates[encounterSlot];
if (roll < hit - 1) {
return encounterSlot;
}
}

return 11;
return encounterSlot;
}

static u8 GetWaterEncounterSlot(void)
{
u8 roll = inline_020564D0(100); // a common rng function

if (roll < 60) {
return 0;
}
u8 encounterSlot;

if (roll >= 60 && roll < 90) {
return 1;
}

if (roll >= 90 && roll < 95) {
return 2;
}
u8 roll = inline_020564D0(100); // a common rng function

if (roll >= 95 && roll < 99) {
return 3;
u8 hit = 0;
for (encounterSlot = 0; encounterSlot < MAX_WATER_ENCOUNTERS; encounterSlot++) {
hit += sWaterEncounterSlotRates[encounterSlot];
if (roll < hit) {
return encounterSlot;
}
}

return 4;
return encounterSlot;
}

static u8 GetRodEncounterSlot(const int fishingRodType)
{
u8 encSlot = 0;
u8 encounterSlot;

u8 roll = inline_020564D0(100); // a common rng function

switch (fishingRodType) {
case FISHING_TYPE_OLD_ROD:
if (roll < 60) {
encSlot = 0;
} else if (roll < 90) {
encSlot = 1;
} else if (roll < 95) {
encSlot = 2;
} else if (roll < 99) {
encSlot = 3;
} else {
encSlot = 4;
}
break;
case FISHING_TYPE_GOOD_ROD:
if (roll < 40) {
encSlot = 0;
} else if (roll < 80) {
encSlot = 1;
} else if (roll < 95) {
encSlot = 2;
} else if (roll < 99) {
encSlot = 3;
} else {
encSlot = 4;
}
break;
case FISHING_TYPE_SUPER_ROD:
if (roll < 40) {
encSlot = 0;
} else if (roll < 80) {
encSlot = 1;
} else if (roll < 95) {
encSlot = 2;
} else if (roll < 99) {
encSlot = 3;
} else {
encSlot = 4;
u8 hit = 0;
for (encounterSlot = 0; encounterSlot < MAX_WATER_ENCOUNTERS; encounterSlot++) {
hit += sRodEncounterSlotRates[fishingRodType][encounterSlot];
if (roll < hit) {
return encounterSlot;
}
break;
default:
GF_ASSERT(FALSE);
}
}

return encSlot;
return encounterSlot;
}

static void ov6_02241A90(Pokemon *mon, u8 *encounterRate)
Expand Down

0 comments on commit 63d8937

Please sign in to comment.