Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
psytp2 committed Sep 12, 2024
2 parents f48833e + 2f4dc19 commit fa907f3
Show file tree
Hide file tree
Showing 42 changed files with 421 additions and 41 deletions.
10 changes: 8 additions & 2 deletions asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,9 @@
.byte \battler
.endm

.macro trainerslidein battler:req
.macro trainerslidein position:req
.byte 0x53
.byte \battler
.byte \position
.endm

.macro playse song:req
Expand Down Expand Up @@ -1721,6 +1721,12 @@
.4byte \failInstr
.endm

.macro jumpifblockedbysoundproof battler:req, failInstr:req
callnative BS_JumpIfBlockedBySoundproof
.byte \battler
.4byte \failInstr
.endm

@ various command changed to more readable macros
.macro cancelmultiturnmoves battler:req
various \battler, VARIOUS_CANCEL_MULTI_TURN_MOVES
Expand Down
36 changes: 18 additions & 18 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ BattleScript_EffectAttackUpUserAlly_TryAlly:
BattleScript_EffectAttackUpUserAlly_End:
goto BattleScript_MoveEnd
BattleScript_EffectAttackUpUserAlly_TryAlly_:
jumpifability BS_ATTACKER_PARTNER, ABILITY_SOUNDPROOF, BattleScript_EffectAttackUpUserAlly_TryAllyBlocked
jumpifblockedbysoundproof BS_ATTACKER_PARTNER, BattleScript_EffectAttackUpUserAlly_TryAllyBlocked
setstatchanger STAT_ATK, 1, FALSE
statbuffchange STAT_CHANGE_ALLOW_PTR, BattleScript_EffectAttackUpUserAlly_End
jumpifbyte CMP_NOT_EQUAL, cMULTISTRING_CHOOSER, B_MSG_STAT_WONT_INCREASE, BattleScript_EffectAttackUpUserAlly_AllyAnim
Expand Down Expand Up @@ -1838,7 +1838,7 @@ BattleScript_HitSwitchTargetForceRandomSwitchFailed:
goto BattleScript_MoveEnd

