Author Topic: Limiting the weapon a soldier can carry  (Read 4789 times)

Offline pjlasl

  • Captain
  • ***
  • Posts: 54
    • View Profile
Limiting the weapon a soldier can carry
« on: January 17, 2022, 12:35:42 am »
Is there a way to only allow a unit/soldier to only carry a particular type of weapon?

For example, Say I wanted a new soldier type I'm creating to only be able to carry a pistol. If I tried to assign a rifle at the beginning of a battlescape or try to pick up a plasma weapon, I couldn't.

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8596
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #1 on: January 17, 2022, 09:22:27 am »
No, such feature doesn't exist and is also not planned.

Offline Ethereal

  • Commander
  • *****
  • Posts: 619
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #2 on: January 17, 2022, 11:41:50 am »
No, such feature doesn't exist and is also not planned.

And it's a pity.

Offline pjlasl

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #3 on: January 17, 2022, 03:50:49 pm »

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #4 on: January 18, 2022, 05:46:56 am »
personally speaking, that was one of the features i liked the least about xcom 2012

Offline Ethereal

  • Commander
  • *****
  • Posts: 619
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #5 on: January 18, 2022, 08:27:49 am »
personally speaking, that was one of the features i liked the least about xcom 2012

I can understand you. It's just that my modification physically needs something like that. Either a ban on certain weapons for different classes of infantry, or a system of bonuses / penalties in weapons for the type of soldier. But, unfortunately, neither one nor the other is likely to happen.

Online Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #6 on: January 19, 2022, 11:10:28 pm »
Using scripts in OXCE you can make that weapon have different accuracy/power/reaction based on used armor

Offline Ethereal

  • Commander
  • *****
  • Posts: 619
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #7 on: January 20, 2022, 10:16:10 am »
Using scripts in OXCE you can make that weapon have different accuracy/power/reaction based on used armor

You constantly advise using scripts, but how many of them appeared? Seriously, usually after the word "script" the discussion of a new option stops forever. Maybe this is also a script?

Offline The Martian

  • Commander
  • *****
  • Posts: 754
  • "It implores you to listen to its arguments..."
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #8 on: January 21, 2022, 12:04:19 pm »
Is there a way to only allow a unit/soldier to only carry a particular type of weapon?

For example, Say I wanted a new soldier type I'm creating to only be able to carry a pistol. If I tried to assign a rifle at the beginning of a battlescape or try to pick up a plasma weapon, I couldn't.

Nord was able to prevent an item from operating via scripting.

But it could still be used (Without effect) which spent TU and it also could be equipped to the slots in inventory.

See the end of this thread:
Restricting weapon use by Stats/Armor/Unit Type?


Alternatively maybe you could use fixedWeapon: to graft the pistol/rifle/etc to that soldier type so it couldn't drop it?


I've been using several scripts in my project and it really does open up new options... however creating them can be difficult compared to YAML in a .rul file.

If you want to give it a try here is some useful information: Scripting Basics

No, such feature doesn't exist and is also not planned.

If you did implement a feature in OXCE to be able to prevent certain weapons firing with specific armors it would be very welcome.

Perhaps something like this:

Code: [Select]
armors:
  - type: STR_ARMOR_THAT_CANNOT_USE_SOME_ITEMS_UC
    forbiddenWeapons:
      - STR_RIFLE
      - STR_PISTOL

This armor with forbiddenWeapons: could not use any items on the above list.

Code: [Select]
armors:
  - type: STR_ARMOR_THAT_CAN_USE_SPECIAL_ITEM_UC
    allowedWeapons:
      - STR_ARMOR_CONNECTED_FLAMETHROWER

This armor with allowedWeapons: acts as if all items have been added to the forbiddenWeapons: list, except for those in the allowedWeapons: list.

Or would it be easier to keep track of lists of forbiddenArmors: allowedArmors: on the item itself?

There are usually less armors than items so maybe that would be better if this was attempted?

Code: [Select]
items:
  - type: STR_SPECIAL_GUN_THAT_CAN_ONLY_BE_USED_BY_SPECIAL_ARMOR
    allowedArmors:
      - STR_SPECIAL_ARMOR_UC
      - STR_OTHER_SPECIAL_ARMOR_UC

