shithub: pokecrystal

Download patch

ref: 85aa236c34e50da698d4eeacd5c76a05463c83b2
parent: 2e200ce85e21eee3d46a4c82074425697c0b433d
author: Remy Oukaour <remy.oukaour@gmail.com>
date: Mon Dec 25 11:18:05 EST 2017

Use percentages for AI scoring logic
Define MAX_DAY_CARE_EXP

--- a/battle/ai/scoring.asm
+++ b/battle/ai/scoring.asm
@@ -141,7 +141,7 @@
 
 .discourage
 	call Random
-	cp 30
+	cp 12 percent
 	jr c, .checkmove
 	inc [hl]
 	inc [hl]
@@ -453,7 +453,7 @@
 
 .asm_38815
 	call Random
-	cp 100
+	cp 39 percent + 1
 	ret c
 
 	inc [hl]
@@ -594,7 +594,7 @@
 ; If enemy's HP is between 25% and 50%,
 ; over 90% chance to greatly discourage this move.
 	call Random
-	cp 20
+	cp 9 percent - 2
 	ret c
 
 .asm_388c6
@@ -610,7 +610,7 @@
 ; The AI_Basic layer will make sure that
 ; Dream Eater is only used against sleeping targets.
 	call Random
-	cp 25
+	cp 10 percent
 	ret c
 	dec [hl]
 	dec [hl]
@@ -637,7 +637,7 @@
 
 ; ...70% chance to greatly encourage this move if player is not badly poisoned.
 	call Random
-	cp $b2
+	cp 70 percent
 	jr nc, .asm_38911
 
 .asm_388ef
@@ -653,7 +653,7 @@
 
 ; If enemy's HP is above 25% but not full, 4% chance to greatly encourage this move.
 	call Random
-	cp $a
+	cp 4 percent
 	jr c, .asm_388ef
 
 ; If enemy's HP is between 25% and 50%,...
@@ -710,11 +710,11 @@
 	ret
 
 ; Player is badly poisoned.
-; 80% chance to greatly encourage this move.
+; 70% chance to greatly encourage this move.
 ; This would counter any previous discouragement.
 .asm_38938
 	call Random
-	cp $50
+	cp 31 percent + 1
 	ret c
 	dec [hl]
 	dec [hl]
@@ -791,7 +791,7 @@
 	ret nc
 
 	call Random
-	cp $19
+	cp 10 percent
 	ret c
 
 	dec [hl]
@@ -816,7 +816,7 @@
 
 ; ...70% chance to greatly encourage this move if player is not badly poisoned.
 	call Random
-	cp $b2
+	cp 70 percent
 	jr nc, .asm_389bf
 
 .asm_3899d
@@ -832,7 +832,7 @@
 
 ; If player's HP is above 25% but not full, 4% chance to greatly encourage this move.
 	call Random
-	cp $a
+	cp 4 percent
 	jr c, .asm_3899d
 
 ; If player's HP is between 25% and 50%,...
@@ -884,11 +884,11 @@
 	ret
 
 ; Player is badly poisoned.
-; 80% chance to greatly encourage this move.
+; 70% chance to greatly encourage this move.
 ; This would counter any previous discouragement.
 .asm_389e6
 	call Random
-	cp $50
+	cp 31 percent + 1
 	ret c
 	dec [hl]
 	dec [hl]
@@ -934,7 +934,7 @@
 .asm_38a12
 	pop hl
 	call Random
-	cp $28
+	cp 16 percent
 	ret c
 	dec [hl]
 	ret
@@ -955,7 +955,7 @@
 	call AICheckEnemyMaxHP
 	ret c
 	call Random
-	cp $19
+	cp 10 percent
 	ret c
 	inc [hl]
 	ret
@@ -997,7 +997,7 @@
 
 .asm_38a45
 	call Random
-	cp $19
+	cp 10 percent
 	ret c
 	dec [hl]
 	dec [hl]
@@ -1023,7 +1023,7 @@
 	call AICheckEnemyMaxHP
 	ret c
 	call Random
-	cp $14
+	cp 8 percent
 	ret c
 	inc [hl]
 	ret
@@ -1126,7 +1126,7 @@
 
 .asm_38acd
 	call Random
-	cp $c8
+	cp 79 percent - 1
 	ret c
 
 .asm_38ad3
@@ -1148,7 +1148,7 @@
 	call AICheckPlayerHalfHP
 	ret c
 	call Random
-	cp $19
+	cp 10 percent
 	jr c, .asm_38ae7
 	inc [hl]
 
@@ -1272,7 +1272,7 @@
 	call AICompareSpeed
 	ret c
 	call Random
-	cp 30
+	cp 12 percent
 	ret c
 	dec [hl]
 	dec [hl]
@@ -1304,7 +1304,7 @@
 .asm_38b72
 ; If enemy's HP is above 50%, discourage this move at random
 	call Random
-	cp 40
+	cp 16 percent
 	ret c
 	inc [hl]
 	call AI_50_50
@@ -1457,7 +1457,7 @@
 
 .asm_38c30
 	call Random
-	cp $64
+	cp 39 percent + 1
 	jr c, .asm_38c38
 
 	dec [hl]
@@ -1510,7 +1510,7 @@
 
 .asm_38c78
 	call Random
-	cp $46
+	cp 28 percent - 1
 	ret c
 	dec [hl]
 	dec [hl]
@@ -1657,7 +1657,7 @@
 	jr nc, .asm_38d0b
 
 	call Random
-	cp $64
+	cp 39 percent + 1
 	ret nc
 
 .asm_38d0b
@@ -1666,7 +1666,7 @@
 
 .asm_38d0d
 	call Random
-	cp $64
+	cp 39 percent + 1
 	ret c
 	dec [hl]
 	dec [hl]
@@ -1827,7 +1827,7 @@
 
 .asm_38dc9
 	call Random
-	cp 25
+	cp 10 percent
 	ret c
 	inc [hl]
 	ret
@@ -1848,7 +1848,7 @@
 	jr nc, .asm_38dee
 
 	call Random
-	cp 100
+	cp 39 percent + 1
 	ret c
 	dec [hl]
 	ret
@@ -1860,7 +1860,7 @@
 
 .asm_38df3
 	call Random
-	cp 20
+	cp 8 percent
 	ret c
 	inc [hl]
 	ret
@@ -2096,7 +2096,7 @@
 
 .asm_38f14
 	call Random
-	cp 20
+	cp 8 percent
 	ret c
 	inc [hl]
 	inc [hl]
@@ -2120,7 +2120,7 @@
 	jr z, .asm_38f41
 
 	call Random
-	cp 20
+	cp 8 percent
 	ret c
 	inc [hl]
 	ret
@@ -2127,7 +2127,7 @@
 
 .asm_38f41
 	call Random
-	cp 100
+	cp 39 percent + 1
 	ret c
 	dec [hl]
 	dec [hl]
@@ -2317,7 +2317,7 @@
 
 ; Otherwise, 80% chance to greatly encourage this move.
 	call Random
-	cp 200
+	cp 79 percent - 1
 	ret nc
 	dec [hl]
 	dec [hl]
@@ -2347,7 +2347,7 @@
 
 .first_turn
 	call Random
-	cp 200
+	cp 79 percent - 1
 	ret nc
 	dec [hl]
 	ret
@@ -2850,7 +2850,7 @@
 	ret nz
 
 	call Random
-	cp 25 ; 1/10
+	cp 10 percent
 	ret c
 
 	inc [hl]
@@ -2875,7 +2875,7 @@
 	ret nz
 
 	call Random
-	cp 25 ; 1/10
+	cp 10 percent
 	ret c
 
 	inc [hl]
@@ -3387,7 +3387,7 @@
 	jr nc, .asm_39425
 
 	call Random
-	cp 230
+	cp 90 percent + 1
 	ret nc
 
 	inc [hl]
@@ -3513,7 +3513,7 @@
 
 ; Else, 80% chance to exclude them.
 	call Random
-	cp 200 ; 1/5
+	cp 79 percent - 1
 	jr c, .nextmove
 
 .checkko
@@ -3586,7 +3586,7 @@
 
 AI_80_20: ; 39521
 	call Random
-	cp 50 ; 1/5
+	cp 20 percent - 1
 	ret
 ; 39527
 
@@ -3593,6 +3593,6 @@
 
 AI_50_50: ; 39527
 	call Random
-	cp $80 ; 1/2
+	cp 50 percent + 1
 	ret
 ; 3952d
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -120,3 +120,5 @@
 	const HAPPINESS_REVIVALHERB       ; 11
 	const HAPPINESS_MASSAGE           ; 12
 	const HAPPINESS_GAINLEVELATHOME   ; 13
+
+MAX_DAY_CARE_EXP EQU $500000
--- a/event/happiness_egg.asm
+++ b/event/happiness_egg.asm
@@ -159,9 +159,9 @@
 	dec hl
 	inc [hl]
 	ld a, [hl]
-	cp HIGH($500000 >> 8)
+	cp HIGH(MAX_DAY_CARE_EXP >> 8)
 	jr c, .day_care_lady
-	ld a, HIGH($500000 >> 8)
+	ld a, HIGH(MAX_DAY_CARE_EXP >> 8)
 	ld [hl], a
 
 .day_care_lady
@@ -181,9 +181,9 @@
 	dec hl
 	inc [hl]
 	ld a, [hl]
-	cp HIGH($500000 >> 8)
+	cp HIGH(MAX_DAY_CARE_EXP >> 8)
 	jr c, .check_egg
-	ld a, HIGH($500000 >> 8)
+	ld a, HIGH(MAX_DAY_CARE_EXP >> 8)
 	ld [hl], a
 
 .check_egg
@@ -199,7 +199,7 @@
 	callfar CheckBreedmonCompatibility
 	ld a, [wd265]
 	cp 230
-	ld b, -1 + 32 percent
+	ld b, 32 percent - 1
 	jr nc, .okay
 	ld a, [wd265]
 	cp 170