Mercurial > mm7
diff Player.cpp @ 1704:cc1d68c17e19
Слияние
author | Ritor1 |
---|---|
date | Mon, 23 Sep 2013 09:34:23 +0600 |
parents | ef42788fef1d |
children | be43171d7bc6 f8414042db1f |
line wrap: on
line diff
--- a/Player.cpp Mon Sep 23 09:33:13 2013 +0600 +++ b/Player.cpp Mon Sep 23 09:34:23 2013 +0600 @@ -60,6 +60,9 @@ +std::array<int, 5> StealingMasteryBonuses = {0, 100, 200, 300, 500}; //dword_4EDEA0 //the zeroth element isn't accessed, it just helps avoid -1 indexing, originally 4 element array off by one +std::array<int, 5> StealingRandomBonuses = {-200, -100, 0, 100, 200}; //dword_4EDEB4 +std::array<int, 5> StealingEnchantmentBonusForSkill = {0, 2, 4, 6, 10}; //dword_4EDEC4 //the zeroth element isn't accessed, it just helps avoid -1 indexing, originally 4 element array off by one @@ -130,7 +133,7 @@ {100, 100, 40, 10}, //Speed {100, 100, 100, 100}}; //Luck -signed int pAgeingTable[4] = {50, 100, 150, 0xFFFF}; +unsigned int pAgeingTable[4] = {50, 100, 150, 0xFFFF}; std::array<unsigned int, 18> pConditionImportancyTable = {{16, 15, 14, 17, 13, 2, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1, 0}}; @@ -1533,7 +1536,7 @@ } //----- (0048CCF5) -------------------------------------------------------- -int Player::GetActualAttack(int a2) +int Player::GetActualAttack( bool a2 ) { int v3; // eax@1 int v4; // edi@1 @@ -1704,7 +1707,7 @@ } else { - v3 = GetActualAttack(1); + v3 = GetActualAttack(true); } return v3; } @@ -2011,25 +2014,24 @@ } //----- (0048D76C) -------------------------------------------------------- -bool Player::StealFromShop(ItemGen *itemToSteal, int a3, int reputation, int a5, int *a6) //check stealing in IDA pro once I get home. The whole thing looks odd, dword_4EDEB4 and dword_4EDEA0 are never filled, might be a bug, might me on purpose +int Player::StealFromShop( ItemGen *itemToSteal, int extraStealDifficulty, int reputation, int a5, int *fineIfFailed ) //returns an int, but is the return value is compared to zero, so might change to bool { unsigned __int16 v6; // cx@8 int v7; // edi@8 unsigned int v8; // ebx@8 unsigned int itemvalue; // esi@8 int v10; // eax@8 - int v11; // edi@12 - bool result; // eax@13 + int currMaxItemValue; // edi@12 if ( !itemToSteal - || this->pConditions[16] - || this->pConditions[14] - || this->pConditions[15] - || this->pConditions[4] - || this->pConditions[13] - || this->pConditions[2] ) - { - result = 0; + || this->IsEradicated() + || this->IsDead() + || this->IsPertified() + || this->IsDrunk() + || this->IsUnconcious() + || this->IsAsleep() ) + { + return 0; } else { @@ -2038,23 +2040,33 @@ v8 = SkillToMastery(v6); itemvalue = itemToSteal->GetValue(); v10 = pItemsTable->pItems[itemToSteal->uItemID].uEquipType; - if ( !pItemsTable->pItems[itemToSteal->uItemID].uEquipType || v10 == 1 || v10 == 2 ) + if ( v10 == EQUIP_OFF_HAND || v10 == EQUIP_MAIN_HAND || v10 == EQUIP_BOW ) itemvalue *= 3; - v11 = dword_4EDEB4[rand() % 100 / 20] + v7 * dword_4EDEA0[v8]; - *a6 = 100 * (reputation + a3) + itemvalue + (a5 != 0 ? 0x1F4 : 0); + currMaxItemValue = StealingRandomBonuses[rand() % 5] + v7 * StealingMasteryBonuses[v8]; + *fineIfFailed = 100 * (reputation + extraStealDifficulty) + itemvalue; + if (a5) + { + *fineIfFailed += 500; + } if ( rand() % 100 >= 5 ) { - if ( *a6 > v11 ) - result = *a6 - v11 < 500; + if ( *fineIfFailed > currMaxItemValue ) + if (*fineIfFailed - currMaxItemValue < 500) + { + return 1; + } + else + { + return 0; + } else - result = 2; + return 2; } else { - result = 0; - } - } - return result; + return 0; + } + } } // 4EDEA0: using guessed type int dword_4EDEA0[]; // 4EDEB4: using guessed type int dword_4EDEB4[]; @@ -2062,162 +2074,130 @@ //----- (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(); - v28 = 4 * v8; - v30 = dword_4EDEA0[v8]; - v29 = dword_4EDEB4[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 ) - { - if ( v11 % 100 >= 70 ) + 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 >= 70 ) //stealing gold + { + enchBonusSum = 0; + for (int i = 0; i < v7; i++) + { + 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 + { + *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 if ( v11 % 100 >= 40 ) //stealing an item + { + 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 ) { - v19 = 0; - if ( v7 > 0 ) - { - do - { - --v7; - v19 += rand() % dword_4EDEC4[v28 / 4] + 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; - } + 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 { - 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 ) - { - 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; - } + ItemGen* itemToSteal = &actroPtr->array_000234[rand() % 4]; + memcpy(&tempItem, itemToSteal, sizeof(tempItem)); + itemToSteal->Reset(); + carriedItemId = tempItem.uItemID; } - } - v26 = (int)v31->pName; - v25 = pGlobalTXT_LocalizationStrings[377]; - } - v23 = pTmpBuf2.data(); - sprintfex(pTmpBuf2.data(), v25, v26); - goto LABEL_43; - } - return 0; + 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; + } + } + 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[]; @@ -2288,173 +2268,125 @@ } //----- (0048DCF6) -------------------------------------------------------- -int Player::_48DCF6(int a2, Actor *pActor) //TODO check this with IDA to see what the uninitialized vars are supposed to contain -{ +int Player::ReceiveSpecialAttackEffect( int attType, struct Actor *pActor ) +{ + SPECIAL_ATTACK_TYPE attTypeCast = (SPECIAL_ATTACK_TYPE) attType; signed int v3; // edi@1 signed int v4; // ebx@1 - Player *v5; // esi@1 int v6; // eax@2 - int v7; // eax@5 int v8; // eax@8 - int v9; // ebx@8 int v10; // eax@8 int v11; // ebx@8 - signed int v12; // edx@9 ItemGen *v13; // eax@9 - int v14; // edx@16 - unsigned int v15; // edx@17 - int v16; // edx@26 - unsigned int v17; // edx@27 - signed int v19; // edx@38 - int *v20; // ecx@38 - signed int v21; // eax@40 int v22; // eax@49 signed int v23; // ebx@49 - unsigned int v24; // eax@60 - int v25; // ecx@61 - int v26; // ebx@74 void *v27; // ecx@76 - unsigned int v28; // ebx@78 - signed int result; // eax@86 - SoundID v30; // [sp-20h] [bp-C0h]@56 - signed int v31; // [sp-1Ch] [bp-BCh]@56 - unsigned int v32; // [sp-18h] [bp-B8h]@56 - signed int v33; // [sp-14h] [bp-B4h]@56 - signed int v34; // [sp-10h] [bp-B0h]@56 - int v35; // [sp-Ch] [bp-ACh]@56 - unsigned int v36; // [sp-8h] [bp-A8h]@51 - unsigned int v37; // [sp-8h] [bp-A8h]@56 - unsigned int v38; // [sp-8h] [bp-A8h]@57 - unsigned int v39; // [sp-8h] [bp-A8h]@68 - enum CHARACTER_ATTRIBUTE_TYPE v40; // [sp-4h] [bp-A4h]@4 - int v41; // [sp-4h] [bp-A4h]@51 - int v42; // [sp-4h] [bp-A4h]@56 - int v43; // [sp-4h] [bp-A4h]@57 - signed int v44; // [sp-4h] [bp-A4h]@59 - int v45; // [sp-4h] [bp-A4h]@68 char v46[140]; // [sp+Ch] [bp-94h]@13 unsigned int v47; // [sp+98h] [bp-8h]@1 - int v48; // [sp+9Ch] [bp-4h]@1 - - v3 = 0; + ItemGen* v48; // [sp+9Ch] [bp-4h]@1 + v4 = 0; - v5 = this; v47 = 0; - v48 = 0; - switch ( a2 ) - { - case 1: + switch ( attTypeCast ) + { + case SPECIAL_ATTACK_CURSE: v6 = GetActualWillpower(); - goto LABEL_46; - case 2: - case 3: - case 4: - case 9: - case 10: - case 11: - case 13: - case 21: + v11 = GetParameterBonus(v6); + break; + case SPECIAL_ATTACK_WEAK: + case SPECIAL_ATTACK_SLEEP: + case SPECIAL_ATTACK_DRUNK: + case SPECIAL_ATTACK_DISEASE1: + case SPECIAL_ATTACK_DISEASE2: + case SPECIAL_ATTACK_DISEASE3: + case SPECIAL_ATTACK_UNCONSCIOUS: + case SPECIAL_ATTACK_AGING: v6 = GetActualEndurance(); - goto LABEL_46; - case 5: - case 12: - case 23: - v40 = (CHARACTER_ATTRIBUTE_TYPE)14; - goto LABEL_5; - case 15: - v40 = (CHARACTER_ATTRIBUTE_TYPE)13; - goto LABEL_5; - case 6: - case 7: - case 8: - case 14: - case 16: - v40 = (CHARACTER_ATTRIBUTE_TYPE)15; -LABEL_5: - v7 = GetActualResistance(v40); - goto LABEL_47; - case 22: + v11 = GetParameterBonus(v6); + break; + case SPECIAL_ATTACK_INSANE: + case SPECIAL_ATTACK_PARALYZED: + case SPECIAL_ATTACK_FEAR: + v11 = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_MIND); + break; + case SPECIAL_ATTACK_PETRIFIED: + v11 = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_EARTH); + break; + case SPECIAL_ATTACK_POISON1: + case SPECIAL_ATTACK_POISON2: + case SPECIAL_ATTACK_POISON3: + case SPECIAL_ATTACK_DEAD: + case SPECIAL_ATTACK_ERADICATED: + v11 = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_BODY); + break; + case SPECIAL_ATTACK_MANA_DRAIN: v8 = GetActualWillpower(); - v9 = GetParameterBonus(v8); v10 = GetActualIntelligence(); - v11 = (GetParameterBonus(v10) + v9) >> 1; + v11 = (GetParameterBonus(v10) + GetParameterBonus(v8)) / 2; break; - case 17: - v12 = 0; - v13 = this->pInventoryItemList; - do - { - if ( (signed int)v13->uItemID > 0 && (signed int)v13->uItemID <= 134 && !v13->IsBroken()) - v46[v4++] = v12; - ++v12; - ++v13; - } - while ( v12 < 138 ); - goto LABEL_36; - case 18: - v14 = 0; - do - { - if ( HasItemEquipped((ITEM_EQUIP_TYPE)v14) ) + case SPECIAL_ATTACK_BREAK_ANY: + for (int i = 0; i < 138; i++) + { + v13 = &this->pInventoryItemList[i]; + if ( v13->uItemID > 0 && v13->uItemID <= 134 && !v13->IsBroken()) + v46[v4++] = i; + } + if ( !v4 ) + return 0; + v48 = &this->pInventoryItemList[v46[rand() % v4]]; + v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod); + break; + case SPECIAL_ATTACK_BREAK_ARMOR: + for (int i = 0; i < 16; i++ ) + { + if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) ) { - __debugbreak(); // player.cpp(2871): warning C4700: uninitialized local variable 'v15' used - if ( v15 == EQUIP_ARMOUR ) - v46[v4++] = LOBYTE(v5->pEquipment.uArmor) - 1; - if ( (!v15 || v15 == 1) && GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v15) == 4 ) - v46[v4++] = *((char *)&v5->pEquipment.uShield + 4 * v15) - 1; + if ( i == EQUIP_ARMOUR ) + v46[v4++] = this->pEquipment.uArmor - 1; + if ( (i == EQUIP_OFF_HAND || i == EQUIP_MAIN_HAND) && GetEquippedItemEquipType((ITEM_EQUIP_TYPE)i) == EQUIP_SHIELD ) + v46[v4++] = this->pEquipment.pIndices[i] - 1; } - v14 = v15 + 1; - } - while ( v14 < 16 ); - goto LABEL_36; - case 19: - v16 = 0; - do - { - if ( HasItemEquipped((ITEM_EQUIP_TYPE)v16) ) + } + if ( !v4 ) + return 0; + v48 = &this->pInventoryItemList[v46[rand() % v4]]; + v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod); + break; + case SPECIAL_ATTACK_BREAK_WEAPON: + for (int i = 0; i < 16; i++ ) + { + if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) ) { - __debugbreak(); // player.cpp(2886): warning C4700: uninitialized local variable 'v17' used - if ( v17 == 2 ) - v46[v4++] = LOBYTE(v5->pEquipment.uBow) - 1; - if ( (!v17 || v17 == 1) - && (!GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v17) || GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v17) == 1) ) - v46[v4++] = *((char *)&v5->pEquipment.uShield + 4 * v17) - 1; + if ( i == EQUIP_BOW ) + v46[v4++] = LOBYTE(this->pEquipment.uBow) - 1; + if ( (i == EQUIP_OFF_HAND || i == EQUIP_MAIN_HAND) + && (GetEquippedItemEquipType((ITEM_EQUIP_TYPE)i) == EQUIP_OFF_HAND || GetEquippedItemEquipType((ITEM_EQUIP_TYPE)i) == EQUIP_MAIN_HAND) ) + v46[v4++] = this->pEquipment.pIndices[i] - 1; } - v16 = v17 + 1; - } - while ( v16 < 16 ); -LABEL_36: + } if ( !v4 ) - goto LABEL_87; - v48 = (int)&v5->pInventoryItemList[(unsigned __int8)v46[rand() % v4]]; - v11 = 3 * (pItemsTable->pItems[*(int *)v48].uMaterial + pItemsTable->pItems[*(int *)v48].uDamageMod); + return 0; + v48 = &this->pInventoryItemList[v46[rand() % v4]]; + v11 = 3 * (pItemsTable->pItems[v48->uItemID].uMaterial + pItemsTable->pItems[v48->uItemID].uDamageMod); break; - case 20: - v19 = 0; - v20 = this->pInventoryMatrix; - do - { - if ( *v20 > 0 ) + case SPECIAL_ATTACK_STEAL: + for ( int i = 0; i < 126; i++ ) + { + int ItemPosInList = this->pInventoryMatrix[i]; + if (ItemPosInList > 0) { - v21 = *(int *)&v5->pInventoryItemList[*v20-1]; - if ( v21 > 0 ) + ItemGen* v21 = &this->pInventoryItemList[ItemPosInList - 1]; + if ( v21->uItemID > 0 && v21->uItemID <= 134 ) { - if ( v21 <= 134 ) - v46[v4++] = v19; + v46[v4++] = i; } } - ++v19; - ++v20; - } - while ( v19 < 126 ); + } if ( !v4 ) - goto LABEL_87; - v47 = (unsigned __int8)v46[rand() % v4]; + return 0; + v47 = v46[rand() % v4]; v6 = GetActualAccuracy(); -LABEL_46: - v7 = GetParameterBonus(v6); -LABEL_47: - v11 = v7; + v11 = GetParameterBonus(v6); break; default: v11 = 0; @@ -2464,185 +2396,168 @@ v23 = GetParameterBonus(v22) + v11 + 30; if ( rand() % v23 >= 30 ) { -LABEL_87: - result = 0; + return 0; } else { - switch ( a2 ) - { - case 1: - v41 = 1; - v36 = 0; - goto LABEL_56; - case 2: - v41 = 1; - v36 = 1; - goto LABEL_56; - case 3: - v41 = 1; - v36 = 2; - goto LABEL_56; - case 23: - v41 = 1; - v36 = 3; - goto LABEL_56; - case 4: - v41 = 1; - v36 = 4; -LABEL_56: - SetCondition(v36, v41); - v42 = 0; - v37 = 0; - v35 = 0; - v34 = 0; - v33 = -1; - v32 = 0; - v31 = 0; - v30 = (SoundID)221; - goto LABEL_83; - case 5: - v43 = 1; - v38 = 5; - goto LABEL_70; - case 6: - case 7: - case 8: - if ( a2 == 6 ) + for ( v3 = 0; v3 < 4; v3++ ) + { + if ( this == pPlayers[v3 + 1] ) + break; + } + + switch ( attTypeCast ) + { + case SPECIAL_ATTACK_CURSE: + SetCondition(Condition_Cursed, 1); + pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_WEAK: + SetCondition(Condition_Weak, 1); + pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_SLEEP: + SetCondition(Condition_Sleep, 1); + pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_DRUNK: + SetCondition(Condition_Drunk, 1); + pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_INSANE: + SetCondition(Condition_Insane, 1); + pAudioPlayer->PlaySound((SoundID)224, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_POISON1: + SetCondition(Condition_Poison1, 1); + pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_POISON2: + SetCondition(Condition_Poison2, 1); + pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_POISON3: + SetCondition(Condition_Poison3, 1); + pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_DISEASE1: + SetCondition(Condition_Disease1, 1); + pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_DISEASE2: + SetCondition(Condition_Disease2, 1); + pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_DISEASE3: + SetCondition(Condition_Disease3, 1); + pAudioPlayer->PlaySound((SoundID)222, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_PARALYZED: + SetCondition(Condition_Paralyzed, 1); + pAudioPlayer->PlaySound((SoundID)224, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_UNCONSCIOUS: + SetCondition(Condition_Unconcious, 1); + pAudioPlayer->PlaySound((SoundID)224, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_DEAD: + SetCondition(Condition_Dead, 1); + pAudioPlayer->PlaySound((SoundID)225, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_PETRIFIED: + SetCondition(Condition_Pertified, 1); + pAudioPlayer->PlaySound((SoundID)225, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_ERADICATED: + SetCondition(Condition_Eradicated, 1); + pAudioPlayer->PlaySound((SoundID)225, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_BREAK_ANY: + case SPECIAL_ATTACK_BREAK_ARMOR: + case SPECIAL_ATTACK_BREAK_WEAPON: + if ( !(v48->uAttributes & ITEM_ENCHANTED) ) { - v44 = 6; - goto LABEL_60; - } - v25 = 2 * (a2 != 8) + 8; - goto LABEL_65; - case 9: - if ( a2 == 6 ) - { - v44 = 7; -LABEL_60: - v24 = v44; - } - else - { - v25 = 2 * (a2 != 8) + 9; -LABEL_65: - v24 = v25; + PlaySound(SPEECH_40, 0); + v48->SetBroken(); + pAudioPlayer->PlaySound((SoundID)47, 0, 0, -1, 0, 0, 0, 0); } - SetCondition(v24, 1); - v42 = 0; - v37 = 0; - v35 = 0; - v34 = 0; - v33 = -1; - v32 = 0; - v31 = 0; - v30 = (SoundID)222; -LABEL_83: - pAudioPlayer->PlaySound(v30, v31, v32, v33, v34, v35, v37, v42); - do - { -LABEL_84: - if ( v5 == pPlayers[v3 + 1] ) - break; - ++v3; - } - while ( v3 < 4 ); pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); - result = 1; + return 1; break; - case 12: - v43 = 1; - v38 = 12; - goto LABEL_70; - case 15: - v45 = 1; - v39 = 15; - goto LABEL_73; - case 13: - v43 = 1; - v38 = 13; -LABEL_70: - SetCondition(v38, v43); - v42 = 0; - v37 = 0; - v35 = 0; - v34 = 0; - v33 = -1; - v32 = 0; - v31 = 0; - v30 = (SoundID)224; - goto LABEL_83; - case 14: - v45 = 1; - v39 = 14; - goto LABEL_73; - case 16: - v45 = 1; - v39 = 16; -LABEL_73: - SetCondition(v39, v45); - v42 = 0; - v37 = 0; - v35 = 0; - v34 = 0; - v33 = -1; - v32 = 0; - v31 = 0; - v30 = (SoundID)225; - goto LABEL_83; - case 17: - case 18: - case 19: - v26 = v48; - if ( *(char *)(v48 + 21) & 2 ) - goto LABEL_84; - PlaySound(SPEECH_40, 0); - *(int *)(v26 + 20) |= 2u; - goto LABEL_79; - case 20: + case SPECIAL_ATTACK_STEAL: PlaySound(SPEECH_40, 0); v27 = pActor->array_000234; if ( pActor->array_000234[0].uItemID ) { v27 = &pActor->array_000234[1]; if ( pActor->array_000234[1].uItemID ) - goto LABEL_84; + { + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + } } - v28 = v47; - memcpy(v27, &v5->pInventoryItemList[v5->pInventoryMatrix[v47]-1], 0x24u); - RemoveItemAtInventoryIndex(v28); -LABEL_79: - v42 = 0; - v37 = 0; - v35 = 0; - v34 = 0; - v33 = -1; - v32 = 0; - v31 = 0; - v30 = (SoundID)47; - goto LABEL_83; - case 21: + memcpy(v27, &this->pInventoryItemList[this->pInventoryMatrix[v47]-1], 0x24u); + RemoveItemAtInventoryIndex(v47); + pAudioPlayer->PlaySound((SoundID)47, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_AGING: PlaySound(SPEECH_42, 0); - ++v5->sAgeModifier; - goto LABEL_82; - case 22: + ++this->sAgeModifier; + pAudioPlayer->PlaySound((SoundID)226, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_MANA_DRAIN: PlaySound(SPEECH_41, 0); - v5->sMana = 0; -LABEL_82: - v42 = 0; - v37 = 0; - v35 = 0; - v34 = 0; - v33 = -1; - v32 = 0; - v31 = 0; - v30 = (SoundID)226; - goto LABEL_83; + this->sMana = 0; + pAudioPlayer->PlaySound((SoundID)226, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; + case SPECIAL_ATTACK_FEAR: + SetCondition(Condition_Fear, 1); + pAudioPlayer->PlaySound((SoundID)221, 0, 0, -1, 0, 0, 0, 0); + pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3); + return 1; + break; default: - goto LABEL_87; - } - } - return result; + return 0; + } + } } // 48DCF6: using guessed type char var_94[140]; @@ -4419,7 +4334,7 @@ //----- (004908A8) -------------------------------------------------------- bool Player::DiscardConditionIfLastsLongerThan(unsigned int uCondition, unsigned __int64 uTime) { - if ( pConditions[uCondition] && (uTime < pConditions[uCondition]) ) + if ( pConditions[uCondition] && (uTime < (signed long long)pConditions[uCondition]) ) { pConditions[uCondition] = 0i64; return true; @@ -4506,7 +4421,7 @@ } else { - thisb->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * 213.3333333333333); + thisb->SetRecoveryTime((int)(flt_6BE3A4_debug_recmod1 * 213.3333333333333)); } } pMouse->RemoveHoldingItem(); @@ -4801,7 +4716,7 @@ } else { - thisb->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * 213.3333333333333); + thisb->SetRecoveryTime((int)(flt_6BE3A4_debug_recmod1 * 213.3333333333333)); } } pMouse->RemoveHoldingItem(); @@ -7467,68 +7382,27 @@ //----- (00439FCB) -------------------------------------------------------- -void __fastcall DamagePlayerFromMonster(unsigned int uObjID, int a2, Vec3_int_ *pPos, unsigned int a4) -{ - signed int v4; // esi@1 - unsigned int v5; // ecx@1 +void __fastcall DamagePlayerFromMonster(unsigned int uObjID, int element, Vec3_int_ *pPos, unsigned int a4) +{ Player *playerPtr; // ebx@3 Actor *actorPtr; // esi@3 unsigned int v8; // eax@4 - int v11; // edx@8 - int v14; // edx@16 - enum SoundID v17; // eax@24 - unsigned __int16 v21; // ax@29 - signed int v22; // edi@36 - int v23; // eax@38 - signed int v24; // eax@44 - AIState v25; // cx@47 - signed int v26; // eax@49 - int v27; // eax@54 - int v34; // edi@61 - int v35; // eax@70 - int v36; // st7@70 - SpriteObject *v37; // ebx@77 - int v38; // edi@77 - int v39; // esi@77 - int v40; // eax@77 - int v41; // eax@77 - Player *v43; // eax@81 - //Actor *actorPtr; // esi@82 - Player *v45; // edi@84 - unsigned __int16 v46; // ax@84 - int v48; // eax@107 - unsigned __int16 v49; // ax@116 - int v50; // ebx@123 - unsigned __int16 v51; // ax@124 - int v53; // eax@128 - signed int v54; // eax@134 - unsigned __int16 v55; // cx@137 + int spellId; // eax@38 signed int recvdMagicDmg; // eax@139 - int v57; // eax@144 - int v64; // ebx@151 - int v65; // eax@161 - int v66; // st7@161 - signed int v68; // eax@170 - int v69; // ecx@170 - int v70; // eax@171 int v72[4]; // [sp+30h] [bp-24h]@164 - signed int v74; // [sp+44h] [bp-10h]@1 int healthBeforeRecvdDamage; // [sp+48h] [bp-Ch]@3 unsigned int uActorID; // [sp+4Ch] [bp-8h]@1 - int dmgToReceive; // [sp+50h] [bp-4h]@26 - - v4 = PID_ID(uObjID); - v5 = PID_TYPE(uObjID) - 2; - v74 = a2; - uActorID = v4; - if ( v5 ) + + uActorID = PID_ID(uObjID); + if ( PID_TYPE(uObjID) != 2) { playerPtr = &pParty->pPlayers[a4]; - actorPtr = &pActors[v4]; + actorPtr = &pActors[uActorID]; healthBeforeRecvdDamage = playerPtr->sHealth; - if ( v5 != 1 || !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) ) + if ( PID_TYPE(uObjID) != 3 || !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) ) return; v8 = playerPtr->pEquipment.uArmor; + SoundID soundToPlay; if ( !v8 || playerPtr->pInventoryItemList[v8 - 1].IsBroken() || @@ -7537,101 +7411,102 @@ ) ) { - v14 = rand() % 4; - switch (v14) - { - case 0 : v17 = (SoundID)108; break; - case 1 : v17 = (SoundID)109; break; - case 2 : v17 = (SoundID)110; break; - case 3 : v17 = (SoundID)44; break; + int randVal = rand() % 4; + switch (randVal) + { + case 0 : soundToPlay = (SoundID)108; break; + case 1 : soundToPlay = (SoundID)109; break; + case 2 : soundToPlay = (SoundID)110; break; + case 3 : soundToPlay = (SoundID)44; break; } } else { - v11 = rand() % 4; - switch (v11) - { - case 0 : v17 = (SoundID)105; break; - case 1 : v17 = (SoundID)106; break; - case 2 : v17 = (SoundID)107; break; - case 3 : v17 = (SoundID)45; break; - } - } - pAudioPlayer->PlaySound(v17, PID(OBJECT_Player,a4 + 80), 0, -1, 0, 0, 0, 0); - dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, v74); + int randVal = rand() % 4; + switch (randVal) + { + case 0 : soundToPlay = (SoundID)105; break; + case 1 : soundToPlay = (SoundID)106; break; + case 2 : soundToPlay = (SoundID)107; break; + case 3 : soundToPlay = (SoundID)45; break; + } + } + pAudioPlayer->PlaySound(soundToPlay, PID(OBJECT_Player,a4 + 80), 0, -1, 0, 0, 0, 0); + int dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, element); if ( actorPtr->pActorBuffs[3].uExpireTime > 0 ) { - v21 = actorPtr->pActorBuffs[3].uPower; - if ( v21 ) - dmgToReceive /= (signed int)v21; - } - switch (v74) - { - case 0: v22 = actorPtr->pMonsterInfo.uAttack1Type; + __int16 spellPower = actorPtr->pActorBuffs[3].uPower; + if ( spellPower ) + dmgToReceive /= (signed int)spellPower; + } + int damageType; + switch (element) + { + case 0: damageType = actorPtr->pMonsterInfo.uAttack1Type; break; - case 1: v22 = actorPtr->pMonsterInfo.uAttack2Type; + case 1: damageType = actorPtr->pMonsterInfo.uAttack2Type; break; - case 2: v23 = actorPtr->pMonsterInfo.uSpell1ID; - v22 = LOBYTE(pSpellStats->pInfos[v23].uSchool); + case 2: spellId = actorPtr->pMonsterInfo.uSpell1ID; + damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool); break; - case 3: v23 = actorPtr->pMonsterInfo.uSpell2ID; - v22 = LOBYTE(pSpellStats->pInfos[v23].uSchool); + case 3: spellId = actorPtr->pMonsterInfo.uSpell2ID; + damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool); break; - case 4: v22 = actorPtr->pMonsterInfo.field_3C_some_special_attack; + case 4: damageType = actorPtr->pMonsterInfo.field_3C_some_special_attack; break; default: - case 5: v22 = 4; //yes, the original just assigned the value 4 + case 5: damageType = 4; //yes, the original just assigned the value 4 break; } if ( !(dword_6BE368_debug_settings_2 & 0x10) ) { - v24 = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v22); + dmgToReceive = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)damageType); if ( playerPtr->pPlayerBuffs[10].uExpireTime > 0 ) { - v25 = actorPtr->uAIState; - if ( v25 != Dying && v25 != Dead) + int actorState = actorPtr->uAIState; + if ( actorState != Dying && actorState != Dead) { - v26 = stru_50C198.CalcMagicalDamageToActor(actorPtr, v22, v24); - actorPtr->sCurrentHP -= v26; - if ( v26 >= 0 ) + int reflectedDamage = stru_50C198.CalcMagicalDamageToActor(actorPtr, damageType, dmgToReceive); + actorPtr->sCurrentHP -= reflectedDamage; + if ( reflectedDamage >= 0 ) { if ( actorPtr->sCurrentHP >= 1 ) { - Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0); + Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0); //todo extract this branch to a function once Actor::functions are changed to nonstatic actor functions Actor::AggroSurroundingPeasants(uActorID, 1); } else { if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pRenderer->pRenderD3D && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS) { - v27 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius; - pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)v27, 0, 0); + int splatRadius = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius; + pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)splatRadius, 0, 0); } Actor::Die(uActorID); Actor::ApplyFineForKillingPeasant(uActorID); Actor::AggroSurroundingPeasants(uActorID, 1); if ( actorPtr->pMonsterInfo.uExp ) GivePartyExp(pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].uExp); - v34 = SPEECH_51; + int speechToPlay = SPEECH_51; if ( rand() % 100 < 20 ) - v34 = ((signed int)actorPtr->pMonsterInfo.uHP >= 100) + 1; - playerPtr->PlaySound((PlayerSpeech)v34, 0); + speechToPlay = actorPtr->pMonsterInfo.uHP >= 100 ? 2 : 1; + playerPtr->PlaySound((PlayerSpeech)speechToPlay, 0); } } } } if ( !(dword_6BE368_debug_settings_2 & 0x10) - && actorPtr->pMonsterInfo.uSpecialAttack - && rand() % 100 < actorPtr->pMonsterInfo.uLevel * actorPtr->pMonsterInfo.uSpecialAttackType ) - { - playerPtr->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, actorPtr); + && actorPtr->pMonsterInfo.uSpecialAttackType + && rand() % 100 < actorPtr->pMonsterInfo.uLevel * actorPtr->pMonsterInfo.uSpecialAttackLevel ) + { + playerPtr->ReceiveSpecialAttackEffect(actorPtr->pMonsterInfo.uSpecialAttackType, actorPtr); } } if ( !pParty->bTurnBasedModeOn ) { - v35 = playerPtr->GetActualEndurance(); - v36 = (int)((20 - playerPtr->GetParameterBonus(v35)) * flt_6BE3A4_debug_recmod1 * 2.133333333333333); - playerPtr->SetRecoveryTime(v36); + int actEndurance = playerPtr->GetActualEndurance(); + int recoveryTime = (int)((20 - playerPtr->GetParameterBonus(actEndurance)) * flt_6BE3A4_debug_recmod1 * 2.133333333333333); + playerPtr->SetRecoveryTime(recoveryTime); } int yellThreshold = playerPtr->GetMaxHealth() / 4; if ( yellThreshold < playerPtr->sHealth && yellThreshold >= healthBeforeRecvdDamage && playerPtr->sHealth > 0 ) @@ -7643,35 +7518,35 @@ } else { - v37 = &pSpriteObjects[uActorID]; - v38 = PID_TYPE(v37->spell_caster_pid); - v39 = PID_ID(v37->spell_caster_pid); - v40 = PID_TYPE(v37->spell_caster_pid); - uActorID = PID_ID(v37->spell_caster_pid); - v41 = v40 - 2; - if ( v40 == 2 ) - { + SpriteObject* v37 = &pSpriteObjects[uActorID]; + int uActorType = PID_TYPE(v37->spell_caster_pid); + int uActorID = PID_ID(v37->spell_caster_pid); + if ( uActorType == 2 ) + { + Player *playerPtr; // eax@81 if ( a4 != -1 ) { - v43 = &pParty->pPlayers[a4]; + playerPtr = &pParty->pPlayers[a4]; } else { - v74 = 0; + element = 0; for (int i = 1; i <= 4; i++) { - v72[v74] = i; - v74++; + v72[element] = i; + element++; } - if ( v74 ) + if ( element ) { - v43 = &pParty->pPlayers[v72[rand() % v74]];//&stru_AA1058[3].pSounds[6972 * *(&v72 + rand() % v74) + 40552]; + playerPtr = &pParty->pPlayers[v72[rand() % element]];//&stru_AA1058[3].pSounds[6972 * *(&v72 + rand() % v74) + 40552]; } } - if ( v38 != OBJECT_Player || v37->spell_id != SPELL_BOW_ARROW) - { - v70 = v43->GetMaxHealth(); - v68 = _43AFE3_calc_spell_damage(v37->spell_id, v37->spell_level, v37->spell_skill, v70); + int v68; + int v69; + if ( uActorType != OBJECT_Player || v37->spell_id != SPELL_BOW_ARROW) + { + int playerMaxHp = playerPtr->GetMaxHealth(); + v68 = _43AFE3_calc_spell_damage(v37->spell_id, v37->spell_level, v37->spell_skill, playerMaxHp); v69 = LOBYTE(pSpellStats->pInfos[v37->spell_id].uSchool); } else @@ -7679,8 +7554,8 @@ v68 = pParty->pPlayers[uActorID].CalculateRangedDamageTo(0); v69 = 0; } - v43->ReceiveDamage(v68, (DAMAGE_TYPE)v69); - if ( v38 == OBJECT_Player && !qword_A750D8 ) + playerPtr->ReceiveDamage(v68, (DAMAGE_TYPE)v69); + if ( uActorType == OBJECT_Player && !qword_A750D8 ) { qword_A750D8 = 256i64; PlayerSpeechID = SPEECH_44; @@ -7688,98 +7563,99 @@ } return; } - else if ( v40 == 3 ) - { - actorPtr = &pActors[v39]; + else if ( uActorType == 3 ) + { + Actor *actorPtr = &pActors[uActorID]; if ( a4 == -1 ) a4 = stru_50C198.which_player_would_attack(actorPtr); - v45 = &pParty->pPlayers[a4]; - dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, v74); - v46 = v37->uType; + Player *playerPtr = &pParty->pPlayers[a4]; + int dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, element); + unsigned __int16 spriteType = v37->uType; if ( v37->uType == 545 ) { - v51 = v45->GetActualSkillLevel(PLAYER_SKILL_UNARMED); - if ( SkillToMastery(v51) >= 4 && rand() % 100 < (v51 & 0x3F) ) + __int16 skillLevel = playerPtr->GetActualSkillLevel(PLAYER_SKILL_UNARMED); + if ( SkillToMastery(skillLevel) >= 4 && rand() % 100 < (skillLevel & 0x3F) ) { - sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[637], v45->pName); + sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[637], playerPtr->pName); ShowStatusBarString(pTmpBuf.data(), 2u); - v45->PlaySound(SPEECH_6, 0); + playerPtr->PlaySound(SPEECH_6, 0); return; } } - else if ( v46 == 555 - || v46 == 510 - || v46 == 500 - || v46 == 515 - || v46 == 505 - || v46 == 530 - || v46 == 525 - || v46 == 520 - || v46 == 535 - || v46 == 540 ) - { - if ( !stru_50C198.ActorHitOrMiss(actorPtr, v45) ) + else if ( spriteType == 555 + || spriteType == 510 + || spriteType == 500 + || spriteType == 515 + || spriteType == 505 + || spriteType == 530 + || spriteType == 525 + || spriteType == 520 + || spriteType == 535 + || spriteType == 540 ) + { + if ( !stru_50C198.ActorHitOrMiss(actorPtr, playerPtr) ) return; - if ( (signed __int64)v45->pPlayerBuffs[13].uExpireTime > 0 ) + if ( playerPtr->pPlayerBuffs[13].uExpireTime > 0 ) dmgToReceive >>= 1; - if ( v45->HasEnchantedItemEquipped(36) ) + if ( playerPtr->HasEnchantedItemEquipped(36) ) dmgToReceive >>= 1; - if ( v45->HasEnchantedItemEquipped(69) ) + if ( playerPtr->HasEnchantedItemEquipped(69) ) dmgToReceive >>= 1; - if ( v45->HasItemEquipped(EQUIP_ARMOUR) - && v45->pInventoryItemList[v45->pEquipment.uArmor-1].uItemID == ITEM_ARTIFACT_GOVERNORS_ARMOR ) + if ( playerPtr->HasItemEquipped(EQUIP_ARMOUR) + && playerPtr->pInventoryItemList[playerPtr->pEquipment.uArmor-1].uItemID == ITEM_ARTIFACT_GOVERNORS_ARMOR ) dmgToReceive >>= 1; - if ( v45->HasItemEquipped(EQUIP_MAIN_HAND)) + if ( playerPtr->HasItemEquipped(EQUIP_MAIN_HAND)) { - v48 = v45->pInventoryItemList[v45->pEquipment.uMainHand - 1].uItemID; - if ( v48 == ITEM_RELIC_KELEBRIM || v48 == ITEM_ARTIFACT_ELFBANE || (v45->GetEquippedItemEquipType(EQUIP_MAIN_HAND) == EQUIP_SHIELD && SkillToMastery(v45->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4)) + int itemId = playerPtr->pInventoryItemList[playerPtr->pEquipment.uMainHand - 1].uItemID; + if ( itemId == ITEM_RELIC_KELEBRIM || itemId == ITEM_ARTIFACT_ELFBANE || (playerPtr->GetEquippedItemEquipType(EQUIP_MAIN_HAND) == EQUIP_SHIELD && SkillToMastery(playerPtr->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4)) dmgToReceive >>= 1; } - if ( v45->HasItemEquipped(EQUIP_OFF_HAND)) + if ( playerPtr->HasItemEquipped(EQUIP_OFF_HAND)) { - v48 = v45->pInventoryItemList[v45->pEquipment.uShield - 1].uItemID; - if ( v48 == ITEM_RELIC_KELEBRIM || v48 == ITEM_ARTIFACT_ELFBANE || (v45->GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD && SkillToMastery(v45->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4)) + int itemId = playerPtr->pInventoryItemList[playerPtr->pEquipment.uShield - 1].uItemID; + if ( itemId == ITEM_RELIC_KELEBRIM || itemId == ITEM_ARTIFACT_ELFBANE || (playerPtr->GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD && SkillToMastery(playerPtr->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4)) dmgToReceive >>= 1; } } if ( actorPtr->pActorBuffs[3].uExpireTime > 0 ) { - v49 = actorPtr->pActorBuffs[3].uPower; - if ( v49 ) - dmgToReceive /= (signed int)v49; - } - switch(v74) + int spellPower = actorPtr->pActorBuffs[3].uPower; + if ( spellPower ) + dmgToReceive /= (signed int)spellPower; + } + int damageType; + switch(element) { case 0: - v50 = actorPtr->pMonsterInfo.uAttack1Type; + damageType = actorPtr->pMonsterInfo.uAttack1Type; break; case 1: - v50 = actorPtr->pMonsterInfo.uAttack2Type; + damageType = actorPtr->pMonsterInfo.uAttack2Type; break; case 2: - v53 = actorPtr->pMonsterInfo.uSpell1ID; - v50 = LOBYTE(pSpellStats->pInfos[v53].uSchool); + spellId = actorPtr->pMonsterInfo.uSpell1ID; + damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool); break; case 3: - v53 = actorPtr->pMonsterInfo.uSpell2ID; - v50 = LOBYTE(pSpellStats->pInfos[v53].uSchool); + spellId = actorPtr->pMonsterInfo.uSpell2ID; + damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool); break; case 4: - v50 = actorPtr->pMonsterInfo.field_3C_some_special_attack; + damageType = actorPtr->pMonsterInfo.field_3C_some_special_attack; break; case 5: - v50 = 4; + damageType = 4; break; } if ( !(dword_6BE368_debug_settings_2 & 0x10) ) { - v54 = v45->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v50); - if ( v45->pPlayerBuffs[10].uExpireTime > 0 ) + int reflectedDmg = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)damageType); + if ( playerPtr->pPlayerBuffs[10].uExpireTime > 0 ) { - v55 = actorPtr->uAIState; - if ( v55 != Dying && v55 != Dead) + unsigned __int16 actorState = actorPtr->uAIState; + if ( actorState != Dying && actorState != Dead) { - recvdMagicDmg = stru_50C198.CalcMagicalDamageToActor(actorPtr, v50, v54); + recvdMagicDmg = stru_50C198.CalcMagicalDamageToActor(actorPtr, damageType, reflectedDmg); actorPtr->sCurrentHP -= recvdMagicDmg; if ( recvdMagicDmg >= 0 ) { @@ -7792,37 +7668,37 @@ { if ( pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].bQuestMonster & 1 && pRenderer->pRenderD3D && pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS ) { - v57 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius; - pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)v57, 0, 0); + int splatRadius = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * actorPtr->uActorRadius : actorPtr->uActorRadius; + pDecalBuilder->AddBloodsplat(actorPtr->vPosition.x, actorPtr->vPosition.y, actorPtr->vPosition.z, 1.0, 0.0, 0.0, (float)splatRadius, 0, 0); } Actor::Die(uActorID); Actor::ApplyFineForKillingPeasant(uActorID); Actor::AggroSurroundingPeasants(uActorID, 1); if ( actorPtr->pMonsterInfo.uExp ) GivePartyExp(pMonsterStats->pInfos[actorPtr->pMonsterInfo.uID].uExp); - v64 = SPEECH_51; + int speechToPlay = SPEECH_51; if ( rand() % 100 < 20 ) - v64 = ((signed int)actorPtr->pMonsterInfo.uHP >= 100) + 1; - v45->PlaySound((PlayerSpeech)v64, 0); + speechToPlay = actorPtr->pMonsterInfo.uHP >= 100 ? 2 : 1; + playerPtr->PlaySound((PlayerSpeech)speechToPlay, 0); } } } } } - if ( !v74 + if ( !element && !(dword_6BE368_debug_settings_2 & 0x10) - && actorPtr->pMonsterInfo.uSpecialAttack - && rand() % 100 < actorPtr->pMonsterInfo.uLevel * actorPtr->pMonsterInfo.uSpecialAttackType ) - { - v45->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, actorPtr); + && actorPtr->pMonsterInfo.uSpecialAttackType + && rand() % 100 < actorPtr->pMonsterInfo.uLevel * actorPtr->pMonsterInfo.uSpecialAttackLevel ) + { + playerPtr->ReceiveSpecialAttackEffect(actorPtr->pMonsterInfo.uSpecialAttackType, actorPtr); } if ( !pParty->bTurnBasedModeOn ) { - v65 = v45->GetActualEndurance(); - v66 = (int)((20 - v45->GetParameterBonus(v65)) + int actEnd = playerPtr->GetActualEndurance(); + int recTime = (int)((20 - playerPtr->GetParameterBonus(actEnd)) * flt_6BE3A4_debug_recmod1 * 2.133333333333333); - v45->SetRecoveryTime(v66); + playerPtr->SetRecoveryTime(recTime); } return; } @@ -7833,105 +7709,109 @@ } } //----- (00421EA6) -------------------------------------------------------- -void OnInventoryLeftClick() -{ - Player *v0; // ebx@1 - signed int v1; // eax@2 +void Player::OnInventoryLeftClick() +{ signed int v2; // ecx@2 int v3; // eax@2 - char v4; // sf@2 - int v5; // eax@2 + int invMatrixIndex; // eax@2 unsigned int v6; // eax@7 - unsigned int v7; // esi@12 - unsigned int v8; // eax@12 + unsigned int pickedItemId; // esi@12 + unsigned int invItemIndex; // eax@12 unsigned int v9; // eax@16 unsigned int v10; // eax@18 - ItemGen this_; // [sp+Ch] [bp-3Ch]@1 + ItemGen tmpItem; // [sp+Ch] [bp-3Ch]@1 POINT a2; // [sp+30h] [bp-18h]@4 - unsigned int v13; // [sp+38h] [bp-10h]@13 unsigned int pY; // [sp+3Ch] [bp-Ch]@2 unsigned int pX; // [sp+40h] [bp-8h]@2 - int a4; // [sp+44h] [bp-4h]@2 - - v0 = pPlayers[uActiveCharacter]; + if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 103 ) { pMouse->GetClickPos(&pX, &pY); - pY = pY - 17; - v2 =pX - 14; - pX = v2; - v3 = 14 * (pY >> 5); - v2 >>= 5; - v4 = v2 + v3 < 0; - v5 = v2 + v3; - a4 = v5; - if ( !v4 ) - { - if ( v5 <= 126 && pMouse->GetCursorPos(&a2)->x < 462 + v3 = Player::INVETORYSLOTSWIDTH * ((pY - 17) / 32); + v2 = (pX - 14) / 32; + invMatrixIndex = v2 + v3; + if ( v2 + v3 >= 0 ) + { + if ( invMatrixIndex <= 126 && pMouse->GetCursorPos(&a2)->x < 462 && pMouse->GetCursorPos(&a2)->x >= 14 ) { - if ( unk_50C9A0 ) + if ( _50C9A0_IsEnchantingInProgress ) { - v6 = v0->GetItemIDAtInventoryIndex(&a4); + v6 = this->GetItemIDAtInventoryIndex(&invMatrixIndex); if ( v6 ) { *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu; *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1; *((int *)pGUIWindow_Settings->ptr_1C + 3) = v6 - 1; - *((short *)pGUIWindow_Settings->ptr_1C + 3) = a4; - ptr_50C9A4 = (ItemGen *)&v0->pInventoryItemList[v6-1]; - unk_50C9A0 = 0; + *((short *)pGUIWindow_Settings->ptr_1C + 3) = invMatrixIndex; + ptr_50C9A4_ItemToEnchant = &this->pInventoryItemList[v6-1]; + _50C9A0_IsEnchantingInProgress = 0; if ( pMessageQueue_50CBD0->uNumMessages ) pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; pMouse->SetCursorBitmap("MICON1"); - dword_50C9D0 = 113; - dword_50C9D4 = 0; - dword_50C9D8 = 256; + _50C9D0_AfterEnchClickEventId = 113; + _50C9D4_AfterEnchClickEventSecondParam = 0; + _50C9D8_AfterEnchClickEventTimeout = 256; } return; } - if ( ptr_50C9A4 ) + if ( ptr_50C9A4_ItemToEnchant ) return; - v7 = pParty->pPickedItem.uItemID; - v8 = v0->GetItemIDAtInventoryIndex(&a4); - if ( !v7 ) + pickedItemId = pParty->pPickedItem.uItemID; + invItemIndex = this->GetItemIDAtInventoryIndex(&invMatrixIndex); + if (!pickedItemId) { - if ( !v8 ) + if ( !invItemIndex ) return; - memcpy(&pParty->pPickedItem, &v0->pInventoryItemList[v8-1], sizeof(pParty->pPickedItem)); - v0->RemoveItemAtInventoryIndex(a4); - v9 = pParty->pPickedItem.uItemID; - pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName); - return; + else + { + memcpy(&pParty->pPickedItem, &this->pInventoryItemList[invItemIndex-1], sizeof(pParty->pPickedItem)); + this->RemoveItemAtInventoryIndex(invMatrixIndex); + v9 = pParty->pPickedItem.uItemID; + pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName); + return; + } } - v13 = v8; - if ( v8 ) + else { - a2.y = (LONG)&v0->pInventoryItemList[v8-1]; - memcpy(&this_, (const void *)a2.y, sizeof(this_)); - v0->RemoveItemAtInventoryIndex(a4); - pX = v0->AddItem2(a4, &pParty->pPickedItem); - if ( !pX ) + if ( invItemIndex ) { - pX = v0->AddItem2(0xFFFFFFFFu, &pParty->pPickedItem); - if ( !pX ) + ItemGen* invItemPtr = &this->pInventoryItemList[invItemIndex-1]; + memcpy(&tmpItem, invItemPtr, sizeof(tmpItem)); + this->RemoveItemAtInventoryIndex(invMatrixIndex); + int emptyIndex = this->AddItem2(invMatrixIndex, &pParty->pPickedItem); + if ( !emptyIndex ) { - v0->PutItemArInventoryIndex(this_.uItemID, v13 - 1, a4); - memcpy((void *)a2.y, &this_, sizeof(ItemGen)); + emptyIndex = this->AddItem2(-1, &pParty->pPickedItem); + if ( !emptyIndex ) + { + this->PutItemArInventoryIndex(tmpItem.uItemID, invItemIndex - 1, invMatrixIndex); + memcpy(invItemPtr, &tmpItem, sizeof(ItemGen)); + return; + } + } + v9 = tmpItem.uItemID; + memcpy(&pParty->pPickedItem, &tmpItem, sizeof(ItemGen)); + pMouse->SetCursorBitmap(pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName); + return; + } + else + { + v10 = this->AddItem(invMatrixIndex, pickedItemId); + if ( v10 ) + { + memcpy(&this->pInventoryItemList[v10-1], &pParty->pPickedItem, sizeof(ItemGen)); + pMouse->RemoveHoldingItem(); + return; + } + v10 = this->AddItem(-1, pickedItemId); + if ( v10 ) + { + memcpy(&this->pInventoryItemList[v10-1], &pParty->pPickedItem, sizeof(ItemGen)); + pMouse->RemoveHoldingItem(); return; } } - v9 = this_.uItemID; - memcpy(&pParty->pPickedItem, &this_, sizeof(pParty->pPickedItem)); - pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName); - return; - } - v10 = v0->AddItem(a4, v7); - pX = v10; - if ( v10 || (v10 = v0->AddItem(-1, pParty->pPickedItem.uItemID), (pX = v10) != 0) ) - { - memcpy(&v0->pInventoryItemList[v10-1], &pParty->pPickedItem, 0x24u); - pMouse->RemoveHoldingItem(); } } } @@ -7984,6 +7864,11 @@ return pConditions[Condition_Paralyzed] != 0; } +bool Player::IsDrunk() +{ + return pConditions[Condition_Drunk] != 0; +} + void Player::SetCursed( bool state ) { pConditions[Condition_Cursed] = state;