BattleScript_EffectToxicThread::
setstatchanger STAT_SPEED, 2, TRUE
setstatchanger STAT_SPEED, 1, TRUE
attackcanceler
jumpifsubstituteblocks BattleScript_FailedFromAtkString
jumpifstat BS_TARGET, CMP_NOT_EQUAL, STAT_SPEED, MIN_STAT_STAGE, BattleScript_ToxicThreadWorks
Expand Down Expand Up @@ -4281,7 +4281,7 @@ BattleScript_EffectPerishSong::
waitmessage B_WAIT_TIME_LONG
setbyte gBattlerTarget, 0
BattleScript_PerishSongLoop::
jumpifability BS_TARGET, ABILITY_SOUNDPROOF, BattleScript_PerishSongBlocked
jumpifblockedbysoundproof BS_TARGET, BattleScript_PerishSongBlocked
jumpifpranksterblocked BS_TARGET, BattleScript_PerishSongNotAffected
BattleScript_PerishSongLoopIncrement::
addbyte gBattlerTarget, 1
Expand Down Expand Up @@ -5603,13 +5603,13 @@ BattleScript_LocalTrainerBattleWon::
BattleScript_LocalTwoTrainersDefeated::
printstring STRINGID_TWOENEMIESDEFEATED
BattleScript_LocalBattleWonLoseTexts::
trainerslidein BS_ATTACKER
trainerslidein BS_OPPONENT1
waitstate
printstring STRINGID_TRAINER1LOSETEXT
jumpifnotbattletype BATTLE_TYPE_TWO_OPPONENTS, BattleScript_LocalBattleWonReward
trainerslideout B_POSITION_OPPONENT_LEFT
trainerslideout BS_OPPONENT1
waitstate
trainerslidein BS_FAINTED
trainerslidein BS_OPPONENT2
waitstate
printstring STRINGID_TRAINER2LOSETEXT
BattleScript_LocalBattleWonReward::
Expand Down Expand Up @@ -5661,15 +5661,15 @@ BattleScript_LocalBattleLostPrintTrainersWinText::
waitstate
returnopponentmon2toball BS_ATTACKER
waitstate
trainerslidein BS_ATTACKER
trainerslidein BS_OPPONENT1
waitstate
printstring STRINGID_TRAINER1WINTEXT
jumpifbattletype BATTLE_TYPE_TOWER_LINK_MULTI, BattleScript_LocalBattleLostDoTrainer2WinText
jumpifnotbattletype BATTLE_TYPE_TWO_OPPONENTS, BattleScript_LocalBattleLostEnd_
BattleScript_LocalBattleLostDoTrainer2WinText::
trainerslideout B_POSITION_OPPONENT_LEFT
trainerslideout BS_OPPONENT1
waitstate
trainerslidein BS_FAINTED
trainerslidein BS_OPPONENT2
waitstate
printstring STRINGID_TRAINER2WINTEXT
BattleScript_LocalBattleLostEnd_::
Expand All @@ -5680,12 +5680,12 @@ BattleScript_FrontierLinkBattleLost::
waitstate
returnopponentmon2toball BS_ATTACKER
waitstate
trainerslidein BS_ATTACKER
trainerslidein BS_OPPONENT1
waitstate
printstring STRINGID_TRAINER1WINTEXT
trainerslideout B_POSITION_OPPONENT_LEFT
trainerslideout BS_OPPONENT1
waitstate
trainerslidein BS_FAINTED
trainerslidein BS_OPPONENT2
waitstate
printstring STRINGID_TRAINER2WINTEXT
jumpifbattletype BATTLE_TYPE_RECORDED, BattleScript_FrontierLinkBattleLostEnd
Expand All @@ -5708,12 +5708,12 @@ BattleScript_TowerLinkBattleWon::
playtrainerdefeatbgm BS_ATTACKER
printstring STRINGID_BATTLEEND
waitmessage B_WAIT_TIME_LONG
trainerslidein BS_ATTACKER
trainerslidein BS_OPPONENT1
waitstate
printstring STRINGID_TRAINER1LOSETEXT
trainerslideout B_POSITION_OPPONENT_LEFT
trainerslideout BS_OPPONENT1
waitstate
trainerslidein BS_FAINTED
trainerslidein BS_OPPONENT2
waitstate
printstring STRINGID_TRAINER2LOSETEXT
jumpifbattletype BATTLE_TYPE_RECORDED, BattleScript_TowerLinkBattleWonEnd
Expand All @@ -5730,13 +5730,13 @@ BattleScript_FrontierTrainerBattleWon::
BattleScript_FrontierTrainerBattleWon_TwoDefeated:
printstring STRINGID_TWOENEMIESDEFEATED
BattleScript_FrontierTrainerBattleWon_LoseTexts:
trainerslidein BS_ATTACKER
trainerslidein BS_OPPONENT1
waitstate
printstring STRINGID_TRAINER1LOSETEXT
jumpifnotbattletype BATTLE_TYPE_TWO_OPPONENTS, BattleScript_TryPickUpItems
trainerslideout B_POSITION_OPPONENT_LEFT
trainerslideout BS_OPPONENT1
waitstate
trainerslidein BS_FAINTED
trainerslidein BS_OPPONENT2
waitstate
printstring STRINGID_TRAINER2LOSETEXT
BattleScript_TryPickUpItems:
Expand Down
10 changes: 5 additions & 5 deletions data/battle_scripts_2.s
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,18 @@ BattleScript_ActionWallyThrow:
waitmessage B_WAIT_TIME_LONG
returnatktoball
waitstate
trainerslidein BS_TARGET
trainerslidein BS_PLAYER1
waitstate
printstring STRINGID_YOUTHROWABALLNOWRIGHT
waitmessage B_WAIT_TIME_LONG
end2

BattleScript_TrainerASlideMsgRet::
handletrainerslidemsg BS_SCRIPTING, 0
trainerslidein B_POSITION_OPPONENT_LEFT
trainerslidein BS_OPPONENT1
handletrainerslidemsg BS_SCRIPTING, 1
waitstate
trainerslideout B_POSITION_OPPONENT_LEFT
trainerslideout BS_OPPONENT1
waitstate
handletrainerslidemsg BS_SCRIPTING, 2
return
Expand All @@ -260,10 +260,10 @@ BattleScript_TrainerASlideMsgEnd2::

