pokeemmo/src/sprays.c
psf 8d6cb9692a
Improved Repel / Lure Menu (#3594)
* First draft of repel lure

* Updated all lure and repel scripts

* Optimized inc file

* Updated y coord

* optimized sprays.c

* Removed spray.inc

* Updated cosnt use

* Removed dead repel and lure code

* Updated debug for testing

* testing new inc file

* turn on debug and options

* playground generated inc file without ifs

* pory generated inc with ifdef complete

* Updated spray.c with new inc

* reverted item config

* Reverted event scripts

* Reverted event scripts

* Revert config

* Added testing scripts for debug

* Added back specials

* reverted debug scripts

* Updated use of constants

* Addressed tabs > spaces feedback
https://github.com/rh-hideout/pokeemerald-expansion/pull/3594\#discussion_r1402917676

* Updated constant names to avoid confusion
Made inc file changes
https://github.com/rh-hideout/pokeemerald-expansion/pull/3594\#pullrequestreview-1746418044

* Updated constant name of NUM_SPRAY_TYPES to NUM_SPRAY_STRENGTH to be more accurate
2023-11-23 21:31:33 +01:00

117 lines
2.7 KiB
C

#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);
}