shithub: pokecrystal

Download patch

ref: 3a7edf8b1ac7e84efa7f86c8f711f99812415701
parent: 573db5b1b451a901404627696c685c10ab35085b
author: yenatch <yenatch@gmail.com>
date: Mon May 6 20:58:35 EDT 2013

even more ai cleanup

--- a/battle/ai/scoring.asm
+++ b/battle/ai/scoring.asm
@@ -391,19 +391,16 @@
 
 
 AIScoring_Sleep: ; 387e3
-	ld b, $8
-	call Function_0x392ca
-
+	ld b, EFFECT_DREAM_EATER
+	call AIHasMove
 	jr c, .asm_387f0
 
-	ld b, $6b
-	call Function_0x392ca
-
+	ld b, EFFECT_NIGHTMARE
+	call AIHasMove
 	ret nc
 
 .asm_387f0
 	call Function_0x39527
-
 	ret c
 	dec [hl]
 	dec [hl]
@@ -413,15 +410,13 @@
 
 AIScoring_LeechHit: ; 387f7
 	push hl
-	ld a, $1
+	ld a, 1
 	ld [hBattleTurn], a
-	ld hl, $47c8
-	ld a, $d
-	rst FarCall
-
+	callab Function0x347c8
 	pop hl
+
 	ld a, [$d265]
-	cp $a
+	cp 10 ; 1.0
 	jr c, .asm_38815
 
 	ret z
@@ -564,31 +559,24 @@
 
 AIScoring_Explosion: ; 388a6
 	push hl
-	ld a, $d
-	ld hl, $49f4
-	rst FarCall
-
+	callba Function0x349f4
 	pop hl
 	jr nc, .asm_388b7
 
 	push hl
-	call Function_0x38e2e
-
+	call AICheckLastPlayerMon
 	pop hl
 	jr nz, .asm_388c6
 
-
 .asm_388b7
 	call AICheckEnemyHalfHP
-
 	jr c, .asm_388c6
 
 	call AICheckEnemyQuarterHP
-
 	ret nc
-	call RNG
 
-	cp $14
+	call RNG
+	cp 20
 	ret c
 
 .asm_388c6
@@ -916,9 +904,7 @@
 
 AIScoring_Whirlwind: ; 38a2a
 	push hl
-	ld hl, $484e
-	ld a, $d
-	rst FarCall
+	callab Function0x3484e
 	ld a, [$c716]
 	cp $a
 	pop hl
@@ -1171,7 +1157,7 @@
 	call AICompareSpeed
 	ret c
 	call RNG
-	cp $1e
+	cp 30
 	ret c
 	dec [hl]
 	dec [hl]
@@ -1198,7 +1184,7 @@
 
 .asm_38b72
 	call RNG
-	cp $28
+	cp 40
 	ret c
 	inc [hl]
 	call Function_0x39527
@@ -1725,7 +1711,6 @@
 
 AIScoring_Disable: ; 38dd1
 	call AICompareSpeed
-
 	jr nc, .asm_38df3
 
 	push hl
@@ -1738,8 +1723,7 @@
 	jr nc, .asm_38dee
 
 	call RNG
-
-	cp $64
+	cp 100
 	ret c
 	dec [hl]
 	ret
@@ -1751,8 +1735,7 @@
 
 .asm_38df3
 	call RNG
-
-	cp $14
+	cp 20
 	ret c
 	inc [hl]
 	ret
@@ -1761,28 +1744,23 @@
 
 AIScoring_MeanLook: ; 38dfb
 	call AICheckEnemyHalfHP
-
 	jr nc, .asm_38e24
 
 	push hl
-	call Function_0x38e2e
-
+	call AICheckLastPlayerMon
 	pop hl
 	jp z, AIDiscourageMove
 
 	ld a, [EnemySubStatus5]
-	bit 0, a
+	bit SUBSTATUS_TOXIC, a
 	jr nz, .asm_38e26
 
 	ld a, [PlayerSubStatus1]
-	and $c9
+	and 1<<SUBSTATUS_IN_LOVE | 1<<SUBSTATUS_ENCORED | 1<<SUBSTATUS_IDENTIFIED | 1<<SUBSTATUS_NIGHTMARE
 	jr nz, .asm_38e26
 
 	push hl
-	ld hl, $484e
-	ld a, $d
-	rst FarCall
-
+	callab Function0x3484e
 	ld a, [$c716]
 	cp $b
 	pop hl
@@ -1794,7 +1772,6 @@
 
 .asm_38e26
 	call Function_0x39521