Although you are not planning to make it, what would you want if it was present Meridian?
(I'm just curious about how you would phrase the code.)


personally speaking, that was one of the features i liked the least about xcom 2012

I think the problem with xcom 2012 was that there wasn't much you could actually equip each soldier with, so it became more of a 'this soldier is this class and thus has this gun'.

Many OpenXcom mods have a large enough item selection that this should not be a problem.

Of course it would depend on how the person writing the mod implemented the restrictions.

Something like Memmaker's 'Vigilo Confido' would probably deliberately mirror xcom 2012 using this ability.
« Last Edit: January 22, 2022, 12:29:07 am by The Martian »

Online Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #9 on: January 21, 2022, 07:13:36 pm »
You constantly advise using scripts, but how many of them appeared? Seriously, usually after the word "script" the discussion of a new option stops forever. Maybe this is also a script?
This indeed one feature of scripts :D
And this is as not serious and serious answer, goal of y-script is allow for modders add custom logic that is not supported normally by engine and it move "burden" from developers to modders too. This is preferred in long run as there is only one developer (Meridian, I only spend only couple hours weekly on OXCE) and there is dozen of modders and each want some new features.

Another aspect of this is that y-scripts requite some learning to easy written them, when I throw "scripts" in discursion then person asking do not want spend try write then and simply drop whole idea.

If someone as "how exactly do this" then I or Meridian will show examples how archive logic like this using scripts.

Offline The Reaver of Darkness

  • Commander
  • *****
  • Posts: 1510
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #10 on: January 23, 2022, 02:55:23 am »
Is there a way to only allow a unit/soldier to only carry a particular type of weapon?

For example, Say I wanted a new soldier type I'm creating to only be able to carry a pistol. If I tried to assign a rifle at the beginning of a battlescape or try to pick up a plasma weapon, I couldn't.
You could try changing the size of the hand slots. If the hand slots were 1x2, they could carry a pistol, knife, grenade, medikit, or other small items but nothing bigger such as a mind probe, high explosive, psi amp, or rifle.
To be clear, I have not done this before and am only speculating.

Offline Ethereal

  • Commander
  • *****
  • Posts: 619
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #11 on: January 23, 2022, 05:21:46 am »
If someone as "how exactly do this" then I or Meridian will show examples how archive logic like this using scripts.

Thank you. I'll try to describe.

What was proposed to make the availability of weapons depending on the armor is counterproductive. This only makes sense when there are no interchangeable armor types. What is needed is a dependence on the type of soldier.

I see the construction of bonuses/penalties for the type of soldiers like this:

Code: [Select]
items:
  - type: STR_RIFLE
    accuracyAuto: 50
    accuracySnap: 70
    accuracyAimed: 110
    tuAuto: 30
    tuSnap: 20
    tuAimed: 35
    autoRange: 10
    snapRange: 15
    aimRange: 30
    dropoff: 4
    soldiersType:
      - STR_SOLDIER_SNIPER
        accuracyAutoAdd: 10 #=60
        accuracySnapAdd: 15 #=85
        accuracyAimedAdd: 20 #=130
        tuAutoAdd: -5 #=25
        tuSnapAdd: -5 #=15
        tuAimedAdd: -5 #=30
        autoRangeAdd: 5 #=15
        snapRangeAdd: 5 #=20
        aimRangeAdd: 10 #=40
        dropoffAdd: -2 #=2
      - STR_SOLDIER_NINJA
        accuracyAutoAdd: -10 #=40
        accuracySnapAdd: -10 #=60
        accuracyAimedAdd: -20 #=90
        tuAutoAdd: 5 #=35
        tuSnapAdd: 5 #=25
        tuAimedAdd: 5 #=40
        autoRangeAdd: -3 #=7
        snapRangeAdd: -3 #=12
        aimRangeAdd: -5 #=25
        dropoffAdd: 2 #=6
  - type: STR_RIFLE_CLIP
    power: 36
    damageBonus:
      firing: 0.1
    soldiersType:
      - STR_SOLDIER_SNIPER
        power: 4 #=40
        damageBonus:
          firing: 0.1 #=0.2
      - STR_SOLDIER_NINJA
        power: -6 #=30
        damageBonus:
          firing: -0.1 #=0

It looks terribly cumbersome and time-consuming to implement, and I strongly doubt that it is possible to do this with the help of scripts.

It remains an option with restrictions, as in armor.

Code: [Select]
items:
  - type: STR_RIFLE
    soldiersType: # Aliens - no restrictions.
      - STR_SOLDIER
      - STR_SOLDIER_SNIPER
      - STR_SOLDIER_MIND

Online Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #12 on: January 23, 2022, 04:14:06 pm »
Thank you. I'll try to describe.

What was proposed to make the availability of weapons depending on the armor is counterproductive. This only makes sense when there are no interchangeable armor types. What is needed is a dependence on the type of soldier.

I see the construction of bonuses/penalties for the type of soldiers like this:

Code: [Select]
items:
  - type: STR_RIFLE
    accuracyAuto: 50
    accuracySnap: 70
    accuracyAimed: 110
    tuAuto: 30
    tuSnap: 20
    tuAimed: 35
    autoRange: 10
    snapRange: 15
    aimRange: 30
    dropoff: 4
    soldiersType:
      - STR_SOLDIER_SNIPER
        accuracyAutoAdd: 10 #=60
        accuracySnapAdd: 15 #=85
        accuracyAimedAdd: 20 #=130
        tuAutoAdd: -5 #=25
        tuSnapAdd: -5 #=15
        tuAimedAdd: -5 #=30
        autoRangeAdd: 5 #=15
        snapRangeAdd: 5 #=20
        aimRangeAdd: 10 #=40
        dropoffAdd: -2 #=2
      - STR_SOLDIER_NINJA
        accuracyAutoAdd: -10 #=40
        accuracySnapAdd: -10 #=60
        accuracyAimedAdd: -20 #=90
        tuAutoAdd: 5 #=35
        tuSnapAdd: 5 #=25
        tuAimedAdd: 5 #=40
        autoRangeAdd: -3 #=7
        snapRangeAdd: -3 #=12
        aimRangeAdd: -5 #=25
        dropoffAdd: 2 #=6
  - type: STR_RIFLE_CLIP
    power: 36
    damageBonus:
      firing: 0.1
    soldiersType:
      - STR_SOLDIER_SNIPER
        power: 4 #=40
        damageBonus:
          firing: 0.1 #=0.2
      - STR_SOLDIER_NINJA
        power: -6 #=30
        damageBonus:
          firing: -0.1 #=0

It looks terribly cumbersome and time-consuming to implement, and I strongly doubt that it is possible to do this with the help of scripts.
Logic like `accuracyAutoAdd` is possible to do today by scripts, I will show example there.
Logic like `tuAutoAdd` probably never will be available in scripts. Action cost is critical for AI to work correctly and scripts will make planing moves a lot of harder.
Rest of options is somewhere in between.

One way to have different cost based on soldier type is skills, this is custom actions that could override default weapons behaviors. Example of its is:
https://openxcom.org/forum/index.php/topic,8007.0.html

For script solution for accuracy.

To reduce number of possible combinations and even add more depth to this each weapon will define only "diff" accuracy based on armor "skill":
Code: [Select]
FinalAccuracy = BaseAccurace + DiffAccuract * SkillSoldier

I will make only one "skill" (not confuse with soldiers skills that are special actions, this "skill" is pure number assigned to armor)
Code: [Select]
extended:
  tags:
    RuleItem:
      WEAPON_SKILL_DIFF_AIM: int
      WEAPON_SKILL_DIFF_AUTO: int
      WEAPON_SKILL_DIFF_SNAP: int
    RuleArmor:
      WEAPON_SKILL_ARMOR_MUL: int
  scripts:
    accuracyMultiplierBonusStats:
      - offset: 1
        code: |
          var int weaponDiff 0;
          var int soldierSkill 0;
         
          if eq battle_action 9;
            weapon.getTag weaponDiff Tag.WEAPON_SKILL_DIFF_AIM; #technicaly this tag should be on rule object from `weapon.getRuleItem r;` but we use short cut and get this tag from item
          end;
          if eq battle_action 7;
            weapon.getTag weaponDiff Tag.WEAPON_SKILL_DIFF_AUTO;
          end;
          if eq battle_action 8;
            weapon.getTag weaponDiff Tag.WEAPON_SKILL_DIFF_SNAP;
          end;
         
          unit.getTag soldierSkill Tag.WEAPON_SKILL_ARMOR_MUL; #again we asking unit what tag its armor have
         
          muldiv soldierSkill weaponDiff 10; #result is natural number but we divide by 10 to have option for 1/2 bonuses too, this mean diff 10 and skill 10 will give bonus 10
         
          add bonus soldierSkill;
         
          return bonus;

And item configs will look like:
Code: [Select]
items:
  - type: STR_RIFLE
    tags:
      WEAPON_SKILL_DIFF_AIM: 40
      WEAPON_SKILL_DIFF_AUTO: 20
      WEAPON_SKILL_DIFF_SNAP: -20

armors:
  - type: STR_NONE_UC
    tags:
      WEAPON_SKILL_ARMOR_MUL: 10

This is very basic version, there is only one "skill" but its easy to expand this script to add multiple parallel bonuses.

It remains an option with restrictions, as in armor.

Code: [Select]
items:
  - type: STR_RIFLE
    soldiersType: # Aliens - no restrictions.
      - STR_SOLDIER
      - STR_SOLDIER_SNIPER
      - STR_SOLDIER_MIND

Restriction can be done by adding:

Code: [Select]
armors:
  - type: STR_NONE_UC
    tags:
      WEAPON_SKILL_ARMOR_MUL: -30
This will make unit still usable but unpractical.

Offline Ethereal

  • Commander
  • *****
  • Posts: 619
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #13 on: January 23, 2022, 05:16:24 pm »
So it's all through the armor, which is no good. The same armor can be worn by different types of infantry, which should have different bonuses. And to make a separate branch of armor for each type of soldier (pieces 8-10) - only clutter up ufopedia, manufactory and the player's brain.

In short - through anything, but not through armor.
« Last Edit: January 23, 2022, 05:19:15 pm by Ethereal »

Online Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: Limiting the weapon a soldier can carry
« Reply #14 on: January 23, 2022, 05:30:20 pm »
This is only initial script, you can easy query solider rule from this unit and grab bonus from there too.
There could be too from SoldierBonuses (but this could require couple of more scripts)

code that get bonus from rule solder would look like:
Code: [Select]
extended:
  tags:
    RuleItem:
      WEAPON_SKILL_DIFF_AIM: int
      WEAPON_SKILL_DIFF_AUTO: int
      WEAPON_SKILL_DIFF_SNAP: int
    RuleArmor:
      WEAPON_SKILL_ARMOR_MUL: int
    RuleSoldier:
      WEAPON_SKILL_SOLDIER_MUL: int
  scripts:
    accuracyMultiplierBonusStats:
      - offset: 1
        code: |
          var int weaponDiff 0;
          var int soldierSkill 0;
         
          if eq battle_action 9;
            weapon.getTag weaponDiff Tag.WEAPON_SKILL_DIFF_AIM; #technicaly this tag should be on rule object from `weapon.getRuleItem r;` but we use short cut and get this tag from item
          end;
          if eq battle_action 7;
            weapon.getTag weaponDiff Tag.WEAPON_SKILL_DIFF_AUTO;
          end;
          if eq battle_action 8;
            weapon.getTag weaponDiff Tag.WEAPON_SKILL_DIFF_SNAP;
          end;
         
          unit.getTag soldierSkill Tag.WEAPON_SKILL_ARMOR_MUL; #again we asking unit what tag its armor have
         
          begin;
            var int temp;
            var ptr GeoscapeSoldier s;
           
            unit.getGeoscapeSoldier s;
            s.getTag temp Tag.WEAPON_SKILL_SOLDIER_MUL; #if `s == null` then `getTag` will set `0` to `temp`
            add soldierSkill temp;
          end;
         
          muldiv soldierSkill weaponDiff 10; #result is natural number but we divide by 10 to have option for 1/2 bonuses too, this mean diff 10 and skill 10 will give bonus 10
         
          add bonus soldierSkill;
         
          return bonus;
« Last Edit: January 23, 2022, 05:32:23 pm by Yankes »