Makefile: use `-I.`
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / hitplot.qc
1 #include "hitplot.qh"
2
3 #include "../antilag.qh"
4 #include "../g_subs.qh"
5 #include <common/weapons/all.qh>
6
7 vector W_HitPlotUnnormalizedUntransform(vector screenforward, vector screenright, vector screenup, vector v)
8 {
9         vector ret;
10         ret.x = screenright * v;
11         ret.y = screenup * v;
12         ret.z = screenforward * v;
13         return ret;
14 }
15
16 vector W_HitPlotNormalizedUntransform(vector org, entity targ, vector screenforward, vector screenright, vector screenup, vector v)
17 {
18         float i, j, k;
19         vector mi, ma, thisv, myv, ret;
20
21         myv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, org);
22
23         // x = 0..1 relative to hitbox; y = 0..1 relative to hitbox; z = distance
24
25         mi = ma = targ.origin + 0.5 * (targ.mins + targ.maxs);
26         for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) for(k = 0; k < 2; ++k)
27         {
28                 thisv = targ.origin;
29                 if(i) thisv.x += targ.maxs.x; else thisv.x += targ.mins.x;
30                 if(j) thisv.y += targ.maxs.y; else thisv.y += targ.mins.y;
31                 if(k) thisv.z += targ.maxs.z; else thisv.z += targ.mins.z;
32                 thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, thisv);
33                 if(i || j || k)
34                 {
35                         if(mi.x > thisv.x) mi.x = thisv.x; if(ma.x < thisv.x) ma.x = thisv.x;
36                         if(mi.y > thisv.y) mi.y = thisv.y; if(ma.y < thisv.y) ma.y = thisv.y;
37                         //if(mi_z > thisv_z) mi_z = thisv_z; if(ma_z < thisv_z) ma_y = thisv_z;
38                 }
39                 else
40                 {
41                         // first run
42                         mi = ma = thisv;
43                 }
44         }
45
46         thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, v);
47         ret.x = (thisv.x - mi.x) / (ma.x - mi.x);
48         ret.y = (thisv.y - mi.y) / (ma.y - mi.y);
49         ret.z = thisv.z - myv.z;
50         return ret;
51 }
52
53 void W_HitPlotAnalysis(entity player, vector screenforward, vector screenright, vector screenup)
54 {
55         vector hitplot;
56         vector org;
57         float lag;
58
59         if(player.hitplotfh >= 0)
60         {
61                 lag = ANTILAG_LATENCY(player);
62                 if(lag < 0.001)
63                         lag = 0;
64                 if(!IS_REAL_CLIENT(player))
65                         lag = 0; // only antilag for clients
66
67                 org = player.origin + player.view_ofs;
68                 traceline_antilag_force(player, org, org + screenforward * MAX_SHOT_DISTANCE, MOVE_NORMAL, player, lag);
69                 if(IS_CLIENT(trace_ent) || IS_MONSTER(trace_ent))
70                 {
71                         antilag_takeback(trace_ent, time - lag);
72                         hitplot = W_HitPlotNormalizedUntransform(org, trace_ent, screenforward, screenright, screenup, trace_endpos);
73                         antilag_restore(trace_ent);
74                         fputs(player.hitplotfh, strcat(ftos(hitplot.x), " ", ftos(hitplot.y), " ", ftos(hitplot.z), " ", ftos(PS(player).m_switchweapon.m_id), "\n"));
75                         //print(strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), "\n"));
76                 }
77         }
78 }
79
80 void W_HitPlotOpen(entity player)
81 {
82         if(autocvar_g_hitplots || strhasword(autocvar_g_hitplots_individuals, player.netaddress))
83         {
84                 player.hitplotfh = fopen(strcat("hits-", matchid, "-", player.netaddress, "-", ftos(player.playerid), ".plot"), FILE_WRITE);
85                 fputs(player.hitplotfh, strcat("#name ", player.netname, "\n"));
86         }
87         else { player.hitplotfh = -1; }
88 }
89
90 void W_HitPlotClose(entity player)
91 {
92         if(player.hitplotfh >= 0)
93         {
94                 fclose(player.hitplotfh);
95                 player.hitplotfh = -1;
96         }
97 }