Mercurial > mm7
diff Player.cpp @ 1553:b98812ead5d9
Get(skillname) functions cleaned up, using GetMultiplierForSkillLevel instead of nested conditions
author | Grumpy7 |
---|---|
date | Sat, 07 Sep 2013 21:00:02 +0200 |
parents | d253172de469 |
children | e303d8a9bcdc |
line wrap: on
line diff
--- a/Player.cpp Sat Sep 07 10:49:42 2013 +0200 +++ b/Player.cpp Sat Sep 07 21:00:02 2013 +0200 @@ -1127,296 +1127,122 @@ int Player::GetBodybuilding() { int v1; // al@1 - int v2; // ecx@1 - int v4; // eax@3 - signed int v6; // [sp-4h] [bp-4h]@2 v1 = GetActualSkillLevel(PLAYER_SKILL_BODYBUILDING); - v2 = v1 & 0x3F; - if ( v1 & 0x100 ) - { - v6 = 5; - } - else - { - if ( (v1&0xFF) >= 0 ) - { - v4 = ((v1 & 0x40) != 0) + 1; - return v2 * v4; - } - v6 = 3; - } - v4 = v6; - return v2 * v4; + int multiplier = GetMultiplierForSkillLevel(v1, 1, 2, 3, 5); + return multiplier * (v1 & 0x3F); } //----- (004910A8) -------------------------------------------------------- int Player::GetMeditation() { int v1; // al@1 - int base_level; // ecx@1 - int v4; // eax@3 - signed int v6; // [sp-4h] [bp-4h]@2 v1 = GetActualSkillLevel(PLAYER_SKILL_MEDITATION); - base_level = v1 & 0x3F; - if ( v1 & 0x100 ) - { - v6 = 5; - } - else - { - if ( (v1&0xFF) >= 0 ) - { - v4 = ((v1 & 0x40) != 0) + 1; - return base_level * v4; - } - v6 = 3; - } - v4 = v6; - return base_level * v4; + int multiplier = GetMultiplierForSkillLevel(v1, 1, 2, 3, 5); + return multiplier * (v1 & 0x3F); } //----- (004910D3) -------------------------------------------------------- -int Player::CanIdentify(ItemGen *pItem) +bool Player::CanIdentify( ItemGen *pItem ) { unsigned __int16 v2; // ax@1 - unsigned __int16 v3; // bx@1 - int uSkillMult; // eax@3 int v5; // edi@7 - signed int v6; // ebp@7 - char *v7; // esi@7 - signed int uSkillMultiplier; // [sp-4h] [bp-14h]@2 if (CheckHiredNPCSpeciality(Scholar)) return true; - v2 = pPlayers[uActiveCharacter]->GetActualSkillLevel(PLAYER_SKILL_ITEM_ID); - v3 = v2; - if ( v2 & 1 ) - { - uSkillMultiplier = 5; - } - else - { - if ( (v2 & 0x80u) == 0 ) - { - uSkillMult = ((v2 & 0x40) != 0) + 1; - v5 = uSkillMult * (v3 & 0x3F); - v6 = 0; - v7 = (char *)&pItemsTable->pItems[pItem->uItemID].pIconName; - - if ( (signed int)SkillToMastery(v3) >= 4 ) - v6 = 1; - if ( v5 >= (unsigned __int8)v7[46] ) - v6 = 1; - return v6; - } - uSkillMultiplier = 3; - } - uSkillMult = uSkillMultiplier; - v5 = uSkillMult * (v3 & 0x3F); - v6 = 0; - v7 = (char *)&pItemsTable->pItems[pItem->uItemID].pIconName; - - if ( (signed int)SkillToMastery(v3) >= 4 ) - v6 = 1; - if ( v5 >= (unsigned __int8)v7[46] ) - v6 = 1; - return v6; + v2 = GetActualSkillLevel(PLAYER_SKILL_ITEM_ID); + if ( (signed int)SkillToMastery(v2) >= 4 ) + return true; + + int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5); + v5 = multiplier * (v2 & 0x3F); + return v5 >= pItemsTable->pItems[pItem->uItemID].uItemID_Rep_St; } //----- (00491151) -------------------------------------------------------- -int Player::CanRepair(ItemGen *a2) +bool Player::CanRepair( ItemGen *pItem ) { unsigned __int16 v2; // ax@1 - unsigned __int16 v3; // bx@1 - int v4; // eax@3 int v5; // edi@7 - signed int v6; // ebp@7 - signed int v10; // [sp-4h] [bp-14h]@2 - - - auto v7 = &pItemsTable->pItems[a2->uItemID]; + + ItemDesc* v7 = &pItemsTable->pItems[pItem->uItemID]; if (CheckHiredNPCSpeciality(Smith) && v7->uEquipType <= 2 || CheckHiredNPCSpeciality(Armorer) && v7->uEquipType >= 3 && v7->uEquipType <= 9 || CheckHiredNPCSpeciality(Alchemist) && v7->uEquipType >= 9 ) return true; v2 = GetActualSkillLevel(PLAYER_SKILL_REPAIR); - v3 = v2; - if (v2 & 0x100 ) - { - v10 = 5; - } - else - { - if ( (v2 & 0x80u) == 0 ) - { - v4 = ((v2 & 0x40) != 0) + 1; - goto LABEL_7; - } - v10 = 3; - } - v4 = v10; -LABEL_7: - v5 = v4 * (v3 & 0x3F); - v6 = 0; - if ( (signed int)SkillToMastery(v3) >= 4 ) + if ( (signed int)SkillToMastery(v2) >= 4 ) return true; - if ( v5 >= *((char *)(v7 + 1) + 2) ) - { - __debugbreak(); // really odd - return true; - } - return false; + + int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5); + v5 = multiplier * (v2 & 0x3F); + return v5 >= v7->uItemID_Rep_St; } //----- (004911F3) -------------------------------------------------------- int Player::GetMerchant() { - Player *v1; // edi@1 unsigned __int16 v2; // ax@1 - unsigned __int16 v3; // bx@1 - int v4; // esi@1 int v5; // edi@1 int v7; // eax@3 - int v8; // ecx@7 - signed int v9; // [sp-4h] [bp-10h]@6 - - v1 = this; + v2 = GetActualSkillLevel(PLAYER_SKILL_MERCHANT); - v3 = v1->pActiveSkills[PLAYER_SKILL_MERCHANT]; - v4 = v2 & 0x003F; - v5 = v1->pActiveSkills[PLAYER_SKILL_MERCHANT] & 0x3F; - if ( (signed int)SkillToMastery(v2) >= 4 ) + if ( SkillToMastery(v2) >= 4 ) return 10000; + v7 = GetPartyReputation(); - if ( !v4 ) + int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5); + v5 = multiplier * (v2 & 0x3F); + if (v5 == 0) + { return -v7; - if ( v3 & 0x100 ) - { - v9 = 5; - } - else - { - if ( (v3 & 0x80u) == 0 ) - { - v8 = ((v3 & 0x40) != 0) + 1; - return v5 * (v8 - 1) - v7 + v4 + 7; - } - v9 = 3; - } - v8 = v9; - return v5 * (v8 - 1) - v7 + v4 + 7; + } + return v5 - v7 + 7; } //----- (0049125A) -------------------------------------------------------- int Player::GetPerception() { - Player *v1; // edi@1 unsigned __int16 v2; // ax@1 - unsigned __int16 v3; // bx@1 - int v4; // esi@1 int v5; // edi@1 - int v7; // eax@5 - signed int v8; // [sp-4h] [bp-10h]@4 - - v1 = this; + v2 = GetActualSkillLevel(PLAYER_SKILL_PERCEPTION); - v3 = v1->pActiveSkills[PLAYER_SKILL_PERCEPTION]; - v4 = v2 & 0x3F; - v5 = v1->pActiveSkills[PLAYER_SKILL_PERCEPTION] & 0x3F; - if ( (signed int)SkillToMastery(v2) >= 4 ) + if ( SkillToMastery(v2) >= 4 ) return 10000; - if ( v3 & 0x100 ) - { - v8 = 5; - } - else - { - if ( (v3 & 0x80u) == 0 ) - { - v7 = ((v3 & 0x40) != 0) + 1; - return v4 + v5 * (v7 - 1); - } - v8 = 3; - } - v7 = v8; - return v4 + v5 * (v7 - 1); + + int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5); + v5 = multiplier * (v2 & 0x3F); + return v5; } //----- (004912B0) -------------------------------------------------------- int Player::GetDisarmTrap() { - Player *v1; // ebp@1 unsigned __int16 v2; // ax@1 - unsigned __int16 v3; // bx@1 - int v4; // esi@1 int v5; // edi@1 - int v7; // eax@7 - signed int v8; // [sp-4h] [bp-14h]@6 - - v1 = this; + v2 = GetActualSkillLevel(PLAYER_SKILL_TRAP_DISARM); - v3 = v1->pActiveSkills[29]; - v4 = v2 & 0x3F; - v5 = v1->pActiveSkills[29] & 0x3F; if ( (signed int)SkillToMastery(v2) >= 4 ) return 10000; - if ( HasEnchantedItemEquipped(35) ) - v4 *= 2; - if ( v3 & 0x100 ) - { - v8 = 5; - } - else - { - if ( (v3 & 0x80u) == 0 ) - { - v7 = ((v3 & 0x40) != 0) + 1; - return v4 + v5 * (v7 - 1); - } - v8 = 3; - } - v7 = v8; - return v4 + v5 * (v7 - 1); + + int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5); + if ( HasEnchantedItemEquipped(35) ) //only the real skill level is supposed to be added again, not the multiplied value + multiplier++; + v5 = multiplier * (v2 & 0x3F); + return v5; } //----- (00491317) -------------------------------------------------------- char Player::GetLearningPercent() { - Player *v1; // esi@1 int v2; // eax@1 - unsigned __int16 v3; // bx@1 - int v4; // ecx@1 - int v5; // eax@4 - signed int v7; // [sp-4h] [bp-Ch]@3 - - v1 = this; + v2 = GetActualSkillLevel(PLAYER_SKILL_LEARNING); - v3 = v1->pActiveSkills[36]; - v4 = v2 & 0x3F; - if ( v2 ) - { - if (v3 & 0x100 ) - { - v7 = 5; - } - else - { - if ( (v3 & 0x80u) == 0 ) - { - v5 = ((v3 & 0x40) != 0) + 1; - goto LABEL_8; - } - v7 = 3; - } - v5 = v7; -LABEL_8: - v2 = (v1->pActiveSkills[36] & 0x3F) * (v5 - 1) + v4 + 9; - } - return v2; + int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5); + return multiplier * v2 + 9; } //----- (0048C6AF) -------------------------------------------------------- @@ -4621,11 +4447,11 @@ int multiplier = 0; if ( inSkill == CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS ) { - multiplier = GetMultiplierForMastery(armmaster_skill, 0, 0, 1, 2); + multiplier = GetMultiplierForSkillLevel(armmaster_skill, 0, 0, 1, 2); } else if ( inSkill == CHARACTER_ATTRIBUTE_ATTACK ) { - multiplier = GetMultiplierForMastery(armmaster_skill, 0, 1, 1, 2); + multiplier = GetMultiplierForSkillLevel(armmaster_skill, 0, 1, 1, 2); } armsMasterBonus = multiplier * (armmaster_skill & 0x3F); } @@ -4636,7 +4462,7 @@ if (HasItemEquipped(EQUIP_BOW)) { int bowSkillLevel = GetActualSkillLevel(PLAYER_SKILL_DODGE); - int multiplier = GetMultiplierForMastery(bowSkillLevel, 0, 0, 0, 1); + int multiplier = GetMultiplierForSkillLevel(bowSkillLevel, 0, 0, 0, 1); return multiplier * (bowSkillLevel & 0x3F); } return 0; @@ -4672,27 +4498,27 @@ switch (itemSkillType) { case PLAYER_SKILL_STAFF: - multiplier = GetMultiplierForMastery(currArmorSkillLevel, 0, 1, 1, 1); + multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 0, 1, 1, 1); break; case PLAYER_SKILL_SWORD: case PLAYER_SKILL_SPEAR: - multiplier = GetMultiplierForMastery(currArmorSkillLevel, 0, 0, 0, 1); + multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 0, 0, 0, 1); break; case PLAYER_SKILL_SHIELD: wearingArmor = true; - multiplier = GetMultiplierForMastery(currArmorSkillLevel, 1, 1, 2, 2); + multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 1, 1, 2, 2); break; case PLAYER_SKILL_LEATHER: wearingLeather = true; - multiplier = GetMultiplierForMastery(currArmorSkillLevel, 1, 1, 2, 2); + multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 1, 1, 2, 2); break; case PLAYER_SKILL_CHAIN: wearingArmor = true; - multiplier = GetMultiplierForMastery(currArmorSkillLevel, 1, 1, 1, 1); + multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 1, 1, 1, 1); break; case PLAYER_SKILL_PLATE: wearingArmor = true; - multiplier = GetMultiplierForMastery(currArmorSkillLevel, 1, 1, 1, 1); + multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 1, 1, 1, 1); break; } ACSum += multiplier * (currArmorSkillLevel & 0x3F); @@ -4701,7 +4527,7 @@ int dodgeSkillLevel = GetActualSkillLevel(PLAYER_SKILL_DODGE); int dodgeMastery = SkillToMastery(dodgeSkillLevel); - int multiplier = GetMultiplierForMastery(dodgeSkillLevel, 1, 2, 3, 3); + int multiplier = GetMultiplierForSkillLevel(dodgeSkillLevel, 1, 2, 3, 3); if ( !wearingArmor && (!wearingLeather || dodgeMastery == 4) ) { ACSum += multiplier * (dodgeSkillLevel & 0x3F); @@ -4717,7 +4543,7 @@ { return 0; } - int multiplier = GetMultiplierForMastery(unarmedSkill, 0, 1, 2, 2); + int multiplier = GetMultiplierForSkillLevel(unarmedSkill, 0, 1, 2, 2); return armsMasterBonus + multiplier * (unarmedSkill & 0x3F); } for (int i = 0; i < 16; ++i) @@ -4731,13 +4557,13 @@ int currentItemSkillLevel = this->GetActualSkillLevel(currItemSkillType); if (currItemSkillType == PLAYER_SKILL_BLASTER) { - int multiplier = GetMultiplierForMastery(currentItemSkillLevel, 1, 2, 3, 5); + int multiplier = GetMultiplierForSkillLevel(currentItemSkillLevel, 1, 2, 3, 5); return multiplier * (currentItemSkillLevel & 0x3F); } else if (currItemSkillType == PLAYER_SKILL_STAFF && this->GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0) { int unarmedSkillLevel = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED); - int multiplier = GetMultiplierForMastery(currentItemSkillLevel, 1, 1, 2, 2); + int multiplier = GetMultiplierForSkillLevel(currentItemSkillLevel, 1, 1, 2, 2); return multiplier * (unarmedSkillLevel & 0x3F) + armsMasterBonus + (currentItemSkillLevel & 0x3F); } else @@ -4759,12 +4585,12 @@ int currentItemSkillLevel = this->GetActualSkillLevel(currentItemSkillType); if ( currentItemSkillType == PLAYER_SKILL_BOW ) { - int multiplier = GetMultiplierForMastery(currentItemSkillLevel, 1, 1, 1, 1); + int multiplier = GetMultiplierForSkillLevel(currentItemSkillLevel, 1, 1, 1, 1); return multiplier * (currentItemSkillLevel & 0x3F); } else if ( currentItemSkillType == PLAYER_SKILL_BLASTER ) { - int multiplier = GetMultiplierForMastery(currentItemSkillLevel, 1, 2, 3, 5); + int multiplier = GetMultiplierForSkillLevel(currentItemSkillLevel, 1, 2, 3, 5); return multiplier * (currentItemSkillLevel & 0x3F); } } @@ -4780,7 +4606,7 @@ { return 0; } - int multiplier = GetMultiplierForMastery(unarmedSkillLevel, 0, 1, 2, 2); + int multiplier = GetMultiplierForSkillLevel(unarmedSkillLevel, 0, 1, 2, 2); return multiplier * (unarmedSkillLevel & 0x3F); } for (int i = 0; i < 16; i++) @@ -4800,7 +4626,7 @@ if ( SkillToMastery(currItemSkillLevel) >= 4 && this->GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0) { int unarmedSkillLevel = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED); - int multiplier = GetMultiplierForMastery(unarmedSkillLevel, 0, 1, 2, 2); + int multiplier = GetMultiplierForSkillLevel(unarmedSkillLevel, 0, 1, 2, 2); return multiplier * (unarmedSkillLevel & 0x3F); } else @@ -4810,23 +4636,23 @@ break; case PLAYER_SKILL_DAGGER: - multiplier = GetMultiplierForMastery(currItemSkillLevel, 0, 0, 0, 1); + multiplier = GetMultiplierForSkillLevel(currItemSkillLevel, 0, 0, 0, 1); baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F); return armsMasterBonus + baseSkillBonus; break; case PLAYER_SKILL_SWORD: - multiplier = GetMultiplierForMastery(currItemSkillLevel, 0, 0, 0, 0); + multiplier = GetMultiplierForSkillLevel(currItemSkillLevel, 0, 0, 0, 0); baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F); return armsMasterBonus + baseSkillBonus; break; case PLAYER_SKILL_MACE: case PLAYER_SKILL_SPEAR: - multiplier = GetMultiplierForMastery(currItemSkillLevel, 0, 1, 1, 1); + multiplier = GetMultiplierForSkillLevel(currItemSkillLevel, 0, 1, 1, 1); baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F); return armsMasterBonus + baseSkillBonus; break; case PLAYER_SKILL_AXE: - multiplier = GetMultiplierForMastery(currItemSkillLevel, 0, 0, 1, 1); + multiplier = GetMultiplierForSkillLevel(currItemSkillLevel, 0, 0, 1, 1); baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F); return armsMasterBonus + baseSkillBonus; break; @@ -4841,7 +4667,7 @@ } } -unsigned int Player::GetMultiplierForMastery(unsigned int skillValue, int mult1, int mult2, int mult3, int mult4) +unsigned int Player::GetMultiplierForSkillLevel(unsigned int skillValue, int mult1, int mult2, int mult3, int mult4) { int masteryLvl = SkillToMastery(skillValue); switch (masteryLvl)