Skip to content

Commit

Permalink
Use some more constants in place of raw numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Nov 22, 2023
1 parent 465b859 commit d4e7a39
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
9 changes: 7 additions & 2 deletions 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
Expand Down
32 changes: 16 additions & 16 deletions engine/battle/core.asm
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -6909,7 +6910,6 @@ _InitBattleCommon:
db "@"

_LoadTrainerPic:
; wd033-wd034 contain pointer to pic
ld a, [wTrainerPicPointer]
ld e, a
ld a, [wTrainerPicPointer + 1]
Expand Down Expand Up @@ -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

0 comments on commit d4e7a39

Please sign in to comment.