Merge remote-tracking branch 'upstream/upcoming' into overworldsnow

This commit is contained in:
kittenchilly 2023-08-31 11:56:12 -05:00
commit 9fcb1a8687
11 changed files with 68 additions and 24 deletions

View File

@ -42,6 +42,7 @@ MAKER_CODE := 01
REVISION := 0 REVISION := 0
MODERN ?= 0 MODERN ?= 0
TEST ?= 0 TEST ?= 0
ANALYZE ?= 0
ifeq (modern,$(MAKECMDGOALS)) ifeq (modern,$(MAKECMDGOALS))
MODERN := 1 MODERN := 1
@ -118,7 +119,10 @@ LIBPATH := -L ../../tools/agbcc/lib
LIB := $(LIBPATH) -lgcc -lc -L../../libagbsyscall -lagbsyscall LIB := $(LIBPATH) -lgcc -lc -L../../libagbsyscall -lagbsyscall
else else
CC1 = $(shell $(PATH_MODERNCC) --print-prog-name=cc1) -quiet CC1 = $(shell $(PATH_MODERNCC) --print-prog-name=cc1) -quiet
override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -std=gnu17 -fanalyzer override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -std=gnu17
ifeq ($(ANALYZE),1)
override CFLAGS += -fanalyzer
endif
ROM := $(MODERN_ROM_NAME) ROM := $(MODERN_ROM_NAME)
OBJ_DIR := $(MODERN_OBJ_DIR_NAME) OBJ_DIR := $(MODERN_OBJ_DIR_NAME)
LIBPATH := -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libc.a))" LIBPATH := -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libc.a))"

View File

@ -2018,3 +2018,10 @@
setvar VAR_0x8002, \tryMultiple setvar VAR_0x8002, \tryMultiple
special TrySpecialOverworldEvo special TrySpecialOverworldEvo
.endm .endm
.macro ai_vs_ai_battle trainer1:req, trainer2:req
setflag B_FLAG_AI_VS_AI_BATTLE
setvar VAR_0x8004, \trainer1
callnative CreateTrainerPartyForPlayer
trainerbattle_no_intro \trainer2, NULL
.endm

View File

@ -9,6 +9,7 @@
bool32 AI_RandLessThan(u8 val); bool32 AI_RandLessThan(u8 val);
void RecordLastUsedMoveByTarget(void); void RecordLastUsedMoveByTarget(void);
bool32 IsAiVsAiBattle(void);
bool32 BattlerHasAi(u32 battlerId); bool32 BattlerHasAi(u32 battlerId);
bool32 IsAiBattlerAware(u32 battlerId); bool32 IsAiBattlerAware(u32 battlerId);
void ClearBattlerMoveHistory(u8 battlerId); void ClearBattlerMoveHistory(u8 battlerId);

View File

@ -156,6 +156,7 @@
#define B_SMART_WILD_AI_FLAG 0 // If not 0, you can set this flag in a script to enable smart wild pokemon #define B_SMART_WILD_AI_FLAG 0 // If not 0, you can set this flag in a script to enable smart wild pokemon
#define B_FLAG_NO_BAG_USE 0 // If this flag is set, the ability to use the bag in battle is disabled. #define B_FLAG_NO_BAG_USE 0 // If this flag is set, the ability to use the bag in battle is disabled.
#define B_FLAG_NO_CATCHING 0 // If this flag is set, the ability to catch wild Pokémon is disabled. #define B_FLAG_NO_CATCHING 0 // If this flag is set, the ability to catch wild Pokémon is disabled.
#define B_FLAG_AI_VS_AI_BATTLE 0 // If this flag is set, the player's mons will be controlled by the ai next battles.
// Var Settings // Var Settings
// To use the following features in scripting, replace the 0s with the var ID you're assigning it to. // To use the following features in scripting, replace the 0s with the var ID you're assigning it to.

View File

@ -1030,6 +1030,9 @@ static bool8 ShouldUseItem(void)
u8 validMons = 0; u8 validMons = 0;
bool8 shouldUse = FALSE; bool8 shouldUse = FALSE;
if (IsAiVsAiBattle())
return FALSE;
// If teaming up with player and Pokemon is on the right, or Pokemon is currently held by Sky Drop // If teaming up with player and Pokemon is on the right, or Pokemon is currently held by Sky Drop
if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT) if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT)
|| gStatuses3[gActiveBattler] & STATUS3_SKY_DROPPED) || gStatuses3[gActiveBattler] & STATUS3_SKY_DROPPED)

View File

