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