forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsprays.c
116 lines (91 loc) · 2.72 KB
/
sprays.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
106
107
108
109
110
111
112
113
114
115
116
#include "global.h"
#include "event_data.h"
#include "script_menu.h"
#include "strings.h"
#include "constants/items.h"
#include "item.h"
#include "script_menu.h"
#include "menu.h"
#define SPRAY_COUNT 0
#define SPRAY_GET 1
#define NUM_SPRAY_STRENGTH 3
#define SPRAY_MENU_Y_COORD 8
#define LOCAL_VAR_SPRAY gSpecialVar_0x8004
#define LOCAL_VAR_SPRAY_CONST VAR_0x8004
u32 CountOrGetSprays(u32);
u32 GetNumberSprayStrength(void);
u32 GetSprayId(void);
u32 GetLastUsedSprayType(void);
u32 SetSprayMenuCursorPosition(int, int);
#if I_REPEL_LURE_MENU == TRUE
void DrawSprayMenu(void);
#endif
void HandleSprayMenuChoice(void);
u32 CountOrGetSprays(u32 func)
{
u32 i, currentSpray, sprayCount = 0;
u32 spray = GetLastUsedSprayType();
for (i = 0; i < NUM_SPRAY_STRENGTH; i++)
{
currentSpray = spray + i;
if (!CheckBagHasItem(currentSpray,1))
continue;
if (func == SPRAY_COUNT)
sprayCount++;
else
return (currentSpray);
}
return sprayCount;
}
u32 GetNumberSprayStrength(void)
{
return CountOrGetSprays(SPRAY_COUNT);
}
u32 GetSprayId(void)
{
return CountOrGetSprays(SPRAY_GET);
}
u32 GetLastUsedSprayType(void)
{
if (IS_LAST_USED_LURE(VarGet(VAR_REPEL_STEP_COUNT)))
return ITEM_LURE;
else
return ITEM_REPEL;
}
u32 SetSprayMenuCursorPosition(int currentSpray, int count)
{
if (VarGet(VAR_LAST_REPEL_LURE_USED) == currentSpray)
return count;
return 0;
}
#if I_REPEL_LURE_MENU == TRUE
void DrawSprayMenu(void)
{
struct MenuAction menuItems[NUM_SPRAY_STRENGTH+1] = {NULL};
int sprayIndex, count = 0, menuPos = 0, currentSpray, yCoord = 0;
u32 spray = GetLastUsedSprayType();
for (sprayIndex = 0; sprayIndex < (NUM_SPRAY_STRENGTH); sprayIndex++)
{
currentSpray = spray + sprayIndex;
if (!CheckBagHasItem(currentSpray, 1))
continue;
menuItems[count].text = ItemId_GetName(currentSpray);
VarSet(LOCAL_VAR_SPRAY_CONST + count, currentSpray);
if (VAR_LAST_REPEL_LURE_USED != 0)
menuPos = SetSprayMenuCursorPosition(currentSpray, count);
yCoord = SPRAY_MENU_Y_COORD - (2 * count);
count++;
}
gSpecialVar_0x8003 = count;
menuItems[count].text = gText_Cancel2;
DrawMultichoiceMenuInternal(18, yCoord, 0, FALSE, menuPos, menuItems, count+1);
}
#endif
void HandleSprayMenuChoice(void)
{
u32 lureMask = (GetLastUsedSprayType() == ITEM_LURE) ? REPEL_LURE_MASK : 0;
LOCAL_VAR_SPRAY = VarGet(LOCAL_VAR_SPRAY_CONST + gSpecialVar_Result);
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(LOCAL_VAR_SPRAY) | lureMask);
if (VAR_LAST_REPEL_LURE_USED != 0)
VarSet(VAR_LAST_REPEL_LURE_USED, LOCAL_VAR_SPRAY);
}