X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fitems%2Finventory.qh;h=f748dda88405d286d73cb0eab68f84431eda96ff;hb=4ad2a6a38665318e08c8ba401b0a2fdb08bd524a;hp=89abc97cff2a82f252cca4730061a367b741c354;hpb=88713a575bd27dabc5926d636542b6145ab6f51c;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index 89abc97cf..f748dda88 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -6,21 +6,25 @@ entityclass(Inventory); /** Stores counts of items, the id being the index */ -class(Inventory) .int inv_items[MAX_ITEMS]; +class(Inventory) .int inv_items[Items_MAX]; /** Player inventory; Inventories also have one inventory for storing the previous state */ .Inventory inventory; +REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY) + #ifdef CSQC -void Inventory_Read(Inventory data) +NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) { + make_pure(this); const int bits = ReadInt24_t(); - ITEMS_FOREACH(bits & BIT(i), LAMBDA({ - .int fld = inv_items[i]; - int prev = data.(fld); - int next = data.(fld) = ReadByte(); - dprintf("%s: %.0f -> %.0f\n", ITEMS[i].m_name, prev, next); - })); + FOREACH(Items, bits & BIT(it.m_id), LAMBDA( + .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); + )); + return true; } #endif @@ -28,21 +32,21 @@ void Inventory_Read(Inventory data) void Inventory_Write(Inventory data) { int bits = 0; - ITEMS_FOREACH(true, LAMBDA({ - .int fld = inv_items[i]; - bits = BITSET(bits, BIT(i), data.inventory.(fld) != (data.inventory.(fld) = data.(fld))); - })); + FOREACH(Items, true, LAMBDA( + .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); - ITEMS_FOREACH(bits & BIT(i), LAMBDA({ - WriteByte(MSG_ENTITY, data.inv_items[i]); - })); + FOREACH(Items, bits & BIT(it.m_id), LAMBDA( + WriteByte(MSG_ENTITY, data.inv_items[it.m_id]); + )); } #endif #ifdef SVQC -bool Inventory_Send(entity to, int sf) +bool Inventory_Send(entity this, entity to, int sf) { - WriteByte(MSG_ENTITY, ENT_CLIENT_INVENTORY); + WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY); entity e = self.owner; if (IS_SPEC(e)) e = e.enemy; Inventory data = e.inventory; @@ -53,7 +57,7 @@ bool Inventory_Send(entity to, int sf) void Inventory_new(entity e) { Inventory inv = new(Inventory), bak = new(Inventory); - inv.classname = "inventory", bak.classname = "inventory"; + make_pure(inv); make_pure(bak); inv.inventory = bak; inv.drawonlytoclient = e; Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send);