sfall-team / sfall

sfall - Engine modifications for Fallout 2
https://sfall-team.github.io/sfall/
GNU General Public License v3.0
342 stars 40 forks source link

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

Open phobos2077 opened 4 months ago

phobos2077 commented 4 months ago

Conditions for aimed shot:

phobos2077 commented 4 months ago

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 commented 4 months ago

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:

CONs:

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:

CONs:

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:

CONs:

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:

CONs:

phobos2077 commented 4 months ago

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.