Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds B_VAR_DIFFICULTY and related functions READ DESC #5337

Open
wants to merge 47 commits into
base: upcoming
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
74f33af
Added difficulty constants
pkmnsnfrn Sep 1, 2024
c77b30c
first compile version
pkmnsnfrn Sep 1, 2024
ec690da
Added GetTrainerDifficultyLevel
pkmnsnfrn Sep 1, 2024
5fd9196
GetTrainerEncounterMusicId fixed
pkmnsnfrn Sep 1, 2024
4dacc2e
Fixed gBattlePartners
pkmnsnfrn Sep 1, 2024
37a485b
Improve trainerproc
pkmnsnfrn Sep 1, 2024
07a15c2
Convert partners to enum
pkmnsnfrn Sep 1, 2024
25c1068
removed preproc
pkmnsnfrn Sep 1, 2024
4319167
Got trainerproc with difficulty working
pkmnsnfrn Sep 1, 2024
5bbb109
Modified trainerproc to add new structs
pkmnsnfrn Sep 1, 2024
ea6f460
Added difficulty to trainer slides
pkmnsnfrn Sep 2, 2024
e28b1f3
Added seperate difficulty files
pkmnsnfrn Sep 2, 2024
f23027e
Rewrote logic so easy could be before normal
pkmnsnfrn Sep 2, 2024
f39a8cd
Added script macros
pkmnsnfrn Sep 2, 2024
a835816
Added DIFFICULTY_NORMAL and new game functions
pkmnsnfrn Sep 2, 2024
6a0dfb9
converted to strings
pkmnsnfrn Sep 2, 2024
d9000bd
Added notes for Mgriffin
pkmnsnfrn Sep 2, 2024
41c806a
first prototype of string version
pkmnsnfrn Sep 6, 2024
b8b98c5
Dynamic version working
pkmnsnfrn Sep 6, 2024
be16d64
Updated party files
pkmnsnfrn Sep 6, 2024
33cfc96
Updated party files
pkmnsnfrn Sep 6, 2024
749f69e
Added constants for difficulty
pkmnsnfrn Sep 7, 2024
b760f2a
Cleaned up trainerproc
pkmnsnfrn Sep 7, 2024
278b8c7
Merged in upcoming
pkmnsnfrn Sep 7, 2024
3562d54
Changed functioality so that difficulty structs are not built for tes…
pkmnsnfrn Sep 7, 2024
151d8e1
Extended comment to prevent compilation issues
pkmnsnfrn Sep 7, 2024
b4dffb6
fixed tabs
pkmnsnfrn Sep 8, 2024
bf4a183
fixed pal
pkmnsnfrn Sep 8, 2024
026f078
Merge branch 'upcoming' of https://github.com/rh-hideout/pokeemerald-…
pkmnsnfrn Sep 8, 2024
b178d44
Removed opcodes
pkmnsnfrn Sep 8, 2024
caec1c2
fixed battle partners space
pkmnsnfrn Sep 8, 2024
88b0894
fixed tabs again
pkmnsnfrn Sep 8, 2024
eee12c4
Merge branch 'upcoming' into difficultySystem
pkmnsnfrn Sep 12, 2024
47fefaa
Merge branch 'upcoming' into difficultySystem
pkmnsnfrn Sep 25, 2024
8d071e4
Added explicit declaration of difficulty to test trainers per https:/…
pkmnsnfrn Oct 11, 2024
91f27d5
Merge branch 'upcoming' into difficultySystem
pkmnsnfrn Oct 11, 2024
2c28653
fix: type confusion of NativeFunc pointers
Oct 24, 2024
a8032f9
Update src/difficulty.c
SBird1337 Oct 24, 2024
15eea86
fixup: naming convention
Oct 24, 2024
032d7d6
Merge pull request #4 from SBird1337/sbird/patch-difficulty
pkmnsnfrn Oct 24, 2024
2d495cf
Collapsed gTrainers to print difficulty and trainer id together per h…
pkmnsnfrn Oct 27, 2024
e78c983
Replaced u32 difficult with enum DifficultyLevel difficulty per https…
pkmnsnfrn Oct 27, 2024
50d8c7a
Merged in upcoming
pkmnsnfrn Oct 27, 2024
d896070
Changed all u32 to enum DifficultyLevel per https://github.com/rh-hid…
pkmnsnfrn Oct 28, 2024
acfe8d3
Stopped line number from printing when difficulty isn't specified per…
pkmnsnfrn Dec 19, 2024
5a829ca
Merge branch 'upcoming' into difficultySystem
pkmnsnfrn Dec 19, 2024
b6cc3e1
Added patch to fix failing tests
pkmnsnfrn Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions asm/macros/event.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2430,3 +2430,19 @@
.2byte \dest
.endm

