Author Topic: [Documentation] Mindless charging AI (Leeroy Jenkins mode)  (Read 5973 times)

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8598
    • View Profile
[Documentation] Mindless charging AI (Leeroy Jenkins mode)
« on: August 02, 2017, 05:19:25 pm »
Based on Stoddard's code with small changes: https://openxcom.org/forum/index.php/topic,5345.msg83664.html#msg83664

Code: [Select]
units:
  - type: STR_CHRYSSALID_TERRORIST
    isLeeroyJenkins: true

Unit marked as leeroy must have a melee weapon (and be able to use it).
It will completely ignore vanilla AI "decision making" and run around (using vanilla patrol routine) until it spots someone and then charge at the nearest target (if multiple spotted).
Charge is mostly vanilla/OXCE, with the following differences:
 - ignore remaining TUs (charge even if not enough TUs to attack now)
 - ignore dangerous tiles (grenades? pfff!)
 - ignore OXCE melee dodge (leeroy is not intelligent enough to attack from behind)

Units which are not marked behave normally... vanilla/OXCE behaviour is untouched.

@Stoddard:
1. cherrypicked commit c6b65f7dfbd2c66a5bdad69d612e7eee9627f19e
2. cherrypicked commit c8f23ec183f07c76b9f9e69112a7ff44868c3f6c
3. fixed compilation error (and vs. &&)
4. reverted all vanilla AI changes from first commit that you (probably?) forgot to revert in the second commit
5. iffed the AI trace logs
6. a few cosmetic changes in code formatting and log output
7. change: charge blindly #1 (don't care even if you end up in grenade blast radius)
8. change: charge blindly #2 (you're not intelligent enough to consider OXCE melee dodge and attack from behind)

Code: [Select]
[02-08-2017_14-56-31] [INFO] LEEROY: Unit 1000014 of type STR_CHRYSSALID_TERRORIST is Leeroy...
[02-08-2017_14-56-31] [INFO] LEEROY: visibleEnemiesToAttack: 0 _melee: 1
[02-08-2017_14-56-31] [INFO] LEEROY: No one to LEEROY!, patrolling...

[02-08-2017_14-56-33] [INFO] LEEROY: Unit 1000014 of type STR_CHRYSSALID_TERRORIST is Leeroy...
[02-08-2017_14-56-33] [INFO] LEEROY: visibleEnemiesToAttack: 2 _melee: 1
[02-08-2017_14-56-33] [INFO] LEEROY: LEEROYIN' at someone!

This code is highly experimental (doesn't mean it's buggy)... test it if you want and give feedback if it's usable in its current form.
« Last Edit: July 17, 2018, 02:57:38 pm by Meridian »

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11408
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Mindless charging AI (Leeroy Jenkins mode)
« Reply #1 on: August 02, 2017, 08:12:50 pm »
That definitely makes me want to buy you a beer or two. :)

Offline yrizoud

  • Commander
  • *****
  • Posts: 1014
    • View Profile
Re: Mindless charging AI (Leeroy Jenkins mode)
« Reply #2 on: August 03, 2017, 03:10:56 am »
Hmm what about a leeroychance instead of a boolean ? (percent chance 0 - 100, or floating point number 0.0 - 1.0) Applied every turn it would let modders use the features also for more subtle situations, like a Black Lotus agent going berserk 5% times, or a Spider normally rushing, but sometimes staying evasive and employing a ranged attack.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8598
    • View Profile
Re: Mindless charging AI (Leeroy Jenkins mode)
« Reply #3 on: August 03, 2017, 08:59:57 am »
Hmm what about a leeroychance instead of a boolean ? (percent chance 0 - 100, or floating point number 0.0 - 1.0) Applied every turn it would let modders use the features also for more subtle situations, like a Black Lotus agent going berserk 5% times, or a Spider normally rushing, but sometimes staying evasive and employing a ranged attack.

That's what vanilla AI does at the moment.

The complaint was that it's not enough and the unit should always charge, not just sometimes.

But yeah, can be done if someone would be interested... 4 lines of code.

Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Mindless charging AI (Leeroy Jenkins mode)
« Reply #4 on: August 05, 2017, 04:12:01 pm »
Nice to see this merged. Thanks, Meridian.

Offline bulletdesigner

  • Commander
  • *****
  • Posts: 676
    • View Profile
Re: Mindless charging AI (Leeroy Jenkins mode)
« Reply #5 on: August 05, 2017, 06:41:37 pm »
Will defnitly use this for beserker units with bloddlust hehe

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8598
    • View Profile
Re: Mindless charging AI (Leeroy Jenkins mode)
« Reply #6 on: September 07, 2017, 06:10:45 pm »
Nice to see this merged. Thanks, Meridian.

Btw. there was a serious flaw in the original code... leeroys were deciding what to do using new AI, but actually acting using old AI.
This led to:
- in usual case, enemies (with low or average TUs) freezing in place (unless you came closer to them)
- in worse cases, a crash

Fix here: https://github.com/MeridianOXC/OpenXcom/commit/d3cfa270ad7a69cc80e6f074f24414262704962b

Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Mindless charging AI (Leeroy Jenkins mode)
« Reply #7 on: September 08, 2017, 08:35:56 pm »
Btw. there was a serious flaw in the original code... leeroys were deciding what to do using new AI, but actually acting using old AI.
This led to:
- in usual case, enemies (with low or average TUs) freezing in place (unless you came closer to them)
- in worse cases, a crash

Fix here: https://github.com/MeridianOXC/OpenXcom/commit/d3cfa270ad7a69cc80e6f074f24414262704962b

Yeah, I saw it back in August. Was a bad idea, no objection.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8598
    • View Profile
Re: [Documentation] Mindless charging AI (Leeroy Jenkins mode)
« Reply #8 on: January 09, 2021, 02:15:53 pm »
Since OXCE v6.9.1 Leeroys can perform charging also over multiple turns.

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11408
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [Documentation] Mindless charging AI (Leeroy Jenkins mode)
« Reply #9 on: January 09, 2021, 06:41:53 pm »
Since OXCE v6.9.1 Leeroys can perform charging also over multiple turns.

This is very good news. Thanks!