Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Spoon on June 26, 2018, 10:30:02 pm

Title: Issue with A.I. and fighter mounted beams
Post by: Spoon on June 26, 2018, 10:30:02 pm
So the issue with fighter mounted beam weapons is this: If the A.I. has only beam weapons equipped, they will fire at targets far beyond the weapon's maximum range.
If the A.I. has one beam weapon equipped and one normal primary weapon, they do respect maximum weapon range.

This bug wouldn't be that big of a deal to work around, by just making sure the A.I. always comes equipped with primaries other than beams. But the A.I. can't handle having two target lead indicators either. They'll fire infront of the target because of the normal weapon, and end up missing most of their beam shots.

Please aid me, code wizards.
Title: Re: Issue with A.I. and fighter mounted beams
Post by: General Battuta on June 26, 2018, 10:35:11 pm
Workaround: can you disable primary linking on the beam weapon?
Title: Re: Issue with A.I. and fighter mounted beams
Post by: JSRNerdo on June 26, 2018, 10:43:26 pm
What are velocity/lifetime/weapon range set to on the beam weapon? IIRC the AI determines range by velocity*lifetime or weapon range, not sure how exactly.
Title: Re: Issue with A.I. and fighter mounted beams
Post by: General Battuta on June 26, 2018, 10:47:36 pm
What are velocity/lifetime/weapon range set to on the beam weapon? IIRC the AI determines range by velocity*lifetime or weapon range, not sure how exactly.

The AI respects the range (not velocity*life) you give it on normal primaries, dunno about beams.
Title: Re: Issue with A.I. and fighter mounted beams
Post by: Nightmare on June 26, 2018, 10:52:59 pm
Do you have +Range: in $Beam info specified?
Title: Re: Issue with A.I. and fighter mounted beams
Post by: Spoon on June 26, 2018, 10:58:30 pm
Do you have +Range: in $Beam info specified?
What are velocity/lifetime/weapon range set to on the beam weapon? IIRC the AI determines range by velocity*lifetime or weapon range, not sure how exactly.
I mean, I get you guys are trying to be helpful, but can we just assume for a moment here that I know all of these things after years and years of modding, and have the weapons set up correctly and that this is an actual engine bug?  :p

But here, see for yourself:

