]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/accuracy.qc
Merge remote-tracking branch 'origin/terencehill/cmd_fixes'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / accuracy.qc
index db5dc6cc5130ac7c17dca8a7993a83a0a3775293..9271e03d0ad20ef4b7e8e9a6536d68b723b40348 100644 (file)
@@ -1,8 +1,17 @@
-.entity accuracy;
 .float accuracy_hit[WEP_MAXCOUNT];
 .float accuracy_fired[WEP_MAXCOUNT];
-FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_hit);
-FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_fired);
+.float accuracy_cnt_hit[WEP_MAXCOUNT];
+.float accuracy_cnt_fired[WEP_MAXCOUNT];
+
+float accuracy_byte(float n, float d)
+{
+       //print(sprintf("accuracy: %d / %d\n", n, d));
+       if(n <= 0)
+               return 0;
+       if(n > d)
+               return 255;
+       return 1 + rint(n * 100.0 / d);
+}
 
 float accuracy_send(entity to, float sf)
 {
@@ -23,15 +32,14 @@ float accuracy_send(entity to, float sf)
        if(sf == 0)
                return TRUE;
        // note: we know that client and server agree about SendFlags...
-       for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2)
+       for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w)
        {
                if(sf & f)
-               {
-                       if(self.(accuracy_fired[w]))
-                               WriteByte(MSG_ENTITY, 0);
-                       else
-                               WriteByte(MSG_ENTITY, 1 + bound(0, (254.0 * self.(accuracy_hit[w])) / self.(accuracy_fired[w]), 254));
-               }
+                       WriteByte(MSG_ENTITY, accuracy_byte(self.(accuracy_hit[w]), self.(accuracy_fired[w])));
+               if(f == 0x800000)
+                       f = 1;
+               else
+                       f *= 2;
        }
        return TRUE;
 }
@@ -58,16 +66,40 @@ void accuracy_resend(entity e)
 }
 
 // update accuracy stats
-void accuracy_set(entity e, float w, float hit, float fired)
+.float hit_time;
+.float fired_time;
+
+void accuracy_add(entity e, float w, float fired, float hit)
 {
        entity a;
+       float b;
+       if(IS_INDEPENDENT_PLAYER(e))
+               return;
        a = e.accuracy;
-       if(!a)
+       if(!a || !(hit || fired))
                return;
        w -= WEP_FIRST;
-       a.(accuracy_hit[w]) = hit;
-       a.(accuracy_fired[w]) = fired;
-       w = pow(2, w);
+       b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
+       if(hit)
+               a.(accuracy_hit[w]) += hit;
+       if(fired)
+               a.(accuracy_fired[w]) += fired;
+
+    if(hit && a.hit_time != time) // only run this once per frame
+    {
+        a.(accuracy_cnt_hit[w]) += 1;
+        a.hit_time = time;
+    }
+
+    if(fired && a.fired_time != time) // only run this once per frame
+    {
+        a.(accuracy_cnt_fired[w]) += 1;
+        a.fired_time = time;
+    }
+
+       if(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])))
+               return;
+       w = pow(2, mod(w, 24));
        a.SendFlags |= w;
        FOR_EACH_CLIENT(a)
                if(a.classname == "spectator")
@@ -75,19 +107,19 @@ void accuracy_set(entity e, float w, float hit, float fired)
                                a.SendFlags |= w;
 }
 
-void accuracy_add(entity e, float w, float hit, float fired)
+float accuracy_isgooddamage(entity attacker, entity targ)
 {
-       entity a;
-       a = e.accuracy;
-       if(!a)
-               return;
-       w -= WEP_FIRST;
-       a.(accuracy_hit[w]) += hit;
-       a.(accuracy_fired[w]) += fired;
-       w = pow(2, w);
-       a.SendFlags |= w;
-       FOR_EACH_CLIENT(a)
-               if(a.classname == "spectator")
-                       if(a.enemy == e)
-                               a.SendFlags |= w;
+       if(!inWarmupStage)
+       if(targ.flags & FL_CLIENT)
+       if(targ.deadflag == DEAD_NO)
+       if(IsDifferentTeam(attacker, targ))
+               return TRUE;
+       return FALSE;
+}
+
+float accuracy_canbegooddamage(entity attacker)
+{
+       if(!inWarmupStage)
+               return TRUE;
+       return FALSE;
 }