From d4e7a39dd89a32c7af13fed31b3178cc769fb797 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Tue, 21 Nov 2023 20:15:30 -0500 Subject: [PATCH] Use some more constants in place of raw numbers --- constants/battle_constants.asm | 9 +++++++-- engine/battle/core.asm | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/constants/battle_constants.asm b/constants/battle_constants.asm index 2ae1cdef..44a85e8d 100644 --- a/constants/battle_constants.asm +++ b/constants/battle_constants.asm @@ -1,15 +1,20 @@ DEF MAX_LEVEL EQU 100 +; maximum moves known per mon DEF NUM_MOVES EQU 4 +; significant stat values +DEF BASE_STAT_LEVEL EQU 7 +DEF MAX_STAT_LEVEL EQU 13 + ; VitaminStats indexes (see data/battle/stat_names.asm) - const_def + const_def 1 const STAT_HEALTH const STAT_ATTACK const STAT_DEFENSE const STAT_SPEED const STAT_SPECIAL -DEF NUM_STATS EQU const_value +DEF NUM_STATS EQU const_value - 1 ; StatModTextStrings indexes (see data/battle/stat_mod_names.asm) const_def diff --git a/engine/battle/core.asm b/engine/battle/core.asm index ed2c4b7a..b93b6fa7 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -18,7 +18,7 @@ SlidePlayerAndEnemySilhouettesOnScreen: call LoadFontTilePatterns call LoadHudAndHpBarAndStatusTilePatterns ld hl, vBGMap0 - ld bc, $400 + ld bc, BG_MAP_WIDTH * BG_MAP_HEIGHT .clearBackgroundLoop ld a, " " ld [hli], a @@ -29,9 +29,9 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; copy the work RAM tile map to VRAM hlcoord 0, 0 ld de, vBGMap0 - ld b, 18 ; number of rows + ld b, SCREEN_HEIGHT .copyRowLoop - ld c, 20 ; number of columns + ld c, SCREEN_WIDTH .copyColumnLoop ld a, [hli] ld [de], a @@ -825,7 +825,7 @@ FaintEnemyPokemon: ; the enemy mon base stats are added to stat exp, so they are halved ; the base exp (which determines normal exp) is also halved ld hl, wEnemyMonBaseStats - ld b, $7 + ld b, NUM_STATS + 2 .halveExpDataLoop srl [hl] inc hl @@ -1259,7 +1259,7 @@ SlideTrainerPicOffScreen: dec c jr nz, .columnLoop pop hl - ld de, 20 + ld de, SCREEN_WIDTH add hl, de dec b jr nz, .rowLoop @@ -4183,7 +4183,7 @@ GetDamageVarsForPlayerAttack: and a ; check for critical hit jr z, .scaleStats ; in the case of a critical hit, reset the player's attack and the enemy's defense to their base values - ld c, 3 ; defense stat + ld c, STAT_DEFENSE call GetEnemyMonStat ldh a, [hProduct + 2] ld b, a @@ -4215,7 +4215,7 @@ GetDamageVarsForPlayerAttack: and a ; check for critical hit jr z, .scaleStats ; in the case of a critical hit, reset the player's and enemy's specials to their base values - ld c, 5 ; special stat + ld c, STAT_SPECIAL call GetEnemyMonStat ldh a, [hProduct + 2] ld b, a @@ -4304,7 +4304,7 @@ GetDamageVarsForEnemyAttack: ld b, a ld c, [hl] push bc - ld c, 2 ; attack stat + ld c, STAT_ATTACK call GetEnemyMonStat ld hl, hProduct + 2 pop bc @@ -4336,7 +4336,7 @@ GetDamageVarsForEnemyAttack: ld b, a ld c, [hl] push bc - ld c, 5 ; special stat + ld c, STAT_SPECIAL call GetEnemyMonStat ld hl, hProduct + 2 pop bc @@ -4380,7 +4380,7 @@ GetDamageVarsForEnemyAttack: ret ; get stat c of enemy mon -; c: stat to get (HP=1,Attack=2,Defense=3,Speed=4,Special=5) +; c: stat to get (STAT_* constant) GetEnemyMonStat: push de push bc @@ -5287,7 +5287,7 @@ AdjustDamageForMoveType: call Multiply ld a, 10 ldh [hDivisor], a - ld b, $04 + ld b, 4 call Divide ldh a, [hQuotient + 2] ld [hli], a @@ -5315,7 +5315,6 @@ AdjustDamageForMoveType: ; this doesn't take into account the effects that dual types can have ; (e.g. 4x weakness / resistance, weaknesses and resistances canceling) ; the result is stored in [wTypeEffectiveness] -; ($05 is not very effective, $10 is neutral, $14 is super effective) ; as far is can tell, this is only used once in some AI code to help decide which move to use AIGetTypeEffectiveness: ld a, [wEnemyMoveType] @@ -5324,8 +5323,10 @@ AIGetTypeEffectiveness: ld b, [hl] ; b = type 1 of player's pokemon inc hl ld c, [hl] ; c = type 2 of player's pokemon - ld a, $10 - ld [wTypeEffectiveness], a ; initialize to neutral effectiveness + ; initialize to neutral effectiveness + ; bug: this is $10 (MORE_EFFECTIVE + 1) but should be 10 (EFFECTIVE) + ld a, MORE_EFFECTIVE + 1 + ld [wTypeEffectiveness], a ld hl, TypeEffects .loop ld a, [hli] @@ -6909,7 +6910,6 @@ _InitBattleCommon: db "@" _LoadTrainerPic: -; wd033-wd034 contain pointer to pic ld a, [wTrainerPicPointer] ld e, a ld a, [wTrainerPicPointer + 1] @@ -7043,7 +7043,7 @@ LoadMonBackPic: call InterlaceMergeSpriteBuffers ; combine the two buffers to a single 2bpp sprite ld hl, vSprites ld de, vBackPic - ld c, (2*SPRITEBUFFERSIZE)/16 ; count of 16-byte chunks to be copied + ld c, (2 * SPRITEBUFFERSIZE) / 16 ; count of 16-byte chunks to be copied ldh a, [hLoadedROMBank] ld b, a jp CopyVideoData