Code: [Select]
$Name:                          Fusion array
+Title:                          XSTR("Fusion array (Medium)", -1)
+Description:
XSTR("Effective range: 2000
Damage type: Energy
Damage: 8 vs Hull, 5 vs Shield
Rate of Fire 0.75 - Beam | Power usage 3", -1)
$end_multi_text
+Tech Title:     XSTR("Fusion array (Medium)", -1)
+Tech Anim:     none
+Tech Description:
XSTR("The result of a series experiments with fighter-based beam weapons, the Fusion Array is a medium-powered fighter based direct line-of-sight weapon. The fusion-pumped laser beam connects nearly instantaneously, thus no leading of targets is required. The Fusion Array has an excellent damage rating, though it consumes significant amounts of weapon energy during sustained fire.", -1)
$end_multi_text
$Tech Model: Beammodel.pof
$Model File:                    none
@Laser Bitmap:                  laserglow01
@Laser Color: 220, 180, 30
@Laser Length: 0.0
@Laser Head Radius: 0.30
@Laser Tail Radius: 0.30
$Mass:                          0
$Velocity:                      4000
$Fire Wait:                      0.75
$Damage:                        8
$Damage Type:                    Energy
$Armor Factor:                  1.0
$Shield Factor:                  1.0
$Subsystem Factor:              1.0
$Lifetime:                      0.5           
$Energy Consumed:                5
$Cargo Size:                    0
$Homing:                        NO
$LaunchSnd:                      205           
$ImpactSnd:                      248             
+Weapon Range: 2000
$Flags:                          ( "beam" "player allowed" "no pierce shields" )
$Icon:                          wi_fusionarray
$Anim:                          wa_fusion
$Impact Explosion:              ExpMissileHit1
$Impact Explosion Radius:        8.0
$BeamInfo:
+Type: 0
+Life:   0.5
+Warmup:   100
+Warmdown: 0
+Radius:   1
+PCount: 0
+PRadius: 0
+PAngle: 0
+PAni: particle_yellow
+Miss Factor: 1 1 1 1 1
+BeamSound: 205
+WarmupSound: -1
+WarmdownSound: -1
+Muzzleglow: beamglow6
+Shots: 0
+ShrinkFactor: 0.2
+ShrinkPct: 0.3
+Range: 2000
+Attenuation: 0.96
$Section:
+Width: 0.1
+Texture: Beam-White2
+RGBA Inner: 255 255 255 255
+RGBA Outer: 150 150 150 10
+Flicker: 0.0
+Zadd: 2.0
$Section:
+Width: 0.3
+Texture: VasBeam2Core
+RGBA Inner: 250 160 50 255
+RGBA Outer: 250 160 50 10
+Flicker: 0.0
+Zadd: 1.0
$Section:
+Width: 0.5
+Texture: VasBeam2Glow
+RGBA Inner: 250 160 50 255
+RGBA Outer: 250 160 50 10
+Flicker: 0.1
+Zadd: 0.0

Workaround: can you disable primary linking on the beam weapon?
That's not a viable option here.
Title: Re: Issue with A.I. and fighter mounted beams
Post by: Nightmare on June 26, 2018, 11:24:45 pm
I'm sorry for my blasphemy :D

Just tested around with fighterbeams and noticed something: which hierarchy are you using? I tried a ship with ("Shivan Fighter Beam" "Shivan Mega Laser"). The only bank firing was the beam, with deadly precision. The other bank fired next to never (only when I was directly in front of the ship and did not move). Apparently only the first bank is used for target calculation. Secondary banks worked normal.
Title: Re: Issue with A.I. and fighter mounted beams
Post by: FrikgFeek on June 27, 2018, 01:09:48 pm
I know that the way $AI In Range Time: works is really weird and counter-intuitive(The AI will sometimes lock onto and fire missiles at targets beyond their maximum range for example), so maybe something's breaking there in regards to beam weapons or other weapons with very high $Velocity.

Have you tried lowering velocity(It only affects how hard you whack things anyway) and seeing if the AI underps itself? Does playing on a difficulty with $AI In Range time: of 1 or greater help at all?
Title: Re: Issue with A.I. and fighter mounted beams
Post by: Spoon on June 27, 2018, 01:48:45 pm
I'm sorry for my blasphemy :D

Just tested around with fighterbeams and noticed something: which hierarchy are you using? I tried a ship with ("Shivan Fighter Beam" "Shivan Mega Laser"). The only bank firing was the beam, with deadly precision. The other bank fired next to never (only when I was directly in front of the ship and did not move). Apparently only the first bank is used for target calculation. Secondary banks worked normal.
Yes, I know, the A.I. leads with the first bank it has. I don't think it really matters regarding this bug, as long as any of its bank has a weapon other than the beam weapon it'll behave. What bank the weapons are set in doesn't seem to change anything.


I know that the way $AI In Range Time: works is really weird and counter-intuitive(The AI will sometimes lock onto and fire missiles at targets beyond their maximum range for example), so maybe something's breaking there in regards to beam weapons or other weapons with very high $Velocity.

Have you tried lowering velocity(It only affects how hard you whack things anyway) and seeing if the AI underps itself? Does playing on a difficulty with $AI In Range time: of 1 or greater help at all?
Changing $AI In Range Time: to any number doesn't do anything for this bug.

Velocity does matter though, that's how the game calculates the lead indicator. So if you want a beam weapon to actually have an accurate lead indicator for a beam weapon, it needs to have a high velocity.
Title: Re: Issue with A.I. and fighter mounted beams
Post by: AdmiralRalwood on June 27, 2018, 03:05:53 pm
I know that the way $AI In Range Time: works is really weird and counter-intuitive(The AI will sometimes lock onto and fire missiles at targets beyond their maximum range for example)
"$AI In Range Time:" has literally no effect on missiles; it only modifies how well the AI predicts where to aim its primary weapons.
Title: Re: Issue with A.I. and fighter mounted beams
Post by: Axem on June 28, 2018, 04:03:52 am
Hey so after investigating this a bit, apparently the AI does not check lifetime or range of a primary before firing. Only weapon speed. (Which MageKing confirmed) (https://cdn.discordapp.com/attachments/334302925981745154/461727603330646016/Clipboard01.png)

FreeSpace. Never change. :cool:

(I think an AI Profile flag like $Actually Use Weapon Range For Primary Firing: would be awesome)
Title: Re: Issue with A.I. and fighter mounted beams
Post by: AdmiralRalwood on June 28, 2018, 06:17:14 am
I think an AI Profile flag like $Actually Use Weapon Range For Primary Firing: would be awesome
Shouldn't be too hard to implement, either; compute the "do I want to fire at this distance" range like it currently does, then use the min() of that or the weapon's actual range. I'll take a stab at it.

EDIT: And done (https://github.com/scp-fs2open/fs2open.github.com/pull/1767).
Title: Re: Issue with A.I. and fighter mounted beams
Post by: Spoon on June 28, 2018, 01:19:44 pm
Yayifications