diff Player.cpp @ 1386:72191abc8116

Player::SelectPhrasesTransaction redone
author Grumpy7
date Wed, 17 Jul 2013 00:19:33 +0200
parents 5644aecb5082
children 297b6f192232
line wrap: on
line diff
--- a/Player.cpp	Tue Jul 16 23:35:40 2013 +0200
+++ b/Player.cpp	Wed Jul 17 00:19:33 2013 +0200
@@ -1083,185 +1083,85 @@
 }
 // 506128: using guessed type int areWeLoadingTexture;
 
-//identf
 //----- (00490EEE) --------------------------------------------------------
-int Player::SelectPhrasesTransaction(ItemGen *pItem, int building_type, int BuildID_2Events, int ShopMenuType)
-{
-  int pSkillLevel; // eax@1
-  int NotBuy; // eax@1
-  int result;
-  signed int pEquipType; // esi@1
-  float *pPriceMultiplier; // esi@26
-  int pPriceItemService; // edi@26
-
-  pSkillLevel = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
-  NotBuy = 4;
-  pEquipType = pItemsTable->pItems[pItem->uItemID].uEquipType;
-  if ( (building_type != 4 || (signed int)pItem->uItemID < 740 || (signed int)pItem->uItemID > 771)
-    && ((signed int)pItem->uItemID >= 600 || (signed int)pItem->uItemID >= 529 && (signed int)pItem->uItemID <= 599) )
-    return 5;
-  if ( building_type == BildingType_WeaponShop )
-  {
-    if ( pEquipType > EQUIP_BOW )
-      return NotBuy;
-    if (pItem->Stolen())
-      return 6;
-  }
-  if ( building_type == BildingType_ArmorShop )
-  {
-    if ( pEquipType < 3 && pEquipType > 9 )
-      return NotBuy;
-    if (pItem->Stolen())
-      return 6;
-  }
-  if ( building_type == BildingType_MagicShop )
-  {
-    if ( pItemsTable->pItems[pItem->uItemID].uSkillType == 38 )
-    {
-      if (pItem->Stolen())
-        return 6;
-      pPriceMultiplier = &p2DEvents[BuildID_2Events - 1].fPriceMultiplier;
-      pPriceItemService = GetBuyingPrice(pItem->GetValue(), *pPriceMultiplier);
-      if ( ShopMenuType == 3 )//Sell
-      {
-        pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier);
-        if (!pItem->Broken())
-        {
-          if ( pSkillLevel )
-            result = (pPriceItemService == pItem->GetValue()) + 2;
-          else
-            result = 1;
-          return result;
-        }
-        pPriceItemService = 1;
-        if ( pSkillLevel )
-          result = (pPriceItemService == pItem->GetValue()) + 2;
-        else
-          result = 1;
-        return result;
-      }
-      if ( ShopMenuType == 4 )//Identify
-      {
-        pPriceItemService = this->GetPriceIdentification(*pPriceMultiplier);
-        if ( pSkillLevel )
-          result = (pPriceItemService == pItem->GetValue()) + 2;
-        else
-          result = 1;
-        return result;
-      }
-      if ( ShopMenuType == 5 )//Repair
-      {
-        pPriceItemService = this->GetPriceRepair(pItem->GetValue(), *pPriceMultiplier);
-        if ( pSkillLevel )
-          result = (pPriceItemService == pItem->GetValue()) + 2;
-        else
-          result = 1;
-        return result;
-      }
-      if ( ShopMenuType != 6 )//Buy and ???
-      {
-        if ( pSkillLevel )
-          result = (pPriceItemService == pItem->GetValue()) + 2;
-        else
-          result = 1;
-        return result;
-      }
-      pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier) / 2;
+int Player::SelectPhrasesTransaction(ItemGen *pItem, int building_type, int BuildID_2Events, int ShopMenuType)  //TODO: probably move this somewhere else, not really Player:: stuff
+{
+  unsigned int idemId; // edx@1
+  signed int equipType; // esi@1
+  float multiplier; // ST04_4@26
+  int price; // edi@26
+  int merchantLevel; // [sp+10h] [bp-8h]@1
+  int itemValue;
+
+  merchantLevel = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
+  idemId = pItem->uItemID;
+  equipType = pItemsTable->pItems[idemId].uEquipType;
+  itemValue = pItem->GetValue();
+
+  switch (building_type)
+  {
+    case 1:
+      if (idemId >= 529)
+        return 5;
+      if (equipType > 2)
+        return 4;
+    break;
+    case 2:
+      if (idemId >= 529)
+        return 5;
+      if ( equipType < 3 || equipType > 9)
+        return 4;
+    break;
+    case 3:
+      if (idemId >= 529)
+        return 5;
+      if ( pItemsTable->pItems[idemId].uSkillType != 38 )
+        return 4;
+    break;
+    case 4:
+      if ((idemId >= 529 && idemId < 740) || idemId > 771)
+        return 5;
+      if ( !(equipType == 13 || equipType == 14 || equipType == 17))
+        return 4;
+    break;
+  }
+  if (pItem->Stolen())
+    return 6;
+
+  multiplier = p2DEvents[BuildID_2Events - 1].fPriceMultiplier;
+  switch (ShopMenuType)
+  {
+    case 2:
+      price = GetBuyingPrice(itemValue, multiplier);
+    break;
+    case 3:
       if (pItem->Broken())
-        pPriceItemService = 1;
-      if ( pPriceItemService >= 1 )
-      {
-        if ( pSkillLevel )
-          result = (pPriceItemService == pItem->GetValue()) + 2;
-        else
-          result = 1;
-        return result;
-      }
-      pPriceItemService = 1;
-      if ( pSkillLevel )
-        result = (pPriceItemService == pItem->GetValue()) + 2;
-      else
-        result = 1;
-      return result;
-    }
-    if ( pEquipType != EQUIP_BOOK )
-      return NotBuy;
-  }
-  if ( building_type == BildingType_AlchemistShop )
-  {
-    if ( pEquipType < EQUIP_REAGENT )
-      return NotBuy;
-    if ( pEquipType > EQUIP_POTION )
-    {
-      if ( pEquipType != EQUIP_MESSAGE_SCROLL )
-        return NotBuy;
-    }
-    if (pItem->Stolen())
-      return 6;
-  }
-  pPriceMultiplier = &p2DEvents[BuildID_2Events - 1].fPriceMultiplier;
-  pPriceItemService = GetBuyingPrice(pItem->GetValue(), *pPriceMultiplier);
-  if ( ShopMenuType == 3 )//Sell
-  {
-    pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier);
-    if (!pItem->Broken())
-    {
-      if ( pSkillLevel )
-        result = (pPriceItemService == pItem->GetValue()) + 2;
+        price = 1;
       else
-        result = 1;
-      return result;
-    }
-    pPriceItemService = 1;
-    if ( pSkillLevel )
-      result = (pPriceItemService == pItem->GetValue()) + 2;
-    else
-      result = 1;
-    return result;
-  }
-  if ( ShopMenuType == 4 )//Identify
-  {
-    pPriceItemService = this->GetPriceIdentification(*pPriceMultiplier);
-    if ( pSkillLevel )
-      result = (pPriceItemService == pItem->GetValue()) + 2;
-    else
-      result = 1;
-    return result;
-  }
-  if ( ShopMenuType == 5 )//Repair
-  {
-    pPriceItemService = this->GetPriceRepair(pItem->GetValue(), *pPriceMultiplier);
-    if ( pSkillLevel )
-      result = (pPriceItemService == pItem->GetValue()) + 2;
+        price = this->GetPriceSell(itemValue, multiplier);
+    break;
+    case 4:
+      price = this->GetPriceIdentification(multiplier);
+    break;
+    case 5:
+      price = this->GetPriceRepair(itemValue, multiplier);
+    break;
+  }
+  if ( merchantLevel )
+  {
+    if (price == itemValue)
+    {
+      return 3;
+    }
     else
-      result = 1;
-    return result;
-  }
-  if ( ShopMenuType != 6 )//Buy and ???
-  {
-    if ( pSkillLevel )
-      result = (pPriceItemService == pItem->GetValue()) + 2;
-    else
-      result = 1;
-    return result;
-  }
-  pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier) / 2;
-  if (pItem->Broken())
-    pPriceItemService = 1;
-  if ( pPriceItemService >= 1 )
-  {
-    if ( pSkillLevel )
-      result = (pPriceItemService == pItem->GetValue()) + 2;
-    else
-      result = 1;
-    return result;
-  }
-  pPriceItemService = 1;
-  if ( pSkillLevel )
-    result = (pPriceItemService == pItem->GetValue()) + 2;
+    {
+      return 2;
+    }
+  }
   else
-    result = 1;
-  return result;
+  {
+    return 1;
+  }
 }
 
 //----- (0049107D) --------------------------------------------------------