aliens

Author Topic: [Documentation] Direct access to Special Weapons, Unarmed combat  (Read 5446 times)

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Since lobstermen can melee attack without a weapon and psionic aliens can still spam you when unarmed, I decided it was time for the player to get some special weapons!  The new code I'm documenting here allows the player to access an armor's specialWeapon, a unit’s meleeWeapon, or a unit’s psiWeapon.

Note: This requires an OXCE+ version published on or after 8 May 2018, otherwise the mods won't do anything.

There are two ways of accomplishing this with the following ruleset parameters:
  • specialIconSprite: -1 # defines an image from SPICONS.DAT for an item to use instead of the 'psi’ button that appears when using a MC’d psionic alien, default -1 means no icon
  • specialUseEmptyHand: false # true here allows this item to be accessed by clicking on a unit's empty hand when used as a special weapon, default is false

If an item is defined as an armor's specialWeapon, a unit's meleeWeapon or psiWeapon, and has either a special icon sprite or can be used in an empty hand, then you'll be able to use it!  There's the further limitation that the item’s battleType must be a firearm, melee weapon, medi-kit, motion scanner, psi-amp, or mind probe; no grenades, no flares, no ammo, and no corpses are allowed to be used as a special weapon.  If the item has a special icon, then it'll appear where the 'psi' button usually does, and can be accessed by clicking on that icon or pressing a hotkey for it, default 'Y'.  If the weapon can be used from an empty hand, just click/press the hotkey for that hand slot when nothing's there.  Both types support middle-clicking to bring up the ufopaedia article for the item if it's been researched, and the empty hand further supports pressing CTRL+M to bring up the preview for melee attack power.  If for some reason you have multiple items that are competing for one of these two access methods, the one displayed will be the first available from this list, in order: melee, psi-amps, firearms, medi-kits, motion scanners, and finally mind probes.

As for item behavior, using either of the buttons will bring up an action menu just the same as any other weapon, though firing animations won't use the item’s handSprite.  The AI already knows how to use melee weapons and psi attacks like this; the code adds use of projectile weapons, but only if the AI unit has no other weapon.  Player units can react with projectile special weapons but only if they have no other weapon in their hands.

If all of that was confusing, here are two example use cases that will hopefully make it clearer.  The first is simply giving X-Com agents the ability to punch with empty hands:
Code: [Select]
items:
# this item is what is used for the attack
  - type: STR_UNARMED_MELEE
    specialUseEmptyHand: true
    # the rest of the item definition procedes as usual, see the attached mod for more

# now, add the attack to X-Com armors
armors:
  - type: STR_NONE_UC
    specialWeapon: STR_UNARMED_MELEE
# the mod attached below does this for personal and power armor too

With this mod, all you have to do is click a soldier's empty hand and start punching away!

The second example puts a built-in gauntlet with a laser equivalent to the laser pistol on the power suit and flying suit:
Code: [Select]
items:
  - type: STR_UNARMED_POWER
    specialIconSprite: 3
    specialUseEmptyHand: true
    # the rest of the item definition is found in the mod attached below

armors:
  - type: STR_POWER_SUIT_UC
    specialWeapon: STR_UNARMED_POWER

  - type: STR_FLYING_SUIT_UC
    specialWeapon: STR_UNARMED_POWER

extraSprites: # get a new image for the icon
  - type: SPICONS.DAT
    width: 32
    height: 24
    files:
      2: Resources/spicon_brawl.png # 0 is used for the launch blaster bomb button, 1 for alien psi
    files:
      3: Resources/spicon_laserpistol.png

Both examples are contained in the mod attached below.
« Last Edit: July 17, 2018, 12:41:58 pm by Meridian »

Offline Nord

  • Commander
  • *****
  • Posts: 1746
  • The Gate is open.
    • View Profile
Re: Special Weapons Documentation
« Reply #1 on: July 16, 2018, 11:38:20 am »
I can not see empty hand sprite (bigob with fist). What i do wrong?

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11728
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Special Weapons Documentation
« Reply #2 on: July 16, 2018, 11:56:56 am »
I can not see empty hand sprite (bigob with fist). What i do wrong?

The bigob isn't displayed. It only shows in the Ufopaedia article, if you create one for this weapon.

Offline Nord

  • Commander
  • *****
  • Posts: 1746
  • The Gate is open.
    • View Profile
Re: Special Weapons Documentation
« Reply #3 on: July 16, 2018, 04:22:09 pm »
Ahh, that so.

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 140
    • View Profile
Re: [Documentation] Direct access to Special Weapons, Unarmed combat
« Reply #4 on: August 04, 2019, 02:52:45 pm »
I noticed that soldiers can strike with the "free" hand even when the weapon they are holding in the other hand has the property "blockBothHands: true". Is there a way to prevent them from fighting with the "free" hand? (Since in this case it is not supposed to be actually free).

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: [Documentation] Direct access to Special Weapons, Unarmed combat
« Reply #5 on: August 04, 2019, 04:35:25 pm »
You misunderstand the use of the "blockBothHand: true" parameter on an item - it's only for making that weapon unusable when carrying something in the other hand. It does not effect the item in the other hand whatsoever. I won't make that change as the current behavior is intended.