shithub: pokecrystal

Download patch

ref: 8ae709be9f74cd194ac1d0a8a1d95f6afb4c6439
parent: eab37ef9200e79fd6b97588c784835a74d53c901
author: yenatch <[email protected]>
date: Thu Jun 13 12:10:39 EDT 2013

comment statdown move command

--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -130,7 +130,7 @@
 
 	xor a
 	ld [AttackMissed], a
-	ld [$c70d], a
+	ld [EffectFailed], a
 	ld [$c689], a
 	ld [AlreadyDisobeyed], a
 	ld [AlreadyFailed], a
@@ -2689,7 +2689,7 @@
 ; effectchance
 
 	xor a
-	ld [$c70d], a
+	ld [EffectFailed], a
 	call CheckSubstituteOpp
 	jr nz, .failed
 
@@ -2708,7 +2708,7 @@
 
 .failed
 	ld a, 1
-	ld [$c70d], a
+	ld [EffectFailed], a
 	and a
 	ret
 ; 34eee
@@ -3467,7 +3467,7 @@
 	ld a, [hli]
 	ld b, a
 	ld c, [hl]
-	ld hl, $c6b6
+	ld hl, PlayerStats
 	jr .thickclub
 
 
@@ -3728,7 +3728,7 @@
 	ld a, [hli]
 	ld b, a
 	ld c, [hl]
-	ld hl, $c6c1
+	ld hl, EnemyStats
 	jr .thickclub
 
 
@@ -5653,7 +5653,7 @@
 	ld a, b
 	cp $14
 	ret z
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	ret nz
 	call Function0x37962
@@ -5922,7 +5922,7 @@
 	ld a, b
 	cp $15
 	ret z
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	ret nz
 	call Function0x37962
@@ -5997,7 +5997,7 @@
 	ld a, b
 	cp $16
 	ret z
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	ret nz
 	call Function0x37962
@@ -6048,7 +6048,7 @@
 	ld a, b
 	cp $18
 	ret z
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	ret nz
 	call Function0x37962
@@ -6127,7 +6127,7 @@
 BattleCommand1c: ; 361e4
 ; statup
 	call Function0x361ef
-	ld a, [$c70e]
+	ld a, [FailedMessage]
 	and a
 	ret nz
 	jp Function0x36281
@@ -6136,7 +6136,7 @@
 
 Function0x361ef: ; 361ef
 	ld a, b
-	ld [$c70c], a
+	ld [LoweredStat], a
 	ld hl, PlayerStatLevels
 	ld a, [hBattleTurn]
 	and a
@@ -6146,10 +6146,10 @@
 	ld a, [AttackMissed]
 	and a
 	jp nz, Function0x3627b
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	jp nz, Function0x3627b
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f
 	ld c, a
 	ld b, $0
@@ -6159,7 +6159,7 @@
 	ld a, $d
 	cp b
 	jp c, Function0x36270
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f0
 	jr z, .asm_3622b ; 0x36222 $7
 	inc b
@@ -6174,12 +6174,12 @@
 	cp $5
 	jr nc, .asm_36268 ; 0x36230 $36
 	ld hl, $c641
-	ld de, $c6b6
+	ld de, PlayerStats
 	ld a, [hBattleTurn]
 	and a
 	jr z, .asm_36243 ; 0x3623b $6
 	ld hl, $d21b
-	ld de, $c6c1
+	ld de, EnemyStats
 .asm_36243
 	push bc
 	sla c
@@ -6209,7 +6209,7 @@
 .asm_36268
 	pop hl
 	xor a
-	ld [$c70e], a
+	ld [FailedMessage], a
 	ret
 ; 3626e
 
@@ -6223,7 +6223,7 @@
 
 Function0x36270: ; 36270
 	ld a, $2
-	ld [$c70e], a
+	ld [FailedMessage], a
 	ld a, $1
 	ld [AttackMissed], a
 	ret
@@ -6232,7 +6232,7 @@
 
 Function0x3627b: ; 3627b
 	ld a, $1
