summaryrefslogtreecommitdiff
path: root/engine/battle
diff options
context:
space:
mode:
Diffstat (limited to 'engine/battle')
-rwxr-xr-xengine/battle/hidden_power.asm108
-rwxr-xr-xengine/battle/misc.asm219
2 files changed, 327 insertions, 0 deletions
diff --git a/engine/battle/hidden_power.asm b/engine/battle/hidden_power.asm
new file mode 100755
index 00000000..f7abd71f
--- /dev/null
+++ b/engine/battle/hidden_power.asm
@@ -0,0 +1,108 @@
+HiddenPowerDamage:
+; Override Hidden Power's type and power based on the user's DVs.
+
+ ld hl, wBattleMonDVs
+ ldh a, [hBattleTurn]
+ and a
+ jr z, .got_dvs
+ ld hl, wEnemyMonDVs
+.got_dvs
+
+; Power:
+
+; Take the top bit from each stat
+
+ ; Attack
+ ld a, [hl]
+ swap a
+ and %1000
+
+ ; Defense
+ ld b, a
+ ld a, [hli]
+ and %1000
+ srl a
+ or b
+
+ ; Speed
+ ld b, a
+ ld a, [hl]
+ swap a
+ and %1000
+ srl a
+ srl a
+ or b
+
+ ; Special
+ ld b, a
+ ld a, [hl]
+ and %1000
+ srl a
+ srl a
+ srl a
+ or b
+
+; Multiply by 5
+ ld b, a
+ add a
+ add a
+ add b
+
+; Add Special & 3
+ ld b, a
+ ld a, [hld]
+ and %0011
+ add b
+
+; Divide by 2 and add 30 + 1
+ srl a
+ add 30
+ inc a
+
+ ld d, a
+
+; Type:
+
+ ; Def & 3
+ ld a, [hl]
+ and %0011
+ ld b, a
+
+ ; + (Atk & 3) << 2
+ ld a, [hl]
+ and %0011 << 4
+ swap a
+ sla a
+ sla a
+ or b
+
+; Skip Normal
+ inc a
+
+; Skip Bird
+ cp BIRD
+ jr c, .done
+ inc a
+
+; Skip unused types
+ cp UNUSED_TYPES
+ jr c, .done
+ add SPECIAL - UNUSED_TYPES
+
+.done
+
+; Overwrite the current move type.
+ push af
+ ld a, BATTLE_VARS_MOVE_TYPE
+ call GetBattleVarAddr
+ pop af
+ ld [hl], a
+
+; Get the rest of the damage formula variables
+; based on the new type, but keep base power.
+ ld a, d
+ push af
+ farcall BattleCommand_DamageStats ; damagestats
+ pop af
+ ld d, a
+ ret
diff --git a/engine/battle/misc.asm b/engine/battle/misc.asm
new file mode 100755
index 00000000..ae178a4b
--- /dev/null
+++ b/engine/battle/misc.asm
@@ -0,0 +1,219 @@
+_DisappearUser:
+ xor a
+ ldh [hBGMapMode], a
+ ldh a, [hBattleTurn]
+ and a
+ jr z, .player
+ call GetEnemyFrontpicCoords
+ jr .okay
+.player
+ call GetPlayerBackpicCoords
+.okay
+ call ClearBox
+ jr FinishAppearDisappearUser
+
+_AppearUserRaiseSub:
+ farcall BattleCommand_RaiseSubNoAnim
+ jr AppearUser
+
+_AppearUserLowerSub:
+ farcall BattleCommand_LowerSubNoAnim
+
+AppearUser:
+ xor a
+ ldh [hBGMapMode], a
+ ldh a, [hBattleTurn]
+ and a
+ jr z, .player
+ call GetEnemyFrontpicCoords
+ xor a
+ jr .okay
+.player
+ call GetPlayerBackpicCoords
+ ld a, $31
+.okay
+ ldh [hGraphicStartTile], a
+ predef PlaceGraphic
+FinishAppearDisappearUser:
+ ld a, $1
+ ldh [hBGMapMode], a
+ ret
+
+GetEnemyFrontpicCoords:
+ hlcoord 12, 0
+ lb bc, 7, 7
+ ret
+
+GetPlayerBackpicCoords:
+ hlcoord 2, 6
+ lb bc, 6, 6
+ ret
+
+DoWeatherModifiers:
+ ld de, WeatherTypeModifiers
+ ld a, [wBattleWeather]
+ ld b, a
+ ld a, [wCurType]
+ ld c, a
+
+.CheckWeatherType:
+ ld a, [de]
+ inc de
+ cp -1
+ jr z, .done_weather_types
+
+ cp b
+ jr nz, .NextWeatherType
+
+ ld a, [de]
+ cp c
+ jr z, .ApplyModifier
+
+.NextWeatherType:
+ inc de
+ inc de
+ jr .CheckWeatherType
+
+.done_weather_types
+ ld de, WeatherMoveModifiers
+
+ ld a, BATTLE_VARS_MOVE_EFFECT
+ call GetBattleVar
+ ld c, a
+
+.CheckWeatherMove:
+ ld a, [de]
+ inc de
+ cp -1
+ jr z, .done
+
+ cp b
+ jr nz, .NextWeatherMove
+
+ ld a, [de]
+ cp c
+ jr z, .ApplyModifier
+
+.NextWeatherMove:
+ inc de
+ inc de
+ jr .CheckWeatherMove
+
+.ApplyModifier:
+ xor a
+ ldh [hMultiplicand + 0], a
+ ld a, [wCurDamage]
+ ldh [hMultiplicand + 1], a
+ ld a, [wCurDamage + 1]
+ ldh [hMultiplicand + 2], a
+
+ inc de
+ ld a, [de]
+ ldh [hMultiplier], a
+
+ call Multiply
+
+ ld a, 10
+ ldh [hDivisor], a
+ ld b, 4
+ call Divide
+
+ ldh a, [hQuotient + 1]
+ and a
+ ld bc, -1
+ jr nz, .Update
+
+ ldh a, [hQuotient + 2]
+ ld b, a
+ ldh a, [hQuotient + 3]
+ ld c, a
+ or b
+ jr nz, .Update
+
+ ld bc, 1
+
+.Update:
+ ld a, b
+ ld [wCurDamage], a
+ ld a, c
+ ld [wCurDamage + 1], a
+
+.done
+ ret
+
+INCLUDE "data/battle/weather_modifiers.asm"
+
+DoBadgeTypeBoosts:
+ ld a, [wLinkMode]
+ and a
+ ret nz
+
+ ldh a, [hBattleTurn]
+ and a
+ ret nz
+
+ push de
+ push bc
+
+ ld hl, BadgeTypeBoosts
+
+ ld a, [wKantoBadges]
+ ld b, a
+ ld a, [wJohtoBadges]
+ ld c, a
+
+.CheckBadge:
+ ld a, [hl]
+ cp -1
+ jr z, .done
+
+ srl b
+ rr c
+ jr nc, .NextBadge
+
+ ld a, [wCurType]
+ cp [hl]
+ jr z, .ApplyBoost
+
+.NextBadge:
+ inc hl
+ jr .CheckBadge
+
+.ApplyBoost:
+ ld a, [wCurDamage]
+ ld h, a
+ ld d, a
+ ld a, [wCurDamage + 1]
+ ld l, a
+ ld e, a
+
+ srl d
+ rr e
+ srl d
+ rr e
+ srl d
+ rr e
+
+ ld a, e
+ or d
+ jr nz, .done_min
+ ld e, 1
+
+.done_min
+ add hl, de
+ jr nc, .Update
+
+ ld hl, $ffff
+
+.Update:
+ ld a, h
+ ld [wCurDamage], a
+ ld a, l
+ ld [wCurDamage + 1], a
+
+.done
+ pop bc
+ pop de
+ ret
+
+INCLUDE "data/types/badge_type_boosts.asm"