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