-	ld [$c70e], a
+	ld [FailedMessage], a
 	ret
 ; 36281
 
@@ -6320,100 +6320,123 @@
 
 BattleCommand1d: ; 362e3
 ; statdown
-	ld [$c70c], a
+
+	ld [LoweredStat], a
+
 	call Function0x36391
-	jp nz, Function0x36386
+	jp nz, .Mist
+
 	ld hl, EnemyStatLevels
 	ld a, [hBattleTurn]
 	and a
-	jr z, .asm_362f7 ; 362f2 $3
+	jr z, .GetStatLevel
 	ld hl, PlayerStatLevels
-.asm_362f7
-	ld a, [$c70c]
+
+.GetStatLevel
+; Attempt to lower the stat.
+	ld a, [LoweredStat]
 	and $f
 	ld c, a
-	ld b, $0
+	ld b, 0
 	add hl, bc
 	ld b, [hl]
 	dec b
-	jp z, .asm_36372
-	ld a, [$c70c]
+	jp z, .CantLower
+
+; Sharply lower the stat if applicable.
+	ld a, [LoweredStat]
 	and $f0
-	jr z, .asm_36310 ; 3630a $4
+	jr z, .ComputerMiss
 	dec b
-	jr nz, .asm_36310 ; 3630d $1
+	jr nz, .ComputerMiss
 	inc b
-.asm_36310
+
+.ComputerMiss
+; Computer opponents have a 1/4 chance of failing.
 	ld a, [hBattleTurn]
 	and a
-	jr z, .asm_36338 ; 36313 $23
+	jr z, .DidntMiss
 	ld a, [InLinkBattle]
 	and a
-	jr nz, .asm_36338 ; 36319 $1d
+	jr nz, .DidntMiss
+
 	ld a, [$cfc0]
 	and a
-	jr nz, .asm_36338 ; 3631f $17
+	jr nz, .DidntMiss
+
+; Lock-On still always works.
 	ld a, [PlayerSubStatus5]
-	bit 5, a
-	jr nz, .asm_36338 ; 36326 $10
+	bit SUBSTATUS_LOCK_ON, a
+	jr nz, .DidntMiss
+
+; Attacking moves that also lower accuracy are unaffected.
 	ld a, BATTLE_VARS_MOVE_EFFECT
 	call CleanGetBattleVarPair
-	cp $49
-	jr z, .asm_36338 ; 3632f $7
+	cp EFFECT_ACCURACY_DOWN_HIT
+	jr z, .DidntMiss
+
 	call FarBattleRNG
 	cp $40
-	jr c, .asm_3637d ; 36336 $45
-.asm_36338
+	jr c, .Failed
+
+.DidntMiss
 	call CheckSubstituteOpp
-	jr nz, .asm_3637d ; 3633b $40
+	jr nz, .Failed
+
 	ld a, [AttackMissed]
 	and a
-	jr nz, .asm_3637d ; 36341 $3a
-	ld a, [$c70d]
+	jr nz, .Failed
+
+	ld a, [EffectFailed]
 	and a
-	jr nz, .asm_3637d ; 36347 $34
+	jr nz, .Failed
+
 	call CheckHiddenOpponent
-	jr nz, .asm_3637d ; 3634c $2f
+	jr nz, .Failed
+
+; Accuracy/Evasion reduction don't involve stats.
 	ld [hl], b
 	ld a, c
-	cp $5
-	jr nc, .asm_3636c ; 36352 $18
+	cp ACCURACY
+	jr nc, .Hit
+
 	push hl
-	ld hl, $d21b
-	ld de, $c6c1
+	ld hl, EnemyMonAtk + 1
+	ld de, EnemyStats
 	ld a, [hBattleTurn]
 	and a
-	jr z, .asm_36366 ; 3635e $6
-	ld hl, $c641
-	ld de, $c6b6
+	jr z, .asm_36366
+	ld hl, BattleMonAtk + 1
+	ld de, PlayerStats
 .asm_36366
 	call Function0x3641a
 	pop hl
