]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up inventory creation code a bit so that it's somewhat spectatable
authorMario <mario@smbclan.net>
Thu, 25 Oct 2018 22:41:14 +0000 (08:41 +1000)
committerMario <mario@smbclan.net>
Thu, 25 Oct 2018 22:41:14 +0000 (08:41 +1000)
qcsrc/common/items/inventory.qh
qcsrc/common/state.qc

index ba824f40b41c14c470a214c33eeb0bd6e9064c4d..2ec0cdb7b1cb367ede1ea9903235df2461580bd7 100644 (file)
@@ -106,20 +106,23 @@ bool Inventory_Send(Inventory this, Client to, int sf)
 {
     TC(Inventory, this);
     WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY);
-    entity e = this.owner;
-    if (IS_SPEC(e)) e = PS(e.enemy); // TODO: how can this *ever* be the case?
-    TC(Player, e);
-    Inventory data = e.inventory;
-    Inventory_Write(data);
+    TC(PlayerState, this.owner);
+    Inventory_Write(this);
     return true;
 }
 
-void Inventory_new(entity e)
+bool Inventory_customize(entity this, entity client)
+{
+    // sends to spectators too!
+    return (PS(client) && PS(client).inventory == this);
+}
+
+void Inventory_new(PlayerState this)
 {
     Inventory inv = NEW(Inventory), bak = NEW(Inventory);
     inv.inventory = bak;
-    inv.drawonlytoclient = IS_CLIENT(e) ? e : e.m_client;
-    Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send);
+    setcefc(inv, Inventory_customize);
+    Net_LinkEntity((inv.owner = this).inventory = inv, false, 0, Inventory_Send);
 }
 void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); }
 void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }
index 2e3a262a59e9662c2456e77a7277f2cb9bd9acef..fc3530744c2a693cc5cb20100e568c78ab517845 100644 (file)
@@ -1,6 +1,6 @@
 #include "state.qh"
 
-void Inventory_new(entity this);
+void Inventory_new(PlayerState this);
 void Inventory_delete(entity this);
 
 void PlayerState_attach(entity this)