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

[AI] A way to make AI using called shots when appropriate #540

Open
phobos2077 opened this issue May 25, 2024 · 3 comments
Open

[AI] A way to make AI using called shots when appropriate #540

phobos2077 opened this issue May 25, 2024 · 3 comments

Comments

@phobos2077
Copy link
Collaborator

Conditions for aimed shot:

  • Enough AP
  • Weapon that has aimed mode
  • Roll against called_freq (most typical enemies have 10 or 20, that's 10% and 5% chance respectively)
  • Difficulty-based INT check (must be >= 5 for NORMAL and 3 for HARD)
  • Hit chance is calculated and it must be >= min_to_hit in the AI packet
@phobos2077
Copy link
Collaborator Author

min_to_hit in ai.txt is used for several different things, not good:

  1. Minimum skill level when checking if AI can use a weapon or not.
  2. When checking if called shot is worth taking instead of uncalled. This is after AI has already decided that it will attack.
  3. When AI checking if a shot should be made from current position (using uncalled hit chance) or from a position along the path to the target if closing in.
  4. When AI checks if it worth to close up on target. It calculates a hit chance without range modifier (as if he's point blank) and compares with this value. This happens either when shot is obstructed for any reason or uncalled hit chance is too low (3).

@phobos2077
Copy link
Collaborator Author

phobos2077 commented May 25, 2024

Possible approaches to this:

(Existing) hook scripts

try to use set_object_data on combat_data to force a different body part in the ctd structure. This could be done from some hook script. But the only one I could find that happens before actual attack calculations (when we need to calculate hit chance), is TOHIT.. the problem is, it is called from many places, not just compute_attack (ok, we can hack a new "reason" parameter, like some other hooks did). Another problem is you need to add a new opcode to calculate hit chance with given parameters, taking potential TOHIT hooks into account. Otherwise you would have to reimplement the whole calculation in SSL just for this to work, which seem too complicated.

PROs:

  • Scriptable
  • No need for new hooks

CONs:

  • Still need to tweak existing hooks
  • Needs new opcodes
  • Messy and complicated
  • Doesn't address the fact that AI used uncalled hit chances when deciding when to stop at current tile and start attacking... so AI will shoot too early and more likely miss

Minimalistic hacks

Metarule to change intelligence requirements for all 3 difficulty levels. Combined with some hack for ignoring "torso" and "uncalled" from the random body part selection... Not perfect, because you'd want AI to use some kind of intelligence to choose the body part. Maybe it sees you are a melee threat and will shoot your legs, or shoot your hands if you're holding a high-dmg weapon, etc.

PROs:

  • Easy to implement
  • No need to design a "worthy hook"

CONs:

  • Inflexible
  • Fixes the problem only partially
  • Still doesn't address the AI approaching issue

C++ rewrite

Just replace the function with a custom one with all the considerations for "smart" behavior. Basically another built-in mod similar to how "ammo mods" started back in the day.

PROs:

  • Same pro's as with hacks - easy.
  • Can solve the issue fully, if combined with some extra logic for deciding to use called shot before approaching enemy for correct min_to_hit checks

CONs:

  • Unscriptable - another opinionated built-in mod. Not good for the purpose of the project.

New hook scripts

Add multiple hook scripts to control key aspects of AI behavior. Complement with a bunch of metarules for certain non-opinionated/lower-level functions to keep SSL implementation of necessary logic possible and manageable.

PROs:

  • Will be able to solve this issue (and some others) with no compromises.
  • Fully scriptable.

CONs:

  • A lot of work
  • Need to design new hooks carefully

@phobos2077
Copy link
Collaborator Author

Figured out how to do this using a combination of HOOK_COMBATTURN and HOOK_TOHIT with no extra hacks. Seems to work so far, so maybe no changes will be needed after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant