forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdifficulty.c
105 lines (75 loc) · 2.38 KB
/
difficulty.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "global.h"
#include "data.h"
#include "event_data.h"
#include "script.h"
#include "constants/battle.h"
enum DifficultyLevel GetCurrentDifficultyLevel(void)
{
if (!B_VAR_DIFFICULTY)
return DIFFICULTY_NORMAL;
return VarGet(B_VAR_DIFFICULTY);
}
void SetCurrentDifficultyLevel(enum DifficultyLevel desiredDifficulty)
{
if (!B_VAR_DIFFICULTY)
return;
if (desiredDifficulty > DIFFICULTY_MAX)
desiredDifficulty = DIFFICULTY_MAX;
VarSet(B_VAR_DIFFICULTY, desiredDifficulty);
}
enum DifficultyLevel GetBattlePartnerDifficultyLevel(u16 partnerId)
{
enum DifficultyLevel difficulty = GetCurrentDifficultyLevel();
if (partnerId > TRAINER_PARTNER(PARTNER_NONE))
partnerId -= TRAINER_PARTNER(PARTNER_NONE);
if (difficulty == DIFFICULTY_NORMAL)
return DIFFICULTY_NORMAL;
if (gBattlePartners[difficulty][partnerId].party == NULL)
return DIFFICULTY_NORMAL;
return difficulty;
}
enum DifficultyLevel GetTrainerDifficultyLevel(u16 trainerId)
{
enum DifficultyLevel difficulty = GetCurrentDifficultyLevel();
if (difficulty == DIFFICULTY_NORMAL)
return DIFFICULTY_NORMAL;
if (gTrainers[difficulty][trainerId].party == NULL)
return DIFFICULTY_NORMAL;
return difficulty;
}
void Script_IncreaseDifficulty(void)
{
enum DifficultyLevel currentDifficulty;
if (!B_VAR_DIFFICULTY)
return;
currentDifficulty = GetCurrentDifficultyLevel();
if (currentDifficulty++ > DIFFICULTY_MAX)
return;
Script_RequestEffects(SCREFF_V1);
Script_RequestWriteVar(B_VAR_DIFFICULTY);
SetCurrentDifficultyLevel(currentDifficulty);
}
void Script_DecreaseDifficulty(void)
{
enum DifficultyLevel currentDifficulty;
if (!B_VAR_DIFFICULTY)
return;
currentDifficulty = GetCurrentDifficultyLevel();
if (!currentDifficulty)
return;
Script_RequestEffects(SCREFF_V1);
Script_RequestWriteVar(B_VAR_DIFFICULTY);
SetCurrentDifficultyLevel(--currentDifficulty);
}
void Script_GetDifficulty(void)
{
Script_RequestEffects(SCREFF_V1);
gSpecialVar_Result = GetCurrentDifficultyLevel();
}
void Script_SetDifficulty(struct ScriptContext *ctx)
{
enum DifficultyLevel desiredDifficulty = ScriptReadByte(ctx);
Script_RequestEffects(SCREFF_V1);
Script_RequestWriteVar(B_VAR_DIFFICULTY);
SetCurrentDifficultyLevel(desiredDifficulty);
}