4 #include "../../dpdefs/progsdefs.qh"
5 #include "../../dpdefs/dpextensions.qh"
6 #include "../../common/constants.qh"
7 #include "../../common/util.qh"
8 #include "../../common/weapons/weapons.qh"
10 #include "../autocvars.qh"
11 #include "../constants.qh"
13 #include "../mutators/mutators_include.qh"
16 float accuracy_byte(float n, float d)
18 //printf("accuracy: %d / %d\n", n, d);
23 return 1 + rint(n * 100.0 / d);
26 float accuracy_send(entity to, int sf)
30 WriteByte(MSG_ENTITY, ENT_CLIENT_ACCURACY);
38 if (!(self.owner.cvar_cl_accuracy_data_share && autocvar_sv_accuracy_data_share))
40 // note: zero sendflags can never be sent... so we can use that to say that we send no accuracy!
41 WriteInt24_t(MSG_ENTITY, sf);
44 // note: we know that client and server agree about SendFlags...
45 for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w)
48 WriteByte(MSG_ENTITY, accuracy_byte(self.(accuracy_hit[w]), self.(accuracy_fired[w])));
58 void accuracy_init(entity e)
62 e.accuracy.classname = "accuracy";
63 e.accuracy.drawonlytoclient = e;
64 Net_LinkEntity(e.accuracy, false, 0, accuracy_send);
67 void accuracy_free(entity e)
72 // force a resend of a player's accuracy stats
73 void accuracy_resend(entity e)
75 e.accuracy.SendFlags = 0xFFFFFF;
78 // update accuracy stats
82 void accuracy_add(entity e, int w, float fired, float hit)
86 if(IS_INDEPENDENT_PLAYER(e))
89 if(!a || !(hit || fired))
92 b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
94 a.(accuracy_hit[w]) += hit;
96 a.(accuracy_fired[w]) += fired;
98 if(hit && a.hit_time != time) // only run this once per frame
100 a.(accuracy_cnt_hit[w]) += 1;
104 if(fired && a.fired_time != time) // only run this once per frame
106 a.(accuracy_cnt_fired[w]) += 1;
110 if(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])))
120 float accuracy_isgooddamage(entity attacker, entity targ)
122 frag_attacker = attacker;
124 float mutator_check = MUTATOR_CALLHOOK(AccuracyTargetValid);
127 if(targ.deadflag == DEAD_NO)
129 if(mutator_check == MUT_ACCADD_INVALID || (mutator_check == MUT_ACCADD_VALID && IS_CLIENT(targ)))
130 if(DIFF_TEAM(attacker, targ))
135 float accuracy_canbegooddamage(entity attacker)