aliens

Author Topic: Extended reaction fire  (Read 15866 times)

Offline Morrandir

  • Sergeant
  • **
  • Posts: 20
    • View Profile
Extended reaction fire
« on: May 22, 2017, 11:56:20 am »
Hi all,

(Updated June 17 2017. Fixes + added the possibility to exclude fire modes from reactions in the battlescape.)

TL;DR: Extended Reaction Fire allows for aimed & auto reaction shots. Balances to reaction score calculations: small penalty to reactions for slow weapons (<20%), small bonus for fast weapons (<6%). Each fire mode can be individually disabled for weapons in the rule set; they are all enabled by default. The choice of reaction fire type is automatic based on distance but can be manually controlled: right click on the corresponding reserve TUs button sets the fire mode as preferred, middle click excludes the mode from reaction fire.

The mod is built on Meridian's OpenXCom Extended+ 3.5 and can be found here: https://github.com/Morrandir-X/OpenXcom/tree/oxce3.5-plus-proto
(Thanks Meridian for help!)

You also should add the following lines to Piratez_lang.rul so that the option is correctly shown:
Code: [Select]
STR_EXTENDED_REACTION_FIRE: "Extended Reaction Fire"
STR_EXTENDED_REACTION_FIRE_DESC: "If enabled, reaction fire uses aimed and auto shots, not just snap shots. Automatic choice based on distance. Right click reserve TUs button for manual preference, middle click to exclude fire modes."

In a nut-shell:
– When enabled from Advanced options (under Extended), ERF allows units to choose aimed, auto, snap shot (and melee of course).
– The mode is automatically selected based on distance, preferring melee, then auto, snap, and aimed shot. The automatic choice can be overridden by manual selection – simply right click the Reserve TUs button and the shooting figure turns golden to mark the selection. Middle click on the button to exclude that type of reaction (the figure in the button disappears to mark the exclusion).
– Each mode can be disabled by setting canReactAimed, canReactAuto, canReactSnap, and canReactMelee flag to false for the weapon in the ruleset.
– For balance purposes, the reaction score calculation has been tweaked to take into account the TUs required for taking the action, lowering the score for slower weapons and making it higher for faster weapons. Disabling the mod reverts the calculation to the standard.

The long story:
One thing that has always bothered me in X-Com is that reaction shots can only be snap shots. The way I see it is that on your turn, you can either opt to act or wait and react (or a combination of the two). Say a sniper is overseeing the battle field. He can decide to shoot any visible units actively or wait for an enemy to move into the open (makes all the more sense if the sniper knows that the enemy is hiding behind cover). Since the time used in both cases is the same, he should be able to make an aimed shot just like when actively engaging. Things get even stranger with someone walking around with a machine gun that only shoots auto: the gunner will just freeze if an opponent comes at him! The role of a gunner is typically to provide cover in the battle field by shooting at whatever moves – an impossibility with the current reaction fire system. (I understand that modders have balanced their mods around this restriction, but further down I suggest another way to keep those balances and still allow for greater variety of reaction fire.)

So, I decided to make new reaction fire rules, call them extended reaction fire. The unit now simply chooses which of the available fire modes to use based on distance or by manual selection, defaulting to the best available shot if the target is beyond accurate firing range.

This change alone would have weird consequences, though. For instance, consider the sniper whose aimed shot takes 95% of his time units, reflecting the time required for aiming and for setting up the gun. If the sniper reserves all its time units, it would be able to react VERY fast – as fast as anyone else – although the point of the high TU cost is the slowness of the weapon. This is because reactions currently depend only on remaining time units and the static reactions stat – how much TUs the shot costs has no bearing on how fast it is taken. Not only would this not make sense, it would overpower reaction fire from slow but accurate/deadly weapons, either sniping shots or auto fire from heavy machine guns. For this reason, the reaction fire calculations require some balancing.

I made the reaction score depend not only on remaining TUs but also on the TU cost of the weapon in the chosen fire mode. The basic idea is that the TUs required for the shot are subtracted from the remaining/reserved TUs used in the calculations. The unit effectively has less TUs reserved as far as reaction fire calculations go. Thus, the slower the gun is to operate, the slower the unit is to react, reflecting better the idea that using 95% of TUs is not done lightning fast but slow. I then made two further tweaks.

1. The subtracted TUs is equal only to HALF of the TUs required by the shot. This I think is a reasonable approximation of when the shot itself is taken (the rest of the TUs include aiming, setting up, and doing any post-shot actions). Balance-wise it makes it feasible to actually fire high-cost aimed and auto shots, which otherwise would require the target to exhaust almost all of its TUs or have really awful reactions.

