1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
Enemy trainers all have set text that gets printed when you win a battle with them. They also have space to set text for when you lose, but that only works for battles you can lose, and the only such battle is the first one with your rival in Cherrygrove City:

It turns out that all the other rival battles have unused loss text ([documented on The Cutting Room Floor](https://tcrf.net/Pok%C3%A9mon_Gold_and_Silver/Unused_Text)); and the battle with Red is also set to use the same "…" text whether you win or lose. Other trainers don't bother to set loss text, and just use 0 as a placeholder. For example, in [maps/Route30.asm](../blob/master/maps/Route30.asm):
```
TrainerYoungsterJoey:
trainer YOUNGSTER, JOEY1, EVENT_BEAT_YOUNGSTER_JOEY, YoungsterJoey1SeenText, YoungsterJoey1BeatenText, 0, .Script
```
And in [maps/VioletGym.asm](../blob/master/maps/VioletGym.asm):
```
VioletGymFalknerScript:
...
winlosstext UnknownText_0x6854a, 0
loadtrainer FALKNER, FALKNER1
startbattle
reloadmapafterbattle
```
Anyway, it's quite simple to enable this feature. Edit [engine/battle/core.asm](../blob/master/engine/battle/core.asm):
```diff
LostBattle:
ld a, 1
ld [wBattleEnded], a
ld a, [wInBattleTowerBattle]
bit 0, a
jr nz, .battle_tower
- ld a, [wBattleType]
- cp BATTLETYPE_CANLOSE
- jr nz, .not_canlose
+ ld a, [wBattleMode]
+ dec a ; wild?
+ jr z, .no_loss_text
+
+ ld hl, wLossTextPointer
+ ld a, [hli]
+ ld h, [hl]
+ and h
+ jr z, .no_loss_text
; Remove the enemy from the screen.
hlcoord 0, 0
lb bc, 8, 21
call ClearBox
call BattleWinSlideInEnemyTrainerFrontpic
ld c, 40
call DelayFrames
ld a, [wDebugFlags]
bit DEBUG_BATTLE_F, a
jr nz, .skip_win_loss_text
call PrintWinLossText
.skip_win_loss_text
ret
.battle_tower
; Remove the enemy from the screen.
hlcoord 0, 0
lb bc, 8, 21
call ClearBox
call BattleWinSlideInEnemyTrainerFrontpic
ld c, 40
call DelayFrames
call EmptyBattleTextbox
ld c, BATTLETOWERTEXT_WIN_TEXT
farcall BattleTowerText
call WaitPressAorB_BlinkCursor
call ClearTileMap
call ClearBGPalettes
ret
-.not_canlose
+.no_loss_text
ld a, [wLinkMode]
and a
jr nz, .LostLinkBattle
```
Now if you lose a trainer battle and `[wLossTextPointer]` is nonzero, the text will be printed, regardless of what the battle type is.
There's one more thing to do. Edit [maps/Route24.asm](../blob/master/maps/Route24.asm):
```diff
Route24RocketScript:
faceplayer
playmusic MUSIC_ROCKET_ENCOUNTER
opentext
writetext Route24RocketSeenText
waitbutton
closetext
- winlosstext Route24RocketBeatenText, -1
+ winlosstext Route24RocketBeatenText, 0
loadtrainer GRUNTM, GRUNTM_31
startbattle
dontrestartmapmusic
reloadmapafterbattle
...
```
If you lost against this Rocket Grunt, it would try printing text at `[-1]`, which might glitch or crash the game. We just had to set it to the usual 0 for no loss text.
Now we're done!

You can optionally edit [home/trainers.asm](../blob/master/home/trainers.asm):
```diff
PrintWinLossText::
- ld a, [wBattleType]
- cp BATTLETYPE_CANLOSE
- jr .canlose ; ??????????
-
-; unused
- ld hl, wWinTextPointer
- jr .ok
-
-.canlose
ld a, [wBattleResult]
ld hl, wWinTextPointer
and $f ; WIN?
jr z, .ok
ld hl, wLossTextPointer
.ok
ld a, [hli]
ld h, [hl]
ld l, a
call GetMapScriptsBank
call FarPrintText
call WaitBGMap
call WaitPressAorB_BlinkCursor
ret
```
That removes some vestigial code which looks like Game Freak planned to check for `BATTLETYPE_CANLOSE` here instead of in `LostBattle`. (This would have worked if `jr .canlose` had been `jr z, .canlose`.) Removing this code doesn't affect gameplay, but it does save ROM space, which is especially useful in the home bank.
|