1 float accuracy_byte(float n, float d)
3 //printf("accuracy: %d / %d\n", n, d);
8 return 1 + rint(n * 100.0 / d);
11 float accuracy_send(entity to, float sf)
15 WriteByte(MSG_ENTITY, ENT_CLIENT_ACCURACY);
23 if (!(self.owner.cvar_cl_accuracy_data_share && autocvar_sv_accuracy_data_share))
25 // note: zero sendflags can never be sent... so we can use that to say that we send no accuracy!
26 WriteInt24_t(MSG_ENTITY, sf);
29 // note: we know that client and server agree about SendFlags...
30 for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w)
33 WriteByte(MSG_ENTITY, accuracy_byte(self.(accuracy_hit[w]), self.(accuracy_fired[w])));
43 void accuracy_init(entity e)
47 e.accuracy.classname = "accuracy";
48 e.accuracy.drawonlytoclient = e;
49 Net_LinkEntity(e.accuracy, FALSE, 0, accuracy_send);
52 void accuracy_free(entity e)
57 // force a resend of a player's accuracy stats
58 void accuracy_resend(entity e)
60 e.accuracy.SendFlags = 0xFFFFFF;
63 // update accuracy stats
67 void accuracy_add(entity e, float w, float fired, float hit)
71 if(IS_INDEPENDENT_PLAYER(e))
74 if(!a || !(hit || fired))
77 b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
79 a.(accuracy_hit[w]) += hit;
81 a.(accuracy_fired[w]) += fired;
83 if(hit && a.hit_time != time) // only run this once per frame
85 a.(accuracy_cnt_hit[w]) += 1;
89 if(fired && a.fired_time != time) // only run this once per frame
91 a.(accuracy_cnt_fired[w]) += 1;
95 if(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])))
97 w = pow(2, mod(w, 24));
105 float accuracy_isgooddamage(entity attacker, entity targ)
107 frag_attacker = attacker;
109 float mutator_check = MUTATOR_CALLHOOK(AccuracyTargetValid);
112 if(targ.deadflag == DEAD_NO)
113 if(mutator_check == MUT_ACCADD_INVALID || (mutator_check == MUT_ACCADD_VALID && IS_CLIENT(targ)))
114 if(DIFF_TEAM(attacker, targ))
119 float accuracy_canbegooddamage(entity attacker)