4 #include "item/pickup.qh"
6 CLASS(Inventory, Object)
7 /** Stores counts of items, the id being the index */
8 ATTRIBARRAY(Inventory, inv_items, int, Items_MAX);
10 ATTRIB(Inventory, inventory, Inventory);
13 /** Player inventory */
16 REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY)
19 NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
22 const int bits = ReadInt24_t();
23 FOREACH(Items, bits & BIT(it.m_id), {
24 .int fld = inv_items[it.m_id];
25 int prev = this.(fld);
26 int next = this.(fld) = ReadByte();
27 LOG_TRACEF("%s: %.0f -> %.0f", it.m_name, prev, next);
34 void Inventory_Write(Inventory data)
37 WriteInt24_t(MSG_ENTITY, 0);
42 FOREACH(Items, true, {
43 .int fld = inv_items[it.m_id];
44 bits = BITSET(bits, BIT(it.m_id), data.inventory.(fld) != (data.inventory.(fld) = data.(fld)));
46 WriteInt24_t(MSG_ENTITY, bits);
47 FOREACH(Items, bits & BIT(it.m_id), {
48 WriteByte(MSG_ENTITY, data.inv_items[it.m_id]);
54 bool Inventory_Send(Inventory this, Client to, int sf)
57 WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY);
58 entity e = this.owner;
59 if (IS_SPEC(e)) e = e.enemy;
61 Inventory data = e.inventory;
62 Inventory_Write(data);
66 void Inventory_new(entity e)
68 Inventory inv = NEW(Inventory), bak = NEW(Inventory);
70 inv.drawonlytoclient = e;
71 Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send);
73 void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); }
74 void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }