Mercurial > mm7
changeset 1681:406872881eb6
DamagePlayerFromMonster reducing variable scope
author | Grumpy7 |
---|---|
date | Thu, 19 Sep 2013 08:26:28 +0200 |
parents | f3986fd1a122 |
children | 3c451fd02fcf |
files | Player.cpp |
diffstat | 1 files changed, 125 insertions(+), 164 deletions(-) [+] |
line wrap: on
line diff
--- a/Player.cpp Wed Sep 18 20:36:18 2013 +0600 +++ b/Player.cpp Thu Sep 19 08:26:28 2013 +0200 @@ -7467,68 +7467,28 @@ //----- (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,45 +7497,45 @@ ) ) { - v14 = rand() % 4; - switch (v14) + int randVal = rand() % 4; + switch (randVal) { - case 0 : v17 = (SoundID)108; break; - case 1 : v17 = (SoundID)109; break; - case 2 : v17 = (SoundID)110; break; - case 3 : v17 = (SoundID)44; break; + 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) + int randVal = rand() % 4; + switch (randVal) { - case 0 : v17 = (SoundID)105; break; - case 1 : v17 = (SoundID)106; break; - case 2 : v17 = (SoundID)107; break; - case 3 : v17 = (SoundID)45; break; + 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(v17, PID(OBJECT_Player,a4 + 80), 0, -1, 0, 0, 0, 0); - dmgToReceive = Actor::_43B3E0_CalcDamage(actorPtr, v74); + 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) + __int16 spellPower = actorPtr->pActorBuffs[3].uPower; + if ( spellPower ) + dmgToReceive /= (signed int)spellPower; + } + switch (element) { case 0: v22 = actorPtr->pMonsterInfo.uAttack1Type; break; case 1: v22 = actorPtr->pMonsterInfo.uAttack2Type; break; - case 2: v23 = actorPtr->pMonsterInfo.uSpell1ID; - v22 = LOBYTE(pSpellStats->pInfos[v23].uSchool); + case 2: spellId = actorPtr->pMonsterInfo.uSpell1ID; + v22 = LOBYTE(pSpellStats->pInfos[spellId].uSchool); break; - case 3: v23 = actorPtr->pMonsterInfo.uSpell2ID; - v22 = LOBYTE(pSpellStats->pInfos[v23].uSchool); + case 3: spellId = actorPtr->pMonsterInfo.uSpell2ID; + v22 = LOBYTE(pSpellStats->pInfos[spellId].uSchool); break; case 4: v22 = actorPtr->pMonsterInfo.field_3C_some_special_attack; break; @@ -7585,15 +7545,15 @@ } if ( !(dword_6BE368_debug_settings_2 & 0x10) ) { - v24 = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v22); + dmgToReceive = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v22); 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, v22, dmgToReceive); + actorPtr->sCurrentHP -= reflectedDamage; + if ( reflectedDamage >= 0 ) { if ( actorPtr->sCurrentHP >= 1 ) { @@ -7604,18 +7564,18 @@ { 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); } } } @@ -7629,9 +7589,9 @@ } 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 +7603,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) + int v68; + int v69; + if ( uActorType != 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 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 +7639,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 +7648,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 ) + 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, v45) ) + 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; + int spellPower = actorPtr->pActorBuffs[3].uPower; + if ( spellPower ) + dmgToReceive /= (signed int)spellPower; } - switch(v74) + 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 +7753,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); + playerPtr->_48DCF6(actorPtr->pMonsterInfo.uSpecialAttack, 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; }