-	jr z, .asm_36371 ; 3636a $5
-.asm_3636c
+	jr z, .CouldntLower
+
+.Hit
 	xor a
-	ld [$c70e], a
+	ld [FailedMessage], a
 	ret
-.asm_36371
+
+.CouldntLower
 	inc [hl]
-.asm_36372
-	ld a, $3
-	ld [$c70e], a
-	ld a, $1
+.CantLower
+	ld a, 3
+	ld [FailedMessage], a
+	ld a, 1
 	ld [AttackMissed], a
 	ret
-.asm_3637d
-	ld a, $1
-	ld [$c70e], a
+
+.Failed
+	ld a, 1
+	ld [FailedMessage], a
 	ld [AttackMissed], a
 	ret
-; 36386
 
-
-Function0x36386: ; 36386
-	ld a, $2
-	ld [$c70e], a
-	ld a, $1
+.Mist
+	ld a, 2
+	ld [FailedMessage], a
+	ld a, 1
 	ld [AttackMissed], a
 	ret
 ; 36391
@@ -6446,10 +6469,10 @@
 
 
 BattleCommand8c: ; 363b8
-	ld a, [$c70e]
+	ld a, [FailedMessage]
 	and a
 	ret nz
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f
 	ld b, a
 	inc b
@@ -6462,7 +6485,7 @@
 	start_asm
 
 	ld hl, .up
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f0
 	ret z
 	ld hl, .wayup
@@ -6480,10 +6503,10 @@
 
 
 BattleCommand8d: ; 363e9
-	ld a, [$c70e]
+	ld a, [FailedMessage]
 	and a
 	ret nz
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f
 	ld b, a
 	inc b
@@ -6496,7 +6519,7 @@
 	start_asm
 
 	ld hl, .fell
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f0
 	ret z
 	ld hl, .sharplyfell
@@ -6513,12 +6536,13 @@
 
 
 Function0x3641a: ; 3641a
-; selfdestruct
+; Lower stat c from stat struct hl (buffer de).
 
 	push bc
 	sla c
 	ld b, 0
 	add hl, bc
+	; add de, c
 	ld a, c
 	add e
 	ld e, a
@@ -6525,8 +6549,9 @@
 	jr nc, .asm_36426
 	inc d
 .asm_36426
-
 	pop bc
+
+; The lowest possible stat is 1.
 	ld a, [hld]
 	sub 1
 	jr nz, .asm_3642f
@@ -6537,21 +6562,19 @@
 .asm_3642f
 	ld a, [hBattleTurn]
 	and a
-	jr z, .asm_3643f
+	jr z, .Player
 
 	call SwitchTurn
 	call Function0x365d7
 	call SwitchTurn
+	jr .end
 
-	jr .asm_36448
-
-.asm_3643f
+.Player
 	call SwitchTurn
 	call Function0x365fd
 	call SwitchTurn
-
-.asm_36448
-	ld a, $1
+.end
+	ld a, 1
 	and a
 	ret
 ; 3644c
@@ -6559,7 +6582,7 @@
 
 BattleCommand8e: ; 3644c
 ; statupfailtext
-	ld a, [$c70e]
+	ld a, [FailedMessage]
 	and a
 	ret z
 	push af
@@ -6567,7 +6590,7 @@
 	pop af
 	dec a
 	jp z, TryPrintButItFailed
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f
 	ld b, a
 	inc b
@@ -6579,7 +6602,7 @@
 
 BattleCommand8f: ; 3646a
 ; statdownfailtext
-	ld a, [$c70e]
+	ld a, [FailedMessage]
 	and a
 	ret z
 	push af
@@ -6590,7 +6613,7 @@
 	dec a
 	ld hl, ProtectedByMistText
 	jp z, FarBattleTextBox
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f
 	ld b, a
 	inc b
@@ -6687,7 +6710,7 @@
 
 
 Function0x36532: ; 36532
-	ld [$c70c], a
+	ld [LoweredStat], a
 
 	ld hl, PlayerStatLevels
 	ld a, [hBattleTurn]