@ -8,6 +8,7 @@
#include "battle_ai_switch_items.h" #include "battle_ai_switch_items.h"
#include "battle_factory.h" #include "battle_factory.h"
#include "battle_setup.h" #include "battle_setup.h"
#include "event_data.h"
#include "data.h" #include "data.h"
#include "item.h" #include "item.h"
#include "pokemon.h" #include "pokemon.h"
@ -440,17 +441,27 @@ void RecordLastUsedMoveByTarget(void)
RecordKnownMove(gBattlerTarget, gLastMoves[gBattlerTarget]); RecordKnownMove(gBattlerTarget, gLastMoves[gBattlerTarget]);
} }
bool32 IsAiVsAiBattle(void)
{
return (B_FLAG_AI_VS_AI_BATTLE && FlagGet(B_FLAG_AI_VS_AI_BATTLE));
}
bool32 BattlerHasAi(u32 battlerId) bool32 BattlerHasAi(u32 battlerId)
{ {
switch (GetBattlerPosition(battlerId)) switch (GetBattlerPosition(battlerId))
{ {
case B_POSITION_PLAYER_LEFT: case B_POSITION_PLAYER_LEFT:
if (IsAiVsAiBattle())
return TRUE;
default: default:
return FALSE; return FALSE;
case B_POSITION_OPPONENT_LEFT: case B_POSITION_OPPONENT_LEFT:
return TRUE; return TRUE;
case B_POSITION_PLAYER_RIGHT: case B_POSITION_PLAYER_RIGHT:
return ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) != 0); if ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) || IsAiVsAiBattle())
return TRUE;
else
return FALSE;
case B_POSITION_OPPONENT_RIGHT: case B_POSITION_OPPONENT_RIGHT:
return TRUE; return TRUE;
} }

View File

