Sync src/battle_util.c with pokeemerald
This commit is contained in:
+22
-10
@@ -2,8 +2,8 @@
|
||||
#include "bg.h"
|
||||
#include "battle.h"
|
||||
#include "battle_anim.h"
|
||||
#include "pokemon.h"
|
||||
#include "malloc.h"
|
||||
#include "pokemon.h"
|
||||
#include "trainer_tower.h"
|
||||
|
||||
void AllocateBattleResources(void)
|
||||
@@ -14,10 +14,12 @@ void AllocateBattleResources(void)
|
||||
{
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < 4; ++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));
|
||||
@@ -27,12 +29,15 @@ void AllocateBattleResources(void)
|
||||
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);
|
||||
|
||||
gBattleAnimBgTileBuffer = AllocZeroed(0x2000);
|
||||
gBattleAnimBgTilemapBuffer = AllocZeroed(0x1000);
|
||||
|
||||
SetBgTilemapBuffer(1, gBattleAnimBgTilemapBuffer);
|
||||
SetBgTilemapBuffer(2, gBattleAnimBgTilemapBuffer);
|
||||
}
|
||||
|
||||
void FreeBattleResources(void)
|
||||
@@ -43,7 +48,7 @@ void FreeBattleResources(void)
|
||||
{
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < 4; ++i)
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
FREE_AND_SET_NULL(gPokedudeBattlerStates[i]);
|
||||
}
|
||||
@@ -51,6 +56,7 @@ void FreeBattleResources(void)
|
||||
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);
|
||||
@@ -60,21 +66,26 @@ void FreeBattleResources(void)
|
||||
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);
|
||||
|
||||
FREE_AND_SET_NULL(gBattleAnimBgTileBuffer);
|
||||
FREE_AND_SET_NULL(gBattleAnimBgTilemapBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void AdjustFriendshipOnBattleFaint(u8 battlerId)
|
||||
{
|
||||
u8 opposingBattlerId, opposingBattlerId2;
|
||||
u8 opposingBattlerId;
|
||||
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||
{
|
||||
u8 opposingBattlerId2;
|
||||
|
||||
opposingBattlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
|
||||
opposingBattlerId2 = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
|
||||
|
||||
if (gBattleMons[opposingBattlerId2].level > gBattleMons[opposingBattlerId].level)
|
||||
opposingBattlerId = opposingBattlerId2;
|
||||
}
|
||||
@@ -82,6 +93,7 @@ void AdjustFriendshipOnBattleFaint(u8 battlerId)
|
||||
{
|
||||
opposingBattlerId = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
|
||||
}
|
||||
|
||||
if (gBattleMons[opposingBattlerId].level > gBattleMons[battlerId].level)
|
||||
{
|
||||
if (gBattleMons[opposingBattlerId].level - gBattleMons[battlerId].level > 29)
|
||||
|
||||
Reference in New Issue
Block a user