]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/items/inventory.qh
Fix PlayerState ownership
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items / inventory.qh
index 7780a0054551c59d50150da9d0e6a5c8c90122be..96c7319b7d0fbb9ae0e8a1e674aebb668036f146 100644 (file)
@@ -4,11 +4,14 @@
 #include "all.qh"
 #include "item/pickup.qh"
 
-entityclass(Inventory);
-/** Stores counts of items, the id being the index */
-class(Inventory) .int inv_items[Items_MAX];
+CLASS(Inventory, Object)
+    /** Stores counts of items, the id being the index */
+    ATTRIBARRAY(Inventory, inv_items, int, Items_MAX)
+    /** Previous state */
+    ATTRIB(Inventory, inventory, Inventory, NULL)
+ENDCLASS(Inventory)
 
-/** Player inventory; Inventories also have one inventory for storing the previous state */
+/** Player inventory */
 .Inventory inventory;
 
 REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY)
@@ -31,6 +34,7 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
 #ifdef SVQC
 void Inventory_Write(Inventory data)
 {
+    TC(Inventory, data);
     int bits = 0;
     FOREACH(Items, true, {
         .int fld = inv_items[it.m_id];
@@ -44,11 +48,13 @@ void Inventory_Write(Inventory data)
 #endif
 
 #ifdef SVQC
-bool Inventory_Send(entity this, entity to, int sf)
+bool Inventory_Send(Inventory this, Client to, int sf)
 {
+    TC(Inventory, this);
     WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY);
-    entity e = self.owner;
+    entity e = this.owner;
     if (IS_SPEC(e)) e = e.enemy;
+    TC(Player, e);
     Inventory data = e.inventory;
     Inventory_Write(data);
     return true;
@@ -56,7 +62,7 @@ bool Inventory_Send(entity this, entity to, int sf)
 
 void Inventory_new(entity e)
 {
-    Inventory inv = new_pure(Inventory), bak = new_pure(Inventory);
+    Inventory inv = NEW(Inventory), bak = NEW(Inventory);
     inv.inventory = bak;
     inv.drawonlytoclient = e;
     Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send);