aboutsummaryrefslogtreecommitdiff
path: root/src/scripts/kalimdor
diff options
context:
space:
mode:
authorAnubisss <none@none>2010-03-27 13:54:38 +0100
committerAnubisss <none@none>2010-03-27 13:54:38 +0100
commitbe739e99009c2796d0153e7b3dabcf819e915541 (patch)
tree22017cf657485b228e93b0dc496d25a5246bd83d /src/scripts/kalimdor
parent099ef2a9b6e2e1c4986878c15ce5758edba5a71c (diff)
Use GUIDs instead of "global" pointers in ~all boss/instance scripts.
GUIDs are most safer than pointers and in some cases can avoid segmentation faults. == - == Let me show a simple example: We have a pointer to a creature: Creature *pCreature; and try to search a creature and store it in the pointer: pCreature = SearchCreature(ID); We can check simply if the creature found or not: if(pCreature) - if this give true: creature found and we have a memory address which points to the creature - if this give false: creature not found and this is a NULL pointer Suppose that we have a valid pointer, so creature found. We wanna use that pointer somewhere, for example in script phase 3. But we delete the creature(from world) in phase 1. In phase 3: if(pCreature) pCreature->DoSomeShit(); The if condition gives true, but pCreature points to an _invalid_ address. In that address maybe have "nothing" or another creature's object or a player or anything else, dont know that. ~~ - ~~ Let me show the correct way: Creature's GUID: uint64 CreatureGUID; search the creature and set the GUID: Creature *pCreature = SearchCreature(ID); CreatureGUID = pCreature ? pCreature->GetGUID() : 0; // if pCreature is NULL set the GUID to 0 So we have a GUID and not a pointer. We can get the creature from that GUID: Creature *pCreature = GetCreature(CreatureGUID); and we can simply check it is valid or not(found or not): if(pCreature) So we deleted the creature in phase 1 and try to use it in phase 3: Creature *pCreature = GetCreature(CreatureGUID); And this gives NULL because GetCreature() can't find the creature which GUID is CreatureGUID. if(pCreature) // pCreature is NULL pCreature->DoSomeShit(); // DoSomeShit() not called == - == Remove some not used variables. Some clean. TODO: Should search/fix these in zones scripts. --HG-- branch : trunk
Diffstat (limited to 'src/scripts/kalimdor')
-rw-r--r--src/scripts/kalimdor/ruins_of_ahnqiraj/boss_ayamiss.cpp4
-rw-r--r--src/scripts/kalimdor/temple_of_ahnqiraj/boss_skeram.cpp6
-rw-r--r--src/scripts/kalimdor/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp53
3 files changed, 33 insertions, 30 deletions
diff --git a/src/scripts/kalimdor/ruins_of_ahnqiraj/boss_ayamiss.cpp b/src/scripts/kalimdor/ruins_of_ahnqiraj/boss_ayamiss.cpp
index f0ce0d41472..9dc3b4f0e0c 100644
--- a/src/scripts/kalimdor/ruins_of_ahnqiraj/boss_ayamiss.cpp
+++ b/src/scripts/kalimdor/ruins_of_ahnqiraj/boss_ayamiss.cpp
@@ -44,7 +44,6 @@ struct boss_ayamissAI : public ScriptedAI
pInstance = c->GetInstanceData();
}
- Unit *pTarget;
uint32 STINGERSPRAY_Timer;
uint32 POISONSTINGER_Timer;
uint32 SUMMONSWARMER_Timer;
@@ -54,7 +53,6 @@ struct boss_ayamissAI : public ScriptedAI
void Reset()
{
- pTarget = NULL;
STINGERSPRAY_Timer = 30000;
POISONSTINGER_Timer = 30000;
SUMMONSWARMER_Timer = 60000;
@@ -66,8 +64,6 @@ struct boss_ayamissAI : public ScriptedAI
void EnterCombat(Unit *who)
{
- pTarget = who;
-
if (pInstance)
pInstance->SetData(DATA_AYAMISS_EVENT, IN_PROGRESS);
}
diff --git a/src/scripts/kalimdor/temple_of_ahnqiraj/boss_skeram.cpp b/src/scripts/kalimdor/temple_of_ahnqiraj/boss_skeram.cpp
index 11980a94b68..c772cfd0a33 100644
--- a/src/scripts/kalimdor/temple_of_ahnqiraj/boss_skeram.cpp
+++ b/src/scripts/kalimdor/temple_of_ahnqiraj/boss_skeram.cpp
@@ -62,8 +62,6 @@ struct boss_skeramAI : public ScriptedAI
uint32 Blink_Timer;
uint32 Invisible_Timer;
- Creature *Image1, *Image2;
-
bool Images75;
bool Images50;
bool Images25;
@@ -260,7 +258,7 @@ struct boss_skeramAI : public ScriptedAI
Unit *pTarget = SelectUnit(SELECT_TARGET_RANDOM,0);
- Image1 = m_creature->SummonCreature(15263, i1->x, i1->y, i1->z, i1->r, TEMPSUMMON_CORPSE_DESPAWN, 30000);
+ Creature *Image1 = m_creature->SummonCreature(15263, i1->x, i1->y, i1->z, i1->r, TEMPSUMMON_CORPSE_DESPAWN, 30000);
if (Image1)
{
Image1->SetMaxHealth(m_creature->GetMaxHealth() / 5);
@@ -270,7 +268,7 @@ struct boss_skeramAI : public ScriptedAI
CAST_AI(boss_skeramAI, Image1->AI())->IsImage = true;
}
- Image2 = m_creature->SummonCreature(15263,i2->x, i2->y, i2->z, i2->r, TEMPSUMMON_CORPSE_DESPAWN, 30000);
+ Creature *Image2 = m_creature->SummonCreature(15263,i2->x, i2->y, i2->z, i2->r, TEMPSUMMON_CORPSE_DESPAWN, 30000);
if (Image2)
{
Image2->SetMaxHealth(m_creature->GetMaxHealth() / 5);
diff --git a/src/scripts/kalimdor/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp b/src/scripts/kalimdor/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp
index 7cdb76a82e1..24e9c68d435 100644
--- a/src/scripts/kalimdor/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp
+++ b/src/scripts/kalimdor/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp
@@ -80,24 +80,25 @@ struct aqsentinelAI : public ScriptedAI
abselected = 0; // just initialization of variable
}
- Creature *nearby[3];
+ uint64 NearbyGUID[3];
void ClearBuddyList()
{
- nearby[0] = nearby[1] = nearby[2] = NULL;
+ NearbyGUID[0] = NearbyGUID[1] = NearbyGUID[2] = 0;
}
- void AddBuddyToList(Creature *c)
+ void AddBuddyToList(uint64 CreatureGUID)
{
- if (c==m_creature)
+ if (CreatureGUID == m_creature->GetGUID())
return;
+
for (int i=0; i<3; ++i)
{
- if (nearby[i] == c)
+ if (NearbyGUID[i] == CreatureGUID)
return;
- if (!nearby[i])
+ if (!NearbyGUID[i])
{
- nearby[i] = c;
+ NearbyGUID[i] = CreatureGUID;
return;
}
}
@@ -107,23 +108,23 @@ struct aqsentinelAI : public ScriptedAI
{
aqsentinelAI *cai = CAST_AI(aqsentinelAI, (c)->AI());
for (int i=0; i<3; ++i)
- if (nearby[i] && nearby[i]!=c)
- cai->AddBuddyToList(nearby[i]);
- cai->AddBuddyToList(m_creature);
+ if (NearbyGUID[i] && NearbyGUID[i] != c->GetGUID())
+ cai->AddBuddyToList(NearbyGUID[i]);
+ cai->AddBuddyToList(m_creature->GetGUID());
}
void SendMyListToBuddies()
{
for (int i=0; i<3; ++i)
- if (nearby[i])
- GiveBuddyMyList(nearby[i]);
+ if (Creature *pNearby = Unit::GetCreature(*m_creature, NearbyGUID[i]))
+ GiveBuddyMyList(pNearby);
}
void CallBuddiesToAttack(Unit *who)
{
for (int i=0; i<3; ++i)
{
- Creature *c = nearby[i];
+ Creature *c = Unit::GetCreature(*m_creature, NearbyGUID[i]);
if (c)
{
if (!c->isInCombat())
@@ -145,7 +146,7 @@ struct aqsentinelAI : public ScriptedAI
return;
for (std::list<Creature*>::iterator iter = assistList.begin(); iter != assistList.end(); ++iter)
- AddBuddyToList((*iter));
+ AddBuddyToList((*iter)->GetGUID());
}
int pickAbilityRandom(bool *chosenAbilities)
@@ -175,11 +176,16 @@ struct aqsentinelAI : public ScriptedAI
int bli;
for (bli = 0; bli < 3; ++bli)
{
- if (!nearby[bli])
+ if (!NearbyGUID[bli])
+ break;
+
+ Creature *pNearby = Unit::GetCreature(*m_creature, NearbyGUID[bli]);
+ if(!pNearby)
break;
- AddSentinelsNear(nearby[bli]);
- CAST_AI(aqsentinelAI, nearby[bli]->AI())->gatherOthersWhenAggro = false;
- CAST_AI(aqsentinelAI, nearby[bli]->AI())->selectAbility(pickAbilityRandom(chosenAbilities));
+
+ AddSentinelsNear(pNearby);
+ CAST_AI(aqsentinelAI, pNearby->AI())->gatherOthersWhenAggro = false;
+ CAST_AI(aqsentinelAI, pNearby->AI())->selectAbility(pickAbilityRandom(chosenAbilities));
}
/*if (bli < 3)
DoYell("I dont have enough buddies.", LANG_NEUTRAL, 0);*/
@@ -197,10 +203,13 @@ struct aqsentinelAI : public ScriptedAI
{
for (int i=0; i<3; ++i)
{
- if (!nearby[i])
+ if (!NearbyGUID[i])
continue;
- if (nearby[i]->isDead())
- nearby[i]->Respawn();
+ if (Creature *pNearby = Unit::GetCreature(*m_creature, NearbyGUID[i]))
+ {
+ if (pNearby->isDead())
+ pNearby->Respawn();
+ }
}
}
ClearBuddyList();
@@ -225,7 +234,7 @@ struct aqsentinelAI : public ScriptedAI
{
for (int ni=0; ni<3; ++ni)
{
- Creature *sent = nearby[ni];
+ Creature *sent = Unit::GetCreature(*m_creature, NearbyGUID[ni]);
if (!sent)
continue;
if (sent->isDead())