pokecrystal/engine/battle/hidden_power.asm

111 lines
1.2 KiB
NASM
Raw Normal View History

2018-06-24 14:09:41 +00:00
HiddenPowerDamage:
2014-01-05 12:49:35 +00:00
; Override Hidden Power's type and power based on the user's DVs.
2013-08-09 21:42:04 +00:00
2018-01-23 22:39:09 +00:00
ld hl, wBattleMonDVs
2013-08-09 21:42:04 +00:00
ld a, [hBattleTurn]
and a
2014-01-05 12:49:35 +00:00
jr z, .got_dvs
2018-01-23 22:39:09 +00:00
ld hl, wEnemyMonDVs
2014-01-05 12:49:35 +00:00
.got_dvs
2013-08-09 21:42:04 +00:00
; Power:
2014-01-05 12:49:35 +00:00
; Take the top bit from each stat
2013-08-09 21:42:04 +00:00
2014-01-05 12:49:35 +00:00
; Attack
2013-08-09 21:42:04 +00:00
ld a, [hl]
swap a
2018-01-09 22:20:47 +00:00
and %1000
2014-01-05 12:49:35 +00:00
; Defense
2013-08-09 21:42:04 +00:00
ld b, a
ld a, [hli]
2018-01-09 22:20:47 +00:00
and %1000
2013-08-09 21:42:04 +00:00
srl a
or b
2014-01-05 12:49:35 +00:00
; Speed
2013-08-09 21:42:04 +00:00
ld b, a
ld a, [hl]
swap a
2018-01-09 22:20:47 +00:00
and %1000
2013-08-09 21:42:04 +00:00
srl a
srl a
or b
2014-01-05 12:49:35 +00:00
; Special
2013-08-09 21:42:04 +00:00
ld b, a
ld a, [hl]
2018-01-09 22:20:47 +00:00
and %1000
2013-08-09 21:42:04 +00:00
srl a
srl a
srl a
or b
2014-01-05 12:49:35 +00:00
; Multiply by 5
ld b, a
2013-08-09 21:42:04 +00:00
add a
add a
2013-08-09 21:42:04 +00:00
add b
2014-01-05 12:49:35 +00:00
; Add Special & 3
ld b, a
2013-08-09 21:42:04 +00:00
ld a, [hld]
2018-01-09 22:20:47 +00:00
and %0011
2013-08-09 21:42:04 +00:00
add b
2014-01-05 12:49:35 +00:00
; Divide by 2 and add 30 + 1
2013-08-09 21:42:04 +00:00
srl a
add 30
inc a
2014-01-05 12:49:35 +00:00
2013-08-09 21:42:04 +00:00
ld d, a
; Type:
2014-01-05 12:49:35 +00:00
; Def & 3
2013-08-09 21:42:04 +00:00
ld a, [hl]
2018-01-09 22:20:47 +00:00
and %0011
2013-08-09 21:42:04 +00:00
ld b, a
2014-01-05 12:49:35 +00:00
; + (Atk & 3) << 2
2013-08-09 21:42:04 +00:00
ld a, [hl]
2018-01-09 22:20:47 +00:00
and %0011 << 4
2013-08-09 21:42:04 +00:00
swap a
add a
add a
2013-08-09 21:42:04 +00:00
or b
; Skip Normal
inc a
2014-01-05 12:49:35 +00:00
; Skip Bird
cp BIRD
jr c, .done
2013-08-09 21:42:04 +00:00
inc a
2014-01-05 13:24:27 +00:00
; Skip unused types
cp UNUSED_TYPES
2014-01-05 12:49:35 +00:00
jr c, .done
2014-01-05 13:24:27 +00:00
add SPECIAL - UNUSED_TYPES
2013-08-09 21:42:04 +00:00
2014-01-05 12:49:35 +00:00
.done
2013-08-09 21:42:04 +00:00
2014-01-05 12:49:35 +00:00
; Overwrite the current move type.
2013-08-09 21:42:04 +00:00
push af
ld a, BATTLE_VARS_MOVE_TYPE
call GetBattleVarAddr
2013-08-09 21:42:04 +00:00
pop af
ld [hl], a
2014-01-05 12:49:35 +00:00
; Get the rest of the damage formula variables
; based on the new type, but keep base power.
2013-08-09 21:42:04 +00:00
ld a, d
push af
2017-12-24 17:47:30 +00:00
farcall BattleCommand_DamageStats ; damagestats
2013-08-09 21:42:04 +00:00
pop af
ld d, a
ret