Skip to content

Commit 80787a8

Browse files
Misc improvements to pokerus code, 2 new egg related configs
1 parent 5e181fd commit 80787a8

File tree

8 files changed

+95
-111
lines changed

8 files changed

+95
-111
lines changed

include/config/pokemon.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@
6666
#define P_LEARNSET_HELPER_TEACHABLE TRUE // If TRUE, teachable_learnsets.h will be populated by tools/learnset_helpers/make_teachables.py using the included JSON files based on available TMs and tutors.
6767
#define P_TUTOR_MOVES_ARRAY FALSE // If TRUE, generates a gTutorMoves array automatically using make_teachables.py. (generally not needed, but the HGSS Pokedex has an optional use for it)
6868

69-
//Pokerus settings
70-
//For pokerus, we refer to infection as a pokemon catching Pokerus from an enemy pokemon (trainer or wild) and we refer to spreading as pokemon catching pokerus from another infected pokemon in the party
71-
#define P_POKERUS_ENABLED TRUE // If FALSE, Pokerus will have no effect, won't be shown and won't be aquired in any way but save data won't be affected
72-
#define P_POKERUS_STRAIN_DISTRIBUTION GEN_LATEST // Pokerus has 16 different strains and their probability distribution change depending on generation
73-
#define P_POKERUS_SPREAD_ADJACENECY GEN_LATEST // In Gen 2, Pokerus spread to one adjacent pokemon but it spreads to both adjacent pokemon in gen 3+
74-
#define P_POKERUS_SPREAD_DAYS_LEFT GEN_LATEST // In Gen 2, a freshly spreaded pokemon will get its full infection duration based on strain. In gen 3+, the pokerus duration will copy the duration from the pokemon it was spreaded from
75-
#define P_POKERUS_INFECT_AGAIN TRUE // If TRUE, your party can get infected even when it is already infected with Pokerus (doesn't affect spreading, only TRUE in gen 2)
76-
#define P_POKERUS_INFECTION_FLAG 0 // If Pokerus can only get infected if this flag is set or undefined (0). This emulates a gen 2 mechanic where Pokemon can only get infected by Pokerus after visiting Goldernrod. This does not affect spreading
77-
7869
// Flag settings
7970
// To use the following features in scripting, replace the 0s with the flag ID you're assigning it to.
8071
// Eg: Replace with FLAG_UNUSED_0x264 so you can use that flag to toggle the feature.

include/config/pokerus.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef GUARD_CONFIG_POKERUS_H
2+
#define GUARD_CONFIG_POKERUS_H
3+
4+
//For pokerus, we refer to infection as a pokemon catching Pokerus from an enemy pokemon (trainer or wild) and we refer to spreading as pokemon catching pokerus from another infected pokemon in the party
5+
#define P_POKERUS_ENABLED TRUE // If FALSE, Pokerus will have no effect, won't be shown and won't be aquired in any way but save data won't be affected
6+
#define P_POKERUS_STRAIN_DISTRIBUTION GEN_LATEST // Pokerus has 16 different strains and their probability distribution change depending on generation
7+
#define P_POKERUS_SPREAD_ADJACENECY GEN_LATEST // In Gen 2, Pokerus spread to one adjacent pokemon but it spreads to both adjacent pokemon in gen 3+
8+
#define P_POKERUS_SPREAD_DAYS_LEFT GEN_LATEST // In Gen 2, a freshly spreaded pokemon will get its full infection duration based on strain. In gen 3+, the pokerus duration will copy the duration from the pokemon it was spreaded from
9+
#define P_POKERUS_INFECT_AGAIN TRUE // If TRUE, your party can get infected even when it is already infected with Pokerus (doesn't affect spreading, only TRUE in gen 2)
10+
#define P_POKERUS_INFECT_EGG FALSE // If TRUE, eggs can receive Pokerus from spread and direction infection (gen 2). If FALSE, eggs can receive Pokerus from spread but not direct infection (gen 3). Behavior is unknown in other gens.
11+
#define P_POKERUS_VISIBLE_ON_EGG TRUE // Controls if eggs can show pokerus symbol in summary screen (TRUE from gen 3 to 6, FALSE in gen 2,7 and 8)
12+
#define P_POKERUS_INFECTION_FLAG 0 // If Pokerus can only get infected if this flag is set or undefined (0). This emulates a gen 2 mechanic where Pokemon can only get infected by Pokerus after visiting Goldernrod. This does not affect spreading
13+
14+
#endif // GUARD_CONFIG_POKERUS_H

include/pokerus.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#define GUARD_POKERUS_H
33

44
void RandomlyGivePartyPokerus(struct Pokemon *party);
5-
u8 CheckPartyPokerus(struct Pokemon *party, u8 selection);
6-
u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection);
5+
u8 CheckPartyPokerus(struct Pokemon *party);
6+
u8 CheckMonPokerus(struct Pokemon *mon);
7+
u8 CheckMonHasHadPokerus(struct Pokemon *mon);
78
void UpdatePartyPokerusTime(u16 days);
89
void PartySpreadPokerus(struct Pokemon *party);
910

10-
#endif // GUARD_POKERUS_H
11+
#endif // GUARD_POKERUS_H

src/field_specials.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,10 +1490,7 @@ bool8 ScriptCheckFreePokemonStorageSpace(void)
14901490

14911491
bool8 IsPokerusInParty(void)
14921492
{
1493-
if (!CheckPartyPokerus(gPlayerParty, (1 << PARTY_SIZE) - 1))
1494-
return FALSE;
1495-
1496-
return TRUE;
1493+
return CheckPartyPokerus(gPlayerParty);
14971494
}
14981495

14991496
// Task data for Task_ShakeCamera

src/party_menu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
#include "constants/party_menu.h"
8080
#include "constants/rgb.h"
8181
#include "constants/songs.h"
82+
#include "config/pokerus.h"
8283

8384
enum {
8485
MENU_SUMMARY,
@@ -2134,7 +2135,7 @@ u8 GetMonAilment(struct Pokemon *mon)
21342135
ailment = GetAilmentFromStatus(GetMonData(mon, MON_DATA_STATUS));
21352136
if (ailment != AILMENT_NONE)
21362137
return ailment;
2137-
if (CheckPartyPokerus(mon, 0))
2138+
if (CheckMonPokerus(mon) && (P_POKERUS_VISIBLE_ON_EGG || !GetMonData(mon, MON_DATA_IS_EGG)))
21382139
return AILMENT_PKRS;
21392140
return AILMENT_NONE;
21402141
}

src/pokemon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5346,7 +5346,7 @@ void MonGainEVs(struct Pokemon *mon, u16 defeatedSpecies)
53465346
if (totalEVs >= currentEVCap)
53475347
break;
53485348

5349-
if (CheckPartyHasHadPokerus(mon, 0))
5349+
if (CheckMonHasHadPokerus(mon))
53505350
multiplier = 2;
53515351
else
53525352
multiplier = 1;

src/pokemon_summary_screen.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "constants/region_map_sections.h"
5353
#include "constants/rgb.h"
5454
#include "constants/songs.h"
55+
#include "config/pokerus.h"
5556

5657
// Screen titles (upper left)
5758
#define PSS_LABEL_WINDOW_POKEMON_INFO_TITLE 0
@@ -2967,7 +2968,8 @@ static void TilemapFiveMovesDisplay(u16 *dst, u16 palette, bool8 remove)
29672968

29682969
static void DrawPokerusCuredSymbol(struct Pokemon *mon) // This checks if the mon has been cured of pokerus
29692970
{
2970-
if (!CheckPartyPokerus(mon, 0) && CheckPartyHasHadPokerus(mon, 0)) // If yes it draws the cured symbol
2971+
if (!CheckMonPokerus(mon) && CheckMonHasHadPokerus(mon)
2972+
&& (P_POKERUS_VISIBLE_ON_EGG || !GetMonData(mon, MON_DATA_IS_EGG))) // If yes it draws the cured symbol
29712973
{
29722974
sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0][0x223] = 0x2C;
29732975
sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][1][0x223] = 0x2C;

src/pokerus.c

Lines changed: 70 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
#include "pokemon.h"
44
#include "pokerus.h"
55
#include "random.h"
6+
#include "config/pokerus.h"
67

78
void RandomlyGivePartyPokerus(struct Pokemon *party)
89
{
910
if (!P_POKERUS_ENABLED)
1011
return;
1112

12-
if (!P_POKERUS_INFECT_AGAIN && CheckPartyPokerus(gPlayerParty, (1 << PARTY_SIZE) - 1))
13+
if (!P_POKERUS_INFECT_AGAIN && CheckPartyPokerus(party))
1314
return;
1415

1516
if (P_POKERUS_INFECTION_FLAG && !FlagGet(P_POKERUS_INFECTION_FLAG))
@@ -25,9 +26,9 @@ void RandomlyGivePartyPokerus(struct Pokemon *party)
2526
rnd = Random() % PARTY_SIZE;
2627
mon = &party[rnd];
2728
}
28-
while (!GetMonData(mon, MON_DATA_SPECIES, 0) || GetMonData(mon, MON_DATA_IS_EGG, 0));
29+
while (!GetMonData(mon, MON_DATA_SPECIES) || (!P_POKERUS_INFECT_EGG && GetMonData(mon, MON_DATA_IS_EGG)));
2930

30-
if (!(CheckPartyHasHadPokerus(party, 1u << rnd)))
31+
if (!(CheckMonHasHadPokerus(&party[rnd])))
3132
{
3233
u32 strain;
3334
u32 daysLeft;
@@ -46,95 +47,73 @@ void RandomlyGivePartyPokerus(struct Pokemon *party)
4647
}
4748
}
4849

49-
u8 CheckPartyPokerus(struct Pokemon *party, u8 selection)
50+
u8 CheckPartyPokerus(struct Pokemon *party)
5051
{
5152
if (!P_POKERUS_ENABLED)
5253
return FALSE;
5354

54-
u8 retVal;
55-
int partyIndex = 0;
56-
unsigned curBit = 1;
57-
retVal = 0;
58-
59-
if (selection)
60-
{
61-
do
62-
{
63-
if ((selection & 1) && GetMonData(&party[partyIndex], MON_DATA_POKERUS_DAYS_LEFT))
64-
retVal |= curBit;
65-
partyIndex++;
66-
curBit <<= 1;
67-
selection >>= 1;
68-
}
69-
while (selection);
70-
}
71-
else if (GetMonData(&party[0], MON_DATA_POKERUS_DAYS_LEFT, 0))
55+
for (u32 i = 0; i < PARTY_SIZE; i++)
7256
{
73-
retVal = 1;
57+
if (!GetMonData(&party[i], MON_DATA_SPECIES))
58+
continue;
59+
60+
if (GetMonData(&party[i], MON_DATA_POKERUS_DAYS_LEFT))
61+
return TRUE;
7462
}
7563

76-
return retVal;
64+
return FALSE;
7765
}
7866

79-
u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection)
67+
u8 CheckMonPokerus(struct Pokemon *mon)
8068
{
8169
if (!P_POKERUS_ENABLED)
8270
return FALSE;
8371

84-
u8 retVal;
85-
int partyIndex = 0;
86-
unsigned curBit = 1;
87-
retVal = 0;
72+
if (GetMonData(mon, MON_DATA_POKERUS_DAYS_LEFT))
73+
return TRUE;
8874

89-
if (selection)
90-
{
91-
do
92-
{
93-
if ((selection & 1) && GetMonData(&party[partyIndex], MON_DATA_POKERUS_STRAIN))
94-
retVal |= curBit;
95-
partyIndex++;
96-
curBit <<= 1;
97-
selection >>= 1;
98-
}
99-
while (selection);
100-
}
101-
else if (GetMonData(&party[0], MON_DATA_POKERUS_STRAIN))
102-
{
103-
retVal = 1;
104-
}
75+
return FALSE;
76+
}
77+
78+
u8 CheckMonHasHadPokerus(struct Pokemon *mon)
79+
{
80+
if (!P_POKERUS_ENABLED)
81+
return FALSE;
82+
83+
if (GetMonData(mon, MON_DATA_POKERUS_STRAIN))
84+
return TRUE;
10585

106-
return retVal;
86+
return FALSE;
10787
}
10888

10989
void UpdatePartyPokerusTime(u16 days)
11090
{
11191
if (!P_POKERUS_ENABLED)
11292
return;
11393

114-
int i;
115-
for (i = 0; i < PARTY_SIZE; i++)
94+
for (u32 i = 0; i < PARTY_SIZE; i++)
11695
{
117-
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, 0))
96+
if (!GetMonData(&gPlayerParty[i], MON_DATA_SPECIES))
97+
continue;
98+
99+
u32 strain = GetMonData(&gPlayerParty[i], MON_DATA_POKERUS_STRAIN);
100+
u32 daysLeft = GetMonData(&gPlayerParty[i], MON_DATA_POKERUS_DAYS_LEFT);
101+
if (daysLeft)
118102
{
119-
u32 strain = GetMonData(&gPlayerParty[i], MON_DATA_POKERUS_STRAIN, 0);
120-
u32 daysLeft = GetMonData(&gPlayerParty[i], MON_DATA_POKERUS_DAYS_LEFT, 0);
121-
if (daysLeft)
103+
if (daysLeft < days || days > 4)
104+
daysLeft = 0;
105+
else
106+
daysLeft -= days;
107+
108+
//If the strain was 0, we changed it to 1 when the pokerus disappear to remember the pokemon was infected by pokerus
109+
// (otherwise its data would look the same as unaffected pokemon)
110+
if (daysLeft == 0 && strain == 0)
122111
{
123-
if (daysLeft < days || days > 4)
124-
daysLeft = 0;
125-
else
126-
daysLeft -= days;
127-
128-
//If the strain was 0, we changed it to 1 when the pokerus disappear to remember the pokemon was infected by pokerus
129-
// (otherwise its data would look the same as unaffected pokemon)
130-
if (daysLeft == 0 && strain == 0)
131-
{
132-
strain = 1;
133-
SetMonData(&gPlayerParty[i], MON_DATA_POKERUS, &strain);
134-
}
135-
136-
SetMonData(&gPlayerParty[i], MON_DATA_POKERUS, &daysLeft);
112+
strain = 1;
113+
SetMonData(&gPlayerParty[i], MON_DATA_POKERUS_STRAIN, &strain);
137114
}
115+
116+
SetMonData(&gPlayerParty[i], MON_DATA_POKERUS_DAYS_LEFT, &daysLeft);
138117
}
139118
}
140119
}
@@ -152,35 +131,34 @@ void PartySpreadPokerus(struct Pokemon *party)
152131
if (!P_POKERUS_ENABLED)
153132
return;
154133

155-
if ((Random() % 3) == 0)
134+
if (Random() % 3)
135+
return;
136+
137+
for (u32 i = 0; i < PARTY_SIZE; i++)
156138
{
157-
int i;
158-
for (i = 0; i < PARTY_SIZE; i++)
139+
if (!GetMonData(&party[i], MON_DATA_SPECIES))
140+
continue;
141+
142+
u32 strain = GetMonData(&party[i], MON_DATA_POKERUS_STRAIN);
143+
u32 daysLeft = GetMonData(&party[i], MON_DATA_POKERUS_DAYS_LEFT);
144+
if (daysLeft)
159145
{
160-
if (GetMonData(&party[i], MON_DATA_SPECIES, 0))
146+
bool32 spreadUp = TRUE, spreadDown = TRUE;
147+
if (P_POKERUS_SPREAD_ADJACENECY < GEN_3)
161148
{
162-
u32 strain = GetMonData(&party[i], MON_DATA_POKERUS_STRAIN);
163-
u32 daysLeft = GetMonData(&party[i], MON_DATA_POKERUS_DAYS_LEFT);
164-
if (daysLeft)
165-
{
166-
bool32 spreadUp = TRUE, spreadDown = TRUE;
167-
if (P_POKERUS_SPREAD_ADJACENECY < GEN_3)
168-
{
169-
if (i == (CalculatePlayerPartyCount() - 1)
170-
|| (Random() % 2))
171-
spreadUp = FALSE;
172-
else
173-
spreadDown = FALSE;
174-
}
175-
if (spreadDown && i != 0 && !GetMonData(&party[i - 1], MON_DATA_POKERUS_STRAIN))
176-
SpreadPokerusToSpecificMon(&party[i - 1], strain, daysLeft);
177-
if (spreadUp && i != (PARTY_SIZE - 1) && !GetMonData(&party[i + 1], MON_DATA_POKERUS_STRAIN))
178-
{
179-
SpreadPokerusToSpecificMon(&party[i + 1], strain, daysLeft);
180-
i++;
181-
}
182-
}
149+
if (i == (gPlayerPartyCount - 1)
150+
|| (Random() % 2))
151+
spreadUp = FALSE;
152+
else
153+
spreadDown = FALSE;
154+
}
155+
if (spreadDown && i != 0 && !GetMonData(&party[i - 1], MON_DATA_POKERUS_STRAIN))
156+
SpreadPokerusToSpecificMon(&party[i - 1], strain, daysLeft);
157+
if (spreadUp && i != (PARTY_SIZE - 1) && !GetMonData(&party[i + 1], MON_DATA_POKERUS_STRAIN))
158+
{
159+
SpreadPokerusToSpecificMon(&party[i + 1], strain, daysLeft);
160+
i++;
183161
}
184162
}
185163
}
186-
}
164+
}

0 commit comments

Comments
 (0)