3 #include "../mutators/mutators_include.qh"
4 #include "../../common/constants.qh"
5 #include "../../common/teams.qh"
6 #include "../../common/util.qh"
7 #include "../../common/weapons/all.qh"
9 float accuracy_byte(float n, float d)
11 //printf("accuracy: %d / %d\n", n, d);
16 return 1 + rint(n * 100.0 / d);
19 bool accuracy_send(entity this, entity to, int sf)
23 WriteByte(MSG_ENTITY, ENT_CLIENT_ACCURACY);
31 if (!(self.owner.cvar_cl_accuracy_data_share && autocvar_sv_accuracy_data_share))
33 // note: zero sendflags can never be sent... so we can use that to say that we send no accuracy!
34 WriteInt24_t(MSG_ENTITY, sf);
37 // note: we know that client and server agree about SendFlags...
38 for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w)
41 WriteByte(MSG_ENTITY, accuracy_byte(self.(accuracy_hit[w]), self.(accuracy_fired[w])));
51 void accuracy_init(entity e)
55 e.accuracy.classname = "accuracy";
56 e.accuracy.drawonlytoclient = e;
57 Net_LinkEntity(e.accuracy, false, 0, accuracy_send);
60 void accuracy_free(entity e)
65 // force a resend of a player's accuracy stats
66 void accuracy_resend(entity e)
68 e.accuracy.SendFlags = 0xFFFFFF;
71 // update accuracy stats
75 void accuracy_add(entity e, int w, float fired, float hit)
79 if(IS_INDEPENDENT_PLAYER(e))
82 if(!a || !(hit || fired))
85 b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
87 a.(accuracy_hit[w]) += hit;
89 a.(accuracy_fired[w]) += fired;
91 if(hit && a.hit_time != time) // only run this once per frame
93 a.(accuracy_cnt_hit[w]) += 1;
97 if(fired && a.fired_time != time) // only run this once per frame
99 a.(accuracy_cnt_fired[w]) += 1;
103 if(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])))
113 float accuracy_isgooddamage(entity attacker, entity targ)
115 float mutator_check = MUTATOR_CALLHOOK(AccuracyTargetValid, attacker, targ);
118 if(targ.deadflag == DEAD_NO)
120 if(mutator_check == MUT_ACCADD_INVALID || (mutator_check == MUT_ACCADD_VALID && IS_CLIENT(targ)))
121 if(DIFF_TEAM(attacker, targ))
126 float accuracy_canbegooddamage(entity attacker)