1 .float accuracy_hit[WEP_MAXCOUNT];
2 .float accuracy_fired[WEP_MAXCOUNT];
3 .float accuracy_cnt_hit[WEP_MAXCOUNT];
4 .float accuracy_cnt_fired[WEP_MAXCOUNT];
6 float accuracy_byte(float n, float d)
8 //print(sprintf("accuracy: %d / %d\n", n, d));
13 return 1 + rint(n * 100.0 / d);
16 float accuracy_send(entity to, float sf)
20 WriteByte(MSG_ENTITY, ENT_CLIENT_ACCURACY);
23 if(a.classname == "spectator")
28 if not(self.owner.cvar_cl_accuracy_data_share && autocvar_sv_accuracy_data_share)
30 // note: zero sendflags can never be sent... so we can use that to say that we send no accuracy!
31 WriteInt24_t(MSG_ENTITY, sf);
34 // note: we know that client and server agree about SendFlags...
35 for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2)
38 WriteByte(MSG_ENTITY, accuracy_byte(self.(accuracy_hit[w]), self.(accuracy_fired[w])));
44 void accuracy_init(entity e)
48 e.accuracy.classname = "accuracy";
49 e.accuracy.drawonlytoclient = e;
50 Net_LinkEntity(e.accuracy, FALSE, 0, accuracy_send);
53 void accuracy_free(entity e)
58 // force a resend of a player's accuracy stats
59 void accuracy_resend(entity e)
61 e.accuracy.SendFlags = 0xFFFFFF;
64 // update accuracy stats
65 void accuracy_set(entity e, float w, float fired, float hit)
73 b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
74 a.(accuracy_hit[w]) = hit;
75 a.(accuracy_fired[w]) = fired;
78 a.(accuracy_cnt_hit[w]) = 1;
79 a.(accuracy_cnt_fired[w]) = 1;
81 if(b == accuracy_byte(hit, fired))
86 if(a.classname == "spectator")
94 void accuracy_add(entity e, float w, float fired, float hit)
99 if(!a || !(hit || fired))
102 b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
104 a.(accuracy_hit[w]) += hit;
106 a.(accuracy_fired[w]) += fired;
108 if(hit && a.hit_time != time) // only run this once per frame
110 a.(accuracy_cnt_hit[w]) += 1;
114 if(fired && a.fired_time != time) // only run this once per frame
116 a.(accuracy_cnt_fired[w]) += 1;
120 if(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])))
125 if(a.classname == "spectator")
130 float accuracy_isgooddamage(entity attacker, entity targ)
133 if(targ.flags & FL_CLIENT)
134 if(targ.deadflag == DEAD_NO)
135 if(IsDifferentTeam(attacker, targ))
140 float accuracy_canbegooddamage(entity attacker)