OpenXcom Forum

Modding => OpenXcom Extended => OXCE Suggestions DONE => Topic started by: memmaker on March 03, 2020, 01:01:13 pm

Title: [Documentation] Soldier Skill Menu
Post by: memmaker on March 03, 2020, 01:01:13 pm
Soldier Skills Docs

So, there is a new feature in OXCE: Soldier Skill Menus.

It allows for skill menu to be defined via rulesets. An icon will be displayed, for soldier types which have skills assigned, in the battlescape, where the the special weapon icon is, in the top right corner. This of course means, that only one of these icons can be shown at the same time. So no special weapon icon and skill menu item at the same time.

So what is a skill as defined in this feature?

A skill is a battlescape action that can be selected through the skill menu and is usually tied to an item. So a skill menu entry can act as any item action.

But a skill can also be used as a trigger for a script, using the new "skillUseUnit" script hook.

As opposed to item usage, skills can have a zero TU activation cost, but need at least a non-zero mana cost then. So no zero cost skills, it's at least some TU or some Mana for activation.

Since skills are a distinct object in terms of the rulesets, they can also have tags and scripts assigned to them.

Here is a small ruleset example which I will discuss:

Code: [Select]
mana:
  enabled: true
  battleUI: true
  trainingPrimary: false
  trainingSecondary: false
  replenishAfterMission: true

skills:
  - type: STR_RUN_AND_GUN # script activated
    tags:
      SKILL_ID: 1
    costUse:
      time: 0
      mana: 12
    flatUse:
      mana: true
  - type: STR_SLASH
    tags:
      SKILL_ID: 2
    costUse:
      time: 5
      mana: 5
    flatUse:
      mana: true
    targetMode: 10
    compatibleWeapons: [STR_STUN_ROD, STR_ALLOY_SWORD]
  - type: STR_HEAL
    tags:
      SKILL_ID: 3
    costUse:
      time: 5
      mana: 6
    flatUse:
      mana: true
      time: true
    compatibleWeapons: [STR_MEDI_KIT]
    checkHandsOnly: true
  - type: STR_RAPID_FIRE
    tags:
      SKILL_ID: 4
    costUse:
      time: 50
      mana: 5
    flatUse:
      mana: true
      time: false
    targetMode: 7 # auto
    battleType: 1 # firearms
    requiredBonuses: [STR_MY_SOLDIER_BONUS1, STR_MY_SOLDIER_BONUS1]
  - type: STR_REAPER # script activated
    requiredBonus: [STR_RANGER_ELITE_BONUS]
    isPsiRequired: true
    tags:
      SKILL_ID: 5
    costUse:
      time: 0
      mana: 12
    flatUse:
      mana: true

soldiers:
  - type: STR_SOLDIER
    minStats:
      mana: 100
    maxStats:
      mana: 100
    statCaps:
      mana: 100
    skillIconSprite: 1
    skills:
      - STR_RUN_AND_GUN # script activated
      - STR_SLASH
      - STR_HEAL
      - STR_RAPID_FIRE
      - STR_REAPER # script activated

items:
  - type: STR_RIFLE
    tuAuto: 0
    confAuto:
      shots: 4

extended:
  tags:
    RuleSkill:
      SKILL_ID: int
  scripts:
    skillUseUnit:
      - offset: 22
        code: |
          var int skill_id;

          skill.getTag skill_id Tag.SKILL_ID;
         
          battle_game.flashMessage "SkillUse triggered {0} {1}" skill_id have_tu;

          if eq have_tu 0;
            debug_log "No Resources. Aborted.";
            set continue_action 0;
            return;
          end;

          # do stuff here

          return;

So, I start out with enabling mana, since I will use that resource for some of the scripted skill activations.

Then there is a new block "skills:", which will globally define all skills which are available.

We have: name (type), tags, cost of use and the flags for flat vs. percentage. All of these attributes should be well known from item definitions.

