]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/items/inventory.qh
Merge branch 'terencehill/bot_waypoints'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items / inventory.qh
index a022979a7065f7ee07c8cdfb0fc94c3ab9a0038a..2ec0cdb7b1cb367ede1ea9903235df2461580bd7 100644 (file)
@@ -1,7 +1,6 @@
 #pragma once
 
 #include "all.qh"
-#include "item/pickup.qh"
 
 CLASS(Inventory, Object)
     /** Stores counts of items, the id being the index */
@@ -22,9 +21,11 @@ const int Inventory_groups_minor = 8; // ceil(Items_MAX / Inventory_groups_major
 #define G_MINOR(id) ((id) % Inventory_groups_minor)
 
 #ifdef CSQC
+Inventory g_inventory;
 NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
 {
     make_pure(this);
+    g_inventory = this;
     const int majorBits = ReadShort();
     for (int i = 0; i < Inventory_groups_major; ++i) {
         if (!(majorBits & BIT(i))) {
@@ -81,7 +82,7 @@ void Inventory_Write(Inventory data)
             if (!(minorBits & BIT(j))) { \
                 continue; \
             } \
-            const GameItem it = Items_from(Inventory_groups_minor * maj + j); \
+            const entity it = Items_from(Inventory_groups_minor * maj + j); \
             WriteByte(MSG_ENTITY, data.inv_items[it.m_id]); \
         } \
     } \
@@ -105,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 = e.enemy;
-    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 = e;
-    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; }