Skip to content

Commit 5e181fd

Browse files
Refactor pokerus and add configs
1 parent a55d603 commit 5e181fd

File tree

10 files changed

+230
-156
lines changed

10 files changed

+230
-156
lines changed

include/config/pokemon.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@
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+
6978
// Flag settings
7079
// To use the following features in scripting, replace the 0s with the flag ID you're assigning it to.
7180
// Eg: Replace with FLAG_UNUSED_0x264 so you can use that flag to toggle the feature.

include/pokemon.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ enum MonData {
5959
MON_DATA_FRIENDSHIP,
6060
MON_DATA_SMART,
6161
MON_DATA_POKERUS,
62+
MON_DATA_POKERUS_STRAIN,
63+
MON_DATA_POKERUS_DAYS_LEFT,
6264
MON_DATA_MET_LOCATION,
6365
MON_DATA_MET_LEVEL,
6466
MON_DATA_MET_GAME,
@@ -808,11 +810,6 @@ u16 ModifyStatByNature(u8 nature, u16 stat, u8 statIndex);
808810
void AdjustFriendship(struct Pokemon *mon, u8 event);
809811
void MonGainEVs(struct Pokemon *mon, u16 defeatedSpecies);
810812
u16 GetMonEVCount(struct Pokemon *mon);
811-
void RandomlyGivePartyPokerus(struct Pokemon *party);
812-
u8 CheckPartyPokerus(struct Pokemon *party, u8 selection);
813-
u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection);
814-
void UpdatePartyPokerusTime(u16 days);
815-
void PartySpreadPokerus(struct Pokemon *party);
816813
bool8 TryIncrementMonLevel(struct Pokemon *mon);
817814
u8 CanLearnTeachableMove(u16 species, u16 move);
818815
u8 GetMoveRelearnerMoves(struct Pokemon *mon, u16 *moves);

include/pokerus.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef GUARD_POKERUS_H
2+
#define GUARD_POKERUS_H
3+
4+
void RandomlyGivePartyPokerus(struct Pokemon *party);
5+
u8 CheckPartyPokerus(struct Pokemon *party, u8 selection);
6+
u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection);
7+
void UpdatePartyPokerusTime(u16 days);
8+
void PartySpreadPokerus(struct Pokemon *party);
9+
10+
#endif // GUARD_POKERUS_H

src/battle_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "pokeball.h"
4343
#include "pokedex.h"
4444
#include "pokemon.h"
45+
#include "pokerus.h"
4546
#include "random.h"
4647
#include "recorded_battle.h"
4748
#include "roamer.h"

src/clock.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#include "global.h"
2+
#include "berry.h"
23
#include "clock.h"
34
#include "event_data.h"
4-
#include "rtc.h"
5-
#include "time_events.h"
65
#include "field_specials.h"
6+
#include "field_weather.h"
77
#include "lottery_corner.h"
88
#include "dewford_trend.h"
9-
#include "tv.h"
10-
#include "field_weather.h"
11-
#include "berry.h"
129
#include "main.h"
1310
#include "overworld.h"
11+
#include "pokerus.h"
12+
#include "rtc.h"
13+
#include "time_events.h"
14+
#include "tv.h"
1415
#include "wallclock.h"
1516
#include "constants/form_change_types.h"
1617

src/field_specials.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "pokedex.h"
3535
#include "pokemon.h"
3636
#include "pokemon_storage_system.h"
37+
#include "pokerus.h"
3738
#include "random.h"
3839
#include "rayquaza_scene.h"
3940
#include "region_map.h"

src/party_menu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "pokemon_jump.h"
5353
#include "pokemon_storage_system.h"
5454
#include "pokemon_summary_screen.h"
55+
#include "pokerus.h"
5556
#include "region_map.h"
5657
#include "reshow_battle_screen.h"
5758
#include "scanline_effect.h"

src/pokemon.c

Lines changed: 13 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "pokemon_icon.h"
3636
#include "pokemon_summary_screen.h"
3737
#include "pokemon_storage_system.h"
38+
#include "pokerus.h"
3839
#include "random.h"
3940
#include "recorded_battle.h"
4041
#include "rtc.h"
@@ -2523,6 +2524,12 @@ u32 GetBoxMonData3(struct BoxPokemon *boxMon, s32 field, u8 *data)
25232524
case MON_DATA_POKERUS:
25242525
retVal = GetSubstruct3(boxMon)->pokerus;
25252526
break;
2527+
case MON_DATA_POKERUS_STRAIN:
2528+
retVal = (GetSubstruct3(boxMon)->pokerus & 0xF0);
2529+
break;
2530+
case MON_DATA_POKERUS_DAYS_LEFT:
2531+
retVal = (GetSubstruct3(boxMon)->pokerus & 0x0F);
2532+
break;
25262533
case MON_DATA_MET_LOCATION:
25272534
retVal = GetSubstruct3(boxMon)->metLocation;
25282535
break;
@@ -3019,6 +3026,12 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
30193026
case MON_DATA_POKERUS:
30203027
SET8(GetSubstruct3(boxMon)->pokerus);
30213028
break;
3029+
case MON_DATA_POKERUS_STRAIN:
3030+
GetSubstruct3(boxMon)->pokerus = (*data << 4) | (GetSubstruct3(boxMon)->pokerus & 0x0F);
3031+
break;
3032+
case MON_DATA_POKERUS_DAYS_LEFT:
3033+
GetSubstruct3(boxMon)->pokerus = (GetSubstruct3(boxMon)->pokerus & 0xF0) | *data;
3034+
break;
30223035
case MON_DATA_MET_LOCATION:
30233036
SET8(GetSubstruct3(boxMon)->metLocation);
30243037
break;
@@ -5408,152 +5421,6 @@ u16 GetMonEVCount(struct Pokemon *mon)
54085421
return count;
54095422
}
54105423

