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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
#include "global.h"
#include "battle_records.h"
#include "game_stat.h"
#include "link.h"
#include "menu.h"
#include "overworld.h"
#include "string_util.h"
#include "strings2.h"
#include "trainer_card.h"
extern struct LinkPlayerMapObject gLinkPlayerMapObjects[4];
extern u8 gBattleOutcome;
static void InitLinkBattleRecord(struct LinkBattleRecord *record)
{
CpuFill16(0, record, sizeof(struct LinkBattleRecord));
record->name[0] = 0xFF;
record->trainerId = 0;
record->wins = 0;
record->losses = 0;
record->draws = 0;
}
static void InitLinkBattleRecords_(struct LinkBattleRecord *records)
{
int i;
for (i = 0; i < 5; i++)
{
InitLinkBattleRecord(records + i);
}
SetGameStat(GAME_STAT_LINK_BATTLE_WINS, 0);
SetGameStat(GAME_STAT_LINK_BATTLE_LOSSES, 0);
SetGameStat(GAME_STAT_LINK_BATTLE_DRAWS, 0);
}
static int GetLinkBattleRecordTotalBattles(struct LinkBattleRecord *record)
{
return record->wins + record->losses + record->draws;
}
static int FindLinkBattleRecord(struct LinkBattleRecord *records, u8 *name, u16 trainerId)
{
int i;
for (i = 0; i < 5; i++)
{
memcpy(gStringVar1, records[i].name, 7);
gStringVar1[7] = EOS;
if (!StringCompareWithoutExtCtrlCodes(gStringVar1, name) && records[i].trainerId == trainerId)
return i;
}
return 5;
}
static void SortLinkBattleRecords(struct LinkBattleRecord *records)
{
int i, j;
for (i = 4; i > 0; i--)
{
for (j = i - 1; j >= 0; j--)
{
int totalBattlesI = GetLinkBattleRecordTotalBattles(records + i);
int totalBattlesJ = GetLinkBattleRecordTotalBattles(records + j);
if (totalBattlesI > totalBattlesJ)
{
struct LinkBattleRecord temp = *(records + i);
*(records + i) = *(records + j);
*(records + j) = temp;
}
}
}
}
static void UpdateLinkBattleRecord(struct LinkBattleRecord *record, int battleOutcome)
{
switch (battleOutcome)
{
case 1:
record->wins++;
if (record->wins > 9999)
record->wins = 9999;
break;
case 2:
record->losses++;
if (record->losses > 9999)
record->losses = 9999;
break;
case 3:
record->draws++;
if (record->draws > 9999)
record->draws = 9999;
break;
}
}
static void UpdateLinkBattleGameStats(int battleOutcome)
{
u8 stat;
switch (battleOutcome)
{
case 1:
stat = GAME_STAT_LINK_BATTLE_WINS;
break;
case 2:
stat = GAME_STAT_LINK_BATTLE_LOSSES;
break;
case 3:
stat = GAME_STAT_LINK_BATTLE_DRAWS;
break;
default:
return;
}
if (GetGameStat(stat) < 9999)
IncrementGameStat(stat);
}
static void UpdateLinkBattleRecords_(struct LinkBattleRecord *records, u8 *name, u16 trainerId, int battleOutcome, u8 language)
{
int index;
UpdateLinkBattleGameStats(battleOutcome);
SortLinkBattleRecords(records);
index = FindLinkBattleRecord(records, name, trainerId);
if (index == 5)
{
index = 4;
InitLinkBattleRecord(records + index);
if (language == LANGUAGE_JAPANESE)
{
records[index].name[0] = EXT_CTRL_CODE_BEGIN;
records[index].name[1] = 0x15;
StringCopyN(records[index].name + 2, name, 5);
}
else
{
StringCopyN(records[index].name, name, 7);
}
// needed block to match
{
struct LinkBattleRecord *record = records + index;
record->trainerId = trainerId;
}
}
UpdateLinkBattleRecord(records + index, battleOutcome);
SortLinkBattleRecords(records);
}
void InitLinkBattleRecords(void)
{
InitLinkBattleRecords_(gSaveBlock1.linkBattleRecords);
}
static void IncTrainerCardWins(int id)
{
u16 *wins = &gTrainerCards[id].linkBattleWins;
(*wins)++;
if (*wins > 9999)
*wins = 9999;
}
static void IncTrainerCardLosses(int id)
{
u16 *losses = &gTrainerCards[id].linkBattleLosses;
(*losses)++;
if (*losses > 9999)
*losses = 9999;
}
static void UpdateTrainerCardWinsLosses(int id)
{
switch (gBattleOutcome)
{
case 1:
IncTrainerCardWins(id ^ 1);
IncTrainerCardLosses(id);
break;
case 2:
IncTrainerCardLosses(id ^ 1);
IncTrainerCardWins(id);
break;
}
}
void UpdateLinkBattleRecords(int id)
{
UpdateTrainerCardWinsLosses(id);
UpdateLinkBattleRecords_(
gSaveBlock1.linkBattleRecords,
gTrainerCards[id].playerName,
gTrainerCards[id].trainerId,
gBattleOutcome,
gLinkPlayers[gLinkPlayerMapObjects[id].linkPlayerId].language);
}
static void PrintLinkBattleWinsLossesDraws(struct LinkBattleRecord *records)
{
ConvertIntToDecimalStringN_DigitWidth6(gStringVar1, GetGameStat(GAME_STAT_LINK_BATTLE_WINS), STR_CONV_MODE_RIGHT_ALIGN, 4);
ConvertIntToDecimalStringN_DigitWidth6(gStringVar2, GetGameStat(GAME_STAT_LINK_BATTLE_LOSSES), STR_CONV_MODE_RIGHT_ALIGN, 4);
ConvertIntToDecimalStringN_DigitWidth6(gStringVar3, GetGameStat(GAME_STAT_LINK_BATTLE_DRAWS), STR_CONV_MODE_RIGHT_ALIGN, 4);
MenuPrint(gOtherText_WinRecord, 3, 3);
}
static void PrintLinkBattleRecord(struct LinkBattleRecord *record, u8 y)
{
if (!record->wins && !record->losses && !record->draws)
{
u8 buffer[16];
buffer[0] = EXT_CTRL_CODE_BEGIN;
buffer[1] = 0x14;
buffer[2] = 6;
buffer[3] = EXT_CTRL_CODE_BEGIN;
buffer[4] = 0x11;
buffer[5] = 1;
StringCopy(buffer + 6, gOtherText_SevenDashes);
MenuPrint(buffer, 3, y);
StringCopy(buffer + 6, gOtherText_FourDashes);
MenuPrint(buffer, 11, y);
MenuPrint(buffer, 17, y);
MenuPrint(buffer, 23, y);
}
else
{
StringFillWithTerminator(gStringVar1, 8);
StringCopyN(gStringVar1, record->name, 7);
MenuPrint(gStringVar1, 3, y);
gStringVar1[0] = EXT_CTRL_CODE_BEGIN;
gStringVar1[1] = 0x14;
gStringVar1[2] = 6;
ConvertIntToDecimalStringN(gStringVar1 + 3, record->wins, STR_CONV_MODE_RIGHT_ALIGN, 4);
MenuPrint(gStringVar1, 11, y);
ConvertIntToDecimalStringN(gStringVar1 + 3, record->losses, STR_CONV_MODE_RIGHT_ALIGN, 4);
MenuPrint(gStringVar1, 17, y);
ConvertIntToDecimalStringN(gStringVar1 + 3, record->draws, STR_CONV_MODE_RIGHT_ALIGN, 4);
MenuPrint(gStringVar1, 23, y);
}
}
void ShowLinkBattleRecords(void) {
s32 i;
MenuDrawTextWindow(1, 0, 28, 18);
sub_8072BD8((u8 *) gOtherText_BattleResults, 0, 1, 240);
PrintLinkBattleWinsLossesDraws(gSaveBlock1.linkBattleRecords);
#if ENGLISH
MenuPrint(gOtherText_WinLoseDraw, 12, 6);
#elif GERMAN
MenuPrint_PixelCoords(gOtherText_WinLoseDraw, 88, 48, 1);
#endif
for (i = 0; i < 5; i++)
{
PrintLinkBattleRecord(&gSaveBlock1.linkBattleRecords[i], 6 + (i + 1) * 2);
}
}
static bool32 sub_8110494(u8 level)
{
struct SaveBlock2_Sub *sb2sub = &gSaveBlock2.filler_A8;
switch (sb2sub->var_4AE[level])
{
case 0:
return FALSE;
case 1:
return FALSE;
case 2:
return TRUE;
case 4:
return FALSE;
case 3:
return TRUE;
case 5:
return FALSE;
case 6:
return TRUE;
default:
return FALSE;
}
}
static void PrintWinStreak(const u8 *str, u16 streak, u8 left, u8 top)
{
MenuPrint(str, left, top);
if (streak > 9999)
streak = 9999;
sub_8072C14(gStringVar1, streak, 24, 1);
MenuPrint(gOtherText_WinStreak, left + 7, top);
}
static void PrintRecordWinStreak(u8 level, u8 left, u8 top)
{
struct SaveBlock2_Sub *sb2sub = &gSaveBlock2.filler_A8;
u16 winStreak = sb2sub->recordWinStreak[level];
PrintWinStreak(gOtherText_Record, winStreak, left, top);
}
static u16 GetLastWinStreak(u8 level)
{
u16 result = gSaveBlock2.filler_A8.winStreak[level];
if (result > 9999)
result = 9999;
return result;
}
static void PrintLastWinStreak(u8 level, u8 left, u8 top)
{
u16 winStreak = GetLastWinStreak(level);
if (sub_8110494(level) == TRUE)
PrintWinStreak(gOtherText_Current, winStreak, left, top);
else
PrintWinStreak(gOtherText_Prev, winStreak, left, top);
}
void ShowBattleTowerRecords(void)
{
u16 i;
MenuDrawTextWindow(3, 1, 27, 17);
sub_8072BD8(gOtherText_BattleTowerResults, 3, 2, 0xC8);
MenuPrint(gOtherText_Lv50, 5, 6);
MenuPrint(gOtherText_Lv100, 5, 12);
for (i = 5; i < 26; i++)
{
sub_8071F60(CHAR_HYPHEN, i, 10);
}
PrintLastWinStreak(0, 10, 6);
PrintRecordWinStreak(0, 10, 8);
PrintLastWinStreak(1, 10, 12);
PrintRecordWinStreak(1, 10, 14);
}
|