diff options
| author | dannye <33dannye@gmail.com> | 2026-01-17 22:38:33 -0600 |
|---|---|---|
| committer | dannye <33dannye@gmail.com> | 2026-01-17 22:38:33 -0600 |
| commit | bc2354dd6626ce28bb9561547ed2107cfa56c18e (patch) | |
| tree | 5902d4c3389253c76b7c3351e0d7dfecb551c28d /engine/battle/core.asm | |
| parent | Identify characters in `_OakSpeechText2B` and `Printer_GetMonStats.IDNo` (#144) (diff) | |
| parent | Use macros for `WildMonEncounterSlotChances` (#562) (diff) | |
| download | pokeyellow-bc2354dd6626ce28bb9561547ed2107cfa56c18e.tar.gz pokeyellow-bc2354dd6626ce28bb9561547ed2107cfa56c18e.tar.xz pokeyellow-bc2354dd6626ce28bb9561547ed2107cfa56c18e.zip | |
Merge branch 'master' of https://github.com/pret/pokered
Diffstat (limited to 'engine/battle/core.asm')
| -rw-r--r-- | engine/battle/core.asm | 258 |
1 files changed, 64 insertions, 194 deletions
diff --git a/engine/battle/core.asm b/engine/battle/core.asm index a1a989e4..33301e58 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -109,8 +109,8 @@ SlidePlayerAndEnemySilhouettesOnScreen: SlidePlayerHeadLeft: push bc ld hl, wShadowOAMSprite00XCoord - ld c, $15 ; number of OAM entries - ld de, $4 ; size of OAM entry + ld c, 7 * 3 ; number of OAM entries + ld de, OBJ_SIZE .loop dec [hl] ; decrement X dec [hl] ; decrement X @@ -140,7 +140,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 @@ -745,7 +745,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 @@ -885,7 +885,7 @@ AnyEnemyPokemonAliveCheck: ld b, a xor a ld hl, wEnemyMon1HP - ld de, wEnemyMon2 - wEnemyMon1 + ld de, PARTYMON_STRUCT_LENGTH .nextPokemon or [hl] inc hl @@ -1222,17 +1222,17 @@ SlideDownFaintedMonPic: push af set BIT_NO_TEXT_DELAY, a ld [wStatusFlags5], a - ld b, 7 ; number of times to slide + ld b, PIC_HEIGHT ; number of times to slide .slideStepLoop ; each iteration, the mon is slid down one row push bc push de push hl - ld b, 6 ; number of rows + ld b, PIC_HEIGHT - 1 ; number of rows .rowLoop push bc push hl push de - ld bc, $7 + ld bc, PIC_WIDTH call CopyData pop de pop hl @@ -1264,7 +1264,8 @@ SlideDownFaintedMonPic: ret SevenSpacesText: - db " @" + ds PIC_WIDTH, ' ' + db "@" ; slides the player or enemy trainer off screen ; a is the number of tiles to slide it horizontally (always 9 for the player trainer or 8 for the enemy trainer) @@ -1276,7 +1277,7 @@ SlideTrainerPicOffScreen: .slideStepLoop ; each iteration, the trainer pic is slid one tile left/right push bc push hl - ld b, 7 ; number of rows + ld b, PIC_HEIGHT ; number of rows .rowLoop push hl ldh a, [hSlideAmount] @@ -1285,7 +1286,7 @@ SlideTrainerPicOffScreen: ldh a, [hSlideAmount] cp 8 jr z, .slideRight -.slideLeft ; slide player sprite off screen +; slide player sprite left off screen ld a, [hld] ld [hli], a inc hl @@ -1368,7 +1369,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 @@ -1380,7 +1381,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 @@ -1495,7 +1496,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 @@ -1511,7 +1512,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] @@ -1665,16 +1666,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 @@ -1709,16 +1710,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 @@ -1869,17 +1870,17 @@ AnimateRetreatingPlayerMon: call ClearScreenArea ret -; Copies player's current pokemon's current HP and status into the party +; Copies player's current pokemon's current HP, party pos, and status into the party ; struct data so it stays after battle or switching ReadPlayerMonCurHPAndStatus: ld a, [wPlayerMonNumber] ld hl, wPartyMon1HP - ld bc, wPartyMon2 - wPartyMon1 + ld bc, PARTYMON_STRUCT_LENGTH call AddNTimes ld d, h ld e, l ld hl, wBattleMonHP - ld bc, $4 ; 2 bytes HP, 1 byte unknown (unused?), 1 byte status + ld bc, MON_STATUS + 1 - MON_HP ; also copies party pos in-between HP and status jp CopyData DrawHUDsAndHPBars: @@ -2623,7 +2624,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 @@ -2969,12 +2970,12 @@ ENDC .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 @@ -3285,7 +3286,7 @@ PlayerCanExecuteChargingMove: ; resulting in the Pokemon being invulnerable for the whole battle res INVULNERABLE, [hl] PlayerCanExecuteMove: - call PrintMonName1Text + call DisplayUsedMoveText ld hl, DecrementPP ld de, wPlayerSelectedMove ; pointer to the move just used ld b, BANK(DecrementPP) @@ -3621,7 +3622,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 @@ -3727,11 +3728,12 @@ CheckPlayerStatusConditions: ld hl, AttackContinuesText call PrintText ld a, [wPlayerNumAttacksLeft] - dec a ; did multi-turn move end? + dec a ld [wPlayerNumAttacksLeft], a - ld hl, GetPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), - ; DecrementPP and MoveHitTest - jp nz, .returnToHL + ld hl, GetPlayerAnimationType ; skip damage calculation (deal damage equal to last hit), + ; DecrementPP and MoveHitTest + jp nz, .returnToHL ; redundant leftover code, the case wEnemyNumAttacksLeft == 0 + ; is handled within CheckNumAttacksLeft jp .returnToHL .RageCheck @@ -3796,7 +3798,7 @@ ConfusedNoMoreText: text_far _ConfusedNoMoreText text_end -SavingEnergyText: +SavingEnergyText: ; unreferenced text_far _SavingEnergyText text_end @@ -3882,139 +3884,7 @@ HandleSelfConfusionDamage: ldh [hWhoseTurn], a jp ApplyDamageToPlayerPokemon -PrintMonName1Text: - ld hl, MonName1Text - jp PrintText - -; this function wastes time calling DetermineExclamationPointTextNum -; and choosing between Used1Text and Used2Text, even though -; those text strings are identical and both continue at PrintInsteadText -; this likely had to do with Japanese grammar that got translated, -; but the functionality didn't get removed -MonName1Text: - text_far _MonName1Text - text_asm - ldh a, [hWhoseTurn] - and a - ld a, [wPlayerMoveNum] - ld hl, wPlayerUsedMove - jr z, .playerTurn - ld a, [wEnemyMoveNum] - ld hl, wEnemyUsedMove -.playerTurn - ld [hl], a - ld [wMoveGrammar], a - call DetermineExclamationPointTextNum - ld a, [wMonIsDisobedient] - and a - ld hl, Used2Text - ret nz - ld a, [wMoveGrammar] - cp 3 - ld hl, Used2Text - ret c - ld hl, Used1Text - ret - -Used1Text: - text_far _Used1Text - text_asm - jr PrintInsteadText - -Used2Text: - text_far _Used2Text - text_asm - ; fall through - -PrintInsteadText: - ld a, [wMonIsDisobedient] - and a - jr z, PrintMoveName - ld hl, InsteadText - ret - -InsteadText: - text_far _InsteadText - text_asm - ; fall through - -PrintMoveName: - ld hl, _PrintMoveName - ret - -_PrintMoveName: - text_far _MoveNameText - text_asm - ld hl, ExclamationPointPointerTable - ld a, [wMoveGrammar] - add a - push bc - ld b, $0 - ld c, a - add hl, bc - pop bc - ld a, [hli] - ld h, [hl] - ld l, a - ret - -ExclamationPointPointerTable: - dw ExclamationPoint1Text - dw ExclamationPoint2Text - dw ExclamationPoint3Text - dw ExclamationPoint4Text - dw ExclamationPoint5Text - -ExclamationPoint1Text: - text_far _ExclamationPoint1Text - text_end - -ExclamationPoint2Text: - text_far _ExclamationPoint2Text - text_end - -ExclamationPoint3Text: - text_far _ExclamationPoint3Text - text_end - -ExclamationPoint4Text: - text_far _ExclamationPoint4Text - text_end - -ExclamationPoint5Text: - text_far _ExclamationPoint5Text - text_end - -; this function does nothing useful -; if the move being used is in set [1-4] from ExclamationPointMoveSets, -; use ExclamationPoint[1-4]Text -; otherwise, use ExclamationPoint5Text -; but all five text strings are identical -; this likely had to do with Japanese grammar that got translated, -; but the functionality didn't get removed -DetermineExclamationPointTextNum: - push bc - ld a, [wMoveGrammar] ; move ID - ld c, a - ld b, $0 - ld hl, ExclamationPointMoveSets -.loop - ld a, [hli] - cp $ff - jr z, .done - cp c - jr z, .done - and a - jr nz, .loop - inc b - jr .loop -.done - ld a, b - ld [wMoveGrammar], a - pop bc - ret - -INCLUDE "data/moves/grammar.asm" +INCLUDE "engine/battle/used_move_text.asm" PrintMoveFailureText: ld de, wPlayerMoveEffect @@ -4140,7 +4010,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] @@ -4341,7 +4211,7 @@ GetDamageVarsForPlayerAttack: ld a, [hl] ; a = [wPlayerMoveType] cp SPECIAL ; types >= SPECIAL are all special jr nc, .specialAttack -.physicalAttack +; physical attack ld hl, wEnemyMonDefense ld a, [hli] ld b, a @@ -4367,7 +4237,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 @@ -4399,7 +4269,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 @@ -4454,7 +4324,7 @@ GetDamageVarsForEnemyAttack: ld a, [hl] ; a = [wEnemyMoveType] cp SPECIAL ; types >= SPECIAL are all special jr nc, .specialAttack -.physicalAttack +; physical attack ld hl, wBattleMonDefense ld a, [hli] ld b, a @@ -4473,7 +4343,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 @@ -4505,7 +4375,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 @@ -4568,7 +4438,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 @@ -5367,7 +5237,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 @@ -5471,7 +5341,6 @@ AdjustDamageForMoveType: ld [hl], a or b ; is damage 0? jr nz, .skipTypeImmunity -.typeImmunity ; if damage is 0, make the move miss ; this only occurs if a move that would do 2 or 3 damage is 0.25x effective against the target inc a @@ -5575,7 +5444,7 @@ MoveHitTest: ldh a, [hWhoseTurn] and a jr nz, .enemyTurn -.playerTurn +; player's turn ; this checks if the move effect is disallowed by mist ld a, [wPlayerMoveEffect] cp ATTACK_DOWN1_EFFECT @@ -5647,12 +5516,12 @@ MoveHitTest: ld [wMoveMissed], a ldh a, [hWhoseTurn] and a - jr z, .playerTurn2 -.enemyTurn2 + jr z, .playerTurn +; enemy's turn ld hl, wEnemyBattleStatus1 res USING_TRAPPING_MOVE, [hl] ; end multi-turn attack e.g. wrap ret -.playerTurn2 +.playerTurn ld hl, wPlayerBattleStatus1 res USING_TRAPPING_MOVE, [hl] ; end multi-turn attack e.g. wrap ret @@ -5823,7 +5692,7 @@ EnemyCanExecuteChargingMove: EnemyCanExecuteMove: xor a ld [wMonIsDisobedient], a - call PrintMonName1Text + call DisplayUsedMoveText ld a, [wEnemyMoveEffect] ld hl, ResidualEffects1 ld de, $1 @@ -6244,10 +6113,11 @@ CheckEnemyStatusConditions: ld hl, AttackContinuesText call PrintText ld hl, wEnemyNumAttacksLeft - dec [hl] ; did multi-turn move end? - ld hl, GetEnemyAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), + dec [hl] + ld hl, GetEnemyAnimationType ; skip damage calculation (deal damage equal to last hit), ; DecrementPP and MoveHitTest - jp nz, .enemyReturnToHL + jp nz, .enemyReturnToHL ; redundant leftover code, the case wEnemyNumAttacksLeft == 0 + ; is handled within CheckNumAttacksLeft jp .enemyReturnToHL .checkIfUsingRage ld a, [wEnemyBattleStatus2] @@ -6387,7 +6257,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 @@ -6538,7 +6408,7 @@ LoadPlayerBackPic: ld [hl], d ; OAM Y inc hl ld [hl], e ; OAM X - ld a, $8 ; height of tile + ld a, TILE_HEIGHT add d ; increase Y by height of tile ld d, a inc hl @@ -6554,7 +6424,7 @@ LoadPlayerBackPic: ldh a, [hOAMTile] add $4 ; increase tile number by 4 ldh [hOAMTile], a - ld a, $8 ; width of tile + ld a, TILE_WIDTH add e ; increase X by width of tile ld e, a dec b @@ -6567,7 +6437,7 @@ LoadPlayerBackPic: ld de, sSpriteBuffer1 ldh a, [hLoadedROMBank] ld b, a - ld c, 7 * 7 + ld c, PIC_SIZE call CopyVideoData call CloseSRAM ld a, $31 @@ -6599,7 +6469,7 @@ QuarterSpeedDueToParalysis: ldh a, [hWhoseTurn] and a jr z, .playerTurn -.enemyTurn ; quarter the player's speed +; enemy's turn, quarter the player's speed ld a, [wBattleMonStatus] and 1 << PAR ret z ; return if player not paralysed @@ -6642,7 +6512,7 @@ HalveAttackDueToBurn: ldh a, [hWhoseTurn] and a jr z, .playerTurn -.enemyTurn ; halve the player's attack +; enemy's turn, halve the player's attack ld a, [wBattleMonStatus] and 1 << BRN ret z ; return if player not burnt @@ -6826,7 +6696,7 @@ LoadHudTilePatterns: ldh a, [rLCDC] add a ; is LCD disabled? jr c, .lcdEnabled -.lcdDisabled +; LCD disabled ld hl, BattleHudTiles1 ld de, vChars2 tile $6d ld bc, BattleHudTiles1End - BattleHudTiles1 @@ -6840,11 +6710,11 @@ LoadHudTilePatterns: .lcdEnabled ld de, BattleHudTiles1 ld hl, vChars2 tile $6d - lb bc, BANK(BattleHudTiles1), (BattleHudTiles1End - BattleHudTiles1) / $8 + lb bc, BANK(BattleHudTiles1), (BattleHudTiles1End - BattleHudTiles1) / TILE_1BPP_SIZE call CopyVideoDataDouble ld de, BattleHudTiles2 ld hl, vChars2 tile $73 - lb bc, BANK(BattleHudTiles2), (BattleHudTiles3End - BattleHudTiles2) / $8 + lb bc, BANK(BattleHudTiles2), (BattleHudTiles3End - BattleHudTiles2) / TILE_1BPP_SIZE jp CopyVideoDataDouble PrintEmptyString: |
