remove assist array from battle struct (#2816)

This commit is contained in:
ghoulslash 2023-03-24 09:23:49 -04:00 committed by GitHub
commit dca6182ed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 22 deletions

View File

@ -534,7 +534,6 @@ struct BattleStruct
u8 wildVictorySong; u8 wildVictorySong;
u8 dynamicMoveType; u8 dynamicMoveType;
u8 wrappedBy[MAX_BATTLERS_COUNT]; u8 wrappedBy[MAX_BATTLERS_COUNT];
u16 assistPossibleMoves[PARTY_SIZE * MAX_MON_MOVES]; // Each of mons can know max 4 moves.
u8 focusPunchBattlerId; u8 focusPunchBattlerId;
u8 battlerPreventingSwitchout; u8 battlerPreventingSwitchout;
u8 moneyMultiplier:6; u8 moneyMultiplier:6;

View File

@ -23,6 +23,7 @@
#include "main.h" #include "main.h"
#include "palette.h" #include "palette.h"
#include "money.h" #include "money.h"
#include "malloc.h"
#include "bg.h" #include "bg.h"
#include "string_util.h" #include "string_util.h"
#include "pokemon_icon.h" #include "pokemon_icon.h"
@ -14766,38 +14767,40 @@ static void Cmd_assistattackselect(void)
s32 chooseableMovesNo = 0; s32 chooseableMovesNo = 0;
struct Pokemon *party; struct Pokemon *party;
s32 monId, moveId; s32 monId, moveId;
u16 *validMoves = gBattleStruct->assistPossibleMoves; u16 *validMoves = Alloc(sizeof(u16) * PARTY_SIZE * MAX_MON_MOVES);
if (GET_BATTLER_SIDE(gBattlerAttacker) != B_SIDE_PLAYER) if (validMoves != NULL)
party = gEnemyParty;
else
party = gPlayerParty;
for (monId = 0; monId < PARTY_SIZE; monId++)
{ {
if (monId == gBattlerPartyIndexes[gBattlerAttacker]) if (GET_BATTLER_SIDE(gBattlerAttacker) != B_SIDE_PLAYER)
continue; party = gEnemyParty;
if (GetMonData(&party[monId], MON_DATA_SPECIES_OR_EGG) == SPECIES_NONE) else
continue; party = gPlayerParty;
if (GetMonData(&party[monId], MON_DATA_SPECIES_OR_EGG) == SPECIES_EGG)
continue;
for (moveId = 0; moveId < MAX_MON_MOVES; moveId++) for (monId = 0; monId < PARTY_SIZE; monId++)
{ {
s32 i = 0; if (monId == gBattlerPartyIndexes[gBattlerAttacker])
u16 move = GetMonData(&party[monId], MON_DATA_MOVE1 + moveId); continue;
if (GetMonData(&party[monId], MON_DATA_SPECIES_OR_EGG) == SPECIES_NONE)
if (sForbiddenMoves[move] & FORBIDDEN_ASSIST) continue;
if (GetMonData(&party[monId], MON_DATA_SPECIES_OR_EGG) == SPECIES_EGG)
continue; continue;
validMoves[chooseableMovesNo] = move; for (moveId = 0; moveId < MAX_MON_MOVES; moveId++)
chooseableMovesNo++; {
u16 move = GetMonData(&party[monId], MON_DATA_MOVE1 + moveId);
if (sForbiddenMoves[move] & FORBIDDEN_ASSIST)
continue;
validMoves[chooseableMovesNo++] = move;
}
} }
} }
if (chooseableMovesNo) if (chooseableMovesNo)
{ {
gHitMarker &= ~HITMARKER_ATTACKSTRING_PRINTED; gHitMarker &= ~HITMARKER_ATTACKSTRING_PRINTED;
gCalledMove = validMoves[((Random() & 0xFF) * chooseableMovesNo) >> 8]; gCalledMove = validMoves[Random() % chooseableMovesNo];
gBattlerTarget = GetMoveTarget(gCalledMove, NO_TARGET_OVERRIDE); gBattlerTarget = GetMoveTarget(gCalledMove, NO_TARGET_OVERRIDE);
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
} }
@ -14805,6 +14808,8 @@ static void Cmd_assistattackselect(void)
{ {
gBattlescriptCurrInstr = cmd->failInstr; gBattlescriptCurrInstr = cmd->failInstr;
} }
TRY_FREE_AND_SET_NULL(validMoves);
} }
static void Cmd_trysetmagiccoat(void) static void Cmd_trysetmagiccoat(void)

22
test/move_effect_assist.c Normal file
View File

@ -0,0 +1,22 @@
#include "global.h"
#include "test_battle.h"
ASSUMPTIONS
{
ASSUME(gBattleMoves[MOVE_ASSIST].effect == EFFECT_ASSIST);
}
SINGLE_BATTLE_TEST("Assist fails if there are no valid moves to choose from")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET) {Moves(MOVE_ASSIST, MOVE_CELEBRATE, MOVE_METRONOME, MOVE_ME_FIRST); }
PLAYER(SPECIES_WOBBUFFET) {Moves(MOVE_ASSIST, MOVE_ENDURE, MOVE_DRAGON_TAIL, MOVE_SPOTLIGHT); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(player, MOVE_ASSIST); }
} SCENE {
MESSAGE("Wobbuffet used Assist!");
NOT ANIMATION(ANIM_TYPE_MOVE, MOVE_ASSIST, player);
MESSAGE("But it failed!");
}
}

View File

@ -1227,6 +1227,7 @@ void Move(u32 sourceLine, struct BattlePokemon *battler, struct MoveContext ctx)
const struct BattleMove *move = &gBattleMoves[moveId]; const struct BattleMove *move = &gBattleMoves[moveId];
if (move->target == MOVE_TARGET_RANDOM if (move->target == MOVE_TARGET_RANDOM
|| move->target == MOVE_TARGET_BOTH || move->target == MOVE_TARGET_BOTH
|| move->target == MOVE_TARGET_DEPENDS
|| move->target == MOVE_TARGET_FOES_AND_ALLY || move->target == MOVE_TARGET_FOES_AND_ALLY
|| move->target == MOVE_TARGET_OPPONENTS_FIELD || move->target == MOVE_TARGET_OPPONENTS_FIELD
|| move->target == MOVE_TARGET_ALL_BATTLERS) || move->target == MOVE_TARGET_ALL_BATTLERS)