Author Topic: Weapon range and AI?  (Read 2898 times)

0 Members and 1 Guest are viewing this topic.

Weapon range and AI?
Having some difficulty getting the AI to shoot at the proper range(s) to target.
Now I know that weapon range should be velocity x lifetime - however I have a situation where the AI is still trying to fire at a target well out of range of it's weapon (this problem seems exasperated when increasing the velocity of the weapon/lowering the lifetime). So this makes me think I am forgetting something or there is another variable at work here I am not seeing. Is there anything in the AI tables that effects this?

What I am trying to accomplish is a weapon with a range of 750m and with a velocity of 1500. (faster and closer even if possible)
I have set the lifetime at 0.5 and the velocity of 1500 (even set +weapon range at 750) - but the AI will attempt to fire it's weapon at the target anyway well past 750m even as the weapons 'life' ends before getting to the target.

Any advice/help with this would be greatly appreciated.
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: Weapon range and AI?
http://www.hard-light.net/wiki/index.php/Weapons.tbl#.2BWeapon_Range:

Has always worked for me.
Even with 0-lifetime weapons (dummies to trigger other things).
They will start fire a bit outside the range, but usually not too much?
(´・ω・`)
=============================================================

 
Re: Weapon range and AI?
Check this flag http://www.hard-light.net/wiki/index.php/Ai_profiles.tbl#.24AI_In_Range_Time:

The AI will try to predict when they'll be in range and start firing according to that flag(if it's set under 0 like it is by default).
[19:31] <MatthTheGeek> you all high up on your mointain looking down at everyone who doesn't beam everything on insane blindfolded

 
Re: Weapon range and AI?
I set the velocity at 1300, the lifetime of .5 (which should give me a range of 650m) and changed the weapon range line to 650 as well. Made sure all the AI in Range Time are set to 0 (for my current difficulty it was already though)
And I retried my test mission.
I have 2 AI ships (hostile to one another) one pointed right at the other - they both have engines disabled so they cannot move. I have positioned them at 765.5m apart.
The AI ship pointed at the other one immediately begins firing frantically as soon as the mission starts - even though it's target is over 100m farther than the supposed weapon's range.
It's shots of course fall short of the target and the target is never hit - but the ai ship continuously fires at it.
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: Weapon range and AI?
What if increase the AI in-range time to a non-zero number (so as to delay it x seconds after they get in range and not before?)
(´・ω・`)
=============================================================

 
Re: Weapon range and AI?
What if increase the AI in-range time to a non-zero number (so as to delay it x seconds after they get in range and not before?)

I suppose that would sort of work as a semi-work-around but wouldn't really fix things as ships may going different speeds all the time.
After further experimentation with this I can't make heads or tails of the current situation - I have a weapon with a velocity of 2000 and a lifetime of 0.325 (and +weapon range set to 650) - which should give me an effective range of 650m, compensated for the length of the laser (30) the max effective range should be 680. However a ship is able to fire at AND hit a ship past 700m.
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod

 
Re: Weapon range and AI?
Well, yes, the projectile is traveling 33.333... units per frame. So 0.325s is 19.5 frames assuming capped 60 fps meaning the projectile will travel 20 frames before fizzling out on the 21st. That's 666.6666... units travelled plus the length of the laser.
[19:31] <MatthTheGeek> you all high up on your mointain looking down at everyone who doesn't beam everything on insane blindfolded

 
Re: Weapon range and AI?
Well, yes, the projectile is traveling 33.333... units per frame. So 0.325s is 19.5 frames assuming capped 60 fps meaning the projectile will travel 20 frames before fizzling out on the 21st. That's 666.6666... units travelled plus the length of the laser.

I am sorry I am not sure I understand what you mean.
If I do understand you correctly (and honestly I am not sure I do) then the max effective range of the weapon should be 666.66 + 30 (length of laser) = 696.66. But the ship is being hit past that.
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Weapon range and AI?
Are you also accounting for the size of the ship?
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 
Re: Weapon range and AI?
Are you also accounting for the size of the ship?

Yup I considered that as well - the ship its firing at has a depth of around 7 and the ship firing has a depth of 12.
Set the distance of target ship to 721m which is more than I should have to (696+19=715), takes a bit but the ship eventually gets hit and destroyed.
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod

 

Offline DahBlount

  • 29
  • Alpine ☆ Cancer Tribulation
    • Minecraft
    • Skype
    • Steam
There is a bit of relevant code at line 8767 in aicode.cpp and based on the code, it looks like the distance it checks against before having the ai fire a primary weapon is generally going to be greater than the range the weapon should go given its lifetime and velocity.
<Axem> yet still more insightful than #hard-light

<Axem> jad2.23 will just be cat videos

