OpenXcom Forum

Modding => OpenXcom Extended => OXCE Suggestions DONE => Topic started by: ohartenstein23 on July 15, 2018, 12:09:57 am

Title: [Documentation] Spray Waypoints Explanation
Post by: ohartenstein23 on July 15, 2018, 12:09:57 am
TL;DR: Hold CTRL+SHIFT while clicking to auto shot to spray and pray when it's enabled.

The newest release of OXCE+ includes a bit of code I wrote for "spray" autoshot attacks, and since it uses some keyboard shortcuts/mechanics not used anywhere else, I wanted to provide an explanation for how it works.  First off, under the hood the engine is using waypoints similar to those placed for firing a blaster bomb, then placing the shots from an autoshot attack spaced out evenly along this waypoint path as if you were able to separately click the firing position for each shot.  That attack looks like this:

(https://openxcom.org/forum/index.php?action=dlattach;topic=6423.0;attach=38241;image)

The laser rifle from that demonstration has the following lines added to its ruleset:
Code: [Select]
items:
  - type: STR_LASER_RIFLE
    autoShots: 10
    sprayWaypoints: 2
In addition, once the auto shot is selected, I am holding the CTRL+SHIFT keys in order to start placing the waypoints; if I had not, the autoshot would have just fired all 10 shots at the first location clicked.  The second waypoint clicked did not need CTRL+SHIFT held as it automatically fires the attack when the maximum number of waypoints is reached.  If you have the confirm fire mode option turned on, then you will need to click one more time anywhere to start the attack.  As with the blaster bomb waypoints, right-clicking will remove the last one placed.

With this code, it is possible to have more than two waypoints:

(https://openxcom.org/forum/index.php?action=dlattach;topic=6423.0;attach=38243;image)

The laser rifle from that demonstration has sprayWaypoints increased to 3 from 2.  As before, the attack automatically fires once I place the last waypoint.  If you'd rather stop before the last waypoint, holding CTRL+SHIFT while clicking to place the final waypoint that you desire will execute the attack with only that many waypoints.  In this example I stop at 2 waypoints even though 3 are available:

(https://openxcom.org/forum/index.php?action=dlattach;topic=6423.0;attach=38245;image)

For modders: the default value of sprayWaypoints is 0, which means this behavior is disabled on that particular weapon.  In order to turn it on, you must give a weapon more than 0 sprayWaypoints.
Title: Re: Spray Waypoints Explanation
Post by: SIMON BAILIE on July 15, 2018, 12:39:49 am
Brilliant, this reminds of the full auto function for the heavy laser from ufo extender:

https://www.ufopaedia.org/index.php/UFOextender

ps: Will this work for TFTD as well?
Title: Re: Spray Waypoints Explanation
Post by: ohartenstein23 on July 15, 2018, 01:23:09 am
Yes, this will work for TFTD on any weapons that are modded to use it.
Title: Re: Spray Waypoints Explanation
Post by: SIMON BAILIE on July 15, 2018, 01:26:39 am
Yep I wasn't sure so that'll be nice for say the gauss rifle.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: The Reaver of Darkness on July 27, 2018, 02:17:50 pm
I'm not able to use more than 2 waypoints. Even when the weapon is set to do more waypoints, as soon as the second waypoint is set, it begins firing.

Code: [Select]
  - type: STR_HEAVY_AUTO_LASER
    power: 75
    accuracyAuto: 70
    tuAuto: 78
    autoShots: 8
    sprayWaypoints: 3
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: Meridian on July 27, 2018, 02:21:55 pm
I'm not able to use more than 2 waypoints. Even when the weapon is set to do more waypoints, as soon as the second waypoint is set, it begins firing.

1. Ctrl+Shift+click for first waypint
2. normal click for waypoints in the middle
3. Ctrl+Shift+click for last waypoint
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: ohartenstein23 on July 27, 2018, 02:44:02 pm
I'll add to that; you only need to CTRL+SHIFT+click for the first waypoint, the rest can just be normal click unless you want to end waypoint selection early.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: The Reaver of Darkness on July 27, 2018, 03:22:50 pm
Thanks. I was trying to hold ctrl+shift the whole time.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: The Reaver of Darkness on August 08, 2018, 05:11:30 am
I am getting a strange bug in which the soldier turns while firing, but continues to fire at the same spot. Is anyone else getting this issue?

It seems to be happening on weapons with arcing shot. Another problem I am getting with arcing shot and spray waypoints is very frequently the soldier ceases firing and claims there is no viable trajectory. This happens sometimes when there is a viable trajectory, such as while flying in the open field and trying to shoot (literally) the broad side of a barn.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: ohartenstein23 on August 08, 2018, 05:27:39 am
This feature is not supported for arcing weapons for the same reasons that you cannot force-fire arcing weapons.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: The Reaver of Darkness on August 08, 2018, 07:39:36 am
I was about to ask why you can't force-fire arcing weapons when I realized perhaps why: Making the displayed shot travel on the correct arc is much simpler than solving its hit position repeatedly for every possible position along the arc. It can probably be done, but you'd have to make the game solve calculus equations on the fly, and that takes a programmer with a good grasp of calculus.

The other bug, however (each shot goes toward the same target) could be partially resolved by simply having the weapon progressively target each waypoint: ie. if the weapon fires 8 shots and has 4 waypoints, it would fire twice at each waypoint. With sufficiently low shot accuracy, the player may never realize this is what the weapon is doing.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: ohartenstein23 on August 08, 2018, 01:38:08 pm
I'm not getting the bug you mention, and the code does progressively target "waypoints" - just before firing it takes the waypoints you defined and interpolates between them for each shot to get a new target for each bullet.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: The Reaver of Darkness on August 09, 2018, 12:36:34 am
I'm glad to hear it does that. But I am definitely getting the bug and I don't know why.

Here's a video of it happening:

I'm using Extended+ 3.10b (v2018-07-21).

I've attached my mod. I'm not using any other mods.



- - - - - -

I also think the shot should not stop completely as soon as a single trajectory fails; rather it should continue attempting all of them until it runs out of shots.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: KZad Bhat on August 09, 2018, 10:22:54 am
Reaver, you're using an arcing weapon. ohartstein already told you that sweep fire doesn't support arcing weapons. Seems you made it work . . . kind of . . . and this is what happens.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: The Reaver of Darkness on August 09, 2018, 02:03:08 pm
Yes but ohartstein said that he is not getting this bug. I want to not get it, too!

I'm not getting the bug you mention, and the code does progressively target "waypoints" - just before firing it takes the waypoints you defined and interpolates between them for each shot to get a new target for each bullet.
Title: Re: [Documentation] Spray Waypoints Explanation
Post by: ohartenstein23 on August 09, 2018, 02:40:56 pm
You made this sound like two separate issues: arcing shots not working and then regular shots behaving strangely. It is not a bug that arcing shots don't work with this code, and it's clear now from your video that you only meant arcing shots don't work.