.macro increasedifficulty
callnative Script_IncreaseDifficulty
.endm

.macro decreasedifficulty
callnative Script_DecreaseDifficulty
.endm

.macro getdifficulty var:req
callnative Script_GetDifficulty
.endm

.macro setdifficulty difficulty:req
callnative Script_SetDifficulty
.byte \difficulty
.endm
1 change: 1 addition & 0 deletions data/event_scripts.s
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "constants/contest.h"
#include "constants/daycare.h"
#include "constants/decorations.h"
#include "constants/difficulty.h"
#include "constants/easy_chat.h"
#include "constants/event_objects.h"
#include "constants/event_object_movement.h"
Expand Down
1 change: 1 addition & 0 deletions include/config/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
#define B_VAR_STARTING_STATUS 0 // If this var has a value, assigning a STATUS_FIELD_xx_TERRAIN to it before battle causes the battle to start with that terrain active.
#define B_VAR_STARTING_STATUS_TIMER 0 // If this var has a value greater or equal than 1 field terrains will last that number of turns, otherwise they will last until they're overwritten.
#define B_VAR_WILD_AI_FLAGS 0 // If not 0, you can use this var to add to default wild AI flags. NOT usable with flags above (1 << 15)
#define B_VAR_DIFFICULTY 0 // If not 0, you can use this var to control which difficulty version of a Trainer is loaded.

// Sky Battles
#define B_FLAG_SKY_BATTLE 0 // If this flag has a value, the player will be able to engage in scripted Sky Battles.
Expand Down
5 changes: 3 additions & 2 deletions include/constants/battle_partner.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#ifndef GUARD_CONSTANTS_BATTLE_PARTNERS_H
#define GUARD_CONSTANTS_BATTLE_PARTNERS_H

#define PARTNER_NONE 0
#define PARTNER_STEVEN 1
#define PARTNER_NONE 0
#define PARTNER_STEVEN 1
#define PARTNER_COUNT 2

#endif // GUARD_CONSTANTS_BATTLE_PARTNERS_H
15 changes: 15 additions & 0 deletions include/constants/difficulty.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef GUARD_DIFFICULTY_CONSTANTS_H
#define GUARD_DIFFICULTY_CONSTANTS_H

enum DifficultyLevel
{
DIFFICULTY_EASY,
DIFFICULTY_NORMAL, //If you rename this, the word "Normal" in fprint_trainers must be replaced with the new difficulty name.
DIFFICULTY_HARD,
DIFFICULTY_COUNT,
};

#define DIFFICULTY_MIN 0
#define DIFFICULTY_MAX (DIFFICULTY_COUNT - 1)

#endif // GUARD_DIFFICULTY_CONSTANTS_H
66 changes: 50 additions & 16 deletions include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "constants/moves.h"
#include "constants/trainers.h"
#include "constants/battle.h"
#include "difficulty.h"

#define MAX_TRAINER_ITEMS 4

Expand Down Expand Up @@ -164,8 +166,8 @@ extern const union AnimCmd *const sAnims_Trainer[];
extern const struct TrainerSprite gTrainerSprites[];
extern const struct TrainerBacksprite gTrainerBacksprites[];

extern const struct Trainer gTrainers[];
extern const struct Trainer gBattlePartners[];
extern const struct Trainer gTrainers[DIFFICULTY_COUNT][TRAINERS_COUNT];
extern const struct Trainer gBattlePartners[DIFFICULTY_COUNT][PARTNER_COUNT];

extern const struct TrainerClass gTrainerClasses[TRAINER_CLASS_COUNT];

Expand All @@ -191,71 +193,103 @@ static inline u16 SanitizeTrainerId(u16 trainerId)

static inline const struct Trainer *GetTrainerStructFromId(u16 trainerId)
{
return &gTrainers[SanitizeTrainerId(trainerId)];
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);
enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

return &gTrainers[difficulty][sanitizedTrainerId];
}

static inline const u8 GetTrainerClassFromId(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].trainerClass;
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);
enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

return gTrainers[difficulty][sanitizedTrainerId].trainerClass;
}

