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