OpenXcom Forum

Modding => Released Mods => XPiratez => Topic started by: peirceg on May 04, 2020, 09:15:07 am

Title: Reaction vs Melee Enable
Post by: peirceg on May 04, 2020, 09:15:07 am
Is there any way for to enable reaction shots/strikes with melee weapons against melee weapon strikes? A nice simple edit somewhere?
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 04, 2020, 10:17:42 am
Yes, here: https://github.com/OpenXcom/OpenXcom/blob/master/src/Battlescape/MeleeAttackBState.cpp#L171
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 06, 2020, 04:21:32 pm
Thank you very much! How can I incorporate this into my game? What files do I have to edit? Sorry for being a newb.
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 06, 2020, 04:28:05 pm
How can I incorporate this into my game?

Edit, compile, run.

What files do I have to edit?

file MeleeAttackBState.cpp at lines 172-175
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 06, 2020, 04:34:49 pm
Yes, here: https://github.com/OpenXcom/OpenXcom/blob/master/src/Battlescape/MeleeAttackBState.cpp#L171

Is this already enabled in OXCE?
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 06, 2020, 04:57:04 pm
Is this already enabled in OXCE?

no
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 06, 2020, 05:12:30 pm
I couldnt find the MeleeAttackBState.cpp file in my xpiratez download folder. I am going to assume that I need to download a seperate OXCE from somewhere?
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 06, 2020, 05:18:36 pm
I couldnt find the MeleeAttackBState.cpp file in my xpiratez download folder. I am going to assume that I need to download a seperate OXCE from somewhere?

Nope, this is c++ code, you have to fork OXC/OXCE on GitHub, and make that edit on it, then compile it according to the instructions on the OXCE subforum except substituting your fork for meridian's link.
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 06, 2020, 05:19:32 pm
I couldnt find the MeleeAttackBState.cpp file in my xpiratez download folder. I am going to assume that I need to download a seperate OXCE from somewhere?

PirateZ has a compiled version of OXCE, not the source code.

Also for OXCE, it's in a difference file: https://github.com/MeridianOXC/OpenXcom/blob/oxce-plus/src/Battlescape/TileEngine.cpp#L2012
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 06, 2020, 05:57:20 pm
Just want to confirm, because I am very new to this,

1.Create a fork on github for this https://github.com/OpenXcom/OpenXcom/blob/master/src/Battlescape/MeleeAttackBState.cpp#L171
2. Delete lines 171-175 then commit those changes
3 Follow instructions here about compiling https://openxcom.org/forum/index.php/topic,7048.0.html

Replace stage 2 here with the link to my newly forked version ;

