Author Topic: PATCH: Autoaim vs "gun convergence"  (Read 9640 times)

0 Members and 1 Guest are viewing this topic.

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: Autoaim vs "gun convergence"
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.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Autoaim vs "gun convergence"
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.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Thaeris

  • Can take his lumps
  • 211
  • Away in Limbo
Re: Autoaim vs "gun convergence"
Or, if the fates smile kindly upon us...

Someone will fix the terribad netcode. Please, someone remind QD that it genuiney blows.
"trolls are clearly social rejects and therefore should be isolated from society, or perhaps impaled."

-Nuke



"Look on the bright side, how many release dates have been given for Doomsday, and it still isn't out yet.

It's the Duke Nukem Forever of prophecies..."


"Jesus saves.

Everyone else takes normal damage.
"

-Flipside

"pirating software is a lesser evil than stealing but its still evil. but since i pride myself for being evil, almost anything is fair game."


"i never understood why women get the creeps so ****ing easily. i mean most serial killers act perfectly normal, until they kill you."


-Nuke

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Autoaim vs "gun convergence"
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.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: Autoaim vs "gun convergence"
Could I at least get my patch in trunk (which corrects existing behavior)? D:
(´・ω・`)
=============================================================

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
PATCH: Autoaim vs "gun convergence"
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
 
(´・ω・`)
=============================================================

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: PATCH: Autoaim vs "gun convergence"
Just gonna bump this every time it gets pushed off...

Its been 2 months since I put a working patch...
(´・ω・`)
=============================================================

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: PATCH: Autoaim vs "gun convergence"
Seconded. Hopefully someone can push this in sometime soon (assuming there's no yet unknown issues with it).

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: PATCH: Autoaim vs "gun convergence"
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.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: PATCH: Autoaim vs "gun convergence"
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.
(´・ω・`)
=============================================================

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: PATCH: Autoaim vs "gun convergence"
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?

Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: PATCH: Autoaim vs "gun convergence"
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...
(´・ω・`)
=============================================================

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: PATCH: Autoaim vs "gun convergence"
I think it would be preferable that it first default to table defined convergence.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: PATCH: Autoaim vs "gun convergence"
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.
(´・ω・`)
=============================================================

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: PATCH: Autoaim vs "gun convergence"
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.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: PATCH: Autoaim vs "gun convergence"
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;
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: PATCH: Autoaim vs "gun convergence"
...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 >.>
(´・ω・`)
=============================================================

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: PATCH: Autoaim vs "gun convergence"
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.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: PATCH: Autoaim vs "gun convergence"
It has already been committed.
Do not meddle in the affairs of coders for they are soggy and hard to light

  

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: PATCH: Autoaim vs "gun convergence"
Cool, will test....as soon as a nightly with it appears.
(´・ω・`)
=============================================================