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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
|
#ifndef GUARD_BATTLE_H
#define GUARD_BATTLE_H
#include "sprite.h"
#include "constants/battle.h"
#include "battle_setup.h"
#include "main.h"
#define GET_BATTLER_POSITION(battler) (gBattlerPositions[battler])
#define GET_BATTLER_SIDE(battler) (GetBattlerPosition(battler) & BIT_SIDE)
#define GET_BATTLER_SIDE2(battler) (GET_BATTLER_POSITION(battler) & BIT_SIDE)
// Battle Actions
// These determine what each battler will do in a turn
#define B_ACTION_USE_MOVE 0
#define B_ACTION_USE_ITEM 1
#define B_ACTION_SWITCH 2
#define B_ACTION_RUN 3
#define B_ACTION_SAFARI_WATCH_CAREFULLY 4
#define B_ACTION_SAFARI_BALL 5
#define B_ACTION_SAFARI_POKEBLOCK 6
#define B_ACTION_SAFARI_GO_NEAR 7
#define B_ACTION_SAFARI_RUN 8
// The exact purposes of these are unclear
#define B_ACTION_WALLY_THROW 9
#define B_ACTION_EXEC_SCRIPT 10 // when executing an action
#define B_ACTION_TRY_FINISH 11
#define B_ACTION_FINISHED 12 // when executing an action
#define B_ACTION_CANCEL_PARTNER 12 // when choosing an action
#define B_ACTION_NOTHING_FAINTED 13 // when choosing an action
#define B_ACTION_NONE 0xFF
#define MAX_TRAINER_ITEMS 4
#define MAX_MON_MOVES 4
// array entries for battle communication
#define MULTIUSE_STATE 0x0
#define CURSOR_POSITION 0x1
#define TASK_ID 0x1 // task Id and cursor position share the same field
#define SPRITES_INIT_STATE1 0x1 // shares the Id as well
#define SPRITES_INIT_STATE2 0x2
#define MOVE_EFFECT_BYTE 0x3
#define ACTIONS_CONFIRMED_COUNT 0x4
#define MULTISTRING_CHOOSER 0x5
#define MSG_DISPLAY 0x7
#define BATTLE_COMMUNICATION_ENTRIES_COUNT 0x8
#define MOVE_TARGET_SELECTED 0x0
#define MOVE_TARGET_DEPENDS 0x1
#define MOVE_TARGET_USER_OR_SELECTED 0x2
#define MOVE_TARGET_RANDOM 0x4
#define MOVE_TARGET_BOTH 0x8
#define MOVE_TARGET_USER 0x10
#define MOVE_TARGET_FOES_AND_ALLY 0x20
#define MOVE_TARGET_OPPONENTS_FIELD 0x40
// defines for the u8 array gTypeEffectiveness
#define TYPE_EFFECT_ATK_TYPE(i)((gTypeEffectiveness[i + 0]))
#define TYPE_EFFECT_DEF_TYPE(i)((gTypeEffectiveness[i + 1]))
#define TYPE_EFFECT_MULTIPLIER(i)((gTypeEffectiveness[i + 2]))
// defines for the gTypeEffectiveness multipliers
#define TYPE_MUL_NO_EFFECT 0
#define TYPE_MUL_NOT_EFFECTIVE 5
#define TYPE_MUL_NORMAL 10
#define TYPE_MUL_SUPER_EFFECTIVE 20
// special type table Ids
#define TYPE_FORESIGHT 0xFE
#define TYPE_ENDTABLE 0xFF
struct DisableStruct
{
/*0x00*/ u32 transformedMonPersonality;
/*0x04*/ u16 disabledMove;
/*0x06*/ u16 encoredMove;
/*0x08*/ u8 protectUses;
/*0x09*/ u8 stockpileCounter;
/*0x0A*/ u8 substituteHP;
/*0x0B*/ u8 disableTimer1 : 4;
/*0x0B*/ u8 disableTimer2 : 4;
/*0x0C*/ u8 encoredMovePos;
/*0x0D*/ u8 unkD;
/*0x0E*/ u8 encoreTimer1 : 4;
/*0x0E*/ u8 encoreTimer2 : 4;
/*0x0F*/ u8 perishSongTimer1 : 4;
/*0x0F*/ u8 perishSongTimer2 : 4;
/*0x10*/ u8 furyCutterCounter;
/*0x11*/ u8 rolloutTimer1 : 4;
/*0x11*/ u8 rolloutTimer2 : 4;
/*0x12*/ u8 chargeTimer1 : 4;
/*0x12*/ u8 chargeTimer2 : 4;
/*0x13*/ u8 tauntTimer1:4;
/*0x13*/ u8 tauntTimer2:4;
/*0x14*/ u8 bankPreventingEscape;
/*0x15*/ u8 battlerWithSureHit;
/*0x16*/ u8 isFirstTurn;
/*0x17*/ u8 unk17;
/*0x18*/ u8 truantCounter : 1;
/*0x18*/ u8 unk18_a : 3;
/*0x18*/ u8 mimickedMoves : 4;
/*0x19*/ u8 rechargeCounter;
/*0x1A*/ u8 unk1A[2];
};
struct ProtectStruct
{
/*field0*/
u32 protected:1;
u32 endured:1;
u32 noValidMoves:1;
u32 helpingHand:1;
u32 bounceMove:1;
u32 stealMove:1;
u32 flag0Unknown:1;
u32 prlzImmobility:1;
/*field1*/
u32 confusionSelfDmg:1;
u32 targetNotAffected:1;
u32 chargingTurn:1;
u32 fleeFlag:2; // For RunAway and Smoke Ball.
u32 usedImprisonedMove:1;
u32 loveImmobility:1;
u32 usedDisabledMove:1;
/*field2*/
u32 usedTauntedMove:1;
u32 flag2Unknown:1;
u32 flinchImmobility:1;
u32 notFirstStrike:1;
u32 free : 4;
/*field3*/
u32 field3 : 8;
s32 physicalDmg;
s32 specialDmg;
u8 physicalBattlerId;
u8 specialBattlerId;
u16 fieldE;
};
struct SpecialStatus
{
u32 statLowered:1;
u32 lightningRodRedirected:1;
u32 restoredBattlerSprite: 1;
u32 intimidatedMon:1;
u32 traced:1;
u32 ppNotAffectedByPressure:1;
u32 flag40:1;
u32 focusBanded:1;
s32 dmg;
s32 physicalDmg;
s32 specialDmg;
u8 physicalBattlerId;
u8 specialBattlerId;
u8 field12;
u8 field13;
};
struct SideTimer
{
u8 reflectTimer; //0x0
u8 lightscreenTimer; //0x1
u8 mistTimer; //0x2
u8 field3; //0x3
u16 field4; //0x4
u8 spikesAmount; //0x6
u8 safeguardTimer; //0x7
u8 followmeTimer; //0x8
u8 followmeTarget; //0x9
u8 fieldA; //0xA
u8 fieldB; //0xB
};
struct WishFutureKnock
{
u8 futureSightCounter[MAX_BATTLERS_COUNT];
u8 futureSightAttacker[MAX_BATTLERS_COUNT];
s32 futureSightDmg[MAX_BATTLERS_COUNT];
u16 futureSightMove[MAX_BATTLERS_COUNT];
u8 wishCounter[MAX_BATTLERS_COUNT];
u8 wishMonId[MAX_BATTLERS_COUNT];
u8 weatherDuration;
u8 knockedOffPokes[2];
};
struct AI_ThinkingStruct /* 0x2016800 */
{
/*0x00*/ u8 aiState;
/*0x01*/ u8 movesetIndex;
/*0x02*/ u16 moveConsidered;
/*0x04*/ s8 score[4]; // score?
/*0x08*/ u32 funcResult;
/*0x0C*/ u32 aiFlags;
/*0x10*/ u8 aiAction;
/*0x11*/ u8 aiLogicId;
/*0x12*/ u8 filler12[6];
/*0x18*/ u8 simulatedRNG[4];
};
struct BattleHistory
{
/*0x00*/ u16 usedMoves[2][8]; // 0xFFFF means move not used (confuse self hit, etc)
/*0x20*/ u8 abilities[MAX_BATTLERS_COUNT / 2];
/*0x22*/ u8 itemEffects[MAX_BATTLERS_COUNT / 2];
/*0x24*/ u16 trainerItems[MAX_BATTLERS_COUNT];
/*0x2C*/ u8 numItems;
};
struct BattleScriptsStack
{
const u8 *ptr[8];
u8 size;
};
struct BattleCallbacksStack
{
void* ptr[8];
u8 size;
};
struct StatsArray
{
u16 hp;
u16 atk;
u16 def;
u16 spd;
u16 spAtk;
u16 spDef;
};
struct BattleResults
{
u8 playerFaintCounter; // 0x0
u8 opponentFaintCounter; // 0x1
u8 totalMonSwitchCounter; // 0x2
u8 playerHealInBattleCount; // 0x3
u8 reviveCount; // 0x4
u8 playerMonWasDamaged:1; // 0x5
u8 usedMasterBall:1; // 0x5
u16 poke1Species; // 0x6
u8 pokeString1[10]; // 0x8
u8 unk12; // unused
u8 battleTurnCounter; // 0x13
u8 pokeString2[10]; // 0x14
u8 filler1E[2];
u16 lastOpponentSpecies; // 0x20
u16 lastUsedMove; // 0x22
u16 opponentMove; // 0x24
u16 opponentSpecies; // 0x26
u16 caughtPoke; // 0x28
u8 caughtNick[10]; // 0x2A
u8 filler34[2];
u8 usedBalls[11];
};
union TrainerMonPtr
{
const struct TrainerMonNoItemDefaultMoves *NoItemDefaultMoves;
const struct TrainerMonNoItemCustomMoves *NoItemCustomMoves;
const struct TrainerMonItemDefaultMoves *ItemDefaultMoves;
const struct TrainerMonItemCustomMoves *ItemCustomMoves;
};
struct Trainer
{
/*0x00*/ u8 partyFlags;
/*0x01*/ u8 trainerClass;
/*0x02*/ u8 encounterMusic_gender;
/*0x03*/ u8 trainerPic;
/*0x04*/ u8 trainerName[12];
/*0x10*/ u16 items[4];
/*0x18*/ bool8 doubleBattle;
/*0x1C*/ u32 aiFlags;
/*0x20*/ u8 partySize;
/*0x24*/ union TrainerMonPtr party;
};
struct AI_Stack
{
u8 *ptr[8];
u8 size;
};
struct LinkPartnerHeader
{
u8 versionSignatureLo;
u8 versionSignatureHi;
u8 vsScreenHealthFlagsLo;
u8 vsScreenHealthFlagsHi;
struct BattleEnigmaBerry battleEnigmaBerry;
};
union MultiBuffers
{
struct LinkPartnerHeader linkPartnerHeader;
struct MultiBattlePokemonTx multiBattleMons[3];
};
// Used internally
struct LinkBattleCommunicationHeader
{
u8 state;
u8 activeBattler;
u8 battlerAttacker;
u8 battlerTarget;
u16 size;
u8 absentBattlerFlags;
u8 effectBattler;
u8 data[0];
};
struct ChooseMoveStruct {
u16 moves[4];
u8 currentPp[4];
u8 maxPp[4];
u16 species;
u8 monType1;
u8 monType2;
};
struct BattleStruct /* 0x2000000 */
{
u8 filler00000[0x14000];
/*0x14000*/ u8 linkSend[0x1000];
/*0x15000*/ u8 linkRecv[0x1000];
/*0x16000*/ u8 turnEffectsTracker;
/*0x16001*/ u8 turnEffectsBattlerId;
/*0x16002*/ u8 animTurn;
/*0x16003*/ u8 scriptingActive;
/*0x16004*/ u8 wrappedMove[MAX_BATTLERS_COUNT * 2];
/*0x1600C*/ u8 cmd49StateTracker;
/*0x1600D*/ u8 unk1600D; // unused
/*0x1600E*/ u8 turnCountersTracker;
/*0x1600F*/ u8 getexpStateTracker;
/*0x16010*/ u8 moveTarget[MAX_BATTLERS_COUNT];
/*0x16014*/ u32 painSplitHP;
/*0x16018*/ u8 expGetterMonId;
/*0x16019*/ u8 unk16019; // unused
/*0x1601A*/ u8 atk5A_StateTracker; //also atk5B, statetracker
/*0x1601B*/ u8 wildVictorySong;
/*0x1601C*/ u8 dynamicMoveType;
/*0x1601D*/ u8 focusPunchBattler;
/*0x1601E*/ u8 statChanger;
/*0x1601F*/ u8 dmgMultiplier;
/*0x16020*/ u8 wrappedBy[MAX_BATTLERS_COUNT];
/*0x16024*/ u16 assistMove[PARTY_SIZE * MAX_MON_MOVES];
/*0x16054*/ u8 battlerPreventingSwitchout;
/*0x16055*/ u8 unk16055; // unused
/*0x16056*/ u8 moneyMultiplier;
/*0x16057*/ u8 savedTurnActionNumber;
/*0x16058*/ u8 switchInAbilitiesCounter;
/*0x16059*/ u8 faintedActionsState;
/*0x1605A*/ u8 faintedActionsBattlerId;
/*0x1605C*/ u16 exp;
/*0x1605E*/ u8 unk1605E;
/*0x1605F*/ u8 sentInPokes;
/*0x16060*/ u8 selectionScriptFinished[MAX_BATTLERS_COUNT];
/*0x16064*/ u8 unk16064[MAX_BATTLERS_COUNT];
/*0x16068*/ u8 monToSwitchIntoId[MAX_BATTLERS_COUNT];
/*0x1606C*/ u8 unk1606C[MAX_BATTLERS_COUNT][3];
/*0x16078*/ u8 runTries;
/*0x16079*/ u8 caughtNick[POKEMON_NAME_LENGTH + 1];
/*0x16084*/ u8 battleStyle;
/*0x16085*/ u8 unk16085;
/*0x16086*/ u8 safariGoNearCounter;
/*0x16087*/ u8 safariPkblThrowCounter;
/*0x16088*/ u8 safariFleeRate;
/*0x16089*/ u8 safariCatchFactor;
/*0x1608A*/ u8 linkBattleVsSpriteId_V;
/*0x1608B*/ u8 linkBattleVsSpriteId_S;
/*0x1608C*/ u8 ChosenMoveID[MAX_BATTLERS_COUNT];
/*0x16090*/ s32 bideDmg;
/*0x16094*/ u8 stateIdAfterSelScript[4];
/*0x16098*/ u8 unk16098[3]; // unused
/*0x1609B*/ u8 castformToChangeInto;
/*0x1609C*/ u8 atk6C_statetracker;
/*0x1609D*/ u8 unk1609D;
/*0x1609E*/ u8 dbgAICycleMoveTracker[2]; // debug
/*0x160A0*/ u8 stringMoveType;
/*0x160A1*/ u8 animTargetsHit;
/*0x160A2*/ u8 expGetterBattlerId;
/*0x160A3*/ u8 unk160A3;
/*0x160A4*/ u8 animArg1;
/*0x160A5*/ u8 animArg2;
/*0x160A6*/ u8 unk160A6; // related to gAbsentBattlerFlags, possibly absent flags turn ago?
/*0x160A7*/ u8 unk160A7;
/*0x160A8*/ u8 unk160A8;
/*0x160A9*/ u8 unk160A9;
/*0x160AA*/ u8 unk160AA;
/*0x160AB*/ u8 unk160AB;
/*0x160AC*/ u16 lastTakenMove[2 * 2 * 2];
/*0x160BC*/ u16 HP_OnSwitchout[2];
/*0x160C0*/ u8 abilityPreventingSwitchout;
/*0x160C1*/ u8 hpScale;
/*0x160C2*/ u16 unk160C2;
/*0x160C4*/ MainCallback unk160C4;
// Buffers used by the AI are indexed using (battler / 2)
// i.e. the flank bit, because at no point in game is the
// player's partner in a multi battle controlled by the AI.
// This is changed in Emerald to support the Tabitha fight
// in the Space Center.
/*0x160C8*/ u8 AI_monToSwitchIntoId[2];
/*0x160CA*/ u8 synchroniseEffect;
/*0x160CB*/ u8 multiplayerId;
/*0x160CC*/ u16 usedHeldItems[MAX_BATTLERS_COUNT];
// Space is reserved for two u16s, one for each opponent in
// doubles. However, only the lower byte of each is ever used.
/*0x160D4*/ u16 AI_usedItemId[2];
/*0x160D8*/ u8 AI_usedItemType[2];
/*0x160DA*/ u8 AI_usedItemEffect[2];
/*0x160DC*/ u8 statAnimPlayed;
/*0x160DD*/ u8 intimidateBank;
/*0x160DE*/ u8 unk160DE;
/*0x160DF*/ u8 unk160DF;
/*0x160E0*/ u8 unk160E0[6];
/*0x160E6*/ u8 unk160E6;
/*0x160E7*/ u8 atkCancellerTracker;
/*0x160E8*/ u16 choicedMove[MAX_BATTLERS_COUNT];
/*0x160F0*/ u16 changedItems[MAX_BATTLERS_COUNT];
/*0x160F8*/ u8 unk160F8;
/*0x160F9*/ u8 unk160F9;
/*0x160FA*/ u8 levelUpHP;
/*0x160FB*/ u8 unk160FB;
/*0x160FC*/ u8 turnSideTracker;
/*0x160FD*/ u8 unk160FD;
/*0x160FE*/ u8 unk160FE;
/*0x160FF*/ u8 unk160FF;
/*0x16100*/ u16 lastTakenMoveFrom[2 * 4];
/*0x16110*/ u8 wishPerishSongState;
/*0x16111*/ u8 wishPerishSongBattlerId;
/*0x16112*/ u8 multihitMoveEffect;
/*0x16113*/ u8 givenExpMons;
};
struct ResourceFlags
{
u32 arr[4];
};
struct BattleSpriteInfo
{
u8 invisible:1;
u8 lowHpSong:1;
u8 substituteSprite:1;
u8 flag_x8:1;
u8 hpNumbersNoBars:1;
u16 transformedSpecies;
};
struct Struct2017810
{
/*0x00*/ u8 unk0_0:1;
/*0x00*/ u8 unk0_1:1;
/*0x00*/ u8 unk0_2:1;
/*0x00*/ u8 unk0_3:1;
/*0x00*/ u8 unk0_4:1;
/*0x00*/ u8 unk0_5:1;
/*0x00*/ u8 unk0_6:1;
/*0x00*/ u8 unk0_7:1;
/*0x01*/ u8 unk1_0:1;
/*0x01*/ u8 unk1_1:5;
/*0x02*/ u8 unk2;
/*0x03*/ u8 unk3;
/*0x04*/ u8 unk4;
/*0x05*/ u8 unk5;
/*0x06*/ u8 unk6;
/*0x07*/ u8 unk7;
/*0x08*/ u8 unk8;
/*0x09*/ u8 unk9;
/*0x0A*/ u8 fillerA[2];
};
struct Struct2017840
{
u16 unk0;
u8 filler2[6];
u8 unk8;
u8 unk9_0:1;
u8 unk9_1:1;
u8 unkA;
u16 unkC;
};
struct Struct20238C8
{
u8 unk0_0:7;
u8 unk0_7:1;
};
#define GET_MOVE_TYPE(move, typeArg) \
{ \
if (gBattleStruct->dynamicMoveType) \
typeArg = gBattleStruct->dynamicMoveType & 0x3F; \
else \
typeArg = gBattleMoves[move].type; \
}
#define IS_TYPE_PHYSICAL(moveType)(moveType < TYPE_MYSTERY)
#define IS_TYPE_SPECIAL(moveType)(moveType > TYPE_MYSTERY)
#define TARGET_TURN_DAMAGED (((gSpecialStatuses[gBattlerTarget].physicalDmg || gSpecialStatuses[gBattlerTarget].specialDmg)))
#define IS_BATTLER_OF_TYPE(battlerId, type)((gBattleMons[battlerId].type1 == type || gBattleMons[battlerId].type2 == type))
#define SET_BATTLER_TYPE(battlerId, type) \
{ \
gBattleMons[battlerId].type1 = type; \
gBattleMons[battlerId].type2 = type; \
}
#define GET_STAT_BUFF_ID(n)((n & 0xF)) // first four bits 0x1, 0x2, 0x4, 0x8
#define GET_STAT_BUFF_VALUE2(n)((n & 0xF0))
#define GET_STAT_BUFF_VALUE(n)(((n >> 4) & 7)) // 0x10, 0x20, 0x40
#define STAT_BUFF_NEGATIVE 0x80 // 0x80, the sign bit
#define SET_STAT_BUFF_VALUE(n)(((s8)(((s8)(n) << 4)) & 0xF0))
#define SET_STATCHANGER(statId, stage, goesDown)(gBattleScripting.statChanger = (statId) + (stage << 4) + (goesDown << 7))
extern struct BattleHistory unk_2016A00;
extern struct DisableStruct gDisableStructs[MAX_BATTLERS_COUNT];
extern struct BattleResults gBattleResults;
extern struct ProtectStruct gProtectStructs[MAX_BATTLERS_COUNT];
extern struct SpecialStatus gSpecialStatuses[MAX_BATTLERS_COUNT];
extern struct SideTimer gSideTimers[2];
extern struct WishFutureKnock gWishFutureKnock;
extern struct AI_ThinkingStruct gAIThinkingSpace;
extern struct Struct20238C8 gUnknown_020238C8;
// used in many battle files, it seems as though Hisashi Sogabe wrote
// some sort of macro to replace the use of actually calling memset.
// Perhaps it was thought calling memset was much slower?
// The compiler wont allow us to locally declare ptr in this macro; some
// functions that invoke this macro will not match without this egregeous
// assumption about the variable names, so in order to avoid this assumption,
// we opt to pass the variables themselves, even though it is likely that
// Sogabe assumed the variables were named src and dest. Trust me: I tried to
// avoid assuming variable names, but the ROM just will not match without the
// assumptions. Therefore, these macros are bad practice, but I'm putting them
// here anyway.
#define MEMSET_ALT(data, c, size, var, dest) \
{ \
dest = (u8 *)data; \
for(var = 0; var < (u32)size; var++) \
dest[var] = c; \
} \
#define MEMCPY_ALT(data, dest, size, var, src) \
{ \
src = (u8 *)data; \
for(var = 0; var < (u32)size; var++) \
dest[var] = src[var]; \
} \
typedef void (*BattleCmdFunc)(void);
extern u8 gBattleTextBuff1[];
//function declarations of buffer emits
void BtlController_EmitGetMonData(u8 buffID, u8 request, u8 c); //0x0
void BtlController_EmitGetRawMonData(u8 a, u8 b, u8 c); //0x1
void BtlController_EmitSetMonData(u8 a, u8 request, u8 c, u8 bytes, void *data); //0x2
void BtlController_EmitSwitchInAnim(u8 a, u8 b, u8 c); //0x5
void BtlController_EmitReturnMonToBall(u8 a, u8 b); //0x6
void BtlController_EmitTrainerSlide(u8 a); //0x8
void BtlController_EmitFaintAnimation(u8 a); //0xA
void BtlController_EmitBallThrowAnim(u8 a, u8 shakes); //0xD
//void BtlController_EmitMoveAnimation(u8 a, u16 move, u8 turn, u16 power, s32 dmg, u8 happiness, void *disable_struct); //0xF
void BtlController_EmitPrintString(u8 a, u16 stringID); //0x10
//void BtlController_EmitPrintSelectionString(u8 a, u16 stringID); //0x11
void BtlController_EmitChoosePokemon(u8 a, u8 b, u8 c, u8 d, u8 *e); //0x16
//void BtlController_EmitHealthBarUpdate(u8 a, u16 b); //0x18; Had to declare the second arg as u16 because s16 wont match in atk0b
//void BtlController_EmitExpUpdate(u8 a, u8 b, u16 c); //0x19
void BtlController_EmitStatusIconUpdate(u8 a, u32 b, u32 c); //0x1A
void BtlController_EmitStatusAnimation(u8 a, u8 b, u32 c); //0x1B
void BtlController_EmitStatusXor(u8 a, u8 b); //0x1C
void BtlController_EmitHitAnimation(u8 a); //0x29
void BtlController_EmitPlaySE(u8 a, u16 sound); //0x2B
void BtlController_EmitPlayFanfareOrBGM(u8 a, u16 sound); //0x2C
void BtlController_EmitFaintingCry(u8 a); //0x2D
void BtlController_EmitIntroSlide(u8 a, u8 b); //0x2E
void BtlController_EmitHidePartyStatusSummary(u8 a); //0x31
void BtlController_EmitSpriteInvisibility(u8 a, u8 b); //0x33
void BtlController_EmitBattleAnimation(u8 a, u8 b, u16 c); //0x34
void BtlController_EmitResetActionMoveSelection(u8 a, u8 b); //0x36
void BtlController_EmitCmd55(u8 a, u8 b); //0x37
void MarkBattlerForControllerExec(u8 bank);
extern u8 gBattleTextBuff1[];
extern u16 gBattle_BG0_X;
extern u16 gBattle_BG0_Y;
extern u16 gBattle_BG1_X;
extern u16 gBattle_BG1_Y;
extern u16 gBattle_BG2_X;
extern u16 gBattle_BG2_Y;
extern u16 gBattle_BG3_X;
extern u16 gBattle_BG3_Y;
extern u16 gBattle_WIN0H;
extern u16 gBattle_WIN0V;
extern u16 gBattle_WIN1H;
extern u16 gBattle_WIN1V;
extern u8 gLastHitBy[MAX_BATTLERS_COUNT];
extern u8 gDisplayedStringBattle[];
extern u16 gBattleTypeFlags;
extern u8 gUnknown_02023A14_50;
extern u16 gTrainerBattleOpponent;
// src/battle_bg.o
void sub_800D6D4();
void ApplyPlayerChosenFrameToBattleMenu();
void DrawMainBattleBackground(void);
void LoadBattleTextboxAndBackground();
void InitLinkBattleVsScreen(u8);
void DrawBattleEntryBackground();
// src/battle_2.o
void CB2_InitBattle(void);
void CB2_InitBattleInternal(void);
void CB2_HandleStartBattle(void);
void sub_800F104(void);
void CB2_HandleStartMultiBattle(void);
void BattleMainCB2(void);
void sub_800F838(struct Sprite *);
u8 CreateNPCTrainerParty(struct Pokemon *, u16);
void sub_800FCFC(void);
void nullsub_36(struct Sprite *);
void c2_8011A1C(void);
void sub_80101B8(void);
void c2_081284E0(void);
void sub_8010278(struct Sprite *);
void sub_80102AC(struct Sprite *);
void nullsub_37(struct Sprite *);
void sub_8010320(struct Sprite *);
void sub_8010494(struct Sprite *);
void sub_801053C(struct Sprite *);
void oac_poke_ally_(struct Sprite *);
void nullsub_86(struct Sprite *);
void objc_dp11b_pingpong(struct Sprite *);
void nullsub_41(void);
void sub_8010800(void);
void BattleMainCB1(void);
void BattleStartClearSetData(void);
void bc_8012FAC(void);
void sub_8011384(void);
void bc_801333C(void);
void bc_battle_begin_message(void);
void bc_8013568(void);
void sub_8011800(void);
void sub_8011834(void);
void bc_801362C(void);
void sub_8011970(void);
void sub_80119B4(void);
void BattleBeginFirstTurn(void);
void BattleTurnPassed(void);
void RunBattleScriptCommands_PopCallbacksStack(void);
void RunBattleScriptCommands(void);
bool8 TryRunFromBattle(u8 bank);
// asm/battle_2.o
void sub_8012324(void);
void SwapTurnOrder(u8, u8);
u8 GetWhoStrikesFirst(u8, u8, u8);
void debug_sub_8010800(void);
// asm/battle_3.o
u8 CheckMoveLimitations(u8 bank, u8 unusableMoves, u8 check);
u8 DoFieldEndTurnEffects(void);
u8 TurnBasedEffects(void);
u8 HandleFaintedMonActions();
u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 move);
u8 ItemBattleEffects(u8 caseID, u8 bank, bool8 moveTurn);
u8 GetMoveTarget(u16 move, u8 useMoveTarget);
// asm/battle_4.o
void AI_CalcDmg(u8, u8);
u8 TypeCalc(u16 move, u8 bank_atk, u8 bank_def);
u8 GetBattlerTurnOrderNum(u8 bank);
// asm/battle_5.o
void nullsub_91(void);
void SetBankFuncToPlayerBufferRunCommand(void);
void sub_802C098();
void c3_0802FDF4(u8);
void sub_802E3E4(u8, int);
void nullsub_8(u8);
void sub_802E414(void);
void sub_802E424(void);
// asm/battle_7.o
void move_anim_start_t4(u8 a, u8 b, u8 c, u8 d);
void nullsub_9(u16);
void nullsub_10(int);
void load_gfxc_health_bar(u8);
u8 battle_load_something();
void sub_8031F88(u8);
void HandleLowHpMusicChange(struct Pokemon *, u8);
void sub_8032638();
void sub_8032AA8(u8, u8);
void SetBankFuncToOpponentBufferRunCommand(void);
void BattleStopLowHpSound(void);
void sub_8031FC4(u8, u8, bool8);
void sub_8032984(u8, u16);
void refresh_graphics_maybe(u8, u8, u8);
void sub_80324E0(u8 a);
void SetBankFuncToLinkOpponentBufferRunCommand(void);
void GameClear(void);
#endif // GUARD_BATTLE_H
|