5 #include "item/pickup.qh"
7 entityclass(Inventory);
8 /** Stores counts of items, the id being the index */
9 class(Inventory) .int inv_items[MAX_ITEMS];
11 /** Player inventory; Inventories also have one inventory for storing the previous state */
15 void Inventory_Read(Inventory data)
17 const int bits = ReadInt24_t();
18 ITEMS_FOREACH(bits & BIT(i), LAMBDA({
19 int prev = data.inv_items[i];
20 int next = data.inv_items[i] = ReadByte();
21 dprintf("%s: %.0f -> %.0f\n", ITEMS[i].m_name, prev, next);
27 void Inventory_Write(Inventory data)
30 ITEMS_FOREACH(true, LAMBDA({
31 .int idx = inv_items[i];
32 bits = BITSET(bits, BIT(i), data.inventory.(idx) != (data.inventory.(idx) = data.(idx)));
34 WriteInt24_t(MSG_ENTITY, bits);
35 ITEMS_FOREACH(bits & BIT(i), LAMBDA({
36 WriteByte(MSG_ENTITY, data.inv_items[i]);
42 bool Inventory_Send(entity to, int sf)
44 WriteByte(MSG_ENTITY, ENT_CLIENT_INVENTORY);
45 entity e = self.owner;
46 if (IS_SPEC(e)) e = e.enemy;
47 Inventory data = e.inventory;
48 Inventory_Write(data);
52 void Inventory_new(entity e)
54 Inventory inv = new(Inventory), bak = new(Inventory);
55 inv.classname = "inventory", bak.classname = "inventory";
57 inv.drawonlytoclient = e;
58 Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send);
60 void Inventory_delete(entity e) { remove(e.inventory.inventory); remove(e.inventory); }
61 void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }