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

Though do test if you doubt me~
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]