@@ -6696,7 +6719,7 @@
 	ld hl, EnemyStatLevels
 
 .asm_36540
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f
 	ld c, a
 	ld b, 0
@@ -6705,7 +6728,7 @@
 	dec b
 	jr z, .asm_36589
 
-	ld a, [$c70c]
+	ld a, [LoweredStat]
 	and $f0
 	jr z, .asm_36558
 	dec b
@@ -6720,12 +6743,12 @@
 
 	push hl
 	ld hl, $c641
-	ld de, $c6b6
+	ld de, PlayerStats
 	ld a, [hBattleTurn]
 	and a
 	jr z, .asm_36570
 	ld hl, $d21b
-	ld de, $c6c1
+	ld de, EnemyStats
 
 .asm_36570
 	call Function0x3641a
@@ -6746,7 +6769,7 @@
 
 .asm_36583
 	xor a
-	ld [$c70e], a
+	ld [FailedMessage], a
 	ret
 
 .asm_36588
@@ -6754,7 +6777,7 @@
 
 .asm_36589
 	ld a, 2
-	ld [$c70e], a
+	ld [FailedMessage], a
 	ret
 ; 3658f
 
@@ -6821,7 +6844,7 @@
 
 Function0x365d7: ; 365d7
 	ld hl, PlayerAtkLevel
-	ld de, $c6b6
+	ld de, PlayerStats
 	ld bc, BattleMonAtk
 
 	ld a, $5
@@ -6844,7 +6867,7 @@
 
 Function0x365fd: ; 365fd
 	ld hl, EnemyAtkLevel
-	ld de, $c6c1
+	ld de, EnemyStats
 	ld bc, EnemyMonAtk
 
 	ld a, $5
@@ -7601,7 +7624,7 @@
 	ret nz
 	call Function0x36abf
 	ret nz
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	ret nz
 
@@ -8036,7 +8059,7 @@
 	ld a, b
 	cp $19
 	ret z
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	ret nz
 	call Function0x37962
@@ -8902,8 +8925,8 @@
 	ld a, [hl]
 	ld [$d265], a
 	call $343b
-	ld hl, $c6c1
-	ld de, $c6b6
+	ld hl, EnemyStats
+	ld de, PlayerStats
 	ld bc, $000a
 	call BattleSideCopy
 	ld hl, EnemyStatLevels
@@ -9320,7 +9343,7 @@
 	ld hl, $5e76
 	rst FarCall
 	ret c
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	ret nz
 	ld a, [InLinkBattle]
@@ -9354,7 +9377,7 @@
 	ld hl, $5e76
 	rst FarCall
 	ret c
-	ld a, [$c70d]
+	ld a, [EffectFailed]
 	and a
 	ret nz
 	call .asm_37501
--- a/battle_constants.asm
+++ b/battle_constants.asm
@@ -1,6 +1,14 @@
 MAX_LEVEL EQU 100
 NUM_MOVES EQU 4
 
+ATTACK EQU 0
+DEFENSE EQU 1
+SPEED EQU 2
+SP_ATTACK EQU 3
+SP_DEFENSE EQU 4
+ACCURACY EQU 5
+EVASION EQU 6
+
 ; move struct
 MOVE_LENGTH EQU 7
 MOVE_ANIM EQU 0
--- a/wram.asm
+++ b/wram.asm
@@ -621,8 +621,15 @@
 BattleScriptBufferLoc: ; c6b2
 	ds 2
 
-	ds 24
+	ds 2
 
+PlayerStats: ; c6b6
+	ds 10
+	ds 1
+EnemyStats: ; c6c1
+	ds 10
+	ds 1
+
 PlayerStatLevels: ; c6cc
 ; 07 neutral
 PlayerAtkLevel: ; c6cc
@@ -749,7 +756,14 @@
 ; # turns remaining
 	ds 1
 
-	ds 6
+LoweredStat: ; c70c
+	ds 1
+EffectFailed: ; c70d
+	ds 1
+FailedMessage: ; c70e
+	ds 1
+
+	ds 3
 
 PlayerUsedMoves: ; c712
 ; add a move that has been used once by the player