blob: e3fa1a6a7569263d7485d39510df640de85784d4 (
plain)
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
|
#include "global.h"
#include "bg.h"
#include "battle.h"
#include "battle_anim.h"
#include "pokemon.h"
#include "malloc.h"
#include "trainer_tower.h"
void AllocateBattleResources(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_TOWER)
InitTrainerTowerBattleStruct();
if (gBattleTypeFlags & BATTLE_TYPE_POKEDUDE)
{
s32 i;
for (i = 0; i < 4; ++i)
gPokedudeBattlerStates[i] = AllocZeroed(sizeof(struct PokedudeBattlerState));
}
gBattleStruct = AllocZeroed(sizeof(*gBattleStruct));
gBattleResources = AllocZeroed(sizeof(*gBattleResources));
gBattleResources->secretBase = AllocZeroed(sizeof(*gBattleResources->secretBase));
gBattleResources->flags = AllocZeroed(sizeof(*gBattleResources->flags));
gBattleResources->battleScriptsStack = AllocZeroed(sizeof(*gBattleResources->battleScriptsStack));
gBattleResources->battleCallbackStack = AllocZeroed(sizeof(*gBattleResources->battleCallbackStack));
gBattleResources->beforeLvlUp = AllocZeroed(sizeof(*gBattleResources->beforeLvlUp));
gBattleResources->ai = AllocZeroed(sizeof(*gBattleResources->ai));
gBattleResources->battleHistory = AllocZeroed(sizeof(*gBattleResources->battleHistory));
gBattleResources->AI_ScriptsStack = AllocZeroed(sizeof(*gBattleResources->AI_ScriptsStack));
gLinkBattleSendBuffer = AllocZeroed(BATTLE_BUFFER_LINK_SIZE);
gLinkBattleRecvBuffer = AllocZeroed(BATTLE_BUFFER_LINK_SIZE);
gBattleAnimMons_BgTilesBuffer = AllocZeroed(0x2000);
gBattleAnimMons_BgTilemapBuffer = AllocZeroed(0x1000);
SetBgTilemapBuffer(1, gBattleAnimMons_BgTilemapBuffer);
SetBgTilemapBuffer(2, gBattleAnimMons_BgTilemapBuffer);
}
void FreeBattleResources(void)
{
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_TOWER)
FreeTrainerTowerBattleStruct();
if (gBattleTypeFlags & BATTLE_TYPE_POKEDUDE)
{
s32 i;
for (i = 0; i < 4; ++i)
{
FREE_AND_SET_NULL(gPokedudeBattlerStates[i]);
}
}
if (gBattleResources != NULL)
{
FREE_AND_SET_NULL(gBattleStruct);
FREE_AND_SET_NULL(gBattleResources->secretBase);
FREE_AND_SET_NULL(gBattleResources->flags);
FREE_AND_SET_NULL(gBattleResources->battleScriptsStack);
FREE_AND_SET_NULL(gBattleResources->battleCallbackStack);
FREE_AND_SET_NULL(gBattleResources->beforeLvlUp);
FREE_AND_SET_NULL(gBattleResources->ai);
FREE_AND_SET_NULL(gBattleResources->battleHistory);
FREE_AND_SET_NULL(gBattleResources->AI_ScriptsStack);
FREE_AND_SET_NULL(gBattleResources);
FREE_AND_SET_NULL(gLinkBattleSendBuffer);
FREE_AND_SET_NULL(gLinkBattleRecvBuffer);
FREE_AND_SET_NULL(gBattleAnimMons_BgTilesBuffer);
FREE_AND_SET_NULL(gBattleAnimMons_BgTilemapBuffer);
}
}
void AdjustFriendshipOnBattleFaint(u8 battlerId)
{
u8 opposingBattlerId, opposingBattlerId2;
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
{
opposingBattlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
opposingBattlerId2 = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
if (gBattleMons[opposingBattlerId2].level > gBattleMons[opposingBattlerId].level)
opposingBattlerId = opposingBattlerId2;
}
else
{
opposingBattlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
}
if (gBattleMons[opposingBattlerId].level > gBattleMons[battlerId].level)
{
if (gBattleMons[opposingBattlerId].level - gBattleMons[battlerId].level > 29)
AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_LARGE);
else
AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_SMALL);
}
else
{
AdjustFriendship(&gPlayerParty[gBattlerPartyIndexes[battlerId]], FRIENDSHIP_EVENT_FAINT_SMALL);
}
}
|