Skip to content
Browse files

Replaced some C-like casts with static_cast, and note to the previous…

… commit: that wasn't an added bug, just method itself was doing something, that it wasn't supposed to do (counting base_dmg in while returning bonus_damage) for ages, tried to blame, to find out when it popped out - it was there 3 years ago, after that I got lost in revisions log.
  • Loading branch information...
1 parent 1effe06 commit 9a9b43d8a19ff01625c79ff492cb3b1dde6d6c91 @neo-mat neo-mat committed Feb 28, 2012
Showing with 77 additions and 74 deletions.
  1. +17 −17 src/arcemu-world/Object.cpp
  2. +18 −18 src/arcemu-world/SpellAuras.cpp
  3. +42 −39 src/arcemu-world/Unit.cpp
View
34 src/arcemu-world/Object.cpp
@@ -1627,12 +1627,12 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
if(spellInfo == NULL)
return;
- if(this->IsPlayer() && ! TO_PLAYER(this)->canCast(spellInfo))
+ if(this->IsPlayer() && ! TO< Player* >(this)->canCast(spellInfo))
return;
//==========================================================================================
//==============================Variables Initialization====================================
//==========================================================================================
- float res = float(damage);
+ float res = static_cast< float >(damage);
bool critical = false;
uint32 aproc = PROC_ON_ANY_HOSTILE_ACTION; /*| PROC_ON_SPELL_HIT;*/
@@ -1673,15 +1673,15 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
caster->RemoveAurasByInterruptFlag(AURA_INTERRUPT_ON_START_ATTACK);
- res += static_cast< float >(caster->GetSpellDmgBonus(pVictim, spellInfo, damage, false));
+ res += static_cast< float >( caster->GetSpellDmgBonus(pVictim, spellInfo, damage, false) );
if(res < 0.0f)
res = 0.0f;
}
//==========================================================================================
//==============================Post +SpellDamage Bonus Modifications=======================
//==========================================================================================
- if(res > 0.0f && !(spellInfo->AttributesExB & ATTRIBUTESEXB_CANT_CRIT))
+ if( res > 0.0f && !(spellInfo->AttributesExB & ATTRIBUTESEXB_CANT_CRIT) )
{
critical = this->IsCriticalDamageForSpell(pVictim, spellInfo);
@@ -1726,7 +1726,7 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
if( this->IsUnit() )
res += TO< Unit* >(this)->CalcSpellDamageReduction(pVictim, spellInfo, res);
//------------------------------absorption--------------------------------------------------
- uint32 ress = (uint32)res;
+ uint32 ress = static_cast< uint32 >(res);
uint32 abs_dmg = pVictim->AbsorbDamage(spellInfo->School, &ress);
uint32 ms_abs_dmg = pVictim->ManaShieldAbsorb(ress);
if(ms_abs_dmg)
@@ -1743,7 +1743,7 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
vproc |= PROC_ON_ABSORB;
// Incanter's Absorption
- if(pVictim->IsPlayer() && pVictim->HasAurasWithNameHash(SPELL_HASH_INCANTER_S_ABSORPTION))
+ if( pVictim->IsPlayer() && pVictim->HasAurasWithNameHash(SPELL_HASH_INCANTER_S_ABSORPTION) )
{
float pctmod = 0.0f;
Player* pl = TO< Player* >(pVictim);
@@ -1754,8 +1754,8 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
else if(pl->HasAura(44396))
pctmod = 0.15f;
- uint32 hp = static_cast<uint32>(0.05f * pl->GetUInt32Value(UNIT_FIELD_MAXHEALTH));
- uint32 spellpower = static_cast<uint32>(pctmod * pl->GetPosDamageDoneMod(SCHOOL_NORMAL));
+ uint32 hp = static_cast< uint32 >( 0.05f * pl->GetUInt32Value(UNIT_FIELD_MAXHEALTH) );
+ uint32 spellpower = static_cast< uint32 >( pctmod * pl->GetPosDamageDoneMod(SCHOOL_NORMAL) );
if(spellpower > hp)
spellpower = hp;
@@ -1773,7 +1773,7 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
if(ress < 0) ress = 0;
- res = (float)ress;
+ res = static_cast< float >(ress);
dealdamage dmg;
dmg.school_type = spellInfo->School;
dmg.full_damage = ress;
@@ -1789,12 +1789,12 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
if((int32)dmg.resisted_damage > dmg.full_damage)
res = 0;
else
- res = float(dmg.full_damage - dmg.resisted_damage);
+ res = static_cast< float >(dmg.full_damage - dmg.resisted_damage);
}
//------------------------------special states----------------------------------------------
if(pVictim->IsPlayer() && TO< Player* >(pVictim)->GodModeCheat == true)
{
- res = float(dmg.full_damage);
+ res = static_cast< float >(dmg.full_damage);
dmg.resisted_damage = dmg.full_damage;
}
@@ -1807,12 +1807,12 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
//==========================================================================================
//==============================Data Sending ProcHandling===================================
//==========================================================================================
- SendSpellNonMeleeDamageLog(this, pVictim, spellID, float2int32(res), static_cast<uint8>(spellInfo->School), abs_dmg, dmg.resisted_damage, false, 0, critical, IsPlayer());
- DealDamage(pVictim, float2int32(res), 2, 0, spellID);
+ SendSpellNonMeleeDamageLog(this, pVictim, spellID, static_cast< int32 >(res), static_cast< uint8 >(spellInfo->School), abs_dmg, dmg.resisted_damage, false, 0, critical, IsPlayer());
+ DealDamage(pVictim, static_cast< int32 >(res), 2, 0, spellID);
if(IsUnit())
{
- int32 dmg2 = float2int32(res);
+ int32 dmg2 = static_cast< int32 >(res);
pVictim->HandleProc(vproc, TO< Unit* >(this), spellInfo, !allowProc, dmg2, abs_dmg);
pVictim->m_procCounter = 0;
@@ -1844,7 +1844,7 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
Player* pl = TO< Player* >(pVictim);
uint32 maxmana = pl->GetMaxPower(POWER_TYPE_MANA);
- uint32 amount = uint32(maxmana * pl->m_RegenManaOnSpellResist);
+ uint32 amount = static_cast< uint32 >(maxmana * pl->m_RegenManaOnSpellResist);
pVictim->Energize(pVictim, 29442, amount, POWER_TYPE_MANA);
}
@@ -1861,10 +1861,10 @@ void Object::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage
//Shadow Word:Death
if(spellID == 32379 || spellID == 32996 || spellID == 48157 || spellID == 48158)
{
- uint32 damage2 = uint32(res + abs_dmg);
+ uint32 damage2 = static_cast< uint32 >(res + abs_dmg);
uint32 absorbed = TO< Unit* >(this)->AbsorbDamage(spellInfo->School, &damage2);
DealDamage(TO< Unit* >(this), damage2, 2, 0, spellID);
- SendSpellNonMeleeDamageLog(this, this, spellID, damage2, static_cast<uint8>(spellInfo->School), absorbed, 0, false, 0, false, IsPlayer());
+ SendSpellNonMeleeDamageLog(this, this, spellID, damage2, static_cast< uint8 >(spellInfo->School), absorbed, 0, false, 0, false, IsPlayer());
}
}
}
View
36 src/arcemu-world/SpellAuras.cpp
@@ -1788,19 +1788,19 @@ void Aura::SpellAuraPeriodicDamage(bool apply)
void Aura::EventPeriodicDamage(uint32 amount)
{
//DOT
- if(! m_target->isAlive())
+ if( !m_target->isAlive() )
return;
if(m_target->SchoolImmunityList[GetSpellProto()->School])
{
if(GetUnitCaster() != NULL)
- SendTickImmune(m_target, GetUnitCaster());
+ SendTickImmune( m_target, GetUnitCaster() );
return;
}
- float res = float(amount);
+ float res = static_cast< float >(amount);
uint32 abs_dmg = 0;
- int bonus = 0;
+ int32 bonus = 0;
uint32 school = GetSpellProto()->School;
Unit* c = GetUnitCaster();
uint32 aproc = PROC_ON_ANY_HOSTILE_ACTION;
@@ -1811,7 +1811,7 @@ void Aura::EventPeriodicDamage(uint32 amount)
{
if(c != NULL)
{
- int amp = m_spellProto->EffectAmplitude[mod->i];
+ uint32 amp = m_spellProto->EffectAmplitude[mod->i];
if(!amp)
amp = event_GetEventPeriod(EVENT_AURA_PERIODIC_DAMAGE);
@@ -1841,7 +1841,7 @@ void Aura::EventPeriodicDamage(uint32 amount)
res = 0.0f;
}
- if(DotCanCrit())
+ if( DotCanCrit() )
{
is_critical = c->IsCriticalDamageForSpell(m_target, GetSpellProto());
@@ -1855,7 +1855,7 @@ void Aura::EventPeriodicDamage(uint32 amount)
}
}
- uint32 ress = (uint32)res;
+ uint32 ress = static_cast< uint32 >(res);
abs_dmg = m_target->AbsorbDamage(school, &ress);
uint32 ms_abs_dmg = m_target->ManaShieldAbsorb(ress);
if(ms_abs_dmg)
@@ -1870,41 +1870,41 @@ void Aura::EventPeriodicDamage(uint32 amount)
if(ress < 0) ress = 0;
- res = (float)ress;
+ res = static_cast< float >(ress);
dealdamage dmg;
dmg.school_type = school;
dmg.full_damage = ress;
dmg.resisted_damage = 0;
- if(res <= 0)
+ if(res <= 0.0f)
dmg.resisted_damage = dmg.full_damage;
- if(res > 0 && c && m_spellProto->MechanicsType != MECHANIC_BLEEDING)
+ if(res > 0.0f && c && m_spellProto->MechanicsType != MECHANIC_BLEEDING)
{
c->CalculateResistanceReduction(m_target, &dmg, m_spellProto, 0);
- if((int32)dmg.resisted_damage > dmg.full_damage)
- res = 0;
+ if(static_cast< int32 >(dmg.resisted_damage) > dmg.full_damage)
+ res = 0.0f;
else
- res = float(dmg.full_damage - dmg.resisted_damage);
+ res = static_cast< float >(dmg.full_damage - dmg.resisted_damage);
}
- m_target->SendPeriodicAuraLog(m_casterGuid, m_target->GetNewGUID(), GetSpellProto()->Id, school, float2int32(res), abs_dmg, dmg.resisted_damage, FLAG_PERIODIC_DAMAGE, is_critical);
+ m_target->SendPeriodicAuraLog(m_casterGuid, m_target->GetNewGUID(), GetSpellProto()->Id, school, static_cast< int32 >(res), abs_dmg, dmg.resisted_damage, FLAG_PERIODIC_DAMAGE, is_critical);
}
// grep: this is hack.. some auras seem to delete this shit.
SpellEntry* sp = m_spellProto;
if(m_target->m_damageSplitTarget)
- res = (float)m_target->DoDamageSplitTarget((uint32)res, GetSpellProto()->School, false);
+ res = static_cast< float >( m_target->DoDamageSplitTarget(static_cast< uint32 >(res), GetSpellProto()->School, false) );
if(c != NULL)
- c->DealDamage(m_target, float2int32(res), 2, 0, GetSpellId());
+ c->DealDamage(m_target, static_cast< int32 >(res), 2, 0, GetSpellId());
else
- m_target->DealDamage(m_target, float2int32(res), 2, 0, GetSpellId());
+ m_target->DealDamage(m_target, static_cast< int32 >(res), 2, 0, GetSpellId());
if(m_target->GetGUID() != m_casterGuid && c != NULL) //don't use resist when cast on self-- this is some internal stuff
{
- int32 dmg = float2int32(res);
+ int32 dmg = static_cast< int32 >(res);
if(abs_dmg)
vproc |= PROC_ON_ABSORB;
View
81 src/arcemu-world/Unit.cpp
@@ -5131,9 +5131,9 @@ int32 Unit::GetSpellDmgBonus(Unit* pVictim, SpellEntry* spellInfo, int32 base_dm
if(spellInfo->c_is_flags & SPELL_FLAG_IS_NOT_USING_DMG_BONUS)
return 0;
- if(caster->IsPlayer())
+ if( caster->IsPlayer())
{
- switch(TO< Player* >(this)->getClass())
+ switch( TO< Player* >(this)->getClass() )
{
case ROGUE:
case WARRIOR:
@@ -5146,32 +5146,33 @@ int32 Unit::GetSpellDmgBonus(Unit* pVictim, SpellEntry* spellInfo, int32 base_dm
}
//------------------------------by school---------------------------------------------------
- plus_damage += caster->GetDamageDoneMod(school);
- plus_damage += static_cast< int32 >( base_dmg * (caster->GetDamageDonePctMod(school)-1) ); //value is initialized with 1
+ plus_damage += static_cast< float >( caster->GetDamageDoneMod(school) );
+ plus_damage += static_cast< float >( base_dmg * ( caster->GetDamageDonePctMod(school)-1) ); //value is initialized with 1
//------------------------------by victim type----------------------------------------------
- if(!pVictim->IsPlayer() && caster->IsPlayer())
- plus_damage += TO< Player* >(caster)->IncreaseDamageByType[TO_CREATURE(pVictim)->GetCreatureInfo()->Type];
+ if( !pVictim->IsPlayer() && caster->IsPlayer() )
+ plus_damage += static_cast< float >( TO< Player* >(caster)->IncreaseDamageByType[TO< Creature* >(pVictim)->GetCreatureInfo()->Type] );
//==========================================================================================
//==============================+Spell Damage Bonus Modifications===========================
//==========================================================================================
//------------------------------by cast duration--------------------------------------------
+
// do not execute this if plus dmg is 0 or lower
if( plus_damage > 0.0f )
{
- if( spellInfo->Dspell_coef_override >= 0 && !isdot )
+ if( spellInfo->Dspell_coef_override >= 0.0f && !isdot )
plus_damage = plus_damage * spellInfo->Dspell_coef_override;
- else if( spellInfo->OTspell_coef_override >= 0 && isdot )
+ else if( spellInfo->OTspell_coef_override >= 0.0f && isdot )
plus_damage = plus_damage * spellInfo->OTspell_coef_override;
else
{
//Bonus to DD part
- if( spellInfo->fixed_dddhcoef >= 0 && !isdot )
+ if( spellInfo->fixed_dddhcoef >= 0.0f && !isdot )
plus_damage = plus_damage * spellInfo->fixed_dddhcoef;
//Bonus to DoT part
- else if( spellInfo->fixed_hotdotcoef >= 0 && isdot )
+ else if( spellInfo->fixed_hotdotcoef >= 0.0f && isdot )
{
plus_damage = plus_damage * spellInfo->fixed_hotdotcoef;
- if(caster->IsPlayer())
+ if( caster->IsPlayer() )
{
int32 durmod = 0;
SM_FIValue( caster->SM_FDur, &durmod, spellInfo->SpellGroupType );
@@ -8028,72 +8029,74 @@ bool Unit::IsCriticalDamageForSpell(Object* victim, SpellEntry* spell)
if(spell->is_ranged_spell)
{
- if(IsPlayer())
+ if( IsPlayer() )
{
CritChance = GetFloatValue(PLAYER_RANGED_CRIT_PERCENTAGE);
- if(victim->IsPlayer())
- CritChance += TO_PLAYER(victim)->res_R_crit_get();
+ if( victim->IsPlayer() )
+ CritChance += TO< Player* >(victim)->res_R_crit_get();
- if(victim->IsUnit())
- CritChance += (float)(TO_UNIT(victim)->AttackerCritChanceMod[spell->School]);
+ if( victim->IsUnit() )
+ CritChance += static_cast< float >(TO< Unit* >(victim)->AttackerCritChanceMod[spell->School]);
}
else
CritChance = 5.0f; // static value for mobs.. not blizzlike, but an unfinished formula is not fatal :)
- if(victim->IsPlayer())
+ if( victim->IsPlayer() )
resilience_type = PLAYER_RATING_MODIFIER_RANGED_CRIT_RESILIENCE;
}
else if(spell->is_melee_spell)
{
- // Same shit with the melee spells, such as Judgement/Seal of Command
- if(IsPlayer())
+ // Same shit with the melee spells, such as Judgment/Seal of Command
+ if( IsPlayer() )
CritChance = GetFloatValue(PLAYER_CRIT_PERCENTAGE);
- if(victim->IsPlayer())
+ if( victim->IsPlayer() )
{
- CritChance += TO_PLAYER(victim)->res_R_crit_get(); //this could be ability but in that case we overwrite the value
+ CritChance += TO< Player* >(victim)->res_R_crit_get(); //this could be ability but in that case we overwrite the value
resilience_type = PLAYER_RATING_MODIFIER_MELEE_CRIT_RESILIENCE;
}
// Victim's (!) crit chance mod for physical attacks?
- if(victim->IsUnit())
- CritChance += (float)(TO_UNIT(victim)->AttackerCritChanceMod[0]);
+ if( victim->IsUnit() )
+ CritChance += static_cast< float >(TO< Unit* >(victim)->AttackerCritChanceMod[0]);
}
else
{
CritChance = spellcritperc + SpellCritChanceSchool[spell->School];
- if(victim->IsUnit())
+ if( victim->IsUnit() )
{
- CritChance += TO_UNIT(victim)->AttackerCritChanceMod[spell->School];
+ CritChance += static_cast< float >(TO< Unit* >(victim)->AttackerCritChanceMod[spell->School]);
- if(IsPlayer() && (TO_UNIT(victim)->m_rooted - TO_UNIT(victim)->m_stunned))
- CritChance += TO_PLAYER(this)->m_RootedCritChanceBonus;
+ if( IsPlayer() && (TO< Unit* >(victim)->m_rooted - TO< Unit* >(victim)->m_stunned) )
+ CritChance += static_cast< float >(TO< Player* >(this)->m_RootedCritChanceBonus);
}
if(spell->SpellGroupType)
SM_FFValue(SM_CriticalChance, &CritChance, spell->SpellGroupType);
- if(victim->IsPlayer())
+ if( victim->IsPlayer() )
resilience_type = PLAYER_RATING_MODIFIER_SPELL_CRIT_RESILIENCE;
}
if(resilience_type)
- CritChance -= TO_PLAYER(victim)->CalcRating(resilience_type);
+ CritChance -= TO< Player* >(victim)->CalcRating(resilience_type);
- if(CritChance < 0)
- CritChance = 0;
- else if(CritChance > 95)
- CritChance = 95;
+ if(CritChance < 0.0f)
+ CritChance = 0.0f;
+ else if(CritChance > 95.0f)
+ CritChance = 95.0f;
result = Rand(CritChance);
// HACK!!!
Aura* fs = NULL;
- if(victim->IsUnit() && spell->NameHash == SPELL_HASH_LAVA_BURST && (fs = TO_UNIT(victim)->FindAuraByNameHash(SPELL_HASH_FLAME_SHOCK)) != NULL)
+ if(victim->IsUnit()
+ && spell->NameHash == SPELL_HASH_LAVA_BURST
+ && ( fs = TO< Unit* >(victim)->FindAuraByNameHash(SPELL_HASH_FLAME_SHOCK) ) != NULL)
{
result = true;
- if(! HasAura(55447)) // Glyph of Flame Shock
+ if( !HasAura(55447) ) // Glyph of Flame Shock
fs->Remove();
}
@@ -8119,7 +8122,7 @@ float Unit::GetCriticalDamageBonusForSpell(Object* victim, SpellEntry* spell, fl
amount *= b;
}
- if(victim->IsPlayer())
+ if( victim->IsPlayer() )
{
//res = res*(1.0f-2.0f*TO< Player* >(pVictim)->CalcRating(PLAYER_RATING_MODIFIER_MELEE_CRIT_RESISTANCE));
//Resilience is a special new rating which was created to reduce the effects of critical hits against your character.
@@ -8128,16 +8131,16 @@ float Unit::GetCriticalDamageBonusForSpell(Object* victim, SpellEntry* spell, fl
//It is believed that resilience also functions against spell crits,
//though it's worth noting that NPC mobs cannot get critical hits with spells.
- float dmg_reduction_pct = 2 * TO_PLAYER(victim)->CalcRating(PLAYER_RATING_MODIFIER_MELEE_CRIT_RESILIENCE) / 100.0f;
+ float dmg_reduction_pct = 2 * TO< Player* >(victim)->CalcRating(PLAYER_RATING_MODIFIER_MELEE_CRIT_RESILIENCE) / 100.0f;
if(dmg_reduction_pct > 1.0f)
dmg_reduction_pct = 1.0f; //we cannot resist more then he is criticalling us, there is no point of the critical then :P
amount -= amount * dmg_reduction_pct;
}
- if(victim->IsCreature() && TO_CREATURE(victim)->GetCreatureInfo()->Rank != ELITE_WORLDBOSS)
- TO_CREATURE(victim)->Emote(EMOTE_ONESHOT_WOUNDCRITICAL);
+ if(victim->IsCreature() && TO< Creature* >(victim)->GetCreatureInfo()->Rank != ELITE_WORLDBOSS)
+ TO< Creature* >(victim)->Emote(EMOTE_ONESHOT_WOUNDCRITICAL);
return amount;
}

0 comments on commit 9a9b43d

Please sign in to comment.
Something went wrong with that request. Please try again.