]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/items/inventory.qh
Key Hunt: when warmup ends kill the "missing teams" message and start the round start...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / items / inventory.qh
1 #pragma once
2
3 #include "all.qh"
4 #include "item/pickup.qh"
5
6 CLASS(Inventory, Object)
7     /** Stores counts of items, the id being the index */
8     ATTRIBARRAY(Inventory, inv_items, int, Items_MAX);
9     /** Previous state */
10     ATTRIB(Inventory, inventory, Inventory);
11 ENDCLASS(Inventory)
12
13 /** Player inventory */
14 .Inventory inventory;
15
16 REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY)
17
18 #ifdef CSQC
19 NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
20 {
21     make_pure(this);
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);
28     });
29     return true;
30 }
31 #endif
32
33 #ifdef SVQC
34 void Inventory_Write(Inventory data)
35 {
36     if (!data) {
37         WriteInt24_t(MSG_ENTITY, 0);
38         return;
39     }
40     TC(Inventory, data);
41     int bits = 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)));
45     });
46     WriteInt24_t(MSG_ENTITY, bits);
47     FOREACH(Items, bits & BIT(it.m_id), {
48         WriteByte(MSG_ENTITY, data.inv_items[it.m_id]);
49     });
50 }
51 #endif
52
53 #ifdef SVQC
54 bool Inventory_Send(Inventory this, Client to, int sf)
55 {
56     TC(Inventory, this);
57     WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY);
58     entity e = this.owner;
59     if (IS_SPEC(e)) e = e.enemy;
60     TC(Player, e);
61     Inventory data = e.inventory;
62     Inventory_Write(data);
63     return true;
64 }
65
66 void Inventory_new(entity e)
67 {
68     Inventory inv = NEW(Inventory), bak = NEW(Inventory);
69     inv.inventory = bak;
70     inv.drawonlytoclient = e;
71     Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send);
72 }
73 void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); }
74 void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }
75 #endif