]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/tturrets/system/system_aimprocs.qc
eol-style only
[divverent/nexuiz.git] / data / qcsrc / server / tturrets / system / system_aimprocs.qc
1 /*
2 * Generic aim
3
4 supports:
5 TFL_AIM_NO
6 TFL_AIM_GROUND
7 TFL_AIM_LEAD
8 TFL_AIM_SHOTTIMECOMPENSATE
9 TFL_AIM_INFRONT
10 TFL_AIM_BEHIND
11 TFL_AIM_ZEASE
12
13 not supported:
14 TFL_AIM_BALISTIC
15 */
16 vector turret_stdproc_aim_generic()
17 {
18
19     vector pre_pos,prep;
20     float distance,impact_time,i,mintime;
21
22     turret_tag_fire_update();
23
24     if(self.aim_flags & TFL_AIM_SIMPLE)
25         return real_origin(self.enemy);
26
27     // Keep track of when we can shoot the next time and
28     // try to predict where the target will be then, so we can put our aimpoint there.
29     // + sys_ticrate for non hitscan, becouse spawned
30     // projectiles dont move during the first tic of their life.
31     if (self.turrcaps_flags & TFL_TURRCAPS_HITSCAN)
32         mintime = max(self.attack_finished_single - time,0);
33     else
34         mintime = max(self.attack_finished_single - time,0) + sys_ticrate;
35
36     // Baseline
37     pre_pos = real_origin(self.enemy);// + (self.enemy.velocity * mintime);
38
39     if (self.aim_flags & TFL_AIM_INFRONT)   // Aim a bit in front of the target
40         pre_pos = pre_pos + (normalize(self.enemy.velocity) * 64);
41
42     if (self.aim_flags & TFL_AIM_BEHIND)    // Aim a bit behind the target
43         pre_pos = pre_pos - (normalize(self.enemy.velocity) * 32);
44
45     // Lead?
46     if (self.aim_flags & TFL_AIM_LEAD)
47     if (self.aim_flags & TFL_AIM_SHOTTIMECOMPENSATE)       // Need to conpensate for shot traveltime
48     {
49         // FIXME: this cant be the best way to do this..
50
51
52         prep = pre_pos;
53         for(i = 0; i < 4; ++i)
54         {
55             distance = vlen(prep - self.tur_shotorg);
56             impact_time = distance / self.shot_speed;
57             prep = pre_pos + self.enemy.velocity * impact_time;
58         }
59
60
61         // tnx to Rudolf "div0" Polzer for this solution.
62         // hmm tobad it dont work.
63         /*
64         vector q;
65         q = solve_quadratic(self.enemy.velocity*self.enemy.velocity - self.shot_speed*self.shot_speed, 2*(pre_pos*self.enemy.velocity), pre_pos * pre_pos);
66         if(q_x > 0)
67             impact_time = q_x;
68         else
69             impact_time = q_y;
70         */
71
72         prep = pre_pos + (self.enemy.velocity * (impact_time + mintime));
73
74         if(self.aim_flags & TFL_AIM_ZPREDICT)
75         if not(self.enemy.flags & FL_ONGROUND)
76         if(self.enemy.movetype == MOVETYPE_WALK || self.enemy.movetype == MOVETYPE_TOSS || self.enemy.movetype == MOVETYPE_BOUNCE)
77         {
78             float vz;
79             prep_z = pre_pos_z;
80             vz = self.enemy.velocity_z;
81             for(i = 0; i < impact_time; i += sys_ticrate)
82             {
83                 vz = vz - (sv_gravity * sys_ticrate);
84                 prep_z = prep_z + vz * sys_ticrate;
85             }
86         }
87
88
89         pre_pos = prep;
90     }
91     else
92         pre_pos = pre_pos + self.enemy.velocity * mintime;
93
94     // Smooth out predict-Z?
95     /*
96     if (self.aim_flags & TFL_AIM_ZEASE)
97     if (self.enemy.flags & FL_CLIENT)
98     {
99         vector v;
100         v = real_origin(self.enemy);
101         pre_pos_z = (pre_pos_z + v_z) * 0.5;
102     }
103     */
104
105     if(self.aim_flags & TFL_AIM_GROUND2)
106     {
107         tracebox(pre_pos + '0 0 32',self.enemy.mins,self.enemy.maxs,pre_pos -'0 0 64',MOVE_WORLDONLY,self.enemy);
108         if(trace_fraction != 1.0)
109             pre_pos = trace_endpos;
110     }
111
112     /*
113     // This turret should hit the ground neer a target rather the do a direct hit
114     if (self.aim_flags & TFL_AIM_GROUND)
115     {
116         traceline(pre_pos + '0 0 8',pre_pos - '0 0 10000',MOVE_WORLDONLY,self.enemy);
117         pre_pos = trace_endpos;
118     }
119     */
120
121     return pre_pos;
122 }