4 #include "../mutators/mutators_include.qh"
5 #include "../../common/constants.qh"
6 #include "../../common/teams.qh"
7 #include "../../common/util.qh"
8 #include "../../common/weapons/weapons.qh"
10 float accuracy_byte(float n, float d)
12 //printf("accuracy: %d / %d\n", n, d);
17 return 1 + rint(n * 100.0 / d);
20 float accuracy_send(entity to, int sf)
24 WriteByte(MSG_ENTITY, ENT_CLIENT_ACCURACY);
32 if (!(self.owner.cvar_cl_accuracy_data_share && autocvar_sv_accuracy_data_share))
34 // note: zero sendflags can never be sent... so we can use that to say that we send no accuracy!
35 WriteInt24_t(MSG_ENTITY, sf);
38 // note: we know that client and server agree about SendFlags...
39 for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w)
42 WriteByte(MSG_ENTITY, accuracy_byte(self.(accuracy_hit[w]), self.(accuracy_fired[w])));
52 void accuracy_init(entity e)
56 e.accuracy.classname = "accuracy";
57 e.accuracy.drawonlytoclient = e;
58 Net_LinkEntity(e.accuracy, false, 0, accuracy_send);
61 void accuracy_free(entity e)
66 // force a resend of a player's accuracy stats
67 void accuracy_resend(entity e)
69 e.accuracy.SendFlags = 0xFFFFFF;
72 // update accuracy stats
76 void accuracy_add(entity e, int w, float fired, float hit)
80 if(IS_INDEPENDENT_PLAYER(e))
83 if(!a || !(hit || fired))
86 b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
88 a.(accuracy_hit[w]) += hit;
90 a.(accuracy_fired[w]) += fired;
92 if(hit && a.hit_time != time) // only run this once per frame
94 a.(accuracy_cnt_hit[w]) += 1;
98 if(fired && a.fired_time != time) // only run this once per frame
100 a.(accuracy_cnt_fired[w]) += 1;
104 if(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])))
114 float accuracy_isgooddamage(entity attacker, entity targ)
116 frag_attacker = attacker;
118 float mutator_check = MUTATOR_CALLHOOK(AccuracyTargetValid);
121 if(targ.deadflag == DEAD_NO)
123 if(mutator_check == MUT_ACCADD_INVALID || (mutator_check == MUT_ACCADD_VALID && IS_CLIENT(targ)))
124 if(DIFF_TEAM(attacker, targ))
129 float accuracy_canbegooddamage(entity attacker)