]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Inventory fix
authorz411 <z411@omaera.org>
Thu, 15 Oct 2020 17:06:28 +0000 (14:06 -0300)
committerz411 <z411@omaera.org>
Thu, 15 Oct 2020 17:06:28 +0000 (14:06 -0300)
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/common/items/inventory.qh
qcsrc/common/items/item/pickup.qc
qcsrc/server/command/vote.qc

index f53a29976ab7ff3a2d09566a53a3d52ae5a8d397..84412ec0c46818e707d4ff66014efb4450fac34c 100644 (file)
@@ -1233,7 +1233,9 @@ void Scoreboard_Duel_DrawTable(vector pos, bool invert, entity pl, entity tm)
                
                int weapon_cnt_fired = pl.accuracy_cnt_fired[i - WEP_FIRST];
                int weapon_cnt_hit   = pl.accuracy_cnt_hit[i - WEP_FIRST];
-               int weapon_acc = floor((weapon_cnt_hit / weapon_cnt_fired) * 100);
+               int weapon_acc = 0;
+               if(weapon_cnt_fired)
+                       weapon_acc = floor((weapon_cnt_hit / weapon_cnt_fired) * 100);
                average_acc += weapon_acc;
                
                string draw_str;
@@ -1271,7 +1273,8 @@ void Scoreboard_Duel_DrawTable(vector pos, bool invert, entity pl, entity tm)
                if(weapon_cnt_fired)
                        total_weapons++;
        });
-       average_acc = floor((average_acc / total_weapons) + 0.5);
+       if(total_weapons)
+               average_acc = floor((average_acc / total_weapons) + 0.5);
        
        // draw total accuracy now
        tmp_str = sprintf("%d%%", average_acc);
index f4abe5eb519cc14f67846e04cfa5eff233a9ae4d..761af2a9c29213f9b04d5aa1190f496d822dacad 100644 (file)
@@ -46,6 +46,7 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
        
        float entnum = ReadByte();
        inventoryslots[entnum-1] = this;
+       LOG_INFO("Got inventory");
        
     const int majorBits = Readbits(Inventory_groups_major);
     for (int i = 0; i < Inventory_groups_major; ++i) {
@@ -89,6 +90,7 @@ void Inventory_Write(Inventory data)
                        int maj = G_MAJOR(it.m_id);
                        majorBits = BITSET(majorBits, BIT(maj), true);
                        minorBitsArr[maj] = BITSET(minorBitsArr[maj], BIT(G_MINOR(it.m_id)), true);
+                       data.inventory.(fld) = data.(fld); // z411 fix
         }
     });
 
@@ -145,4 +147,17 @@ void Inventory_new(PlayerState this)
 }
 void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); }
 void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }
+
+void Inventory_ClearAll() {
+       LOG_INFO("Clearing inventory");
+       
+       FOREACH_CLIENT(IS_PLAYER(it), {
+               entity store = PS(it);          
+               FOREACH(Items, true, {
+                       store.inventory.inv_items[it.m_id] = 0;
+               });
+        Inventory_update(store);
+       });
+}
+
 #endif
index a3c2d779edcde089ac3d4f7e142693de8e47070b..aef34cc1bd03955f2c84d21dcf21a50381c54dd8 100644 (file)
@@ -15,6 +15,7 @@ METHOD(Pickup, giveTo, bool(Pickup this, entity item, entity player))
         entity store = IS_PLAYER(player) ? PS(player) : player;
         store.inventory.inv_items[this.m_id]++;
         Inventory_update(store);
+               //store.inventory.inventory.inv_items[this.m_id]++;
     }
     return b;
 }
index c24459762ae225f37d0084b0a0ea287ee55eca3c..edd898546e539dc258e86e9964e703f15f51d987 100644 (file)
@@ -415,6 +415,7 @@ void ReadyRestart_think(entity this)
        restart_mapalreadyrestarted = true;
        reset_map(true);
        Score_ClearAll();
+       Inventory_ClearAll();
        delete(this);
 }
 
@@ -491,7 +492,10 @@ void ReadyRestart()
 
        // Reset ALL scores, but only do that at the beginning of the countdown if sv_ready_restart_after_countdown is off!
        // Otherwise scores could be manipulated during the countdown.
-       if (!sv_ready_restart_after_countdown) Score_ClearAll();
+       if (!sv_ready_restart_after_countdown) {
+               Score_ClearAll();
+               Inventory_ClearAll();
+       }
        ReadyRestart_force();
 }