ref: 16eb97ae9cca0ce52531860c499c3346e6a2cf9e
parent: 7de7441e72f12ba1518504055acdec741bf4db74
author: Remy Oukaour <remy.oukaour@gmail.com>
date: Tue Jan 9 21:55:44 EST 2018
Constant swap explains this Battle Tower bug
--- a/constants/battle_tower_constants.asm
+++ b/constants/battle_tower_constants.asm
@@ -44,6 +44,12 @@
BATTLETOWER_NROFPKMNS EQU 3
BATTLETOWER_NROFTRAINERS EQU 7
+BATTLETOWER_NUM_UNIQUE_TRAINERS EQU 70
+BATTLETOWER_TRAINER_MASK EQU %1111111
+
+BATTLETOWER_NUM_UNIQUE_PKMN EQU 21
+BATTLETOWER_PKMN_MASK EQU %11111
+
BATTLETOWER_TRAINERDATALENGTH EQU $24
BATTLE_TOWER_STRUCT_LENGTH EQU $e0 ; NAME_LENGTH + BATTLETOWER_NROFPKMNS * (PARTYMON_STRUCT_LENGTH + PKMN_NAME_LENGTH) + BATTLETOWER_TRAINERDATALENGTH
--- a/data/battle_tower/classes.asm
+++ b/data/battle_tower/classes.asm
@@ -23,9 +23,6 @@
db "KAUFMAN@@@", SWIMMERM
db "LANCASTER@", SKIER
db "McMAHILL@@", CAMPER
-if !DEF(_CRYSTAL11)
-BattleTowerTrainersEnd:
-endc
; The following can only be sampled in Crystal 1.1.
db "OBRIEN@@@@", GENTLEMAN
db "FROST@@@@@", BEAUTY
@@ -76,7 +73,4 @@
db "DYKSTRA@@@", SWIMMERF
db "EATON@@@@@", BIKER
db "WONG@@@@@@", FIREBREATHER
-if DEF(_CRYSTAL11)
-BattleTowerTrainersEnd:
-endc
; 1f8450
--- a/engine/events/battle_tower/load_trainer.asm
+++ b/engine/events/battle_tower/load_trainer.asm
@@ -27,11 +27,14 @@
add b
ld b, a ; b contains the nr of the trainer
if DEF(_CRYSTAL11)
- and $7f
+ and BATTLETOWER_TRAINER_MASK
+ cp BATTLETOWER_NUM_UNIQUE_TRAINERS
else
- and $1f
+; Crystal 1.0 used the wrong constants here, so only the first 21
+; trainers in BattleTowerTrainers can be sampled.
+ and BATTLETOWER_PKMN_MASK
+ cp BATTLETOWER_NUM_UNIQUE_PKMN
endc
- cp (BattleTowerTrainersEnd - BattleTowerTrainers) / NAME_LENGTH
jr nc, .resample
ld b, a
@@ -112,8 +115,8 @@
ld a, [hRandomAdd]
add b
ld b, a
- and $1f
- cp BATTLETOWER_NROFPKMNS * BATTLETOWER_NROFTRAINERS
+ and BATTLETOWER_PKMN_MASK
+ cp BATTLETOWER_NUM_UNIQUE_PKMN
jr nc, .resample
; in register 'a' is the chosen Pkmn of the LevelGroup
--- a/engine/events/battle_tower/rules.asm
+++ b/engine/events/battle_tower/rules.asm
@@ -213,7 +213,7 @@
BattleTower_CheckPartyLengthIs3: ; 8b2bb
ld a, [PartyCount]
- cp 3
+ cp BATTLETOWER_NROFPKMNS
ret
; 8b2c1
@@ -235,13 +235,13 @@
cp b
ret z
ld a, b
- cp 3
+ cp BATTLETOWER_NROFPKMNS
ret
; 8b2da
Function_PartyCountEq3: ; 8b2da
ld a, [PartyCount]
- cp 3
+ cp BATTLETOWER_NROFPKMNS
ret z
scf
ret