Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partner Battle refactor #3592

Merged
merged 12 commits into from
Dec 20, 2023
17 changes: 1 addition & 16 deletions data/maps/MossdeepCity_SpaceCenter_2F/scripts.inc
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,7 @@ MossdeepCity_SpaceCenter_2F_EventScript_ChoosePartyForMultiBattle::
goto MossdeepCity_SpaceCenter_2F_EventScript_ReadyForBattlePrompt

MossdeepCity_SpaceCenter_2F_EventScript_DoStevenMultiBattle::
special ReducePlayerPartyToSelectedMons
frontier_set FRONTIER_DATA_SELECTED_MON_ORDER
setvar VAR_0x8004, SPECIAL_BATTLE_STEVEN
setvar VAR_0x8005, 0
special DoSpecialTrainerBattle
waitstate
frontier_saveparty
special LoadPlayerParty
multi_2_vs_2 TRAINER_MAXIE_MOSSDEEP, MossdeepCity_SpaceCenter_2F_Text_JustWantToExpandLand, TRAINER_TABITHA_MOSSDEEP, MossdeepCity_SpaceCenter_Text_TabithaDefeat, PARTNER_STEVEN, TRAINER_BACK_PIC_STEVEN
switch VAR_RESULT
case 1, MossdeepCity_SpaceCenter_2F_EventScript_DefeatedMaxieTabitha
fadescreen FADE_TO_BLACK
Expand Down Expand Up @@ -336,14 +329,6 @@ MossdeepCity_SpaceCenter_2F_EventScript_StevenFacePlayerWest::
turnobject LOCALID_STEVEN, DIR_EAST
return

MossdeepCity_SpaceCenter_2F_EventScript_MaxieTrainer::
trainerbattle TRAINER_BATTLE_SET_TRAINER_A, TRAINER_MAXIE_MOSSDEEP, 0, MossdeepCity_SpaceCenter_2F_Text_JustWantToExpandLand, MossdeepCity_SpaceCenter_2F_Text_JustWantToExpandLand
end

MossdeepCity_SpaceCenter_2F_EventScript_TabithaTrainer::
trainerbattle TRAINER_BATTLE_SET_TRAINER_B, TRAINER_TABITHA_MOSSDEEP, 0, MossdeepCity_SpaceCenter_Text_TabithaDefeat, MossdeepCity_SpaceCenter_Text_TabithaDefeat
end

MossdeepCity_SpaceCenter_2F_EventScript_RivalRayquazaCall::
lockall
checkplayergender
Expand Down
7 changes: 3 additions & 4 deletions include/constants/battle_frontier.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@
#define SPECIAL_BATTLE_ARENA 5
#define SPECIAL_BATTLE_FACTORY 6
#define SPECIAL_BATTLE_PIKE_SINGLE 7
#define SPECIAL_BATTLE_STEVEN 8
#define SPECIAL_BATTLE_PIKE_DOUBLE 9
#define SPECIAL_BATTLE_PYRAMID 10
#define SPECIAL_BATTLE_MULTI 11
#define SPECIAL_BATTLE_PIKE_DOUBLE 8
#define SPECIAL_BATTLE_PYRAMID 9
#define SPECIAL_BATTLE_MULTI 10

#define MAX_BATTLE_FRONTIER_POINTS 9999
#define MAX_STREAK 9999
Expand Down
8 changes: 8 additions & 0 deletions include/constants/battle_partner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#ifndef GUARD_CONSTANTS_BATTLE_PARTNERS_H
#define GUARD_CONSTANTS_BATTLE_PARTNERS_H

#define PARTNER_NONE 0
#define PARTNER_STEVEN 1

#endif // GUARD_CONSTANTS_BATTLE_PARTNERS_H
3 changes: 3 additions & 0 deletions include/constants/opponents.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef GUARD_CONSTANTS_OPPONENTS_H
#define GUARD_CONSTANTS_OPPONENTS_H

#include "constants/battle_partner.h"

#define TRAINER_NONE 0
#define TRAINER_SAWYER_1 1
#define TRAINER_GRUNT_AQUA_HIDEOUT_1 2
Expand Down Expand Up @@ -863,5 +865,6 @@

#define TRAINERS_COUNT 855
#define MAX_TRAINERS_COUNT 864
#define TRAINER_PARTNER(partner) (MAX_TRAINERS_COUNT + partner)

#endif // GUARD_CONSTANTS_OPPONENTS_H
2 changes: 0 additions & 2 deletions include/constants/trainers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#define TRAINER_SECRET_BASE 1024
#define TRAINER_LINK_OPPONENT 2048
#define TRAINER_UNION_ROOM 3072
#define TRAINER_STEVEN_PARTNER 3075
#define TRAINER_CUSTOM_PARTNER 3076

#define TRAINER_PIC_HIKER 0
#define TRAINER_PIC_AQUA_GRUNT_M 1
Expand Down
2 changes: 2 additions & 0 deletions include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ extern const struct CompressedSpriteSheet gTrainerBackPicTable[]; // functionall
extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[];

extern const struct Trainer gTrainers[];
extern const struct Trainer gBattlePartners[];

extern const u8 gTrainerClassNames[][13];
extern const u8 gMoveNames[MOVES_COUNT_DYNAMAX][MOVE_NAME_LENGTH + 1];
extern const u8 *const gZMoveNames[];
Expand Down
1 change: 0 additions & 1 deletion include/event_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ extern const u8 EventScript_TradeCenter_Chair1[];
extern const u8 EventScript_TradeCenter_Chair0[];
extern const u8 EventScript_ConfirmLeaveCableClubRoom[];
extern const u8 EventScript_TerminateLink[];

extern const u8 VSSeeker_Text_BatteryNotChargedNeedXSteps[];
extern const u8 VSSeeker_Text_NoTrainersWithinRange[];
extern const u8 VSSeeker_Text_TrainersNotReady[];
Expand Down
3 changes: 2 additions & 1 deletion src/battle_bg.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "constants/songs.h"
#include "constants/trainers.h"
#include "constants/battle_anim.h"
#include "constants/battle_partner.h"

// .rodata
static const u16 sUnrefArray[] = {0x0300, 0x0000}; //OamData?
Expand Down Expand Up @@ -1146,7 +1147,7 @@ void DrawBattleEntryBackground(void)
}
else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_EREADER_TRAINER))
{
if (!(gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || gPartnerTrainerId == TRAINER_STEVEN_PARTNER || gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER)
if (!(gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE))
{
LZDecompressVram(gBattleTerrainAnimTiles_Building, (void *)(BG_CHAR_ADDR(1)));
LZDecompressVram(gBattleTerrainAnimTilemap_Building, (void *)(BG_SCREEN_ADDR(28)));
Expand Down
5 changes: 3 additions & 2 deletions src/battle_controller_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "util.h"
#include "window.h"
#include "constants/battle_anim.h"
#include "constants/battle_partner.h"
#include "constants/hold_effects.h"
#include "constants/items.h"
#include "constants/moves.h"
Expand Down Expand Up @@ -1875,7 +1876,7 @@ static void PlayerHandleDrawTrainerPic(u32 battler)
else // First mon, on the left.
xPos = 32;

if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER && gPartnerTrainerId < TRAINER_CUSTOM_PARTNER)
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId < TRAINER_PARTNER(PARTNER_NONE))
{
xPos = 90;
yPos = (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 80;
Expand All @@ -1893,7 +1894,7 @@ static void PlayerHandleDrawTrainerPic(u32 battler)
}

// Use front pic table for any tag battles unless your partner is Steven or a custom partner.
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER && gPartnerTrainerId < TRAINER_CUSTOM_PARTNER)
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId < TRAINER_PARTNER(PARTNER_NONE))
{
trainerPicId = PlayerGenderToFrontTrainerPicId(gSaveBlock2Ptr->playerGender);
isFrontPic = TRUE;
Expand Down
19 changes: 6 additions & 13 deletions src/battle_controller_player_partner.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "util.h"
#include "window.h"
#include "constants/battle_anim.h"
#include "constants/battle_partner.h"
#include "constants/songs.h"
#include "constants/party_menu.h"
#include "constants/trainers.h"
Expand Down Expand Up @@ -296,15 +297,9 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler)
s16 xPos, yPos;
u32 trainerPicId;

if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER)
if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE))
{
trainerPicId = TRAINER_BACK_PIC_STEVEN;
xPos = 90;
yPos = (8 - gTrainerBackPicCoords[trainerPicId].size) * 4 + 80;
}
else if (gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER)
{
trainerPicId = gPartnerSpriteId;
trainerPicId = gBattlePartners[gPartnerTrainerId - TRAINER_PARTNER(PARTNER_NONE)].trainerPic;
xPos = 90;
yPos = (8 - gTrainerBackPicCoords[trainerPicId].size) * 4 + 80;
}
Expand All @@ -321,8 +316,8 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler)
yPos = (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 80;
}

