Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Droid803 on August 06, 2011, 10:26:23 pm

Title: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on August 06, 2011, 10:26:23 pm
"Gun convergence" disables autoaim.
That's kinda dumb.
I would expect autoaim to override gun convergence, and have it only occur in absence of a target.

That, and using "gun convergence" for off-axis secondary banks ruins primary bank autoaim which sux.

Any chance of a fix, or is this intended behavior?
Also, would it be possible for secondary banks to obey their normal without requiring "gun convergence"? :/
Title: Re: Autoaim vs "gun convergence"
Post by: Nuke on August 07, 2011, 04:22:56 am
way i see it if you can have convergence you have all the mechanical workings for autoaim anyway, so therefore i think autoaim should supersede convergence. just my opinion. of course i never liked the implementation of autoaim. i think it should include a delta value to control lockon speed. mechanical systems are far from instantaneous, and there should be some time lag for the guns to actuate onto the target. say it takes half a second for the gun to rotate 30 degrees, shots should arc over to that over time. but im currently drunk so what do i know.
Title: Re: Autoaim vs "gun convergence"
Post by: chief1983 on August 07, 2011, 02:36:53 pm
Lockon delay is still an anticipated feature, actually.  I'd like ships in FotG to eventually have variable lock on delays based on targeting computer strength, as another way to differentiate the craft.  The delay isn't probably the worst part, I was trying to figure out a way to present it to the user.  Can't really use the secondary lock mechanism because then you'd have two different reticules trying to lock on to the ship.  My other thought was using the scan line system to show a lock in the target cam box somehow, or some sort of indicator by the primary weapon list.