static inline const u8 *GetTrainerClassNameFromId(u16 trainerId)
{
enum DifficultyLevel difficulty = GetBattlePartnerDifficultyLevel(trainerId);

if (trainerId > TRAINER_PARTNER(PARTNER_NONE))
return gTrainerClasses[gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerClass].name;
return gTrainerClasses[gBattlePartners[difficulty][trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerClass].name;
return gTrainerClasses[GetTrainerClassFromId(trainerId)].name;
}

static inline const u8 *GetTrainerNameFromId(u16 trainerId)
{
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);

enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

u32 partnerDifficulty = GetBattlePartnerDifficultyLevel(trainerId);

if (trainerId > TRAINER_PARTNER(PARTNER_NONE))
return gBattlePartners[trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName;
return gTrainers[SanitizeTrainerId(trainerId)].trainerName;
return gBattlePartners[partnerDifficulty][trainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerName;
return gTrainers[difficulty][sanitizedTrainerId].trainerName;
}

static inline const u8 GetTrainerPicFromId(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].trainerPic;
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);
enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

return gTrainers[difficulty][sanitizedTrainerId].trainerPic;
}

static inline const u8 GetTrainerStartingStatusFromId(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].startingStatus;
return gTrainers[GetCurrentDifficultyLevel()][SanitizeTrainerId(trainerId)].startingStatus;
}

static inline const bool32 IsTrainerDoubleBattle(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].doubleBattle;
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);
enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

return gTrainers[difficulty][sanitizedTrainerId].doubleBattle;
}

static inline const u8 GetTrainerPartySizeFromId(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].partySize;
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);
enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

return gTrainers[difficulty][sanitizedTrainerId].partySize;
}

static inline const bool32 DoesTrainerHaveMugshot(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].mugshotEnabled;
return gTrainers[GetCurrentDifficultyLevel()][SanitizeTrainerId(trainerId)].mugshotEnabled;
}

static inline const u8 GetTrainerMugshotColorFromId(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].mugshotColor;
return gTrainers[GetCurrentDifficultyLevel()][SanitizeTrainerId(trainerId)].mugshotColor;
}

static inline const u16 *GetTrainerItemsFromId(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].items;
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);
enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

return gTrainers[difficulty][sanitizedTrainerId].items;
}

static inline const struct TrainerMon *GetTrainerPartyFromId(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].party;
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);
enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

return gTrainers[difficulty][sanitizedTrainerId].party;
}

static inline const bool32 GetTrainerAIFlagsFromId(u16 trainerId)
{
return gTrainers[SanitizeTrainerId(trainerId)].aiFlags;
u32 sanitizedTrainerId = SanitizeTrainerId(trainerId);
enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId);

return gTrainers[difficulty][sanitizedTrainerId].aiFlags;
}

#endif // GUARD_DATA_H
17 changes: 17 additions & 0 deletions include/difficulty.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef GUARD_DIFFICULTY_H
#define GUARD_DIFFICULTY_H

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

u32 GetCurrentDifficultyLevel(void);
pkmnsnfrn marked this conversation as resolved.
Show resolved Hide resolved
void SetCurrentDifficultyLevel(u32);

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

#endif // GUARD_DIFFICULTY_H
7 changes: 5 additions & 2 deletions src/battle_controller_player_partner.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,11 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler)
s16 xPos, yPos;
u32 trainerPicId;

enum DifficultyLevel difficulty = GetBattlePartnerDifficultyLevel(gPartnerTrainerId);

if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE))
{
trainerPicId = gBattlePartners[gPartnerTrainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerPic;
trainerPicId = gBattlePartners[difficulty][gPartnerTrainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerPic;
xPos = 90;
yPos = (8 - gTrainerBacksprites[trainerPicId].coordinates.size) * 4 + 80;
}
Expand Down Expand Up @@ -433,9 +435,10 @@ static void PlayerPartnerHandleHealthBarUpdate(u32 battler)
static void PlayerPartnerHandleIntroTrainerBallThrow(u32 battler)
{
const u32 *trainerPal;
enum DifficultyLevel difficulty = GetBattlePartnerDifficultyLevel(gPartnerTrainerId);

if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE))
trainerPal = gTrainerBacksprites[gBattlePartners[gPartnerTrainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerPic].palette.data;
trainerPal = gTrainerBacksprites[gBattlePartners[difficulty][gPartnerTrainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerPic].palette.data;
else if (IsAiVsAiBattle())
trainerPal = gTrainerSprites[GetTrainerPicFromId(gPartnerTrainerId)].palette.data;
else
Expand Down
Loading
Loading