View Issue Details

IDProjectCategoryView StatusLast Update
0001948FSSCP---------public2009-07-20 04:14
ReporterKeldorKatarn Assigned Tochief1983  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformIBM PCOSWindowsOS VersionVista SP1
Product Version3.6.11 
Summary0001948: "fire down normals" without effect
DescriptionI have a model that has a torpedo launcher as a turret. The turret is just a tube that cannot move (rotation speed = 0.0 in ships.tbl).

However the torpedoes are all still fired directly towards the target.

So someone told me to use the "fire down normals" flag and I did. To my surprise this didn't change a thing. The torp is still fired directly at the target.
Steps To ReproduceLook at the source code.
Additional InformationThe function int aifft_rotate_turret(...) in aiturret.cpp has the following ending:

    // return 0 by default (to preserve retail behavior) but allow for a per-subsystem option
    // for using the turret normals for firing
    if (ss->system_info->flags & MSS_FLAG_FIRE_ON_NORMAL)
        return 1;

    return 0;

This is the only place where MSS_FLAG_FIRE_ON_NORMAL is evaluated.

The only caller to aifft_rotate_turret() is void ai_fire_from_turret() in the same file. And that function does this with the return value:

int use_angles = aifft_rotate_turret(...);

use_angles is passes as a parameter to ship_get_global_turret_gun_info()
which does this with it. (gvec seems to be the output direction vector)

        if (use_angles)
        model_find_world_dir(gvec, &tp->turret_norm, tp->model_num, tp->turret_gun_sobj, &objp->orient, &objp->pos );
    else {
        //vector gun_pos2;
        //vm_vec_add(&gun_pos2, gpos, gun_pos);
        vm_vec_normalized_dir(gvec, targetp, gpos);
    }

That output vector is used in ai_fire_from_turret() later and that's where the bug is, I believe:

Here a wrong vector is assigned:

            // We're ready to fire... now get down to specifics, like where is the
            // actual gun point and normal, not just the one for whole turret.
            // moved here as if there are two weapons with indentical fire stamps
            // they would have shared the fire point.
            tv2e = v2e;


v2e was only calculated to get the dot product:
            // Fire in the direction the turret is facing, not right at the target regardless of turret dir.
            vm_vec_sub(&v2e, &predicted_enemy_pos, &gpos);
            dist_to_enemy = vm_vec_normalize(&v2e);
            dot = vm_vec_dot(&v2e, &gvec);

it was never meant as the firing direction, otherwise the gvec would not have been calculated. This if that is changed to:

tv2e = gvec;

This should work correctly. Later the correct vector is then used to initialize fire the weapon:

turret_fire_weapon(valid_weapons[0], ss, parent_objnum, &gpos, &tv2e, &predicted_enemy_pos);

THis is also the only place where tv2e is used except for the line that adds jitter, but I think here also the correct firing vector must be used:

if(wip->wi_flags & WIF_FLAK){
    flak_jitter_aim(&tv2e, dist_to_enemy, ship_get_subsystem_strength(shipp, SUBSYSTEM_WEAPONS));
}


Proposed (1-line) patch attached. Please check in detail and confirm.

Please check and confirm.

TagsNo tags attached.

Activities

2009-07-02 20:24

 

fire-down-normal.patch (505 bytes)   
Index: code/ai/aiturret.cpp
===================================================================
--- code/ai/aiturret.cpp	(revision 5382)
+++ code/ai/aiturret.cpp	(working copy)
@@ -1951,7 +1951,7 @@
 			// actual gun point and normal, not just the one for whole turret.
 			// moved here as if there are two weapons with indentical fire stamps
 			// they would have shared the fire point.
-			tv2e = v2e;
+			tv2e = gvec;
 	
 			// make sure to reset this for current weapon
 			ok_to_fire = false;
fire-down-normal.patch (505 bytes)   

portej05

2009-07-03 16:29

reporter   ~0011036

This seems to be right.
Can someone confirm that the patch works as expected?

portej05

2009-07-03 17:13

reporter   ~0011037

KKs patch committed.

KeldorKatarn

2009-07-20 00:47

reporter   ~0011096

I think this is confirmed to work and can be set to resolved.

chief1983

2009-07-20 04:14

administrator   ~0011097

Closed.

Issue History

Date Modified Username Field Change
2009-07-02 20:24 KeldorKatarn New Issue
2009-07-02 20:24 KeldorKatarn File Added: fire-down-normal.patch
2009-07-03 16:29 portej05 Note Added: 0011036
2009-07-03 17:13 portej05 Status new => assigned
2009-07-03 17:13 portej05 Assigned To => chief1983
2009-07-03 17:13 portej05 Note Added: 0011037
2009-07-03 17:13 portej05 Status assigned => feedback
2009-07-20 00:47 KeldorKatarn Note Added: 0011096
2009-07-20 04:14 chief1983 Note Added: 0011097
2009-07-20 04:14 chief1983 Status feedback => resolved
2009-07-20 04:14 chief1983 Resolution open => fixed