changeset 1687:5f01f1ed97f4

Player::StealFromActor cleanup, renamed UIMSG_1B to UIMSG_STEALFROMACTOR
author Grumpy7
date Sun, 22 Sep 2013 03:12:11 +0200
parents df30a0c901e5
children ece764a4672d
files GUIWindow.h Mouse.cpp Player.cpp mm7_5.cpp
diffstat 4 files changed, 121 insertions(+), 150 deletions(-) [+]
line wrap: on
line diff
--- a/GUIWindow.h	Sat Sep 21 18:48:10 2013 +0200
+++ b/GUIWindow.h	Sun Sep 22 03:12:11 2013 +0200
@@ -24,7 +24,7 @@
 
   UIMSG_CastQuickSpell = 25,
 
-  UIMSG_1B = 27,
+  UIMSG_STEALFROMACTOR = 27,
   UIMSG_1C = 28,
   UIMSG_PlayArcomage = 29,
 
--- a/Mouse.cpp	Sat Sep 21 18:48:10 2013 +0200
+++ b/Mouse.cpp	Sun Sep 22 03:12:11 2013 +0200
@@ -603,7 +603,7 @@
       *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
       ++pMessageQueue_50CBD0->uNumMessages;
     }*/
-    pMessageQueue_50CBD0->AddMessage(UIMSG_1B, PID_ID(v6), 0);
+    pMessageQueue_50CBD0->AddMessage(UIMSG_STEALFROMACTOR, PID_ID(v6), 0);
 
     if ( pParty->bTurnBasedModeOn == 1 )
     {
--- a/Player.cpp	Sat Sep 21 18:48:10 2013 +0200
+++ b/Player.cpp	Sun Sep 22 03:12:11 2013 +0200
@@ -2027,7 +2027,7 @@
     || this->IsEradicated()
     || this->IsDead()
     || this->IsPertified()
-    || this->pConditions[Condition_Drunk]
+    || this->IsDrunk()
     || this->IsUnconcious()
     || this->IsAsleep() )
   {
@@ -2040,7 +2040,7 @@
     v8 = SkillToMastery(v6);
     itemvalue = itemToSteal->GetValue();
     v10 = pItemsTable->pItems[itemToSteal->uItemID].uEquipType;
-    if ( v10 == 0 || v10 == 1 || v10 == 2 )
+    if ( v10 == EQUIP_OFF_HAND || v10 == EQUIP_MAIN_HAND || v10 == EQUIP_BOW )
       itemvalue *= 3;
     currMaxItemValue = StealingRandomBonuses[rand() % 5] + v7 * StealingMasteryBonuses[v8];
     *fineIfFailed = 100 * (reputation + extraStealDifficulty) + itemvalue;
@@ -2074,161 +2074,133 @@
 //----- (0048D88B) --------------------------------------------------------
 int Player::StealFromActor(unsigned int uActorID, int _steal_perm, int reputation)
 {
-  Player *v4; // esi@1
-  Actor *v5; // edi@1
-  unsigned __int16 v6; // cx@10
+  Actor *actroPtr; // edi@1
   int v7; // ebx@10
-  unsigned int v8; // esi@10
-  int v9; // eax@10
-  int v10; // esi@10
+  unsigned int stealingMastery; // esi@10
+  int fineIfFailed; // esi@10
   int v11; // eax@13
-  signed int v12; // ebx@15
-  signed int v13; // edx@15
-  int v14; // ecx@15
-  unsigned __int16 v15; // si@21
-  unsigned int v16; // ebx@24
-  int v17; // esi@24
-  const void *v18; // eax@29
-  unsigned int v19; // esi@31
-  int v20; // eax@34
-  char v21; // zf@36
-  unsigned int v22; // ST0C_4@39
-  char *v23; // esi@39
-  const char *v25; // [sp-Ch] [bp-48h]@40
-  int v26; // [sp-8h] [bp-44h]@40
-  ItemGen v27; // [sp+8h] [bp-34h]@15
-  unsigned int v28; // [sp+2Ch] [bp-10h]@10
-  int v29; // [sp+30h] [bp-Ch]@10
-  int v30; // [sp+34h] [bp-8h]@10
-  Player *v31; // [sp+38h] [bp-4h]@1
-  signed int _steal_perma; // [sp+48h] [bp+Ch]@12
-
-  v4 = this;
-  v5 = &pActors[uActorID];
-  v31 = this;
-  if ( &pActors[uActorID]
-    && !this->pConditions[16]
-    && !this->pConditions[14]
-    && !this->pConditions[15]
-    && !this->pConditions[4]
-    && !this->pConditions[13]
-    && !this->pConditions[2] )
-  {
-    if ( !(BYTE2(v5->uAttributes) & 0x80) )
-      pActors[uActorID].SetRandomGoldIfTheresNoItem();
-    v6 = v4->pActiveSkills[34];
-    v7 = v6 & 0x3F;
-    v8 = SkillToMastery(v6);
-    v9 = rand();
-    v30 = StealingMasteryBonuses[v8];
-    v29 = StealingRandomBonuses[v9 % 100 / 20];
-    v10 = v5->pMonsterInfo.uLevel + 100 * (_steal_perm + reputation);
-    if ( rand() % 100 < 5 || v10 > v29 + v7 * v30 || (_steal_perma = 2, BYTE2(v5->uAttributes) & 8) )
-    {
-      Actor::AggroSurroundingPeasants(uActorID, 1);
-      _steal_perma = 0;
-      v26 = (int)v31->pName;
-      v25 = pGlobalTXT_LocalizationStrings[376];
-    }
-    else
-    {
-      v11 = rand();
-      if ( v11 % 100 >= 40 )
+  bool HasFullItemSlots; // ebx@15
+  unsigned __int16 carriedItemId; // si@21
+  unsigned int enchBonusSum; // esi@31
+  int *enchTypePtr; // eax@34
+  ItemGen tempItem; // [sp+8h] [bp-34h]@15
+  int currMaxItemValue;
+
+  actroPtr = &pActors[uActorID];
+  if ( !actroPtr
+    || this->IsEradicated()
+    || this->IsDead()
+    || this->IsPertified()
+    || this->IsDrunk()
+    || this->IsUnconcious()
+    || this->IsAsleep() )
+  {
+    return 0;
+  }
+    pGlobalTXT_LocalizationStrings[1];
+  if ( !(BYTE2(actroPtr->uAttributes) & 0x80) )
+    actroPtr->SetRandomGoldIfTheresNoItem();
+  unsigned __int16 v6 = this->pActiveSkills[34];
+  v7 = v6 & 0x3F;
+  stealingMastery = SkillToMastery(v6);
+  int v30 = StealingMasteryBonuses[stealingMastery];
+  int v29 = StealingRandomBonuses[rand() % 5];
+  fineIfFailed = actroPtr->pMonsterInfo.uLevel + 100 * (_steal_perm + reputation);
+  currMaxItemValue = v29 + v7 * v30;
+  pGlobalTXT_LocalizationStrings[200];
+  if ( false && (rand() % 100 < 5 || fineIfFailed > currMaxItemValue || BYTE2(actroPtr->uAttributes) & 8) )
+  {
+    Actor::AggroSurroundingPeasants(uActorID, 1);
+    sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[376], this->pName);
+    ShowStatusBarString(pTmpBuf2.data(), 2u);
+    return 0;
+  }
+  else
+  {
+    v11 = rand();
+    if ( v11 % 100 >= 40 )
+    {
+      if ( v11 % 100 >= 70 )
       {
-        if ( v11 % 100 >= 70 )
+        enchBonusSum = 0;
+        for (int i = 0; i < v7; i++)
         {
-          v19 = 0;
-          if ( v7 > 0 )
-          {
-            do
-            {
-              --v7;
-              v19 += rand() % StealingEnchantmentBonusForSkill[v8] + 1;
-            }
-            while ( v7 );
-          }
-          if ( pItemsTable->pItems[v5->array_000234[3].uItemID].uEquipType != 18 )
-            return _steal_perma;
-          v20 = (int)&v5->array_000234[3].uSpecEnchantmentType;
-          if ( (signed int)v19 > v5->array_000234[3].uSpecEnchantmentType )
-            v19 = v5->array_000234[3].uSpecEnchantmentType;
-          v21 = *(int *)v20 == v19;
-          *(int *)v20 -= v19;
-          if ( v21 )
-            v5->array_000234[3].uItemID = 0;
-          if ( v19 )
-          {
-            party_finds_gold(v19, 2);
-            v22 = v19;
-            v23 = pTmpBuf2.data();
-            sprintf(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[302], v31->pName, v22);
-LABEL_43:
-            ShowStatusBarString(v23, 2u);
-            return _steal_perma;
-          }
+          enchBonusSum += rand() % StealingEnchantmentBonusForSkill[stealingMastery] + 1;
+        }
+        if ( pItemsTable->pItems[actroPtr->array_000234[3].uItemID].uEquipType != EQUIP_GOLD )
+          return 2;
+        enchTypePtr = &actroPtr->array_000234[3].uSpecEnchantmentType;
+        if ( (int)enchBonusSum >= *enchTypePtr )
+        {
+          actroPtr->array_000234[3].uItemID = 0;
+          *enchTypePtr = 0;
         }
         else
         {
-          v27.Reset();
-          v12 = 0;
-          v13 = 0;
-          v14 = (int)v5->array_000234;
-          while ( !*(int *)v14 || pItemsTable->pItems[*(int *)v14].uEquipType == 18 )
-          {
-            ++v13;
-            v14 += 36;
-            if ( v13 >= 4 )
-              goto LABEL_21;
-          }
-          v12 = 1;
-LABEL_21:
-          v15 = v5->uCarriedItemID;
-          if ( v15 || v12 )
+          *enchTypePtr -= enchBonusSum;
+        }
+        if ( enchBonusSum )
+        {
+          party_finds_gold(enchBonusSum, 2);
+          sprintf(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[302], this->pName, enchBonusSum);     //%stole %d gold
+        }
+        else
+        {
+          sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[377], this->pName);   //%s failed to steal anything
+        }
+        ShowStatusBarString(pTmpBuf2.data(), 2u);
+        return 2;
+      }
+      else
+      {
+        tempItem.Reset();
+        HasFullItemSlots = false;
+        int i;
+        for (i = 0; i < 4; i++)
+        {
+          if ( actroPtr->array_000234[i].uItemID != 0 && pItemsTable->pItems[actroPtr->array_000234[i].uItemID].uEquipType != EQUIP_GOLD )
+            break;
+        }
+        if (i == 4)
+          HasFullItemSlots = true;
+        carriedItemId = actroPtr->uCarriedItemID;
+        if ( carriedItemId != 0 || HasFullItemSlots )
+        {
+          tempItem.Reset();
+          if ( carriedItemId != 0 )
           {
-            v27.Reset();
-            if ( v15 )
-            {
-              v16 = (signed __int16)v15;
-              v5->uCarriedItemID = 0;
-              v27.uItemID = (signed __int16)v15;
-              v17 = (signed __int16)v15;
-              if ( pItemsTable->pItems[v17].uEquipType == 12 )
-                v27.uNumCharges = rand() % 6 + pItemsTable->pItems[v17].uDamageMod + 1;
-              if ( pItemsTable->pItems[v17].uEquipType == 14 )
-              {
-                if ( v16 != 220 )
-                  v27.uEnchantmentType = 2 * rand() % 4 + 2;
-              }
-            }
-            else
-            {
-              v18 = &v5->array_000234[rand() % 4];
-              memcpy(&v27, v18, sizeof(v27));
-              ((ItemGen *)v18)->Reset();
-              v16 = v27.uItemID;
-            }
-            sub_421B2C_PlaceInInventory_or_DropPickedItem();
-            sprintf(
-              pTmpBuf2.data(),
-              pGlobalTXT_LocalizationStrings[304],
-              v31->pName,
-              pItemsTable->pItems[v16].pUnidentifiedName);
-            ShowStatusBarString(pTmpBuf2.data(), 2u);
-            sub_421B2C_PlaceInInventory_or_DropPickedItem();
-            memcpy(&pParty->pPickedItem, &v27, sizeof(pParty->pPickedItem));
-            pMouse->SetCursorBitmapFromItemID(v16);
-            return _steal_perma;
+            actroPtr->uCarriedItemID = 0;
+            tempItem.uItemID = carriedItemId;
+            if ( pItemsTable->pItems[carriedItemId].uEquipType == EQUIP_WAND )
+              tempItem.uNumCharges = rand() % 6 + pItemsTable->pItems[carriedItemId].uDamageMod + 1;
+            else if ( pItemsTable->pItems[carriedItemId].uEquipType == EQUIP_POTION && carriedItemId != ITEM_POTION_BOTTLE)
+              tempItem.uEnchantmentType = 2 * rand() % 4 + 2;
           }
+          else
+          {
+            ItemGen* itemToSteal = &actroPtr->array_000234[rand() % 4];
+            memcpy(&tempItem, itemToSteal, sizeof(tempItem));
+            itemToSteal->Reset();
+            carriedItemId = tempItem.uItemID;
+          }
+          sub_421B2C_PlaceInInventory_or_DropPickedItem();
+          sprintf(
+            pTmpBuf2.data(),
+            pGlobalTXT_LocalizationStrings[304],   // Official                   //TODO: add a normal "%d stole %d" message
+            this->pName,
+            pItemsTable->pItems[carriedItemId].pUnidentifiedName);
+          ShowStatusBarString(pTmpBuf2.data(), 2u);
+          sub_421B2C_PlaceInInventory_or_DropPickedItem();
+          memcpy(&pParty->pPickedItem, &tempItem, sizeof(ItemGen));
+          pMouse->SetCursorBitmapFromItemID(carriedItemId);
+          return 2;
         }
       }
-      v26 = (int)v31->pName;
-      v25 = pGlobalTXT_LocalizationStrings[377];
-    }
-    v23 = pTmpBuf2.data();
-    sprintfex(pTmpBuf2.data(), v25, v26);
-    goto LABEL_43;
-  }
-  return 0;
+    }
+    sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[377], this->pName);   //%s failed to steal anything
+    ShowStatusBarString(pTmpBuf2.data(), 2u);
+    return 2;
+  }
 }
 // 4EDEA0: using guessed type int dword_4EDEA0[];
 // 4EDEB4: using guessed type int dword_4EDEB4[];
--- a/mm7_5.cpp	Sat Sep 21 18:48:10 2013 +0200
+++ b/mm7_5.cpp	Sun Sep 22 03:12:11 2013 +0200
@@ -2399,8 +2399,7 @@
           pCurrentScreen = SCREEN_19;
           pEventTimer->Pause();
           continue;
-        case UIMSG_1B:
-			__debugbreak();
+        case UIMSG_STEALFROMACTOR:
           if ( !uActiveCharacter )
             continue;
           if ( pParty->bTurnBasedModeOn != 1 )