X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fitems%2Finventory.qh;h=22a4d94c387335f833d0867f2acb1df01e776663;hb=415aa53e6a5e50a97d95e14f48fb3589f04f64d5;hp=ca53f718d1ae2462f780dfd262f1d26b347e2989;hpb=90d9f7c775306324957323d53d5a4ad995d999e3;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index ca53f718d..22a4d94c3 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -6,12 +6,12 @@ CLASS(Inventory, Object) /** Stores counts of items, the id being the index */ ATTRIBARRAY(Inventory, inv_items, int, REGISTRY_MAX(Items)); - /** Previous state */ - ATTRIB(Inventory, inventory, Inventory); ENDCLASS(Inventory) /** Player inventory */ .Inventory inventory; +/** Player inventory storage (holds previous state) */ +.Inventory inventory_store; REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY) @@ -38,10 +38,17 @@ STATIC_INIT(Inventory) #ifdef CSQC Inventory g_inventory; +void Inventory_remove(entity this) +{ + if(g_inventory == this) + g_inventory = NULL; +} + NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) { make_pure(this); g_inventory = this; + this.entremove = Inventory_remove; const int majorBits = Readbits(Inventory_groups_major); for (int i = 0; i < Inventory_groups_major; ++i) { if (!(majorBits & BIT(i))) { @@ -65,7 +72,7 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) #ifdef SVQC int minorBitsArr[Inventory_groups_major]; -void Inventory_Write(Inventory data) +void Inventory_Write(Inventory data, Inventory store) { if (!data) { WriteShort(MSG_ENTITY, 0); @@ -79,7 +86,8 @@ void Inventory_Write(Inventory data) int majorBits = 0; FOREACH(Items, true, { .int fld = inv_items[it.m_id]; - const bool changed = data.inventory.(fld) != data.(fld); + const bool changed = store.(fld) != data.(fld); + store.(fld) = data.(fld); if (changed) { int maj = G_MAJOR(it.m_id); majorBits = BITSET(majorBits, BIT(maj), true); @@ -116,7 +124,7 @@ bool Inventory_Send(Inventory this, Client to, int sf) TC(Inventory, this); WriteHeader(MSG_ENTITY, ENT_CLIENT_INVENTORY); TC(PlayerState, this.owner); - Inventory_Write(this); + Inventory_Write(this, to.inventory_store); return true; } @@ -128,11 +136,25 @@ bool Inventory_customize(entity this, entity client) void Inventory_new(PlayerState this) { - Inventory inv = NEW(Inventory), bak = NEW(Inventory); - inv.inventory = bak; + Inventory inv = NEW(Inventory); setcefc(inv, Inventory_customize); - Net_LinkEntity((inv.owner = this).inventory = inv, false, 0, Inventory_Send); + this.inventory = inv; + inv.owner = this; + Net_LinkEntity(inv, false, 0, Inventory_Send); } -void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); } +void Inventory_delete(entity e) { delete(e.inventory); } void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; } + +void Inventory_clear(entity store) +{ + // NOTE: you will need to perform Inventory_update after this to update the storage entity + // (unless store is the storage entity) + FOREACH(Items, true, { + .int fld = inv_items[it.m_id]; + store.(fld) = 0; + }); +} + +void InventoryStorage_attach(entity e) { e.inventory_store = NEW(Inventory); e.inventory_store.drawonlytoclient = e; } +void InventoryStorage_delete(entity e) { delete(e.inventory_store); } #endif