From: Mario Date: Sat, 5 Dec 2020 09:13:46 +0000 (+1000) Subject: Reuse the inventory clear function for map resets X-Git-Tag: xonotic-v0.8.5~588^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3abecbbfab3bccc2342d508e2f8814648cadb3bf;p=xonotic%2Fxonotic-data.pk3dir.git Reuse the inventory clear function for map resets --- diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index 3ffa6c003..abc367d51 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -143,14 +143,16 @@ void Inventory_new(PlayerState this) void Inventory_delete(entity e) { delete(e.inventory); } void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; } -void InventoryStorage_attach(entity e) { e.inventory_store = NEW(Inventory); e.inventory_store.drawonlytoclient = e; } -void InventoryStorage_delete(entity e) { delete(e.inventory_store); } -void InventoryStorage_clear(entity e) +void Inventory_clear(entity store) { - // we don't need to network the changes, that is done when the inventory is detached + // 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]; - e.inventory_store.(fld) = 0; + 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 diff --git a/qcsrc/common/state.qc b/qcsrc/common/state.qc index 406003efc..3060a51aa 100644 --- a/qcsrc/common/state.qc +++ b/qcsrc/common/state.qc @@ -4,9 +4,9 @@ void Inventory_new(PlayerState this); void Inventory_delete(entity this); +void Inventory_clear(PlayerState this); void InventoryStorage_attach(PlayerState this); void InventoryStorage_delete(PlayerState this); -void InventoryStorage_clear(PlayerState this); void PlayerState_attach(entity this) { @@ -23,7 +23,7 @@ void PlayerState_detach(entity this) PlayerState ps = PS(this); if (!ps) return; // initial connect PS(this) = NULL; - InventoryStorage_clear(this); + Inventory_clear(this.inventory_store); // no need to network updates, as there is no inventory attached if (ps.m_client != this) return; // don't own state, spectator ps.ps_push(ps, this); diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index 7b3818f74..1167e56a4 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -355,8 +355,7 @@ void reset_map(bool dorespawn) entity store = PS(it); if (store) { - for (int j = 0; j < REGISTRY_COUNT(Items); j++) - store.inventory.inv_items[j] = 0; + Inventory_clear(store.inventory); Inventory_update(store); } });