diff --git a/data/scripts/repel.inc b/data/scripts/repel.inc index ab7924bd21..44cfcb5d23 100644 --- a/data/scripts/repel.inc +++ b/data/scripts/repel.inc @@ -1,117 +1,152 @@ -EventScript_RepelWoreOff:: +.set LOCAL_VAR_SPRAY, VAR_0x8004 +.set LOCAL_VAR_NUM_SPRAY_STRENGTH, VAR_0x8005 +.set LOCAL_VAR_SPRAY_TYPE, VAR_0x8009 +.set LOCAL_VAR_NEW_SPRAY, VAR_0x8007 + +EventScript_BufferSprayName:: +.if VAR_LAST_REPEL_LURE_USED != 0 + bufferitemname STR_VAR_1, VAR_LAST_REPEL_LURE_USED + return +.endif + specialvar LOCAL_VAR_SPRAY_TYPE, GetLastUsedSprayType + compare LOCAL_VAR_SPRAY_TYPE, ITEM_REPEL + goto_if_eq EventScript_BufferSprayName_2 + bufferitemname STR_VAR_1, ITEM_LURE +EventScript_BufferSprayName_1: + return + +EventScript_BufferSprayName_2: + bufferitemname STR_VAR_1, ITEM_REPEL + goto EventScript_BufferSprayName_1 + + +EventScript_SprayWoreOff:: + lock + call EventScript_BufferSprayName + specialvar LOCAL_VAR_NUM_SPRAY_STRENGTH, GetNumberSprayStrength + switch LOCAL_VAR_NUM_SPRAY_STRENGTH + case 0, EventScript_SprayWoreOffMessage + case 1, EventScript_UseSingleSpray + goto EventScript_HandleMultipleSprays + return + +EventScript_HandleMultipleSprays:: .if I_REPEL_LURE_MENU == TRUE - checkitem ITEM_REPEL, 1 - goto_if_eq VAR_RESULT, TRUE, EventScript_RepelUseAnother - checkitem ITEM_SUPER_REPEL, 1 - goto_if_eq VAR_RESULT, TRUE, EventScript_RepelUseAnother - checkitem ITEM_MAX_REPEL, 1 - goto_if_eq VAR_RESULT, TRUE, EventScript_RepelUseAnother + goto EventScript_ChooseWhichSpray +.else + goto EventScript_UseSingleSpray +.endif + return + + +EventScript_SprayWoreOffMessage:: + msgbox Text_SprayWoreOff, MSGBOX_SIGN + releaseall + end + + +EventScript_UseSingleSpray:: +.if VAR_LAST_REPEL_LURE_USED == 0 + call EventScript_UseDifferentSpray .else checkitem VAR_LAST_REPEL_LURE_USED, 1 - goto_if_eq VAR_RESULT, TRUE, EventScript_RepelUseAnother + compare VAR_RESULT, TRUE + goto_if_eq EventScript_UseSingleSpray_2 + call EventScript_UseDifferentSpray .endif - lock - msgbox Text_RepelWoreOff, MSGBOX_SIGN - release +EventScript_UseSingleSpray_1: + closemessage + releaseall end -EventScript_RepelUseAnother: - lock - msgbox Text_UseAnotherRepel, MSGBOX_YESNO +.if VAR_LAST_REPEL_LURE_USED != 0 +EventScript_UseSingleSpray_2: + call EventScript_UseLastUsedSpray + goto EventScript_UseSingleSpray_1 +.endif + + +EventScript_SetSingleSprayAndUse:: + setvar VAR_RESULT, 0 + call EventScript_UseSpray + return + + +EventScript_UseDifferentSpray:: + specialvar LOCAL_VAR_NEW_SPRAY, GetSprayId + bufferitemname STR_VAR_2, LOCAL_VAR_NEW_SPRAY + msgbox Text_SprayWoreOffAskUseX, MSGBOX_YESNO + compare VAR_RESULT, YES + goto_if_eq EventScript_UseDifferentSpray_2 +EventScript_UseDifferentSpray_1: + return + +EventScript_UseDifferentSpray_2: + copyvar LOCAL_VAR_SPRAY, LOCAL_VAR_NEW_SPRAY + call EventScript_SetSingleSprayAndUse + goto EventScript_UseDifferentSpray_1 + + +.if VAR_LAST_REPEL_LURE_USED != 0 +EventScript_UseLastUsedSpray:: + msgbox Text_SprayWoreOffAskUseAnother, MSGBOX_YESNO + compare VAR_RESULT, YES + goto_if_eq EventScript_UseLastUsedSpray_2 +EventScript_UseLastUsedSpray_1: + return + +EventScript_UseLastUsedSpray_2: + copyvar LOCAL_VAR_SPRAY, VAR_LAST_REPEL_LURE_USED + call EventScript_SetSingleSprayAndUse + goto EventScript_UseLastUsedSpray_1 +.endif + + .if I_REPEL_LURE_MENU == TRUE - goto_if_eq VAR_RESULT, NO, EventScript_RepelWoreOff_End - callnative TryDrawRepelMenu - goto_if_eq VAR_RESULT, FALSE, EventScript_RepelWoreOff_Chose +EventScript_ChooseWhichSpray:: + message Text_SprayWoreOffAskUseAnother + waitmessage + callnative DrawSprayMenu waitstate - goto_if_eq VAR_RESULT, 127, EventScript_RepelWoreOff_End -EventScript_RepelWoreOff_Chose: - callnative HandleRepelMenuChoice - bufferitemname 1, VAR_0x8004 - removeitem VAR_0x8004, 1 - playse SE_REPEL - msgbox Text_UsedNewRepelLure, MSGBOX_SIGN -.else - goto_if_eq VAR_RESULT, YES, EventScript_UsedRepel -.endif -EventScript_RepelWoreOff_End: - release + compare VAR_RESULT, MULTI_B_PRESSED + goto_if_ne EventScript_ChooseWhichSpray_3 +EventScript_ChooseWhichSpray_1: + closemessage + releaseall end -EventScript_UsedRepel: - bufferitemname 1, VAR_LAST_REPEL_LURE_USED +EventScript_ChooseWhichSpray_2: + call EventScript_UseSpray + goto EventScript_ChooseWhichSpray_1 + +EventScript_ChooseWhichSpray_3: + compare VAR_RESULT, VAR_0x8003 + goto_if_ne EventScript_ChooseWhichSpray_2 + goto EventScript_ChooseWhichSpray_1 +.endif + + +EventScript_UseSpray:: playse SE_REPEL - lock - msgbox Text_UsedNewRepelLure, MSGBOX_SIGN - removeitem VAR_LAST_REPEL_LURE_USED, 1 waitse - callnative HandleUseExpiredRepel - release - end + callnative HandleSprayMenuChoice + removeitem LOCAL_VAR_SPRAY, 1 + bufferitemname STR_VAR_2, LOCAL_VAR_SPRAY + msgbox Text_SprayWoreOffUseX, MSGBOX_SIGN + return -EventScript_LureWoreOff:: -.if I_REPEL_LURE_MENU == TRUE - checkitem ITEM_LURE, 1 - goto_if_eq VAR_RESULT, TRUE, EventScript_LureUseAnother - checkitem ITEM_SUPER_LURE, 1 - goto_if_eq VAR_RESULT, TRUE, EventScript_LureUseAnother - checkitem ITEM_MAX_LURE, 1 - goto_if_eq VAR_RESULT, TRUE, EventScript_LureUseAnother -.else - checkitem VAR_LAST_REPEL_LURE_USED, 1 - goto_if_eq VAR_RESULT, TRUE, EventScript_LureUseAnother -.endif - lock - msgbox Text_LureWoreOff, MSGBOX_SIGN - release - end -EventScript_LureUseAnother: - lock - msgbox Text_UseAnotherLure, MSGBOX_YESNO -.if I_REPEL_LURE_MENU == TRUE - goto_if_eq VAR_RESULT, NO, EventScript_LureWoreOff_End - callnative TryDrawLureMenu - goto_if_eq VAR_RESULT, FALSE, EventScript_LureWoreOff_Chose - waitstate - goto_if_eq VAR_RESULT, 127, EventScript_LureWoreOff_End -EventScript_LureWoreOff_Chose: - callnative HandleLureMenuChoice - bufferitemname 1, VAR_0x8004 - removeitem VAR_0x8004, 1 - playse SE_REPEL - msgbox Text_UsedNewRepelLure, MSGBOX_SIGN -.else - goto_if_eq VAR_RESULT, YES, EventScript_UsedLure -.endif -EventScript_LureWoreOff_End: - release - end +Text_SprayWoreOff:: + .string "{STR_VAR_1}'s effect wore off…$" -EventScript_UsedLure: - bufferitemname 1, VAR_LAST_REPEL_LURE_USED - playse SE_REPEL - lock - msgbox Text_UsedNewRepelLure, MSGBOX_SIGN - removeitem VAR_LAST_REPEL_LURE_USED, 1 - waitse - callnative HandleUseExpiredLure - release - end - -Text_RepelWoreOff: - .string "REPEL's effect wore off…$" - -Text_UseAnotherRepel:: - .string "REPEL's effect wore off!\n" +Text_SprayWoreOffAskUseAnother:: + .string "{STR_VAR_1}'s effect wore off!\n" .string "Use another?$" -Text_LureWoreOff: - .string "Lure's effect wore off…$" +Text_SprayWoreOffAskUseX:: + .string "{STR_VAR_1}'s effect wore off…\n" + .string "Use a {STR_VAR_2}?$" -Text_UseAnotherLure:: - .string "Lure's effect wore off!\n" - .string "Use another?$" - -Text_UsedNewRepelLure:: +Text_SprayWoreOffUseX:: .string "{PLAYER} used the\n" .string "{STR_VAR_2}.$" diff --git a/data/specials.inc b/data/specials.inc index ded2e3f4fe..91ba7cac13 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -536,3 +536,6 @@ gSpecials:: def_special TrySetBattleTowerLinkType def_special SetTotemBoost def_special TrySpecialOverworldEvo + def_special GetNumberSprayStrength + def_special GetSprayId + def_special GetLastUsedSprayType diff --git a/include/script_menu.h b/include/script_menu.h index 734c717cff..41b45000eb 100644 --- a/include/script_menu.h +++ b/include/script_menu.h @@ -2,11 +2,13 @@ #define GUARD_SCRIPT_MENU_H #include "constants/script_menu.h" +#include "menu.h" extern const u8 *const gStdStrings[]; bool8 ScriptMenu_Multichoice(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress); bool8 ScriptMenu_MultichoiceWithDefault(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 defaultChoice); +void DrawMultichoiceMenuInternal(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos, const struct MenuAction *actions, int count); bool8 ScriptMenu_YesNo(u8 left, u8 top); bool8 ScriptMenu_MultichoiceGrid(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 columnCount); bool8 ScriptMenu_ShowPokemonPic(u16 species, u8 x, u8 y); diff --git a/src/script_menu.c b/src/script_menu.c index 01b7f6a588..6444e382e9 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -89,7 +89,7 @@ static u16 UNUSED GetLengthWithExpandedPlayerName(const u8 *str) return length; } -static void DrawMultichoiceMenuInternal(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos, const struct MenuAction *actions, int count) +void DrawMultichoiceMenuInternal(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos, const struct MenuAction *actions, int count) { int i; u8 windowId; @@ -116,79 +116,6 @@ static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, bool8 ignoreB DrawMultichoiceMenuInternal(left, top, multichoiceId, ignoreBPress, cursorPos, sMultichoiceLists[multichoiceId].list, sMultichoiceLists[multichoiceId].count); } -#if I_REPEL_LURE_MENU == TRUE -void TryDrawRepelMenu(struct ScriptContext *ctx) -{ - static const u16 repelItems[] = {ITEM_REPEL, ITEM_SUPER_REPEL, ITEM_MAX_REPEL}; - struct MenuAction menuItems[ARRAY_COUNT(repelItems) + 1] = {NULL}; - int i, count = 0, menuPos = 0; - - for (i = 0; i < ARRAY_COUNT(repelItems); i++) - { - if (CheckBagHasItem(repelItems[i], 1)) - { - VarSet(VAR_0x8004 + count, repelItems[i]); - #if VAR_LAST_REPEL_LURE_USED != 0 - if (VarGet(VAR_LAST_REPEL_LURE_USED) == repelItems[i]) - menuPos = count; - #endif - menuItems[count].text = ItemId_GetName(repelItems[i]); - count++; - } - } - - if (count > 1) - DrawMultichoiceMenuInternal(0, 0, 0, FALSE, menuPos, menuItems, count); - - gSpecialVar_Result = (count > 1); -} - -void HandleRepelMenuChoice(struct ScriptContext *ctx) -{ - gSpecialVar_0x8004 = VarGet(VAR_0x8004 + gSpecialVar_Result); // Get item Id; - VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_0x8004)); -#if VAR_LAST_REPEL_LURE_USED != 0 - VarSet(VAR_LAST_REPEL_LURE_USED, gSpecialVar_0x8004); -#endif -} - -void TryDrawLureMenu(struct ScriptContext *ctx) -{ - static const u16 lureItems[] = {ITEM_LURE, ITEM_SUPER_LURE, ITEM_MAX_LURE}; - struct MenuAction menuItems[ARRAY_COUNT(lureItems) + 1] = {NULL}; - int i, count = 0, menuPos = 0; - - - for (i = 0; i < ARRAY_COUNT(lureItems); i++) - { - if (CheckBagHasItem(lureItems[i], 1)) - { - VarSet(VAR_0x8004 + count, lureItems[i]); - #if VAR_LAST_REPEL_LURE_USED != 0 - if (VarGet(VAR_LAST_REPEL_LURE_USED) == lureItems[i]) - menuPos = count; - #endif - menuItems[count].text = ItemId_GetName(lureItems[i]); - count++; - } - } - - if (count > 1) - DrawMultichoiceMenuInternal(0, 0, 0, FALSE, menuPos, menuItems, count); - - gSpecialVar_Result = (count > 1); -} - -void HandleLureMenuChoice(struct ScriptContext *ctx) -{ - gSpecialVar_0x8004 = VarGet(VAR_0x8004 + gSpecialVar_Result); // Get item Id; - VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_0x8004) | REPEL_LURE_MASK); -#if VAR_LAST_REPEL_LURE_USED != 0 - VarSet(VAR_LAST_REPEL_LURE_USED, gSpecialVar_0x8004); -#endif -} -#endif //I_REPEL_LURE_MENU == TRUE - #define tLeft data[0] #define tTop data[1] #define tRight data[2] diff --git a/src/sprays.c b/src/sprays.c new file mode 100644 index 0000000000..b553d125ac --- /dev/null +++ b/src/sprays.c @@ -0,0 +1,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); +} diff --git a/src/wild_encounter.c b/src/wild_encounter.c index e3a284c850..13b92136f8 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -24,8 +24,7 @@ #include "constants/layouts.h" #include "constants/weather.h" -extern const u8 EventScript_RepelWoreOff[]; -extern const u8 EventScript_LureWoreOff[]; +extern const u8 EventScript_SprayWoreOff[]; #define MAX_ENCOUNTER_RATE 2880 @@ -968,7 +967,7 @@ bool8 UpdateRepelCounter(void) VarSet(VAR_REPEL_STEP_COUNT, steps); if (steps == 0) { - ScriptContext_SetupScript(EventScript_RepelWoreOff); + ScriptContext_SetupScript(EventScript_SprayWoreOff); return TRUE; } } @@ -977,7 +976,7 @@ bool8 UpdateRepelCounter(void) VarSet(VAR_REPEL_STEP_COUNT, steps | REPEL_LURE_MASK); if (steps == 0) { - ScriptContext_SetupScript(EventScript_LureWoreOff); + ScriptContext_SetupScript(EventScript_SprayWoreOff); return TRUE; } }