Scripts/Misc: Replace some unsafe WorldObject* class members in scripts with ObjectGuid

Replace some unsafe WorldObject* class members and derived types in scripts with ObjectGuid.
Code cleanup.
This commit is contained in:
jackpoz committed 2015-08-16 22:29:56 +02:00
1 parent 418155fe3a
commit 2f92a2f58e
17 files changed
+50 -648

No files matched your search

@@ -664,10 +664,9 @@ struct boss_faction_championsAI : public BossAI
{
std::list<HostileReference*> const& tList = me->getThreatManager().getThreatList();
std::list<HostileReference*>::const_iterator iter;
Unit* target;
for (iter = tList.begin(); iter!=tList.end(); ++iter)
{
target = ObjectAccessor::GetUnit(*me, (*iter)->getUnitGuid());
Unit* target = ObjectAccessor::GetUnit(*me, (*iter)->getUnitGuid());
if (target && target->getPowerType() == POWER_MANA)
return target;
}
@@ -679,10 +678,9 @@ struct boss_faction_championsAI : public BossAI
std::list<HostileReference*> const& tList = me->getThreatManager().getThreatList();
std::list<HostileReference*>::const_iterator iter;
uint32 count = 0;
Unit* target;
for (iter = tList.begin(); iter != tList.end(); ++iter)
{
target = ObjectAccessor::GetUnit(*me, (*iter)->getUnitGuid());
Unit* target = ObjectAccessor::GetUnit(*me, (*iter)->getUnitGuid());
if (target && me->GetDistance2d(target) < distance)
++count;
}
@@ -137,9 +137,8 @@ class boss_ick : public CreatureScript
struct boss_ickAI : public BossAI
{
boss_ickAI(Creature* creature) : BossAI(creature, DATA_ICK), _vehicle(creature->GetVehicleKit())
boss_ickAI(Creature* creature) : BossAI(creature, DATA_ICK)
{
ASSERT(_vehicle);
_tempThreat = 0;
}
@@ -177,7 +176,8 @@ class boss_ick : public CreatureScript
{
if (Creature* krick = GetKrick())
{
_vehicle->RemoveAllPassengers();
if (Vehicle* _vehicle = me->GetVehicleKit())
_vehicle->RemoveAllPassengers();
if (krick->AI())
krick->AI()->DoAction(ACTION_OUTRO);
}
@@ -268,7 +268,6 @@ class boss_ick : public CreatureScript
}
private:
Vehicle* _vehicle;
float _tempThreat;
};
@@ -290,9 +290,8 @@ class boss_rimefang : public CreatureScript
struct boss_rimefangAI : public ScriptedAI
{
boss_rimefangAI(Creature* creature) : ScriptedAI(creature), _vehicle(creature->GetVehicleKit())
boss_rimefangAI(Creature* creature) : ScriptedAI(creature)
{
ASSERT(_vehicle);
Initialize();
}
@@ -314,7 +313,8 @@ class boss_rimefang : public CreatureScript
void JustReachedHome() override
{
_vehicle->InstallAllAccessories(false);
if (Vehicle* _vehicle = me->GetVehicleKit())
_vehicle->InstallAllAccessories(false);
}
void DoAction(int32 actionId) override
@@ -376,7 +376,6 @@ class boss_rimefang : public CreatureScript
}
private:
Vehicle* _vehicle;
ObjectGuid _hoarfrostTargetGUID;
EventMap _events;
uint8 _currentWaypoint;
@@ -110,9 +110,8 @@ class npc_iceborn_protodrake : public CreatureScript
struct npc_iceborn_protodrakeAI: public ScriptedAI
{
npc_iceborn_protodrakeAI(Creature* creature) : ScriptedAI(creature), _vehicle(creature->GetVehicleKit())
npc_iceborn_protodrakeAI(Creature* creature) : ScriptedAI(creature)
{
ASSERT(_vehicle);
Initialize();
}
@@ -128,7 +127,8 @@ class npc_iceborn_protodrake : public CreatureScript
void EnterCombat(Unit* /*who*/) override
{
_vehicle->RemoveAllPassengers();
if (Vehicle* _vehicle = me->GetVehicleKit())
_vehicle->RemoveAllPassengers();
}
void UpdateAI(uint32 diff) override
@@ -148,7 +148,6 @@ class npc_iceborn_protodrake : public CreatureScript
}
private:
Vehicle* _vehicle;
uint32 _frostBreathCooldown;
};
@@ -432,20 +432,21 @@ class StartMovementEvent : public BasicEvent
{
public:
StartMovementEvent(Creature* summoner, Creature* owner)
: _summoner(summoner), _owner(owner)
: _summonerGuid(summoner->GetGUID()), _owner(owner)
{
}
bool Execute(uint64 /*time*/, uint32 /*diff*/)
{
_owner->SetReactState(REACT_AGGRESSIVE);
if (Unit* target = _summoner->AI()->SelectTarget(SELECT_TARGET_RANDOM, 0, NonTankTargetSelector(_summoner)))
_owner->AI()->AttackStart(target);
if (Creature* _summoner = ObjectAccessor::GetCreature(*_owner, _summonerGuid))
if (Unit* target = _summoner->AI()->SelectTarget(SELECT_TARGET_RANDOM, 0, NonTankTargetSelector(_summoner)))
_owner->AI()->AttackStart(target);
return true;
}
private:
Creature* _summoner;
ObjectGuid _summonerGuid;
Creature* _owner;
};
@@ -117,14 +117,12 @@ class boss_keristrasza : public CreatureScript
ContainmentSphereGUIDs[1] = instance->GetGuidData(ORMOROKS_CONTAINMET_SPHERE);
ContainmentSphereGUIDs[2] = instance->GetGuidData(TELESTRAS_CONTAINMET_SPHERE);
GameObject* ContainmentSpheres[DATA_CONTAINMENT_SPHERES];
for (uint8 i = 0; i < DATA_CONTAINMENT_SPHERES; ++i)
{
ContainmentSpheres[i] = ObjectAccessor::GetGameObject(*me, ContainmentSphereGUIDs[i]);
if (!ContainmentSpheres[i])
GameObject* ContainmentSphere = ObjectAccessor::GetGameObject(*me, ContainmentSphereGUIDs[i]);
if (!ContainmentSphere)
return false;
if (ContainmentSpheres[i]->GetGoState() != GO_STATE_ACTIVE)
if (ContainmentSphere->GetGoState() != GO_STATE_ACTIVE)
return false;
}
if (remove_prison)
@@ -224,7 +224,7 @@ class boss_flame_leviathan : public CreatureScript
struct boss_flame_leviathanAI : public BossAI
{
boss_flame_leviathanAI(Creature* creature) : BossAI(creature, BOSS_LEVIATHAN), vehicle(creature->GetVehicleKit())
boss_flame_leviathanAI(Creature* creature) : BossAI(creature, BOSS_LEVIATHAN)
{
Initialize();
}
@@ -244,7 +244,6 @@ class boss_flame_leviathan : public CreatureScript
void InitializeAI() override
{
ASSERT(vehicle);
if (!me->isDead())
Reset();
@@ -256,7 +255,6 @@ class boss_flame_leviathan : public CreatureScript
me->SetReactState(REACT_PASSIVE);
}
Vehicle* vehicle;
uint8 ActiveTowersCount;
uint8 Shutdown;
bool ActiveTowers;
@@ -339,7 +337,7 @@ class boss_flame_leviathan : public CreatureScript
void SpellHit(Unit* /*caster*/, SpellInfo const* spell) override
{
if (spell->Id == SPELL_START_THE_ENGINE)
vehicle->InstallAllAccessories(false);
ASSERT_NOTNULL(me->GetVehicleKit())->InstallAllAccessories(false);
if (spell->Id == SPELL_ELECTROSHOCK)
me->InterruptSpell(CURRENT_CHANNELED_SPELL);
@@ -584,16 +582,14 @@ class boss_flame_leviathan_seat : public CreatureScript
struct boss_flame_leviathan_seatAI : public ScriptedAI
{
boss_flame_leviathan_seatAI(Creature* creature) : ScriptedAI(creature), vehicle(creature->GetVehicleKit())
boss_flame_leviathan_seatAI(Creature* creature) : ScriptedAI(creature)
{
ASSERT(vehicle);
me->SetReactState(REACT_PASSIVE);
me->SetDisplayId(me->GetCreatureTemplate()->Modelid2);
instance = creature->GetInstanceScript();
}
InstanceScript* instance;
Vehicle* vehicle;
void PassengerBoarded(Unit* who, int8 seatId, bool apply) override
{
@@ -628,7 +624,7 @@ class boss_flame_leviathan_seat : public CreatureScript
if (apply)
return;
if (Unit* device = vehicle->GetPassenger(SEAT_DEVICE))
if (Unit* device = ASSERT_NOTNULL(me->GetVehicleKit())->GetPassenger(SEAT_DEVICE))
{
device->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
device->SetUInt32Value(UNIT_FIELD_FLAGS, 0); // unselectable
@@ -611,17 +611,16 @@ class boss_freya : public CreatureScript
me->DespawnOrUnsummon(7500);
me->CastSpell(me, SPELL_KNOCK_ON_WOOD_CREDIT, true);
Creature* Elder[3];
for (uint8 n = 0; n < 3; ++n)
{
Elder[n] = ObjectAccessor::GetCreature(*me, instance->GetGuidData(BOSS_BRIGHTLEAF + n));
if (Elder[n] && Elder[n]->IsAlive())
Creature* Elder = ObjectAccessor::GetCreature(*me, instance->GetGuidData(BOSS_BRIGHTLEAF + n));
if (Elder && Elder->IsAlive())
{
Elder[n]->RemoveAllAuras();
Elder[n]->AttackStop();
Elder[n]->CombatStop(true);
Elder[n]->DeleteThreatList();
Elder[n]->GetAI()->DoAction(ACTION_ELDER_FREYA_KILLED);
Elder->RemoveAllAuras();
Elder->AttackStop();
Elder->CombatStop(true);
Elder->DeleteThreatList();
Elder->GetAI()->DoAction(ACTION_ELDER_FREYA_KILLED);
}
}
}
@@ -117,10 +117,9 @@ class boss_ignis : public CreatureScript
struct boss_ignis_AI : public BossAI
{
boss_ignis_AI(Creature* creature) : BossAI(creature, BOSS_IGNIS), _vehicle(me->GetVehicleKit())
boss_ignis_AI(Creature* creature) : BossAI(creature, BOSS_IGNIS)
{
Initialize();
ASSERT(_vehicle);
}
void Initialize()
@@ -133,7 +132,7 @@ class boss_ignis : public CreatureScript
void Reset() override
{
_Reset();
if (_vehicle)
if (Vehicle* _vehicle = me->GetVehicleKit())
_vehicle->RemoveAllPassengers();
instance->DoStopTimedAchievement(ACHIEVEMENT_TIMED_TYPE_EVENT, ACHIEVEMENT_IGNIS_START_EVENT);
@@ -284,7 +283,6 @@ class boss_ignis : public CreatureScript
private:
ObjectGuid _slagPotGUID;
Vehicle* _vehicle;
time_t _firstConstructKill;
bool _shattered;
@@ -100,11 +100,9 @@ class boss_kologarn : public CreatureScript
struct boss_kologarnAI : public BossAI
{
boss_kologarnAI(Creature* creature) : BossAI(creature, BOSS_KOLOGARN), vehicle(creature->GetVehicleKit()),
boss_kologarnAI(Creature* creature) : BossAI(creature, BOSS_KOLOGARN),
left(false), right(false)
{
ASSERT(vehicle);
me->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE);
@@ -113,7 +111,6 @@ class boss_kologarn : public CreatureScript
Reset();
}
Vehicle* vehicle;
bool left, right;
ObjectGuid eyebeamTarget;
@@ -128,9 +125,10 @@ class boss_kologarn : public CreatureScript
events.ScheduleEvent(EVENT_FOCUSED_EYEBEAM, 21000);
events.ScheduleEvent(EVENT_ENRAGE, 600000);
for (uint8 i = 0; i < 2; ++i)
if (Unit* arm = vehicle->GetPassenger(i))
arm->ToCreature()->SetInCombatWithZone();
if (Vehicle* vehicle = me->GetVehicleKit())
for (uint8 i = 0; i < 2; ++i)
if (Unit* arm = vehicle->GetPassenger(i))
arm->ToCreature()->SetInCombatWithZone();
_EnterCombat();
}
@@ -283,7 +281,7 @@ class boss_kologarn : public CreatureScript
case EVENT_RESPAWN_LEFT_ARM:
case EVENT_RESPAWN_RIGHT_ARM:
{
if (vehicle)
if (Vehicle* vehicle = me->GetVehicleKit())
{
int8 seat = eventId == EVENT_RESPAWN_LEFT_ARM ? 0 : 1;
uint32 entry = eventId == EVENT_RESPAWN_LEFT_ARM ? NPC_LEFT_ARM : NPC_RIGHT_ARM;
@@ -401,20 +401,21 @@ class StartAttackEvent : public BasicEvent
{
public:
StartAttackEvent(Creature* summoner, Creature* owner)
: _summoner(summoner), _owner(owner)
: _summonerGuid(summoner->GetGUID()), _owner(owner)
{
}
bool Execute(uint64 /*time*/, uint32 /*diff*/)
{
_owner->SetReactState(REACT_AGGRESSIVE);
if (Unit* target = _summoner->AI()->SelectTarget(SELECT_TARGET_RANDOM, 0, 300.0f))
_owner->AI()->AttackStart(target);
if (Creature* _summoner = ObjectAccessor::GetCreature(*_owner, _summonerGuid))
if (Unit* target = _summoner->AI()->SelectTarget(SELECT_TARGET_RANDOM, 0, 300.0f))
_owner->AI()->AttackStart(target);
return true;
}
private:
Creature* _summoner;
ObjectGuid _summonerGuid;
Creature* _owner;
};
@@ -381,7 +381,7 @@ class npc_hyldsmeet_protodrake : public CreatureScript
class npc_hyldsmeet_protodrakeAI : public CreatureAI
{
public:
npc_hyldsmeet_protodrakeAI(Creature* creature) : CreatureAI(creature), _accessoryRespawnTimer(0), _vehicleKit(creature->GetVehicleKit()) { }
npc_hyldsmeet_protodrakeAI(Creature* creature) : CreatureAI(creature), _accessoryRespawnTimer(0) { }
void PassengerBoarded(Unit* who, int8 /*seat*/, bool apply) override
{
@@ -396,6 +396,7 @@ class npc_hyldsmeet_protodrake : public CreatureScript
{
//! We need to manually reinstall accessories because the vehicle itself is friendly to players,
//! so EnterEvadeMode is never triggered. The accessory on the other hand is hostile and killable.
Vehicle* _vehicleKit = me->GetVehicleKit();
if (_accessoryRespawnTimer && _accessoryRespawnTimer <= diff && _vehicleKit)
{
_vehicleKit->InstallAllAccessories(true);
@@ -407,7 +408,6 @@ class npc_hyldsmeet_protodrake : public CreatureScript
private:
uint32 _accessoryRespawnTimer;
Vehicle* _vehicleKit;
};
CreatureAI* GetAI(Creature* creature) const override