Auto‐Repel when Repel runs out - pret/pokered GitHub Wiki
In later generations, the player is prompted with the option to use another repel when their current repel runs out if they have an additional repel in the bag. This tutorial covers how to incorporate this feature into Red.
Editing the Repel Text
Make the following edits to data/text/text_4.asm:
_RepelWoreOffText::
text_asm
ld hl, RepelWoreOffPromptText
call PrintText
+ ld b, REPEL
+ predef GetQuantityOfItemInBag
+ ld a, b
+ and a
+ ld d, REPEL
+ ld e, REPEL_NUMBER_STEPS
+ jr nz, .askUseAnother
+ ld b, SUPER_REPEL
+ predef GetQuantityOfItemInBag
+ ld a, b
+ and a
+ ld d, SUPER_REPEL
+ ld e, SUPER_REPEL_NUMBER_STEPS
+ jr nz, .askUseAnother
+ ld b, MAX_REPEL
+ predef GetQuantityOfItemInBag
+ ld a, b
+ and a
+ ld d, MAX_REPEL
+ ld e, MAX_REPEL_NUMBER_STEPS
+ jr nz, .askUseAnother
+ jr .done
+ .askUseAnother
+ push de
+ ld hl, UseAnotherRepelText
+ call PrintText
+ call YesNoChoice
+ pop de
+ ld a, [wCurrentMenuItem]
+ and a
+ jr nz, .done
+ ld a, e
+ ld [wRepelRemainingSteps], a
+ ld a, d
+ ldh [hItemToRemoveID], a
+ farcall RemoveItemByID
+ ld a, SFX_HEAL_AILMENT
+ call PlaySound
+.done
+ jp CloseTextDisplay
+
+RepelWoreOffPromptText::
+ text "REPEL's effect"
+ line "wore off."
+ prompt
+
+UseAnotherRepelText::
+ text "Use another?"
+ done
These changes are the bulk of the tutorial. First, we check for any quantity of Repel, Super Repel, or Max Repel in that order. If any of them are in the bag, we prompt for using another repel. This opens a YES/NO prompt.
Code Smells
You'll notice that I put in three new constants: REPEL_NUMBER_STEPS, SUPER_REPEL_NUMBER_STEPS, AND MAX_REPEL_NUMBER_STEPS. This is because with this change, the number of steps for each respective repel were stored in two files. Extract the value of the repel steps to constants in: constants/item_constants.asm
DEF MAX_HIDDEN_ITEMS EQU 112
DEF MAX_HIDDEN_COINS EQU 16
+DEF REPEL_NUMBER_STEPS EQU 100
+DEF SUPER_REPEL_NUMBER_STEPS EQU 200
+DEF MAX_REPEL_NUMBER_STEPS EQU 250
Then, update: engine/items/item_effects.asm
ItemUseRepel:
- ld b, 100
+ ld b, REPEL_NUMBER_STEPS
ItemUseSuperRepel:
- ld b, 200
+ ld b, SUPER_REPEL_NUMBER_STEPS
jp ItemUseRepelCommon
ItemUseMaxRepel:
- ld b, 250
+ ld b, MAX_REPEL_NUMBER_STEPS
jp ItemUseRepelCommon
Enjoy friction-less Repel usage!