From d52016bc310ca6d476067b0cb27c40c20ee1946d Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 24 Nov 2018 13:29:10 +0100 Subject: [PATCH] Mon creation in custom multi battles --- .../scripts.inc | 2 + include/battle_debug.h | 2 +- src/battle_ai_script_commands.c | 2 +- src/battle_setup.c | 4 +- src/battle_tower.c | 68 +++++++++++++++++-- 5 files changed, 67 insertions(+), 11 deletions(-) diff --git a/data/maps/EverGrandeCity_PokemonLeague_1F/scripts.inc b/data/maps/EverGrandeCity_PokemonLeague_1F/scripts.inc index 4e46bd1d0e..27ac842afc 100644 --- a/data/maps/EverGrandeCity_PokemonLeague_1F/scripts.inc +++ b/data/maps/EverGrandeCity_PokemonLeague_1F/scripts.inc @@ -47,6 +47,8 @@ EverGrandeCity_PokemonLeague_1F_Pokemart_229624: @ 8229624 end EverGrandeCity_PokemonLeague_1F_EventScript_229636:: @ 8229636 + trainerbattle 10, 406, 0, NULL, EverGrandeCity_PokemonLeague_1F_Text_2297EF, NULL + trainerbattle 11, 402, 0, NULL, EverGrandeCity_PokemonLeague_1F_Text_2297EF, NULL setvar VAR_0x8004, 11 setvar VAR_0x8006, 404 setvar VAR_0x8007, 3 diff --git a/include/battle_debug.h b/include/battle_debug.h index 42dd97f5a7..271f875538 100644 --- a/include/battle_debug.h +++ b/include/battle_debug.h @@ -3,6 +3,6 @@ #define USE_BATTLE_DEBUG TRUE -extern void CB2_BattleDebugMenu(void); +void CB2_BattleDebugMenu(void); #endif // GUARD_BATTLE_DEBUG_H diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 91baf4d7c3..db63a5c68e 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -2524,5 +2524,5 @@ static void BattleAICmd_if_doesnt_hold_berry(void) if (ItemId_GetPocket(item) == POCKET_BERRIES) gAIScriptPtr += 6; else - T1_READ_PTR(gAIScriptPtr + 2); + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); } diff --git a/src/battle_setup.c b/src/battle_setup.c index d42f572370..7770815b13 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -1143,10 +1143,10 @@ const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) return EventScript_271362; case TRAINER_BATTLE_SET_TRAINER_A: TrainerBattleLoadArgs(sOrdinaryBattleParams, data); - return NULL; + return sTrainerBattleEndScript; case TRAINER_BATTLE_SET_TRAINER_B: TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); - return NULL; + return sTrainerBattleEndScript; case TRAINER_BATTLE_12: if (gApproachingTrainerId == 0) { diff --git a/src/battle_tower.c b/src/battle_tower.c index b4a92a8467..2131b5d11c 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1476,10 +1476,6 @@ void DoSpecialTrainerBattle(void) gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER; gPartnerSpriteId = gSpecialVar_0x8007; FillPartnerParty(gSpecialVar_0x8006 + TRAINER_CUSTOM_PARTNER); - gApproachingTrainerId = 0; - BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_224157 + 1); - gApproachingTrainerId = 1; - BattleSetup_ConfigureTrainerBattle(MossdeepCity_SpaceCenter_2F_EventScript_224166 + 1); gPartnerTrainerId = gSpecialVar_0x8006 + TRAINER_CUSTOM_PARTNER; CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); @@ -2302,7 +2298,7 @@ static void FillPartnerParty(u16 trainerId) u32 friendship; u16 monSetId; u32 otID; - u8 trainerName[PLAYER_NAME_LENGTH + 1]; + u8 trainerName[(PLAYER_NAME_LENGTH * 3) + 1]; SetFacilityPtrsGetLevel(); if (trainerId == TRAINER_STEVEN_PARTNER) @@ -2331,10 +2327,68 @@ static void FillPartnerParty(u16 trainerId) } else if (trainerId >= TRAINER_CUSTOM_PARTNER) { + otID = Random32(); + for (i = 0; i < 3; i++) + ZeroMonData(&gPlayerParty[i + 3]); + + for (i = 0; i < 3 && i < gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].partySize; i++) { - // Temporary. - CreateMon(&gPlayerParty[3 + i], Random() % NUM_SPECIES, Random() % MAX_LEVEL, Random() % 31, 0, 0, 0, 0); + do + { + j = Random32(); + } while (IsShinyOtIdPersonality(otID, j)); + + switch (gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].partyFlags) + { + case 0: + { + const struct TrainerMonNoItemDefaultMoves *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party.NoItemDefaultMoves; + + CreateMon(&gPlayerParty[i + 3], partyData[i].species, partyData[i].lvl, partyData[i].iv * 31 / 255, TRUE, j, TRUE, otID); + break; + } + case F_TRAINER_PARTY_CUSTOM_MOVESET: + { + const struct TrainerMonNoItemCustomMoves *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party.NoItemCustomMoves; + + CreateMon(&gPlayerParty[i + 3], partyData[i].species, partyData[i].lvl, partyData[i].iv * 31 / 255, TRUE, j, TRUE, otID); + + for (j = 0; j < 4; j++) + { + SetMonData(&gPlayerParty[i + 3], MON_DATA_MOVE1 + j, &partyData[i].moves[j]); + SetMonData(&gPlayerParty[i + 3], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp); + } + break; + } + case F_TRAINER_PARTY_HELD_ITEM: + { + const struct TrainerMonItemDefaultMoves *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party.ItemDefaultMoves; + + CreateMon(&gPlayerParty[i + 3], partyData[i].species, partyData[i].lvl, partyData[i].iv * 31 / 255, TRUE, j, TRUE, otID); + + SetMonData(&gPlayerParty[i + 3], MON_DATA_HELD_ITEM, &partyData[i].heldItem); + break; + } + case F_TRAINER_PARTY_CUSTOM_MOVESET | F_TRAINER_PARTY_HELD_ITEM: + { + const struct TrainerMonItemCustomMoves *partyData = gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].party.ItemCustomMoves; + + CreateMon(&gPlayerParty[i + 3], partyData[i].species, partyData[i].lvl, partyData[i].iv * 31 / 255, TRUE, j, TRUE, otID); + + SetMonData(&gPlayerParty[i + 3], MON_DATA_HELD_ITEM, &partyData[i].heldItem); + + for (j = 0; j < 4; j++) + { + SetMonData(&gPlayerParty[i + 3], MON_DATA_MOVE1 + j, &partyData[i].moves[j]); + SetMonData(&gPlayerParty[i + 3], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp); + } + break; + } + } + + StringCopy(trainerName, gTrainers[trainerId - TRAINER_CUSTOM_PARTNER].trainerName); + SetMonData(&gPlayerParty[i + 3], MON_DATA_OT_NAME, trainerName); } } else if (trainerId == TRAINER_EREADER)