14 .Inventory inventory_store;
18 const int Inventory_groups_minor = 8;
19 const int Inventory_groups_major = 4;
26 if (Inventory_groups_minor / 8 !=
floor(Inventory_groups_minor / 8))
27 error(
"Inventory_groups_minor is not a multiple of 8.");
29 if (Inventory_groups_major < min_major_value)
30 error(sprintf(
"Inventory_groups_major can not be < %d.", min_major_value));
35 #define G_MAJOR(id) (floor((id) / Inventory_groups_minor)) 36 #define G_MINOR(id) ((id) % Inventory_groups_minor) 40 Inventory g_inventory;
41 void Inventory_remove(
entity this)
43 if(g_inventory ==
this)
51 this.entremove = Inventory_remove;
52 const int majorBits = Readbits(Inventory_groups_major);
53 for (
int i = 0; i < Inventory_groups_major; ++i) {
54 if (!(majorBits &
BIT(i))) {
57 const int minorBits = Readbits(Inventory_groups_minor);
58 for (
int j = 0; j < Inventory_groups_minor; ++j) {
59 if (!(minorBits &
BIT(j))) {
63 .int fld = inv_items[it.
m_id];
64 int prev = this.(fld);
65 int next = this.(fld) = ReadByte();
66 LOG_DEBUGF(
"%s: %.0f -> %.0f", it.m_name, prev, next);
74 int minorBitsArr[Inventory_groups_major];
75 void Inventory_Write(Inventory data, Inventory store)
83 for (
int i = 0; i < Inventory_groups_major; ++i)
88 .int fld = inv_items[it.m_id];
89 const bool changed = store.(fld) != data.(fld);
90 store.(fld) = data.(fld);
92 int maj = G_MAJOR(it.m_id);
93 majorBits =
BITSET(majorBits,
BIT(maj),
true);
94 minorBitsArr[maj] =
BITSET(minorBitsArr[maj],
BIT(G_MINOR(it.m_id)),
true);
98 Writebits(MSG_ENTITY, majorBits, Inventory_groups_major);
99 for (
int i = 0; i < Inventory_groups_major; ++i)
101 if (!(majorBits &
BIT(i)))
104 const int minorBits = minorBitsArr[i];
105 Writebits(MSG_ENTITY, minorBits, Inventory_groups_minor);
106 for (
int j = 0; j < Inventory_groups_minor; ++j)
108 if (!(minorBits &
BIT(j)))
112 WriteByte(MSG_ENTITY, data.inv_items[it.m_id]);
122 bool Inventory_Send(Inventory
this,
Client to,
int sf)
125 WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY);
127 Inventory_Write(
this, to.inventory_store);
134 return (
PS(client) &&
PS(client).inventory ==
this);
139 Inventory inv =
NEW(Inventory);
140 setcefc(inv, Inventory_customize);
141 this.inventory = inv;
143 Net_LinkEntity(inv,
false, 0, Inventory_Send);
146 void Inventory_update(
entity e) { e.inventory.SendFlags = 0xFFFFFF; }
153 .int fld = inv_items[it.m_id];
#define REGISTER_NET_LINKED(id)
void InventoryStorage_delete(PlayerState this)
#define REGISTRY_GET(id, i)
#define NET_HANDLE(id, param)
#define STATIC_INIT(func)
during worldspawn
#define REGISTRY_COUNT(id)
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
#define BITSET(var, mask, flag)
Purpose: common player state, usable on client and server Client: singleton representing the viewed p...
void Inventory_clear(PlayerState this)
void Inventory_new(PlayerState this)
void Inventory_delete(entity this)
void InventoryStorage_attach(PlayerState this)
#define ATTRIBARRAY(cname, name, type, cnt)
#define FOREACH(list, cond, body)