shithub: pokecrystal

Download patch

ref: b9c1d1b61e529ccda59cafda037c54964af544f3
parent: 706f289c709b8dddd0c196e9d8a6900da34167ea
author: JimB16 <f1@jimb.de>
date: Tue Aug 25 13:02:13 EDT 2015

named labels and commented WRAMVars in battle_tower.asm

--- a/data/battle_tower.asm
+++ b/data/battle_tower.asm
@@ -14,11 +14,11 @@
 	ld de, w3_d100
 	ld a, [hRandomAdd]
 	ld b, a
-.asm_1f8022
+.asm_1f8022 ; loop to find a random trainer
 	call Random
 	ld a, [hRandomAdd]
 	add b
-	ld b, a
+	ld b, a ; b contains the nr of the trainer
 IF DEF(CRYSTAL11)
 	and $7f
 	cp $46
@@ -31,14 +31,14 @@
 	ld a, BANK(sbe46)
 	call GetSRAMBank
 	ld c, $7
-	ld hl, sbe48
+	ld hl, sBTTrainers
 .asm_1f803a
 	ld a, [hli]
 	cp b
 	jr z, .asm_1f8022
 	dec c
-	jr nz, .asm_1f803a
-	ld hl, sbe48
+	jr nz, .asm_1f803a ; c <= 7  initialise all 7 trainers?
+	ld hl, sBTTrainers
 	ld a, [sbe46]
 	ld c, a
 	ld a, b
@@ -77,10 +77,10 @@
 	ld c, $3
 .loop
 	push bc
-	ld a, BANK(sbe51)
+	ld a, BANK(sBTPkmnPrevTrainer1)
 	call GetSRAMBank
 
-.asm_1f8089
+.FindARandomBattleTowerPkmn
 	; From Which LevelGroup are the Pkmn loaded
 	; a = 1..10
 	ld a, [$d800]
@@ -102,6 +102,8 @@
 	; in register 'a' is the chosen Pkmn of the LevelGroup
 
 	; Check if Pkmn was already loaded before
+	; Check current and the 2 previous teams
+	; includes check if item is double at the current team
 	ld bc, $3b
 	call AddNTimes
 	ld a, [hli]
@@ -110,40 +112,40 @@
 	ld c, a
 	ld a, [w3_d100 + $0b]
 	cp b
-	jr z, .asm_1f8089
+	jr z, .FindARandomBattleTowerPkmn
 	ld a, [w3_d100 + $0c]
 	cp c
-	jr z, .asm_1f8089
+	jr z, .FindARandomBattleTowerPkmn
 	ld a, [w3_d100 + $46]
 	cp b
-	jr z, .asm_1f8089
+	jr z, .FindARandomBattleTowerPkmn
 	ld a, [w3_d100 + $47]
 	cp c
-	jr z, .asm_1f8089
+	jr z, .FindARandomBattleTowerPkmn
 	ld a, [w3_d100 + $81]
 	cp b
-	jr z, .asm_1f8089
+	jr z, .FindARandomBattleTowerPkmn
 	ld a, [w3_d100 + $82]
 	cp c
-	jr z, .asm_1f8089
-	ld a, [sbe51]
+	jr z, .FindARandomBattleTowerPkmn
+	ld a, [sBTPkmnPrevTrainer1]
 	cp b
-	jr z, .asm_1f8089
-	ld a, [sbe52]
+	jr z, .FindARandomBattleTowerPkmn
+	ld a, [sBTPkmnPrevTrainer2]
 	cp b
-	jr z, .asm_1f8089
-	ld a, [sbe53]
+	jr z, .FindARandomBattleTowerPkmn
+	ld a, [sBTPkmnPrevTrainer3]
 	cp b
-	jr z, .asm_1f8089
-	ld a, [sbe54]
+	jr z, .FindARandomBattleTowerPkmn
+	ld a, [sBTPkmnPrevPrevTrainer1]
 	cp b
-	jr z, .asm_1f8089
-	ld a, [sbe55]
+	jr z, .FindARandomBattleTowerPkmn
+	ld a, [sBTPkmnPrevPrevTrainer2]
 	cp b
-	jr z, .asm_1f8089
-	ld a, [sbe56]
+	jr z, .FindARandomBattleTowerPkmn
+	ld a, [sBTPkmnPrevPrevTrainer3]
 	cp b
-	jr z, .asm_1f8089
+	jr z, .FindARandomBattleTowerPkmn
 
 	ld bc, $3b
 	call CopyBytes
@@ -170,18 +172,18 @@
 	dec c
 	jp nz, .loop
 
-	ld a, [sbe51]
-	ld [sbe54], a
-	ld a, [sbe52]
-	ld [sbe55], a
-	ld a, [sbe53]
-	ld [sbe56], a
+	ld a, [sBTPkmnPrevTrainer1]
+	ld [sBTPkmnPrevPrevTrainer1], a
+	ld a, [sBTPkmnPrevTrainer2]
+	ld [sBTPkmnPrevPrevTrainer2], a
+	ld a, [sBTPkmnPrevTrainer3]
+	ld [sBTPkmnPrevPrevTrainer3], a
 	ld a, [w3_d100 + $0b]
-	ld [sbe51], a
+	ld [sBTPkmnPrevTrainer1], a
 	ld a, [w3_d100 + $46]
-	ld [sbe52], a
+	ld [sBTPkmnPrevTrainer2], a
 	ld a, [w3_d100 + $81]
-	ld [sbe53], a
+	ld [sBTPkmnPrevTrainer3], a
 	call CloseSRAM
 	ret
 ; 1f814e
--- a/wram.asm
+++ b/wram.asm
@@ -2600,8 +2600,24 @@
 
 	ds $100
 
-w3_d100::
-	ds $700
+w3_d100:: ; BattleTower OpponentTrainer-Data (lengt = 0xe0)
+	ds $6
+BT_OTTrainerPkmn1:: ; w3_d10b
+	ds $1
+BT_OTTrainerPkmn1Item::
+	ds $3b-1
+BT_OTTrainerPkmn2:: ; w3_d146
+	ds $1
+BT_OTTrainerPkmn2Item::
+	ds $3b-1
+BT_OTTrainerPkmn3:: ; w3_d181
+	ds $1
+BT_OTTrainerPkmn3Item::
+	ds $3b-1
+	
+	ds $29
+	
+	ds $620
 
 w3_d800:: ds 1
 
@@ -2772,17 +2788,24 @@
 s1_be44:: ds 1
 s1_be45:: ds 1
 
+; data of the BattleTower must be in SRAM because you can save and leave between battles
 sBattleTower:: ; be46
 sbe46:: ds 1
 sbe47:: ds 1
-sbe48:: ds 7
+; The 7 trainers of the BattleTower are saved here, so nobody appears more than once
+sBTTrainers:: ; sbe48
+	ds 7
 sbe4f:: ds 2
-sbe51:: ds 1
-sbe52:: ds 1
-sbe53:: ds 1
-sbe54:: ds 1
-sbe55:: ds 1
-sbe56:: ds 1
+; Pkmn of previous trainer
+sBTPkmnOfTrainers::
+sBTPkmnPrevTrainer1::
+	ds 1
+sBTPkmnPrevTrainer2:: ds 1
+sBTPkmnPrevTrainer3:: ds 1
+; Pkmn of preprevious trainer
+sBTPkmnPrevPrevTrainer1:: ds 1
+sBTPkmnPrevPrevTrainer2:: ds 1
+sBTPkmnPrevPrevTrainer3:: ds 1
 
 
 SECTION "Boxes 1-7",  SRAM, BANK [2]