One of the most important attributes is called "targetMode". This tells the game which battleaction will be carried out and what kind of targeting behaviour should occur. So let's talk about them for a bit.

There are:
Code: [Select]
# 0   = No target needed (Just activation, script takes over) - BA_NONE
# 10  = Melee Range Targeted (1 Tile) - BA_HIT
# mul = Firearm (Default firarm targeting) - SNAP = 8, AUTO = 7, AIMED = 9
# mul = Psi Targeting (Default PSI Targeting, with or without LOS) - BA_USE = 11, BA_MINDCONTROL = 13, BA_PANIC = 14
# 6   = Thrown Targeting (Default Thrown targeting, uses throwing arc) - BA_THROW
# 12  = Waypoint Targeting (Default blaster launcher targeting) - BA_LAUNCH

0 is the one you want to use for completely scripted skills.
All the other modes will tell the game to switch to a specific targeting behaviour you will know from the weapons already in the game.

Every targetMode, except mode 0, expects an item to present in order to work. After all, a melee action needs at least a stick and if you want to fire a gun.. you better have one.

There are currently two ways to tell the game which item to use: "compatibleWeapons" and "battleType".

"compatibleWeapons" takes a list of item names and will look for them in the hands of the respective soldier and will use the first weapon it finds.
There is a switch called "checkHandsOnly", defaulting to true, which you can switch off, in order to enable the skill to search through the whole inventory of the soldier for a compatible weapon. When "checkHandsOnly" is disabled, also special weapons of the soldier will be checked, this can be used to great effect.

You can also define a compatible "battleType":

Code: [Select]
0 - None (Geoscape-only item)
1 - Firearm
2 - Ammo
3 - Melee
4 - Grenade
5 - Proximity Grenade
6 - Medi-Kit
7 - Motion Scanner
8 - Mind Probe
9 - Psi-Amp
10 - Electro-flare
11 - Corpse

And the skill would look through the soldiers inventory (this time ignoring checkHandsOnly) for an item which matches the battletype and will use the first one it finds. This is currently the only check carried out, so it won't check if the specified targetMode is available, for example.

Now we have some skill defined, what can we do with them?

You can see, that the "soldiers:" section in the ruleset allows for two new attributes: "skillIconSprite" and "skills".

"skillIconSprite" works just like "specialIconSprite" with the same syntax and semantic just applying to the soldier type's skill menu.

"skills" is a list of names of skills this soldier type should have available. There is currently a limit of 5 skills so don't expect more entries than this to show up.

I have also included a rifle item to show what skills can do: You may notice that I disabled auto-shot on the rifle by assigning a TU cost of zero. That means it won't be selectable by the player when he clicks on his gun. But a skill can still use that action: The "STR_RAPID_FIRE" skill defined above has its "targetMode" set to auto and will use any item with a "battleType" of firearm. So if a player has the rifle equipped and activates that skill, the auto shot of the rifle will be triggered. The action costs will be as defined by the skill.

This is already pretty powerful, but with some additional scripting, even more can be done.

There is a new script called "skillUseUnit" which receives the unit currently acting ("actor"), the selected "battle_action" the item being used (if any) and the skill itself which triggered the script.

The script implementation itself can now decide wether to spend the TU for the action and carry on or not to spend any TU and cancel the action.

This enables scripts to act as a battle action in their own rights and is a useful addition to a modder's toolkit.

Additionally, the "hitUnit" and "damageUnit" script now also receive a reference to the script which initiated the action, if applicable. Thus enabling skill based "on hit" and "on damage" effects.

Hope I covered everything, questions please  8)
Title: Re: [Documentation] Soldier Skill Menu
Post by: memmaker on March 03, 2020, 01:16:55 pm
One more thing: Grenades.

The skill menu currently only supports instant grenades, no priming, no unpriming. Every grenade associated with a throw action will have it's fuse enabled and set to zero upon throwing.

Another thing: Convenience.

The skill menu uses the same hotkey as the special weapon menu to pop up. So it can be toggled via keyboard shortcut. Also every skill item is assigned a hotkey (keyBattleActionItem1-5).

And still one more thing: Bonus requirements.

You can see that I used the attribute "requiredBonuses" to specify a requirement. If the soldier in question does not have these soldier bonuses applied, he will not see the corresponding entry in the skill menu.
Title: Re: [Documentation] Soldier Skill Menu
Post by: ohartenstein23 on March 03, 2020, 03:32:16 pm
This looks like a super-useful feature, I can already think of a handful of ways to update the 40k mod with skills over just special weapons.

When the skill list in battlescape is populated with items, does it only show skills for which you meet the item requirements? For example, if I gave a soldier type more than 5 skills, but tied each to a specific set of mutually-exclusive special weapons on armor, would the skill menu have different actions based on the armor? Or another example: if my soldier doesn't have the bonuses required for a specific skill, say STR_REAPER in your example ruleset, will that skill show up in the menu?
Title: Re: [Documentation] Soldier Skill Menu
Post by: memmaker on March 03, 2020, 04:54:28 pm
When the skill list in battlescape is populated with items, does it only show skills for which you meet the item requirements?

No. The entries would still show up, but when using them and you do not have the required item it will flash a message: "This skill requires an item."

Quote
For example, if I gave a soldier type more than 5 skills, but tied each to a specific set of mutually-exclusive special weapons on armor, would the skill menu have different actions based on the armor?

No, it is tied to the soldier not the armor. However, you could use scripts to at least have different effects triggered based on the armor the soldier is wearing.

Quote
Or another example: if my soldier doesn't have the bonuses required for a specific skill, say STR_REAPER in your example ruleset, will that skill show up in the menu?

No. This is the only parameter that really controls the display. You can for example define 5 skills and have each depend on a different bonus. And only those with the acquired bonuses would show.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on March 16, 2020, 07:40:01 am
Correct me if something wrong:
If i want my soldier to throw fireballs from empty hands, i can use specialweapon and forget about skills.
If i want my soldier to throw fireballs from empty hands and replenish HP's or TU's with mana, i can use skills and special weapons.
If i want my soldier to throw fireballs or lightning bolts from empty hands, i can forget about it.
Thanks.
Title: Re: [Documentation] Soldier Skill Menu
Post by: memmaker on March 16, 2020, 03:04:59 pm
If i want my soldier to throw fireballs from empty hands, i can use specialweapon and forget about skills.

Technically the special weapon is still an item. But you can make an item which throws fireballs and assign them as special weapon, yes.

If i want my soldier to throw fireballs from empty hands and replenish HP's or TU's with mana, i can use skills and special weapons.

You can already replenish TU and HP with mana without using skills. Not sure what the intended use case is here?

If i want my soldier to throw fireballs or lightning bolts from empty hands, i can forget about it.

Sorry, could you rephrase that? I seem to not understand.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on March 16, 2020, 05:23:34 pm
Second case - using item and scripted skill. It is possible as i understand.
Third case - as i think, it is impossible to create two skills, using different special weapons. So that soldier can use two weapons without having them in his inventory. Or is this somehow possible?
Title: Re: [Documentation] Soldier Skill Menu
Post by: memmaker on March 16, 2020, 05:46:16 pm
@Nord:

No, this does not add another special weapon.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on March 17, 2020, 07:08:37 am
Looks like specialWeapon defined in soldier rule, blocks skill button. How to use them simultaneously?
Title: Re: [Documentation] Soldier Skill Menu
Post by: memmaker on March 17, 2020, 08:39:20 am
They are not designed to be used to together. The icons that is.
It is only one icon that gets placed there.
Either a special Weapon or the skills. Since the skill menu can do most of the things a specialweapon could, the latter would be the more flexible solution.