5411-
void RandomlyGivePartyPokerus(struct Pokemon *party)
5412-
{
5413-
u16 rnd = Random();
5414-
if (rnd == 0x4000 || rnd == 0x8000 || rnd == 0xC000)
5415-
{
5416-
struct Pokemon *mon;
5417-
5418-
do
5419-
{
5420-
rnd = Random() % PARTY_SIZE;
5421-
mon = &party[rnd];
5422-
}
5423-
while (!GetMonData(mon, MON_DATA_SPECIES, 0) || GetMonData(mon, MON_DATA_IS_EGG, 0));
5424-
5425-
if (!(CheckPartyHasHadPokerus(party, 1u << rnd)))
5426-
{
5427-
u8 rnd2;
5428-
5429-
do
5430-
{
5431-
rnd2 = Random();
5432-
}
5433-
while ((rnd2 & 0x7) == 0);
5434-
5435-
if (rnd2 & 0xF0)
5436-
rnd2 &= 0x7;
5437-
5438-
rnd2 |= (rnd2 << 4);
5439-
rnd2 &= 0xF3;
5440-
rnd2++;
5441-
5442-
SetMonData(&party[rnd], MON_DATA_POKERUS, &rnd2);
5443-
}
5444-
}
5445-
}
5446-
5447-
u8 CheckPartyPokerus(struct Pokemon *party, u8 selection)
5448-
{
5449-
u8 retVal;
5450-
5451-
int partyIndex = 0;
5452-
unsigned curBit = 1;
5453-
retVal = 0;
5454-
5455-
if (selection)
5456-
{
5457-
do
5458-
{
5459-
if ((selection & 1) && (GetMonData(&party[partyIndex], MON_DATA_POKERUS, 0) & 0xF))
5460-
retVal |= curBit;
5461-
partyIndex++;
5462-
curBit <<= 1;
5463-
selection >>= 1;
5464-
}
5465-
while (selection);
5466-
}
5467-
else if (GetMonData(&party[0], MON_DATA_POKERUS, 0) & 0xF)
5468-
{
5469-
retVal = 1;
5470-
}
5471-
5472-
return retVal;
5473-
}
5474-
5475-
u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection)
5476-
{
5477-
u8 retVal;
5478-
5479-
int partyIndex = 0;
5480-
unsigned curBit = 1;
5481-
retVal = 0;
5482-
5483-
if (selection)
5484-
{
5485-
do
5486-
{
5487-
if ((selection & 1) && GetMonData(&party[partyIndex], MON_DATA_POKERUS, 0))
5488-
retVal |= curBit;
5489-
partyIndex++;
5490-
curBit <<= 1;
5491-
selection >>= 1;
5492-
}
5493-
while (selection);
5494-
}
5495-
else if (GetMonData(&party[0], MON_DATA_POKERUS, 0))
5496-
{
5497-
retVal = 1;
5498-
}
5499-
5500-
return retVal;
5501-
}
5502-
5503-
void UpdatePartyPokerusTime(u16 days)
5504-
{
5505-
int i;
5506-
for (i = 0; i < PARTY_SIZE; i++)
5507-
{
5508-
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, 0))
5509-
{
5510-
u8 pokerus = GetMonData(&gPlayerParty[i], MON_DATA_POKERUS, 0);
5511-
if (pokerus & 0xF)
5512-
{
5513-
if ((pokerus & 0xF) < days || days > 4)
5514-
pokerus &= 0xF0;
5515-
else
5516-
pokerus -= days;
5517-
5518-
if (pokerus == 0)
5519-
pokerus = 0x10;
5520-
5521-
SetMonData(&gPlayerParty[i], MON_DATA_POKERUS, &pokerus);
5522-
}
5523-
}
5524-
}
5525-
}
5526-
5527-
void PartySpreadPokerus(struct Pokemon *party)
5528-
{
5529-
if ((Random() % 3) == 0)
5530-
{
5531-
int i;
5532-
for (i = 0; i < PARTY_SIZE; i++)
5533-
{
5534-
if (GetMonData(&party[i], MON_DATA_SPECIES, 0))
5535-
{
5536-
u8 pokerus = GetMonData(&party[i], MON_DATA_POKERUS, 0);
5537-
u8 curPokerus = pokerus;
5538-
if (pokerus)
5539-
{
5540-
if (pokerus & 0xF)
5541-
{
5542-
// Spread to adjacent party members.
5543-
if (i != 0 && !(GetMonData(&party[i - 1], MON_DATA_POKERUS, 0) & 0xF0))
5544-
SetMonData(&party[i - 1], MON_DATA_POKERUS, &curPokerus);
5545-
if (i != (PARTY_SIZE - 1) && !(GetMonData(&party[i + 1], MON_DATA_POKERUS, 0) & 0xF0))
5546-
{
5547-
SetMonData(&party[i + 1], MON_DATA_POKERUS, &curPokerus);
5548-
i++;
5549-
}
5550-
}
5551-
}
5552-
}
5553-
}
5554-
}
5555-
}
5556-
55575424
bool8 TryIncrementMonLevel(struct Pokemon *mon)
55585425
{
55595426
u16 species = GetMonData(mon, MON_DATA_SPECIES, 0);

src/pokemon_summary_screen.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "pokemon_sprite_visualizer.h"
3434
#include "pokemon_storage_system.h"
3535
#include "pokemon_summary_screen.h"
36+
#include "pokerus.h"
3637
#include "region_map.h"
3738
#include "scanline_effect.h"
3839
#include "sound.h"

0 commit comments

Comments
 (0)