The actual mechanical display you refer too really only works if the guns are actually relying on a mechanical targeting system (in Star Wars it's more about electrical voodoo focusing shots different leaving the barrel, so it can be instantaneous), but even a non-mechanical firepoint adjustment could probably get closer to the target as the computer tracks for a lock.
Title: Re: Autoaim vs "gun convergence"
Post by: Dragon on August 07, 2011, 03:05:56 pm
Could be 2 vertical lines moving onto the middle of the target (in target view), with something (for example 4 triangles pointing to it) appearing when locked?
IMHO, this would look rather SW-ish.
Title: Re: Autoaim vs "gun convergence"
Post by: Nuke on August 08, 2011, 12:41:21 am
Lockon delay is still an anticipated feature, actually.  I'd like ships in FotG to eventually have variable lock on delays based on targeting computer strength, as another way to differentiate the craft.  The delay isn't probably the worst part, I was trying to figure out a way to present it to the user.  Can't really use the secondary lock mechanism because then you'd have two different reticules trying to lock on to the ship.  My other thought was using the scan line system to show a lock in the target cam box somehow, or some sort of indicator by the primary weapon list.

The actual mechanical display you refer too really only works if the guns are actually relying on a mechanical targeting system (in Star Wars it's more about electrical voodoo focusing shots different leaving the barrel, so it can be instantaneous), but even a non-mechanical firepoint adjustment could probably get closer to the target as the computer tracks for a lock.

i dont necessarily want a delay where you cant fire until it locks on, that reduces the probability of pilot error. i like to give the pilot a chance to waste energy or ammo by being impatient. if i were to pick a game to emulate it would be starlancer. if the gun is not locked on you are still allowed to fire, it will just not be on target. essentially it acts like a turret. when not locked on to anything it is kept at or returned to center. this is the gun normal or 0'0'1 if normal is not used. when you lock on to a target or a subsystem, and the target is in the guns field of view, then the gun will rotate from its current position onto the target at the appropriate rate. rate would just be a float, probibluy representing time it takes to go from center to its max angle. then 0 would be instantaneous. perhaps negatives could be used if you want the gun to lockout the fire command if the gun is not on target, so you could get all desired behaviors in that way, while only adding one additional value to the table.

displaying the current position of the gun could just be as simple as drawing a second reticle indicating the current direction of fire. from the huds point of view optimal firing angle is when the reticle and the lead indicator are in alignment. it is technically not a lock because the tracking rate is limited. if the target is moving faster than the guns ability to track then the ship can escape the gun.
Title: Re: Autoaim vs "gun convergence"
Post by: chief1983 on August 08, 2011, 01:47:45 am
I was never planning on preventing firing, just using a default convergence until auto-aim lock is achieved.  I also want to be a be able to allow disabling auto-aim, and switching to fixed convergence or convergence directly ahead at the target's range.
Title: Re: Autoaim vs "gun convergence"
Post by: Nuke on August 08, 2011, 07:06:19 am
i still think auto aim should not be a lock on kinda behavior because that would make it too similar to missile behavior. guns should try their best to follow the target's lead. instead of firing straight for a time, and then snap to target once it has been in the field of view long enough, it should be an animated progression from default position to target position, and shots fired during that progression would draw closer to the target as aim becomes more accurate.

autoaim guns should always try to converge, probibly at max weapon range if no target is selected (different linked banks would coverge at a distance based on maximum range for that weapon), target range if one is, and only tracking when target is within the guns field of view. guns that only converge but dont track would have 2 types. static gun convergence where convergence range is set at mission start based on the weapon's maximum range, but cannot change in game, as if the guns were adjusted in preflight ops. you could also have dynamic convergence, where convergence is adjusted based on target range.

so it would go in order static convergence->dynamic convergence->full autoaim bot, where each one has all the features of the previous mode. idea is guns manually adjusted before launch->1 axis (axis being paralell to the cross of the gun direction and the gun position) actuator converges guns->2 axis gimbal aims guns, each one being a more complex system that can do everything of the previous system and more. when you get a starwarsish voodoo insta snap weapons, meh, just set your lock time to zero. but dont make the system universe centric, make it moddable to any configuration possible with the least amount of data to edit.
Title: Re: Autoaim vs "gun convergence"
Post by: chief1983 on August 08, 2011, 09:57:21 am
A behavior like you described could also be nice, but there are very clear portrayals of primary weapon locking in the Star Wars movies, so it is something FotG would like to be able to replicate if possible.  And you're right, a configurable system could probably provide all the features we're both looking for, I'm not asking it to be set up any particular way and only that way.

User-controlled ability to disable this is probably a necessity for multiplayer, when you have fast ships, because it's almost certainly going to keep you from being able to compensate for lag.
Title: Re: Autoaim vs "gun convergence"
Post by: Nuke on August 08, 2011, 03:30:44 pm
yea some people may just want tot urn off the whole thing if its doing something they dont like. so maybe a key to cycle convergence/autoaim modes? of which there would probably be 4, no convergence, max range convergence, target distance convergence, and full aimbot. of course if your ship/weapon does not support one of those modes, it would be omitted from the list.
Title: Re: Autoaim vs "gun convergence"
Post by: Droid803 on August 08, 2011, 09:07:13 pm
I would be very happy if any of this is implemented :)
Title: Re: Autoaim vs "gun convergence"
Post by: chief1983 on August 09, 2011, 12:56:40 am
So would I, as it's on the FotG request list still :)
Title: Re: Autoaim vs "gun convergence"
Post by: Droid803 on September 18, 2011, 02:28:19 am
BABUMP

No awesome new features, but at least i got priorities sorted out.

OLD BEHAVIOR
'gun convergence' disables autoaim/autoconvergence/table-defined fixed convergence. always use gunpoint normal for primaries.
use gunpoint normal for secondaries.

NEW BEHAVIOR
with 'gun convergence' activated, autoaim/autoconverge is active as long as target is in autoaim FOV, otherwise, follow gunpoint normal.
table defined convergence overrides pof-based 'gun convergence' for primaries.
use gunpoint normal for secondaries.



I feel the second behavior is closer to what one would want (seeing as if you go out of the way to define table-based convergence/autoaim for primaries, you probably want them to actually work eh?). You can always have your regular gun convergence simply by *not defining* any of the table based convergence options and leaving "gun convergence".

Also, it is now it is possible to have autoaim and off-axis secondaries, which was previously impossible. This was the primary motivation for me to create this patch.

It's a bit messy looking since I had to remove an entire conditional level and clear a bunch of indentations. (manually, oops)

I've tested the following scenarios
Autoaim Active with "gun convergence", target in FOV -> AUTOAIM behavior (tracking)
Autoaim Active with "gun convergence", target out of FOV -> firepoint normal
Autoaim Active no "gun convergence", target in FOV -> AUTOAIM behavior (tracking)
Autoaim Active no "gun convergence", target out of FOV -> straight forward

Secondaries with "gun convergence" -> firepoint normal
Secondaries no "gun convergence" -> straight forward

Thus I presume it should work with everything else :P
Though do test if you doubt me~



Code: [Select]
Index: ship.cpp
===================================================================
--- ship.cpp (revision 7759)
+++ ship.cpp (working copy)
@@ -1,4 +1,4 @@
-
+
 /*
  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
  *
@@ -9756,123 +9756,68 @@
  vm_vec_add(&firing_pos, &gun_point, &obj->pos);
 
  matrix firing_orient;
- if (!(sip->flags2 & SIF2_GUN_CONVERGENCE))
+
+ if ((sip->aiming_flags & AIM_FLAG_AUTOAIM) &&
+ aip->target_objnum != -1)
  {
- if ((sip->aiming_flags & AIM_FLAG_AUTOAIM) &&
- aip->target_objnum != -1)
+ // Fire weapon in target direction
+ vec3d target_position, target_velocity_vec, predicted_target_pos;
+ vec3d firing_vec, last_delta_vec, player_forward_vec, plr_to_target_vec;
+ float dist_to_target, time_to_target, angle_to_target;
+
+ // If a subsystem is targeted, fire in that direction instead
+ if (aip->targeted_subsys != NULL)
  {
- // Fire weapon in target direction
- vec3d target_position, target_velocity_vec, predicted_target_pos;
- vec3d firing_vec, last_delta_vec, player_forward_vec, plr_to_target_vec;
- float dist_to_target, time_to_target, angle_to_target;
+ get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
+ }
+ else
+ {
+ target_position = Objects[aip->target_objnum].pos;
+ }
 
- // If a subsystem is targeted, fire in that direction instead
- if (aip->targeted_subsys != NULL)
- {
- get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
- }
- else
- {
- target_position = Objects[aip->target_objnum].pos;
- }
+ target_velocity_vec = Objects[aip->target_objnum].phys_info.vel;
+ if (The_mission.ai_profile->flags & AIPF_USE_ADDITIVE_WEAPON_VELOCITY)
+ vm_vec_sub2(&target_velocity_vec, &obj->phys_info.vel);
 
- target_velocity_vec = Objects[aip->target_objnum].phys_info.vel;
- if (The_mission.ai_profile->flags & AIPF_USE_ADDITIVE_WEAPON_VELOCITY)
- vm_vec_sub2(&target_velocity_vec, &obj->phys_info.vel);
+ dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
+ time_to_target = 0.0f;
 
- dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
- time_to_target = 0.0f;
+ if (winfo_p->max_speed != 0)
+ {
+ time_to_target = dist_to_target / winfo_p->max_speed;
+ }
 
- if (winfo_p->max_speed != 0)
- {
- time_to_target = dist_to_target / winfo_p->max_speed;
- }
+ vm_vec_scale_add(&predicted_target_pos, &target_position, &target_velocity_vec, time_to_target);
+ polish_predicted_target_pos(winfo_p, &Objects[aip->target_objnum], &target_position, &predicted_target_pos, dist_to_target, &last_delta_vec, 1);
+ vm_vec_sub(&plr_to_target_vec, &predicted_target_pos, &obj->pos);
 
- vm_vec_scale_add(&predicted_target_pos, &target_position, &target_velocity_vec, time_to_target);
- polish_predicted_target_pos(winfo_p, &Objects[aip->target_objnum], &target_position, &predicted_target_pos, dist_to_target, &last_delta_vec, 1);
- vm_vec_sub(&plr_to_target_vec, &predicted_target_pos, &obj->pos);
-
- // minimum convergence distance
- if (sip->minimum_convergence_distance > dist_to_target) {
- float dist_mult;
- dist_mult = sip->minimum_convergence_distance / dist_to_target;
- vm_vec_scale_add(&predicted_target_pos, &obj->pos, &plr_to_target_vec, dist_mult);
- }
+ // minimum convergence distance
+ if (sip->minimum_convergence_distance > dist_to_target) {
+ float dist_mult;
+ dist_mult = sip->minimum_convergence_distance / dist_to_target;
+ vm_vec_scale_add(&predicted_target_pos, &obj->pos, &plr_to_target_vec, dist_mult);
+ }
 
- // setting to autoaim to converge on to the target.
- if (sip->aiming_flags & AIM_FLAG_AUTOAIM_CONVERGENCE)
- vm_vec_sub(&firing_vec, &predicted_target_pos, &firing_pos);
- else
- vm_vec_sub(&firing_vec, &predicted_target_pos, &obj->pos);
+ // setting to autoaim to converge on to the target.
+ if (sip->aiming_flags & AIM_FLAG_AUTOAIM_CONVERGENCE)
+ vm_vec_sub(&firing_vec, &predicted_target_pos, &firing_pos);
+ else
+ vm_vec_sub(&firing_vec, &predicted_target_pos, &obj->pos);
 
 
- // Deactivate autoaiming if the target leaves the autoaim-FOV cone
- player_forward_vec = obj->orient.vec.fvec;
- angle_to_target = vm_vec_delta_ang(&player_forward_vec, &plr_to_target_vec, NULL);
+ // Deactivate autoaiming if the target leaves the autoaim-FOV cone
+ player_forward_vec = obj->orient.vec.fvec;
 
- if (angle_to_target < sip->autoaim_fov)
- {
- vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
- }
- else
- {
- firing_orient = obj->orient;
- }
- }
- else if ((sip->aiming_flags & AIM_FLAG_AUTO_CONVERGENCE) && (aip->target_objnum != -1))
+ angle_to_target = vm_vec_delta_ang(&player_forward_vec, &plr_to_target_vec, NULL);
+
+ if (angle_to_target < sip->autoaim_fov)
  {
- //Write automatic convergence code here!
- //If set, switch to manual if automatic fails
- //better idea.. mix it with the above... assume autoaim takes precedence
-
- // Fire weapon in target direction
- vec3d target_position, target_vec;
- vec3d firing_vec, player_forward_vec, convergence_offset;
- float dist_to_target;
-
- // If a subsystem is targeted, fire in that direction instead
- if (aip->targeted_subsys != NULL)
- {
- get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
- }
- else
- {
- target_position = Objects[aip->target_objnum].pos;
- }
-
- dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
-
- if (sip->minimum_convergence_distance > dist_to_target)
- dist_to_target = sip->minimum_convergence_distance;
-
- player_forward_vec = obj->orient.vec.fvec;
- // make sure vector is of the set length
- vm_vec_copy_normalize(&target_vec, &player_forward_vec);
- vm_vec_scale(&target_vec, dist_to_target);
- // if there is convergence offset then make use of it)
- vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
- vm_vec_add2(&target_vec, &convergence_offset);
- vm_vec_add2(&target_vec, &obj->pos);
- vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
-
- // set orientation
  vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
-
  }
- else if (sip->aiming_flags & AIM_FLAG_STD_CONVERGENCE)
+ else if (sip->flags2 & SIF2_GUN_CONVERGENCE)
  {
- vec3d player_forward_vec, target_vec, firing_vec, convergence_offset;
- player_forward_vec = obj->orient.vec.fvec;
- // make sure vector is of the set length
- vm_vec_copy_normalize(&target_vec, &player_forward_vec);
- vm_vec_scale(&target_vec, sip->convergence_distance);
- // if there is convergence offset then make use of it)
- vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
- vm_vec_add2(&target_vec, &convergence_offset);
- vm_vec_add2(&target_vec, &obj->pos);
- vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
-
- // set orientation
+ vec3d firing_vec;
+ vm_vec_unrotate(&firing_vec, &pm->gun_banks[bank_to_fire].norm[pt], &obj->orient);
  vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
  }
  else
@@ -9880,12 +9825,73 @@
  firing_orient = obj->orient;
  }
  }
- else
+ else if ((sip->aiming_flags & AIM_FLAG_AUTO_CONVERGENCE) && (aip->target_objnum != -1))
  {
+ //Write automatic convergence code here!
+ //If set, switch to manual if automatic fails
+ //better idea.. mix it with the above... assume autoaim takes precedence
+
+ // Fire weapon in target direction
+ vec3d target_position, target_vec;
+ vec3d firing_vec, player_forward_vec, convergence_offset;
+ float dist_to_target;
+
+ // If a subsystem is targeted, fire in that direction instead
+ if (aip->targeted_subsys != NULL)
+ {
+ get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
+ }
+ else
+ {
+ target_position = Objects[aip->target_objnum].pos;
+ }
+
+ dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
+
+ if (sip->minimum_convergence_distance > dist_to_target)
+ dist_to_target = sip->minimum_convergence_distance;
+
+ player_forward_vec = obj->orient.vec.fvec;
+ // make sure vector is of the set length
+ vm_vec_copy_normalize(&target_vec, &player_forward_vec);
+ vm_vec_scale(&target_vec, dist_to_target);
+ // if there is convergence offset then make use of it)
+ vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
+ vm_vec_add2(&target_vec, &convergence_offset);
+ vm_vec_add2(&target_vec, &obj->pos);
+ vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
+
+ // set orientation
+ vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+
+ }
+ else if (sip->aiming_flags & AIM_FLAG_STD_CONVERGENCE)
+ {
+ vec3d player_forward_vec, target_vec, firing_vec, convergence_offset;
+ player_forward_vec = obj->orient.vec.fvec;
+ // make sure vector is of the set length
+ vm_vec_copy_normalize(&target_vec, &player_forward_vec);
+ vm_vec_scale(&target_vec, sip->convergence_distance);
+ // if there is convergence offset then make use of it)
+ vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
+ vm_vec_add2(&target_vec, &convergence_offset);
+ vm_vec_add2(&target_vec, &obj->pos);
+ vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
+
+ // set orientation
+ vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+ }
+ else if (sip->flags2 & SIF2_GUN_CONVERGENCE)
+ {
  vec3d firing_vec;
  vm_vec_unrotate(&firing_vec, &pm->gun_banks[bank_to_fire].norm[pt], &obj->orient);
  vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
  }
+ else
+ {
+ firing_orient = obj->orient;
+ }
+
  // create the weapon -- the network signature for multiplayer is created inside
  // of weapon_create
 

[attachment deleted by ninja]
Title: Re: Autoaim vs "gun convergence"
Post by: chief1983 on September 18, 2011, 02:49:05 am
From your description, that does sound like it's what FotG would want, although I probably want to play it just to make sure it doesn't break anything for us.
Title: Re: Autoaim vs "gun convergence"
Post by: Droid803 on September 20, 2011, 11:08:59 pm
Bubump.
I want this in trunk.
I don't want to keep basing my code off like two different patches >.> this, and nuke's armor.tbl upgrades, but they both fix issues critical to a number of missions I have >.>

Damage scaling before cutoff made things too easy on not-insane.
No autoaim with off axis missiles makes things too hard not-very-easy (you try hitting a 8m ship flying at 400m/s circle strafing you unassisted :/)

A Test Build: http://dl.dropbox.com/u/126554/FS2/fs2_open_3_6_13r_INF_SSE2.exe
Title: Re: Autoaim vs "gun convergence"
Post by: Alan Bolte on September 21, 2011, 03:09:36 am
Can't really use the secondary lock mechanism because then you'd have two different reticules trying to lock on to the ship.  My other thought was using the scan line system to show a lock in the target cam box somehow, or some sort of indicator by the primary weapon list.
You could also just copy x-wing and change the color or intensity of the boresight reticule. Alternately, take a feature from the modern FPS world and use variable-separation crosshairs.

(Yes, I know I'm replying to a month-old post)
Title: Re: Autoaim vs "gun convergence"
Post by: zookeeper on September 29, 2011, 04:50:52 pm
BABUMP

No awesome new features, but at least i got priorities sorted out.

OLD BEHAVIOR
'gun convergence' disables autoaim/autoconvergence/table-defined fixed convergence. always use gunpoint normal for primaries.
use gunpoint normal for secondaries.

NEW BEHAVIOR
with 'gun convergence' activated, autoaim/autoconverge is active as long as target is in autoaim FOV, otherwise, follow gunpoint normal.
table defined convergence overrides pof-based 'gun convergence' for primaries.
use gunpoint normal for secondaries.



I feel the second behavior is closer to what one would want (seeing as if you go out of the way to define table-based convergence/autoaim for primaries, you probably want them to actually work eh?). You can always have your regular gun convergence simply by *not defining* any of the table based convergence options and leaving "gun convergence".

Doesn't this mean that now autoaim settings would simply disable convergence settings, instead of converge settings disabling autoaim settings? Here's a flowchart of sorts of how I think they should work and which should satisfy everyone.

Frankly, I think autoaim and gun convergence should be two completely separate settings. Autoaim should control only the direction of fire, and convergence should control convergence, and neither should affect the other.

EDIT: Nevermind the inconsistent use of arrows and that I forgot one "No" bubble.

[attachment deleted by ninja]
Title: Re: Autoaim vs "gun convergence"
Post by: Droid803 on September 29, 2011, 11:27:28 pm
The flowchart is what it should be doing.

I just removed the check that disables all autoaim/autoconverge if the "gun convergence" flag is used, and told it to use gunpoint normals only if no other convergence/autoaim is currently active (ie, nothing tracking), and then shoot straight forwards otherwise.

Firepoint normal gun convergence still works with converging autoaim tabled as long as target is not in autoaim FoV. As soon as the target enters autoaim FoV, all the gunpoints will start "tracking" it. :)

I tested it with a POF that has primary points at 90 degrees from forward, so it was pretty obvious what was happening XD
Title: Re: Autoaim vs "gun convergence"
Post by: Nuke on September 30, 2011, 09:16:10 am
i really dont see why you wouldn't want convergence with autoaim. if each gun is on its own gimbal then each gun would be able to track any point in space, and to intentionally making the shots maintain their spread doesn't make a lot of sense, unless of course you were independently targeting individual subsystems with each of your guns. i could understand any other scenario but that one.

also curious if your patch allows for tracking rate or if its still insti-snaps.
Title: Re: Autoaim vs "gun convergence"
Post by: chief1983 on September 30, 2011, 10:18:39 am
But if the ship jukes just enough, you would miss all 4 shots.  If you fire them parallel, and your ship has a naturally wide coverage, you end up with good coverage at the target distance.  Maybe all won't hit, but one might be likely to.  It would probably come down to ship design and could affect pilot preference for one ship or another if you mix it up, or even find a way to make it selectable.
Title: Re: Autoaim vs "gun convergence"
Post by: CaptJosh on October 05, 2011, 10:13:28 pm
Perhaps a method for primary fire lock-on that can be enabled or disabled to enable or disable convergence/auto-aim? Just a random idea.
Title: Re: Autoaim vs "gun convergence"
Post by: chief1983 on October 05, 2011, 11:53:31 pm
It's already in FotG's requests, as it will probably be necessary to disable auto-aim in multiplayer in order to compensate for lag.
Title: Re: Autoaim vs "gun convergence"
Post by: Nuke on October 06, 2011, 02:22:02 am
another idea, it would be kinda cool to gimbal the weapon models to show what direction the guns are pointing, for some added animation eye candy.
Title: Re: Autoaim vs "gun convergence"
Post by: Thaeris on October 07, 2011, 01:24:06 pm
Or, if the fates smile kindly upon us...

Someone will fix the terribad netcode. Please, someone remind QD that it genuiney blows.
Title: Re: Autoaim vs "gun convergence"
Post by: The E on October 07, 2011, 01:34:10 pm
Or, if the fates smile kindly upon us...

Someone will fix the terribad netcode. Please, someone remind QD that it genuiney blows.

And you felt the need to hijack this thread why, exactly?

Just to be clear, this is not a general "Things we'd like to have thread", nor has it degenerated into one. Nuke's request, while slightly offtopic, is still related to the matter initially discussed, the netcode definitely isn't.
Title: Re: Autoaim vs "gun convergence"
Post by: Droid803 on October 07, 2011, 05:14:59 pm
Could I at least get my patch in trunk (which corrects existing behavior)? D:
Title: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on October 29, 2011, 01:19:58 am
Doublebump...
Been using this for ages on my own custom builds.

I'm pretty sure it works fine.
Could it please replace the existing (broken) handling? PLEASE?

I don't want to apply 5+ patches to each new build I make because the bugfixes I need to actually test the mod I'm working on properly on a new build. :(

BABUMP

No awesome new features, but at least i got priorities sorted out.

OLD BEHAVIOR
'gun convergence' disables autoaim/autoconvergence/table-defined fixed convergence. always use gunpoint normal for primaries.
use gunpoint normal for secondaries.

NEW BEHAVIOR
with 'gun convergence' activated, autoaim/autoconverge is active as long as target is in autoaim FOV, otherwise, follow gunpoint normal.
table defined convergence overrides pof-based 'gun convergence' for primaries.
use gunpoint normal for secondaries.



I feel the second behavior is closer to what one would want (seeing as if you go out of the way to define table-based convergence/autoaim for primaries, you probably want them to actually work eh?). You can always have your regular gun convergence simply by *not defining* any of the table based convergence options and leaving "gun convergence".

Also, it is now it is possible to have autoaim and off-axis secondaries, which was previously impossible. This was the primary motivation for me to create this patch.

It's a bit messy looking since I had to remove an entire conditional level and clear a bunch of indentations. (manually, oops)

I've tested the following scenarios
Autoaim Active with "gun convergence", target in FOV -> AUTOAIM behavior (tracking)
Autoaim Active with "gun convergence", target out of FOV -> firepoint normal
Autoaim Active no "gun convergence", target in FOV -> AUTOAIM behavior (tracking)
Autoaim Active no "gun convergence", target out of FOV -> straight forward

Secondaries with "gun convergence" -> firepoint normal
Secondaries no "gun convergence" -> straight forward

Thus I presume it should work with everything else :P
Though do test if you doubt me~



Code: [Select]
Index: ship.cpp
===================================================================
--- ship.cpp (revision 7759)
+++ ship.cpp (working copy)
@@ -1,4 +1,4 @@
-
+
 /*
  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
  *
@@ -9756,123 +9756,68 @@
  vm_vec_add(&firing_pos, &gun_point, &obj->pos);
 
  matrix firing_orient;
- if (!(sip->flags2 & SIF2_GUN_CONVERGENCE))
+
+ if ((sip->aiming_flags & AIM_FLAG_AUTOAIM) &&
+ aip->target_objnum != -1)
  {
- if ((sip->aiming_flags & AIM_FLAG_AUTOAIM) &&
- aip->target_objnum != -1)
+ // Fire weapon in target direction
+ vec3d target_position, target_velocity_vec, predicted_target_pos;
+ vec3d firing_vec, last_delta_vec, player_forward_vec, plr_to_target_vec;
+ float dist_to_target, time_to_target, angle_to_target;
+
+ // If a subsystem is targeted, fire in that direction instead
+ if (aip->targeted_subsys != NULL)
  {
- // Fire weapon in target direction
- vec3d target_position, target_velocity_vec, predicted_target_pos;
- vec3d firing_vec, last_delta_vec, player_forward_vec, plr_to_target_vec;
- float dist_to_target, time_to_target, angle_to_target;
+ get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
+ }
+ else
+ {
+ target_position = Objects[aip->target_objnum].pos;
+ }
 
- // If a subsystem is targeted, fire in that direction instead
- if (aip->targeted_subsys != NULL)
- {
- get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
- }
- else
- {
- target_position = Objects[aip->target_objnum].pos;
- }
+ target_velocity_vec = Objects[aip->target_objnum].phys_info.vel;
+ if (The_mission.ai_profile->flags & AIPF_USE_ADDITIVE_WEAPON_VELOCITY)
+ vm_vec_sub2(&target_velocity_vec, &obj->phys_info.vel);
 
- target_velocity_vec = Objects[aip->target_objnum].phys_info.vel;
- if (The_mission.ai_profile->flags & AIPF_USE_ADDITIVE_WEAPON_VELOCITY)
- vm_vec_sub2(&target_velocity_vec, &obj->phys_info.vel);
+ dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
+ time_to_target = 0.0f;
 
- dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
- time_to_target = 0.0f;
+ if (winfo_p->max_speed != 0)
+ {
+ time_to_target = dist_to_target / winfo_p->max_speed;
+ }
 
- if (winfo_p->max_speed != 0)
- {
- time_to_target = dist_to_target / winfo_p->max_speed;
- }
+ vm_vec_scale_add(&predicted_target_pos, &target_position, &target_velocity_vec, time_to_target);
+ polish_predicted_target_pos(winfo_p, &Objects[aip->target_objnum], &target_position, &predicted_target_pos, dist_to_target, &last_delta_vec, 1);
+ vm_vec_sub(&plr_to_target_vec, &predicted_target_pos, &obj->pos);
 
- vm_vec_scale_add(&predicted_target_pos, &target_position, &target_velocity_vec, time_to_target);
- polish_predicted_target_pos(winfo_p, &Objects[aip->target_objnum], &target_position, &predicted_target_pos, dist_to_target, &last_delta_vec, 1);
- vm_vec_sub(&plr_to_target_vec, &predicted_target_pos, &obj->pos);
-
- // minimum convergence distance
- if (sip->minimum_convergence_distance > dist_to_target) {
- float dist_mult;
- dist_mult = sip->minimum_convergence_distance / dist_to_target;
- vm_vec_scale_add(&predicted_target_pos, &obj->pos, &plr_to_target_vec, dist_mult);
- }
+ // minimum convergence distance
+ if (sip->minimum_convergence_distance > dist_to_target) {
+ float dist_mult;
+ dist_mult = sip->minimum_convergence_distance / dist_to_target;
+ vm_vec_scale_add(&predicted_target_pos, &obj->pos, &plr_to_target_vec, dist_mult);
+ }
 
- // setting to autoaim to converge on to the target.
- if (sip->aiming_flags & AIM_FLAG_AUTOAIM_CONVERGENCE)
- vm_vec_sub(&firing_vec, &predicted_target_pos, &firing_pos);
- else
- vm_vec_sub(&firing_vec, &predicted_target_pos, &obj->pos);
+ // setting to autoaim to converge on to the target.
+ if (sip->aiming_flags & AIM_FLAG_AUTOAIM_CONVERGENCE)
+ vm_vec_sub(&firing_vec, &predicted_target_pos, &firing_pos);
+ else
+ vm_vec_sub(&firing_vec, &predicted_target_pos, &obj->pos);
 
 
- // Deactivate autoaiming if the target leaves the autoaim-FOV cone
- player_forward_vec = obj->orient.vec.fvec;
- angle_to_target = vm_vec_delta_ang(&player_forward_vec, &plr_to_target_vec, NULL);
+ // Deactivate autoaiming if the target leaves the autoaim-FOV cone
+ player_forward_vec = obj->orient.vec.fvec;
 
- if (angle_to_target < sip->autoaim_fov)
- {
- vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
- }
- else
- {
- firing_orient = obj->orient;
- }
- }
- else if ((sip->aiming_flags & AIM_FLAG_AUTO_CONVERGENCE) && (aip->target_objnum != -1))
+ angle_to_target = vm_vec_delta_ang(&player_forward_vec, &plr_to_target_vec, NULL);
+
+ if (angle_to_target < sip->autoaim_fov)
  {
- //Write automatic convergence code here!
- //If set, switch to manual if automatic fails
- //better idea.. mix it with the above... assume autoaim takes precedence
-
- // Fire weapon in target direction
- vec3d target_position, target_vec;
- vec3d firing_vec, player_forward_vec, convergence_offset;
- float dist_to_target;
-
- // If a subsystem is targeted, fire in that direction instead
- if (aip->targeted_subsys != NULL)
- {
- get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
- }
- else
- {
- target_position = Objects[aip->target_objnum].pos;
- }
-
- dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
-
- if (sip->minimum_convergence_distance > dist_to_target)
- dist_to_target = sip->minimum_convergence_distance;
-
- player_forward_vec = obj->orient.vec.fvec;
- // make sure vector is of the set length
- vm_vec_copy_normalize(&target_vec, &player_forward_vec);
- vm_vec_scale(&target_vec, dist_to_target);
- // if there is convergence offset then make use of it)
- vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
- vm_vec_add2(&target_vec, &convergence_offset);
- vm_vec_add2(&target_vec, &obj->pos);
- vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
-
- // set orientation
  vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
-
  }
- else if (sip->aiming_flags & AIM_FLAG_STD_CONVERGENCE)
+ else if (sip->flags2 & SIF2_GUN_CONVERGENCE)
  {
- vec3d player_forward_vec, target_vec, firing_vec, convergence_offset;
- player_forward_vec = obj->orient.vec.fvec;
- // make sure vector is of the set length
- vm_vec_copy_normalize(&target_vec, &player_forward_vec);
- vm_vec_scale(&target_vec, sip->convergence_distance);
- // if there is convergence offset then make use of it)
- vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
- vm_vec_add2(&target_vec, &convergence_offset);
- vm_vec_add2(&target_vec, &obj->pos);
- vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
-
- // set orientation
+ vec3d firing_vec;
+ vm_vec_unrotate(&firing_vec, &pm->gun_banks[bank_to_fire].norm[pt], &obj->orient);
  vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
  }
  else
@@ -9880,12 +9825,73 @@
  firing_orient = obj->orient;
  }
  }
- else
+ else if ((sip->aiming_flags & AIM_FLAG_AUTO_CONVERGENCE) && (aip->target_objnum != -1))
  {
+ //Write automatic convergence code here!
+ //If set, switch to manual if automatic fails
+ //better idea.. mix it with the above... assume autoaim takes precedence
+
+ // Fire weapon in target direction
+ vec3d target_position, target_vec;
+ vec3d firing_vec, player_forward_vec, convergence_offset;
+ float dist_to_target;
+
+ // If a subsystem is targeted, fire in that direction instead
+ if (aip->targeted_subsys != NULL)
+ {
+ get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
+ }
+ else
+ {
+ target_position = Objects[aip->target_objnum].pos;
+ }
+
+ dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
+
+ if (sip->minimum_convergence_distance > dist_to_target)
+ dist_to_target = sip->minimum_convergence_distance;
+
+ player_forward_vec = obj->orient.vec.fvec;
+ // make sure vector is of the set length
+ vm_vec_copy_normalize(&target_vec, &player_forward_vec);
+ vm_vec_scale(&target_vec, dist_to_target);
+ // if there is convergence offset then make use of it)
+ vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
+ vm_vec_add2(&target_vec, &convergence_offset);
+ vm_vec_add2(&target_vec, &obj->pos);
+ vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
+
+ // set orientation
+ vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+
+ }
+ else if (sip->aiming_flags & AIM_FLAG_STD_CONVERGENCE)
+ {
+ vec3d player_forward_vec, target_vec, firing_vec, convergence_offset;
+ player_forward_vec = obj->orient.vec.fvec;
+ // make sure vector is of the set length
+ vm_vec_copy_normalize(&target_vec, &player_forward_vec);
+ vm_vec_scale(&target_vec, sip->convergence_distance);
+ // if there is convergence offset then make use of it)
+ vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
+ vm_vec_add2(&target_vec, &convergence_offset);
+ vm_vec_add2(&target_vec, &obj->pos);
+ vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
+
+ // set orientation
+ vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+ }
+ else if (sip->flags2 & SIF2_GUN_CONVERGENCE)
+ {
  vec3d firing_vec;
  vm_vec_unrotate(&firing_vec, &pm->gun_banks[bank_to_fire].norm[pt], &obj->orient);
  vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
  }
+ else
+ {
+ firing_orient = obj->orient;
+ }
+
  // create the weapon -- the network signature for multiplayer is created inside
  // of weapon_create
 
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on November 17, 2011, 08:53:13 pm
Just gonna bump this every time it gets pushed off...

Its been 2 months since I put a working patch...
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: zookeeper on November 24, 2011, 02:16:08 am
Seconded. Hopefully someone can push this in sometime soon (assuming there's no yet unknown issues with it).
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Wanderer on November 24, 2011, 03:08:33 am
Well.. it was written like that to retain the model file set gun convergence (ie. SIF flag based gun convergence) due backwards compatibility. However the autoaim also allowed for modder to defined gun convergence set in the table file to be used instead. Difference is that the AIM flag based convergence does not require model file editing.

Code: [Select]
$Convergence:
   +Automatic
      +Minimum Distance:
   +Standard
      +Distance:
   +Offset:

I'm not sure i see much benefits in this patch. I hope you can help explaining those.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on November 24, 2011, 05:29:11 pm
I still retains model file set gun convergence.

The only difference is that with the patch you can have off-axis missiles (and other model-based convergence) and autoaim working together, whereas without it you cannot.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Wanderer on November 25, 2011, 01:24:07 am
Hmm... You set it to default to model file (SIF) gun convergence instead of table set (AIM) gun convergence in case of autoaim 'failure', any particular reason for setting it so?

Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on November 25, 2011, 06:01:46 pm
Not really a particular reason, just picked one cause it has to default to something.
I guess I could modify it to default to table, then go to model if table isn't defined...
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Wanderer on November 26, 2011, 01:52:51 pm
I think it would be preferable that it first default to table defined convergence.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on November 27, 2011, 05:34:34 pm
Looks like I guess wrong.
Due to some changes to that section of the code I...don't think I can even merge my patch properly anymore without picking it apart all over again... :/

To be expected since everyone ignored me for months. I don't even remember what I did anymore.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: chief1983 on November 28, 2011, 01:36:21 am
Well that's a bit hard on yourself.  I'll admit, I was interested in this patch of yours, but I was waiting for either Wanderer to weigh in with how it affects the code since he has made most of the recent changes to that area, or zookeeper, since he's been the most recent FotG developer to hack through the code at all.  Judging by Wanderer's latest comments, if you were able to address his issues with it, I'd have no qualms with pushing it into trunk, assuming you can get it trunk-ready again.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Wanderer on November 28, 2011, 06:26:32 am
Droid, since you did work on it here is my version of the code, opinions? Any one else's opinions are valued as well

Code: [Select]
Index: code/ship/ship.cpp
===================================================================
--- code/ship/ship.cpp (revision 8050)
+++ code/ship/ship.cpp (working copy)
@@ -1873,8 +1873,14 @@
  if(required_string("+Distance:"))
  stuff_float(&sip->convergence_distance);
  }
- if(optional_string("+Offset:"))
+ if(optional_string("+Offset:")) {
  stuff_vector(&sip->convergence_offset);
+
+ if (IS_VEC_NULL(&sip->convergence_offset))
+ sip->aiming_flags &= ~AIM_FLAG_CONVERGENCE_OFFSET;
+ else
+ sip->aiming_flags |= AIM_FLAG_CONVERGENCE_OFFSET;
+ }
  }
 
  if(optional_string("$Warpin type:"))
@@ -9418,7 +9424,7 @@
 // primary.
 int ship_fire_primary(object * obj, int stream_weapons, int force)
 {
- vec3d gun_point, pnt, firing_pos;
+ vec3d gun_point, pnt, firing_pos, target_position, target_velocity_vec;
  int n = obj->instance;
  ship *shipp;
  ship_weapon *swp;
@@ -9430,6 +9436,9 @@
  have_timeout = 0; // used to help tell us whether or not we need to send a packet
  banks_fired = 0; // used in multiplayer -- bitfield of banks that were fired
  bool has_fired = false; // used to determine whether we should fire the scripting hook
+ bool has_autoaim, has_converging_autoaim, needs_target_pos; // used to flag weapon/ship as having autoaim
+ float autoaim_fov = 0; // autoaim limit
+ float dist_to_target = 0; // distance to target, for autoaim & automatic convergence
 
  int sound_played; // used to track what sound is played.  If the player is firing two banks
  // of the same laser, we only want to play one sound
@@ -9505,6 +9514,33 @@
  if(i!=swp->current_primary_bank)ship_stop_fire_primary_bank(obj, i);
  }
 
+ // lets start gun convergence / autoaim code from here - Wanderer
+ has_converging_autoaim = ((sip->aiming_flags & AIM_FLAG_AUTOAIM_CONVERGENCE || (The_mission.ai_profile->player_autoaim_fov[Game_skill_level] > 0.0f)) && aip->target_objnum != -1);
+ has_autoaim = ((has_converging_autoaim || (sip->aiming_flags & AIM_FLAG_AUTOAIM)) && aip->target_objnum != -1);
+ needs_target_pos = ((has_autoaim || (sip->aiming_flags & AIM_FLAG_AUTO_CONVERGENCE)) && aip->target_objnum != -1);
+
+ if (needs_target_pos) {
+ if (has_autoaim) {
+ autoaim_fov = MAX(sip->autoaim_fov, The_mission.ai_profile->player_autoaim_fov[Game_skill_level]);
+ }
+
+ // If a subsystem is targeted, fire in that direction instead
+ if (aip->targeted_subsys != NULL)
+ {
+ get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
+ }
+ else
+ {
+ target_position = Objects[aip->target_objnum].pos;
+ }
+
+ target_velocity_vec = Objects[aip->target_objnum].phys_info.vel;
+ if (The_mission.ai_profile->flags & AIPF_USE_ADDITIVE_WEAPON_VELOCITY)
+ vm_vec_sub2(&target_velocity_vec, &obj->phys_info.vel);
+
+ dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
+ }
+
  for ( i = 0; i < num_primary_banks; i++ ) {
  // Goober5000 - allow more than two banks
  bank_to_fire = (swp->current_primary_bank+i) % swp->num_primary_banks;
@@ -9640,6 +9676,43 @@
 
  if ( pm->n_guns > 0 ) {
  int num_slots = pm->gun_banks[bank_to_fire].num_slots;
+ vec3d predicted_target_pos, plr_to_target_vec;
+ vec3d player_forward_vec = obj->orient.vec.fvec;
+ bool in_automatic_aim_fov = false;
+ float dist_to_aim = 0;
+
+ // more autoaim stuff here - Wanderer
+ // needs weapon speed
+ if (needs_target_pos) {
+ float time_to_target, angle_to_target;
+ vec3d last_delta_vec;
+
+ time_to_target = 0.0f;
+
+ if (winfo_p->max_speed != 0)
+ {
+ time_to_target = dist_to_target / winfo_p->max_speed;
+ }
+
+ vm_vec_scale_add(&predicted_target_pos, &target_position, &target_velocity_vec, time_to_target);
+ polish_predicted_target_pos(winfo_p, &Objects[aip->target_objnum], &target_position, &predicted_target_pos, dist_to_target, &last_delta_vec, 1);
+ vm_vec_sub(&plr_to_target_vec, &predicted_target_pos, &obj->pos);
+
+ if (has_autoaim) {
+ angle_to_target = vm_vec_delta_ang(&player_forward_vec, &plr_to_target_vec, NULL);
+ if (angle_to_target < autoaim_fov)
+ in_automatic_aim_fov = true;
+ }
+
+ dist_to_aim = vm_vec_mag_quick(&plr_to_target_vec);
+
+ // minimum convergence distance
+ if (sip->minimum_convergence_distance > dist_to_aim) {
+ float dist_mult;
+ dist_mult = sip->minimum_convergence_distance / dist_to_aim;
+ vm_vec_scale_add(&predicted_target_pos, &obj->pos, &plr_to_target_vec, dist_mult);
+ }
+ }
 
  if(winfo_p->wi_flags & WIF_BEAM){ // the big change I made for fighter beams, if there beams fill out the Fire_Info for a targeting laser then fire it, for each point in the weapon bank -Bobboau
  float t;
@@ -9865,141 +9938,80 @@
  vm_vec_add(&firing_pos, &gun_point, &obj->pos);
 
  matrix firing_orient;
- if (!(sip->flags2 & SIF2_GUN_CONVERGENCE))
- {
- bool player_has_autoaim = (The_mission.ai_profile->player_autoaim_fov[Game_skill_level] > 0.0f);
- float autoaim_fov = sip->autoaim_fov;
- if (player_has_autoaim)
- autoaim_fov = MAX(autoaim_fov, The_mission.ai_profile->player_autoaim_fov[Game_skill_level]);
+
+ /* I AIM autoaim convergence
+ II AIM autoaim
+ III AIM auto convergence
+ IV AIM std convergence
+ V SIF convergence
+ no convergence or autoaim
+ */
+ if (has_autoaim && in_automatic_aim_fov) {
+ vec3d firing_vec;
 
- if ((sip->aiming_flags & AIM_FLAG_AUTOAIM || player_has_autoaim) &&
- aip->target_objnum != -1)
- {
- // Fire weapon in target direction
- vec3d target_position, target_velocity_vec, predicted_target_pos;
- vec3d firing_vec, last_delta_vec, player_forward_vec, plr_to_target_vec;
- float dist_to_target, time_to_target, angle_to_target;
+ if (has_converging_autoaim) {
+ // converging autoaim
+ vm_vec_sub(&firing_vec, &predicted_target_pos, &firing_pos);
+ } else {
+ // autoaim
+ vm_vec_sub(&firing_vec, &predicted_target_pos, &obj->pos);
+ }
 
- // If a subsystem is targeted, fire in that direction instead
- if (aip->targeted_subsys != NULL)
- {
- get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
- }
- else
- {
- target_position = Objects[aip->target_objnum].pos;
- }
-
- target_velocity_vec = Objects[aip->target_objnum].phys_info.vel;
- if (The_mission.ai_profile->flags & AIPF_USE_ADDITIVE_WEAPON_VELOCITY)
- vm_vec_sub2(&target_velocity_vec, &obj->phys_info.vel);
-
- dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
- time_to_target = 0.0f;
-
- if (winfo_p->max_speed != 0)
- {
- time_to_target = dist_to_target / winfo_p->max_speed;
- }
-
- vm_vec_scale_add(&predicted_target_pos, &target_position, &target_velocity_vec, time_to_target);
- polish_predicted_target_pos(winfo_p, &Objects[aip->target_objnum], &target_position, &predicted_target_pos, dist_to_target, &last_delta_vec, 1);
- vm_vec_sub(&plr_to_target_vec, &predicted_target_pos, &obj->pos);
-
- // minimum convergence distance
- if (sip->minimum_convergence_distance > dist_to_target) {
- float dist_mult;
- dist_mult = sip->minimum_convergence_distance / dist_to_target;
- vm_vec_scale_add(&predicted_target_pos, &obj->pos, &plr_to_target_vec, dist_mult);
- }
-
- // setting to autoaim to converge on to the target.
- if (sip->aiming_flags & AIM_FLAG_AUTOAIM_CONVERGENCE || player_has_autoaim)
- vm_vec_sub(&firing_vec, &predicted_target_pos, &firing_pos);
- else
- vm_vec_sub(&firing_vec, &predicted_target_pos, &obj->pos);
-
-
- // Deactivate autoaiming if the target leaves the autoaim-FOV cone
- player_forward_vec = obj->orient.vec.fvec;
- angle_to_target = vm_vec_delta_ang(&player_forward_vec, &plr_to_target_vec, NULL);
-
- if (angle_to_target < autoaim_fov)
- {
- vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
- }
- else
- {
- firing_orient = obj->orient;
- }
+ vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+ } else if ((sip->aiming_flags & AIM_FLAG_STD_CONVERGENCE) || ((sip->aiming_flags & AIM_FLAG_AUTO_CONVERGENCE) && (aip->target_objnum != -1))) {
+ // std & auto convergence
+ vec3d target_vec, firing_vec, convergence_offset;
+
+ // make sure vector is of the set length
+ vm_vec_copy_normalize(&target_vec, &player_forward_vec);
+ if ((sip->aiming_flags & AIM_FLAG_AUTO_CONVERGENCE) && (aip->target_objnum != -1)) {
+ // auto convergence
+ vm_vec_scale(&target_vec, dist_to_aim);
+ } else {
+ // std convergence
+ vm_vec_scale(&target_vec, sip->convergence_distance);
  }
- else if ((sip->aiming_flags & AIM_FLAG_AUTO_CONVERGENCE) && (aip->target_objnum != -1))
- {
- //Write automatic convergence code here!
- //If set, switch to manual if automatic fails
- //better idea.. mix it with the above... assume autoaim takes precedence
-
- // Fire weapon in target direction
- vec3d target_position, target_vec;
- vec3d firing_vec, player_forward_vec, convergence_offset;
- float dist_to_target;
-
- // If a subsystem is targeted, fire in that direction instead
- if (aip->targeted_subsys != NULL)
- {
- get_subsystem_world_pos(&Objects[aip->target_objnum], aip->targeted_subsys, &target_position);
- }
- else
- {
- target_position = Objects[aip->target_objnum].pos;
- }
-
- dist_to_target = vm_vec_dist_quick(&target_position, &firing_pos);
-
- if (sip->minimum_convergence_distance > dist_to_target)
- dist_to_target = sip->minimum_convergence_distance;
-
- player_forward_vec = obj->orient.vec.fvec;
- // make sure vector is of the set length
- vm_vec_copy_normalize(&target_vec, &player_forward_vec);
- vm_vec_scale(&target_vec, dist_to_target);
- // if there is convergence offset then make use of it)
+
+ // if there is convergence offset then make use of it)
+ if (sip->aiming_flags & AIM_FLAG_CONVERGENCE_OFFSET) {
  vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
  vm_vec_add2(&target_vec, &convergence_offset);
- vm_vec_add2(&target_vec, &obj->pos);
- vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
+ }
 
- // set orientation
- vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+ vm_vec_add2(&target_vec, &obj->pos);
+ vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
+
+ // set orientation
+ vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+ } else if (sip->aiming_flags & AIM_FLAG_STD_CONVERGENCE) {
+ // fixed distance convergence
+ vec3d target_vec, firing_vec, convergence_offset;
+
+ // make sure vector is of the set length
+ vm_vec_copy_normalize(&target_vec, &player_forward_vec);
+ vm_vec_scale(&target_vec, sip->convergence_distance);
 
- }
- else if (sip->aiming_flags & AIM_FLAG_STD_CONVERGENCE)
- {
- vec3d player_forward_vec, target_vec, firing_vec, convergence_offset;
- player_forward_vec = obj->orient.vec.fvec;
- // make sure vector is of the set length
- vm_vec_copy_normalize(&target_vec, &player_forward_vec);
- vm_vec_scale(&target_vec, sip->convergence_distance);
- // if there is convergence offset then make use of it)
+ // if there is convergence offset then make use of it)
+ if (sip->aiming_flags & AIM_FLAG_CONVERGENCE_OFFSET) {
  vm_vec_unrotate(&convergence_offset, &sip->convergence_offset, &obj->orient);
  vm_vec_add2(&target_vec, &convergence_offset);
- vm_vec_add2(&target_vec, &obj->pos);
- vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
+ }
 
- // set orientation
- vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
- }
- else
- {
- firing_orient = obj->orient;
- }
- }
- else
- {
+ vm_vec_add2(&target_vec, &obj->pos);
+ vm_vec_sub(&firing_vec, &target_vec, &firing_pos);
+
+ // set orientation
+ vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+ } else if (sip->flags2 & SIF2_GUN_CONVERGENCE) {
+ // model file defined convergence
  vec3d firing_vec;
  vm_vec_unrotate(&firing_vec, &pm->gun_banks[bank_to_fire].norm[pt], &obj->orient);
  vm_vector_2_matrix(&firing_orient, &firing_vec, NULL, NULL);
+ } else {
+ // no autoaim or convergence
+ firing_orient = obj->orient;
  }
+
  // create the weapon -- the network signature for multiplayer is created inside
  // of weapon_create
 
Index: code/ship/ship.h
===================================================================
--- code/ship/ship.h (revision 8050)
+++ code/ship/ship.h (working copy)
@@ -881,6 +881,7 @@
 #define AIM_FLAG_AUTO_CONVERGENCE (1 << 1) // has automatic convergence
 #define AIM_FLAG_STD_CONVERGENCE (1 << 2) // has standard - ie. non-automatic - convergence
 #define AIM_FLAG_AUTOAIM_CONVERGENCE (1 << 3) // has autoaim with convergence
+#define AIM_FLAG_CONVERGENCE_OFFSET (1 << 4) // marks that convergence has offset value
 
 typedef struct thruster_particles {
  generic_anim thruster_bitmap;
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on December 03, 2011, 01:38:54 am
...Can I have a build? For some reason pacthing/building doesn't seem to be working for me >.>
Keeps failing :/

I hope its not that someone re-enabled tts or something >.>
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: chief1983 on December 03, 2011, 05:25:37 am
If building worked for you at one point, and suddenly stopped, feel free to post a new thread in the SCP forum including the error messages you got.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Wanderer on December 03, 2011, 07:30:16 am
It has already been committed.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on December 03, 2011, 03:29:29 pm
Cool, will test....as soon as a nightly with it appears.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Zacam on December 04, 2011, 05:40:08 am
Cool, will test....as soon as a nightly with it appears.

Uh, what? We're in RC phase, so nightly builds won't happen for a while, but you obviously demonstrated that you're capable of making builds, but you wont test code factored on your idea until it hit somebody else releasing it?

I'm sorry, but that makes absolutely no sense to me, what am I missing here?
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Tomo on December 04, 2011, 06:17:02 am
I'm sorry, but that makes absolutely no sense to me, what am I missing here?
Presumably, this:
...Can I have a build? For some reason pacthing/building doesn't seem to be working for me >.>
Keeps failing :/

I hope its not that someone re-enabled tts or something >.>

That said - Droid, does it work if you just pull down the latest svn instead of using the .patch?
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on December 04, 2011, 12:47:51 pm
Eh, alright, let's give compiling a shot again.

EDOT: Nope.jpg not working.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Wanderer on December 04, 2011, 11:10:43 pm
'No the autoaim does not work' or 'no i can't compile the build'?
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on December 04, 2011, 11:45:15 pm
Can't compile a build.
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Wanderer on December 05, 2011, 12:03:02 am
Where does it fail? 
Title: Re: PATCH: Autoaim vs "gun convergence"
Post by: Droid803 on December 06, 2011, 03:21:37 pm
iunno it just says like 0 succeeded 2 failed or something at the end of compile...

i think i got it working now actually.
at least, autoaim seems to be working w/ "gun convergence".