X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fitems%2Finventory.qh;h=2ec0cdb7b1cb367ede1ea9903235df2461580bd7;hb=8639f042c5ef61287b2f7e0dbf17f8c08a2c0ebf;hp=a022979a7065f7ee07c8cdfb0fc94c3ab9a0038a;hpb=b834eab77489d98d5d722d67c8a96cf6c3549436;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index a022979a7..2ec0cdb7b 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -1,7 +1,6 @@ #pragma once #include "all.qh" -#include "item/pickup.qh" CLASS(Inventory, Object) /** Stores counts of items, the id being the index */ @@ -22,9 +21,11 @@ const int Inventory_groups_minor = 8; // ceil(Items_MAX / Inventory_groups_major #define G_MINOR(id) ((id) % Inventory_groups_minor) #ifdef CSQC +Inventory g_inventory; NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) { make_pure(this); + g_inventory = this; const int majorBits = ReadShort(); for (int i = 0; i < Inventory_groups_major; ++i) { if (!(majorBits & BIT(i))) { @@ -81,7 +82,7 @@ void Inventory_Write(Inventory data) if (!(minorBits & BIT(j))) { \ continue; \ } \ - const GameItem it = Items_from(Inventory_groups_minor * maj + j); \ + const entity it = Items_from(Inventory_groups_minor * maj + j); \ WriteByte(MSG_ENTITY, data.inv_items[it.m_id]); \ } \ } \ @@ -105,20 +106,23 @@ bool Inventory_Send(Inventory this, Client to, int sf) { TC(Inventory, this); WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY); - entity e = this.owner; - if (IS_SPEC(e)) e = e.enemy; - TC(Player, e); - Inventory data = e.inventory; - Inventory_Write(data); + TC(PlayerState, this.owner); + Inventory_Write(this); return true; } -void Inventory_new(entity e) +bool Inventory_customize(entity this, entity client) +{ + // sends to spectators too! + return (PS(client) && PS(client).inventory == this); +} + +void Inventory_new(PlayerState this) { Inventory inv = NEW(Inventory), bak = NEW(Inventory); inv.inventory = bak; - inv.drawonlytoclient = e; - Net_LinkEntity((inv.owner = e).inventory = inv, false, 0, Inventory_Send); + setcefc(inv, Inventory_customize); + Net_LinkEntity((inv.owner = this).inventory = inv, false, 0, Inventory_Send); } void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); } void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }