Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/battle/read_trainer_party.asm
1271 views
1
ReadTrainer:
2
3
; don't change any moves in a link battle
4
ld a, [wLinkState]
5
and a
6
ret nz
7
8
; set [wEnemyPartyCount] to 0, [wEnemyPartySpecies] to FF
9
; XXX first is total enemy pokemon?
10
; XXX second is species of first pokemon?
11
ld hl, wEnemyPartyCount
12
xor a
13
ld [hli], a
14
dec a
15
ld [hl], a
16
17
; get the pointer to trainer data for this class
18
ld a, [wCurOpponent]
19
sub OPP_ID_OFFSET + 1 ; convert value from pokemon to trainer
20
add a
21
ld hl, TrainerDataPointers
22
ld c, a
23
ld b, 0
24
add hl, bc ; hl points to trainer class
25
ld a, [hli]
26
ld h, [hl]
27
ld l, a
28
ld a, [wTrainerNo]
29
ld b, a
30
; At this point b contains the trainer number,
31
; and hl points to the trainer class.
32
; Our next task is to iterate through the trainers,
33
; decrementing b each time, until we get to the right one.
34
.CheckNextTrainer
35
dec b
36
jr z, .IterateTrainer
37
.SkipTrainer
38
ld a, [hli]
39
and a
40
jr nz, .SkipTrainer
41
jr .CheckNextTrainer
42
43
; if the first byte of trainer data is FF,
44
; - each pokemon has a specific level
45
; (as opposed to the whole team being of the same level)
46
; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
47
; else the first byte is the level of every pokemon on the team
48
.IterateTrainer
49
ld a, [hli]
50
cp $FF ; is the trainer special?
51
jr z, .SpecialTrainer ; if so, check for special moves
52
ld [wCurEnemyLevel], a
53
.LoopTrainerData
54
ld a, [hli]
55
and a ; have we reached the end of the trainer data?
56
jr z, .FinishUp
57
ld [wCurPartySpecies], a
58
ld a, ENEMY_PARTY_DATA
59
ld [wMonDataLocation], a
60
push hl
61
call AddPartyMon
62
pop hl
63
jr .LoopTrainerData
64
.SpecialTrainer
65
; if this code is being run:
66
; - each pokemon has a specific level
67
; (as opposed to the whole team being of the same level)
68
; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
69
ld a, [hli]
70
and a ; have we reached the end of the trainer data?
71
jr z, .AddLoneMove
72
ld [wCurEnemyLevel], a
73
ld a, [hli]
74
ld [wCurPartySpecies], a
75
ld a, ENEMY_PARTY_DATA
76
ld [wMonDataLocation], a
77
push hl
78
call AddPartyMon
79
pop hl
80
jr .SpecialTrainer
81
.AddLoneMove
82
; does the trainer have a single monster with a different move?
83
ld a, [wLoneAttackNo] ; Brock is 01, Misty is 02, Erika is 04, etc
84
and a
85
jr z, .AddTeamMove
86
dec a
87
add a
88
ld c, a
89
ld b, 0
90
ld hl, LoneMoves
91
add hl, bc
92
ld a, [hli]
93
ld d, [hl]
94
ld hl, wEnemyMon1Moves + 2
95
ld bc, wEnemyMon2 - wEnemyMon1
96
call AddNTimes
97
ld [hl], d
98
jr .FinishUp
99
.AddTeamMove
100
; check if our trainer's team has special moves
101
102
; get trainer class number
103
ld a, [wCurOpponent]
104
sub OPP_ID_OFFSET
105
ld b, a
106
ld hl, TeamMoves
107
108
; iterate through entries in TeamMoves, checking each for our trainer class
109
.IterateTeamMoves
110
ld a, [hli]
111
cp b
112
jr z, .GiveTeamMoves ; is there a match?
113
inc hl ; if not, go to the next entry
114
inc a
115
jr nz, .IterateTeamMoves
116
117
; no matches found. is this trainer champion rival?
118
ld a, b
119
cp RIVAL3
120
jr z, .ChampionRival
121
jr .FinishUp ; nope
122
.GiveTeamMoves
123
ld a, [hl]
124
ld [wEnemyMon5Moves + 2], a
125
jr .FinishUp
126
.ChampionRival ; give moves to his team
127
128
; pidgeot
129
ld a, SKY_ATTACK
130
ld [wEnemyMon1Moves + 2], a
131
132
; starter
133
ld a, [wRivalStarter]
134
cp STARTER3
135
ld b, MEGA_DRAIN
136
jr z, .GiveStarterMove
137
cp STARTER1
138
ld b, FIRE_BLAST
139
jr z, .GiveStarterMove
140
ld b, BLIZZARD ; must be squirtle
141
.GiveStarterMove
142
ld a, b
143
ld [wEnemyMon6Moves + 2], a
144
.FinishUp
145
; clear wAmountMoneyWon addresses
146
xor a
147
ld de, wAmountMoneyWon
148
ld [de], a
149
inc de
150
ld [de], a
151
inc de
152
ld [de], a
153
ld a, [wCurEnemyLevel]
154
ld b, a
155
.LastLoop
156
; update wAmountMoneyWon addresses (money to win) based on enemy's level
157
ld hl, wTrainerBaseMoney + 1
158
ld c, 2 ; wAmountMoneyWon is a 3-byte number
159
push bc
160
predef AddBCDPredef
161
pop bc
162
inc de
163
inc de
164
dec b
165
jr nz, .LastLoop ; repeat wCurEnemyLevel times
166
ret
167
168