You can however have a skill menu and a special weapon without the icon. Using the skill menu to pass through specific actions to the special weapon.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on March 17, 2020, 10:04:32 am
You can however have a skill menu and a special weapon without the icon. Using the skill menu to pass through specific actions to the special weapon.
Oh, did'nt know that special weapon without icon is possible. It works fine. Thanks.

One more thing: how to use panic attack through skills?
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on April 02, 2020, 12:48:22 pm
Quote
# 0   = No target needed (Just activation, script takes over) - BA_NONE
# 10  = Melee Range Targeted (1 Tile) - BA_HIT
# mul = Firearm (Default firarm targeting) - SNAP = 8, AUTO = 7, AIMED = 9
# mul = Psi Targeting (Default PSI Targeting, with or without LOS) - BA_USE = 11, BA_MINDCONTROL = 13, BA_PANIC = 14
# 6   = Thrown Targeting (Default Thrown targeting, uses throwing arc) - BA_THROW
# 12  = Waypoint Targeting (Default blaster launcher targeting) - BA_LAUNCH

What about healing? To use most of doping abilities we need not hitUnit, but healUnit. How to access that?
I have tried to give
Code: [Select]
    targetMode: 10 # closeBut then no healUnit goes.
Title: Re: [Documentation] Soldier Skill Menu
Post by: memmaker on April 02, 2020, 12:52:42 pm
Hi Nord,

