diff options
author | Anubisss <none@none> | 2010-03-27 16:08:14 +0100 |
---|---|---|
committer | Anubisss <none@none> | 2010-03-27 16:08:14 +0100 |
commit | ce8cc85dfabeb57c30f2f2e6deb577abeaabaf37 (patch) | |
tree | 55dbae80d50737b77b869013552e78701e8e5201 | |
parent | 769f54eedfd979101ecc9bd94dea0a274c569ed3 (diff) |
Make a function(ToTempSummon()) which can convert Creature to TempSummon with a C++ cast(reinterpret_cast) and with a type check(isSummon()).
This function is like ToPlayer(), ToTotem(), etc.
This commit is like ede831bdd6f0cff481acc33f269fa7f8c78befd4 / r7496:
http://code.google.com/p/trinitycore/source/detail?r=ede831bdd6f0cff481acc33f269fa7f8c78befd4
As a result, this commit has the advantages and the "disadvantages" too, like r7496.
Please try to be polite if this commit causes some crashes.
--HG--
branch : trunk
-rw-r--r-- | src/game/CreatureAI.cpp | 2 | ||||
-rw-r--r-- | src/game/ObjectMgr.cpp | 2 | ||||
-rw-r--r-- | src/game/OutdoorPvPWG.cpp | 2 | ||||
-rw-r--r-- | src/game/SpellEffects.cpp | 6 | ||||
-rw-r--r-- | src/game/TemporarySummon.cpp | 2 | ||||
-rw-r--r-- | src/game/Unit.cpp | 8 | ||||
-rw-r--r-- | src/game/Unit.h | 4 | ||||
-rw-r--r-- | src/game/Vehicle.cpp | 2 | ||||
-rw-r--r-- | src/scripts/northrend/utgarde_keep/utgarde_pinnacle/boss_svala.cpp | 2 |
9 files changed, 16 insertions, 14 deletions
diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index 106ac67d03f..503c7ce033d 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -57,7 +57,7 @@ void CreatureAI::DoZoneInCombat(Creature* creature) creature->AI()->AttackStart(target); else if(creature->isSummon()) { - if(Unit *summoner = ((TempSummon*)creature)->GetSummoner()) + if(Unit *summoner = creature->ToTempSummon()->GetSummoner()) { Unit *target = summoner->getAttackerForHelper(); if(!target && summoner->CanHaveThreatList() && !summoner->getThreatManager().isThreatListEmpty()) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 84a8254bbe8..c449267e5f5 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -141,7 +141,7 @@ bool SpellClickInfo::IsFitToRequirements(Player const* player, Creature const * Unit const * summoner = NULL; // Check summoners for party if (clickNpc->isSummon()) - summoner = ((TempSummon*)clickNpc)->GetSummoner(); + summoner = clickNpc->ToTempSummon()->GetSummoner(); if (!summoner) summoner = clickNpc; diff --git a/src/game/OutdoorPvPWG.cpp b/src/game/OutdoorPvPWG.cpp index 018bcaa556d..a5047e3a5ff 100644 --- a/src/game/OutdoorPvPWG.cpp +++ b/src/game/OutdoorPvPWG.cpp @@ -641,7 +641,7 @@ void OutdoorPvPWG::OnCreatureCreate(Creature *creature, bool add) else return; - if (uint32 engLowguid = GUID_LOPART(((TempSummon*)creature)->GetSummonerGUID())) + if (uint32 engLowguid = GUID_LOPART(creature->ToTempSummon()->GetSummonerGUID())) { if (OPvPCapturePointWG *workshop = GetWorkshopByEngGuid(engLowguid)) { diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 36f8387d91a..f63b36e8736 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -5456,7 +5456,7 @@ void Spell::EffectScriptEffect(uint32 effIndex) case 52173: // Coyote Spirit Despawn case 60243: // Blood Parrot Despawn if (unitTarget->GetTypeId() == TYPEID_UNIT && unitTarget->ToCreature()->isSummon()) - ((TempSummon*)unitTarget)->UnSummon(); + unitTarget->ToTempSummon()->UnSummon(); return; // Sky Darkener Assault case 52124: @@ -5664,10 +5664,10 @@ void Spell::EffectScriptEffect(uint32 effIndex) if(chargesaura && chargesaura->GetCharges() > 1) { chargesaura->SetCharges(chargesaura->GetCharges() - 1); - m_caster->CastSpell(unitTarget, spell_heal, true, NULL, NULL, ((TempSummon*)m_caster)->GetSummonerGUID()); + m_caster->CastSpell(unitTarget, spell_heal, true, NULL, NULL, m_caster->ToTempSummon()->GetSummonerGUID()); } else - ((TempSummon*)m_caster)->UnSummon(); + m_caster->ToTempSummon()->UnSummon(); return; } // Stoneclaw Totem diff --git a/src/game/TemporarySummon.cpp b/src/game/TemporarySummon.cpp index e708aadfd77..c60e0119821 100644 --- a/src/game/TemporarySummon.cpp +++ b/src/game/TemporarySummon.cpp @@ -197,7 +197,7 @@ void TempSummon::InitStats(uint32 duration) { Creature *oldSummon = GetMap()->GetCreature(owner->m_SummonSlot[slot]); if(oldSummon && oldSummon->isSummon()) - ((TempSummon*)oldSummon)->UnSummon(); + oldSummon->ToTempSummon()->UnSummon(); } owner->m_SummonSlot[slot] = GetGUID(); } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index fabc476e8ff..afcf7e1a44f 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -9335,7 +9335,7 @@ void Unit::RemoveAllMinionsByEntry(uint32 entry) ++itr; if (unit->GetEntry() == entry && unit->GetTypeId() == TYPEID_UNIT && unit->ToCreature()->isSummon()) // minion, actually - ((TempSummon*)unit)->UnSummon(); + unit->ToTempSummon()->UnSummon(); // i think this is safe because i have never heard that a despawned minion will trigger a same minion } } @@ -9502,7 +9502,7 @@ void Unit::RemoveAllControlled() if (target->GetCharmerGUID() == GetGUID()) target->RemoveCharmAuras(); else if (target->GetOwnerGUID() == GetGUID() && target->isSummon()) - ((TempSummon*)target)->UnSummon(); + target->ToTempSummon()->UnSummon(); else sLog.outError("Unit %u is trying to release unit %u which is neither charmed nor owned by it", GetEntry(), target->GetEntry()); } @@ -9620,7 +9620,7 @@ void Unit::UnsummonAllTotems() if (Creature *OldTotem = GetMap()->GetCreature(m_SummonSlot[i])) if (OldTotem->isSummon()) - ((TempSummon*)OldTotem)->UnSummon(); + OldTotem->ToTempSummon()->UnSummon(); } } @@ -12138,7 +12138,7 @@ Unit* Creature::SelectVictim() target = getAttackerForHelper(); if (!target && isSummon()) { - if (Unit * owner = ((TempSummon*)this)->GetOwner()) + if (Unit * owner = this->ToTempSummon()->GetOwner()) { if (owner->isInCombat()) target = owner->getAttackerForHelper(); diff --git a/src/game/Unit.h b/src/game/Unit.h index d98c9730049..88db4527727 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1957,8 +1957,10 @@ class Unit : public WorldObject void OutDebugInfo() const; virtual bool isBeingLoaded() const { return false;} - Pet* ToPet(){ if(isPet()) return reinterpret_cast<Pet*>(this); else return NULL; } + Pet* ToPet(){ if(isPet()) return reinterpret_cast<Pet*>(this); else return NULL; } Totem* ToTotem(){ if(isTotem()) return reinterpret_cast<Totem*>(this); else return NULL; } + TempSummon* ToTempSummon() { if(isSummon()) return reinterpret_cast<TempSummon*>(this); else return NULL; } + const TempSummon* ToTempSummon() const { if(isSummon()) return reinterpret_cast<const TempSummon*>(this); else return NULL; } protected: explicit Unit (); diff --git a/src/game/Vehicle.cpp b/src/game/Vehicle.cpp index 6fcea316787..bd81199a375 100644 --- a/src/game/Vehicle.cpp +++ b/src/game/Vehicle.cpp @@ -105,7 +105,7 @@ void Vehicle::Uninstall() for (SeatMap::iterator itr = m_Seats.begin(); itr != m_Seats.end(); ++itr) if(Unit *passenger = itr->second.passenger) if(passenger->HasUnitTypeMask(UNIT_MASK_ACCESSORY)) - ((TempSummon*)passenger)->UnSummon(); + passenger->ToTempSummon()->UnSummon(); RemoveAllPassengers(); } diff --git a/src/scripts/northrend/utgarde_keep/utgarde_pinnacle/boss_svala.cpp b/src/scripts/northrend/utgarde_keep/utgarde_pinnacle/boss_svala.cpp index 1dfa43d171a..99e3fee4069 100644 --- a/src/scripts/northrend/utgarde_keep/utgarde_pinnacle/boss_svala.cpp +++ b/src/scripts/northrend/utgarde_keep/utgarde_pinnacle/boss_svala.cpp @@ -174,7 +174,7 @@ struct boss_svalaAI : public ScriptedAI { m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE|UNIT_FLAG_NOT_SELECTABLE); m_creature->SetDisplayId(DATA_SVALA_DISPLAY_ID); - ((TempSummon*)pArthas)->UnSummon(); // TODO: should need a ToTempSummon() + pArthas->ToTempSummon()->UnSummon(); ArthasGUID = 0; Phase = FINISHED; } |