"1. Download, install and update Visual Studio 2019 Community Edition: https://visualstudio.microsoft.com/downloads/
2. Clone OXCE repo: https://github.com/MeridianOXC/OpenXcom.git
3. Download and extract the pre-compiled dependencies (into repo's root): openxcom-deps-win-vc2017-newest.zip
4. Open solution "src/OpenXcom.2010.sln"
5. Click "Build" from menu or toolbar"

4. Compile then overwrite with the newly compiled OXCE into my xpiratez folder.
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 06, 2020, 06:03:00 pm
2. Delete lines 171-175 then commit those changes

All steps are correct except the quoted ones, don't delete the lines, just remove the comments from the code, other than the obvious comment at the start.

Comments are the // symbols.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 06, 2020, 06:16:46 pm
All steps are correct except the quoted ones, don't delete the lines, just remove the comments from the code, other than the obvious comment at the start.

Comments are the // symbols.

https://imgur.com/a/KOpEddH

I am going to assume that this is now correct? I am going to assume with these edits units will not be able to reaction fire with their equipped weapons when engaged by enemies in melee?
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 06, 2020, 06:23:34 pm
https://imgur.com/a/KOpEddH

I am going to assume that this is now correct? I am going to assume with these edits units will not be able to reaction fire with their equipped weapons when engaged by enemies in melee?

Units WILL be able to react with those edits
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 06, 2020, 06:27:17 pm
sorry had a bit of brainfar, its pretty late here. Thanks a lot for your help guys. I didnt like my melee units standing defenceless as they got whapped on by aliens in their turn.
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 06, 2020, 06:47:21 pm
Just want to confirm, because I am very new to this,

1.Create a fork on github for this https://github.com/OpenXcom/OpenXcom/blob/master/src/Battlescape/MeleeAttackBState.cpp#L171
2. Delete lines 171-175 then commit those changes
3 Follow instructions here about compiling https://openxcom.org/forum/index.php/topic,7048.0.html


This is if you want OXC.

If you want OXCE, you need to download a different repo and change different file and different line... as written above.

The rest is OK.

PS: no need to fork unless you want to publish your changes, downloading existing repo is enough
Title: Re: Reaction vs Melee Enable
Post by: Yankes on May 06, 2020, 10:37:26 pm
But you do not need change any thing in OXCE, is not enabled by default but code still allow to enable it by scripts.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 07, 2020, 07:12:18 am
What lines do I need to edit for https://github.com/MeridianOXC/OpenXcom/blob/oxce-plus/src/Battlescape/TileEngine.cpp#L2012   ?

It was unfortunately never mentioned and I cant write c++ so I dont know where to look.
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 07, 2020, 10:21:39 am
As the link says, line 2012.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 07, 2020, 11:50:15 am
I am seeing this at line 2012

int reactionChance = BA_HIT != originalAction.type ? 100 : 0;

What should I edit now?
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 07, 2020, 11:57:44 am
change the reaction chance from 0 to 100 maybe?
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 07, 2020, 11:59:00 am
Thank you! I will see if it works.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 07, 2020, 01:51:59 pm
After building, I got this file OpenXcom.2010.vcxproj successfully built, where is the .exe? What should I do with this newly built file?
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 07, 2020, 01:54:26 pm
Have you ever built anything?

If not, nothing I say will help you.
If yes, you should not need our help.
Title: Re: Reaction vs Melee Enable
Post by: Yankes on May 07, 2020, 09:36:28 pm
I am seeing this at line 2012

int reactionChance = BA_HIT != originalAction.type ? 100 : 0;

What should I edit now?

This line set default behavior that script will read and change, you do not need change this source code, only add mod that will have script like:
Code: [Select]
extended:
  scripts:
    reactionUnitAction:
      - offset: -10
        code: |
          if eq battle_action battle_action_hit;
            set reaction_chance 100;
          end;
          return reaction_chance;
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 08, 2020, 03:29:31 am
By the way which hand does the game prioritise when making a reaction shot? Or is it random?
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 08, 2020, 03:37:33 am
Good question, will check tomorrow, see if Meridian answers this as fast as he normally does. I swear that he must have somehow memorized the codebase. 8)
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 08, 2020, 10:22:58 am
Game prefers:
1. melee weapons
2. if not found, melee attack of ranged weapons (gunbutt)
3. if not found, ranged weapons with snapshot

For AI, weapon with quickest  snapshot; for xcom main (=last used) weapon.
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 08, 2020, 10:30:23 am
Btw. I've added some experimental support for reactions to melee attacks.

Configurable via global switch

Code: [Select]
constants:
  extendedMeleeReactions: 2     # default 0

0 = vanilla, cannot react to melee attacks
1 = can react to melee attacks, if attacked from the front... same effect as Yankes' script above
2 = can react to melee attacks, if attacked from any side

PS: The scripts can change the % chance to perform a melee reaction in all 3 cases. But only with option "2" the reaction from any side can be triggered, that's not scriptable (yet).

PPS: turn on only if you're 120% sure you want it
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 08, 2020, 04:10:50 pm
Will units also react to movement in tiles other than the one directly in front of them?
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 08, 2020, 04:21:49 pm
No, and that wouldn't make sense anyway.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 08, 2020, 04:26:26 pm
Aliens react to movement already. Trying to stab someone in the back  or running past them should provoke a reaction but I digress.
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 08, 2020, 04:43:39 pm
Aliens react to movement already. Trying to stab someone in the back  or running past them should provoke a reaction but I digress.

Of course stabbing someone in the back would provoke a reaction, but if they don't see you, moving around behind them wouldn't. Unless we're bringing sound into this game which has been suggested(and rejected) before.
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 08, 2020, 04:57:36 pm
Will units also react to movement in tiles other than the one directly in front of them?