<DahBlount> So
<DahBlount> JAD2.2 is like that
<Axem> maybe
<Axem> it can be whatever you like!
<DahBlount> A Chocolate Sundae?
<Axem> sure

My models: GTF Gilgamesh - GTD Nuadha [Redesigning] - Ningirama [WIP] - GTG Zephyrus

 
There is a bit of relevant code at line 8767 in aicode.cpp and based on the code, it looks like the distance it checks against before having the ai fire a primary weapon is generally going to be greater than the range the weapon should go given its lifetime and velocity.

Just took a look at that - unfortunately my knowledge of programming is limited and can't really make a whole lot of sense of what I am looking at -- anyway you can help translate the relevant portion for me DahBlount because it looks like you might have hit upon something here - but I am not sure what some of the variables correspond to ('pwip', 'scale' the '->' symbol)

I think this was the portion of the code you where talking about -

               scale = pwip->max_speed/(En_objp->phys_info.speed + pwip->max_speed);
               if (scale > 0.6f)
                  scale = (scale - 0.6f) * 1.5f;
               else
                  scale = 0.0f;
               if (dist_to_enemy < pwip->max_speed * (1.0f + scale)) {
                  if(ai_fire_primary_weapon(Pl_objp) == 1){
                     has_fired = 1;
                  }else{
                     has_fired = -1;
                  }
               }
            }

 
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Okay, so basically it's making a scale value based on the speed on the weapon compared to the speed of the target; the general idea is to make the AI less likely to fire if the enemy is far away and moving fast relative to the speed of the weapon it would be trying to shoot at it with. Confusingly, this means that the weapon's actual range is completely ignored for primary weapons (unless it's a ballistic primary and "$Primary Ammo Burst Multiplier:" is greater than 0, in which case the range affects the burst probability); while secondary weapons use weapon range to determine if it should fire at all, primary weapons use the above-quoted speed-versus-distance check instead of checking the weapon's range.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 
Okay, so basically it's making a scale value based on the speed on the weapon compared to the speed of the target; the general idea is to make the AI less likely to fire if the enemy is far away and moving fast relative to the speed of the weapon it would be trying to shoot at it with. Confusingly, this means that the weapon's actual range is completely ignored for primary weapons (unless it's a ballistic primary and "$Primary Ammo Burst Multiplier:" is greater than 0, in which case the range affects the burst probability); while secondary weapons use weapon range to determine if it should fire at all, primary weapons use the above-quoted speed-versus-distance check instead of checking the weapon's range.

So unfortunately I am guessing there is no real solution to my problem other than changing the code above and re-compiling the source code?
What do the variables 'pwip' and 'scale' represent in the above code?
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
"scale" is the scaling factor I just mentioned; "pwip" is a pointer to the weapon info for the primary weapon the code is evaluating (the "->" operator retrieves an attribute of the object a pointer points to, so "pwip->max_speed" is the velocity of the primary weapon and "En_objp->phys_info.speed" is the current speed of the AI's current target).

And no, there's no way to fix this without changing the source; on the plus side, there are probably lots of other modders that could use weapon range checks with primary weapons, so it's less unlikely to make it into the source than any arbitrary feature request.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 
"scale" is the scaling factor I just mentioned; "pwip" is a pointer to the weapon info for the primary weapon the code is evaluating (the "->" operator retrieves an attribute of the object a pointer points to, so "pwip->max_speed" is the velocity of the primary weapon and "En_objp->phys_info.speed" is the current speed of the AI's current target).

And no, there's no way to fix this without changing the source; on the plus side, there are probably lots of other modders that could use weapon range checks with primary weapons, so it's less unlikely to make it into the source than any arbitrary feature request.

Thanks very much for this info AdmiralRalwood as well as everyone else - looks like I need to do some brushing up on C++. At least I have somewhat of a place to start from now - albeit only a partial understanding of that starting place.
It is good to know there is a chance (even if slim) of this making it into the code eventually as this is something that has annoyed me for a long time with many modding attempts - especially if i can't figure it out by myself by fumbling around with it.
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
... while secondary weapons use weapon range to determine if it should fire at all...

That explains why I haven't had problems with that - i was testing using secondaries.
(´・ω・`)
=============================================================

 
... while secondary weapons use weapon range to determine if it should fire at all...

That explains why I haven't had problems with that - i was testing using secondaries.

Yeah secondaries behave themselves - but thanks for the suggestions anyhow Droid803!
The Irresponsible Captain Nathan
http://steamcommunity.com/id/IrresponsibleCaptNathan/
Team Leader - Star Wars Original Trilogy Mod
http://www.moddb.com/mods/star-wars-the-original-trilogy-mod