3 #include <common/state.qh>
4 #include <common/stats.qh>
5 #include <common/weapons/_all.qh>
6 #include <common/weapons/_all.qh>
7 #include <common/wepent.qh>
8 #include <server/antilag.qh>
9 #include <server/client.qh>
10 #include <server/world.qh>
12 vector W_HitPlotUnnormalizedUntransform(vector screenforward, vector screenright, vector screenup, vector v)
15 ret.x = screenright * v;
17 ret.z = screenforward * v;
21 vector W_HitPlotNormalizedUntransform(vector org, entity targ, vector screenforward, vector screenright, vector screenup, vector v)
24 vector mi, ma, thisv, myv, ret;
26 myv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, org);
28 // x = 0..1 relative to hitbox; y = 0..1 relative to hitbox; z = distance
30 mi = ma = targ.origin + 0.5 * (targ.mins + targ.maxs);
31 for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) for(k = 0; k < 2; ++k)
34 if(i) thisv.x += targ.maxs.x; else thisv.x += targ.mins.x;
35 if(j) thisv.y += targ.maxs.y; else thisv.y += targ.mins.y;
36 if(k) thisv.z += targ.maxs.z; else thisv.z += targ.mins.z;
37 thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, thisv);
40 if(mi.x > thisv.x) mi.x = thisv.x; if(ma.x < thisv.x) ma.x = thisv.x;
41 if(mi.y > thisv.y) mi.y = thisv.y; if(ma.y < thisv.y) ma.y = thisv.y;
42 //if(mi_z > thisv_z) mi_z = thisv_z; if(ma_z < thisv_z) ma_y = thisv_z;
51 thisv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, v);
52 ret.x = (thisv.x - mi.x) / (ma.x - mi.x);
53 ret.y = (thisv.y - mi.y) / (ma.y - mi.y);
54 ret.z = thisv.z - myv.z;
58 void W_HitPlotAnalysis(entity player, entity wep, vector screenforward, vector screenright, vector screenup)
60 if(CS(player).hitplotfh >= 0)
62 float lag = ANTILAG_LATENCY(player);
65 if(!IS_REAL_CLIENT(player))
66 lag = 0; // only antilag for clients
68 vector 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) || IS_MONSTER(trace_ent))
72 entity store = IS_CLIENT(trace_ent) ? CS(trace_ent) : trace_ent;
73 antilag_takeback(trace_ent, store, time - lag);
74 vector hitplot = W_HitPlotNormalizedUntransform(org, trace_ent, screenforward, screenright, screenup, trace_endpos);
75 antilag_restore(trace_ent, store);
76 fputs(CS(player).hitplotfh, strcat(ftos(hitplot.x), " ", ftos(hitplot.y), " ", ftos(hitplot.z), " ", ftos(wep.m_id), "\n"));
77 //print(strcat(ftos(hitplot_x), " ", ftos(hitplot_y), " ", ftos(hitplot_z), "\n"));
82 void W_HitPlotOpen(entity player)
84 if(autocvar_g_hitplots || strhasword(autocvar_g_hitplots_individuals, player.netaddress))
86 CS(player).hitplotfh = fopen(strcat("hits-", matchid, "-", player.netaddress, "-", ftos(player.playerid), ".plot"), FILE_WRITE);
87 fputs(CS(player).hitplotfh, strcat("#name ", playername(player.netname, player.team, false), "\n"));
89 else { CS(player).hitplotfh = -1; }
92 void W_HitPlotClose(entity player)
94 if(CS(player).hitplotfh >= 0)
96 fclose(CS(player).hitplotfh);
97 CS(player).hitplotfh = -1;