-
 	ret c
 	dec [hl]
 	dec [hl]
@@ -1803,7 +1780,7 @@
 ; 38e2e
 
 
-Function_0x38e2e: ; 38e2e
+AICheckLastPlayerMon: ; 38e2e
 	ld a, [PartyCount]
 	ld b, a
 	ld c, 0
@@ -1832,7 +1809,6 @@
 
 AIScoring_Nightmare: ; 38e4a
 	call Function_0x39527
-
 	ret c
 	dec [hl]
 	ret
@@ -1841,7 +1817,7 @@
 
 AIScoring_FlameWheel: ; 38e50
 	ld a, [EnemyMonStatus]
-	bit 5, a
+	bit FRZ, a
 	ret z
 	dec [hl]
 	dec [hl]
@@ -1854,34 +1830,30 @@
 
 AIScoring_Curse: ; 38e5c
 	ld a, [EnemyMonType1]
-	cp $8
-	jr z, .asm_38e95
-
+	cp GHOST
+	jr z, .ghostcurse
 	ld a, [EnemyMonType2]
-	cp $8
-	jr z, .asm_38e95
+	cp GHOST
+	jr z, .ghostcurse
 
 	call AICheckEnemyHalfHP
-
 	jr nc, .asm_38e93
 
 	ld a, [EnemyAtkLevel]
 	cp $b
 	jr nc, .asm_38e93
-
 	cp $9
 	ret nc
+
 	ld a, [BattleMonType1]
-	cp $8
+	cp GHOST
 	jr z, .asm_38e92
-
-	cp $14
+	cp FIRE
 	ret nc
 	ld a, [BattleMonType2]
-	cp $14
+	cp FIRE
 	ret nc
 	call Function_0x39521
-
 	ret c
 	dec [hl]
 	dec [hl]
@@ -1890,30 +1862,24 @@
 .asm_38e90
 	inc [hl]
 	inc [hl]
-
 .asm_38e92
 	inc [hl]
-
 .asm_38e93
 	inc [hl]
 	ret
 
-.asm_38e95
+.ghostcurse
 	ld a, [PlayerSubStatus1]
-	bit 1, a
+	bit SUBSTATUS_CURSE, a
 	jp nz, AIDiscourageMove
 
 	push hl
-	ld a, $d
-	ld hl, $49f4
-	rst FarCall
-
+	callba Function0x349f4
 	pop hl
 	jr nc, .asm_38eb0
 
 	push hl
-	call Function_0x38e2e
-
+	call AICheckLastPlayerMon
 	pop hl
 	jr nz, .asm_38e90
 
@@ -1922,8 +1888,7 @@
 
 .asm_38eb0
 	push hl
-	call Function_0x38e2e
-
+	call AICheckLastPlayerMon
 	pop hl
 	jr z, .asm_38ecb
 
@@ -1930,16 +1895,14 @@
 
 .asm_38eb7
 	call AICheckEnemyQuarterHP
-
 	jp nc, .asm_38e90
 
 	call AICheckEnemyHalfHP
-
 	jr nc, .asm_38e92
 
 	call AICheckEnemyMaxHP
-
 	ret nc
+
 	ld a, [PlayerTurnsTaken]
 	and a
 	ret nz
@@ -1960,40 +1923,36 @@
 	jr nz, .asm_38f13
 
 	ld a, [PlayerSubStatus5]
-	bit 5, a
+	bit SUBSTATUS_LOCK_ON, a
 	jr nz, .asm_38f14
 
 	ld a, [PlayerFuryCutterCount]
-	cp $3
+	cp 3
 	jr nc, .asm_38f0d
 
 	ld a, [PlayerSubStatus3]
-	bit 4, a
+	bit SUBSTATUS_CHARGED, a
 	jr nz, .asm_38f0d
 
 	ld a, [PlayerSubStatus5]
-	bit 0, a
+	bit SUBSTATUS_TOXIC, a
 	jr nz, .asm_38f0d
-
 	ld a, [PlayerSubStatus4]
-	bit 7, a
+	bit SUBSTATUS_LEECH_SEED, a
 	jr nz, .asm_38f0d
-
 	ld a, [PlayerSubStatus1]
-	bit 1, a
+	bit SUBSTATUS_CURSE, a
 	jr nz, .asm_38f0d
 
-	bit 6, a
+	bit SUBSTATUS_ENCORED, a
 	jr z, .asm_38f14
 
 	ld a, [PlayerRolloutCount]
-	cp $3
+	cp 3
 	jr c, .asm_38f14
 
-
 .asm_38f0d
 	call Function_0x39521
-
 	ret c
 	dec [hl]
 	ret
@@ -2003,8 +1962,7 @@
 
 .asm_38f14
 	call RNG
-
-	cp $14
+	cp 20
 	ret c
 	inc [hl]
 	inc [hl]
@@ -2016,22 +1974,19 @@
 	ld a, [EnemyAccLevel]
 	cp $5
 	jr c, .asm_38f41
-
 	ld a, [PlayerEvaLevel]
 	cp $a
 	jr nc, .asm_38f41
 
 	ld a, [BattleMonType1]
-	cp $8
+	cp GHOST
 	jr z, .asm_38f41
-
 	ld a, [BattleMonType2]
-	cp $8
+	cp GHOST
 	jr z, .asm_38f41
 
 	call RNG
-
-	cp $14
+	cp 20
 	ret c
 	inc [hl]
 	ret
@@ -2038,8 +1993,7 @@
 
 .asm_38f41
 	call RNG
-
-	cp $64
+	cp 100
 	ret c
 	dec [hl]
 	dec [hl]
@@ -2049,10 +2003,7 @@
 
 AIScoring_PerishSong: ; 38f4a
 	push hl
-	ld hl, $49f4
-	ld a, $d
-	rst FarCall
-
+	callab Function0x349f4
 	pop hl
 	jr c, .asm_38f75
 
@@ -2061,17 +2012,15 @@
 	jr nz, .asm_38f6f
 
 	push hl
-	ld hl, $484e
-	ld a, $d
-	rst FarCall
-
+	callab Function0x3484e
 	ld a, [$c716]
-	cp $a
+	cp 10 ; 1.0
 	pop hl
 	ret c
-	call Function_0x39527
 
+	call Function_0x39527
 	ret c
+
 	inc [hl]
 	ret
 
@@ -2084,7 +2033,7 @@
 
 .asm_38f75
 	ld a, [hl]
-	add $5
+	add 5
 	ld [hl], a
 	ret
 ; 38f7a
@@ -2137,21 +2086,18 @@
 	jr nz, .asm_38fd8
 
 	call AICheckEnemyMaxHP
-
 	jr c, .asm_38fd8
 
 	call AICheckEnemyQuarterHP
-
 	jr c, .asm_38fd9
 
-	ld b, $63
-	call Function_0x392ca
-
+	ld b, EFFECT_REVERSAL
+	call AIHasMove
 	jr nc, .asm_38fcb
 
 	call Function_0x39521
-
 	ret c
+
 	dec [hl]
 	dec [hl]
 	dec [hl]
@@ -2159,7 +2105,7 @@
 
 .asm_38fcb
 	ld a, [EnemySubStatus5]
-	bit 5, a
+	bit SUBSTATUS_LOCK_ON, a
 	ret z
 	call Function_0x39527
 
@@ -2180,21 +2126,22 @@
 AIScoring_FuryCutter: ; 38fdb
 	ld a, [EnemyFuryCutterCount]
 	and a
-	jr z, AIScoring_Rollout
-
+	jr z, .end
 	dec [hl]
-	cp $2
-	jr c, AIScoring_Rollout
 
+	cp 2
+	jr c, .end
 	dec [hl]
 	dec [hl]
-	cp $3
-	jr c, AIScoring_Rollout
 
+	cp 3
+	jr c, .end
 	dec [hl]
 	dec [hl]
 	dec [hl]
 
+.end
+
 	; fallthrough
 ; 38fef
 
@@ -2201,32 +2148,29 @@
 
 AIScoring_Rollout: ; 38fef
 	ld a, [EnemySubStatus1]
-	bit 7, a
+	bit SUBSTATUS_IN_LOVE, a
 	jr nz, .asm_39020
 
 	ld a, [EnemySubStatus3]
-	bit 7, a
+	bit SUBSTATUS_CONFUSED, a
 	jr nz, .asm_39020
 
 	ld a, [EnemyMonStatus]
-	bit 6, a
+	bit PAR, a
 	jr nz, .asm_39020
 
 	call AICheckEnemyQuarterHP
-
 	jr nc, .asm_39020
 
 	ld a, [EnemyAccLevel]
-	cp $7
+	cp 7
 	jr c, .asm_39020
-
 	ld a, [PlayerEvaLevel]
-	cp $8
+	cp 8
 	jr nc, .asm_39020
 
 	call RNG
-
-	cp $c8
+	cp 200
 	ret nc
 	dec [hl]
 	dec [hl]
@@ -2234,7 +2178,6 @@
 
 .asm_39020
 	call Function_0x39521
-
 	ret c
 	inc [hl]
 	ret
@@ -2248,7 +2191,6 @@
 	jr z, .asm_39032
 
 	call Function_0x39521
-
 	ret c
 	inc [hl]
 	ret
@@ -2255,8 +2197,7 @@
 
 .asm_39032
 	call RNG
-
-	cp $c8
+	cp 200
 	ret nc
 	dec [hl]
 	ret
@@ -2265,10 +2206,8 @@
 
 AIScoring_Safeguard: ; 3903a
 	call AICheckPlayerHalfHP
-
 	ret c
 	call Function_0x39521
-
 	ret c
 	inc [hl]
 	ret
@@ -2278,14 +2217,14 @@
 AIScoring_Magnitude:
 AIScoring_Earthquake: ; 39044
 	ld a, [LastEnemyCounterMove]
-	cp $5b
+	cp DIG
 	ret nz
+
 	ld a, [PlayerSubStatus3]
-	bit 5, a
+	bit SUBSTATUS_UNDERGROUND, a
 	jr z, .asm_39058
 
 	call AICompareSpeed
-
 	ret nc
 	dec [hl]
 	dec [hl]
@@ -2293,10 +2232,8 @@
 
 .asm_39058
 	call AICompareSpeed
-
 	ret c
 	call Function_0x39527
-
 	ret c
 	dec [hl]
 	ret
@@ -2305,12 +2242,9 @@
 
 AIScoring_BatonPass: ; 39062
 	push hl
-	ld hl, $484e
-	ld a, $d
-	rst FarCall
-
+	callab Function0x3484e
 	ld a, [$c716]
-	cp $a
+	cp 10 ; 1.0
 	pop hl
 	ret c
 	inc [hl]
@@ -2320,11 +2254,8 @@
 
 AIScoring_Pursuit: ; 39072
 	call AICheckPlayerQuarterHP
-
 	jr nc, .asm_3907d
-
 	call Function_0x39521
-
 	ret c
 	inc [hl]
 	ret
@@ -2331,7 +2262,6 @@
 
 .asm_3907d
 	call Function_0x39527
-
 	ret c
 	dec [hl]
 	dec [hl]
@@ -2345,11 +2275,11 @@
 	jr nz, .asm_39097
 
 	ld a, [EnemySubStatus4]
-	bit 7, a
+	bit SUBSTATUS_LEECH_SEED, a
 	jr nz, .asm_39097
 
 	ld a, [EnemyScreens]
-	bit 0, a
+	bit SCREENS_SPIKES, a
 	ret z
 
 .asm_39097
@@ -2364,17 +2294,14 @@
 
 AIScoring_HiddenPower: ; 3909e
 	push hl
-	ld a, $1
+	ld a, 1
 	ld [hBattleTurn], a
 	ld hl, $7ced
 	ld a, $3e
 	rst FarCall
-
-	ld hl, $47c8
-	ld a, $d
-	rst FarCall
-
+	callab Function0x347c8
 	pop hl
+
 	ld a, [$d265]
 	cp $a
 	jr c, .asm_390c9
@@ -2404,22 +2331,21 @@
 AIScoring_RainDance: ; 390cb
 	ld a, [BattleMonType1]
 	cp WATER
-	jr z, Function_0x3911e
+	jr z, AIBadWeatherType
 	cp FIRE
-	jr z, Function_0x39122
+	jr z, AIGoodWeatherType
 
 	ld a, [BattleMonType2]
 	cp WATER
-	jr z, Function_0x3911e
+	jr z, AIBadWeatherType
 	cp FIRE
-	jr z, Function_0x39122
+	jr z, AIGoodWeatherType
 
 	push hl
 	ld hl, RainDanceMoves
-	jr Function_0x3910d
+	jr AIScoring_WeatherMove
 ; 390e7
 
-
 RainDanceMoves: ; 390e7
 	db WATER_GUN
 	db HYDRO_PUMP
@@ -2439,15 +2365,15 @@
 AIScoring_SunnyDay: ; 390f3
 	ld a, [BattleMonType1]
 	cp FIRE
-	jr z, Function_0x3911e
+	jr z, AIBadWeatherType
 	cp WATER
-	jr z, Function_0x39122
+	jr z, AIGoodWeatherType
 
 	ld a, [BattleMonType2]
 	cp FIRE
-	jr z, Function_0x3911e
+	jr z, AIBadWeatherType
 	cp WATER
-	jr z, Function_0x39122
+	jr z, AIGoodWeatherType
 
 	push hl
 	ld hl, SunnyDayMoves
@@ -2456,13 +2382,13 @@
 ; 3910d
 
 
-Function_0x3910d: ; 3910d
-	call Function_0x392e6
+AIScoring_WeatherMove: ; 3910d
+	call AIHasMoveInArray
 	pop hl
-	jr nc, Function_0x3911e
+	jr nc, AIBadWeatherType
 
 	call AICheckPlayerHalfHP
-	jr nc, Function_0x3911e
+	jr nc, AIBadWeatherType
 
 	call Function_0x39527
 	ret c
@@ -2469,26 +2395,28 @@
 
 	dec [hl]
 	ret
+; 3911e
 
-Function_0x3911e: ; 3911e
+AIBadWeatherType: ; 3911e
 	inc [hl]
 	inc [hl]
 	inc [hl]
 	ret
+; 39122
 
-Function_0x39122: ; 39122
+AIGoodWeatherType: ; 39122
 	call AICheckPlayerHalfHP
 	ret nc
 
 	ld a, [PlayerTurnsTaken]
 	and a
-	jr z, .asm_39131
+	jr z, .good
 
 	ld a, [EnemyTurnsTaken]
 	and a
 	ret nz
 
-.asm_39131
+.good
 	dec [hl]
 	dec [hl]
 	ret
@@ -2597,7 +2525,7 @@
 	jr z, .asm_391a8
 
 	ld a, [EnemyMoveType]
-	cp $14
+	cp FIRE
 	jr c, .asm_391a8
 
 	inc b
@@ -2625,16 +2553,14 @@
 	jr z, .asm_391d2
 
 	ld a, [EnemyMoveType]
-	cp $14
+	cp FIRE
 	jr c, .asm_391d2
 
 
 .asm_391ca
 	call RNG
-
-	cp $64
+	cp 100
 	jr c, .asm_391d2
-
 	dec [hl]
 
 .asm_391d2
@@ -2649,15 +2575,16 @@
 AIScoring_Twister:
 AIScoring_Gust: ; 391d5
 	ld a, [LastEnemyCounterMove]
-	cp $13
+	cp FLY
 	ret nz
+
 	ld a, [PlayerSubStatus3]
-	bit 6, a
+	bit SUBSTATUS_FLYING, a
 	jr z, .asm_391e9
 
 	call AICompareSpeed
-
 	ret nc
+
 	dec [hl]
 	dec [hl]
 	ret
@@ -2664,10 +2591,8 @@
 
 .asm_391e9
 	call AICompareSpeed
-
 	ret c
 	call Function_0x39527
-
 	ret c
 	dec [hl]
 	ret
@@ -2676,11 +2601,12 @@
 
 AIScoring_FutureSight: ; 391f3
 	call AICompareSpeed
-
 	ret nc
+
 	ld a, [PlayerSubStatus3]
-	and $60
+	and 1<<SUBSTATUS_FLYING | 1<<SUBSTATUS_UNDERGROUND
 	ret z
+
 	dec [hl]
 	dec [hl]
 	ret
@@ -2691,9 +2617,10 @@
 	ld a, [$c6fe]
 	and a
 	ret z
-	call Function_0x39521
 
+	call Function_0x39521
 	ret c
+
 	dec [hl]
 	ret
 ; 3920b
@@ -2889,12 +2816,13 @@
 ; 392ca
 
 
-Function_0x392ca: ; 392ca
+AIHasMove: ; 392ca
+; Return carry if the enemy has move b.
 	push hl
 	ld hl, EnemyMonMoves
 	ld c, EnemyMonMovesEnd - EnemyMonMoves
 
-.asm_392d0
+.checkmove
 	ld a, [hli]
 	and a
 	jr z, .asm_392e0
@@ -2906,7 +2834,7 @@
 	jr z, .asm_392e3
 
 	dec c
-	jr nz, .asm_392d0
+	jr nz, .checkmove
 
 .asm_392e0
 	pop hl
@@ -2920,7 +2848,9 @@
 ; 392e6
 
 
-Function_0x392e6: ; 392e6
+AIHasMoveInArray: ; 392e6
+; Return carry if the enemy has a move in array hl.
+
 	push hl
 	push de
 	push bc
--