Mercurial > mm7
diff 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 |
line wrap: on
line diff
--- a/Player.cpp Sat Sep 07 10:04:37 2013 +0200 +++ b/Player.cpp Sat Sep 07 10:49:42 2013 +0200 @@ -815,25 +815,21 @@ } if ( slotHeight == 0 || slotWidth == 0) { - assert("Items should have nonzero dimensions"); + assert("Items should have nonzero dimensions" && false); return 1; } if ( (slotWidth + uSlot % INVETORYSLOTSWIDTH) <= INVETORYSLOTSWIDTH && (slotHeight + uSlot / INVETORYSLOTSWIDTH) <= INVETORYSLOTSHEIGHT ) { - int startOfInnerLoop = uSlot; - for (unsigned int y = 0; y < slotHeight; y++) - { - int innerLoopPos = startOfInnerLoop; for (unsigned int x = 0; x < slotWidth; x++) { - if (pInventoryMatrix[innerLoopPos] != 0) + for (unsigned int y = 0; y < slotHeight; y++) { - return false; + if (pInventoryMatrix[y * INVETORYSLOTSWIDTH + x + uSlot] != 0) + { + return false; + } } - innerLoopPos++; } - startOfInnerLoop += INVETORYSLOTSWIDTH; - } return true; } return false; @@ -911,23 +907,19 @@ int Player::AddItem(int index, unsigned int uItemID) { int xStartValue = 0; - int startOfInnerLoop = 0; if ( index == -1 ) { - for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++) - { - int innerLoopPos = startOfInnerLoop; for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++) { - if ( CanFitItem(innerLoopPos, uItemID) ) + for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++) { - return CreateItemInInventory(innerLoopPos, uItemID); + if ( CanFitItem(ycoord * INVETORYSLOTSWIDTH + xcoord, uItemID) ) + { + return CreateItemInInventory(ycoord * INVETORYSLOTSWIDTH + xcoord, uItemID); + } } - innerLoopPos++; } - startOfInnerLoop += INVETORYSLOTSWIDTH; - } return 0; } if ( !CanFitItem(index, uItemID) ) @@ -941,24 +933,19 @@ //----- (00492826) -------------------------------------------------------- int Player::AddItem2(int index, ItemGen *Src) { - int xStartValue = 0; pItemsTable->SetSpecialBonus(Src); - int startOfInnerLoop = 0; if ( index == -1 ) { - for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++) //TODO: change pInventoryMatrix to 2 dimensional array. - { - int innerLoopPos = startOfInnerLoop; - for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++) + for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++) + { + for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++) //TODO: change pInventoryMatrix to 2 dimensional array. { - if ( CanFitItem(innerLoopPos, Src->uItemID) ) + if ( CanFitItem(ycoord * INVETORYSLOTSWIDTH + xcoord, Src->uItemID) ) { - return CreateItemInInventory2(innerLoopPos, Src); + return CreateItemInInventory2(ycoord * INVETORYSLOTSWIDTH + xcoord, Src); } - innerLoopPos++; } - startOfInnerLoop += INVETORYSLOTSWIDTH; } return 0; } @@ -1693,37 +1680,37 @@ //----- (0048C93C) -------------------------------------------------------- int Player::GetActualMight() { - return GetActualAttribute(CHARACTER_ATTRIBUTE_STRENGTH); + return GetActualAttribute(CHARACTER_ATTRIBUTE_STRENGTH, &Player::uMight, &Player::uMightBonus); } //----- (0048C9C2) -------------------------------------------------------- int Player::GetActualIntelligence() { - return GetActualAttribute(CHARACTER_ATTRIBUTE_INTELLIGENCE); + return GetActualAttribute(CHARACTER_ATTRIBUTE_INTELLIGENCE, &Player::uIntelligence, &Player::uIntelligenceBonus); } //----- (0048CA3F) -------------------------------------------------------- int Player::GetActualWillpower() { - return GetActualAttribute(CHARACTER_ATTRIBUTE_WILLPOWER); + return GetActualAttribute(CHARACTER_ATTRIBUTE_WILLPOWER, &Player::uWillpower, &Player::uWillpowerBonus); } //----- (0048CABC) -------------------------------------------------------- int Player::GetActualEndurance() { - return GetActualAttribute(CHARACTER_ATTRIBUTE_ENDURANCE); + return GetActualAttribute(CHARACTER_ATTRIBUTE_ENDURANCE, &Player::uEndurance, &Player::uEnduranceBonus); } //----- (0048CB39) -------------------------------------------------------- int Player::GetActualAccuracy() { - return GetActualAttribute(CHARACTER_ATTRIBUTE_ACCURACY); + return GetActualAttribute(CHARACTER_ATTRIBUTE_ACCURACY, &Player::uAccuracy, &Player::uAccuracyBonus); } //----- (0048CBB6) -------------------------------------------------------- int Player::GetActualSpeed() { - return GetActualAttribute(CHARACTER_ATTRIBUTE_SPEED); + return GetActualAttribute(CHARACTER_ATTRIBUTE_SPEED, &Player::uSpeed, &Player::uSpeedBonus); } //----- (0048CC33) -------------------------------------------------------- @@ -1739,49 +1726,13 @@ if ( CheckHiredNPCSpeciality(Psychic) ) npc_luck_bonus += 10; - return GetActualAttribute(CHARACTER_ATTRIBUTE_LUCK) + return GetActualAttribute(CHARACTER_ATTRIBUTE_LUCK, &Player::uLuck, &Player::uLuckBonus) + npc_luck_bonus; } //----- (new function) -------------------------------------------------------- -int Player::GetActualAttribute( CHARACTER_ATTRIBUTE_TYPE attrId ) -{ - unsigned __int16 attrValue = 0; - unsigned __int16 attrBonus = 0; - switch (attrId) - { - case CHARACTER_ATTRIBUTE_STRENGTH: - attrValue = uMight; - attrBonus = uMightBonus; - break; - case CHARACTER_ATTRIBUTE_INTELLIGENCE: - attrValue = uIntelligence; - attrBonus = uIntelligenceBonus; - break; - case CHARACTER_ATTRIBUTE_WILLPOWER: - attrValue = uWillpower; - attrBonus = uWillpowerBonus; - break; - case CHARACTER_ATTRIBUTE_ENDURANCE: - attrValue = uEndurance; - attrBonus = uEnduranceBonus; - break; - case CHARACTER_ATTRIBUTE_ACCURACY: - attrValue = uAccuracy; - attrBonus = uAccuracyBonus; - break; - case CHARACTER_ATTRIBUTE_SPEED: - attrValue = uSpeed; - attrBonus = uSpeedBonus; - break; - case CHARACTER_ATTRIBUTE_LUCK: - attrValue = uLuck; - attrBonus = uLuckBonus; - break; - default: - return 0; - } - +int Player::GetActualAttribute( CHARACTER_ATTRIBUTE_TYPE attrId, unsigned short Player::* attrValue, unsigned short Player::* attrBonus ) +{ uint uActualAge = this->sAgeModifier + GetBaseAge(); uint uAgeingMultiplier = 100; for (uint i = 0; i < 4; ++i) @@ -1795,10 +1746,10 @@ auto uConditionMult = pConditionAttributeModifier[attrId][GetMajorConditionIdx()]; int magicBonus = GetMagicalBonus(attrId); int itemBonus = GetItemsBonus(attrId, 0); - return uConditionMult * uAgeingMultiplier * attrValue / 100 / 100 + return uConditionMult * uAgeingMultiplier * this->*attrValue / 100 / 100 + magicBonus - + magicBonus - + attrBonus; + + itemBonus + + this->*attrBonus; } //----- (0048CCF5) --------------------------------------------------------