comparison Player.cpp @ 1552:d253172de469

Player::CanFitItem, AddItem, AddItem2 changed changed the retarded 2 dimensional array traversal, changed GetActualAttribute input parameters to get rid of the attrid case
author Grumpy7
date Sat, 07 Sep 2013 10:49:42 +0200
parents a9e8d2a7abb5
children b98812ead5d9
comparison
equal deleted inserted replaced
1551:a9e8d2a7abb5 1552:d253172de469
813 texture->Release(); 813 texture->Release();
814 pIcons_LOD->SyncLoadedFilesCount(); 814 pIcons_LOD->SyncLoadedFilesCount();
815 } 815 }
816 if ( slotHeight == 0 || slotWidth == 0) 816 if ( slotHeight == 0 || slotWidth == 0)
817 { 817 {
818 assert("Items should have nonzero dimensions"); 818 assert("Items should have nonzero dimensions" && false);
819 return 1; 819 return 1;
820 } 820 }
821 if ( (slotWidth + uSlot % INVETORYSLOTSWIDTH) <= INVETORYSLOTSWIDTH && (slotHeight + uSlot / INVETORYSLOTSWIDTH) <= INVETORYSLOTSHEIGHT ) 821 if ( (slotWidth + uSlot % INVETORYSLOTSWIDTH) <= INVETORYSLOTSWIDTH && (slotHeight + uSlot / INVETORYSLOTSWIDTH) <= INVETORYSLOTSHEIGHT )
822 { 822 {
823 int startOfInnerLoop = uSlot;
824 for (unsigned int y = 0; y < slotHeight; y++)
825 {
826 int innerLoopPos = startOfInnerLoop;
827 for (unsigned int x = 0; x < slotWidth; x++) 823 for (unsigned int x = 0; x < slotWidth; x++)
828 { 824 {
829 if (pInventoryMatrix[innerLoopPos] != 0) 825 for (unsigned int y = 0; y < slotHeight; y++)
830 { 826 {
831 return false; 827 if (pInventoryMatrix[y * INVETORYSLOTSWIDTH + x + uSlot] != 0)
828 {
829 return false;
830 }
832 } 831 }
833 innerLoopPos++; 832 }
834 }
835 startOfInnerLoop += INVETORYSLOTSWIDTH;
836 }
837 return true; 833 return true;
838 } 834 }
839 return false; 835 return false;
840 } 836 }
841 // 506128: using guessed type int areWeLoadingTexture; 837 // 506128: using guessed type int areWeLoadingTexture;
909 905
910 //----- (004927A8) -------------------------------------------------------- 906 //----- (004927A8) --------------------------------------------------------
911 int Player::AddItem(int index, unsigned int uItemID) 907 int Player::AddItem(int index, unsigned int uItemID)
912 { 908 {
913 int xStartValue = 0; 909 int xStartValue = 0;
914 int startOfInnerLoop = 0;
915 910
916 if ( index == -1 ) 911 if ( index == -1 )
917 { 912 {
918 for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++)
919 {
920 int innerLoopPos = startOfInnerLoop;
921 for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++) 913 for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++)
922 { 914 {
923 if ( CanFitItem(innerLoopPos, uItemID) ) 915 for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++)
924 { 916 {
925 return CreateItemInInventory(innerLoopPos, uItemID); 917 if ( CanFitItem(ycoord * INVETORYSLOTSWIDTH + xcoord, uItemID) )
918 {
919 return CreateItemInInventory(ycoord * INVETORYSLOTSWIDTH + xcoord, uItemID);
920 }
926 } 921 }
927 innerLoopPos++; 922 }
928 }
929 startOfInnerLoop += INVETORYSLOTSWIDTH;
930 }
931 return 0; 923 return 0;
932 } 924 }
933 if ( !CanFitItem(index, uItemID) ) 925 if ( !CanFitItem(index, uItemID) )
934 { 926 {
935 pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0); 927 pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
939 } 931 }
940 932
941 //----- (00492826) -------------------------------------------------------- 933 //----- (00492826) --------------------------------------------------------
942 int Player::AddItem2(int index, ItemGen *Src) 934 int Player::AddItem2(int index, ItemGen *Src)
943 { 935 {
944 int xStartValue = 0;
945 pItemsTable->SetSpecialBonus(Src); 936 pItemsTable->SetSpecialBonus(Src);
946 int startOfInnerLoop = 0;
947 937
948 if ( index == -1 ) 938 if ( index == -1 )
949 { 939 {
950 for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++) //TODO: change pInventoryMatrix to 2 dimensional array. 940 for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++)
951 { 941 {
952 int innerLoopPos = startOfInnerLoop; 942 for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++) //TODO: change pInventoryMatrix to 2 dimensional array.
953 for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++) 943 {
954 { 944 if ( CanFitItem(ycoord * INVETORYSLOTSWIDTH + xcoord, Src->uItemID) )
955 if ( CanFitItem(innerLoopPos, Src->uItemID) )
956 { 945 {
957 return CreateItemInInventory2(innerLoopPos, Src); 946 return CreateItemInInventory2(ycoord * INVETORYSLOTSWIDTH + xcoord, Src);
958 } 947 }
959 innerLoopPos++; 948 }
960 }
961 startOfInnerLoop += INVETORYSLOTSWIDTH;
962 } 949 }
963 return 0; 950 return 0;
964 } 951 }
965 if ( !CanFitItem(index, Src->uItemID) ) 952 if ( !CanFitItem(index, Src->uItemID) )
966 return 0; 953 return 0;
1691 } 1678 }
1692 1679
1693 //----- (0048C93C) -------------------------------------------------------- 1680 //----- (0048C93C) --------------------------------------------------------
1694 int Player::GetActualMight() 1681 int Player::GetActualMight()
1695 { 1682 {
1696 return GetActualAttribute(CHARACTER_ATTRIBUTE_STRENGTH); 1683 return GetActualAttribute(CHARACTER_ATTRIBUTE_STRENGTH, &Player::uMight, &Player::uMightBonus);
1697 } 1684 }
1698 1685
1699 //----- (0048C9C2) -------------------------------------------------------- 1686 //----- (0048C9C2) --------------------------------------------------------
1700 int Player::GetActualIntelligence() 1687 int Player::GetActualIntelligence()
1701 { 1688 {
1702 return GetActualAttribute(CHARACTER_ATTRIBUTE_INTELLIGENCE); 1689 return GetActualAttribute(CHARACTER_ATTRIBUTE_INTELLIGENCE, &Player::uIntelligence, &Player::uIntelligenceBonus);
1703 } 1690 }
1704 1691
1705 //----- (0048CA3F) -------------------------------------------------------- 1692 //----- (0048CA3F) --------------------------------------------------------
1706 int Player::GetActualWillpower() 1693 int Player::GetActualWillpower()
1707 { 1694 {
1708 return GetActualAttribute(CHARACTER_ATTRIBUTE_WILLPOWER); 1695 return GetActualAttribute(CHARACTER_ATTRIBUTE_WILLPOWER, &Player::uWillpower, &Player::uWillpowerBonus);
1709 } 1696 }
1710 1697
1711 //----- (0048CABC) -------------------------------------------------------- 1698 //----- (0048CABC) --------------------------------------------------------
1712 int Player::GetActualEndurance() 1699 int Player::GetActualEndurance()
1713 { 1700 {
1714 return GetActualAttribute(CHARACTER_ATTRIBUTE_ENDURANCE); 1701 return GetActualAttribute(CHARACTER_ATTRIBUTE_ENDURANCE, &Player::uEndurance, &Player::uEnduranceBonus);
1715 } 1702 }
1716 1703
1717 //----- (0048CB39) -------------------------------------------------------- 1704 //----- (0048CB39) --------------------------------------------------------
1718 int Player::GetActualAccuracy() 1705 int Player::GetActualAccuracy()
1719 { 1706 {
1720 return GetActualAttribute(CHARACTER_ATTRIBUTE_ACCURACY); 1707 return GetActualAttribute(CHARACTER_ATTRIBUTE_ACCURACY, &Player::uAccuracy, &Player::uAccuracyBonus);
1721 } 1708 }
1722 1709
1723 //----- (0048CBB6) -------------------------------------------------------- 1710 //----- (0048CBB6) --------------------------------------------------------
1724 int Player::GetActualSpeed() 1711 int Player::GetActualSpeed()
1725 { 1712 {
1726 return GetActualAttribute(CHARACTER_ATTRIBUTE_SPEED); 1713 return GetActualAttribute(CHARACTER_ATTRIBUTE_SPEED, &Player::uSpeed, &Player::uSpeedBonus);
1727 } 1714 }
1728 1715
1729 //----- (0048CC33) -------------------------------------------------------- 1716 //----- (0048CC33) --------------------------------------------------------
1730 int Player::GetActualLuck() 1717 int Player::GetActualLuck()
1731 { 1718 {
1737 if ( CheckHiredNPCSpeciality(ChimneySweep) ) 1724 if ( CheckHiredNPCSpeciality(ChimneySweep) )
1738 npc_luck_bonus += 20; 1725 npc_luck_bonus += 20;
1739 if ( CheckHiredNPCSpeciality(Psychic) ) 1726 if ( CheckHiredNPCSpeciality(Psychic) )
1740 npc_luck_bonus += 10; 1727 npc_luck_bonus += 10;
1741 1728
1742 return GetActualAttribute(CHARACTER_ATTRIBUTE_LUCK) 1729 return GetActualAttribute(CHARACTER_ATTRIBUTE_LUCK, &Player::uLuck, &Player::uLuckBonus)
1743 + npc_luck_bonus; 1730 + npc_luck_bonus;
1744 } 1731 }
1745 1732
1746 //----- (new function) -------------------------------------------------------- 1733 //----- (new function) --------------------------------------------------------
1747 int Player::GetActualAttribute( CHARACTER_ATTRIBUTE_TYPE attrId ) 1734 int Player::GetActualAttribute( CHARACTER_ATTRIBUTE_TYPE attrId, unsigned short Player::* attrValue, unsigned short Player::* attrBonus )
1748 { 1735 {
1749 unsigned __int16 attrValue = 0;
1750 unsigned __int16 attrBonus = 0;
1751 switch (attrId)
1752 {
1753 case CHARACTER_ATTRIBUTE_STRENGTH:
1754 attrValue = uMight;
1755 attrBonus = uMightBonus;
1756 break;
1757 case CHARACTER_ATTRIBUTE_INTELLIGENCE:
1758 attrValue = uIntelligence;
1759 attrBonus = uIntelligenceBonus;
1760 break;
1761 case CHARACTER_ATTRIBUTE_WILLPOWER:
1762 attrValue = uWillpower;
1763 attrBonus = uWillpowerBonus;
1764 break;
1765 case CHARACTER_ATTRIBUTE_ENDURANCE:
1766 attrValue = uEndurance;
1767 attrBonus = uEnduranceBonus;
1768 break;
1769 case CHARACTER_ATTRIBUTE_ACCURACY:
1770 attrValue = uAccuracy;
1771 attrBonus = uAccuracyBonus;
1772 break;
1773 case CHARACTER_ATTRIBUTE_SPEED:
1774 attrValue = uSpeed;
1775 attrBonus = uSpeedBonus;
1776 break;
1777 case CHARACTER_ATTRIBUTE_LUCK:
1778 attrValue = uLuck;
1779 attrBonus = uLuckBonus;
1780 break;
1781 default:
1782 return 0;
1783 }
1784
1785 uint uActualAge = this->sAgeModifier + GetBaseAge(); 1736 uint uActualAge = this->sAgeModifier + GetBaseAge();
1786 uint uAgeingMultiplier = 100; 1737 uint uAgeingMultiplier = 100;
1787 for (uint i = 0; i < 4; ++i) 1738 for (uint i = 0; i < 4; ++i)
1788 { 1739 {
1789 if (uActualAge >= pAgeingTable[i]) 1740 if (uActualAge >= pAgeingTable[i])
1793 } 1744 }
1794 1745
1795 auto uConditionMult = pConditionAttributeModifier[attrId][GetMajorConditionIdx()]; 1746 auto uConditionMult = pConditionAttributeModifier[attrId][GetMajorConditionIdx()];
1796 int magicBonus = GetMagicalBonus(attrId); 1747 int magicBonus = GetMagicalBonus(attrId);
1797 int itemBonus = GetItemsBonus(attrId, 0); 1748 int itemBonus = GetItemsBonus(attrId, 0);
1798 return uConditionMult * uAgeingMultiplier * attrValue / 100 / 100 1749 return uConditionMult * uAgeingMultiplier * this->*attrValue / 100 / 100
1799 + magicBonus 1750 + magicBonus
1800 + magicBonus 1751 + itemBonus
1801 + attrBonus; 1752 + this->*attrBonus;
1802 } 1753 }
1803 1754
1804 //----- (0048CCF5) -------------------------------------------------------- 1755 //----- (0048CCF5) --------------------------------------------------------
1805 int Player::GetActualAttack(int a2) 1756 int Player::GetActualAttack(int a2)
1806 { 1757 {