Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / system / system_aimprocs.qc
1 /*
2 * Generic aim
3
4 supports:
5 TFL_AIM_NO
6 TFL_AIM_GROUNDGROUND
7 TFL_AIM_LEAD
8 TFL_AIM_SHOTTIMECOMPENSATE
9 */
10 vector turret_stdproc_aim_generic()
11 {
12
13     vector pre_pos, prep;
14     float distance, i, mintime;
15
16     turret_tag_fire_update();
17
18     if(self.aim_flags & TFL_AIM_SIMPLE)
19         return real_origin(self.enemy);
20
21         mintime = max(self.attack_finished_single - time,0) + sys_frametime;
22
23     // Baseline
24     pre_pos = real_origin(self.enemy);
25
26     // Lead?
27     if (self.aim_flags & TFL_AIM_LEAD)
28     {
29                 if (self.aim_flags & TFL_AIM_SHOTTIMECOMPENSATE)       // Need to conpensate for shot traveltime
30                 {
31                         // FIXME: this cant be the best way to do this..
32                         prep = pre_pos;
33                         float impact_time = 0;
34                         for(i = 0; i < 4; ++i)
35                         {
36                                 distance = vlen(prep - self.tur_shotorg);
37                                 impact_time = distance / self.shot_speed;
38                                 prep = pre_pos + self.enemy.velocity * impact_time;
39                         }
40
41                         prep = pre_pos + (self.enemy.velocity * (impact_time + mintime));
42
43                         if(self.aim_flags & TFL_AIM_ZPREDICT)
44                         if (!(self.enemy.flags & FL_ONGROUND))
45                         if(self.enemy.movetype == MOVETYPE_WALK || self.enemy.movetype == MOVETYPE_TOSS || self.enemy.movetype == MOVETYPE_BOUNCE)
46                         {
47                                 float vz;
48                                 prep.z = pre_pos.z;
49                                 vz = self.enemy.velocity.z;
50                                 for(i = 0; i < impact_time; i += sys_frametime)
51                                 {
52                                         vz = vz - (autocvar_sv_gravity * sys_frametime);
53                                         prep.z = prep.z + vz * sys_frametime;
54                                 }
55                         }
56                         pre_pos = prep;
57                 }
58                 else
59                         pre_pos = pre_pos + self.enemy.velocity * mintime;
60     }
61
62     if(self.aim_flags & TFL_AIM_GROUNDGROUND)
63     {
64         //tracebox(pre_pos + '0 0 32',self.enemy.mins,self.enemy.maxs,pre_pos -'0 0 64',MOVE_WORLDONLY,self.enemy);
65         traceline(pre_pos + '0 0 32',pre_pos -'0 0 64',MOVE_WORLDONLY,self.enemy);
66         if(trace_fraction != 1.0)
67             pre_pos = trace_endpos;
68     }
69
70     return pre_pos;
71 }