]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Reuse the inventory clear function for map resets
authorMario <zacjardine@y7mail.com>
Sat, 5 Dec 2020 09:13:46 +0000 (19:13 +1000)
committerMario <zacjardine@y7mail.com>
Sat, 5 Dec 2020 09:13:46 +0000 (19:13 +1000)
qcsrc/common/items/inventory.qh
qcsrc/common/state.qc
qcsrc/server/command/vote.qc

index 3ffa6c003d63155fd6c3f4dd2450cc04a779089e..abc367d51389615815274c79100f7a462e208e31 100644 (file)
@@ -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
index 406003efcb0ab36e3bf7a48ded846b6ac63d4287..3060a51aa5f40e29c5af984bad43d96b92bf702b 100644 (file)
@@ -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);
index 7b3818f74f14e8d1030c561e9395e07fd8013a41..1167e56a4acb1cc21e436181fb30b537e71c2803 100644 (file)
@@ -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);
                }
        });