shithub: pokered

Download patch

ref: fa9c66dc639cbbbd8809fcd98f6be6cde731e1f0
parent: b87848642c3ca215c5cd2ea3f28a5c977d7b1af6
author: IIMarckus <iimarckus@gmail.com>
date: Tue Dec 27 15:04:33 EST 2011

Cleanup, and added new RAM variables (and changed some others).

hg-commit-id: 91fe5cdac0f3


--- a/constants.asm
+++ b/constants.asm
@@ -81,12 +81,17 @@
 
 W_TRAINERCLASS EQU $D031
 
-W_BATTLETYPE EQU $D057 ; in a wild battle, this is 1
-                       ; in a trainer battle, this is 2
+W_ISINBATTLE EQU $D057 ; no battle, this is 0
+                       ; wild battle, this is 1
+                       ; trainer battle, this is 2
 
 W_CUROPPONENT EQU $D059 ; in a wild battle, this is the species of pokemon
 			; in a trainer battle, this is the trainer class + $C8
 
+W_BATTLETYPE EQU $D05A ; in normal battle, this is 0
+                       ; in old man battle, this is 1
+                       ; in safari battle, this is 2
+
 W_LONEATTACKNO EQU $D05C ; which entry in LoneAttacks to use
 W_TRAINERNO    EQU $D05D ; which instance of [youngster, lass, etc] is this?
 
@@ -106,6 +111,8 @@
 
 W_PLAYERNAME EQU $D158 ; 11 characters, including null
 
+W_NUMINPARTY EQU $D163
+
 W_RIVALNAME  EQU $D34A ; 11 characters, including null
 
 W_CURMAP EQU $D35E
@@ -137,6 +144,10 @@
 W_ENEMYMON5MOVE3 EQU $D95E
 
 W_ENEMYMON6MOVE3 EQU $D98A
+
+W_NUMSAFARIBALLS EQU $DA47
+
+W_NUMINBOX EQU $DA80
 
 H_RAND1 EQU $FFD3
 H_RAND2 EQU $FFD4
--- a/pokered.asm
+++ b/pokered.asm
@@ -735,7 +735,8 @@
 	db "@"
 
 Char5F:
-	ld [hl],$E8 ; .
+; ends a Pokédex entry
+	ld [hl],"."
 	pop hl
 	ret
 
@@ -1823,7 +1824,7 @@
 	ld a,[$D5A2]
 	and a
 	jp z,$5D5F
-	ld a,[$D35E] ; map ID
+	ld a,[W_CURMAP] ; map ID
 	cp a,$76 ; Hall of Fame
 	jp nz,$5D5F
 	xor a
@@ -4224,38 +4225,30 @@
 	dw $631E
 	dw $631E
 
-
-;[$D057]==0 -> OutsideBattle
-;[$D057]==1 -> WildBattle
-;[$D057]==2 -> TrainerBattle
-
-;[$D05A]==0 -> NormalBattle
-;[$D05A]==1 -> OldManExampleBattle
-;[$D05A]==2 -> SafariBattle
-
 ItemUseBall:	;03:5687
-	ld a,[$d057]
+	ld a,[W_ISINBATTLE]
 	and a
-	jp z,$6581
+	jp z,ItemUseNotTime ; not in battle
 	dec a
-	jp nz,$658b
-	ld a,[$d05a]
+	jp nz,$658b ; in trainer battle
+	ld a,[W_BATTLETYPE]
 	dec a
-	jr z,.next\@
-	ld a,[$d163]	;is Party full?
+	jr z,.UseBall\@
+	ld a,[W_NUMINPARTY]	;is Party full?
 	cp a,6
-	jr nz,.next\@
-	ld a,[$da80]	;is Box full?
+	jr nz,.UseBall\@
+	ld a,[W_NUMINBOX]	;is Box full?
 	cp a,20
 	jp z,$65b1
-.next\@	;$56a7
+.UseBall\@	;$56a7
 ;ok, you can use a ball
 	xor a
 	ld [$d11c],a
-	ld a,[$d05a]
+	ld a,[W_BATTLETYPE]
 	cp a,2		;SafariBattle
 	jr nz,.next2\@
-	ld hl,$da47	;dec SafariBall's num
+	; remove a Safari Ball from inventory
+	ld hl,W_NUMSAFARIBALLS
 	dec [hl]
 .next2\@	;$56b6
 	call GoPAL_SET_CF1C
@@ -4269,16 +4262,16 @@
 	call Bankswitch
 	ld b,$10
 	jp z,$5801
-	ld a,[$d05a]
+	ld a,[W_BATTLETYPE]
 	dec a
 	jr nz,.next3\@
 	ld hl,W_GRASSRATE	;backups wildMon data
-	ld de,$d158
+	ld de,W_PLAYERNAME
 	ld bc,11
 	call CopyData
 	jp .BallSuccess\@	;$578b
 .next3\@	;$56e9
-	ld a,[$d35e]
+	ld a,[W_CURMAP]
 	cp a,$93	;MonTower 6F
 	jr nz,.next4\@
 	ld a,[$cfd8]
@@ -4516,7 +4509,7 @@
 	ld [$d11c],a
 	ld [$cf91],a
 	ld [$d11e],a
-	ld a,[$d05a]
+	ld a,[W_BATTLETYPE]
 	dec a
 	jr z,.printText1\@
 	ld hl,ItemUseBallText05
@@ -4549,7 +4542,7 @@
 	ld a,$3d
 	call Predef
 .checkParty\@	;$58f4
-	ld a,[$d163]	;nbr of mon in party
+	ld a,[W_NUMINPARTY]
 	cp a,6		;is party full?
 	jr z,.sendToBox\@
 	xor a
@@ -4574,7 +4567,7 @@
 	call PrintText
 	call CleanLCD_OAM
 .End\@	;$5928
-	ld a,[$d05a]
+	ld a,[W_BATTLETYPE]
 	and a
 	ret nz
 	ld hl,$d31d
@@ -4625,7 +4618,7 @@
 	db "@"
 
 ItemUseTownMap:	;03:5968
-	ld a,[$d057]	;in-battle or outside
+	ld a,[W_ISINBATTLE]	;in-battle or outside
 	and a
 	jp nz,ItemUseNotTime	;OAK: "this isn't the time..."
 
@@ -4633,7 +4626,7 @@
 
 GoodRodCode: ; 6259
 	call $62B4
-	jp c,$6581
+	jp c,ItemUseNotTime
 Next625F:
 	call GenRandom
 	srl a
@@ -4663,7 +4656,7 @@
 
 Next6283:
 	call $62B4
-	jp c,$6581
+	jp c,ItemUseNotTime
 Next6289:
 	call $68EA
 	ld a,e
@@ -7148,7 +7141,7 @@
 TrainerAI: ; 652E
 ;XXX called at 34964, 3c342, 3c398
 	and a
-	ld a,[W_BATTLETYPE]
+	ld a,[W_ISINBATTLE]
 	dec a
 	ret z ; if not a trainer, we're done here
 	ld a,[W_ISLINKBATTLE]
@@ -9922,7 +9915,7 @@
 	ld a,[$D11D]
 	dec a
 	jr z,.next4\@
-	ld a,[$D163]
+	ld a,[W_NUMINPARTY]
 	dec a
 	jr z,.next4\@
 	ld a,[$D12B]
@@ -13473,7 +13466,7 @@
 INCBIN "baserom.gbc",$79AAE,$79E16 - $79AAE
 
 TossBallAnimation: ; 5E16
-	ld a,[W_BATTLETYPE]
+	ld a,[W_ISINBATTLE]
 	cp a,2
 	jr z,.BlockBall\@ ; if in trainer battle, play different animation
 	ld a,[$D11E]