]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/ent_cs.qc
Purge most cases of self from the client folder
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / ent_cs.qc
index bb716ca3b8970af0f4ffbf3b758e07e5042f829e..ff67a72cdc21a0c5cf398a16de87918200ea64df 100644 (file)
                e.nextthink = time;
                Net_LinkEntity(e, false, 0, entcs_send);
                if (!IS_REAL_CLIENT(player)) return;
-               FOR_EACH_CLIENT(e)
-               {
-                       assert(e.entcs);
-                       _entcs_send(e.entcs, msg_entity = player, BITS(23), MSG_ONE);
-               }
+               FOREACH_CLIENT(true, LAMBDA(
+                       assert(it.entcs);
+                       _entcs_send(it.entcs, msg_entity = player, BITS(23), MSG_ONE);
+               ));
        }
 
        void entcs_detach(entity player)
 
 #ifdef CSQC
 
-       void Ent_RemoveEntCS()
+       void Ent_RemoveEntCS(entity this)
        {
-               SELFPARAM();
-               entcs_receiver(this.sv_entnum, NULL);
+               int n = this.sv_entnum;
+               entity e = entcs_receiver(n);
+               entcs_receiver(n, NULL);
+               if (e != this) remove(e);
        }
 
        void entcs_think()
        bool ReadEntcs(entity this)
        {
                int n = ReadByte();
-               if (this) this.sv_entnum = n;
                entity e = entcs_receiver(n);
-               if (!e)
+               if (e == NULL)
                {
                        if (this)
                        {
                        {
                                e = new(entcs_receiver);
                                make_pure(e);
-                               e.think = entcs_think;
                        }
+                       e.sv_entnum = n;
+                       e.think = entcs_think;
                        entcs_receiver(n, e);
                }
+               else if (this && e != this)
+               {
+                       this.classname = "entcs_gc";
+                       this.sv_entnum = n;
+               }
                this = e;
                InterpolateOrigin_Undo(this);
                this.sv_entnum = n;
        #undef X
                this.iflags |= IFLAG_ORIGIN;
                InterpolateOrigin_Note(this);
-               this.think();
+               WITH(entity, self, this, this.think());
                return true;
        }