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

Dynamic Switch AI + Switch Utility Functions #6208

Open
wants to merge 2 commits into
base: upcoming
Choose a base branch
from

Conversation

ghoulslash
Copy link
Collaborator

Introduces gDynamicAiSwitchFunc, which is similar to sDynamicAiFunc but is meant for switching logic rather than move scoring. This function takes precedence over all other switching logic checks.

An example dynamic switch logic function for prioritizing a specific terrain is also provided. (NOTE this was only tested at a base level so may be flawed)

This PR also introduces some utility functions to battle_ai_switch_items.c including:

  • GetActiveBattlerIds which gets the active battler IDs (single vs. double)
  • IsPartyMonOnFieldOrChosenToSwitch checks if the party indices of active battler IDs OR the AI's chosen switch IDs match a given party index. Simplifies a lot of switch logic loops
  • FindMonWithAbility to support the absorbing ability switch logic as well as the terrain function to look for a surge ability

@ghoulslash ghoulslash added the category: battle-ai Pertains to Battle Engine Upgrade's AI label Feb 7, 2025
@Pawkkie Pawkkie self-assigned this Feb 7, 2025
@Pawkkie Pawkkie added the new-feature Adds a feature label Feb 7, 2025
Copy link
Collaborator

@Pawkkie Pawkkie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review and a few questions, the cleanup changes look great! :D

for (j = 0; j < abilityCount; j++) {
if (GetMonAbility(&party[i]) == abilities[j]) {
// mon has ability
if (percentChance && (Random() % 100 > percentChance))
Copy link
Collaborator

@Pawkkie Pawkkie Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I love the idea of embedding a non-testable Random call in a function like this. Is the goal of the randomization to have a failure rate for switching, ie. have percentChance to not return a valid mon even if one exists? If so, I think that should be handled on the switching function side, not in the helper function.

I'm on board for the idea of randomizing between acceptable candidate mons (though again I'd use RandomPercentage with a tag instead so we can write a test for it, which I'd also want included) if you that's something you want to do here, but I'm not on board for having a failure rate in the helper function rather than the switch decision function.


// custom switching logic
// NOTE: needs to always end with `return SetSwitchinAndSwitch` or `return FALSE`
if (gDynamicAiSwitchFunc != NULL && gDynamicAiSwitchFunc(battler))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this below the // NOTE: The sequence of the below functions matter! Do not change unless you have carefully considered the outcome. comments, because that also applies to this function

struct TerrainParams {
u32 flag;
u16 move;
u16 abilities[2];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2 used throughout this sequence feels like a magic number, can we use a define instead?

return FALSE;
}

bool32 ShouldSwitchIntoElectricTerrain(u32 battler)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't actually used by default, right? This set of functions is just an example of a function that could be used? If so, could you include a few lines (either in comment or in the PR description) for how to use this as the dynamic switching function the same as you did for the AI flag one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: battle-ai Pertains to Battle Engine Upgrade's AI new-feature Adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants