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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
#include "global.h"
#include "battle_records.h"
#include "constants/game_stat.h"
#include "link.h"
#include "menu.h"
#include "overworld.h"
#include "string_util.h"
#include "strings2.h"
#include "trainer_card.h"
struct DebugStruct1
{
u16 var0;
u8 var1[10];
};
extern struct LinkPlayerMapObject gLinkPlayerMapObjects[4];
extern u8 gBattleOutcome;
#if DEBUG
const struct DebugStruct1 gUnknown_Debug_4245CC[] =
{
{ 1, _("NUMBER1") },
{ 2, _("ナンバー2") },
{ 3, _("ナンバー3") },
{ 4, _("ナンバー4") },
{ 5, _("ナンバー5") },
{ 6, _("ナンバー6") },
{ 7, _("ナンバー7") },
};
const u8 gUnknown_Debug_8424620[][4] =
{
{ 1, 1, 0, 0 },
{ 2, 1, 0, 0 },
{ 3, 1, 0, 0 },
};
#endif
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);
}
#if DEBUG
__attribute__((naked))
void debug_sub_81257E0(void)
{
asm("\
push {r4, r5, r6, r7, lr}\n\
mov r7, r8\n\
push {r7}\n\
add sp, sp, #0xfffffffc\n\
bl InitLinkBattleRecords\n\
mov r5, #0x0\n\
ldr r6, ._62 @ gUnknown_Debug_4245CC\n\
sub r0, r6, #2\n\
mov r8, r0\n\
ldr r7, ._62 + 4 @ gLinkPlayers\n\
._61:\n\
ldr r0, ._62 + 8 @ gUnknown_Debug_8424620\n\
lsl r3, r5, #0x2\n\
add r3, r3, r0\n\
ldrb r4, [r3]\n\
sub r4, r4, #0x1\n\
lsl r0, r4, #0x1\n\
add r0, r0, r4\n\
lsl r0, r0, #0x2\n\
add r1, r0, r6\n\
add r0, r0, r8\n\
ldrh r2, [r0]\n\
ldrb r3, [r3, #0x1]\n\
ldr r0, ._62 + 12 @ gLinkPlayerMapObjects\n\
lsl r4, r4, #0x2\n\
add r4, r4, r0\n\
ldrb r4, [r4, #0x1]\n\
lsl r0, r4, #0x3\n\
sub r0, r0, r4\n\
lsl r0, r0, #0x2\n\
add r0, r0, r7\n\
ldrb r0, [r0, #0x1a]\n\
str r0, [sp]\n\
ldr r0, ._62 + 16 @ gSaveBlock1\n\
bl UpdateLinkBattleRecords_\n\
add r5, r5, #0x1\n\
cmp r5, #0x2\n\
bls ._61 @cond_branch\n\
add sp, sp, #0x4\n\
pop {r3}\n\
mov r8, r3\n\
pop {r4, r5, r6, r7}\n\
pop {r0}\n\
bx r0\n\
._63:\n\
.align 2, 0\n\
._62:\n\
.word gUnknown_Debug_4245CC+2\n\
.word gLinkPlayers\n\
.word gUnknown_Debug_8424620\n\
.word gLinkPlayerMapObjects\n\
.word gSaveBlock1+0x30b8");
}
#endif
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);
Menu_PrintText(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);
Menu_PrintText(buffer, 3, y);
StringCopy(buffer + 6, gOtherText_FourDashes);
Menu_PrintText(buffer, 11, y);
Menu_PrintText(buffer, 17, y);
Menu_PrintText(buffer, 23, y);
}
else
{
StringFillWithTerminator(gStringVar1, 8);
StringCopyN(gStringVar1, record->name, 7);
Menu_PrintText(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);
Menu_PrintText(gStringVar1, 11, y);
ConvertIntToDecimalStringN(gStringVar1 + 3, record->losses, STR_CONV_MODE_RIGHT_ALIGN, 4);
Menu_PrintText(gStringVar1, 17, y);
ConvertIntToDecimalStringN(gStringVar1 + 3, record->draws, STR_CONV_MODE_RIGHT_ALIGN, 4);
Menu_PrintText(gStringVar1, 23, y);
}
}
void ShowLinkBattleRecords(void)
{
s32 i;
Menu_DrawStdWindowFrame(1, 0, 28, 18);
sub_8072BD8(gOtherText_BattleResults, 0, 1, 240);
PrintLinkBattleWinsLossesDraws(gSaveBlock1.linkBattleRecords);
#if ENGLISH
Menu_PrintText(gOtherText_WinLoseDraw, 12, 6);
#elif GERMAN
Menu_PrintTextPixelCoords(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 BattleTowerData *battleTower = &gSaveBlock2.battleTower;
switch (battleTower->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)
{
Menu_PrintText(str, left, top);
if (streak > 9999)
streak = 9999;
sub_8072C14(gStringVar1, streak, 24, 1);
Menu_PrintText(gOtherText_WinStreak, left + 7, top);
}
static void PrintRecordWinStreak(u8 level, u8 left, u8 top)
{
struct BattleTowerData *battleTower = &gSaveBlock2.battleTower;
u16 winStreak = battleTower->recordWinStreaks[level];
PrintWinStreak(gOtherText_Record, winStreak, left, top);
}
static u16 GetLastWinStreak(u8 level)
{
u16 winStreak = gSaveBlock2.battleTower.currentWinStreaks[level];
if (winStreak > 9999)
winStreak = 9999;
return winStreak;
}
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;
Menu_DrawStdWindowFrame(3, 1, 27, 17);
sub_8072BD8(gOtherText_BattleTowerResults, 3, 2, 0xC8);
Menu_PrintText(gOtherText_Lv50, 5, 6);
Menu_PrintText(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);
}
|