aliens

Author Topic: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge  (Read 1043 times)

Online Delian

  • Commander
  • *****
  • Posts: 501
    • View Profile
[Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« on: September 09, 2024, 10:27:25 pm »
If you shoot a friendly unit at point blank range, the friendly unit will not trigger CQC mechanics, so your weapon will never get deflected. That's normal and okay.
But, if you melee attacking a friendly unit, it does trigger evasion, causing your otherwise 100% accuracy melee attack to miss it.
I believe this is a bug, because:
1. It's inconsistent with the gun deflection CQC mechanics
2. It doesn't make logical sense - the player intends to hit a friendly unit, so the friendly unit should cooperative with this intention, the same way they cooperate with any other command, and not dodge
3. Mind-controlled enemies will evade melee attacks, despite being under your complete control

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9098
    • View Profile
Re: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« Reply #1 on: September 09, 2024, 11:17:31 pm »
Maybe I'm missing something, but why would you attack a friendly unit?

I don't know if this is a bug or not, I'd have to investigate (and/or ask the feature authors what they intended).
Likely outcome is that it was never explicitly specified.

If it turns out to be an "issue", I'd prefer fixing it the other way around... i.e. check CQC for friendlies too.
If the commanding officer orders a soldier to kill a fellow soldier, the target soldier has all reasons to defend himself (and the other soldier should in theory be able to ignore such order).
Maybe for stun attacks?
But even then I think soldiers have the right to defend themselves from being zapped with 10k volts, regardless if attacked by enemy or friendly.

Lastly, mind-controlled enemy is not really a friendly unit. There's already many situations, where they are treated differently and this seems like a natural case for different treatment too.
This should probably be fixed.
...unless modders disagree, since this could potentially be abused and break mod balance... and I'd have to make yet another configuration on per unit basis for units with innate dodge or VIP targets or something...
« Last Edit: September 09, 2024, 11:25:34 pm by Meridian »

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11728
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« Reply #2 on: September 09, 2024, 11:58:35 pm »
I also don't understand the issue. It looks like a solution looking for a problem. But I'm naive.

Online Delian

  • Commander
  • *****
  • Posts: 501
    • View Profile
Re: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« Reply #3 on: September 10, 2024, 02:04:25 am »
why would you attack a friendly unit?

Haha, I assure you, I'm not a sadist! In XPZ there are some weapons with beneficial effects. Of course, it doesn't make sense to deflect or evade a beneficial attack. If you added deflecting CQC mechanics, you'd be breaking some of these weapons.

and the other soldier should in theory be able to ignore such order

Haha, that would be pretty funny. Unfortunately, soldiers in this game are empty husks and the player has absolute control over them ;D If you order a soldier to throw a grenade under their feet and sit on it, they'll do it. Hmm, maybe you could create a mod where soldiers have an Obedience value, and based on this value they would sometimes refuse commands, or move in random directions. Soldiers fighting each other! Mutiny! Anyway...

As far as mod balance goes, in XPZ there's only 1 beneficial-attack melee weapon (Officer's Lash), and it's already balanced - the weapon will never produce more resources than it uses, and it already has high accuracy, so if the meleeDodge vs friendlies was removed, it wouldn't affect this weapon's balance. Hmm. I've analyzed ALL enemy units in XPZ, and the conclusion is that all the units with high meleeDodge also have high psiDefence. This means that there's 0 cases where mind-controlling a unit would counter an otherwise high meleeDodge. There's also no friendly VIPs who would would a high meleeDodge to evade any stun tactics. Well, even if such cases did exist, you could just stun them with ranged weapons instead.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« Reply #4 on: September 10, 2024, 12:35:58 pm »
I think it could be possible to make workaround using scripts, if I recall corrrectly bonus dodge calculation have access to attacker and if `attacker.faction == target.faction` it could reduce dodge to negative values.

Online Delian

  • Commander
  • *****
  • Posts: 501
    • View Profile
Re: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« Reply #5 on: September 10, 2024, 08:53:15 pm »
In meleeDodgeBonusStats attacker isn't a variable. BattleUnit.faction / BattleUnit.getFaction also don't work. hitUnit hook is too late

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« Reply #6 on: September 10, 2024, 09:14:33 pm »
Right, as I see dodge look only for target, but after checking code to confirm I remember that I made `tryMeleeAttackItem` control whole attack logic. And there you can do this and have access to all needed data.

Online Delian

  • Commander
  • *****
  • Posts: 501
    • View Profile
Re: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« Reply #7 on: September 10, 2024, 11:47:54 pm »
Code: [Select]
# Friendly units won't try to dodge melee attacks from friendly units
extended:
  scripts:
    tryMeleeAttackItem:
      - new: YSCRIPT_NOFRIENDLYDODGE
        offset: 49.99
        code: |
          var int attackerFaction;
          var int victimFaction;
          attacker.getFaction attackerFaction;
          victim.getFaction victimFaction;
          if eq attackerFaction victimFaction;
            add melee_attack_success defense_strength;
            sub melee_attack_success defense_strength_penalty;
          end;
          return melee_attack_success;

Temporary solution I guess. What's the difference between tryMeleeAttackItem and tryMeleeAttackUnit?

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Bug] Melee attacking friendly unit doesn't ignore meleeDodge
« Reply #8 on: September 11, 2024, 01:13:22 am »
As name suggest one is linked to item and another to unit (to be accurate armor).
If you use global script hook in many cases its do not matter.
Only in some cases when one of script have some default impletion it would matter if you run your code before or after it.