Magic numbers cleanup:

- Replace many magic numbers with constants
- Use enum for vehicle flags/seat flags
- Correct structure for ItemRandomSuffixEntry

--HG--
branch : trunk
This commit is contained in:
Shocker
2010-09-28 08:21:51 +03:00
parent 192e972a59
commit 78803c9f09
44 changed files with 245 additions and 194 deletions
@@ -418,12 +418,12 @@ int32 AuraEffect::CalculateAmount(Unit * caster)
ItemRandomSuffixEntry const *item_rand_suffix = sItemRandomSuffixStore.LookupEntry(abs(castItem->GetItemRandomPropertyId()));
if (item_rand_suffix)
{
for (int k=0; k<MAX_SPELL_EFFECTS; k++)
for (int k = 0; k < MAX_ITEM_ENCHANTMENT_EFFECTS; k++)
{
SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(item_rand_suffix->enchant_id[k]);
if (pEnchant)
{
for (int t=0; t<MAX_SPELL_EFFECTS; t++)
for (int t = 0; t < MAX_ITEM_ENCHANTMENT_EFFECTS; t++)
if (pEnchant->spellid[t] == m_spellProto->Id)
{
amount = uint32((item_rand_suffix->prefix[k]*castItem->GetItemSuffixFactor()) / 10000);
@@ -2525,7 +2525,7 @@ void AuraEffect::HandleShapeshiftBoosts(Unit * target, bool apply) const
if (itr->second->state == PLAYERSPELL_REMOVED || itr->second->disabled) continue;
if (itr->first == spellId || itr->first == spellId2) continue;
SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
if (!spellInfo || !(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | (1<<7)))) continue;
if (!spellInfo || !(spellInfo->Attributes & (SPELL_ATTR_PASSIVE | SPELL_ATTR_UNK7))) continue;
if (spellInfo->Stances & (1<<(GetMiscValue()-1)))
target->CastSpell(target, itr->first, true, NULL, this);
}
@@ -4680,8 +4680,8 @@ void AuraEffect::HandleModTotalPercentStat(AuraApplication const * aurApp, uint8
}
}
//recalculate current HP/MP after applying aura modifications (only for spells with 0x10 flag)
if ((GetMiscValue() == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & 0x10))
//recalculate current HP/MP after applying aura modifications (only for spells with SPELL_ATTR_UNK4 0x00000010 flag)
if ((GetMiscValue() == STAT_STAMINA) && (maxHPValue > 0) && (m_spellProto->Attributes & SPELL_ATTR_UNK4))
{
uint32 newHPValue = target->CountPctFromMaxHealth(int32(100.0f * curHPValue / maxHPValue));
target->SetHealth(newHPValue);
+1 -1
View File
@@ -243,7 +243,7 @@ struct SpellValue
{
explicit SpellValue(SpellEntry const *proto)
{
for (uint32 i = 0; i < 3; ++i)
for (uint32 i = 0; i < MAX_SPELL_EFFECTS; ++i)
EffectBasePoints[i] = proto->EffectBasePoints[i];
MaxAffectedTargets = proto->MaxAffectedTargets;
RadiusMod = 1.0f;
+6 -7
View File
@@ -3424,9 +3424,8 @@ void Spell::EffectEnchantItemPerm(SpellEffIndex effIndex)
if (!pEnchant)
return;
// Prevent applying enchanements with Use: spell on items that already have a Use: effect, this is usually blocked from client side and
// can only be bypassed with memory manipulation.
for (int s = 0; s < 3; ++s)
// Prevent applying enchantments with Use: spell on items that already have an Use: effect, client-side check is not enough
for (int s = 0; s < MAX_ITEM_ENCHANTMENT_EFFECTS; ++s)
{
if (pEnchant->type[s] == ITEM_ENCHANTMENT_TYPE_USE_SPELL)
{
@@ -3488,7 +3487,7 @@ void Spell::EffectEnchantItemPrismatic(SpellEffIndex effIndex)
// support only enchantings with add socket in this slot
{
bool add_socket = false;
for (uint8 i = 0; i < 3; ++i)
for (uint8 i = 0; i < MAX_ITEM_ENCHANTMENT_EFFECTS; ++i)
{
if (pEnchant->type[i] == ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET)
{
@@ -3868,7 +3867,7 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex)
// multiple weapon dmg effect workaround
// execute only the last weapon damage
// and handle all effects at once
for (uint32 j = effIndex + 1; j < 3; ++j)
for (uint32 j = effIndex + 1; j < MAX_SPELL_EFFECTS; ++j)
{
switch (m_spellInfo->Effect[j])
{
@@ -4077,7 +4076,7 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex)
bool normalized = false;
float weaponDamagePercentMod = 1.0;
for (int j = 0; j < 3; ++j)
for (int j = 0; j < MAX_SPELL_EFFECTS; ++j)
{
switch(m_spellInfo->Effect[j])
{
@@ -4122,7 +4121,7 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex)
int32 weaponDamage = m_caster->CalculateDamage(m_attackType, normalized, true);
// Sequence is important
for (int j = 0; j < 3; ++j)
for (int j = 0; j < MAX_SPELL_EFFECTS; ++j)
{
// We assume that a spell have at most one fixed_bonus
// and at most one weaponDamagePercentMod
+12 -12
View File
@@ -514,7 +514,7 @@ SpellSpecific GetSpellSpecific(SpellEntry const * spellInfo)
{
bool food = false;
bool drink = false;
for (int i = 0; i < 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
switch(spellInfo->EffectApplyAuraName[i])
{
@@ -650,7 +650,7 @@ SpellSpecific GetSpellSpecific(SpellEntry const * spellInfo)
break;
}
for (int i = 0; i < 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
if (spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA)
{
@@ -869,7 +869,7 @@ bool SpellMgr::_isPositiveEffect(uint32 spellId, uint32 effIndex, bool deep) con
if (spellTriggeredProto)
{
// non-positive targets of main spell return early
for (int i = 0; i < 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
if (!spellTriggeredProto->Effect[i])
continue;
@@ -909,7 +909,7 @@ bool SpellMgr::_isPositiveEffect(uint32 spellId, uint32 effIndex, bool deep) con
if (spellproto->EffectImplicitTargetA[effIndex] != TARGET_UNIT_CASTER)
return false;
// but not this if this first effect (didn't find better check)
if (spellproto->Attributes & 0x4000000 && effIndex == 0)
if (spellproto->Attributes & SPELL_ATTR_NEGATIVE_1 && effIndex == 0)
return false;
break;
case SPELL_AURA_MECHANIC_IMMUNITY:
@@ -1010,7 +1010,7 @@ bool SpellMgr::_isPositiveSpell(uint32 spellId, bool deep) const
// spells with at least one negative effect are considered negative
// some self-applied spells have negative effects but in self casting case negative check ignored.
for (int i = 0; i < 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
if (!_isPositiveEffect(spellId, i, deep))
return false;
return true;
@@ -1172,7 +1172,7 @@ void SpellMgr::LoadSpellTargetPositions()
}
bool found = false;
for (int i = 0; i < 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
if (spellInfo->EffectImplicitTargetA[i] == TARGET_DST_DB || spellInfo->EffectImplicitTargetB[i] == TARGET_DST_DB)
{
@@ -1210,7 +1210,7 @@ void SpellMgr::LoadSpellTargetPositions()
continue;
bool found = false;
for (int j = 0; j < 3; ++j)
for (int j = 0; j < MAX_SPELL_EFFECTS; ++j)
{
switch(spellInfo->EffectImplicitTargetA[j])
{
@@ -1711,7 +1711,7 @@ bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo)
return false;
// All stance spells. if any better way, change it.
for (int i = 0; i < 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
switch(spellInfo->SpellFamilyName)
{
@@ -1927,7 +1927,7 @@ SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spell
return spellInfo;
bool needRankSelection = false;
for (int i=0; i<3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
if (IsPositiveEffect(spellInfo->Id, i) && (
spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA ||
@@ -2375,7 +2375,7 @@ bool SpellMgr::IsSpellValid(SpellEntry const *spellInfo, Player *pl, bool msg)
bool need_check_reagents = false;
// check effects
for (uint8 i = 0; i < 3; ++i)
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
switch (spellInfo->Effect[i])
{
@@ -2439,7 +2439,7 @@ bool SpellMgr::IsSpellValid(SpellEntry const *spellInfo, Player *pl, bool msg)
if (need_check_reagents)
{
for (uint8 j = 0; j < 8; ++j)
for (uint8 j = 0; j < MAX_SPELL_REAGENTS; ++j)
{
if (spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype(spellInfo->Reagent[j]))
{
@@ -2674,7 +2674,7 @@ SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const *spell
AreaGroupEntry const* groupEntry = sAreaGroupStore.LookupEntry(spellInfo->AreaGroupId);
while (groupEntry)
{
for (uint8 i = 0; i < 6; ++i)
for (uint8 i = 0; i < MAX_GROUP_AREA_IDS; ++i)
if (groupEntry->AreaId[i] == zone_id || groupEntry->AreaId[i] == area_id)
found = true;
if (found || !groupEntry->nextGroup)
+5 -5
View File
@@ -252,7 +252,7 @@ inline float GetSpellMaxRange(uint32 id, bool positive)
inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
{
for (int i= 0; i < 3; ++i)
for (int i= 0; i < MAX_SPELL_EFFECTS; ++i)
if (SpellEffects(spellInfo->Effect[i]) == effect)
return true;
return false;
@@ -260,7 +260,7 @@ inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
inline bool IsSpellHaveAura(SpellEntry const *spellInfo, AuraType aura)
{
for (int i= 0; i < 3; ++i)
for (int i= 0; i < MAX_SPELL_EFFECTS; ++i)
if (AuraType(spellInfo->EffectApplyAuraName[i]) == aura)
return true;
return false;
@@ -386,7 +386,7 @@ inline bool IsPositionTarget(uint32 target)
inline bool IsSpellWithCasterSourceTargetsOnly(SpellEntry const* spellInfo)
{
for (int i = 0; i < 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
uint32 targetA = spellInfo->EffectImplicitTargetA[i];
if (targetA && !IsCasterSourceTarget(targetA))
@@ -518,7 +518,7 @@ inline uint32 GetAllSpellMechanicMask(SpellEntry const* spellInfo)
uint32 mask = 0;
if (spellInfo->Mechanic)
mask |= 1<<spellInfo->Mechanic;
for (int i=0; i< 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
if (spellInfo->Effect[i] && spellInfo->EffectMechanic[i])
mask |= 1<<spellInfo->EffectMechanic[i];
return mask;
@@ -1352,7 +1352,7 @@ class SpellMgr
inline bool IsSpellWithCasterSourceTargetsOnly(SpellEntry const* spellInfo)
{
for (int i = 0; i < 3; ++i)
for (int i = 0; i < MAX_SPELL_EFFECTS; ++i)
if (uint32 target = spellInfo->EffectImplicitTargetA[i])
if (!IsCasterSourceTarget(target))
return false;