diff options
| author | Narishma-gb <194818981+Narishma-gb@users.noreply.github.com> | 2025-11-27 19:39:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-27 13:39:25 -0500 |
| commit | 3a4382c6055e21da72357dd18638947a2acbbda9 (patch) | |
| tree | cb383fbd6a0dc57e3b0f9e9483c2a3f898f42f96 | |
| parent | Avoid magic numbers for most `CopyData` calls (#542) (diff) | |
| download | pokeyellow-3a4382c6055e21da72357dd18638947a2acbbda9.tar.gz pokeyellow-3a4382c6055e21da72357dd18638947a2acbbda9.tar.xz pokeyellow-3a4382c6055e21da72357dd18638947a2acbbda9.zip | |
Use more Pokemon data constants, create MOVE_NAME_LENGTH (#543)
35 files changed, 235 insertions, 207 deletions
diff --git a/constants/pokemon_data_constants.asm b/constants/pokemon_data_constants.asm index 1234acab..16d21f54 100644 --- a/constants/pokemon_data_constants.asm +++ b/constants/pokemon_data_constants.asm @@ -44,7 +44,7 @@ DEF MON_SPD_EXP rw DEF MON_SPC_EXP rw DEF MON_DVS rw DEF MON_PP rb NUM_MOVES -DEF BOXMON_STRUCT_LENGTH EQU _RS +DEF BOXMON_STRUCT_LENGTH EQU _RS ; $21 DEF MON_LEVEL rb DEF MON_STATS rw NUM_STATS rsset MON_STATS @@ -53,7 +53,7 @@ DEF MON_ATK rw DEF MON_DEF rw DEF MON_SPD rw DEF MON_SPC rw -DEF PARTYMON_STRUCT_LENGTH EQU _RS +DEF PARTYMON_STRUCT_LENGTH EQU _RS ; $2c DEF PARTY_LENGTH EQU 6 diff --git a/constants/text_constants.asm b/constants/text_constants.asm index ed195172..88a42bbe 100644 --- a/constants/text_constants.asm +++ b/constants/text_constants.asm @@ -1,5 +1,7 @@ +DEF PLAYER_NAME_LENGTH EQU 8 DEF NAME_LENGTH EQU 11 DEF ITEM_NAME_LENGTH EQU 13 +DEF MOVE_NAME_LENGTH EQU 14 DEF NAME_BUFFER_LENGTH EQU 20 DEF GYM_CITY_LENGTH EQU 17 diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm index 3670cddc..a37a5054 100644 --- a/engine/battle/battle_transitions.asm +++ b/engine/battle/battle_transitions.asm @@ -104,11 +104,11 @@ GetBattleTransitionID_CompareLevels: ld a, [hli] or [hl] jr nz, .notFainted - ld de, wPartyMon2 - (wPartyMon1 + 1) + ld de, PARTYMON_STRUCT_LENGTH - 1 add hl, de jr .faintedLoop .notFainted - ld de, wPartyMon1Level - (wPartyMon1HP + 1) + ld de, MON_LEVEL - (MON_HP + 1) add hl, de ld a, [hl] add $3 diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 4c25373a..44fd9a70 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -137,7 +137,7 @@ StartBattle: inc a ld [wFirstMonsNotOutYet], a ld hl, wEnemyMon1HP - ld bc, wEnemyMon2 - wEnemyMon1 - 1 + ld bc, PARTYMON_STRUCT_LENGTH - 1 ld d, $3 .findFirstAliveEnemyMonLoop inc d @@ -736,7 +736,7 @@ FaintEnemyPokemon: jr z, .wild ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1HP - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes xor a ld [hli], a @@ -876,7 +876,7 @@ AnyEnemyPokemonAliveCheck: ld b, a xor a ld hl, wEnemyMon1HP - ld de, wEnemyMon2 - wEnemyMon1 + ld de, PARTYMON_STRUCT_LENGTH .nextPokemon or [hl] inc hl @@ -1330,7 +1330,7 @@ EnemySendOutFirstMon: ld a, b ld [wWhichPokemon], a push bc - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes pop bc inc hl @@ -1342,7 +1342,7 @@ EnemySendOutFirstMon: .next3 ld a, [wWhichPokemon] ld hl, wEnemyMon1Level - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hl] ld [wCurEnemyLevel], a @@ -1457,7 +1457,7 @@ AnyPartyAlive:: ld e, a xor a ld hl, wPartyMon1HP - ld bc, wPartyMon2 - wPartyMon1 - 1 + ld bc, PARTYMON_STRUCT_LENGTH - 1 .partyMonsLoop or [hl] inc hl @@ -1473,7 +1473,7 @@ AnyPartyAlive:: HasMonFainted: ld a, [wWhichPokemon] ld hl, wPartyMon1HP - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] or [hl] @@ -1625,16 +1625,16 @@ GotAwayText: ; copies from party data to battle mon data when sending out a new player mon LoadBattleMonFromParty: ld a, [wWhichPokemon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld hl, wPartyMon1Species call AddNTimes ld de, wBattleMonSpecies ld bc, wBattleMonDVs - wBattleMonSpecies call CopyData - ld bc, wPartyMon1DVs - wPartyMon1OTID + ld bc, MON_DVS - MON_OTID add hl, bc ld de, wBattleMonDVs - ld bc, wPartyMon1PP - wPartyMon1DVs + ld bc, MON_PP - MON_DVS call CopyData ld de, wBattleMonPP ld bc, NUM_MOVES @@ -1669,16 +1669,16 @@ LoadBattleMonFromParty: ; copies from enemy party data to current enemy mon data when sending out a new enemy mon LoadEnemyMonFromParty: ld a, [wWhichPokemon] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld hl, wEnemyMons call AddNTimes ld de, wEnemyMonSpecies ld bc, wEnemyMonDVs - wEnemyMonSpecies call CopyData - ld bc, wEnemyMon1DVs - wEnemyMon1OTID + ld bc, MON_DVS - MON_OTID add hl, bc ld de, wEnemyMonDVs - ld bc, wEnemyMon1PP - wEnemyMon1DVs + ld bc, MON_PP - MON_DVS call CopyData ld de, wEnemyMonPP ld bc, NUM_MOVES @@ -1800,7 +1800,7 @@ AnimateRetreatingPlayerMon: ReadPlayerMonCurHPAndStatus: ld a, [wPlayerMonNumber] ld hl, wPartyMon1HP - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld d, h ld e, l @@ -2520,7 +2520,7 @@ MoveSelectionMenu: .relearnmenu ld a, [wWhichPokemon] ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes call .loadmoves hlcoord 4, 7 @@ -2798,12 +2798,12 @@ SwapMovesInMenu: .swapMovesInPartyMon ld hl, wPartyMon1Moves ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes push hl call .swapBytes ; swap moves pop hl - ld bc, wPartyMon1PP - wPartyMon1Moves + ld bc, MON_PP - MON_MOVES add hl, bc call .swapBytes ; swap move PP xor a @@ -3451,7 +3451,7 @@ CheckPlayerStatusConditions: bit PAR, [hl] jr z, .BideCheck call BattleRandom - cp $3F ; 25% to be fully paralyzed + cp 25 percent ; chance to be fully paralyzed jr nc, .BideCheck ld hl, FullyParalyzedText call PrintText @@ -3970,7 +3970,7 @@ CheckForDisobedience: ; compare the mon's original trainer ID with the player's ID to see if it was traded .checkIfMonIsTraded ld hl, wPartyMon1OTID - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wPlayerMonNumber] call AddNTimes ld a, [wPlayerID] @@ -4197,7 +4197,7 @@ GetDamageVarsForPlayerAttack: push bc ld hl, wPartyMon1Attack ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes pop bc jr .scaleStats @@ -4229,7 +4229,7 @@ GetDamageVarsForPlayerAttack: push bc ld hl, wPartyMon1Special ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes pop bc ; if either the offensive or defensive stat is too large to store in a byte, scale both stats by dividing them by 4 @@ -4303,7 +4303,7 @@ GetDamageVarsForEnemyAttack: ; in the case of a critical hit, reset the player's defense and the enemy's attack to their base values ld hl, wPartyMon1Defense ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ld b, a @@ -4335,7 +4335,7 @@ GetDamageVarsForEnemyAttack: ; in the case of a critical hit, reset the player's and enemy's specials to their base values ld hl, wPartyMon1Special ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ld b, a @@ -4398,7 +4398,7 @@ GetEnemyMonStat: ld b, $0 add hl, bc ld a, [wEnemyMonPartyPos] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ldh [hMultiplicand + 1], a @@ -5197,7 +5197,7 @@ IncrementMovePP: jr z, .updatePP ld a, [wEnemyMonPartyPos] ; value for enemy turn .updatePP - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes inc [hl] ; increment PP in the party memory location ret @@ -6206,7 +6206,7 @@ LoadEnemyMonData: ; if it's a trainer battle, copy moves from enemy party data ld hl, wEnemyMon1Moves ld a, [wWhichPokemon] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld bc, NUM_MOVES call CopyData diff --git a/engine/battle/decrement_pp.asm b/engine/battle/decrement_pp.asm index 441bbb81..93515224 100644 --- a/engine/battle/decrement_pp.asm +++ b/engine/battle/decrement_pp.asm @@ -31,7 +31,7 @@ DecrementPP: ld hl, wPartyMon1PP ; PP of first move (in party) ld a, [wPlayerMonNumber] ; which mon in party is active - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ; calculate address of the mon to modify .DecrementPP: ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use? diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm index 011b4b33..768a6e20 100644 --- a/engine/battle/draw_hud_pokeball_gfx.asm +++ b/engine/battle/draw_hud_pokeball_gfx.asm @@ -90,7 +90,7 @@ PickPokeball: .done ld a, b ld [de], a - ld bc, wPartyMon2 - wPartyMon1Status + ld bc, PARTYMON_STRUCT_LENGTH - MON_STATUS add hl, bc ; next mon struct ret diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm index 003592aa..2cef2521 100644 --- a/engine/battle/effects.asm +++ b/engine/battle/effects.asm @@ -323,7 +323,7 @@ CheckDefrost: ld [wEnemyMonStatus], a ; set opponent status to 00 ["defrost" a frozen monster] ld hl, wEnemyMon1Status ld a, [wEnemyMonPartyPos] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes xor a ld [hl], a ; clear status in roster @@ -336,7 +336,7 @@ CheckDefrost: ld [wBattleMonStatus], a ld hl, wPartyMon1Status ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes xor a ld [hl], a diff --git a/engine/battle/end_of_battle.asm b/engine/battle/end_of_battle.asm index 80fdf002..2feb50bd 100644 --- a/engine/battle/end_of_battle.asm +++ b/engine/battle/end_of_battle.asm @@ -5,7 +5,7 @@ EndOfBattle: ; link battle ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1Status - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [wEnemyMonStatus] ld [hl], a @@ -60,8 +60,8 @@ EndOfBattle: ld [hli], a ld [hl], a ld [wListScrollOffset], a - ld hl, wPlayerStatsToDouble - ld b, $18 + ld hl, wBattleStatusData + ld b, wBattleStatusDataEnd - wBattleStatusData .loop ld [hli], a dec b diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm index a8ee6747..4e44643c 100644 --- a/engine/battle/experience.asm +++ b/engine/battle/experience.asm @@ -21,7 +21,7 @@ GainExperience: and a ; is mon's gain exp flag set? pop hl jp z, .nextMon ; if mon's gain exp flag not set, go to next mon - ld de, (wPartyMon1HPExp + 1) - (wPartyMon1HP + 1) + ld de, (MON_HP_EXP + 1) - (MON_HP + 1) add hl, de ld d, h ld e, l @@ -66,9 +66,9 @@ GainExperience: ldh [hDivisor], a ld b, 4 call Divide - ld hl, wPartyMon1OTID - (wPartyMon1DVs - 1) + ld hl, MON_OTID - (MON_DVS - 1) add hl, de - ld b, [hl] ; party mon OTID + ld b, [hl] ; wPartyMon*OTID inc hl ld a, [wPlayerID] cp b @@ -152,7 +152,7 @@ GainExperience: ld [wMonDataLocation], a call LoadMonData pop hl - ld bc, wPartyMon1Level - wPartyMon1Exp + ld bc, MON_LEVEL - MON_EXP add hl, bc push hl farcall CalcLevelFromExperience @@ -166,13 +166,13 @@ GainExperience: ld a, d ld [wCurEnemyLevel], a ld [hl], a - ld bc, wPartyMon1Species - wPartyMon1Level + ld bc, MON_SPECIES - MON_LEVEL add hl, bc ld a, [hl] ld [wCurSpecies], a ld [wPokedexNum], a call GetMonHeader - ld bc, (wPartyMon1MaxHP + 1) - wPartyMon1Species + ld bc, (MON_MAXHP + 1) - MON_SPECIES add hl, bc push hl ld a, [hld] @@ -181,7 +181,7 @@ GainExperience: push bc ; push max HP (from before levelling up) ld d, h ld e, l - ld bc, (wPartyMon1HPExp - 1) - wPartyMon1MaxHP + ld bc, (MON_HP_EXP - 1) - MON_MAXHP add hl, bc ld b, $1 ; consider stat exp when calculating stats call CalcStats @@ -193,15 +193,15 @@ GainExperience: ld a, [hl] sbc b ld b, a ; bc = difference between old max HP and new max HP after levelling - ld de, (wPartyMon1HP + 1) - wPartyMon1MaxHP + ld de, (MON_HP + 1) - MON_MAXHP add hl, de ; add to the current HP the amount of max HP gained when levelling - ld a, [hl] ; wPartyMon1HP + 1 + ld a, [hl] ; wPartyMon*HP + 1 add c ld [hld], a - ld a, [hl] ; wPartyMon1HP + 1 + ld a, [hl] ; wPartyMon*HP + 1 adc b - ld [hl], a ; wPartyMon1HP + ld [hl], a ; wPartyMon*HP ld a, [wPlayerMonNumber] ld b, a ld a, [wWhichPokemon] @@ -216,7 +216,7 @@ GainExperience: ld a, [hl] ld [de], a ; copy other stats from party mon to battle mon - ld bc, wPartyMon1Level - (wPartyMon1HP + 1) + ld bc, MON_LEVEL - (MON_HP + 1) add hl, bc push hl ld de, wBattleMonLevel @@ -271,7 +271,7 @@ GainExperience: cp b jr z, .done ld [wWhichPokemon], a - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld hl, wPartyMon1 call AddNTimes jp .partyMonLoop diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm index df1132ea..1e173690 100644 --- a/engine/battle/read_trainer_party.asm +++ b/engine/battle/read_trainer_party.asm @@ -92,7 +92,7 @@ ReadTrainer: ld a, [hli] ld d, [hl] ld hl, wEnemyMon1Moves + 2 - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld [hl], d jr .FinishUp diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm index 546dd60e..b9447779 100644 --- a/engine/battle/trainer_ai.asm +++ b/engine/battle/trainer_ai.asm @@ -569,7 +569,7 @@ AISwitchIfEnoughMons: inc d .Fainted push bc - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH add hl, bc pop bc dec c @@ -587,7 +587,7 @@ SwitchEnemyMon: ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1HP - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld d, h ld e, l @@ -626,7 +626,7 @@ AICureStatus: ; cures the status of enemy's active pokemon ld a, [wEnemyMonPartyPos] ld hl, wEnemyMon1Status - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes xor a ld [hl], a ; clear status in enemy team roster diff --git a/engine/events/heal_party.asm b/engine/events/heal_party.asm index e6551bcd..5532fd92 100644 --- a/engine/events/heal_party.asm +++ b/engine/events/heal_party.asm @@ -11,7 +11,7 @@ HealParty: push hl push de - ld hl, wPartyMon1Status - wPartyMon1HP + ld hl, MON_STATUS - MON_HP add hl, de xor a ld [hl], a @@ -19,7 +19,7 @@ HealParty: push de ld b, NUM_MOVES ; A Pokémon has 4 moves .pp - ld hl, wPartyMon1Moves - wPartyMon1HP + ld hl, MON_MOVES - MON_HP add hl, de ld a, [hl] @@ -27,7 +27,7 @@ HealParty: jr z, .nextmove dec a - ld hl, wPartyMon1PP - wPartyMon1HP + ld hl, MON_PP - MON_HP add hl, de push hl @@ -60,7 +60,7 @@ HealParty: jr nz, .pp pop de - ld hl, wPartyMon1MaxHP - wPartyMon1HP + ld hl, MON_MAXHP - MON_HP add hl, de ld a, [hli] ld [de], a @@ -72,7 +72,7 @@ HealParty: pop hl push hl - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld h, d ld l, e add hl, bc diff --git a/engine/events/in_game_trades.asm b/engine/events/in_game_trades.asm index 5cc251f4..3107550f 100644 --- a/engine/events/in_game_trades.asm +++ b/engine/events/in_game_trades.asm @@ -115,7 +115,7 @@ InGameTrade_DoTrade: jr nz, .tradeFailed ; jump if the selected mon's species is not the required one ld a, [wWhichPokemon] ld hl, wPartyMon1Level - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hl] ld [wCurEnemyLevel], a @@ -190,7 +190,7 @@ InGameTrade_PrepareTradeData: ld de, wLinkEnemyTrainerName call InGameTrade_CopyData ld hl, wPartyMon1OTID - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wWhichPokemon] call AddNTimes ld de, wTradedPlayerMonOTID @@ -223,7 +223,7 @@ InGameTrade_CopyDataToReceivedMon: ld bc, NAME_LENGTH call CopyData ld hl, wPartyMon1OTID - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call InGameTrade_GetReceivedMonPointer ld hl, wTradedEnemyMonOTID ld bc, 2 diff --git a/engine/events/poison.asm b/engine/events/poison.asm index beb1a312..8c3dc8b3 100644 --- a/engine/events/poison.asm +++ b/engine/events/poison.asm @@ -65,7 +65,7 @@ ApplyOutOfBattlePoisonDamage: ld a, [de] inc a jr z, .applyDamageLoopDone - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH add hl, bc push hl ld hl, wWhichPokemon @@ -82,7 +82,7 @@ ApplyOutOfBattlePoisonDamage: and 1 << PSN or e ld e, a - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH add hl, bc dec d jr nz, .countPoisonedLoop 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 diff --git a/engine/link/cable_club.asm b/engine/link/cable_club.asm index ea39b938..4a300164 100644 --- a/engine/link/cable_club.asm +++ b/engine/link/cable_club.asm @@ -763,9 +763,9 @@ TradeCenter_Trade: call CopyData ld hl, wPartyMon1Species ld a, [wTradingWhichPlayerMon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes - ld bc, wPartyMon1OTID - wPartyMon1 + ld bc, MON_OTID add hl, bc ld a, [hli] ld [wTradedPlayerMonOTID], a @@ -779,9 +779,9 @@ TradeCenter_Trade: call CopyData ld hl, wEnemyMons ld a, [wTradingWhichEnemyMon] - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes - ld bc, wEnemyMon1OTID - wEnemyMon1 + ld bc, MON_OTID add hl, bc ld a, [hli] ld [wTradedEnemyMonOTID], a @@ -809,10 +809,10 @@ TradeCenter_Trade: ld [wCurPartySpecies], a ld hl, wEnemyMons ld a, c - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld de, wLoadedMon - ld bc, wEnemyMon2 - wEnemyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call CopyData call AddEnemyMonToPlayerParty ld a, [wPartyCount] diff --git a/engine/menus/naming_screen.asm b/engine/menus/naming_screen.asm index 9c0cd0a8..24b172f0 100644 --- a/engine/menus/naming_screen.asm +++ b/engine/menus/naming_screen.asm @@ -241,11 +241,11 @@ DisplayNamingScreen: cp NAME_MON_SCREEN jr nc, .checkMonNameLength ld a, [wNamingScreenNameLength] - cp $7 ; max length of player/rival names + cp PLAYER_NAME_LENGTH - 1 jr .checkNameLength .checkMonNameLength ld a, [wNamingScreenNameLength] - cp $a ; max length of pokemon nicknames + cp NAME_LENGTH - 1 .checkNameLength jr c, .addLetter ret diff --git a/engine/menus/start_sub_menus.asm b/engine/menus/start_sub_menus.asm index c27e58a9..ec10dd11 100644 --- a/engine/menus/start_sub_menus.asm +++ b/engine/menus/start_sub_menus.asm @@ -236,7 +236,7 @@ StartMenu_Pokemon:: .softboiled ld hl, wPartyMon1MaxHP ld a, [wWhichPokemon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hli] ldh [hDividend], a @@ -246,7 +246,7 @@ StartMenu_Pokemon:: ldh [hDivisor], a ld b, 2 ; number of bytes call Divide - ld bc, wPartyMon1HP - wPartyMon1MaxHP + ld bc, MON_HP - MON_MAXHP add hl, bc ld a, [hld] ld b, a @@ -743,24 +743,24 @@ SwitchPartyMon_InitVarOrSwapData: ldh a, [hSwapTemp] ld [de], a ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wCurrentMenuItem] call AddNTimes push hl ld de, wSwitchPartyMonTempBuffer - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call CopyData ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wMenuItemToSwap] call AddNTimes pop de push hl - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call CopyData pop de ld hl, wSwitchPartyMonTempBuffer - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call CopyData ld hl, wPartyMonOT ld a, [wCurrentMenuItem] diff --git a/engine/menus/text_box.asm b/engine/menus/text_box.asm index 94c432c7..e618b1d0 100644 --- a/engine/menus/text_box.asm +++ b/engine/menus/text_box.asm @@ -509,7 +509,7 @@ PokemonMenuEntries: GetMonFieldMoves: ld a, [wWhichPokemon] ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld d, h ld e, l diff --git a/engine/movie/hall_of_fame.asm b/engine/movie/hall_of_fame.asm index 88e777af..ec457141 100644 --- a/engine/movie/hall_of_fame.asm +++ b/engine/movie/hall_of_fame.asm @@ -49,7 +49,7 @@ AnimateHallOfFame: ld a, c ld [wHoFPartyMonIndex], a ld hl, wPartyMon1Level - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld a, [hl] ld [wHoFMonLevel], a diff --git a/engine/pokemon/add_mon.asm b/engine/pokemon/add_mon.asm index a7c201ea..455221ce 100644 --- a/engine/pokemon/add_mon.asm +++ b/engine/pokemon/add_mon.asm @@ -59,7 +59,7 @@ _AddPartyMon:: .next3 ldh a, [hNewPartyLength] dec a - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld e, l ld d, h @@ -117,12 +117,12 @@ _AddPartyMon:: .next4 push bc - ld bc, wPartyMon1DVs - wPartyMon1 + ld bc, MON_DVS add hl, bc pop bc ld [hli], a ld [hl], b ; write IVs - ld bc, (wPartyMon1HPExp - 1) - (wPartyMon1DVs + 1) + ld bc, (MON_HP_EXP - 1) - (MON_DVS + 1) add hl, bc ld a, 1 ld c, a @@ -142,7 +142,7 @@ _AddPartyMon:: inc de jr .copyMonTypesAndMoves .copyEnemyMonData - ld bc, wEnemyMon1DVs - wEnemyMon1 + ld bc, MON_DVS add hl, bc ld a, [wEnemyMonDVs] ; copy IVs from cur enemy mon ld [hli], a @@ -237,7 +237,7 @@ _AddPartyMon:: jr .done .calcFreshStats pop hl - ld bc, wPartyMon1HPExp - 1 - wPartyMon1 + ld bc, MON_HP_EXP - 1 add hl, bc ld b, $0 call CalcStats ; calculate fresh set of stats @@ -294,7 +294,7 @@ _AddEnemyMonToPlayerParty:: ld hl, wPartyMons ld a, [wPartyCount] dec a - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld e, l ld d, h @@ -379,12 +379,12 @@ _MoveMon:: ld a, [wMoveMonType] dec a ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 ; $2c + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wPartyCount] jr nz, .addMonOffset ; if it's PARTY_TO_BOX ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 ; $21 + ld bc, BOXMON_STRUCT_LENGTH ld a, [wBoxCount] .addMonOffset dec a @@ -396,20 +396,20 @@ _MoveMon:: ld a, [wMoveMonType] and a ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 ; $21 + ld bc, BOXMON_STRUCT_LENGTH jr z, .addMonOffset2 cp DAYCARE_TO_PARTY ld hl, wDayCareMon jr z, .copyMonData ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 ; $2c + ld bc, PARTYMON_STRUCT_LENGTH .addMonOffset2 ld a, [wWhichPokemon] call AddNTimes .copyMonData push hl push de - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH call CopyData pop de pop hl @@ -418,7 +418,7 @@ _MoveMon:: jr z, .findOTdest cp DAYCARE_TO_PARTY jr z, .findOTdest - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH add hl, bc ld a, [hl] ; hl = Level inc de @@ -493,6 +493,7 @@ _MoveMon:: jr z, .done cp PARTY_TO_DAYCARE jr z, .done + ; returning mon to party, compute level and stats push hl srl a add $2 @@ -502,13 +503,13 @@ _MoveMon:: ld a, d ld [wCurEnemyLevel], a pop hl - ld bc, wBoxMon2 - wBoxMon1 - add hl, bc + ld bc, BOXMON_STRUCT_LENGTH + add hl, bc ; hl = wPartyMon*Level ld [hli], a ld d, h ld e, l - ld bc, -18 - add hl, bc + ld bc, (MON_HP_EXP - 1) - MON_STATS + add hl, bc ; hl = wPartyMon*HPExp - 1 ld b, $1 call CalcStats .done diff --git a/engine/pokemon/bills_pc.asm b/engine/pokemon/bills_pc.asm index 0fcdedc6..09adfa37 100644 --- a/engine/pokemon/bills_pc.asm +++ b/engine/pokemon/bills_pc.asm @@ -352,11 +352,11 @@ BoxNoPCText: KnowsHMMove:: ; returns whether mon with party index [wWhichPokemon] knows an HM move ld hl, wPartyMon1Moves - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH jr .next ; unreachable ld hl, wBoxMon1Moves - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH .next ld a, [wWhichPokemon] call AddNTimes diff --git a/engine/pokemon/evos_moves.asm b/engine/pokemon/evos_moves.asm index 1b92a093..794cb164 100644 --- a/engine/pokemon/evos_moves.asm +++ b/engine/pokemon/evos_moves.asm @@ -177,13 +177,13 @@ Evolution_PartyMonLoop: ; loop over party mons call CalcStats ld a, [wWhichPokemon] ld hl, wPartyMon1 - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld e, l ld d, h push hl push bc - ld bc, wPartyMon1MaxHP - wPartyMon1 + ld bc, MON_MAXHP add hl, bc ld a, [hli] ld b, a @@ -357,7 +357,7 @@ LearnMoveFromLevelUp: ; If it is not 0, this function will not work properly. ld hl, wPartyMon1Moves ld a, [wWhichPokemon] - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes .next ld b, NUM_MOVES @@ -458,7 +458,7 @@ WriteMonMoves: ; shift PP as well if learning moves from day care push de - ld bc, wPartyMon1PP - (wPartyMon1Moves + 3) + ld bc, MON_PP - (MON_MOVES + 3) add hl, bc ld d, h ld e, l @@ -477,7 +477,7 @@ WriteMonMoves: ; write move PP value if learning moves from day care push hl ld a, [hl] - ld hl, wPartyMon1PP - wPartyMon1Moves + ld hl, MON_PP - MON_MOVES add hl, de push hl dec a diff --git a/engine/pokemon/learn_move.asm b/engine/pokemon/learn_move.asm index 62ffeefd..b57fedcd 100644 --- a/engine/pokemon/learn_move.asm +++ b/engine/pokemon/learn_move.asm @@ -10,7 +10,7 @@ LearnMove: DontAbandonLearning: ld hl, wPartyMon1Moves - ld bc, wPartyMon2Moves - wPartyMon1Moves + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wWhichPokemon] call AddNTimes ld d, h @@ -38,7 +38,7 @@ DontAbandonLearning: .next ld a, [wMoveNum] ld [hl], a - ld bc, wPartyMon1PP - wPartyMon1Moves + ld bc, MON_PP - MON_MOVES add hl, bc push hl push de @@ -66,7 +66,7 @@ DontAbandonLearning: ld de, wBattleMonMoves ld bc, NUM_MOVES call CopyData - ld bc, wPartyMon1PP - wPartyMon1OTID + ld bc, MON_PP - MON_OTID add hl, bc ld de, wBattleMonPP ld bc, NUM_MOVES diff --git a/engine/pokemon/load_mon_data.asm b/engine/pokemon/load_mon_data.asm index 7a39f083..d90b9cd8 100644 --- a/engine/pokemon/load_mon_data.asm +++ b/engine/pokemon/load_mon_data.asm @@ -23,7 +23,7 @@ LoadMonData_:: call GetMonHeader ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wMonDataLocation] cp ENEMY_PARTY_DATA jr c, .getMonEntry @@ -33,7 +33,7 @@ LoadMonData_:: cp 2 ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 + ld bc, BOXMON_STRUCT_LENGTH jr z, .getMonEntry ld hl, wDayCareMon @@ -45,5 +45,5 @@ LoadMonData_:: .copyMonData ld de, wLoadedMon - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH jp CopyData diff --git a/engine/pokemon/remove_mon.asm b/engine/pokemon/remove_mon.asm index 60ec8c27..ee47f0c8 100644 --- a/engine/pokemon/remove_mon.asm +++ b/engine/pokemon/remove_mon.asm @@ -2,15 +2,16 @@ _RemovePokemon:: ld hl, wPartyCount ld a, [wRemoveMonFromBox] and a - jr z, .usePartyCount + jr z, .gotCount ld hl, wBoxCount -.usePartyCount +.gotCount ld a, [hl] dec a ld [hli], a + ld a, [wWhichPokemon] ld c, a - ld b, $0 + ld b, 0 add hl, bc ld e, l ld d, h @@ -21,21 +22,27 @@ _RemovePokemon:: ld [hli], a inc a ; reached terminator? jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species + ld hl, wPartyMonOT ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift ld a, [wRemoveMonFromBox] and a - jr z, .usePartyMonOTs + jr z, .gotOTsPointer ld hl, wBoxMonOT ld d, MONS_PER_BOX - 1 -.usePartyMonOTs +.gotOTsPointer ld a, [wWhichPokemon] call SkipFixedLengthTextEntries ld a, [wWhichPokemon] cp d ; are we removing the last pokemon? jr nz, .notRemovingLastMon ; if not, shift the pokemon below - ld [hl], $ff ; else, write the terminator and return + + ; bug: to erase a string, this should be ld [hl], '@' + ; This is not needed, as wBoxSpecies/wPartySpecies determine if a slot is used. + ; Besides, existing mon nick is left untouched + ld [hl], $ff ret + .notRemovingLastMon ld d, h ld e, l @@ -44,44 +51,49 @@ _RemovePokemon:: ld bc, wPartyMonNicks ld a, [wRemoveMonFromBox] and a - jr z, .usePartyMonNicks + jr z, .gotNicksPointer ld bc, wBoxMonNicks -.usePartyMonNicks +.gotNicksPointer call CopyDataUntil + ld hl, wPartyMons - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wRemoveMonFromBox] and a - jr z, .usePartyMonStructs + jr z, .gotMonStructs ld hl, wBoxMons - ld bc, wBoxMon2 - wBoxMon1 -.usePartyMonStructs + ld bc, BOXMON_STRUCT_LENGTH +.gotMonStructs ld a, [wWhichPokemon] call AddNTimes ; get address of the pokemon removed - ld d, h ; store in de for CopyDataUntil + + ld d, h ; de = start address for CopyDataUntil ld e, l ld a, [wRemoveMonFromBox] and a - jr z, .copyUntilPartyMonOTs - ld bc, wBoxMon2 - wBoxMon1 - add hl, bc ; get address of pokemon after the pokemon removed - ld bc, wBoxMonOT ; address of when to stop copying - jr .continue -.copyUntilPartyMonOTs - ld bc, wPartyMon2 - wPartyMon1 - add hl, bc ; get address of pokemon after the pokemon removed - ld bc, wPartyMonOT ; address of when to stop copying -.continue - call CopyDataUntil ; shift all pokemon data after the removed mon to the removed mon's location + jr z, .copyUntilPartyMonOT +; copy until wBoxMonOT + ld bc, BOXMON_STRUCT_LENGTH + add hl, bc ; get address of next slot + ld bc, wBoxMonOT + jr .shiftOTs +.copyUntilPartyMonOT + ld bc, PARTYMON_STRUCT_LENGTH + add hl, bc ; get address of next slot + ld bc, wPartyMonOT +.shiftOTs + call CopyDataUntil ; shift all pokemon data up one slot + ld hl, wPartyMonNicks ld a, [wRemoveMonFromBox] and a - jr z, .usePartyMonNicks2 + jr z, .gotNicksPointer2 ld hl, wBoxMonNicks -.usePartyMonNicks2 +.gotNicksPointer2 ld bc, NAME_LENGTH ld a, [wWhichPokemon] call AddNTimes + ld d, h ld e, l ld bc, NAME_LENGTH @@ -89,7 +101,7 @@ _RemovePokemon:: ld bc, wPartyMonNicksEnd ld a, [wRemoveMonFromBox] and a - jr z, .copyUntilPartyMonNicksEnd + jr z, .shiftMonNicks ld bc, wBoxMonNicksEnd -.copyUntilPartyMonNicksEnd - jp CopyDataUntil +.shiftMonNicks + jp CopyDataUntil ; shift all pokemon nicknames up one slot diff --git a/engine/pokemon/set_types.asm b/engine/pokemon/set_types.asm index 2cf8f14c..d42c3cf3 100644 --- a/engine/pokemon/set_types.asm +++ b/engine/pokemon/set_types.asm @@ -1,7 +1,7 @@ ; updates the types of a party mon (pointed to in hl) to the ones of the mon specified in [wPokedexNum] SetPartyMonTypes: call GetPredefRegisters - ld bc, wPartyMon1Type - wPartyMon1 ; $5 + ld bc, MON_TYPE add hl, bc ld a, [wPokedexNum] ld [wCurSpecies], a diff --git a/engine/pokemon/status_screen.asm b/engine/pokemon/status_screen.asm index 80cdfb17..9c708a22 100644 --- a/engine/pokemon/status_screen.asm +++ b/engine/pokemon/status_screen.asm @@ -361,7 +361,7 @@ StatusScreen2: pop de pop hl push hl - ld bc, wPartyMon1PP - wPartyMon1Moves - 1 + ld bc, MON_PP - MON_MOVES - 1 add hl, bc ld a, [hl] and PP_MASK diff --git a/home/list_menu.asm b/home/list_menu.asm index 00b5704a..d0d3f732 100644 --- a/home/list_menu.asm +++ b/home/list_menu.asm @@ -456,7 +456,7 @@ PrintListMenuEntries:: ld [wLoadedMonLevel], a .skipCopyingLevel pop hl - ld bc, $1c + ld bc, SCREEN_WIDTH + 8 ; 1 row down and 8 columns right add hl, bc call PrintLevel pop af diff --git a/home/move_mon.asm b/home/move_mon.asm index 45b10322..cb19d0e3 100644 --- a/home/move_mon.asm +++ b/home/move_mon.asm @@ -94,7 +94,7 @@ CalcStat:: srl c pop hl push bc - ld bc, wPartyMon1DVs - (wPartyMon1HPExp - 1) ; also wEnemyMonDVs - wEnemyMonHP + ld bc, MON_DVS - (MON_HP_EXP - 1) add hl, bc pop bc ld a, c diff --git a/macros/ram.asm b/macros/ram.asm index 61358434..5f7c5228 100644 --- a/macros/ram.asm +++ b/macros/ram.asm @@ -4,8 +4,6 @@ MACRO? flag_array ds ((\1) + 7) / 8 ENDM -DEF BOX_STRUCT_LENGTH EQU 25 + NUM_MOVES * 2 - MACRO box_struct \1Species:: db \1HP:: dw diff --git a/ram/wram.asm b/ram/wram.asm index 0b00d272..fff7f703 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1212,7 +1212,7 @@ wTrainerPicPointer:: dw ds 1 UNION -wTempMoveNameBuffer:: ds ITEM_NAME_LENGTH + 1 +wTempMoveNameBuffer:: ds MOVE_NAME_LENGTH NEXTU ; The name of the mon that is learning a move. @@ -1274,6 +1274,7 @@ wCriticalHitOrOHKO:: db wMoveMissed:: db +wBattleStatusData:: ; always 0 wPlayerStatsToDouble:: db ; always 0 @@ -1331,6 +1332,7 @@ wPlayerNumHits:: db ENDU ds 2 +wBattleStatusDataEnd:: ; non-zero when an item or move that allows escape from battle was used wEscapedFromBattle:: db @@ -1560,7 +1562,8 @@ wMoves:: ds NUM_MOVES wMoveNum:: db -wMovesString:: ds 56 +; concatenated move name list where intermediate '@' are replaced with '<NEXT>' +wMovesString:: ds NUM_MOVES * MOVE_NAME_LENGTH wUnusedCurMapTilesetCopy:: db diff --git a/scripts/Daycare.asm b/scripts/Daycare.asm index 05b69935..f7354e37 100644 --- a/scripts/Daycare.asm +++ b/scripts/Daycare.asm @@ -173,7 +173,7 @@ DaycareGentlemanText: ld a, [wPartyCount] dec a push af - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH push bc ld hl, wPartyMon1Moves call AddNTimes @@ -190,7 +190,7 @@ DaycareGentlemanText: call AddNTimes ld d, h ld e, l - ld bc, wPartyMon1MaxHP - wPartyMon1HP + ld bc, MON_MAXHP - MON_HP add hl, bc ld a, [hli] ld [de], a diff --git a/scripts/NameRatersHouse.asm b/scripts/NameRatersHouse.asm index 61b10a3e..b1e3bf95 100644 --- a/scripts/NameRatersHouse.asm +++ b/scripts/NameRatersHouse.asm @@ -19,7 +19,7 @@ NameRatersHouseCheckMonOTScript: call .check_match_loop jr c, .no_match ld hl, wPartyMon1OTID - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH ld a, [wWhichPokemon] call AddNTimes ld de, wPlayerID |