// Use back pic only if the partner is Steven or a custom partner.
if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER || gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER)
// Use back pic only if the partner Steven or is custom.
if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE))
isFrontPic = FALSE;
else
isFrontPic = TRUE;
Expand Down Expand Up @@ -439,9 +434,7 @@ static void PlayerPartnerHandleIntroTrainerBallThrow(u32 battler)
{
const u32 *trainerPal;

if (gPartnerTrainerId == TRAINER_STEVEN_PARTNER)
trainerPal = gTrainerBackPicPaletteTable[TRAINER_STEVEN_PARTNER].data;
else if (gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) // Custom multi battle.
if (gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE))
trainerPal = gTrainerBackPicPaletteTable[gPartnerSpriteId].data;
else if (IsAiVsAiBattle())
trainerPal = gTrainerFrontPicPaletteTable[gTrainers[gPartnerTrainerId].trainerPic].data;
Expand Down
3 changes: 2 additions & 1 deletion src/battle_intro.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "scanline_effect.h"
#include "task.h"
#include "trig.h"
#include "constants/battle_partner.h"
#include "constants/trainers.h"

extern const u8 gBattleAnimBgCntSet[];
Expand Down Expand Up @@ -104,7 +105,7 @@ void HandleIntroSlide(u8 terrain)
{
u8 taskId;

if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) && gPartnerTrainerId != TRAINER_STEVEN_PARTNER && gPartnerTrainerId < TRAINER_CUSTOM_PARTNER)
if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) && gPartnerTrainerId < TRAINER_PARTNER(PARTNER_NONE))
{
taskId = CreateTask(BattleIntroSlidePartner, 0);
}
Expand Down
3 changes: 2 additions & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "constants/abilities.h"
#include "constants/battle_move_effects.h"
#include "constants/battle_string_ids.h"
#include "constants/battle_partner.h"
#include "constants/hold_effects.h"
#include "constants/items.h"
#include "constants/moves.h"
Expand Down Expand Up @@ -512,7 +513,7 @@ static void CB2_InitBattleInternal(void)

gBattle_WIN0H = DISPLAY_WIDTH;

if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId != TRAINER_STEVEN_PARTNER && gPartnerTrainerId < TRAINER_CUSTOM_PARTNER)
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId < TRAINER_PARTNER(PARTNER_NONE))
{
gBattle_WIN0V = DISPLAY_HEIGHT - 1;
gBattle_WIN1H = DISPLAY_WIDTH;
Expand Down
24 changes: 6 additions & 18 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "constants/battle_anim.h"
#include "constants/battle_move_effects.h"
#include "constants/battle_string_ids.h"
#include "constants/battle_partner.h"
#include "constants/hold_effects.h"
#include "constants/items.h"
#include "constants/item_effects.h"
Expand Down Expand Up @@ -4363,7 +4364,7 @@ static bool32 NoAliveMonsForPlayerAndPartner(void)
u32 i;
u32 HP_count = 0;

if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && (gPartnerTrainerId == TRAINER_STEVEN_PARTNER || gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER))
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gPartnerTrainerId > TRAINER_PARTNER(PARTNER_NONE))
{
for (i = 0; i < PARTY_SIZE; i++)
{
Expand All @@ -4383,25 +4384,12 @@ bool32 NoAliveMonsForPlayer(void)
u32 i;
u32 HP_count = 0;

// Get total HP for the player's party to determine if the player has lost
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && (gPartnerTrainerId == TRAINER_STEVEN_PARTNER || gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER))
for (i = 0; i < PARTY_SIZE; i++)
{
// In multi battle with Steven, skip his Pokémon
for (i = 0; i < MULTI_PARTY_SIZE; i++)
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)
&& (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || !(gBattleStruct->arenaLostPlayerMons & gBitTable[i])))
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG))
HP_count += GetMonData(&gPlayerParty[i], MON_DATA_HP);
}
}
else
{
for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)
&& (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || !(gBattleStruct->arenaLostPlayerMons & gBitTable[i])))
{
HP_count += GetMonData(&gPlayerParty[i], MON_DATA_HP);
}
HP_count += GetMonData(&gPlayerParty[i], MON_DATA_HP);
}
}

Expand Down
Loading
Loading