aboutsummaryrefslogtreecommitdiffstats
path: root/engine/items
diff options
context:
space:
mode:
authorNarishma-gb <194818981+Narishma-gb@users.noreply.github.com>2025-11-27 19:39:25 +0100
committerGitHub <noreply@github.com>2025-11-27 13:39:25 -0500
commit3a4382c6055e21da72357dd18638947a2acbbda9 (patch)
treecb383fbd6a0dc57e3b0f9e9483c2a3f898f42f96 /engine/items
parentAvoid magic numbers for most `CopyData` calls (#542) (diff)
downloadpokeyellow-3a4382c6055e21da72357dd18638947a2acbbda9.tar.gz
pokeyellow-3a4382c6055e21da72357dd18638947a2acbbda9.tar.xz
pokeyellow-3a4382c6055e21da72357dd18638947a2acbbda9.zip
Use more Pokemon data constants, create MOVE_NAME_LENGTH (#543)
Diffstat (limited to 'engine/items')
-rw-r--r--engine/items/item_effects.asm124
-rw-r--r--engine/items/tmhm.asm2
2 files changed, 69 insertions, 57 deletions
diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm
index 7fffae59..a716ebb7 100644
--- a/engine/items/item_effects.asm
+++ b/engine/items/item_effects.asm
@@ -834,7 +834,7 @@ ItemUseMedicine:
.getPartyMonDataAddress
jp c, .canceledItemUse
ld hl, wPartyMons
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
ld a, [wWhichPokemon]
call AddNTimes
ld a, [wWhichPokemon]
@@ -866,7 +866,7 @@ ItemUseMedicine:
jr nc, .healHP ; if it's a Full Restore or one of the potions
; fall through if it's one of the status-specific healing items
.cureStatusAilment
- ld bc, wPartyMon1Status - wPartyMon1
+ ld bc, MON_STATUS
add hl, bc ; hl now points to status
ld a, [wCurItem]
lb bc, ANTIDOTE_MSG, 1 << PSN
@@ -904,7 +904,7 @@ ItemUseMedicine:
ld hl, wPlayerBattleStatus3
res BADLY_POISONED, [hl] ; heal Toxic status
pop hl
- ld bc, wPartyMon1Stats - wPartyMon1Status
+ ld bc, MON_STATS - MON_STATUS
add hl, bc ; hl now points to party stats
ld de, wBattleMonStats
ld bc, NUM_STATS * 2
@@ -962,7 +962,7 @@ ItemUseMedicine:
.compareCurrentHPToMaxHP
push hl
push bc
- ld bc, wPartyMon1MaxHP - (wPartyMon1HP + 1)
+ ld bc, MON_MAXHP - (MON_HP + 1)
add hl, bc ; hl now points to max HP
pop bc
ld a, [hli]
@@ -994,7 +994,7 @@ ItemUseMedicine:
ld [wChannelSoundIDs + CHAN5], a
push hl
push de
- ld bc, wPartyMon1MaxHP - (wPartyMon1HP + 1)
+ ld bc, MON_MAXHP - (MON_HP + 1)
add hl, bc ; hl now points to max HP
ld a, [hli]
ld [wHPBarMaxHP+1], a
@@ -1015,7 +1015,7 @@ ItemUseMedicine:
push af
ld hl, wPartyMon1MaxHP
ld a, [wWhichPokemon]
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld a, [hli]
ld [wHPBarMaxHP + 1], a
@@ -1027,7 +1027,7 @@ ItemUseMedicine:
ldh [hDivisor], a
ld b, 2 ; number of bytes
call Divide ; get 1/5 of max HP of pokemon that used Softboiled
- ld bc, (wPartyMon1HP + 1) - (wPartyMon1MaxHP + 1)
+ ld bc, (MON_HP + 1) - (MON_MAXHP + 1)
add hl, bc ; hl now points to LSB of current HP of pokemon that used Softboiled
; subtract 1/5 of max HP from current HP of pokemon that used Softboiled
ldh a, [hQuotient + 3]
@@ -1106,7 +1106,7 @@ ItemUseMedicine:
inc hl
ld d, h
ld e, l ; de now points to current HP
- ld hl, (wPartyMon1MaxHP + 1) - (wPartyMon1HP + 1)
+ ld hl, (MON_MAXHP + 1) - (MON_HP + 1)
add hl, de ; hl now points to max HP
ld a, [wCurItem]
cp REVIVE
@@ -1153,7 +1153,7 @@ ItemUseMedicine:
ld a, [wCurItem]
cp FULL_RESTORE
jr nz, .updateInBattleData
- ld bc, wPartyMon1Status - (wPartyMon1MaxHP + 1)
+ ld bc, MON_STATUS - (MON_MAXHP + 1)
add hl, bc
xor a
ld [hl], a ; remove the status ailment in the party data
@@ -1256,7 +1256,7 @@ ItemUseMedicine:
ld a, [hl]
ld [wCurSpecies], a
ld [wPokedexNum], a
- ld bc, wPartyMon1Level - wPartyMon1
+ ld bc, MON_LEVEL
add hl, bc ; hl now points to level
ld a, [hl] ; a = level
ld [wCurEnemyLevel], a ; store level
@@ -1273,7 +1273,7 @@ ItemUseMedicine:
push hl
sub HP_UP
add a
- ld bc, wPartyMon1HPExp - wPartyMon1
+ ld bc, MON_HP_EXP
add hl, bc
add l
ld l, a
@@ -1321,17 +1321,17 @@ ItemUseMedicine:
call PrintText
jp GBPalWhiteOut
.recalculateStats
- ld bc, wPartyMon1Stats - wPartyMon1
+ ld bc, MON_STATS
add hl, bc
ld d, h
ld e, l ; de now points to stats
- ld bc, (wPartyMon1Exp + 2) - wPartyMon1Stats
+ ld bc, (MON_EXP + 2) - MON_STATS
add hl, bc ; hl now points to LSB of experience
ld b, 1
jp CalcStats ; recalculate stats
.useRareCandy
push hl
- ld bc, wPartyMon1Level - wPartyMon1
+ ld bc, MON_LEVEL
add hl, bc ; hl now points to level
ld a, [hl] ; a = level
cp MAX_LEVEL
@@ -1345,7 +1345,7 @@ ItemUseMedicine:
callfar CalcExperience ; calculate experience for next level and store it at hExperience
pop de
pop hl
- ld bc, wPartyMon1Exp - wPartyMon1Level
+ ld bc, MON_EXP - MON_LEVEL
add hl, bc ; hl now points to MSB of experience
; update experience to minimum for new level
ldh a, [hExperience]
@@ -1361,7 +1361,7 @@ ItemUseMedicine:
push af
push de
push hl
- ld bc, wPartyMon1MaxHP - wPartyMon1
+ ld bc, MON_MAXHP
add hl, bc ; hl now points to MSB of max HP
ld a, [hli]
ld b, a
@@ -1371,7 +1371,7 @@ ItemUseMedicine:
push hl
call .recalculateStats
pop hl
- ld bc, (wPartyMon1MaxHP + 1) - wPartyMon1
+ ld bc, (MON_MAXHP + 1)
add hl, bc ; hl now points to LSB of max HP
pop bc
ld a, [hld]
@@ -1381,7 +1381,7 @@ ItemUseMedicine:
sbc b
ld b, a ; bc = the amount of max HP gained from leveling up
; add the amount gained to the current HP
- ld de, (wPartyMon1HP + 1) - wPartyMon1MaxHP
+ ld de, (MON_HP + 1) - MON_MAXHP
add hl, de ; hl now points to LSB of current HP
ld a, [hl]
add c
@@ -1984,7 +1984,7 @@ ItemUsePPRestore:
ld [wPlayerMoveListIndex], a
jr nz, .chooseMon
ld hl, wPartyMon1Moves
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
call GetSelectedMoveOffset
push hl
ld a, [hl]
@@ -1996,7 +1996,7 @@ ItemUsePPRestore:
cp ETHER
jr nc, .useEther ; if Ether or Max Ether
.usePPUp
- ld bc, wPartyMon1PP - wPartyMon1Moves
+ ld bc, MON_PP - MON_MOVES
add hl, bc
ld a, [hl] ; move PP
cp 3 << 6 ; have 3 PP Ups already been used?
@@ -2026,7 +2026,7 @@ ItemUsePPRestore:
cp b ; is the pokemon whose PP was restored active in battle?
jr nz, .skipUpdatingInBattleData
ld hl, wPartyMon1PP
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld de, wBattleMonPP
ld bc, NUM_MOVES
@@ -2048,9 +2048,9 @@ ItemUsePPRestore:
ld [wMonDataLocation], a
call GetMaxPP
ld hl, wPartyMon1Moves
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
call GetSelectedMoveOffset
- ld bc, wPartyMon1PP - wPartyMon1Moves
+ ld bc, MON_PP - MON_MOVES
add hl, bc ; hl now points to move's PP
ld a, [wMaxPP]
ld b, a
@@ -2098,7 +2098,7 @@ ItemUsePPRestore:
.elixirLoop
push bc
ld hl, wPartyMon1Moves
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
call GetSelectedMoveOffset
ld a, [hl]
and a ; does the current slot have a move?
@@ -2195,7 +2195,7 @@ ItemUseTMHM:
.chooseMon
ld hl, wStringBuffer
ld de, wTempMoveNameBuffer
- ld bc, ITEM_NAME_LENGTH + 1
+ ld bc, MOVE_NAME_LENGTH
call CopyData ; save the move name because DisplayPartyMenu will overwrite it
ld a, $ff
ld [wUpdateSpritesEnabled], a
@@ -2205,7 +2205,7 @@ ItemUseTMHM:
push af
ld hl, wTempMoveNameBuffer
ld de, wStringBuffer
- ld bc, ITEM_NAME_LENGTH + 1
+ ld bc, MOVE_NAME_LENGTH
call CopyData
pop af
jr nc, .checkIfAbleToLearnMove
@@ -2375,14 +2375,14 @@ GotOffBicycleText:
; [wCurrentMenuItem] = index of move (when using a PP Up)
RestoreBonusPP:
ld hl, wPartyMon1Moves
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
ld a, [wWhichPokemon]
call AddNTimes
push hl
ld de, wNormalMaxPPList - 1
predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList
pop hl
- ld c, wPartyMon1PP - wPartyMon1Moves
+ ld c, MON_PP - MON_MOVES
ld b, 0
add hl, bc ; hl now points to move 1 PP
ld de, wNormalMaxPPList
@@ -2468,13 +2468,13 @@ GetMaxPP:
ld a, [wMonDataLocation]
and a
ld hl, wPartyMon1Moves
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
jr z, .sourceWithMultipleMon
ld hl, wEnemyMon1Moves
dec a
jr z, .sourceWithMultipleMon
ld hl, wBoxMon1Moves
- ld bc, wBoxMon2 - wBoxMon1
+ ld bc, BOXMON_STRUCT_LENGTH
dec a
jr z, .sourceWithMultipleMon
ld hl, wDayCareMonMoves
@@ -2501,7 +2501,7 @@ GetMaxPP:
ld b, a ; b = normal max PP
pop hl
push bc
- ld bc, wPartyMon1PP - wPartyMon1Moves ; PP offset if not player's in-battle pokemon data
+ ld bc, MON_PP - MON_MOVES ; PP offset if not player's in-battle pokemon data
ld a, [wMonDataLocation]
cp 4 ; player's in-battle pokemon?
jr nz, .addPPOffset
@@ -2645,29 +2645,33 @@ IsKeyItem_::
INCLUDE "data/items/key_items.asm"
+; store the new mon in the first slot, shifting all existing box data down
SendNewMonToBox:
ld de, wBoxCount
ld a, [de]
inc a
ld [de], a
+
ld a, [wCurPartySpecies]
ld [wCurSpecies], a
ld c, a
-.loop
+.shiftSpeciesLoop
inc de
ld a, [de]
ld b, a
ld a, c
ld c, b
ld [de], a
- cp $ff
- jr nz, .loop
+ cp -1
+ jr nz, .shiftSpeciesLoop
+
call GetMonHeader
ld hl, wBoxMonOT
ld bc, NAME_LENGTH
ld a, [wBoxCount]
dec a
- jr z, .skip
+ jr z, .skipOTshift ; if the box was empty, there is nothing to shift
+
dec a
call AddNTimes
push hl
@@ -2679,7 +2683,7 @@ SendNewMonToBox:
ld a, [wBoxCount]
dec a
ld b, a
-.loop2
+.shiftMonOTLoop
push bc
push hl
ld bc, NAME_LENGTH
@@ -2691,15 +2695,18 @@ SendNewMonToBox:
add hl, bc
pop bc
dec b
- jr nz, .loop2
-.skip
+ jr nz, .shiftMonOTLoop
+
+.skipOTshift
ld hl, wPlayerName
- ld de, wBoxMonOT
+ ld de, wBoxMon1OT
ld bc, NAME_LENGTH
call CopyData
+
ld a, [wBoxCount]
dec a
- jr z, .skip2
+ jr z, .skipNickShift
+
ld hl, wBoxMonNicks
ld bc, NAME_LENGTH
dec a
@@ -2713,7 +2720,7 @@ SendNewMonToBox:
ld a, [wBoxCount]
dec a
ld b, a
-.loop3
+.shiftNickLoop
push bc
push hl
ld bc, NAME_LENGTH
@@ -2725,21 +2732,24 @@ SendNewMonToBox:
add hl, bc
pop bc
dec b
- jr nz, .loop3
-.skip2
- ld hl, wBoxMonNicks
+ jr nz, .shiftNickLoop
+
+.skipNickShift
+ ld hl, wBoxMon1Nick
ld a, NAME_MON_SCREEN
ld [wNamingScreenType], a
predef AskName
+
ld a, [wBoxCount]
dec a
- jr z, .skip3
+ jr z, .skipMonDataShift
+
ld hl, wBoxMons
- ld bc, wBoxMon2 - wBoxMon1
+ ld bc, BOXMON_STRUCT_LENGTH
dec a
call AddNTimes
push hl
- ld bc, wBoxMon2 - wBoxMon1
+ ld bc, BOXMON_STRUCT_LENGTH
add hl, bc
ld d, h
ld e, l
@@ -2747,20 +2757,21 @@ SendNewMonToBox:
ld a, [wBoxCount]
dec a
ld b, a
-.loop4
+.shiftMonDataLoop
push bc
push hl
- ld bc, wBoxMon2 - wBoxMon1
+ ld bc, BOXMON_STRUCT_LENGTH
call CopyData
pop hl
ld d, h
ld e, l
- ld bc, wBoxMon1 - wBoxMon2
+ ld bc, -BOXMON_STRUCT_LENGTH
add hl, bc
pop bc
dec b
- jr nz, .loop4
-.skip3
+ jr nz, .shiftMonDataLoop
+
+.skipMonDataShift
ld a, [wEnemyMonLevel]
ld [wEnemyMonBoxLevel], a
ld hl, wEnemyMon
@@ -2790,11 +2801,12 @@ SendNewMonToBox:
inc de
xor a
ld b, NUM_STATS * 2
-.loop5
+.statLoop
ld [de], a
inc de
dec b
- jr nz, .loop5
+ jr nz, .statLoop
+
ld hl, wEnemyMonDVs
ld a, [hli]
ld [de], a
@@ -2803,12 +2815,12 @@ SendNewMonToBox:
ld [de], a
ld hl, wEnemyMonPP
ld b, NUM_MOVES
-.loop6
+.movePPLoop
ld a, [hli]
inc de
ld [de], a
dec b
- jr nz, .loop6
+ jr nz, .movePPLoop
ret
; checks if the tile in front of the player is a shore or water tile
diff --git a/engine/items/tmhm.asm b/engine/items/tmhm.asm
index a11cd736..bac92f5d 100644
--- a/engine/items/tmhm.asm
+++ b/engine/items/tmhm.asm
@@ -2,7 +2,7 @@
CheckIfMoveIsKnown:
ld a, [wWhichPokemon]
ld hl, wPartyMon1Moves
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld a, [wMoveNum]
ld b, a