-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Battle Item Refactor #2902
Battle Item Refactor #2902
Conversation
…expansion into pr/battle_item_refactor
Ready for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very exciting! Thanks for all the hard work :)
EDIT: Don't worry about the outdated things, I couldn't work out how to delete them before submitting my review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be one of those PRs where it is cleaner if you rebase / squash your commits before we merge them :)
* Treat map data as const * Document the trendy saying word group * Fix scanner item flag name * Use tilemap file for cable car pylons * Replace NUM_TEXT_PRINTERS with WINDOWS_MAX * MOVE_REVIVAL_BLESSING Effect (rh-hideout#2883) * implemented Revival Blessing * Improve PR Template * Fixed AI not considering Hidden Abilities in its team during switching logic * Battle Item Refactor (rh-hideout#2902) * items that can be used in battle now use battlescripts * removed ExecuteTableBasedItemEffect_ * taught AI how to use items, removed AI_itemtype/flag * X-Items store stages raised in holdEffectParam * USE_ITEM in tests --------- Co-authored-by: GriffinR <[email protected]> Co-authored-by: Zunawe <[email protected]> Co-authored-by: AgustinGDLV <[email protected]> Co-authored-by: Eduardo Quezada <[email protected]> Co-authored-by: Martin Griffin <[email protected]>
* Treat map data as const * Document the trendy saying word group * Fix scanner item flag name * Use tilemap file for cable car pylons * Replace NUM_TEXT_PRINTERS with WINDOWS_MAX * MOVE_REVIVAL_BLESSING Effect (rh-hideout#2883) * implemented Revival Blessing * Improve PR Template * Fixed AI not considering Hidden Abilities in its team during switching logic * Battle Item Refactor (rh-hideout#2902) * items that can be used in battle now use battlescripts * removed ExecuteTableBasedItemEffect_ * taught AI how to use items, removed AI_itemtype/flag * X-Items store stages raised in holdEffectParam * USE_ITEM in tests --------- Co-authored-by: GriffinR <[email protected]> Co-authored-by: Zunawe <[email protected]> Co-authored-by: AgustinGDLV <[email protected]> Co-authored-by: Eduardo Quezada <[email protected]> Co-authored-by: Martin Griffin <[email protected]>
* Treat map data as const * Document the trendy saying word group * Fix scanner item flag name * Use tilemap file for cable car pylons * Replace NUM_TEXT_PRINTERS with WINDOWS_MAX * MOVE_REVIVAL_BLESSING Effect (rh-hideout#2883) * implemented Revival Blessing * Improve PR Template * Fixed AI not considering Hidden Abilities in its team during switching logic * Battle Item Refactor (rh-hideout#2902) * items that can be used in battle now use battlescripts * removed ExecuteTableBasedItemEffect_ * taught AI how to use items, removed AI_itemtype/flag * X-Items store stages raised in holdEffectParam * USE_ITEM in tests --------- Co-authored-by: GriffinR <[email protected]> Co-authored-by: Zunawe <[email protected]> Co-authored-by: AgustinGDLV <[email protected]> Co-authored-by: Eduardo Quezada <[email protected]> Co-authored-by: Martin Griffin <[email protected]>
* Treat map data as const * Document the trendy saying word group * Fix scanner item flag name * Use tilemap file for cable car pylons * Replace NUM_TEXT_PRINTERS with WINDOWS_MAX * MOVE_REVIVAL_BLESSING Effect (rh-hideout#2883) * implemented Revival Blessing * Improve PR Template * Fixed AI not considering Hidden Abilities in its team during switching logic * Battle Item Refactor (rh-hideout#2902) * items that can be used in battle now use battlescripts * removed ExecuteTableBasedItemEffect_ * taught AI how to use items, removed AI_itemtype/flag * X-Items store stages raised in holdEffectParam * USE_ITEM in tests --------- Co-authored-by: GriffinR <[email protected]> Co-authored-by: Zunawe <[email protected]> Co-authored-by: AgustinGDLV <[email protected]> Co-authored-by: Eduardo Quezada <[email protected]> Co-authored-by: Martin Griffin <[email protected]>
* Treat map data as const * Document the trendy saying word group * Fix scanner item flag name * Use tilemap file for cable car pylons * Replace NUM_TEXT_PRINTERS with WINDOWS_MAX * MOVE_REVIVAL_BLESSING Effect (rh-hideout#2883) * implemented Revival Blessing * Improve PR Template * Fixed AI not considering Hidden Abilities in its team during switching logic * Battle Item Refactor (rh-hideout#2902) * items that can be used in battle now use battlescripts * removed ExecuteTableBasedItemEffect_ * taught AI how to use items, removed AI_itemtype/flag * X-Items store stages raised in holdEffectParam * USE_ITEM in tests --------- Co-authored-by: GriffinR <[email protected]> Co-authored-by: Zunawe <[email protected]> Co-authored-by: AgustinGDLV <[email protected]> Co-authored-by: Eduardo Quezada <[email protected]> Co-authored-by: Martin Griffin <[email protected]>
Description
This PR refactors all battle item usage into battle scripts completely divorced from their other effects. Usable battle items are now almost identical to moves, with script IDs in
constants/items.h
that correspond to a table inbattle_scripts_2.s
. There's a lot of cool functionality this opens up, as well as making it way easier to understand and add items in general.Included: Max Mushrooms item effect, item test compatibility!
Showcases
Single Battle Showcase
Double Battle Showcase
Trainer Battle Showcase
Out of Battle Showcase
What's left?
Nothing!
What's been explicitly tested?
What does the code do?
General
Items that can be used in battle now call battle scripts. The functionality is split between items that are used directly in the bag (X-Items, Poké Dolls, Poké Balls), items that are used in the party menu (Potions, Revives, etc.), and items that are used in the party menu on a specific move (Leppa Berries and Ethers). These categories are set and checked in the
.type
field of an item. Party menu items store the selected party index ingBattleStruct->itemPartyIndex[gActiveBattler]
, and the chosen move index (for PP items) ingChosenMovePos
.The
gBattlescriptsForUsingItem
table inbattle_scripts_2.s
has been expanded and now looks much like the move equivalent inbattle_scripts_1.s
. The.battleUsage
field now corresponds to anEFFECT
constant, which corresponds to an index in this script table. The constants start at 1 so that possible usage can be checked by just seeing if the field is non-zero.AI
Trainer AI will use the same items in the exact same way as the player! This means they are now able to use Revives, the new Max Mushrooms, and even PP-items with some logic added (and perhaps a change to the current use of
gChosenMovePos
, as this could change between the AI choosing an item and executing it). The AI checks remain identical, but instead of checkingAI_itemType
, they simply check the item script ID just like they do for moves. Realistically, this could be converted to a viability system of sorts. The selected party ID is set to the active battler by default, meaning the AI will always use party menu items on the active battler unless otherwise specified. The only case where this occurs is Revives, where the AI chooses the first fainted party index like Revival Blessing.Tests
Adds a new
USE_ITEM(battler, itemId)
macro. This works exactly how you'd expect! To facilitate this, some behavior needed to be added to the recorded player/opponent battle controllers and new constantRECORDED_ITEM_ID
was added. The technical details probably aren't important.Similar to how moves work, you will need to specify party index and move slot if necessary. These are checked for items that require those inputs and are checked for validity. For example, using Leppa Berry might look like
USE_ITEM(player, ITEM_LEPPA_BERRY, partyIndex: 0, move: MOVE_TACKLE)
.Clean-up
The party menu's helper
ExecuteTableBasedItemEffect_
function is gone, as it is no longer necessary to check battle behavior. Similarly,PokemonUseItemEffects
has had a lot of code wiped that was meant for item usage in battle, as this function will never be called in battle.Everything related to
AI_itemType
andAI_itemField
is gone, including the enums, functions, and all the AI behavior that used this.The
.battleUseFunc
field for items has been removed, as the proper function is called using their.type
field. TheItemUseInBattle_Medicine
and similar functions have been consolidated into three functions for these.type
categories. TheITEM_B_USE_MEDICINE
andITEM_B_USE_OTHER
constants are gone now, too, as these were redundant.