Skip to content

Commit e756a2e

Browse files
Add rng rigging and config to function test engines; add pokerus tests; misc pokerus changes
1 parent 80787a8 commit e756a2e

16 files changed

+922
-83
lines changed

include/config/pokerus.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
#define GUARD_CONFIG_POKERUS_H
33

44
//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
5+
#define 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 POKERUS_STRAIN_DISTRIBUTION GEN_LATEST // Pokerus has 16 different strains and their probability distribution change depending on generation
7+
#define POKERUS_SPREAD_ADJACENCY GEN_LATEST // In Gen 2, Pokerus spread to one adjacent pokemon but it spreads to both adjacent pokemon in gen 3+
8+
#define 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 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 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 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 POKERUS_FLAG_INFECTION 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+
//Weird Pokerus behaviors that could be considered bugs. They are TRUE in vanilla Emerald but set to FALSE by default in Expansion (behaviors in other gens is unknown)
15+
#define POKERUS_HERD_IMMUNITY FALSE // If TRUE, pokemon who have been previously infected by the pokerus in your party reduce the chances of your party getting infected by the Pokerus (because they can be rolled at the target of the infection but are now "immune")
16+
#define POKERUS_WEAK_VARIANT FALSE // If TRUE, the variant 0 of pokerus can be erased by stronger variant when Pokerus is spreading
17+
18+
#define POKERUS_INFECTION_ODDS 3 // Actual probability is POKERUS_INFECTION_ODDS/65536
19+
#define POKERUS_SPREAD_ODDS 21846 // Actual probability is POKERUS_SPREAD_ODDS/65536 (21846 should correspond to the vanilla Random() % 3)
1320

1421
#endif // GUARD_CONFIG_POKERUS_H

include/constants/generational_changes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ enum GenConfigTag
4141
GEN_CONFIG_PRANKSTER_DARK_TYPES,
4242
GEN_CONFIG_DESTINY_BOND_FAIL,
4343
GEN_CONFIG_POWDER_RAIN,
44+
POKERUS_CONFIG_ENABLED,
45+
POKERUS_CONFIG_STRAIN_DISTRIBUTION,
46+
POKERUS_CONFIG_SPREAD_ADJACENCY,
47+
POKERUS_CONFIG_SPREAD_DAYS_LEFT,
48+
POKERUS_CONFIG_INFECT_AGAIN,
49+
POKERUS_CONFIG_INFECT_EGG,
50+
POKERUS_CONFIG_HERD_IMMUNITY,
51+
POKERUS_CONFIG_WEAK_VARIANT,
4452
GEN_CONFIG_COUNT
4553
};
4654

include/generational_changes.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "constants/generational_changes.h"
55
#include "config/battle.h"
6-
6+
#include "config/pokerus.h"
77
static const u8 sGenerationalChanges[GEN_CONFIG_COUNT] =
88
{
99
[GEN_CONFIG_CRIT_CHANCE] = B_CRIT_CHANCE,
@@ -44,6 +44,13 @@ static const u8 sGenerationalChanges[GEN_CONFIG_COUNT] =
4444
[GEN_CONFIG_PRANKSTER_DARK_TYPES] = B_PRANKSTER_DARK_TYPES,
4545
[GEN_CONFIG_DESTINY_BOND_FAIL] = B_DESTINY_BOND_FAIL,
4646
[GEN_CONFIG_POWDER_RAIN] = B_POWDER_RAIN,
47+
[POKERUS_CONFIG_ENABLED] = POKERUS_ENABLED,
48+
[POKERUS_CONFIG_SPREAD_ADJACENCY] = POKERUS_SPREAD_ADJACENCY,
49+
[POKERUS_CONFIG_SPREAD_DAYS_LEFT] = POKERUS_SPREAD_DAYS_LEFT,
50+
[POKERUS_CONFIG_INFECT_AGAIN] = POKERUS_INFECT_AGAIN,
51+
[POKERUS_CONFIG_INFECT_EGG] = POKERUS_INFECT_EGG,
52+
[POKERUS_CONFIG_HERD_IMMUNITY] = POKERUS_HERD_IMMUNITY,
53+
[POKERUS_CONFIG_WEAK_VARIANT] = POKERUS_WEAK_VARIANT,
4754
};
4855

4956
#if TESTING

include/pokerus.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#ifndef GUARD_POKERUS_H
22
#define GUARD_POKERUS_H
33

4-
void RandomlyGivePartyPokerus(struct Pokemon *party);
5-
u8 CheckPartyPokerus(struct Pokemon *party);
6-
u8 CheckMonPokerus(struct Pokemon *mon);
7-
u8 CheckMonHasHadPokerus(struct Pokemon *mon);
4+
u32 GetDaysLeftBasedOnStrain(u32 strain);
5+
void RandomlyGivePartyPokerus(void);
6+
bool32 CheckPartyPokerus(void);
7+
bool32 CheckMonPokerus(struct Pokemon *mon);
8+
bool32 CheckMonHasHadPokerus(struct Pokemon *mon);
89
void UpdatePartyPokerusTime(u16 days);
9-
void PartySpreadPokerus(struct Pokemon *party);
10+
void PartySpreadPokerus(void);
1011

1112
#endif // GUARD_POKERUS_H

include/random.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ enum RandomTag
215215
RNG_AI_REFRESH_TRICK_ROOM_ON_LAST_TURN,
216216
RNG_AI_APPLY_TAILWIND_ON_LAST_TURN_OF_TRICK_ROOM,
217217
RNG_WRAP,
218+
RNG_POKERUS_PARTY_MEMBER,
219+
RNG_POKERUS_INFECTION,
220+
RNG_POKERUS_STRAIN_DISTRIBUTION,
221+
RNG_POKERUS_SPREAD,
222+
RNG_POKERUS_SPREAD_SIDE,
218223
};
219224

220225
#define RandomWeighted(tag, ...) \

include/test/battle.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -622,18 +622,12 @@ struct QueuedEvent
622622
} as;
623623
};
624624

625-
struct TurnRNG
626-
{
627-
u16 tag;
628-
u16 value;
629-
};
630-
631625
struct BattlerTurn
632626
{
633627
u8 hit:2;
634628
u8 criticalHit:2;
635629
u8 secondaryEffect:2;
636-
struct TurnRNG rng;
630+
struct RiggedRNG rng;
637631
};
638632

639633
struct ExpectedAIAction
@@ -969,7 +963,7 @@ enum { TURN_CLOSED, TURN_OPEN, TURN_CLOSING };
969963
#define SKIP_TURN(battler) SkipTurn(__LINE__, battler)
970964
#define SEND_OUT(battler, partyIndex) SendOut(__LINE__, battler, partyIndex)
971965
#define USE_ITEM(battler, ...) UseItem(__LINE__, battler, (struct ItemContext) { R_APPEND_TRUE(__VA_ARGS__) })
972-
#define WITH_RNG(tag, value) rng: ((struct TurnRNG) { tag, value })
966+
#define WITH_RNG(tag, value) rng: ((struct RiggedRNG) { tag, value })
973967

974968
struct MoveContext
975969
{
@@ -994,7 +988,7 @@ struct MoveContext
994988
u16 explicitNotExpected:1;
995989
struct BattlePokemon *target;
996990
bool8 explicitTarget;
997-
struct TurnRNG rng;
991+
struct RiggedRNG rng;
998992
bool8 explicitRNG;
999993
};
1000994

include/test/test.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define GUARD_TEST_H
33

44
#include "test_runner.h"
5+
#include "random.h"
56

67
#define MAX_PROCESSES 32 // See also tools/mgba-rom-test-hydra/main.c
78

@@ -89,6 +90,14 @@ extern struct FunctionTestRunnerState *gFunctionTestRunnerState;
8990
extern struct TestRunnerState gTestRunnerState;
9091
extern struct PersistentTestRunnerState gPersistentTestRunnerState;
9192

93+
struct RiggedRNG
94+
{
95+
u16 tag;
96+
u16 value;
97+
};
98+
99+
extern EWRAM_DATA struct RiggedRNG gRiggedRngList[8];
100+
92101
void CB2_TestRunner(void);
93102

94103
void Test_ExpectedResult(enum TestResult);
@@ -97,6 +106,8 @@ void Test_ExpectCrash(bool32);
97106
void Test_ExitWithResult(enum TestResult, u32 stopLine, const char *fmt, ...);
98107
u32 SourceLine(u32 sourceLineOffset);
99108
u32 SourceLineOffset(u32 sourceLine);
109+
void SetupRiggedRng(u32 sourceLine, enum RandomTag randomTag, u32 value);
110+
void ClearRiggedRng();
100111

101112
s32 Test_MgbaPrintf(const char *fmt, ...);
102113

@@ -245,6 +256,8 @@ static inline struct Benchmark BenchmarkStop(void)
245256

246257
#define PARAMETRIZE_LABEL(f, label) if (gFunctionTestRunnerState->parameters++ == gFunctionTestRunnerState->runParameter && (Test_MgbaPrintf(":N%s: " f " (%d/%d)", gTestRunnerState.test->name, label, gFunctionTestRunnerState->runParameter + 1, gFunctionTestRunnerState->parameters), 1))
247258

259+
#define SET_RNG(tag, value) SetupRiggedRng(__LINE__, tag, value)
260+
248261
#define TO_DO \
249262
do { \
250263
Test_ExpectedResult(TEST_RESULT_TODO); \

src/battle_main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5733,8 +5733,9 @@ static void ReturnFromBattleToOverworld(void)
57335733
{
57345734
if (!(gBattleTypeFlags & BATTLE_TYPE_LINK))
57355735
{
5736-
RandomlyGivePartyPokerus(gPlayerParty);
5737-
PartySpreadPokerus(gPlayerParty);
5736+
CalculatePlayerPartyCount();
5737+
RandomlyGivePartyPokerus();
5738+
PartySpreadPokerus();
57385739
}
57395740

57405741
if (gBattleTypeFlags & BATTLE_TYPE_LINK && gReceivedRemoteLinkPlayers)

src/field_specials.c

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

14911491
bool8 IsPokerusInParty(void)
14921492
{
1493-
return CheckPartyPokerus(gPlayerParty);
1493+
return CheckPartyPokerus();
14941494
}
14951495

14961496
// Task data for Task_ShakeCamera

src/party_menu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ u8 GetMonAilment(struct Pokemon *mon)
21352135
ailment = GetAilmentFromStatus(GetMonData(mon, MON_DATA_STATUS));
21362136
if (ailment != AILMENT_NONE)
21372137
return ailment;
2138-
if (CheckMonPokerus(mon) && (P_POKERUS_VISIBLE_ON_EGG || !GetMonData(mon, MON_DATA_IS_EGG)))
2138+
if (CheckMonPokerus(mon) && (POKERUS_VISIBLE_ON_EGG || !GetMonData(mon, MON_DATA_IS_EGG)))
21392139
return AILMENT_PKRS;
21402140
return AILMENT_NONE;
21412141
}

0 commit comments

Comments
 (0)