The list there has all the targeting modes (which are derived from the internal battle actions). Medi-Kits have no special handling regarding the targeting. They use BA_USE as a battle action as do most special inventory items, iirc. So a skill with a medi-kit and targetMode: 11 should be what you are looking for.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on April 02, 2020, 01:09:23 pm
Thanks. It works...
But "healUnit" have no "skill" parameter of RuleSkill type. :(
Title: Re: [Documentation] Soldier Skill Menu
Post by: memmaker on April 02, 2020, 01:13:24 pm
It has not been added to that call, yet. True.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on April 17, 2020, 05:37:55 pm
It has not been added to that call, yet. True.
Any plans of adding skill support into "healUnit" and "tryPsiAttackUnit"?

Also it will be useful IMHO to add restriction for psi-item skill, for using only on ally/only on enemy.
Thanks.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Yankes on April 17, 2020, 05:48:24 pm
For psi is already pans, I have not finished it yet.
Title: Re: [Documentation] Soldier Skill Menu
Post by: TBeholder on December 14, 2022, 01:30:01 pm
I seem to almost get it. So for example —
Code: [Select]
items:
  - type: STR_HIGH_EXPLOSIVE
    twoHanded: true
  - type: STR_SNIPER_RIFLE
# [. . .] from "Sniper Rifle" or "New Heavy Weapons".

soldiers:
  - type: STR_SOLDIER
    skills:
      - STR_SNIPE
      - STR_PLANT_CHARGE


soldierTransformation:
  - name: STR_SNIPER_TRAINING
    keepSoldierArmor: true
    allowsDeadSoldiers: false
    allowsLiveSoldiers: true
    allowedSoldierTypes:
      - STR_SOLDIER
    forbiddenPreviousTransformations:
      - STR_SNIPER_TRAINING
    cost: 2000
    transferTime: 120
    includeBonusesForMinStats: true
    requiredMinStats:
      firing: 60
    soldierBonusType: STR_TRAINED_SNIPER
    lowerBoundAtMinStats: true
    upperBoundAtMaxStats: false
    upperBoundAtStatCaps: true
    flatOverallStatChange:  # ??? are adjustments this needed in both places, if only for indication? or will this add stats both here and from the bonus?
      reactions: 5
      firing: 10

  - name: STR_DEMOLITIONS_TRAINING
    keepSoldierArmor: true
    allowsDeadSoldiers: false
    allowsLiveSoldiers: true
    allowedSoldierTypes:
      - STR_SOLDIER
    forbiddenPreviousTransformations:
      - STR_DEMOLITIONS_TRAINING
    cost: 2000
    transferTime: 120
    includeBonusesForMinStats: true
    requiredMinStats:
      bravery: 40
      tu: 40
    soldierBonusType: STR_TRAINED_DEMOMAN
    lowerBoundAtMinStats: true
    upperBoundAtMaxStats: false
    upperBoundAtStatCaps: true
    flatOverallStatChange:
      bravery: 5
      tu: 6


soldierBonuses:
  - name: STR_TRAINED_SNIPER
    stats:
      reactions: 5
      firing: 10
    recovery:
      morale:
        flatOne: 1

  - name: STR_TRAINED_DEMOMAN
    stats:
      bravery: 5
      tu: 6


skills:
  - type: STR_SNIPE
    tags:
      SKILL_ID: 1
    costUse:
      time: 5
    flatUse:
      time: true
    targetMode: 9
    requiredBonuses: STR_TRAINED_SNIPER
    compatibleWeapons: [STR_RIFLE STR_LASER_RIFLE STR_PLASMA_RIFLE STR_SNIPER_RIFLE]
    checkHandsOnly: true

  - STR_PLANT_CHARGE
    tags:
      SKILL_ID: 2
    costUse:
      time: 10
    targetMode: 11
    requiredBonuses: STR_TRAINED_DEMOMAN
    compatibleWeapons: STR_HIGH_EXPLOSIVE
    checkHandsOnly: true


extended:
  tags:
    RuleSkill:
      SKILL_ID: int
  scripts:
    skillUseUnit:
      - offset: 22  # ??? how to determine this?
        code: |
          var int skill_id;

          skill.getTag skill_id Tag.SKILL_ID;
         
          battle_game.flashMessage "SkillUse triggered {0} {1}" skill_id have_tu;

          if eq have_tu 0;
            debug_log "No Time. Aborted.";
            set continue_action 0;
            return;
          end;

          # do stuff here

          if eq skill_id 1;

            #???

            return;
          end;
         
          if eq skill_id 2;

            #???

            return;
          end;

          return;
Is this right this far?
Now… I want to add for (1) tweaked item properties, such as increased kneelBonus, accuracy and confAimed: range: …

 and for (2) damageAlter: ToTile: 0.92
I want to do it just for this one action, without altering anything permanently? So, no messing with RuleItem?

If that can be done, are LOSRequired and blockBothHands for this action checked before script hook of Skill, or they can be introduced in the script (and likewise either used locally or reset later) too?
If so, when a two-handed item is required, is there a way to make sure the other hand is empty for this action (rather than just give it blockBothHands always)? Or drop the other item (if any)?
Or check for 2 items in hands (including empty hand) somehow? The latter would also allow pistols akimbo.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Yankes on December 15, 2022, 01:25:23 pm
What exactly you want to archive?
Did you read https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Soldier_Skillls ?
It should have answer for most of your questions.
Title: Re: [Documentation] Soldier Skill Menu
Post by: TBeholder on December 15, 2022, 08:50:35 pm
What exactly you want to archive?
Specifically, change properties of the required items for this action
Did you read https://www.ufopaedia.org/index.php/Ruleset_Reference_Nightly_(OpenXcom)#Soldier_Skillls ?
It should have answer for most of your questions.
I don’t see how. It’s just a list of properties for Skills. There’s nothing at all on how to make skills actually do something.

I don’t see anything on scripting in the context of skills in general anywhere else, never mind related to the targetMode actions or the compatibleWeapons items in particular (are those even passed to the scripts, or just checked when validating activation and forgotten?).
The only available example is the first post of this thread, which… shows that in practice those properties would need to be supplemented by «tags:» rather than relying on the name under «type:»? It also introduces the relevant script hook skillUseUnit, shows how to wrap it all in a sanity check / pseudo-case… but even then, for the actually working part there’s just placeholder «# do stuff here ».
Title: Re: [Documentation] Soldier Skill Menu
Post by: Yankes on December 15, 2022, 09:55:04 pm
main function of script hook`skillUseUnit` is to determine if given action will execute, you can block action based on some custom condition (variable `continue_action` set to 1).
Another function is determine if use cost of action should be applied on unit (variable `spend_tu` set to 1).
And finally script is allowed to change whole game state, this is done before processing of action is done but you can kill every unit in game if you want, or change states of any unit.

You can in some cases ignore this hook as most logic is done by engine itself. `targetMode` and `compatibleWeapons` are used to prepare action before any script is called. Based on this this engine determine what normal unit action should be performed and what unit weapon should be choose.
What action will be performed and on what weapon you get this in script in variables `battle_action` and `item`.

Btw to see what exactly is available in scripts you should look in verbose logs where game dup all scripts with all its meta data.
Old copy of list of all hooks can be find in https://www.ufopaedia.org/index.php/Script_(OpenXcom)#
Title: Re: [Documentation] Soldier Skill Menu
Post by: TBeholder on December 24, 2022, 05:26:52 am
main function of script hook`skillUseUnit` is to determine if given action will execute

to see what exactly is available in scripts you should look in verbose logs where game dup all scripts with all its meta data.
Old copy of list of all hooks can be find in https://www.ufopaedia.org/index.php/Script_(OpenXcom)
Thanks. The links to examples from that page helped, too.
So, this script runs before the action itself, mostly as free-form validation, any follow-ups would need to use other hooks somehow. It could adjust stats for the soldier or item involved, but then resetting them will be very tricky… unless doing this on new turn is acceptable (if it is, a special tag could be set, to be checked in newTurnUnit / newTurnItem).
While checking hands is trivial — the item is given as a pointer that can be compared to output of actor.getLeftHandWeapon and actor.getRightHandWeapon, much like in Vampiric item script (https://openxcom.org/forum/index.php/topic,5245.msg78346.html#msg78346).
Are my conclusions correct?
Title: Re: [Documentation] Soldier Skill Menu
Post by: Yankes on December 24, 2022, 11:19:38 am
Yes, you can check on what hand item is held.

Another things is that damage scripts hooks have pointer to used skill, this mean hen you hit any thing you can check if that hit was done using skill.
Same with accuracy and base damage calculation, it too have access to used skill.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on December 30, 2022, 04:24:06 pm
I think it was allready discussed, but again:
When soldier have psionic skills (similar to vanilla panic or psi control ), then near the special skill button in top right corner of the screeen we can see an old psionic button, which can not be pressed or do something. How to remove this? Thanks.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Yankes on December 30, 2022, 04:45:46 pm
I recall that I already fixed this, if PSI is not useful then it should show only one button.
Could you make small mod that have this behavior or show it in bigger one what solder is affected?
Title: Re: [Documentation] Soldier Skill Menu
Post by: Nord on January 01, 2023, 03:09:05 am
It is from my X-Chronicles. Use any mentat soldier.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Meridian on April 23, 2023, 12:26:30 pm
I recall that I already fixed this, if PSI is not useful then it should show only one button.

That's probably between a psi weapon and special weapon.

But the issue here is between a psi weapon and a soldier skill.

I can think of a few solutions, but I don't like any of them.
@Yankes: maybe you can think of something...

Could you make small mod that have this behavior or show it in bigger one what solder is affected?
It is from my X-Chronicles. Use any mentat soldier.

Attached a save from XCHR.

See soldiers Saba Zare and Isaura Fraga.
Title: Re: [Documentation] Soldier Skill Menu
Post by: Kronos913 on August 07, 2023, 08:58:54 pm
Quote
This of course means, that only one of these icons can be shown at the same time. So no special weapon icon and skill menu item at the same time.
When I tested this - I had two icons displayed side by side