Skip to content

Commit

Permalink
Merge pull request #4 from SBird1337/sbird/patch-difficulty
Browse files Browse the repository at this point in the history
fix: type confusion of NativeFunc pointers
  • Loading branch information
pkmnsnfrn authored Oct 24, 2024
2 parents 91f27d5 + 15eea86 commit 032d7d6
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
5 changes: 2 additions & 3 deletions asm/macros/event.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2348,11 +2348,10 @@
.endm

.macro getdifficulty var:req
callnative ScrCmd_getdifficulty
.2byte \var
callnative Script_GetDifficulty
.endm

.macro setdifficulty difficulty:req
callnative ScrCmd_setdifficulty
callnative Script_SetDifficulty
.byte \difficulty
.endm
10 changes: 7 additions & 3 deletions include/difficulty.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
#define GUARD_DIFFICULTY_H

#include "constants/difficulty.h"
#include "script.h"

u32 GetCurrentDifficultyLevel(void);
void SetCurrentDifficultyLevel(u32);

u32 GetBattlePartnerDifficultyLevel(u16);
u32 GetTrainerDifficultyLevel(u16);
void Script_IncreaseDifficulty(void);
void Script_DecreaseDifficulty(void);
void Script_SetDifficulty(u32);
void Script_IncreaseDifficulty(struct ScriptContext *);
void Script_DecreaseDifficulty(struct ScriptContext *);
void Script_GetDifficulty(struct ScriptContext *);
void Script_SetDifficulty(struct ScriptContext *);

#endif // GUARD_DIFFICULTY_H
36 changes: 18 additions & 18 deletions src/data/battle_partners.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,62 +41,62 @@
.party = (const struct TrainerMon[])
{
{
#line 16
#line 15
.species = SPECIES_METANG,
.gender = TRAINER_MON_RANDOM_GENDER,
#line 20
.ev = TRAINER_PARTY_EVS(0, 252, 252, 0, 6, 0),
#line 19
.iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31),
.ev = TRAINER_PARTY_EVS(0, 252, 252, 0, 6, 0),
#line 18
.lvl = 42,
.iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31),
#line 17
.lvl = 42,
#line 16
.nature = NATURE_BRAVE,
.dynamaxLevel = MAX_DYNAMAX_LEVEL,
.moves = {
#line 21
#line 20
MOVE_LIGHT_SCREEN,
MOVE_PSYCHIC,
MOVE_REFLECT,
MOVE_METAL_CLAW,
},
},
{
#line 26
#line 25
.species = SPECIES_SKARMORY,
.gender = TRAINER_MON_RANDOM_GENDER,
#line 30
.ev = TRAINER_PARTY_EVS(252, 0, 0, 0, 6, 252),
#line 29
.iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31),
.ev = TRAINER_PARTY_EVS(252, 0, 0, 0, 6, 252),
#line 28
.lvl = 43,
.iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31),
#line 27
.lvl = 43,
#line 26
.nature = NATURE_IMPISH,
.dynamaxLevel = MAX_DYNAMAX_LEVEL,
.moves = {
#line 31
#line 30
MOVE_TOXIC,
MOVE_AERIAL_ACE,
MOVE_PROTECT,
MOVE_STEEL_WING,
},
},
{
#line 36
#line 35
.species = SPECIES_AGGRON,
.gender = TRAINER_MON_RANDOM_GENDER,
#line 40
.ev = TRAINER_PARTY_EVS(0, 252, 0, 0, 252, 6),
#line 39
.iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31),
.ev = TRAINER_PARTY_EVS(0, 252, 0, 0, 252, 6),
#line 38
.lvl = 44,
.iv = TRAINER_PARTY_IVS(31, 31, 31, 31, 31, 31),
#line 37
.lvl = 44,
#line 36
.nature = NATURE_ADAMANT,
.dynamaxLevel = MAX_DYNAMAX_LEVEL,
.moves = {
#line 41
#line 40
MOVE_THUNDER,
MOVE_PROTECT,
MOVE_SOLAR_BEAM,
Expand Down
33 changes: 23 additions & 10 deletions src/difficulty.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "global.h"
#include "data.h"
#include "event_data.h"
#include "script.h"
#include "constants/battle.h"

u32 GetCurrentDifficultyLevel(void)
Expand All @@ -11,6 +12,17 @@ u32 GetCurrentDifficultyLevel(void)
return VarGet(B_VAR_DIFFICULTY);
}

void SetCurrentDifficultyLevel(u32 desiredDifficulty)
{
if (!B_VAR_DIFFICULTY)
return;

if (desiredDifficulty > DIFFICULTY_MAX)
desiredDifficulty = DIFFICULTY_MAX;

VarSet(B_VAR_DIFFICULTY, desiredDifficulty);
}

u32 GetBattlePartnerDifficultyLevel(u16 partnerId)
{
u32 difficulty = GetCurrentDifficultyLevel();
Expand Down Expand Up @@ -40,7 +52,7 @@ u32 GetTrainerDifficultyLevel(u16 trainerId)
return difficulty;
}

void Script_IncreaseDifficulty(void)
void Script_IncreaseDifficulty(struct ScriptContext *ctx)
{
u32 currentDifficulty;

Expand All @@ -52,10 +64,10 @@ void Script_IncreaseDifficulty(void)
if (currentDifficulty++ > DIFFICULTY_MAX)
return;

Script_SetDifficulty(currentDifficulty);
SetCurrentDifficultyLevel(currentDifficulty);
}

void Script_DecreaseDifficulty(void)
void Script_DecreaseDifficulty(struct ScriptContext *ctx)
{
u32 currentDifficulty;

Expand All @@ -67,16 +79,17 @@ void Script_DecreaseDifficulty(void)
if (!currentDifficulty)
return;

Script_SetDifficulty(--currentDifficulty);
SetCurrentDifficultyLevel(--currentDifficulty);
}

void Script_SetDifficulty(u32 desiredDifficulty)
void Script_GetDifficulty(struct ScriptContext *ctx)
{
if (!B_VAR_DIFFICULTY)
return;
gSpecialVar_Result = GetCurrentDifficultyLevel();
}

if (desiredDifficulty > DIFFICULTY_MAX)
desiredDifficulty = DIFFICULTY_MAX;
void Script_SetDifficulty(struct ScriptContext *ctx)
{
u32 desiredDifficulty = ScriptReadByte(ctx);

VarSet(B_VAR_DIFFICULTY,desiredDifficulty);
SetCurrentDifficultyLevel(desiredDifficulty);
}
2 changes: 1 addition & 1 deletion src/new_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void NewGameInitData(void)
WipeTrainerNameRecords();
ResetTrainerHillResults();
ResetContestLinkResults();
Script_SetDifficulty(DIFFICULTY_NORMAL);
SetCurrentDifficultyLevel(DIFFICULTY_NORMAL);
ResetItemFlags();
}

Expand Down
16 changes: 0 additions & 16 deletions src/scrcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2478,19 +2478,3 @@ void ScriptSetDoubleBattleFlag(struct ScriptContext *ctx)
{
sIsScriptedWildDouble = TRUE;
}

bool8 ScrCmd_getdifficulty(struct ScriptContext *ctx)
{
u16 *var = GetVarPointer(ScriptReadHalfword(ctx));

*var = GetCurrentDifficultyLevel();
return FALSE;
}

bool8 ScrCmd_setdifficulty(struct ScriptContext *ctx)
{
u8 desiredDifficulty = ScriptReadByte(ctx);

Script_SetDifficulty(desiredDifficulty);
return FALSE;
}

0 comments on commit 032d7d6

Please sign in to comment.