2. I set a default TU cost, modelling it on the snap shot of an assault rifle, namely 25% of TUs. That is, if the reaction shot is 25% of TUs, the standard formula applies (reactions x remaining TUs / all TUs); if it is more or less than 25%, the reactions are slower or faster. (With 95% aimed shot for a unit with 100 /100 TUs left, for reaction calculations the unit would have 100 - (95 - 25) / 2 = 65 / 100 TUs left.) Note that this only applies to the actor: the target’s reactions are calculated always with the standard formula so that defensive use of reactions does not depend on how fast a gun the target wields.

The end result is, I think, pretty satisfactory. Now whenever a reaction fire check is made, it includes a check on which fire mode is reasonable. I made this to be as simple as possible: within accurate auto fire range, auto fire is used, within accurate snap shot range, snap shot, and finally aimed shot is used outside both ranges. This selection can be overridden with a manual selection, by a combination of setting a preferred fire mode that will be checked first (if the reaction fails, another shot is taken) and excluding fire modes from reactions. Unless all fire modes are excluded, one of the available shooting modes WILL be used: a snap shot will be fired even outside its accurate range if an aimed shot is not available; if the selected firing mode is not feasible (e.g. auto shot would have 0% chance to hit), another is automatically chosen. And yes, a unit can shoot auto/aimed shots and finish off with a snap shot when TUs are just enough for that. With the tweaks in the calculations, an aimed or auto shot is a little slower than a snap shot, but still reasonable (a 90% aimed shot allows the opponent to use 15% more TUs before the shot is taken than in the standard case of 25%; close to the standard the deviation from the current calculations is minimal: within 15%-35% range is is <2.5%).

Finally, since some weapons are incapable of reaction fire by design (e.g. X-Piratez's Long Bow that has aimed shot exactly so that it can't be used for reaction fire), I have added the possibility for disabling reaction fire of any type for any weapons in the ruleset. (The case could be made that e.g. a mortar cannot effectively be used for reaction fire and that some weapons are too dangerous to be used in that fashion (though in X-Piratez reaction fire baby nukes are a thing, so…). This actually results in more possibilities for modders: now reaction fire is no longer dependent on the fire mode and the two can be combined at will.

ERF makes it possible e.g. to:
a)   Set up a gunner with heavy auto fire (e.g. X-Piratez's Heavy Machine Gun) to fire upon enemies in their turn,
b)   Set up a sniper that shoots aimed shots instead of snap shots,
c)   Have auto-only gun wielding soldier take reaction shots (e.g. X-Piratez's Machine Gun),
d)   Have assault rifle wielding units shoot auto when the enemy turns around a corner in close range or fire one accurate aimed shot when an enemy is far away, making these weapons truly versatile,
e)     Have one assault rifle wielding unit overwatch with aimed shots for precision and one with auto shot for more mayhem,
f)     Choose manually two 25% snap shots over one 50% aimed shot, or vice versa, depending on the situation.
g)   Have SMG wielding or fast melee units react to an opponent faster: one can effectively increase one’s reactions stat by using a fast weapon,
h)     Give snap shot to a weapon not meant for reaction fire (e.g. X-Piratez's Long Bow), in addition to aimed shot,
i)      Have weapons that can only use some of its fire modes for reaction fire, including disallowing melee while allowing firing reactions, or vice versa,
j)     Have any sort of combination of excluded and preferred fire modes, e.g. a sniper that never snap shots or a soldier with assault rifle that only shoots auto when units are close enough and does not react otherwise, or a unit that only uses melee for reactions (e.g. stun weapon) even though it has a ranged weapon.