BattleScript_TrainerBSlideMsgRet::
handletrainerslidemsg BS_SCRIPTING, 0
trainerslidein B_POSITION_OPPONENT_RIGHT
trainerslidein BS_OPPONENT2
handletrainerslidemsg BS_SCRIPTING, 1
waitstate
trainerslideout B_POSITION_OPPONENT_RIGHT
trainerslideout BS_OPPONENT2
waitstate
handletrainerslidemsg BS_SCRIPTING, 2
return
Expand Down
Binary file modified graphics/interface/category_icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/ambipom/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/crobat/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/donphan/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/flygon/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/grovyle/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/igglybuff/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/ledian/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/ledyba/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/mantine/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/marshtomp/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/meganium/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/mightyena/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/miltank/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/prinplup/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/raikou/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/roserade/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/skarmory/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/skiploom/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/spinarak/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/stunky/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/torkoal/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/wooper/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/xatu/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/pokemon/yanma/overworld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions include/battle_ai_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ bool32 HasMoveEffectANDArg(u32 battlerId, u32 effect, u32 argument);
bool32 HasMoveWithAdditionalEffect(u32 battlerId, u32 moveEffect);
bool32 HasMoveWithCriticalHitChance(u32 battlerId);
bool32 HasMoveWithMoveEffectExcept(u32 battlerId, u32 moveEffect, u32 exception);
bool32 HasMoveThatLowersOwnStats(u32 battlerId);
bool32 HasMoveWithLowAccuracy(u32 battlerAtk, u32 battlerDef, u32 accCheck, bool32 ignoreStatus, u32 atkAbility, u32 defAbility, u32 atkHoldEffect, u32 defHoldEffect);
bool32 HasAnyKnownMove(u32 battlerId);
bool32 IsAromaVeilProtectedMove(u32 move);
Expand All @@ -138,6 +139,7 @@ bool32 ShouldFakeOut(u32 battlerAtk, u32 battlerDef, u32 move);
bool32 HasThawingMove(u32 battler);
bool32 IsStatRaisingEffect(u32 effect);
bool32 IsStatLoweringEffect(u32 effect);
bool32 IsSelfStatLoweringEffect(u32 effect);
bool32 IsAttackBoostMoveEffect(u32 effect);
bool32 IsUngroundingEffect(u32 effect);
bool32 IsSemiInvulnerable(u32 battlerDef, u32 move);
Expand Down
19 changes: 15 additions & 4 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3049,15 +3049,26 @@ static s32 AI_DoubleBattle(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
case EFFECT_SKILL_SWAP:
if (aiData->abilities[battlerAtk] != aiData->abilities[BATTLE_PARTNER(battlerAtk)] && !attackerHasBadAbility)
{
// Partner abilities
if (aiData->abilities[BATTLE_PARTNER(battlerAtk)] == ABILITY_TRUANT)
{
RETURN_SCORE_PLUS(10);
ADJUST_SCORE(10);
}
else if (aiData->abilities[battlerAtk] == ABILITY_COMPOUND_EYES
&& HasMoveWithLowAccuracy(battlerAtkPartner, FOE(battlerAtkPartner), 90, TRUE, atkPartnerAbility, aiData->abilities[FOE(battlerAtkPartner)], atkPartnerHoldEffect, aiData->holdEffects[FOE(battlerAtkPartner)]))
else if (aiData->abilities[BATTLE_PARTNER(battlerAtk)] == ABILITY_INTIMIDATE)
{
RETURN_SCORE_PLUS(3);
ADJUST_SCORE(DECENT_EFFECT);
}
// Active mon abilities
if (aiData->abilities[battlerAtk] == ABILITY_COMPOUND_EYES
&& HasMoveWithLowAccuracy(battlerAtkPartner, FOE(battlerAtkPartner), 90, TRUE, atkPartnerAbility, aiData->abilities[FOE(battlerAtkPartner)], atkPartnerHoldEffect, aiData->holdEffects[FOE(battlerAtkPartner)]))
{
ADJUST_SCORE(GOOD_EFFECT);
}
else if (aiData->abilities[battlerAtk] == ABILITY_CONTRARY && HasMoveThatLowersOwnStats(battlerAtkPartner))
{
ADJUST_SCORE(GOOD_EFFECT);
}
return score;
}
break;
case EFFECT_ROLE_PLAY:
Expand Down
6 changes: 5 additions & 1 deletion src/battle_ai_switch_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ static u32 GetSwitchinHitsToKO(s32 damageTaken, u32 battler)
u16 maxHP = AI_DATA->switchinCandidate.battleMon.maxHP, item = AI_DATA->switchinCandidate.battleMon.item, heldItemEffect = ItemId_GetHoldEffect(item);
u8 weatherDuration = gWishFutureKnock.weatherDuration, holdEffectParam = ItemId_GetHoldEffectParam(item);
u32 opposingBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(battler)));
u32 opposingAbility = gBattleMons[opposingBattler].ability;
u32 opposingAbility = gBattleMons[opposingBattler].ability, ability = AI_DATA->switchinCandidate.battleMon.ability;
bool32 usedSingleUseHealingItem = FALSE;
s32 currentHP = startingHP;

Expand All @@ -1631,6 +1631,10 @@ static u32 GetSwitchinHitsToKO(s32 damageTaken, u32 battler)
// Take attack damage for the turn
currentHP = currentHP - damageTaken;

// One shot prevention effects
if (damageTaken >= maxHP && currentHP == maxHP && (heldItemEffect == HOLD_EFFECT_FOCUS_SASH || (B_STURDY >= GEN_5 && ability == ABILITY_STURDY)))
currentHP = 1;

