Mercurial > mm7
diff Player.cpp @ 1258:eb1a22f7dfef
Player::SetVariable cleanup - removed some labels at the cost of 2 extra small functions
author | Grumpy7 |
---|---|
date | Wed, 12 Jun 2013 03:59:08 +0200 |
parents | 7ef8ae7ce42a |
children | d6e5b6b76612 |
line wrap: on
line diff
--- a/Player.cpp Tue Jun 11 23:10:30 2013 +0200 +++ b/Player.cpp Wed Jun 12 03:59:08 2013 +0200 @@ -7871,11 +7871,11 @@ void Player::SetVariable(enum VariableType var_type, signed int var_value) { signed int currPlayerId; // ebx@1 - Player *unused4; // esi@1 - unsigned int v5; // edi@1 + Player *v4_unused; // esi@1 + unsigned int v5_unused; // edi@1 unsigned int v6; // esi@13 unsigned int v7; // esi@14 - signed int v8; // eax@17 + signed int v8_unused; // eax@17 ItemGen *v9; // ecx@17 int v10; // eax@21 signed int v11; // eax@30 @@ -7897,12 +7897,11 @@ signed int unused27; // [sp-4h] [bp-38h]@4 int v28; // [sp-4h] [bp-38h]@84 ItemGen item; // [sp+Ch] [bp-28h]@52 - char v30; // [sp+32h] [bp-2h]@1 - char v31; // [sp+33h] [bp-1h]@1 - - v30 = 0; - v31 = 0; - v5 = 0; + char v30_drawanim; // [sp+32h] [bp-2h]@1 + char v31_playsound; // [sp+33h] [bp-1h]@1 + + v30_drawanim = 0; + v31_playsound = 0; currPlayerId = -1; for (int i = 1; i <= 4; i++) //TODO: add a member variable for playerid in the future @@ -7979,10 +7978,9 @@ return; bFlashHistoryBook = 1; } -LABEL_172: v25 = 8 * currPlayerId + 400; LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112); - pAudioPlayer->PlaySound(SOUND_20001, v25, v5, -1, v5, v5, v5, v5); + pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0); return; } if ( var_type != VAR_NumDeaths ) @@ -8010,18 +8008,13 @@ } return; } - pParty->uNumDeaths = var_value; -LABEL_168: - if (v30 == 1) - { -LABEL_169: - pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId); - } -LABEL_170: - if ( v31 != 1 ) + else + { + pParty->uNumDeaths = var_value; + DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId); + PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId); return; - v5 = 0; - goto LABEL_172; + } } if ( var_type == VAR_AutoNotes ) { @@ -8030,15 +8023,17 @@ && pAutonoteTxt[var_value-1].pText ) { v20 = pPlayers[currPlayerId + 1]; - v30 = 1; + v30_drawanim = 1; v20->PlaySound(SPEECH_96, 0); v21 = pAutonoteTxt[var_value-1].eType;// dword_72371C[2 * a3]; bFlashAutonotesBook = 1; _506568_autonote_type = v21; } _449B7E_toggle_bit(pParty->_autonote_bits, var_value, 1u); - v31 = 1; - goto LABEL_168; + v31_playsound = 1; + DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId); + PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId); + return; } if ( var_type <= VAR_BaseLuck ) { @@ -8051,19 +8046,19 @@ this->classType = (PLAYER_CLASS_TYPE)var_value; if ( (char)var_value == PLAYER_CLASS_LICH ) { - v8 = 0; - v9 = this->pInventoryItems; - while ( v9->uItemID != 615 ) + v9 = NULL; + for (int i = 0; i < 138; i++) { - ++v8; - ++v9; - if ( v8 >= 138 ) - goto LABEL_22; + v9 = &this->pInventoryItems[i]; + if (v9->uItemID == 615) + break; } - v10 = (int)((char *)this + 36 * v8); - *(int *)(v10 + 532) = 601; - *(char *)(v10 + 558) = currPlayerId + 1; -LABEL_22: + if (v9 != NULL || v9->uItemID != 615) + { + v10 = (int)((char *)this + 36 * 138); //originally 36 * v8. the code got to this condition only if v8 was equal to 138 + *(int *)(v10 + 532) = 601; + *(char *)(v10 + 558) = currPlayerId + 1; + } if ( this->sResFireBase < 20 ) this->sResFireBase = 20; if ( this->sResAirBase < 20 ) @@ -8120,12 +8115,14 @@ //&& dword_723E80_award_related[2 * a3] ) && pAwards[var_value].pText ) { - v30 = 1; - v31 = 1; + v30_drawanim = 1; + v31_playsound = 1; pPlayers[currPlayerId + 1]->PlaySound(SPEECH_96, 0); } _449B7E_toggle_bit((unsigned char *)this->_guilds_member_bits, var_value, 1u); - goto LABEL_168; + DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId); + PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId); + return; case VAR_Experience: this->uExperience = var_value; goto LABEL_124; @@ -8136,22 +8133,15 @@ { v14 = pPlayers[currPlayerId + 1]; bFlashQuestBook = 1; - v30 = 1; - v31 = 1; + v30_drawanim = 1; + v31_playsound = 1; v14->PlaySound(SPEECH_93, 0); } v13 = (char *)pParty->_quest_bits; LABEL_51: _449B7E_toggle_bit((unsigned char *)v13, var_value, 1u); - if (( v30 != 1 )&&( v31 != 1 )) - return; - else - pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId); - if ( v31 != 1 ) - return; - v25 = 8 * currPlayerId + 400; - LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112); - pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0); + DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId); + PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId); return; case VAR_PlayerItemInHands: item.Reset(); @@ -8198,25 +8188,39 @@ goto LABEL_73; case VAR_BaseMight: this->uMight = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_BaseIntellect: this->uIntelligence = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_BasePersonality: this->uWillpower = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_BaseEndurance: this->uEndurance = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_BaseSpeed: this->uSpeed = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_BaseAccuracy: this->uAccuracy = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_BaseLuck: this->uLuck = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; default: return; } @@ -8225,9 +8229,11 @@ v26 = SPEECH_91; LABEL_112: v19 = pPlayers[currPlayerId + 1]; - v31 = 1; + v31_playsound = 1; v19->PlaySound((PlayerSpeech)v26, v28); - goto LABEL_169; + DrawPlayerBuffAnimBasedOnCondition(true, currPlayerId); + PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId); + return; } if ( var_type <= VAR_MagicResistance ) { @@ -8263,34 +8269,51 @@ goto LABEL_111; case VAR_FireResistance: this->sResFireBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_AirResistance: this->sResAirBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_WaterResistance: this->sResWaterBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_EarthResistance: this->sResEarthBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_SpiritResistance: this->sResSpiritBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_MindResistance: this->sResMindBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_BodyResistance: this->sResBodyBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_LightResistance: this->sResLightBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_DarkResistance: this->sResDarkBase = (unsigned __int8)var_value; - goto LABEL_84; + v28 = 0; + v26 = 92; + goto LABEL_112; case VAR_MagicResistance: this->sResMagicBase = (unsigned __int8)var_value; -LABEL_84: v28 = 0; v26 = 92; goto LABEL_112; @@ -8321,8 +8344,10 @@ memset(this, 0, 0xA0u); } LABEL_124: - v31 = 1; - goto LABEL_169; + v31_playsound = 1; + DrawPlayerBuffAnimBasedOnCondition(true, currPlayerId); + PlaySoundBasedOnCondition(v31_playsound = 1, currPlayerId); + return; } LABEL_106: v16 = (int)((char *)&this->pConditions[16] + 2 * var_type); @@ -8340,15 +8365,9 @@ goto LABEL_124; } if ( var_type == VAR_DisarmTrapSkill ) - if ( v30 != 1 ) - { - if ( v31 != 1 ) - return; - v5 = 0; - goto LABEL_172; - } - pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId); - goto LABEL_170; + PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId); + DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId); + return; if ( var_type <= VAR_MagicResistanceBonus ) { switch ( var_type ) @@ -8395,20 +8414,33 @@ goto LABEL_111; } if ( var_type > VAR_MagicResistanceBonus && var_type <= VAR_DiplomacySkill ) - if ( v30 != 1 ) - { - if ( v31 != 1 ) - return; - v5 = 0; - v25 = 8 * currPlayerId + 400; - LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112); - pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0); - return; - } - pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId); - goto LABEL_170; -} - + { + PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId); + DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId); + return; + } +} + + +//----- (new function) -------------------------------------------------------- +void Player::PlaySoundBasedOnCondition(bool condition, int currPlayerId) +{ + if (condition) + { + signed int v25 = 8 * currPlayerId + 400; + LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112); + pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0); + } +} + +//----- (new function) -------------------------------------------------------- +void Player::DrawPlayerBuffAnimBasedOnCondition(bool condition, int currPlayerId) +{ + if (condition) + { + pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId); + } +} //----- (0044AFFB) -------------------------------------------------------- void Player::AddVariable(enum VariableType var_type, signed int val)