For further development:
– Perhaps it is possible to add a special reaction fire mode that cannot be actively used on player's turn but is used for reaction shots, with e.g. lower accuracy or higher TU cost.
[ *** DONE AND DONE *** – One issue is that sometimes one prefers three snap shots over one aimed shot, and apart from distance, there is no way that can be enforced now. I think such issues are minor compared to all the issues in the existing system (no machine gun reaction fire…!). One might consider a bigger change in the game mechanics to solve this: make the “reserve TUs for x shot” buttons work the way I used to think they did, namely if you have “reserve TUs for aimed shot” on when you move the unit, it would reaction fire with aimed shot EVEN when within accurate snap / auto shot range, and if you have “reserve TUs for snap shot” on, then snap shots would be used. I am unsure if this change is possible and how difficult it would be, however.]
– A known issue is that currently the choice of reaction fire weapon in dual wielding situations is a bit wobbly. For instance currently if the active weapon cannot react with a fire mode, the system does not check if the inactive weapon could (it's complicated to make it switch between checking both weapons for each instance).

It would be great to hear what the community thinks of this, the idea and the implementation.

(The extended reaction fire is probably compatible with vanilla OpenXCom too but has not yet been made to work with it.)

Thanks!

~M~
« Last Edit: June 17, 2017, 05:58:26 pm by Morrandir »

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11721
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Extended reaction fire
« Reply #1 on: May 22, 2017, 04:33:18 pm »
I browsed your post and while I can't really estimate how well it works in reality, the way you presented your idea seems solid and encouraging.

One question I have: since the TUs used to determine reactions are lower by half the firing cost, it means they are effectively much lower. Doesn't it make reaction fire very slow?

Offline Morrandir

  • Sergeant
  • **
  • Posts: 20
    • View Profile
Re: Extended reaction fire
« Reply #2 on: May 22, 2017, 06:19:22 pm »
I browsed your post and while I can't really estimate how well it works in reality, the way you presented your idea seems solid and encouraging.

One question I have: since the TUs used to determine reactions are lower by half the firing cost, it means they are effectively much lower. Doesn't it make reaction fire very slow?

Thanks – in my tests this worked very well, and balancing it should be easy. I think the only thing to keep in mind would be that a poor accuracy auto fire volley from a unit can be potentially very devastating to your own troops. So one would have to adjust one's game strategy accordingly.

The reaction stat is calculated using the formula: Reactions * (Current TU's / TU's). In my suggestion the change would be only Firing TU's / 2TU's, which is then subtracted from the Current TUs. That is not particularly much to begin with (since a typical shot is about 25% of TU's, the change in the reactions modifier is about 12,5%). But I also set 25% of TU's as a standard, meaning that in that case the modification is zero. (I wanted to avoid making all reaction stats lower: now the old reaction stat is simply the standard reaction stat.) What it means in practice is that for slow weapons the reaction score is 10% less for every 20% over the 25%, which is to say that the unit can move 10% further before the shot is taken.

Here are some examples of how it works (number is for the reaction stat) for someone with 50 reactions and 100 TUs, compared with the current formula that gives 50:

FORMULA: Reactions * (Current TUs - (WTU - 0.25*TUs)) / TUs, where WTU is the firing cost in TUs.

WTU 10: 54
WTU 20: 51.5
WTU 25: 50 (default case, i.e. as it is now)
WTU 30: 49
WTU 50: 44
WTU 75: 37.5
WTU 90: 34
WTU 100: 31.5

What this means is this: if the target has 50 reactions and 50/50 TUs, the reaction score is 50 (shot would be fired immediately on action). With WTU 50, compared to how it is now, the target would have to use 12% more of its TUs for the shot to be taken, i.e. 6. With WTU 75 that's 25%, i.e. 13 TUs. If the target has 100 reactions instead, as it is now the shot would be taken at 50% = 25 TUs. With the modified calculations, given WTU 50 the target needs to move 3 more TUs (6%, or 12% more of remaining TUs), given WTU 75, 7 more TUs. Notice, then, that the 10% for every 20% over 25% rule I mentioned above pertains to the remaining TUs: if the target's reaction score is much higher than the actor's, when reacting becomes possible to begin with, the change is even smaller. The main factor is, then, still the reaction stat.

In any case, the formula could well be tweaked for balance. The main thing for me is to allow for auto and aimed shot reactions, and the rest of the changes support making that feasible.

Thanks, and cheers!

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9087
    • View Profile
Re: Extended reaction fire
« Reply #3 on: May 25, 2017, 11:42:18 am »
It would be great to hear what the community thinks of this, the idea and the implementation.

The second part of this feature (reaction score calculation) is already possible to mod at will using Yankes' scripts (since version 3.0).

I made the changes to Meridian's OpenXCom Extended (because I'm playing X-Piratez) and the fork can be found here: https://github.com/Morrandir-X/OpenXcom.

Actually, you have made changes on the master branch, which is equal to vanilla.
If you want to make changes for the Extended version, you should use branch "oxce3.5-plus-proto".

EDIT: actually, it's some kind of mix?? The source code doesn't even compile (I tried compiling from branch master, commit 7cc33f6). And I can't see what you have changed, diff between ac69cb7 and 7cc33f6 is too big and has definitely more than just your changes.
« Last Edit: May 25, 2017, 12:06:41 pm by Meridian »

Offline Morrandir

  • Sergeant
  • **
  • Posts: 20
    • View Profile
Re: Extended reaction fire
« Reply #4 on: May 25, 2017, 01:03:51 pm »
The second part of this feature (reaction score calculation) is already possible to mod at will using Yankes' scripts (since version 3.0).

Actually, you have made changes on the master branch, which is equal to vanilla.
If you want to make changes for the Extended version, you should use branch "oxce3.5-plus-proto".

EDIT: actually, it's some kind of mix?? The source code doesn't even compile (I tried compiling from branch master, commit 7cc33f6). And I can't see what you have changed, diff between ac69cb7 and 7cc33f6 is too big and has definitely more than just your changes.

Damn, you are right, I accidentally forked the wrong version. I deleted it and forked 3.5, it SHOULD work now – I tested it and it does compile just fine on my machine. I'll edit my post.

Offline Morrandir

  • Sergeant
  • **
  • Posts: 20
    • View Profile
Re: Extended reaction fire
« Reply #5 on: May 30, 2017, 09:41:04 pm »
The Extended Reaction Fire mod is now fully functional. It is built on OpenXCom+, v. 3.5. I will look into making it compatible with OpenXCom vanilla.

ERF can be enabled from advanced settings under extended. It is disabled by default.

ERF includes four new flags for items (see RuleItem.cpp and .h): canReactAimed, canReactAuto, canReactSnap, canReactMelee. Each are set to true on default so that a weapon can use any of the attack modes it has for reaction fire. Setting any of them to false disables that reaction type for the weapon, leaving others (if any) enabled.

When ERF is enabled, the reaction score calculation depends on the weapon the acting unit reacts with (the target's weapon is irrelevant), as explained above. When it is disabled, the standard calculation is used.

I would be grateful for any feedback and suggestions you might have. Thanks!

Offline Morrandir

  • Sergeant
  • **
  • Posts: 20
    • View Profile
Re: Extended reaction fire
« Reply #6 on: June 04, 2017, 11:11:38 pm »
I added new functionality to Extended Reaction Fire. It is now possible to select an individual reaction fire choice for each unit separately: by right clicking the Reserve TUs button in battlescape one can set the unit to react with auto/snap/aimed as long as it has TUs and the target is within minimum reaction range. Otherwise the mod reverts to automatic choice based on distance. This choice can be made separately for each unit and in conjunction with the normal/standard choice of reserving TUs (which, as you know, does not effect reaction fire, just reserves TUs for the selected shot). The choice can be seen by the golden figure in the selected Reserve TUs button.

It is now possible e.g. to:
- Set up an over watching unit with an assault rifle that always reacts with auto fire, regardless of distance (except below minimum hitting chance, usually something like 2%)
- Set up an over watching unit with an assault rifle that will always react with an aimed shot, for extra security.
- Have a unit with a BIG BOOM BOOM GUN always react with snap shot (or auto) instead of an aimed shot, even from a long distance, if you prefer many inaccurate shots over one accurate one, which may well be the case since precision is not important for a BIG BOOM BOOM GUN.
- Specifically avoid that a unit shoots auto shots even at close range – perhaps to avoid friendly fire.
- Make a unit prefer two snap shots of 25% over one auto shot of 50% TUs, or whatever special requirements you might have.

As always, feedback and suggestions are welcome!

Link to build in the first post.

Cheers,

~M~

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11721
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Extended reaction fire
« Reply #7 on: June 04, 2017, 11:34:48 pm »
I can't way to try it. :)

Offline Stoddard

  • Colonel
  • ****
  • Posts: 485
  • in a fey mood
    • View Profile
    • Linux builds & stuff
Re: Extended reaction fire
« Reply #8 on: June 05, 2017, 01:08:29 am »
I really like how it nicely is thought out. Can't wait to try it out either.

Offline Morrandir

  • Sergeant
  • **
  • Posts: 20
    • View Profile
Re: Extended reaction fire
« Reply #9 on: June 09, 2017, 05:45:42 pm »
Updates abound! Apart from completely reworking the function to determine reaction type (I made it iterative over a for-loop – it's nicer and allows for easier expansion of allowed reaction types), I also fixed an oversight in the current system: reactions with gun butt! Now one can melee react with guns that have a swing function – previously the weapon would only shoot, and if it had no ammo, do nothing. (E.g. X-Piratez's Shotgun Fist would never function for melee reactions.)

Note that as reactions system prioritises melee, a weapon with a swing function WILL use it over shooting in close quarters (particularly nice with the new CQC system that makes point blank auto fire often... pointless). You can override this however by making a manual choice of fire mode.

As the new function is a bit experimental and requires further testing (although I cannot get it to crash or fail), I have not yet updated the main ERF linked above. For those who want gun butt reactions, get it here:
https://github.com/Morrandir-X/OpenXcom/tree/oxce3.5-plus-proto-ERF-plus

For both versions I also fixed some bugs. (One known issue is that right-clicking the Expend All TUs button will colour it golden. I'll fix it soon.)

Test it out! I can say that this mod has some pretty exciting fire fights with amazingly destructive auto fire from both sides – those assault grenade launchers have never been so much fun! ;D

Cheers,

~M~

Offline NeoWorm

  • Colonel
  • ****
  • Posts: 104
    • View Profile
Re: Extended reaction fire
« Reply #10 on: June 09, 2017, 07:20:46 pm »
I really liked how reactions were handled in jagged alliance 2. You just get to control the soldier that was able to interrupt enemy turn and you can whatever you want with the remaining action points.

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11721
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: Extended reaction fire
« Reply #11 on: June 09, 2017, 07:25:41 pm »
I really liked how reactions were handled in jagged alliance 2. You just get to control the soldier that was able to interrupt enemy turn and you can whatever you want with the remaining action points.

That's how it was in Laser Squad, X-Com's predecessor. But the one in X-Com seems more accurate actually, since soldiers can only shoot at units which they win initiative against.

Anyway, I'm excited about this, Morrandir. It looks competent.

Offline Morrandir

  • Sergeant
  • **
  • Posts: 20
    • View Profile
Re: Extended reaction fire
« Reply #12 on: June 09, 2017, 07:40:48 pm »
I really liked how reactions were handled in jagged alliance 2. You just get to control the soldier that was able to interrupt enemy turn and you can whatever you want with the remaining action points.

Quote from: Solarius Scorch
That's how it was in Laser Squad, X-Com's predecessor. But the one in X-Com seems more accurate actually, since soldiers can only shoot at units which they win initiative against.

Anyway, I'm excited about this, Morrandir. It looks competent.

There are certainly some good aspects to that system – it would for instance be really cool to be able to shoot or hide depending on what kind of target you see. Quite often I would prefer a, errm, tactical retreat when a cyberdisc comes around the corner rather than agitate it with whatever pea shooter I happen to have. The initiative aspect is indeed important, however, and even IF one could program in some sort of option to retreat, one question is, how many TUs would one get for it and how to tweak the interface to accommodate it.**

Thanks, Solarius, I hope to hear your thoughts on it soon. In the name of control over your units, I'm planning to add a middle click to the reserve TUs buttons for choosing only one reaction type and disabling others for the unit. That way one could e.g. hold fire until opposing units come to accurate auto fire range 8)

Cheers,

~M~

** I wonder if it would be possible to have a pop up appear when a unit is allowed to react, halting the game (like death notifications do), with an option to shoot or hide. Hiding could be done automatically (let computer control the unit) by allowing the user to, say, choose a hiding spot before end of the turn. Clicking on "TACTICAL RETREAT" would automate the unit's movement to that location, whereas "GIVE 'EM HELL" would initiate normal reaction fire. Sounds do-able...? ??? Then again, might be a bit of a chore setting up escape routes...
« Last Edit: June 09, 2017, 07:47:07 pm by Morrandir »

Offline Dioxine

  • Commander
  • *****
  • Posts: 5455
  • punk not dead
    • View Profile
    • Nocturnal Productions
Re: Extended reaction fire
« Reply #13 on: June 09, 2017, 09:55:10 pm »
I think this mod idea is highly commendable.

Offline Morrandir

  • Sergeant
  • **
  • Posts: 20
    • View Profile
Re: Extended reaction fire
« Reply #14 on: June 09, 2017, 11:07:54 pm »
One more update, for Friday's sake: it is now impossible to select an unsupported fire mode for reactions. It can be unsupported because the weapon does not have that fire mode or because it has been specifically excluded from reaction fire. (Especially the latter is useful, as the player might not be aware of which reaction modes a weapon supports, if any.) If the user tries to select an unsupported fire mode, a pop up warning will appear and the selection is not made.

This is currently available only in the experimental version of Extended Reaction Fire, i.e. here: https://github.com/Morrandir-X/OpenXcom/tree/oxce3.5-plus-proto-ERF-plus

I think this mod idea is highly commendable.

Thanks, Dioxine, I'm happy to hear that – if one day it were to find its way into the official X-Piratez build, I would not have to update my own build every time there are updates  ;D

Cheers,

~M~