]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/items/inventory.qh
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items / inventory.qh
index f748dda88405d286d73cb0eab68f84431eda96ff..811f716fb84bccad19e7cf9044c6f56ffafaa0d0 100644 (file)
@@ -1,14 +1,16 @@
-#ifndef INVENTORY_H
-#define INVENTORY_H
+#pragma once
 
 #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);
+ENDCLASS(Inventory)
 
-/** Player inventory; Inventories also have one inventory for storing the previous state */
+/** Player inventory */
 .Inventory inventory;
 
 REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY)
@@ -18,12 +20,12 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
 {
     make_pure(this);
     const int bits = ReadInt24_t();
-    FOREACH(Items, bits & BIT(it.m_id), LAMBDA(
+    FOREACH(Items, bits & BIT(it.m_id), {
         .int fld = inv_items[it.m_id];
         int prev = this.(fld);
         int next = this.(fld) = ReadByte();
-        LOG_TRACEF("%s: %.0f -> %.0f\n", it.m_name, prev, next);
-    ));
+        LOG_TRACEF("%s: %.0f -> %.0f", it.m_name, prev, next);
+    });
     return true;
 }
 #endif
@@ -31,24 +33,31 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
 #ifdef SVQC
 void Inventory_Write(Inventory data)
 {
+    if (!data) {
+        WriteInt24_t(MSG_ENTITY, 0);
+        return;
+    }
+    TC(Inventory, data);
     int bits = 0;
-    FOREACH(Items, true, LAMBDA(
+    FOREACH(Items, true, {
         .int fld = inv_items[it.m_id];
         bits = BITSET(bits, BIT(it.m_id), data.inventory.(fld) != (data.inventory.(fld) = data.(fld)));
-    ));
+    });
     WriteInt24_t(MSG_ENTITY, bits);
-    FOREACH(Items, bits & BIT(it.m_id), LAMBDA(
+    FOREACH(Items, bits & BIT(it.m_id), {
         WriteByte(MSG_ENTITY, data.inv_items[it.m_id]);
-    ));
+    });
 }
 #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,14 +65,11 @@ bool Inventory_Send(entity this, entity to, int sf)
 
 void Inventory_new(entity e)
 {
-    Inventory inv = new(Inventory), bak = new(Inventory);
-    make_pure(inv); make_pure(bak);
+    Inventory inv = NEW(Inventory), bak = NEW(Inventory);
     inv.inventory = bak;
     inv.drawonlytoclient = e;
     Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send);
 }
-void Inventory_delete(entity e) { remove(e.inventory.inventory); remove(e.inventory); }
+void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); }
 void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }
 #endif
-
-#endif