4 #include "../../dpdefs/progsdefs.qh"
5 #include "../../dpdefs/dpextensions.qh"
6 #include "../../common/weapons/weapons.qh"
8 #include "../autocvars.qh"
10 #include "../antilag.qh"
13 vector W_HitPlotUnnormalizedUntransform(vector screenforward, vector screenright, vector screenup, vector v)
16 ret.x = screenright * v;
18 ret.z = screenforward * v;
22 vector W_HitPlotNormalizedUntransform(vector org, entity targ, vector screenforward, vector screenright, vector screenup, vector v)
25 vector mi, ma, thisv, myv, ret;
27 myv = W_HitPlotUnnormalizedUntransform(screenforward, screenright, screenup, org);
29 // x = 0..1 relative to hitbox; y = 0..1 relative to hitbox; z = distance
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)
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);
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;
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;
59 void W_HitPlotAnalysis(entity player, vector screenforward, vector screenright, vector screenup)
65 if(player.hitplotfh >= 0)
67 lag = ANTILAG_LATENCY(player);
70 if(!IS_REAL_CLIENT(player))
71 lag = 0; // only antilag for clients
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))
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"));
86 void W_HitPlotOpen(entity player)
88 if(autocvar_g_hitplots || strstrofs(strcat(" ", autocvar_g_hitplots_individuals, " "), strcat(" ", player.netaddress, " "), 0) >= 0)
90 player.hitplotfh = fopen(strcat("hits-", matchid, "-", player.netaddress, "-", ftos(player.playerid), ".plot"), FILE_WRITE);
91 fputs(player.hitplotfh, strcat("#name ", player.netname, "\n"));
93 else { player.hitplotfh = -1; }
96 void W_HitPlotClose(entity player)
98 if(player.hitplotfh >= 0)
100 fclose(player.hitplotfh);
101 player.hitplotfh = -1;