@ -307,6 +307,12 @@ static void PlayerPartnerHandleDrawTrainerPic(u32 battler)
xPos = 90; xPos = 90;
yPos = (8 - gTrainerBackPicCoords[trainerPicId].size) * 4 + 80; yPos = (8 - gTrainerBackPicCoords[trainerPicId].size) * 4 + 80;
} }
else if (IsAiVsAiBattle())
{
trainerPicId = gTrainers[gPartnerTrainerId].trainerPic;
xPos = 60;
yPos = (8 - gTrainerFrontPicCoords[trainerPicId].size) * 4 + 80;
}
else else
{ {
trainerPicId = GetFrontierTrainerFrontSpriteId(gPartnerTrainerId); trainerPicId = GetFrontierTrainerFrontSpriteId(gPartnerTrainerId);
@ -434,6 +440,8 @@ static void PlayerPartnerHandleIntroTrainerBallThrow(u32 battler)
trainerPal = gTrainerBackPicPaletteTable[TRAINER_STEVEN_PARTNER].data; trainerPal = gTrainerBackPicPaletteTable[TRAINER_STEVEN_PARTNER].data;
else if (gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) // Custom multi battle. else if (gPartnerTrainerId >= TRAINER_CUSTOM_PARTNER) // Custom multi battle.
trainerPal = gTrainerBackPicPaletteTable[gPartnerSpriteId].data; trainerPal = gTrainerBackPicPaletteTable[gPartnerSpriteId].data;
else if (IsAiVsAiBattle())
trainerPal = gTrainerFrontPicPaletteTable[gTrainers[gPartnerTrainerId].trainerPic].data;
else else
trainerPal = gTrainerFrontPicPaletteTable[GetFrontierTrainerFrontSpriteId(gPartnerTrainerId)].data; // 2 vs 2 multi battle in Battle Frontier, load front sprite and pal. trainerPal = gTrainerFrontPicPaletteTable[GetFrontierTrainerFrontSpriteId(gPartnerTrainerId)].data; // 2 vs 2 multi battle in Battle Frontier, load front sprite and pal.

View File

@ -1,8 +1,9 @@
#include "global.h" #include "global.h"
#include "battle.h" #include "battle.h"
#include "battle_ai_main.h" #include "battle_ai_main.h"
#include "battle_arena.h" #include "battle_ai_util.h"
#include "battle_anim.h" #include "battle_anim.h"
#include "battle_arena.h"
#include "battle_controllers.h" #include "battle_controllers.h"
#include "battle_gfx_sfx_util.h" #include "battle_gfx_sfx_util.h"
#include "battle_interface.h" #include "battle_interface.h"
@ -185,6 +186,8 @@ static void InitSinglePlayerBtlControllers(void)
gBattlerControllerFuncs[0] = SetControllerToSafari; gBattlerControllerFuncs[0] = SetControllerToSafari;
else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL) else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL)
gBattlerControllerFuncs[0] = SetControllerToWally; gBattlerControllerFuncs[0] = SetControllerToWally;
else if (IsAiVsAiBattle())
gBattlerControllerFuncs[0] = SetControllerToPlayerPartner;
else else
gBattlerControllerFuncs[0] = SetControllerToPlayer; gBattlerControllerFuncs[0] = SetControllerToPlayer;
@ -236,13 +239,19 @@ static void InitSinglePlayerBtlControllers(void)
{ {
gBattleMainFunc = BeginBattleIntro; gBattleMainFunc = BeginBattleIntro;
gBattlerControllerFuncs[0] = SetControllerToPlayer; if (IsAiVsAiBattle())
gBattlerControllerFuncs[0] = SetControllerToPlayerPartner;
else
gBattlerControllerFuncs[0] = SetControllerToPlayer;
gBattlerPositions[0] = B_POSITION_PLAYER_LEFT; gBattlerPositions[0] = B_POSITION_PLAYER_LEFT;
gBattlerControllerFuncs[1] = SetControllerToOpponent; gBattlerControllerFuncs[1] = SetControllerToOpponent;
gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT; gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT;
gBattlerControllerFuncs[2] = SetControllerToPlayer; if (IsAiVsAiBattle())
gBattlerControllerFuncs[2] = SetControllerToPlayerPartner;
else
gBattlerControllerFuncs[2] = SetControllerToPlayer;
gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT; gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT;
gBattlerControllerFuncs[3] = SetControllerToOpponent; gBattlerControllerFuncs[3] = SetControllerToOpponent;

View File

@ -565,13 +565,12 @@ static void CB2_InitBattleInternal(void)
gBattle_BG3_X = 0; gBattle_BG3_X = 0;
gBattle_BG3_Y = 0; gBattle_BG3_Y = 0;
#if DEBUG_OVERWORLD_MENU == FALSE #if DEBUG_OVERWORLD_MENU == TRUE
gBattleTerrain = BattleSetup_GetTerrainId();
#else
if (!gIsDebugBattle) if (!gIsDebugBattle)
gBattleTerrain = BattleSetup_GetTerrainId();
#endif #endif
{
gBattleTerrain = BattleSetup_GetTerrainId();
}
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
gBattleTerrain = BATTLE_TERRAIN_BUILDING; gBattleTerrain = BATTLE_TERRAIN_BUILDING;
@ -594,27 +593,19 @@ static void CB2_InitBattleInternal(void)
else else
SetMainCallback2(CB2_HandleStartBattle); SetMainCallback2(CB2_HandleStartBattle);
#if DEBUG_OVERWORLD_MENU == FALSE #if DEBUG_OVERWORLD_MENU == TRUE
if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED)))
{
CreateNPCTrainerParty(&gEnemyParty[0], gTrainerBattleOpponent_A, TRUE);
if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && !BATTLE_TWO_VS_ONE_OPPONENT)
CreateNPCTrainerParty(&gEnemyParty[PARTY_SIZE / 2], gTrainerBattleOpponent_B, FALSE);
SetWildMonHeldItem();
CalculateEnemyPartyCount();
}
#else
if (!gIsDebugBattle) if (!gIsDebugBattle)
#endif
{ {
if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED))) if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED)))
{ {
CreateNPCTrainerParty(&gEnemyParty[0], gTrainerBattleOpponent_A, TRUE); CreateNPCTrainerParty(&gEnemyParty[0], gTrainerBattleOpponent_A, TRUE);
if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && !BATTLE_TWO_VS_ONE_OPPONENT)
CreateNPCTrainerParty(&gEnemyParty[PARTY_SIZE / 2], gTrainerBattleOpponent_B, FALSE); CreateNPCTrainerParty(&gEnemyParty[PARTY_SIZE / 2], gTrainerBattleOpponent_B, FALSE);
SetWildMonHeldItem(); SetWildMonHeldItem();
CalculateEnemyPartyCount();
} }
} }
#endif
gMain.inBattle = TRUE; gMain.inBattle = TRUE;
gSaveBlock2Ptr->frontier.disableRecordBattle = FALSE; gSaveBlock2Ptr->frontier.disableRecordBattle = FALSE;
@ -2071,6 +2062,13 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir
return retVal; return retVal;
} }
void CreateTrainerPartyForPlayer(void)
{
ZeroPlayerPartyMons();
gPartnerTrainerId = gSpecialVar_0x8004;
CreateNPCTrainerPartyFromTrainer(gPlayerParty, &gTrainers[gSpecialVar_0x8004], TRUE, BATTLE_TYPE_TRAINER);
}
void VBlankCB_Battle(void) void VBlankCB_Battle(void)
{ {
// Change gRngSeed every vblank unless the battle could be recorded. // Change gRngSeed every vblank unless the battle could be recorded.

View File

@ -4068,7 +4068,9 @@ static void Cmd_getexp(void)
switch (gBattleScripting.getexpState) switch (gBattleScripting.getexpState)
{ {
case 0: // check if should receive exp at all case 0: // check if should receive exp at all
if (GetBattlerSide(gBattlerFainted) != B_SIDE_OPPONENT || (gBattleTypeFlags & if (GetBattlerSide(gBattlerFainted) != B_SIDE_OPPONENT
|| IsAiVsAiBattle()
|| (gBattleTypeFlags &
(BATTLE_TYPE_LINK (BATTLE_TYPE_LINK
| BATTLE_TYPE_RECORDED_LINK | BATTLE_TYPE_RECORDED_LINK
| BATTLE_TYPE_TRAINER_HILL | BATTLE_TYPE_TRAINER_HILL

View File

@ -7985,7 +7985,7 @@ u8 IsMonDisobedient(void)
if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK)) if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK))
return 0; return 0;
if (GetBattlerSide(gBattlerAttacker) == B_SIDE_OPPONENT) if (BattlerHasAi(gBattlerAttacker))
return 0; return 0;
if (IsBattlerModernFatefulEncounter(gBattlerAttacker)) // only false if illegal Mew or Deoxys if (IsBattlerModernFatefulEncounter(gBattlerAttacker)) // only false if illegal Mew or Deoxys