Merge branch 'battle_engine' of https://github.com/rh-hideout/pokeemerald-expansion into infestation

This commit is contained in:
Evan 2020-12-13 17:09:04 -07:00
commit ead8637e4f
18 changed files with 106 additions and 11 deletions

View File

@ -1756,6 +1756,10 @@
.4byte \ptr
.endm
.macro destroyabilitypopup
various BS_ABILITY_BATTLER, VARIOUS_DESTROY_ABILITY_POPUP
.endm
@ helpful macros
.macro setstatchanger stat:req, stages:req, down:req
setbyte sSTATCHANGER \stat | \stages << 3 | \down << 7

View File

@ -815,6 +815,7 @@ gBattleAnims_General::
.4byte General_IllusionOff
.4byte General_FormChange
.4byte General_SlideOffScreen
.4byte General_RestoreBg
.align 2
gBattleAnims_Special::
@ -8453,6 +8454,8 @@ Move_GRASSY_TERRAIN::
delay 4
createvisualtask AnimTask_BlendBattleAnimPal, 10, ANIM_PAL_BG, 3, 4, 0, RGB(31, 24, 31)
waitforvisualfinish
restorebg
waitbgfadein
end
Move_MISTY_TERRAIN::
@ -8491,6 +8494,8 @@ Move_MISTY_TERRAIN::
delay 4
createvisualtask AnimTask_BlendBattleAnimPal, 10, ANIM_PAL_BG, 3, 7, 0, RGB(31, 24, 31)
waitforvisualfinish
restorebg
waitbgfadein
end
Move_ELECTRIFY::
@ -9374,6 +9379,8 @@ Move_ELECTRIC_TERRAIN::
delay 2
createvisualtask AnimTask_BlendBattleAnimPal, 10, ANIM_PAL_BG, 3, 4, 0, RGB(28, 28, 0)
waitforvisualfinish
restorebg
waitbgfadein
end
Move_DAZZLING_GLEAM::
@ -9451,6 +9458,7 @@ Move_BABY_DOLL_EYES::
loadspritegfx ANIM_TAG_PINK_CLOUD
loadspritegfx ANIM_TAG_OPENING_EYE @eye
setalpha 8, 8
monbg ANIM_DEF_PARTNER
launchtask AnimTask_BlendBattleAnimPal 0xa 0x5 ANIM_PAL_BG 0x0 0x0 0xA 0x7FFF
waitforvisualfinish
launchtemplate gOpeningEyeSpriteTemplate 0x5 0x4 0x0 0x0 0x1 0x0
@ -9463,6 +9471,7 @@ Move_BABY_DOLL_EYES::
launchtask AnimTask_ShakeMon2 0x2 0x5 0x3 0x1 0x0 0x9 0x1
launchtask AnimTask_BlendBattleAnimPal 0xa 0x5 ANIM_PAL_BG 0x0 0xA 0x0 0x7FFF
waitforvisualfinish
clearmonbg ANIM_DEF_PARTNER
blendoff
end
@ -11027,6 +11036,8 @@ Move_PSYCHIC_TERRAIN::
delay 4
createvisualtask AnimTask_BlendBattleAnimPal, 10, ANIM_PAL_BG, 3, 4, 0, RGB(27, 0, 13)
waitforvisualfinish
restorebg
waitbgfadein
end
Move_LUNGE::
@ -24337,6 +24348,11 @@ General_TerrainElectric:
General_TerrainPsychic:
end
General_RestoreBg:
restorebg
waitbgfadein
end
SnatchMoveTrySwapFromSubstitute:
createvisualtask AnimTask_IsAttackerBehindSubstitute, 2
jumprettrue SnatchMoveSwapSubstituteForMon

View File

@ -5424,21 +5424,25 @@ BattleScript_MagicRoomEnds::
BattleScript_ElectricTerrainEnds::
printstring STRINGID_ELECTRICTERRAINENDS
waitmessage 0x40
playanimation BS_ATTACKER, B_ANIM_RESTORE_BG, NULL
end2
BattleScript_MistyTerrainEnds::
printstring STRINGID_MISTYTERRAINENDS
waitmessage 0x40
playanimation BS_ATTACKER, B_ANIM_RESTORE_BG, NULL
end2
BattleScript_GrassyTerrainEnds::
printstring STRINGID_GRASSYTERRAINENDS
waitmessage 0x40
playanimation BS_ATTACKER, B_ANIM_RESTORE_BG, NULL
end2
BattleScript_PsychicTerrainEnds::
printstring STRINGID_PSYCHICTERRAINENDS
waitmessage 0x40
playanimation BS_ATTACKER, B_ANIM_RESTORE_BG, NULL
end2
BattleScript_MudSportEnds::

