]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/accuracy.qc
Merge remote-tracking branch 'origin/divVerent/allow-override-item-model'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / accuracy.qc
index c2a68d723eb0081e4d1e0464d315b69b1f1e6942..de6b52752b95b358503e9fdd1a846377bd4f6bc6 100644 (file)
@@ -1,14 +1,16 @@
-.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)
 {
-       if(d == 0)
+       //print(sprintf("accuracy: %d / %d\n", n, d));
+       if(n <= 0)
                return 0;
-       return 1.0 + rint(n * 254.0 / d);
+       if(n > d)
+               return 255;
+       return 1 + rint(n * 100.0 / d);
 }
 
 float accuracy_send(entity to, float sf)
@@ -60,7 +62,7 @@ void accuracy_resend(entity e)
 }
 
 // update accuracy stats
-void accuracy_set(entity e, float w, float hit, float fired)
+void accuracy_set(entity e, float w, float fired, float hit)
 {
        entity a;
        float b;
@@ -71,6 +73,11 @@ void accuracy_set(entity e, float w, float hit, float fired)
        b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
        a.(accuracy_hit[w]) = hit;
        a.(accuracy_fired[w]) = fired;
+
+    if(hit)
+        a.(accuracy_cnt_hit[w]) = 1;
+    a.(accuracy_cnt_fired[w]) = 1;
+
        if(b == accuracy_byte(hit, fired))
                return;
        w = pow(2, w);
@@ -81,7 +88,10 @@ 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 hit_time;
+.float fired_time;
+
+void accuracy_add(entity e, float w, float fired, float hit)
 {
        entity a;
        float b;
@@ -94,6 +104,19 @@ void accuracy_add(entity e, float w, float hit, float fired)
                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, w);