// If mon is still alive, apply weather impact first, as it might KO the mon before it can heal with its item (order is weather -> item -> status)
if (currentHP != 0)
currentHP = currentHP - weatherImpact;
Expand Down
50 changes: 49 additions & 1 deletion src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ static bool32 AI_IsMoveEffectInPlus(u32 battlerAtk, u32 battlerDef, u32 move, s3
case MOVE_EFFECT_SP_DEF_MINUS_2:
case MOVE_EFFECT_ACC_MINUS_2:
case MOVE_EFFECT_EVS_MINUS_2:
if (ShouldLowerStat(battlerDef, abilityDef, STAT_ATK + (gMovesInfo[move].additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_MINUS_1)) && noOfHitsToKo != 1)
if (ShouldLowerStat(battlerDef, abilityDef, STAT_ATK + (gMovesInfo[move].additionalEffects[i].moveEffect - MOVE_EFFECT_ATK_MINUS_2)) && noOfHitsToKo != 1)
return TRUE;
break;
}
Expand Down Expand Up @@ -2089,6 +2089,26 @@ bool32 HasAnyKnownMove(u32 battlerId)
return FALSE;
}

bool32 HasMoveThatLowersOwnStats(u32 battlerId)
{
s32 i, j;
u32 aiMove;
u16 *moves = GetMovesArray(battlerId);
for (i = 0; i < MAX_MON_MOVES; i++)
{
aiMove = moves[i];
if (aiMove != MOVE_NONE && aiMove != MOVE_UNAVAILABLE)
{
for (j = 0; j < gMovesInfo[aiMove].numAdditionalEffects; j++)
{
if (IsSelfStatLoweringEffect(gMovesInfo[aiMove].additionalEffects[j].moveEffect) && gMovesInfo[aiMove].additionalEffects[j].self)
return TRUE;
}
}
}
return FALSE;
}

bool32 HasMoveWithLowAccuracy(u32 battlerAtk, u32 battlerDef, u32 accCheck, bool32 ignoreStatus, u32 atkAbility, u32 defAbility, u32 atkHoldEffect, u32 defHoldEffect)
{
s32 i;
Expand Down Expand Up @@ -2294,6 +2314,34 @@ bool32 IsStatLoweringEffect(u32 effect)
}
}

bool32 IsSelfStatLoweringEffect(u32 effect)
{
// Self stat lowering moves like Overheart, Superpower etc.
switch (effect)
{
case MOVE_EFFECT_ATK_MINUS_1:
case MOVE_EFFECT_DEF_MINUS_1:
case MOVE_EFFECT_SPD_MINUS_1:
case MOVE_EFFECT_SP_ATK_MINUS_1:
case MOVE_EFFECT_SP_DEF_MINUS_1:
case MOVE_EFFECT_EVS_MINUS_1:
case MOVE_EFFECT_ACC_MINUS_1:
case MOVE_EFFECT_ATK_MINUS_2:
case MOVE_EFFECT_DEF_MINUS_2:
case MOVE_EFFECT_SPD_MINUS_2:
case MOVE_EFFECT_SP_ATK_MINUS_2:
case MOVE_EFFECT_SP_DEF_MINUS_2:
case MOVE_EFFECT_EVS_MINUS_2:
case MOVE_EFFECT_ACC_MINUS_2:
case MOVE_EFFECT_V_CREATE:
case MOVE_EFFECT_ATK_DEF_DOWN:
case MOVE_EFFECT_DEF_SPDEF_DOWN:
return TRUE;
default:
return FALSE;
}
}

bool32 HasDamagingMove(u32 battlerId)
{
u32 i;
Expand Down
21 changes: 19 additions & 2 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -7428,9 +7428,9 @@ static void Cmd_switchineffects(void)

static void Cmd_trainerslidein(void)
{
CMD_ARGS(u8 battler);
CMD_ARGS(u8 position);

u32 battler = GetBattlerForBattleScript(cmd->battler);
u32 battler = GetBattlerForBattleScript(cmd->position);
BtlController_EmitTrainerSlide(battler, BUFFER_A);
MarkBattlerForControllerExec(battler);

Expand Down Expand Up @@ -17092,6 +17092,23 @@ void BS_TryTarShot(void)
}
}

void BS_JumpIfBlockedBySoundproof(void)
{
NATIVE_ARGS(u8 battler, const u8 *jumpInstr);
u32 battler = GetBattlerForBattleScript(cmd->battler);
if (gMovesInfo[gCurrentMove].soundMove && GetBattlerAbility(battler) == ABILITY_SOUNDPROOF)
{
gLastUsedAbility = ABILITY_SOUNDPROOF;
gBattlescriptCurrInstr = cmd->jumpInstr;
RecordAbilityBattle(battler, gLastUsedAbility);
gBattlerAbility = battler;
}
else
{
gBattlescriptCurrInstr = cmd->nextInstr;
}
}

void BS_TeatimeInvul(void)
{
NATIVE_ARGS(u8 battler, const u8 *jumpInstr);
Expand Down
Loading

0 comments on commit fa907f3

Please sign in to comment.