View File

@ -520,6 +520,7 @@ struct BattleStruct
u8 savedBattlerTarget;
bool8 ateBoost[MAX_BATTLERS_COUNT];
u8 activeAbilityPopUps; // as bits for each battler
u8 abilityPopUpSpriteIds[MAX_BATTLERS_COUNT][2]; // two per battler
bool8 throwingPokeBall;
struct MegaEvolutionData mega;
const u8 *trainerSlideMsg;
@ -611,6 +612,7 @@ struct BattleScripting
u16 moveEffect;
u16 multihitMoveEffect;
u8 illusionNickHack; // To properly display nick in STRINGID_ENEMYABOUTTOSWITCHPKMN.
bool8 fixedPopup; // force ability popup to stick until manually called back
};
// rom_80A5C6C

View File

@ -68,6 +68,7 @@ s16 KeepPanInRange(s16 a, int oldPan);
s16 CalculatePanIncrement(s16 sourcePan, s16 targetPan, s16 incrementPan);
void sub_80A4720(u16 a, u16 *b, u32 c, u8 d);
void sub_80A477C(bool8);
void LoadMoveBg(u16 bgId);
// battle_intro.c
void SetAnimBgAttribute(u8 bgId, u8 attributeId, u8 value);

View File

@ -9,5 +9,6 @@ void LoadBattleTextboxAndBackground(void);
void InitLinkBattleVsScreen(u8 taskId);
void DrawBattleEntryBackground(void);
bool8 LoadChosenBattleElement(u8 caseId);
void DrawTerrainTypeBattleBackground(void);
#endif // GUARD_BATTLE_BG_H

View File

@ -92,5 +92,6 @@ s32 MoveBattleBar(u8 battler, u8 healthboxSpriteId, u8 whichBar, u8 arg3);
u8 GetScaledHPFraction(s16 hp, s16 maxhp, u8 scale);
u8 GetHPBarLevel(s16 hp, s16 maxhp);
void CreateAbilityPopUp(u8 battlerId, u32 ability, bool32 isDoubleBattle);
void DestroyAbilityPopUp(u8 battlerId);
#endif // GUARD_BATTLE_INTERFACE_H

View File

@ -234,6 +234,8 @@
#define STATUS_FIELD_ION_DELUGE 0x400
#define STATUS_FIELD_FAIRY_LOCK 0x800
#define STATUS_TERRAIN_ANY (STATUS_FIELD_GRASSY_TERRAIN | STATUS_FIELD_MISTY_TERRAIN | STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_PSYCHIC_TERRAIN)
// Flags describing move's result
#define MOVE_RESULT_MISSED (1 << 0)
#define MOVE_RESULT_SUPER_EFFECTIVE (1 << 1)

View File

@ -525,6 +525,7 @@
#define B_ANIM_ILLUSION_OFF 0x1C
#define B_ANIM_FORM_CHANGE 0x1D
#define B_ANIM_SLIDE_OFFSCREEN 0x1E // for Emergency Exit
#define B_ANIM_RESTORE_BG 0x1F // for Terrain Endings
// special animations table
#define B_ANIM_LVL_UP 0x0

View File

@ -109,11 +109,13 @@
#define B_DISABLE_TURNS GEN_6 // Disable's turns. See Cmd_disablelastusedattack.
#define B_INCINERATE_GEMS GEN_6 // In Gen6+, Incinerate can destroy Gems.
#define B_MINIMIZE_DMG_ACC GEN_6 // In Gen6+, moves that causes double damage to minimized Pokémon will also skip accuracy checks.
#define B_PP_REDUCED_BY_SPITE GEN_6 // In Gen4+, Spite reduces the foe's last move's PP by 4, instead of 2 to 5.
#define B_CAN_SPITE_FAIL GEN_6 // In Gen4+, Spite can no longer fail if the foe's last move only has 1 remaining PP.
// Ability settings
#define B_ABILITY_WEATHER GEN_6 // In Gen5+, weather caused by abilities lasts the same amount of turns as induced from a move. Before, they lasted till the battle's end or weather change by a move.
#define B_GALE_WINGS GEN_6 // In Gen7+ requires full HP to trigger.
#define B_STANCE_CHANGE_FAIL GEN_7 // In Gen7+, Aegislash's form change does not happen, if the Pokémon cannot use a move, because of confusion, paralysis, etc. In gen6, the form change occurs despite not being able to move.
#define B_STANCE_CHANGE_FAIL GEN_7 // In Gen7+, Stance Change fails if the Pokémon is unable to use a move because of confusion, paralysis, etc. In Gen6, it doesn't.
#define B_GHOSTS_ESCAPE GEN_6 // In Gen6+, ghosts can escape even when blocked by abilities such as Shadow Tag.
#define B_MOODY_ACC_EVASION GEN_6 // In Gen8+, Moody CANNOT raise Accuray and Evasion any more.
#define B_FLASH_FIRE_FROZEN GEN_6 // In Gen5+, Flash Fire can trigger even when frozen, when it couldn't before.
@ -164,5 +166,6 @@
#define B_NEW_SURF_PARTICLE_PALETTE TRUE // If set to TRUE, it updates Surf's wave palette.
#define HIDE_HEALTHBOXES_DURING_ANIMS TRUE //if TRUE, hides healthboxes during move animations
#define B_TERRAIN_BG_CHANGE TRUE // If TRUE, terrain moves permanently change the default battle background until the effect fades.
#endif // GUARD_CONSTANTS_BATTLE_CONFIG_H

