changeset 1708:f8414042db1f

Moving NZIArray to a separate class, fixing a few inventory bugs
author Grumpy7
date Mon, 23 Sep 2013 07:07:06 +0200
parents 5cbd88f8a2eb
children 8251e59fd7c1
files Items.h NZIArray.h Player.cpp mm7_data.h
diffstat 4 files changed, 53 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/Items.h	Sun Sep 22 19:48:02 2013 +0200
+++ b/Items.h	Mon Sep 23 07:07:06 2013 +0200
@@ -1,6 +1,7 @@
 #pragma once
 #include <array>
 #include <map>
+#include "NZIArray.h"
 
 enum DAMAGE_TYPE:unsigned int
     {
@@ -380,7 +381,7 @@
   void Release();
 
   int uAllItemsCount;
-  ItemDesc pItems[800]; //4-9604h
+  NZIArray<ItemDesc, 800> pItems; //4-9604h
   ItemEnchantment pEnchantments[24]; //9604h
   ItemSpecialEnchantment pSpecialEnchantments[72]; //97E4h -9FC4h
   char field_9FC4[5000];
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NZIArray.h	Mon Sep 23 07:07:06 2013 +0200
@@ -0,0 +1,43 @@
+#pragma once
+#include <array>
+#include <assert.h>
+
+
+template<class _Ty,
+  size_t _Size>
+class NZIArray : std::array<_Ty, _Size>
+{
+public:
+  reference ZerothIndex()
+  {
+    return std::array<_Ty, _Size>::operator [](0);
+  }
+
+  reference operator[](size_type _Pos)
+  {	// subscript nonmutable sequence
+#if _ITERATOR_DEBUG_LEVEL == 2
+    assert(_Pos != 0 && "not allowed to access zeroth element");
+
+#elif _ITERATOR_DEBUG_LEVEL == 1
+    _SCL_SECURE_VALIDATE_RANGE(_Pos != 0);
+#endif /* _ITERATOR_DEBUG_LEVEL */
+
+    __analysis_assume(_Pos != 0);
+
+    return std::array<_Ty, _Size>::operator [](_Pos);
+  }
+
+  const_reference operator[](size_type _Pos) const
+  {	// subscript nonmutable sequence
+#if _ITERATOR_DEBUG_LEVEL == 2
+    assert(_Pos != 0 && "not allowed to access zeroth element");
+
+#elif _ITERATOR_DEBUG_LEVEL == 1
+    _SCL_SECURE_VALIDATE_RANGE(_Pos != 0);
+#endif /* _ITERATOR_DEBUG_LEVEL */
+
+    __analysis_assume(_Pos != 0);
+
+    return std::array<_Ty, _Size>::operator [](_Pos);
+  }
+};
--- a/Player.cpp	Sun Sep 22 19:48:02 2013 +0200
+++ b/Player.cpp	Mon Sep 23 07:07:06 2013 +0200
@@ -3139,7 +3139,7 @@
           v22 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
           if ( v22 >= 0 && v22 <= 2)
           {
-            v23 = this->pOwnItems[this->pEquipment.uMainHand].uItemID;
+            v23 = this->pOwnItems[this->pEquipment.uMainHand - 1].uItemID;
             v26 = pItemsTable->pItems[v23].uDamageRoll;
             if ( this->pEquipment.uShield || pItemsTable->pItems[v23].uSkillType != 4 )
             {
@@ -3152,13 +3152,13 @@
             v5 = pItemsTable->pItems[v23].uDamageMod + v25 * v26;
           }
         }
-        if ( getOnlyMainHandDmg || !this->HasItemEquipped(EQUIP_OFF_HAND) ||  (GetEquippedItemEquipType(EQUIP_OFF_HAND) < 0 && GetEquippedItemEquipType(EQUIP_OFF_HAND) > 2))
+        if ( getOnlyMainHandDmg || !this->HasItemEquipped(EQUIP_OFF_HAND) ||  (GetEquippedItemEquipType(EQUIP_OFF_HAND) < 0 || GetEquippedItemEquipType(EQUIP_OFF_HAND) > 2))
         {
             return v5;
         }
         else
         {
-          v23 = this->pOwnItems[this->pEquipment.uShield].uItemID;
+          v23 = this->pOwnItems[this->pEquipment.uShield - 1].uItemID;
           v15 = pItemsTable->pItems[v23].uDamageMod;
           v14 = pItemsTable->pItems[v23].uDamageDice * pItemsTable->pItems[v23].uDamageRoll;
           return v5 + v15 + v14;
@@ -3200,9 +3200,9 @@
         v9 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
         if ( v9 >= 0 && v9 <= 2)
         {
-          v5 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand].uItemID].uDamageDice +
-            pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand].uItemID].uDamageMod;
-          if ( !this->pEquipment.uShield && pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand].uItemID].uSkillType == 4)
+          v5 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand - 1].uItemID].uDamageDice +
+            pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand - 1].uItemID].uDamageMod;
+          if ( !this->pEquipment.uShield && pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand - 1].uItemID].uSkillType == 4)
           {
             ++v5;
           }
@@ -3773,7 +3773,7 @@
     {
       if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
       {
-        int currItemId = this->pInventoryItemList[this->pEquipment.pIndices[i]].uItemID;
+        int currItemId = this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID;
         if ( pItemsTable->pItems[currItemId].uEquipType == EQUIP_MAIN_HAND || pItemsTable->pItems[currItemId].uEquipType == EQUIP_OFF_HAND )
         {
           PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[currItemId].uSkillType;
--- a/mm7_data.h	Sun Sep 22 19:48:02 2013 +0200
+++ b/mm7_data.h	Mon Sep 23 07:07:06 2013 +0200
@@ -4,6 +4,7 @@
 #include "OSAPI.h"
 #include <array>
 #include <assert.h>
+#include "NZIArray.h"
 
 typedef char _UNKNOWN;
 typedef unsigned int uint;
@@ -283,44 +284,6 @@
   return uint64(x) > uint64(x+y);
 }
 
-template<class _Ty,
-  size_t _Size>
-class NZIArray : std::array<_Ty, _Size>
-{
-public:
-  reference ZerothIndex()
-  {
-    return std::array<_Ty, _Size>::operator [](0);
-  }
-
-  reference operator[](size_type _Pos)
-  {	// subscript nonmutable sequence
-#if _ITERATOR_DEBUG_LEVEL == 2
-    assert(_Pos != 0 && "not allowed to access zeroth element");
-
-#elif _ITERATOR_DEBUG_LEVEL == 1
-    _SCL_SECURE_VALIDATE_RANGE(_Pos != 0);
-#endif /* _ITERATOR_DEBUG_LEVEL */
-
-    __analysis_assume(_Pos != 0);
-
-    return std::array<_Ty, _Size>::operator [](_Pos);
-  }
-
-  const_reference operator[](size_type _Pos) const
-  {	// subscript nonmutable sequence
-#if _ITERATOR_DEBUG_LEVEL == 2
-    assert(_Pos != 0 && "not allowed to access zeroth element");
-
-#elif _ITERATOR_DEBUG_LEVEL == 1
-    _SCL_SECURE_VALIDATE_RANGE(_Pos != 0);
-#endif /* _ITERATOR_DEBUG_LEVEL */
-
-    __analysis_assume(_Pos != 0);
-
-    return std::array<_Ty, _Size>::operator [](_Pos);
-  }
-};
 
 //-------------------------------------------------------------------------
 // Data declarations