Skip to content

Commit

Permalink
Document BattleSystem_PluckBerry + _FlingItem and related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lhearachel committed Nov 1, 2023
1 parent 221cde6 commit 4926316
Show file tree
Hide file tree
Showing 8 changed files with 786 additions and 548 deletions.
14 changes: 14 additions & 0 deletions include/constants/flavor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef POKEPLATINUM_CONSTANTS_FLAVOR_H
#define POKEPLATINUM_CONSTANTS_FLAVOR_H

enum {
FLAVOR_SPICY = 0,
FLAVOR_DRY,
FLAVOR_SWEET,
FLAVOR_BITTER,
FLAVOR_SOUR,

FLAVOR_MAX,
};

#endif // POKEPLATINUM_CONSTANTS_FLAVOR_H
57 changes: 57 additions & 0 deletions include/constants/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,63 @@ enum {
#define HOLD_EFFECT_EVOLVE_PORYGON2 145
#define HOLD_EFFECT_EVOLVE_DUSCLOPS 146

#define FLING_EFFECT_NONE 0
#define FLING_EFFECT_PRZ_RESTORE 1
#define FLING_EFFECT_SLP_RESTORE 2
#define FLING_EFFECT_PSN_RESTORE 3
#define FLING_EFFECT_BRN_RESTORE 4
#define FLING_EFFECT_FRZ_RESTORE 5
#define FLING_EFFECT_PP_RESTORE 6
#define FLING_EFFECT_HP_RESTORE 7
#define FLING_EFFECT_CNF_RESTORE 8
#define FLING_EFFECT_ALL_RESTORE 9
#define FLING_EFFECT_HP_PCT_RESTORE 10
#define FLING_EFFECT_HP_RESTORE_SPICY 11
#define FLING_EFFECT_HP_RESTORE_DRY 12
#define FLING_EFFECT_HP_RESTORE_SWEET 13
#define FLING_EFFECT_HP_RESTORE_BITTER 14
#define FLING_EFFECT_HP_RESTORE_SOUR 15
#define FLING_EFFECT_ATK_UP 16
#define FLING_EFFECT_DEF_UP 17
#define FLING_EFFECT_SPEED_UP 18
#define FLING_EFFECT_SPATK_UP 19
#define FLING_EFFECT_SPDEF_UP 20
#define FLING_EFFECT_CRIT_UP 21
#define FLING_EFFECT_RANDOM_UP2 22
#define FLING_EFFECT_TEMP_ACC_UP 23
#define FLING_EFFECT_STATDOWN_RESTORE 24
#define FLING_EFFECT_HEAL_INFATUATION 25
#define FLING_EFFECT_FLINCH 26
#define FLING_EFFECT_PARALYZE 27
#define FLING_EFFECT_POISON 28
#define FLING_EFFECT_BADLY_POISON 29
#define FLING_EFFECT_BURN 30

#define PLUCK_EFFECT_NONE 0
#define PLUCK_EFFECT_PRZ_RESTORE 1
#define PLUCK_EFFECT_SLP_RESTORE 2
#define PLUCK_EFFECT_PSN_RESTORE 3
#define PLUCK_EFFECT_BRN_RESTORE 4
#define PLUCK_EFFECT_FRZ_RESTORE 5
#define PLUCK_EFFECT_PP_RESTORE 6
#define PLUCK_EFFECT_HP_RESTORE 7
#define PLUCK_EFFECT_CNF_RESTORE 8
#define PLUCK_EFFECT_ALL_RESTORE 9
#define PLUCK_EFFECT_HP_PCT_RESTORE 10
#define PLUCK_EFFECT_HP_RESTORE_SPICY 11
#define PLUCK_EFFECT_HP_RESTORE_DRY 12
#define PLUCK_EFFECT_HP_RESTORE_SWEET 13
#define PLUCK_EFFECT_HP_RESTORE_BITTER 14
#define PLUCK_EFFECT_HP_RESTORE_SOUR 15
#define PLUCK_EFFECT_ATK_UP 16
#define PLUCK_EFFECT_DEF_UP 17
#define PLUCK_EFFECT_SPEED_UP 18
#define PLUCK_EFFECT_SPATK_UP 19
#define PLUCK_EFFECT_SPDEF_UP 20
#define PLUCK_EFFECT_CRIT_UP 21
#define PLUCK_EFFECT_RANDOM_UP2 22
#define PLUCK_EFFECT_TEMP_ACC_UP 23

#define ITEM_NONE 0

// Balls
Expand Down
24 changes: 20 additions & 4 deletions include/constants/narc_files/battle_skill_subseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ enum NARCFilesBattleSubSeq {
BATTLE_SUBSEQ_TRAINER_MESSAGE,
BATTLE_SUBSEQ_NO_PP,

BATTLE_SUBSEQ_BADLY_POISON = 47,

BATTLE_SUBSEQ_MOVE_EFFECT_END = 50,
BATTLE_SUBSEQ_THRASH_END,

Expand Down Expand Up @@ -108,9 +110,22 @@ enum NARCFilesBattleSubSeq {

BATTLE_SUBSEQ_AFTERMATH = 193,

BATTLE_SUBSEQ_HELD_ITEM_RESTORE_HP = 198,

BATTLE_SUBSEQ_RESTORE_A_LITTLE_HP = 213,
BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE = 198,
BATTLE_SUBSEQ_HELD_ITEM_PRZ_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_SLP_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_PSN_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_BRN_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_FRZ_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_PP_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_CNF_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_MULTI_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR,
BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT,
BATTLE_SUBSEQ_HELD_ITEM_RAISE_CRIT,
BATTLE_SUBSEQ_HELD_ITEM_SHARPLY_RAISE_STAT,
BATTLE_SUBSEQ_HELD_ITEM_STATDOWN_RESTORE,
BATTLE_SUBSEQ_HELD_ITEM_HEAL_INFATUATION,
BATTLE_SUBSEQ_RESTORE_A_LITTLE_HP,
BATTLE_SUBSEQ_LOSE_HP_FROM_ITEM,

BATTLE_SUBSEQ_TRANSFER_STICKY_BARB = 216,
Expand Down Expand Up @@ -149,7 +164,8 @@ enum NARCFilesBattleSubSeq {

BATTLE_SUBSEQ_BAD_DREAMS = 263,

BATTLE_SUBSEQ_HELD_ITEM_RECOIL_WHEN_HIT = 266,
BATTLE_SUBSEQ_HELD_ITEM_TEMP_ACC_UP = 265,
BATTLE_SUBSEQ_HELD_ITEM_RECOIL_WHEN_HIT,
BATTLE_SUBSEQ_USE_POTION,
BATTLE_SUBSEQ_USE_STATUS_RECOVERY,
BATTLE_SUBSEQ_USE_STAT_BOOSTER,
Expand Down
104 changes: 96 additions & 8 deletions include/overlay016/ov16_0225177C.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,15 @@ int BattleMon_Get(BattleContext *battleCtx, int battler, enum BattleMonParam par
*/
void BattleMon_Set(BattleContext *battleCtx, int battler, enum BattleMonParam paramID, const void *buf);
void ov16_02252A14(BattleContext * param0, int param1, int param2, int param3);
void ov16_02252A2C(BattleMon * param0, int param1, int param2);

/**
* @brief Add a value to a Pokemon's data field.
*
* @param mon
* @param paramID ID of the field which should be modified
* @param val Value to be added to the Pokemon's data field
*/
void BattleMon_AddVal(BattleMon *mon, enum BattleMonParam paramID, int val);
u8 BattleSystem_CompareBattlerSpeed(BattleSystem * param0, BattleContext * param1, int param2, int param3, int param4);
void BattleSystem_NoExpGain(BattleContext * param0, int param1);
void BattleSystem_FlagExpGain(BattleSystem * param0, BattleContext * param1, int param2);
Expand Down Expand Up @@ -529,22 +537,102 @@ u16 Battler_HeldItem(BattleContext *battleCtx, int battler);
BOOL Battler_MovedThisTurn(BattleContext * param0, int param1);
BOOL BattleSystem_TriggerHeldItemOnHit(BattleSystem * param0, BattleContext * param1, int * param2);
s32 Battler_HeldItemEffect(BattleContext * param0, int param1);
s32 Battler_HeldItemPower(BattleContext * param0, int param1, int param2);

enum HeldItemPowerOp {
ITEM_POWER_CHECK_ALL = 0, //< Check all possible effects which would suppress a battler's held item.
ITEM_POWER_CHECK_NONE, //< Perform no suppression checks; always return the item's power.
ITEM_POWER_CHECK_EMBARGO, //< Check if Embargo is active; if so, return 0 power.
};

/**
* @brief Get the power of the battler's held item.
*
* This routine optionally can perform a series of checks for effects which
* would suppress the held item.
*
* @param battleCtx
* @param battler
* @param opcode Opcode controlling the behavior of this subroutine.
* @return The power of the battler's held item.
*/
s32 Battler_HeldItemPower(BattleContext *battleCtx, int battler, enum HeldItemPowerOp opcode);
s32 ov16_02258B18(BattleContext * param0, int param1);
s32 ov16_02258B2C(BattleContext * param0, int param1);
s32 ov16_02258B40(BattleContext * param0, int param1);
s32 ov16_02258B58(BattleContext * param0, int param1);
s32 ov16_02258B80(BattleContext * param0, int param1);

/**
* @brief Get the Pluck effect of the battler's held item.
*
* @param battleCtx
* @param battler
* @return Pluck effect of the battler's held item.
*/
s32 Battler_ItemPluckEffect(BattleContext *battleCtx, int battler);

/**
* @brief Get the Fling effect of the battler's held item.
*
* @param battleCtx
* @param battler
* @return Fling effect of the battler's held item.
*/
s32 Battler_ItemFlingEffect(BattleContext *battleCtx, int battler);

/**
* @brief Get the Fling power of the battler's held item.
*
* @param battleCtx
* @param battler
* @return Fling power of the battler's held item.
*/
s32 Battler_ItemFlingPower(BattleContext *battleCtx, int battler);
int BattleSystem_CanSwitch(BattleSystem *battleSys, BattleContext *battleCtx, int battler);
BOOL ov16_02258CB4(BattleSystem * param0, BattleContext * param1, int param2);
BOOL ov16_02259204(BattleSystem * param0, BattleContext * param1, int param2);

/**
* @brief Try to Pluck the given battler's berry.
*
* This routine will determine what subsequence should be run as the stolen
* effect (if any) and store it in battleCtx->scriptTemp. It will also update
* the attacker's self-turn status flags to denote that the attacker has
* Plucked a berry.
*
* @param battleSys
* @param battleCtx
* @param battler The battler whose berry is to be Plucked.
* @return TRUE if a follow-up subsequence should be run to apply the berry's
* Pluck effect; FALSE if no such follow-up is needed.
*/
BOOL BattleSystem_PluckBerry(BattleSystem *battleSys, BattleContext *battleCtx, int battler);

/**
* @brief Try to Fling the attacker's item at the given battler.
*
* This routine will determine what subsequence should be run as the flung
* effect (if any) and store it in battleCtx->flingScript. It will also
* determine the base power of Fling, as specified in the item data, and
* store it in battleCtx->movePower.
*
* @param battleSys
* @param battleCtx
* @param battler The target of the flung item.
* @return TRUE if a follow-up subsequence should be run to apply the item's
* Fling effect; FALSE if no such follow-up is needed.
*/
BOOL BattleSystem_FlingItem(BattleSystem * param0, BattleContext * param1, int param2);
void BattleSystem_UpdateMetronomeCount(BattleSystem * param0, BattleContext * param1);
void BattleSystem_VerifyMetronomeCount(BattleSystem * param0, BattleContext * param1);
int ov16_022599D0(BattleContext * param0, int param1, int param2, int param3);
BOOL BattleSystem_CanPickCommand(BattleContext *battleSys, int battler);
void ov16_02259A5C(BattleSystem * param0, BattleContext * param1, Pokemon * param2);
u8 BattleContext_IOBufferVal(BattleContext *battleCtx, int battler);
BOOL Battler_BehindSubstitute(BattleContext * param0, int param1);

/**
* @brief Check if a battler's substitute was hit.
*
* @param battleCtx
* @param battler
* @return TRUE if the battler's substitute was hit, FALSE if not.
*/
BOOL Battler_SubstituteWasHit(BattleContext *battleCtx, int battler);
BOOL BattleSystem_TrainerIsOT(BattleSystem * param0, BattleContext * param1);
BOOL BattleSystem_PokemonIsOT(BattleSystem * param0, Pokemon * param1);
BOOL BattleSystem_UpdateWeatherForms(BattleSystem * param0, BattleContext * param1, int * param2);
Expand Down
6 changes: 3 additions & 3 deletions res/items/pl_item_data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ ITEM_IRON,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,
ITEM_CARBOS,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,true,false,false,true,true,true,0,0,0,10,0,0,0,0,5,3,2
ITEM_CALCIUM,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,true,false,true,true,true,0,0,0,0,10,0,0,0,5,3,2
ITEM_RARE_CANDY,4800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,true,false,true,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2
ITEM_ppUp,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,true,false,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2
ITEM_PP_UP,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,true,false,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2
ITEM_ZINC,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,true,true,true,true,0,0,0,0,0,10,0,0,5,3,2
ITEM_ppMax,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,true,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2
ITEM_PP_MAX,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,true,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2
ITEM_OLD_GATEAU,200,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,8,1,2,1,true,true,true,true,true,true,false,false,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,0,0,0,0
ITEM_guardSpec_,700,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,true,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0
ITEM_GUARD_SPEC,700,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,true,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0
ITEM_DIRE_HIT,650,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,1,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0
ITEM_X_ATTACK,500,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,false,false,false,false,false,1,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0
ITEM_X_DEFENSE,550,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,1,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0
Expand Down
2 changes: 1 addition & 1 deletion src/overlay014/ov14_0221FC20.c
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ static void ov14_02221EBC (BattleSystem * param0, BattleContext * param1)
v1 = ov14_02222CF0(param1);
v0 = ov14_02222D34(param1, v1);

param1->aiContext.calcTemp = ov16_02258B80(param1, v0);
param1->aiContext.calcTemp = Battler_ItemFlingPower(param1, v0);
}

static void ov14_02221EEC (BattleSystem * param0, BattleContext * param1)
Expand Down
4 changes: 2 additions & 2 deletions src/overlay016/battle_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -8518,7 +8518,7 @@ static BOOL ov16_02247B28 (BattleSystem * param0, BattleContext * param1)

if ((param1->battleMons[param1->defender].heldItem) && (Battler_IgnorableAbility(param1, param1->attacker, param1->defender, 60) == 1)) {
BattleScript_Iter(param1, v0);
} else if (((param1->battleMons[param1->defender].heldItem) && (param1->battleMons[param1->defender].moveEffectsData.custapBerry)) || (ov16_02258CB4(param0, param1, param1->defender) != 1)) {
} else if (((param1->battleMons[param1->defender].heldItem) && (param1->battleMons[param1->defender].moveEffectsData.custapBerry)) || (BattleSystem_PluckBerry(param0, param1, param1->defender) != 1)) {
BattleScript_Iter(param1, v1);
}

Expand All @@ -8533,7 +8533,7 @@ static BOOL ov16_02247BA4 (BattleSystem * param0, BattleContext * param1)

v0 = BattleScript_Read(param1);

if (ov16_02259204(param0, param1, param1->attacker) != 1) {
if (BattleSystem_FlingItem(param0, param1, param1->attacker) != 1) {
BattleScript_Iter(param1, v0);
}

Expand Down
Loading

0 comments on commit 4926316

Please sign in to comment.