View File

@ -35,6 +35,7 @@
#define sMOVE_EFFECT gBattleScripting + 0x2E
#define sMULTIHIT_EFFECT gBattleScripting + 0x30
#define sILLUSION_NICK_HACK gBattleScripting + 0x32
#define sFIXED_ABILITY_POPUP gBattleScripting + 0x33
#define cMULTISTRING_CHOOSER gBattleCommunication + 5
@ -165,6 +166,7 @@
#define VARIOUS_SET_LAST_USED_ITEM 99
#define VARIOUS_PARALYZE_TYPE_IMMUNITY 100
#define VARIOUS_JUMP_IF_ABSENT 101
#define VARIOUS_DESTROY_ABILITY_POPUP 102
// Cmd_manipulatedamage
#define DMG_CHANGE_SIGN 0

View File

@ -88,7 +88,6 @@ static void Task_PanFromInitialToTarget(u8 taskId);
static void Task_LoopAndPlaySE(u8 taskId);
static void Task_WaitAndPlaySE(u8 taskId);
static void LoadDefaultBg(void);
static void LoadMoveBg(u16 bgId);
// ewram
EWRAM_DATA static const u8 *sBattleAnimScriptPtr = NULL;
@ -3177,7 +3176,7 @@ static void Task_FadeToBg(u8 taskId)
}
}
static void LoadMoveBg(u16 bgId)
void LoadMoveBg(u16 bgId)
{
if (IsContest())
{
@ -3205,6 +3204,10 @@ static void LoadDefaultBg(void)
{
if (IsContest())
LoadContestBgAfterMoveAnim();
#if B_TERRAIN_BG_CHANGE == TRUE
else if (gFieldStatuses & STATUS_TERRAIN_ANY)
DrawTerrainTypeBattleBackground();
#endif
else
DrawMainBattleBackground();
}

View File

@ -14,6 +14,7 @@
#include "battle_scripts.h"
#include "battle_controllers.h"
#include "constants/moves.h"
#include "constants/hold_effects.h"
//// function declarations
static void SpriteCB_SpriteToCentreOfSide(struct Sprite* sprite);
@ -5001,8 +5002,9 @@ void AnimTask_PurpleFlamesOnTarget(u8 taskId)
void AnimTask_TechnoBlast(u8 taskId)
{
//gBattleAnimArgs[0] = gItems[GetBattlerPartyData(gBattleAnimAttacker).item].holdEffectParam;
gBattleAnimArgs[0] = ItemId_GetHoldEffectParam(gBattleMons[gBattleAnimAttacker].item);
if (ItemId_GetHoldEffect(gBattleMons[gBattleAnimAttacker].item) == HOLD_EFFECT_DRIVE)
gBattleAnimArgs[0] = ItemId_GetSecondaryId(gBattleMons[gBattleAnimAttacker].item);
else
gBattleAnimArgs[0] = 0;
DestroyAnimVisualTask(taskId);
}

View File

@ -1,5 +1,6 @@
#include "global.h"
#include "battle.h"
#include "battle_anim.h"
#include "battle_bg.h"
#include "battle_main.h"
#include "battle_message.h"
@ -23,6 +24,7 @@
#include "constants/map_types.h"
#include "constants/songs.h"
#include "constants/trainers.h"
#include "constants/battle_anim.h"
struct BattleBackground
{
@ -863,7 +865,11 @@ void LoadBattleTextboxAndBackground(void)
CopyBgTilemapBufferToVram(0);
LoadCompressedPalette(gBattleTextboxPalette, 0, 0x40);
LoadBattleMenuWindowGfx();
#if B_TERRAIN_BG_CHANGE == TRUE
DrawTerrainTypeBattleBackground();
#else
DrawMainBattleBackground();
#endif
}
static void DrawLinkBattleParticipantPokeballs(u8 taskId, u8 multiplayerId, u8 bgId, u8 destX, u8 destY)
@ -1413,3 +1419,26 @@ bool8 LoadChosenBattleElement(u8 caseId)
return ret;
}
void DrawTerrainTypeBattleBackground(void)
{
switch (gFieldStatuses & STATUS_TERRAIN_ANY)
{
case STATUS_FIELD_GRASSY_TERRAIN:
LoadMoveBg(BG_GRASSY_TERRAIN);
break;
case STATUS_FIELD_MISTY_TERRAIN:
LoadMoveBg(BG_MISTY_TERRAIN);
break;
case STATUS_FIELD_ELECTRIC_TERRAIN:
LoadMoveBg(BG_ELECTRIC_TERRAIN);
break;
case STATUS_FIELD_PSYCHIC_TERRAIN:
LoadMoveBg(BG_PSYCHIC_TERRAIN);
break;
default:
DrawMainBattleBackground();
break;
}
}

View File

@ -3063,6 +3063,9 @@ void CreateAbilityPopUp(u8 battlerId, u32 ability, bool32 isDoubleBattle)
gSprites[spriteId2].tRightToLeft = FALSE;
}
gBattleStruct->abilityPopUpSpriteIds[gBattleAnimAttacker][0] = spriteId1;
gBattleStruct->abilityPopUpSpriteIds[gBattleAnimAttacker][1] = spriteId2;
taskId = CreateTask(Task_FreeAbilityPopUpGfx, 5);
gTasks[taskId].tSpriteId1 = spriteId1;
gTasks[taskId].tSpriteId2 = spriteId2;
@ -3110,11 +3113,19 @@ static void SpriteCb_AbilityPopUp(struct Sprite *sprite)
}
else
{
if (!gBattleScripting.fixedPopup)
sprite->tFrames--;
}
}
}
void DestroyAbilityPopUp(u8 battlerId)
{
gSprites[gBattleStruct->abilityPopUpSpriteIds[battlerId][0]].tFrames = 0;
gSprites[gBattleStruct->abilityPopUpSpriteIds[battlerId][1]].tFrames = 0;
gBattleScripting.fixedPopup = FALSE;
}
static void Task_FreeAbilityPopUpGfx(u8 taskId)
{
if (!gSprites[gTasks[taskId].tSpriteId1].inUse

View File

@ -3432,7 +3432,7 @@ static void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst)
srcID += 2;
break;
case B_BUFF_ABILITY: // ability names
StringAppend(dst, gAbilityNames[src[srcID + 1]]);
StringAppend(dst, gAbilityNames[T1_READ_16(&src[srcID + 1])]);
srcID += 3;
break;
case B_BUFF_ITEM: // item name

View File

@ -6952,7 +6952,7 @@ static void HandleTerrainMove(u32 moveEffect)
}
else
{
gFieldStatuses &= ~(STATUS_FIELD_MISTY_TERRAIN | STATUS_FIELD_GRASSY_TERRAIN | STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_PSYCHIC_TERRAIN);
gFieldStatuses &= ~STATUS_TERRAIN_ANY;
gFieldStatuses |= statusFlag;
if (GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_TERRAIN_EXTENDER)
*timer = 8;
@ -8300,6 +8300,9 @@ static void Cmd_various(void)
gBattlescriptCurrInstr += 7;
}
return;
case VARIOUS_DESTROY_ABILITY_POPUP:
DestroyAbilityPopUp(gActiveBattler);
break;
}
gBattlescriptCurrInstr += 3;
@ -10192,9 +10195,18 @@ static void Cmd_tryspiteppreduce(void)
break;
}
#if B_CAN_SPITE_FAIL <= GEN_3
if (i != MAX_MON_MOVES && gBattleMons[gBattlerTarget].pp[i] > 1)
#else
if (i != MAX_MON_MOVES && gBattleMons[gBattlerTarget].pp[i] != 0)
#endif
{
#if B_PP_REDUCED_BY_SPITE <= GEN_3
s32 ppToDeduct = (Random() & 3) + 2;
#else
s32 ppToDeduct = 4;
#endif
if (gBattleMons[gBattlerTarget].pp[i] < ppToDeduct)
ppToDeduct = gBattleMons[gBattlerTarget].pp[i];

View File

@ -46,6 +46,7 @@ void FreeBattleResources(void)
if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_HILL)
FreeTrainerHillBattleStruct();
gFieldStatuses = 0;
if (gBattleResources != NULL)
{
FREE_AND_SET_NULL(gBattleStruct);