X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Faccuracy.qc;h=4d63fd82002dcb9ea176cfabdedd43f3d4bd5db1;hb=406b13f464e47f8ca373b6bbe8ebe3bfc0f6be44;hp=30f9e18d2682de503504d566d76523dcb4074709;hpb=a8e1017ded352efb6f9189cfd735c5fdbdec671d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/accuracy.qc b/qcsrc/server/accuracy.qc index 30f9e18d2..4d63fd820 100644 --- a/qcsrc/server/accuracy.qc +++ b/qcsrc/server/accuracy.qc @@ -4,6 +4,16 @@ FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_hit); FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_fired); +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) { float w, f; @@ -26,12 +36,7 @@ float accuracy_send(entity to, float sf) for(w = 0, f = 1; w <= WEP_LAST - WEP_FIRST; ++w, f *= 2) { 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]))); } return TRUE; } @@ -42,8 +47,8 @@ void accuracy_init(entity e) e.accuracy = spawn(); e.accuracy.owner = e; e.accuracy.classname = "accuracy"; - e.accuracy.SendEntity = accuracy_send; e.accuracy.drawonlytoclient = e; + Net_LinkEntity(e.accuracy, FALSE, 0, accuracy_send); } void accuracy_free(entity e) @@ -58,15 +63,19 @@ 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; a = e.accuracy; if(!a) return; w -= WEP_FIRST; + b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])); a.(accuracy_hit[w]) = hit; a.(accuracy_fired[w]) = fired; + if(b == accuracy_byte(hit, fired)) + return; w = pow(2, w); a.SendFlags |= w; FOR_EACH_CLIENT(a) @@ -75,15 +84,21 @@ 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) +void accuracy_add(entity e, float w, float fired, float hit) { entity a; + float b; a = e.accuracy; - if(!a) + if(!a || !(hit || fired)) return; w -= WEP_FIRST; - a.(accuracy_hit[w]) += hit; - a.(accuracy_fired[w]) += fired; + 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(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]))) + return; w = pow(2, w); a.SendFlags |= w; FOR_EACH_CLIENT(a) @@ -91,3 +106,20 @@ void accuracy_add(entity e, float w, float hit, float fired) if(a.enemy == e) a.SendFlags |= w; } + +float accuracy_isgooddamage(entity attacker, entity targ) +{ + 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; +}