Use some more constants in place of raw numbers

This commit is contained in:
Rangi42 2023-11-21 20:15:30 -05:00
parent 465b859c4c
commit d4e7a39dd8
2 changed files with 23 additions and 18 deletions

View file

@ -1,15 +1,20 @@
DEF MAX_LEVEL EQU 100 DEF MAX_LEVEL EQU 100
; maximum moves known per mon
DEF NUM_MOVES EQU 4 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) ; VitaminStats indexes (see data/battle/stat_names.asm)
const_def const_def 1
const STAT_HEALTH const STAT_HEALTH
const STAT_ATTACK const STAT_ATTACK
const STAT_DEFENSE const STAT_DEFENSE
const STAT_SPEED const STAT_SPEED
const STAT_SPECIAL 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) ; StatModTextStrings indexes (see data/battle/stat_mod_names.asm)
const_def const_def

View file

@ -18,7 +18,7 @@ SlidePlayerAndEnemySilhouettesOnScreen:
call LoadFontTilePatterns call LoadFontTilePatterns
call LoadHudAndHpBarAndStatusTilePatterns call LoadHudAndHpBarAndStatusTilePatterns
ld hl, vBGMap0 ld hl, vBGMap0
ld bc, $400 ld bc, BG_MAP_WIDTH * BG_MAP_HEIGHT
.clearBackgroundLoop .clearBackgroundLoop
ld a, " " ld a, " "
ld [hli], a ld [hli], a
@ -29,9 +29,9 @@ SlidePlayerAndEnemySilhouettesOnScreen:
; copy the work RAM tile map to VRAM ; copy the work RAM tile map to VRAM
hlcoord 0, 0 hlcoord 0, 0
ld de, vBGMap0 ld de, vBGMap0
ld b, 18 ; number of rows ld b, SCREEN_HEIGHT
.copyRowLoop .copyRowLoop
ld c, 20 ; number of columns ld c, SCREEN_WIDTH
.copyColumnLoop .copyColumnLoop
ld a, [hli] ld a, [hli]
ld [de], a ld [de], a
@ -825,7 +825,7 @@ FaintEnemyPokemon:
; the enemy mon base stats are added to stat exp, so they are halved ; the enemy mon base stats are added to stat exp, so they are halved
; the base exp (which determines normal exp) is also halved ; the base exp (which determines normal exp) is also halved
ld hl, wEnemyMonBaseStats ld hl, wEnemyMonBaseStats
ld b, $7 ld b, NUM_STATS + 2
.halveExpDataLoop .halveExpDataLoop
srl [hl] srl [hl]
inc hl inc hl
@ -1259,7 +1259,7 @@ SlideTrainerPicOffScreen:
dec c dec c
jr nz, .columnLoop jr nz, .columnLoop
pop hl pop hl
ld de, 20 ld de, SCREEN_WIDTH
add hl, de add hl, de
dec b dec b
jr nz, .rowLoop jr nz, .rowLoop
@ -4183,7 +4183,7 @@ GetDamageVarsForPlayerAttack:
and a ; check for critical hit and a ; check for critical hit
jr z, .scaleStats jr z, .scaleStats
; in the case of a critical hit, reset the player's attack and the enemy's defense to their base values ; 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 call GetEnemyMonStat
ldh a, [hProduct + 2] ldh a, [hProduct + 2]
ld b, a ld b, a
@ -4215,7 +4215,7 @@ GetDamageVarsForPlayerAttack:
and a ; check for critical hit and a ; check for critical hit
jr z, .scaleStats jr z, .scaleStats
; in the case of a critical hit, reset the player's and enemy's specials to their base values ; 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 call GetEnemyMonStat
ldh a, [hProduct + 2] ldh a, [hProduct + 2]
ld b, a ld b, a
@ -4304,7 +4304,7 @@ GetDamageVarsForEnemyAttack:
ld b, a ld b, a
ld c, [hl] ld c, [hl]
push bc push bc
ld c, 2 ; attack stat ld c, STAT_ATTACK
call GetEnemyMonStat call GetEnemyMonStat
ld hl, hProduct + 2 ld hl, hProduct + 2
pop bc pop bc
@ -4336,7 +4336,7 @@ GetDamageVarsForEnemyAttack:
ld b, a ld b, a
ld c, [hl] ld c, [hl]
push bc push bc
ld c, 5 ; special stat ld c, STAT_SPECIAL
call GetEnemyMonStat call GetEnemyMonStat
ld hl, hProduct + 2 ld hl, hProduct + 2
pop bc pop bc
@ -4380,7 +4380,7 @@ GetDamageVarsForEnemyAttack:
ret ret
; get stat c of enemy mon ; 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: GetEnemyMonStat:
push de push de
push bc push bc
@ -5287,7 +5287,7 @@ AdjustDamageForMoveType:
call Multiply call Multiply
ld a, 10 ld a, 10
ldh [hDivisor], a ldh [hDivisor], a
ld b, $04 ld b, 4
call Divide call Divide
ldh a, [hQuotient + 2] ldh a, [hQuotient + 2]
ld [hli], a ld [hli], a
@ -5315,7 +5315,6 @@ AdjustDamageForMoveType:
; this doesn't take into account the effects that dual types can have ; this doesn't take into account the effects that dual types can have
; (e.g. 4x weakness / resistance, weaknesses and resistances canceling) ; (e.g. 4x weakness / resistance, weaknesses and resistances canceling)
; the result is stored in [wTypeEffectiveness] ; 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 ; as far is can tell, this is only used once in some AI code to help decide which move to use
AIGetTypeEffectiveness: AIGetTypeEffectiveness:
ld a, [wEnemyMoveType] ld a, [wEnemyMoveType]
@ -5324,8 +5323,10 @@ AIGetTypeEffectiveness:
ld b, [hl] ; b = type 1 of player's pokemon ld b, [hl] ; b = type 1 of player's pokemon
inc hl inc hl
ld c, [hl] ; c = type 2 of player's pokemon ld c, [hl] ; c = type 2 of player's pokemon
ld a, $10 ; initialize to neutral effectiveness
ld [wTypeEffectiveness], a ; 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 ld hl, TypeEffects
.loop .loop
ld a, [hli] ld a, [hli]
@ -6909,7 +6910,6 @@ _InitBattleCommon:
db "@" db "@"
_LoadTrainerPic: _LoadTrainerPic:
; wd033-wd034 contain pointer to pic
ld a, [wTrainerPicPointer] ld a, [wTrainerPicPointer]
ld e, a ld e, a
ld a, [wTrainerPicPointer + 1] ld a, [wTrainerPicPointer + 1]
@ -7043,7 +7043,7 @@ LoadMonBackPic:
call InterlaceMergeSpriteBuffers ; combine the two buffers to a single 2bpp sprite call InterlaceMergeSpriteBuffers ; combine the two buffers to a single 2bpp sprite
ld hl, vSprites ld hl, vSprites
ld de, vBackPic 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] ldh a, [hLoadedROMBank]
ld b, a ld b, a
jp CopyVideoData jp CopyVideoData