Convert some C style casts to new functions

--HG--
branch : trunk
This commit is contained in:
thenecromancer
2010-03-11 20:51:31 +01:00
parent 02a9cd6a43
commit e1542df90c
10 changed files with 51 additions and 60 deletions
+1 -1
View File
@@ -2110,7 +2110,7 @@ bool ChatHandler::HandleModifyBitCommand(const char* args)
}
// check online security
if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity(unit->ToPlayer(), 0))
return false;
char* pField = strtok((char*)args, " ");
+9 -9
View File
@@ -3026,7 +3026,7 @@ void Map::ScriptsProcess()
switch(step.script->datalong)
{
case 0: // Say
((Creature *)source)->Say(step.script->dataint, LANG_UNIVERSAL, unit_target);
source->ToCreature()->Say(step.script->dataint, LANG_UNIVERSAL, unit_target);
break;
case 1: // Whisper
if(!unit_target)
@@ -3034,17 +3034,17 @@ void Map::ScriptsProcess()
sLog.outError("SCRIPT_COMMAND_TALK attempt to whisper (%u) NULL, skipping.",step.script->datalong);
break;
}
((Creature *)source)->Whisper(step.script->dataint,unit_target);
source->ToCreature()->Whisper(step.script->dataint,unit_target);
break;
case 2: // Yell
((Creature *)source)->Yell(step.script->dataint, LANG_UNIVERSAL, unit_target);
source->ToCreature()->Yell(step.script->dataint, LANG_UNIVERSAL, unit_target);
break;
case 3: // Emote text
((Creature *)source)->TextEmote(step.script->dataint, unit_target);
source->ToCreature()->TextEmote(step.script->dataint, unit_target);
break;
case 4: // Boss Emote text
((Creature *)source)->MonsterTextEmote(step.script->dataint, unit_target, true);
break;
source->ToCreature()->MonsterTextEmote(step.script->dataint, unit_target, true);
break;
default:
break; // must be already checked at load
}
@@ -3064,7 +3064,7 @@ void Map::ScriptsProcess()
break;
}
((Creature *)source)->HandleEmoteCommand(step.script->datalong);
source->ToCreature()->HandleEmoteCommand(step.script->datalong);
break;
case SCRIPT_COMMAND_FIELD_SET:
if(!source)
@@ -3694,8 +3694,8 @@ void Map::ScriptsProcess()
break;
}
((Creature *)source)->SetOrientation(step.script->o);
((Creature *)source)->SendMovementFlagUpdate();
source->ToCreature()->SetOrientation(step.script->o);
source->ToCreature()->SendMovementFlagUpdate();
break;
}
+1 -1
View File
@@ -1572,7 +1572,7 @@ bool Pet::resetTalents(bool no_cost)
if (!pet_family || pet_family->petTalentType < 0)
return false;
Player *player = (Player *)owner;
Player *player = owner->ToPlayer();
uint8 level = getLevel();
uint32 talentPointsForLevel = GetMaxTalentPointsForLevel(level);
+3 -5
View File
@@ -6404,7 +6404,7 @@ bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, float honor, bool pvpt
if( uVictim->GetTypeId() == TYPEID_PLAYER )
{
Player *pVictim = (Player *)uVictim;
Player *pVictim = uVictim->ToPlayer();
if( GetTeam() == pVictim->GetTeam() && !sWorld.IsFFAPvPRealm() )
return false;
@@ -6459,9 +6459,7 @@ bool Player::RewardHonor(Unit *uVictim, uint32 groupsize, float honor, bool pvpt
}
else
{
Creature *cVictim = (Creature *)uVictim;
if (!cVictim->isRacialLeader())
if (!uVictim->ToCreature()->isRacialLeader())
return false;
honor = 100; // ??? need more info
@@ -19921,7 +19919,7 @@ bool Player::canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList, bool
if(isGameMaster())
{
if(u->GetTypeId() == TYPEID_PLAYER)
return ((Player *)u)->GetSession()->GetSecurity() <= GetSession()->GetSecurity();
return u->ToPlayer()->GetSession()->GetSecurity() <= GetSession()->GetSecurity();
else
return true;
}
+3 -3
View File
@@ -1182,7 +1182,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo *target)
caster->ProcDamageAndSpell(unitTarget, procAttacker, procVictim, procEx, damageInfo.damage, m_attackType, m_spellInfo, m_triggeredByAuraSpell);
if(caster->GetTypeId() == TYPEID_PLAYER && (m_spellInfo->Attributes & SPELL_ATTR_STOP_ATTACK_TARGET) == 0 &&
(m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MELEE || m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_RANGED))
((Player *)caster)->CastItemCombatSpell(unitTarget, m_attackType, procVictim, procEx);
caster->ToPlayer()->CastItemCombatSpell(unitTarget, m_attackType, procVictim, procEx);
}
caster->DealSpellDamage(&damageInfo, true);
@@ -1730,7 +1730,7 @@ WorldObject* Spell::SearchNearbyTarget(float range, SpellTargets TargetType)
if ((*itr)->GetEntry() == i_spellST->second.targetEntry && (*itr)->IsWithinDistInMap(m_caster, range))
{
goScriptTarget = NULL;
creatureScriptTarget = ((Creature *)*itr);
creatureScriptTarget = (*itr)->ToCreature();
range = m_caster->GetDistance(creatureScriptTarget);
}
break;
@@ -4506,7 +4506,7 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_targets.m_targetMask == TARGET_FLAG_SELF &&
m_spellInfo->EffectImplicitTargetA[1] == TARGET_UNIT_TARGET_ENEMY)
{
if (target = m_caster->GetUnit(*m_caster, ((Player *)m_caster)->GetSelection()))
if (target = m_caster->GetUnit(*m_caster, m_caster->ToPlayer()->GetSelection()))
m_targets.setUnitTarget(target);
else
return SPELL_FAILED_BAD_TARGETS;
+7 -7
View File
@@ -2385,20 +2385,20 @@ void AuraEffect::HandleShapeshiftBoosts(Unit * target, bool apply) const
if (spellId)
{
if(target->GetTypeId() == TYPEID_PLAYER)
((Player *)target)->RemoveSpellCooldown(spellId);
target->ToPlayer()->RemoveSpellCooldown(spellId);
target->CastSpell(target, spellId, true, NULL, this );
}
if (spellId2)
{
if(target->GetTypeId() == TYPEID_PLAYER)
((Player *)target)->RemoveSpellCooldown(spellId2);
target->ToPlayer()->RemoveSpellCooldown(spellId2);
target->CastSpell(target, spellId2, true, NULL, this);
}
if(target->GetTypeId() == TYPEID_PLAYER)
{
const PlayerSpellMap& sp_list = ((Player *)target)->GetSpellMap();
const PlayerSpellMap& sp_list = target->ToPlayer()->GetSpellMap();
for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
{
if(itr->second->state == PLAYERSPELL_REMOVED || itr->second->disabled) continue;
@@ -2886,7 +2886,7 @@ void AuraEffect::HandleAuraModShapeshift(AuraApplication const * aurApp, uint8 m
// Stance mastery + Tactical mastery (both passive, and last have aura only in defense stance, but need apply at any stance switch)
if(target->GetTypeId() == TYPEID_PLAYER)
{
PlayerSpellMap const& sp_list = ((Player *)target)->GetSpellMap();
PlayerSpellMap const& sp_list = target->ToPlayer()->GetSpellMap();
for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
{
if(itr->second->state == PLAYERSPELL_REMOVED || itr->second->disabled) continue;
@@ -5834,7 +5834,7 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo
{
// Play part 1
if(apply)
target->PlayDirectSound(14970, (Player *)target);
target->PlayDirectSound(14970, target->ToPlayer());
// continue in 58205
else
target->CastSpell(target, 58205, true);
@@ -5846,10 +5846,10 @@ void AuraEffect::HandleAuraDummy(AuraApplication const * aurApp, uint8 mode, boo
{
// Play part 2
if(apply)
target->PlayDirectSound(14971, (Player *)target);
target->PlayDirectSound(14971, target->ToPlayer());
// Play part 3
else
target->PlayDirectSound(14972, (Player *)target);
target->PlayDirectSound(14972, target->ToPlayer());
}
break;
}
+8 -8
View File
@@ -510,7 +510,7 @@ void Spell::SpellDamageSchoolDmg(uint32 effect_idx)
// Shadow Bite
else if (m_spellInfo->SpellFamilyFlags[1] & 0x400000)
{
if (m_caster->GetTypeId() == TYPEID_UNIT && ((Creature *)m_caster)->isPet())
if (m_caster->GetTypeId() == TYPEID_UNIT && m_caster->ToCreature()->isPet())
{
// Get DoTs on target by owner (5% increase by dot)
damage += 5 * unitTarget->GetDoTsByCaster(m_caster->GetOwnerGUID()) / 100;
@@ -1473,7 +1473,7 @@ void Spell::EffectDummy(uint32 i)
return;
// immediately finishes the cooldown on Frost spells
const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
const SpellCooldowns& cm = m_caster->ToPlayer()->GetSpellCooldownMap();
for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
{
SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
@@ -1751,7 +1751,7 @@ void Spell::EffectDummy(uint32 i)
return;
//immediately finishes the cooldown on certain Rogue abilities
const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
const SpellCooldowns& cm = m_caster->ToPlayer()->GetSpellCooldownMap();
for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
{
SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
@@ -4829,8 +4829,8 @@ void Spell::EffectSummonObjectWild(uint32 i)
if(pGameObj->GetGoType() == GAMEOBJECT_TYPE_FLAGDROP && m_caster->GetTypeId() == TYPEID_PLAYER)
{
Player *pl = (Player*)m_caster;
BattleGround* bg = ((Player *)m_caster)->GetBattleGround();
Player *pl = m_caster->ToPlayer();
BattleGround* bg = pl->GetBattleGround();
switch(pGameObj->GetMapId())
{
@@ -5807,7 +5807,7 @@ void Spell::EffectScriptEffect(uint32 effIndex)
// Demonic Empowerment
case 47193:
{
if(!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || !((Creature *)unitTarget)->isPet())
if(!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || !unitTarget->ToCreature()->isPet())
return;
CreatureInfo const * ci = objmgr.GetCreatureTemplate(unitTarget->GetEntry());
switch (ci->family)
@@ -6152,7 +6152,7 @@ void Spell::EffectSanctuary(uint32 /*i*/)
&& m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE
&& (m_spellInfo->SpellFamilyFlags[0] & SPELLFAMILYFLAG_ROGUE_VANISH))
{
((Player *)m_caster)->RemoveAurasByType(SPELL_AURA_MOD_ROOT);
m_caster->ToPlayer()->RemoveAurasByType(SPELL_AURA_MOD_ROOT);
// Overkill
if(m_caster->ToPlayer()->HasSpell(58426))
m_caster->CastSpell(m_caster, 58427, true);
@@ -7580,7 +7580,7 @@ void Spell::EffectPlayerNotification(uint32 /*eff_idx*/)
{
case 58730: // Restricted Flight Area
case 58600: // Restricted Flight Area
((Player *)unitTarget)->GetSession()->SendNotification(LANG_ZONE_NOFLYZONE);
unitTarget->ToPlayer()->GetSession()->SendNotification(LANG_ZONE_NOFLYZONE);
break;
}
}
+1 -1
View File
@@ -582,7 +582,7 @@ void WorldSession::HandleMirrrorImageDataRequest( WorldPacket & recv_data )
data << (uint32)creator->GetDisplayId();
if (creator->GetTypeId() == TYPEID_PLAYER)
{
Player * pCreator = (Player *)creator;
Player * pCreator = creator->ToPlayer();
data << (uint8)pCreator->getRace();
data << (uint8)pCreator->getGender();
data << (uint8)pCreator->getClass();
+17 -24
View File
@@ -241,7 +241,7 @@ void Unit::Update(uint32 p_time)
SendThreatListUpdate();
// update combat timer only for players and pets (only pets with PetAI)
if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || (((Creature *)this)->isPet() && IsControlledByPlayer())))
if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || (ToCreature()->isPet() && IsControlledByPlayer())))
{
// Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away
// targets without stopping half way there and running off.
@@ -578,13 +578,6 @@ void Unit::DealDamageMods(Unit *pVictim, uint32 &damage, uint32* absorb)
uint32 originalDamage = damage;
//Script Event damage Deal
//if (GetTypeId() == TYPEID_UNIT && ((Creature *)this)->AI())
// ((Creature *)this)->AI()->DamageDeal(pVictim, damage);
//Script Event damage taken
//if (pVictim->GetTypeId() == TYPEID_UNIT && ((Creature *)pVictim)->IsAIEnabled)
// ((Creature *)pVictim)->AI()->DamageTaken(this, damage);
if (absorb && originalDamage > damage)
absorb += (originalDamage - damage);
}
@@ -1553,7 +1546,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss)
}
if (GetTypeId() == TYPEID_PLAYER)
((Player *)this)->CastItemCombatSpell(pVictim, damageInfo->attackType, damageInfo->procVictim, damageInfo->procEx);
ToPlayer()->CastItemCombatSpell(pVictim, damageInfo->attackType, damageInfo->procVictim, damageInfo->procEx);
// Do effect if any damage done to target
if (damageInfo->damage)
@@ -1649,7 +1642,7 @@ uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage, SpellEnt
// item dependent spell - check curent weapons
for (int i = 0; i < MAX_ATTACK; ++i)
{
Item *weapon = ((Player *)this)->GetWeaponForAttack(WeaponAttackType(i));
Item *weapon = ToPlayer()->GetWeaponForAttack(WeaponAttackType(i));
if (weapon && weapon->IsFitToSpellRequirements((*itr)->GetSpellProto()))
{
@@ -5518,14 +5511,14 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
return false;
// Get Aldor reputation rank
if (((Player *)this)->GetReputationRank(932) == REP_EXALTED)
if (ToPlayer()->GetReputationRank(932) == REP_EXALTED)
{
target = this;
triggered_spell_id = 45479;
break;
}
// Get Scryers reputation rank
if (((Player *)this)->GetReputationRank(934) == REP_EXALTED)
if (ToPlayer()->GetReputationRank(934) == REP_EXALTED)
{
// triggered at positive/self casts also, current attack target used then
if(IsFriendlyTo(target))
@@ -5533,7 +5526,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
target = getVictim();
if(!target)
{
uint64 selected_guid = ((Player *)this)->GetSelection();
uint64 selected_guid = ToPlayer()->GetSelection();
target = ObjectAccessor::GetUnit(*this,selected_guid);
if(!target)
return false;
@@ -5556,14 +5549,14 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
return false;
// Get Aldor reputation rank
if (((Player *)this)->GetReputationRank(932) == REP_EXALTED)
if (ToPlayer()->GetReputationRank(932) == REP_EXALTED)
{
target = this;
triggered_spell_id = 45480;
break;
}
// Get Scryers reputation rank
if (((Player *)this)->GetReputationRank(934) == REP_EXALTED)
if (ToPlayer()->GetReputationRank(934) == REP_EXALTED)
{
triggered_spell_id = 45428;
break;
@@ -5579,14 +5572,14 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
return false;
// Get Aldor reputation rank
if (((Player *)this)->GetReputationRank(932) == REP_EXALTED)
if (ToPlayer()->GetReputationRank(932) == REP_EXALTED)
{
target = this;
triggered_spell_id = 45432;
break;
}
// Get Scryers reputation rank
if (((Player *)this)->GetReputationRank(934) == REP_EXALTED)
if (ToPlayer()->GetReputationRank(934) == REP_EXALTED)
{
target = this;
triggered_spell_id = 45431;
@@ -5603,14 +5596,14 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
return false;
// Get Aldor reputation rank
if (((Player *)this)->GetReputationRank(932) == REP_EXALTED)
if (ToPlayer()->GetReputationRank(932) == REP_EXALTED)
{
target = this;
triggered_spell_id = 45478;
break;
}
// Get Scryers reputation rank
if (((Player *)this)->GetReputationRank(934) == REP_EXALTED)
if (ToPlayer()->GetReputationRank(934) == REP_EXALTED)
{
triggered_spell_id = 45430;
break;
@@ -6288,7 +6281,7 @@ bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, AuraEffect* trigger
int32 basepoints1 = triggerAmount * 2;
// Improved Leader of the Pack
// Check cooldown of heal spell cooldown
if (GetTypeId() == TYPEID_PLAYER && !((Player *)this)->HasSpellCooldown(34299))
if (GetTypeId() == TYPEID_PLAYER && !ToPlayer()->HasSpellCooldown(34299))
CastCustomSpell(this,60889,&basepoints1,0,0,true,0,triggeredByAura);
break;
}
@@ -11301,7 +11294,7 @@ void Unit::Mount(uint32 mount, uint32 VehicleId)
Pet* pet = this->ToPlayer()->GetPet();
if (pet)
{
BattleGround *bg = ((Player *)this)->GetBattleGround();
BattleGround *bg = ToPlayer()->GetBattleGround();
// don't unsummon pet in arena but SetFlag UNIT_FLAG_STUNNED to disable pet's interface
if (bg && bg->isArena())
pet->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
@@ -11541,7 +11534,7 @@ bool Unit::isAttackableByAOE() const
UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_OOC_NOT_ATTACKABLE))
return false;
if (GetTypeId() == TYPEID_PLAYER && ((Player *)this)->isGameMaster())
if (GetTypeId() == TYPEID_PLAYER && ToPlayer()->isGameMaster())
return false;
return !hasUnitState(UNIT_STAT_UNATTACKABLE);
@@ -14828,7 +14821,7 @@ void Unit::SetStunned(bool apply)
// don't remove UNIT_FLAG_STUNNED for pet when owner is mounted (disabled pet's interface)
Unit *pOwner = GetOwner();
if (!pOwner || (pOwner->GetTypeId() == TYPEID_PLAYER && !((Player *)pOwner)->IsMounted()))
if (!pOwner || (pOwner->GetTypeId() == TYPEID_PLAYER && !pOwner->ToPlayer()->IsMounted()))
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
if (!hasUnitState(UNIT_STAT_ROOT)) // prevent allow move if have also root effect
@@ -14855,7 +14848,7 @@ void Unit::SetRooted(bool apply)
SendMessageToSet(&data,true);
if (GetTypeId() != TYPEID_PLAYER)
((Creature *)this)->StopMoving();
ToCreature()->StopMoving();
}
else
{
+1 -1
View File
@@ -62,7 +62,7 @@ struct npc_lazy_peonAI : public ScriptedAI
if (spell->Id == SPELL_AWAKEN_PEON && caster->GetTypeId() == TYPEID_PLAYER
&& CAST_PLR(caster)->GetQuestStatus(QUEST_LAZY_PEONS) == QUEST_STATUS_INCOMPLETE)
{
((Player *)caster)->KilledMonsterCredit(m_creature->GetEntry(),m_creature->GetGUID());
caster->ToPlayer()->KilledMonsterCredit(m_creature->GetEntry(),m_creature->GetGUID());
DoScriptText(SAY_SPELL_HIT, m_creature, caster);
m_creature->RemoveAllAuras();
if(GameObject* Lumberpile = m_creature->FindNearestGameObject(GO_LUMBERPILE, 20))