]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_player.qc
ha! got health/armor networking right finally
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_player.qc
index 84d090acc21e9eadc29d86e391612682f67770b6..5f0a08ef78eeddd1d590103222942f86f7b36cbf 100644 (file)
@@ -732,60 +732,53 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        }
 }
 
-void net_shownames(entity selected, float teammate)
+.float the_entnum;
+// sendflags use: 1 = origin, 2 = health/armor, 0x80 = same team (includes health)
+float SendEntity_ShowNames(entity to, float sendflags)
 {
-    float teammate_health, teammate_armor;
-    if(teammate)
+    if(vlen(to.origin - self.origin) < autocvar_sv_shownames_cull_distance) // distance cull
+        return FALSE;
+
+    WriteByte(MSG_ENTITY, ENT_CLIENT_SHOWNAMES);
+    sendflags = sendflags & 127;
+    if(teams_matter && self.owner.team == to.team)
+        sendflags |= 128;
+    else
+        sendflags &~= 2;
+    WriteByte(MSG_ENTITY, sendflags);
+    WriteByte(MSG_ENTITY, self.the_entnum);
+    if(sendflags & 1)
     {
-        teammate_health = selected.health;
-        teammate_armor = selected.armorvalue;
+        WriteShort(MSG_ENTITY, rint(self.origin_x));
+        WriteShort(MSG_ENTITY, rint(self.origin_y));
+        WriteShort(MSG_ENTITY, rint(self.origin_z));
     }
-
-    msg_entity = self;
-       WRITESPECTATABLE_MSG_ONE({
-               WriteByte(MSG_ONE, SVC_TEMPENTITY);
-               WriteByte(MSG_ONE, TE_CSQC_SHOWNAMES);
-               WriteString(MSG_ONE, playername(selected));
-        WriteByte(MSG_ONE, teammate_health);
-        WriteByte(MSG_ONE, teammate_armor);
-        });
+    if(sendflags & 2)
+    {
+        WriteByte(MSG_ENTITY, self.health);
+        WriteByte(MSG_ENTITY, self.armorvalue);
+    }
+    return TRUE;
 }
 
-void UpdateSelectedPlayer()
+void shownames_think()
 {
-    entity selected;
-    selected = world;
-
-       if(!autocvar_sv_allow_shownames)
-               return;
-
-       if(clienttype(self) != CLIENTTYPE_REAL)
-               return;
-
-       if(self.cvar_cl_shownames == 0)
-               return;
-
-       makevectors(self.v_angle); // sets v_forward
-
-       // cursor trace
-       if(self.selected_player_display_timeout < time)
+    if(self.origin != self.owner.origin)
     {
-        WarpZone_crosshair_trace(self);
-        if(trace_ent && trace_ent.classname == "player" && !trace_ent.deadflag)
-        {
-            selected = trace_ent;
-            self.last_selected_player = selected;
-            self.selected_player_display_timeout = time + 0.1; // update at 0.1s intervals
-        }
+        setorigin(self, self.owner.origin);
+        self.SendFlags |= 1;
     }
-
-       if(selected)
-       {
-        if(teams_matter && self.team == selected.team)
-                net_shownames(selected, 1);
-        else
-            net_shownames(selected, 0);
+    if(self.health != floor(self.owner.health) || self.armorvalue != floor(self.owner.armorvalue))
+    {
+        self.health = floor(self.owner.health);
+        self.armorvalue = floor(self.owner.armorvalue);
+        self.SendFlags |= 2;
+    }
+    if(self.the_entnum != num_for_edict(self.owner))
+    {
+        self.the_entnum = num_for_edict(self.owner);
     }
+    self.nextthink = time;
 }
 
 .float muted; // to be used by prvm_edictset server playernumber muted 1