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

Disable items in trainer battle #349

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hooks
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,5 @@ arm9 form_evo_hook_2 0207641C 0
0002 PlayerStepEvent_RepelCounterDecrement 0224BAE4 2
0015 BagApp_GetRepelStepCountAddr 021F993C 3
#endif

0012 BattleContext_Main 022486B0 2
23 changes: 23 additions & 0 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
#define BATTLE_TYPE_ROAMER 0x100
#define BATTLE_TYPE_POKE_PARK 0x200
#define BATTLE_TYPE_CATCHING_DEMO 0x400
#define BATTLE_TYPE_BUG_CONTEST 0x1000

#define BATTLE_TYPE_NO_EXPERIENCE (BATTLE_TYPE_WIRELESS | BATTLE_TYPE_SAFARI | BATTLE_TYPE_BATTLE_TOWER | BATTLE_TYPE_POKE_PARK)

Expand Down Expand Up @@ -965,6 +966,28 @@ typedef struct {
} TerrainOverlay;


typedef enum BattleSelectState {
SSI_STATE_SELECT_COMMAND_INIT,
SSI_STATE_1,
SSI_STATE_2,
SSI_STATE_3,
SSI_STATE_4,
SSI_STATE_5,
SSI_STATE_6,
SSI_STATE_7,
SSI_STATE_8,
SSI_STATE_9,
SSI_STATE_10,
SSI_STATE_11,
SSI_STATE_12,
SSI_STATE_13,
SSI_STATE_14,
SSI_STATE_15,
SSI_STATE_NO_MOVES,
SSI_STATE_END
} BattleSelectState;


/**
* @brief enum for command field from BattleStruct
*/
Expand Down
14 changes: 14 additions & 0 deletions include/battle_controller_player.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef BATTLE_CONTROLLER_PLAYER_H
#define BATTLE_CONTROLLER_PLAYER_H

#include "battle.h"

typedef void (*ControllerFunction)(struct BattleSystem *, struct BattleStruct *);

extern const ControllerFunction sPlayerBattleCommands[];

void LONG_CALL ov12_022639B8(struct BattleSystem *bsys, int battlerId, MESSAGE_PARAM msg);
u8 LONG_CALL BattleSystem_GetBattleOutcomeFlags(struct BattleSystem *bsys);
BOOL LONG_CALL BattleContext_Main(struct BattleSystem *bsys, struct BattleStruct *ctx);

#endif
3 changes: 3 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,7 @@
// IMPLEMENT_REUSABLE_REPELS defines whether or not a prompt to use another repel automatically appears upon the previous repel being used up
#define IMPLEMENT_REUSABLE_REPELS

// DISABLE_ITEMS_IN_TRAINER_BATTLE will disable the usage of items in trainer battles. This is also true for the AI.
//#define DISABLE_ITEMS_IN_TRAINER_BATTLE

#endif
2 changes: 2 additions & 0 deletions include/constants/battle_message_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#define BATTLE_MSG_MON_KNOCKED_OFF_ITEM (552)

#define BATTLE_MSG_ITEMS_CANT_BE_USED_HERE (593)

#define BATTLE_MSG_CANNOT_USE_MOVE_DISABLED (609)
#define BATTLE_MSG_CANNOT_USE_MOVE_TORMENT (612)
#define BATTLE_MSG_CANNOT_USE_MOVE_TAUNT (613)
Expand Down
4 changes: 4 additions & 0 deletions rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,7 @@ BattleContext_CheckMoveHealBlocked = 0x02252DF8 | 1;
CanUseItemOnPokemon = 0x0208FD9C | 1;

BagApp_GetSaveRoamers = 0x021F992C | 1;

sPlayerBattleCommands = 0x0226CA90;
BattleSystem_GetBattleOutcomeFlags = 0x0223BD14 | 1;
ov12_022639B8 = 0x022639B8 | 1;
49 changes: 49 additions & 0 deletions src/battle/battle_controller_player.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "../../include/battle.h"
#include "../../include/battle_controller_player.h"
#include "../../include/constants/battle_message_constants.h"

#if defined (DISABLE_ITEMS_IN_TRAINER_BATTLE)
void overrideItemUsage(struct BattleSystem *bsys, struct BattleStruct *ctx)
{
MESSAGE_PARAM mp;
int battlerId;
u32 fight_type = BattleTypeGet(bsys);

for (battlerId = 0; battlerId < bsys->maxBattlers; battlerId++)
{
if (ctx->playerActions[battlerId][0] == CONTROLLER_COMMAND_ITEM_INPUT && ctx->com_seq_no[battlerId] == 7)
{
if (fight_type & BATTLE_TYPE_TRAINER)
{
mp.msg_id = BATTLE_MSG_ITEMS_CANT_BE_USED_HERE; //msg.id = msg_0197_00593; // Items can't be used here
mp.msg_tag = TAG_NONE;
ov12_022639B8(bsys, battlerId, mp);
ctx->com_seq_no[battlerId] = SSI_STATE_15;
ctx->ret_seq_no[battlerId] = SSI_STATE_SELECT_COMMAND_INIT;
}
}
}
}
#endif

BOOL LONG_CALL BattleContext_Main(struct BattleSystem *bsys, struct BattleStruct *ctx)
{
if (!ctx->fight_end_flag)
{
if (BattleSystem_GetBattleOutcomeFlags(bsys) && !(BattleSystem_GetBattleOutcomeFlags(bsys) & 0x40))
{
ctx->server_seq_no = CONTROLLER_COMMAND_42;
}
}

sPlayerBattleCommands[ctx->server_seq_no](bsys, ctx);
#if defined (DISABLE_ITEMS_IN_TRAINER_BATTLE)
overrideItemUsage(bsys, ctx);
#endif

if (ctx->server_seq_no == CONTROLLER_COMMAND_45)
{
return TRUE;
}
return FALSE;
}