@@ -1334,9 +1334,56 @@ void ship_get_global_turret_gun_info(object *objp, ship_subsys *ssp, vec3d *gpos
13341334 // model_find_world_point(gpos, gun_pos, tp->model_num, tp->turret_gun_sobj, &objp->orient, &objp->pos );
13351335 model_instance_find_world_point (gpos, gun_pos, tp->model_num , Ships[objp->instance ].model_instance_num , tp->turret_gun_sobj , &objp->orient , &objp->pos );
13361336
1337- if (use_angles)
1338- model_instance_find_world_dir (gvec, &tp->turret_norm , tp->model_num , Ships[objp->instance ].model_instance_num , tp->turret_gun_sobj , &objp->orient , &objp->pos );
1339- else {
1337+ if (use_angles) {
1338+ model_instance_find_world_dir (gvec, &tp->turret_norm , tp->model_num , Ships[objp->instance ].model_instance_num , tp->turret_gun_sobj , &objp->orient , &objp->pos );
1339+ } else if (tp->flags2 & MSS_FLAG2_SHARE_FIRE_DIRECTION) {
1340+ vec3d shared_dir, avg, tmp_pos, tmp_target, enemy_point;
1341+ vm_vec_avg_n (&avg, tp->turret_num_firing_points , tp->turret_firing_point );
1342+
1343+ model_instance_find_world_point (&tmp_pos, &avg, tp->model_num , Ships[objp->instance ].model_instance_num , tp->turret_gun_sobj , &objp->orient , &objp->pos );
1344+
1345+ if (targetp == nullptr ) {
1346+ Assertion (ssp->turret_enemy_objnum >= 0 , " The turret enemy object number %d for %s on ship number %d is invalid." , ssp->turret_enemy_objnum , ssp->sub_name , ssp->parent_objnum );
1347+ object *lep = &Objects[ssp->turret_enemy_objnum ];
1348+
1349+ int best_weapon_tidx = turret_select_best_weapon (ssp, lep);
1350+
1351+ // This turret doesn't have any good weapons
1352+ if (best_weapon_tidx < 0 )
1353+ return ;
1354+
1355+ weapon_info *wip = get_turret_weapon_wip (&ssp->weapons , best_weapon_tidx);
1356+
1357+ float weapon_system_strength = ship_get_subsystem_strength (&Ships[ssp->parent_objnum ], SUBSYSTEM_WEAPONS);
1358+
1359+ if ((ssp->targeted_subsys != nullptr ) && !(ssp->flags & SSF_NO_SS_TARGETING)) {
1360+ vm_vec_unrotate (&enemy_point, &ssp->targeted_subsys ->system_info ->pnt , &Objects[ssp->turret_enemy_objnum ].orient );
1361+ vm_vec_add2 (&enemy_point, &ssp->last_aim_enemy_pos );
1362+ } else {
1363+ if ((lep->type == OBJ_SHIP) && (Ship_info[Ships[lep->instance ].ship_info_index ].flags & (SIF_BIG_SHIP | SIF_HUGE_SHIP))) {
1364+ ai_big_pick_attack_point_turret (lep, ssp, &tmp_pos, &tp->turret_norm , &enemy_point, tp->turret_fov , MIN (wip->max_speed * wip->lifetime , wip->weapon_range ));
1365+ }
1366+ else {
1367+ enemy_point = ssp->last_aim_enemy_pos ;
1368+ }
1369+ }
1370+
1371+ vec3d target_moving_direction = ssp->last_aim_enemy_vel ;
1372+
1373+ // Try to guess where the enemy will be, and store that spot in predicted_enemy_pos
1374+ if (The_mission.ai_profile ->flags & AIPF_USE_ADDITIVE_WEAPON_VELOCITY) {
1375+ vm_vec_scale_sub2 (&target_moving_direction, &objp->phys_info .vel , wip->vel_inherit_amount );
1376+ }
1377+
1378+ set_predicted_enemy_pos_turret (&tmp_target, &tmp_pos, objp, &enemy_point, &target_moving_direction, wip->max_speed , ssp->turret_time_enemy_in_range * (weapon_system_strength + 1 .0f ) / 2 .0f );
1379+ } else {
1380+ tmp_target = *targetp;
1381+ }
1382+
1383+ vm_vec_normalized_dir (&shared_dir, &tmp_target, &tmp_pos);
1384+
1385+ model_instance_find_world_dir (gvec, &shared_dir, tp->model_num , Ships[objp->instance ].model_instance_num , tp->turret_gun_sobj , &objp->orient , &objp->pos );
1386+ } else {
13401387 // vector gun_pos2;
13411388 // vm_vec_add(&gun_pos2, gpos, gun_pos);
13421389 vm_vec_normalized_dir (gvec, targetp, gpos);
0 commit comments