The units react only to units they see (90 degrees cone) or units that have hit/shot them (even if they are not in the cone).

With the new option = 2, they will also react to units that have attempted melee attack on them (both hit and miss count!).

So theoretical situation like this is possible:
1. you melee attack a Lobsterman from behind... hit or miss, doesn't matter
2. Lobsterman has low TU and poor reactions, so it won't attack you immediately.... but it WILL remember you
3. now you run away from Lobsterman (outside of his vision range)... slowly decreasing your TUs
4. as soon as you have low enough TU, the Lobsterman will turn around and shoot at you

Enjoy the pain.
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 08, 2020, 05:19:23 pm
Scenario above illustrated with reactions 100 and full TU.

Just rename `lobster.mp4.txt` to `lobster.mp4`
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 09, 2020, 12:37:14 am
So in the situation detailed above, which sounds wonderful btw, will they also react to you moving and coming into melee range if you move into melee range in their 90 degree arc (if they have high reactions), the three tiles directly in front of them with a melee attack-potentially before you do a melee attack?
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 09, 2020, 12:39:55 am
So in the situation detailed above, which sounds wonderful btw, will they also react to you moving and coming into melee range if you move into melee range in their 90 degree arc, the three tiles directly in front of them with a melee attack?
They've always done that...
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 09, 2020, 12:44:14 am
So they will react to movement with a melee attack of their own if a unit just steps into melee range in their 90 degree front arc?
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 09, 2020, 12:45:06 am
They've always done that...

they reacted with melee only from 1 tile, directly in front of them... for the other 2 tiles they reacted with a snapshot

now they can react with melee on all 3 tiles (assuming the new setting = 2)... or to be precise on all 8 tiles around them
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 09, 2020, 12:52:44 am
Fantastic option, makes certain weapons that reduce TUs really useful now.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 10, 2020, 12:46:12 pm
Ive also noted that in CQC situations pistols are preferred to a melee weapon, is this intentional?
Title: Re: Reaction vs Melee Enable
Post by: Meridian on May 10, 2020, 03:06:44 pm
Ive also noted that in CQC situations pistols are preferred to a melee weapon, is this intentional?

Depends on the modder.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 11, 2020, 02:34:09 am
Was stumped for a bit when "Ranged" melee weapons were not activating on reactions (Barbarian Sword etc), realized that the gauntlets on certain armors were taking priority. I edited the gauntlets to act as ranged weapons with a melee component (both are effectively the same when selected except one has a crosshair icon). Is there anyway to get rid of one of the selections?.

Anyways after testing it seems to work, units use their ranged melee weapons if available, then their gauntlet weapons.
Title: Re: Reaction vs Melee Enable
Post by: vadracas on May 11, 2020, 02:44:19 am
Was stumped for a bit when "Ranged" melee weapons were not activating on reactions (Barbarian Sword etc), realized that the gauntlets on certain armors were taking priority. I edited the gauntlets to act as ranged weapons with a melee component (both are effectively the same when selected except one has a crosshair icon). Is there anyway to get rid of one of the selections?.

Anyways after testing it seems to work, units use their ranged melee weapons if available, then their gauntlet weapons.

Both aren't effectively the same as one Is affected by cqc.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 11, 2020, 03:30:10 am
How can i match the cqc multiplier to be effectively the same?

Title: Re: Reaction vs Melee Enable
Post by: Bobit on May 11, 2020, 03:45:58 am
Melees don't use CQB, they use melee dodge, which is just an accuracy reduction based on target stats.

You could make the formula for enemy CQB similar to the formula for melee dodge, and give the weapon a CQB multiplier and high accuracy to make it similarly likely to hit. But it's impossible to make them very similar.
Title: Re: Reaction vs Melee Enable
Post by: peirceg on May 11, 2020, 04:01:23 am
Guess Ill just save myself the hassle and not use the ranged version. Reactions are based on the melee segment anyways. Is there any way to get the ranged version to not display?

*Just worked it out just needed to delete all references to Snapshots autoshots etc, it acts like a gun without the gun part now.