Skip to content

Commit 86d2602

Browse files
author
NoFantasy
committed
[1776] Clean up some needless casts and in addition make more safe code using dynamic_cast when trying to access local functions/variables in other classes/structs
Clean up some needless casts and in addition make more safe code using dynamic_cast when trying to access local functions/variables in other classes/structs git-svn-id: https://scriptdev2.svn.sourceforge.net/svnroot/scriptdev2@1776 5f9c896b-1e26-0410-94da-f77f675e2462
1 parent 530482b commit 86d2602

50 files changed

Lines changed: 403 additions & 233 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/eastern_kingdoms/blackrock_depths/boss_ambassador_flamelash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct MANGOS_DLL_DECL boss_ambassador_flamelashAI : public ScriptedAI
5959
}
6060
Summoned = DoSpawnCreature(9178, RandX, RandY, 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 60000);
6161
if (Summoned)
62-
((CreatureAI*)Summoned->AI())->AttackStart(victim);
62+
Summoned->AI()->AttackStart(victim);
6363
}
6464

6565
void UpdateAI(const uint32 diff)

scripts/eastern_kingdoms/blackrock_depths/boss_general_angerforge.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct MANGOS_DLL_DECL boss_general_angerforgeAI : public ScriptedAI
7272
Rand1 = 0;
7373
SummonedAdds = DoSpawnCreature(8901, Rand1X, Rand1Y, 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000);
7474
if (SummonedAdds)
75-
((CreatureAI*)SummonedAdds->AI())->AttackStart(victim);
75+
SummonedAdds->AI()->AttackStart(victim);
7676
}
7777

7878
void SummonMedics(Unit* victim)
@@ -93,7 +93,7 @@ struct MANGOS_DLL_DECL boss_general_angerforgeAI : public ScriptedAI
9393
Rand2 = 0;
9494
SummonedMedics = DoSpawnCreature(8894, Rand2X, Rand2Y, 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 120000);
9595
if (SummonedMedics)
96-
((CreatureAI*)SummonedMedics->AI())->AttackStart(victim);
96+
SummonedMedics->AI()->AttackStart(victim);
9797
}
9898

9999
void UpdateAI(const uint32 diff)

scripts/eastern_kingdoms/blackwing_lair/boss_victor_nefarius.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ bool GossipSelect_boss_victor_nefarius(Player* pPlayer, Creature* pCreature, uin
367367
case GOSSIP_ACTION_INFO_DEF+3:
368368
pPlayer->CLOSE_GOSSIP_MENU();
369369
DoScriptText(SAY_GAMESBEGIN_1, pCreature);
370-
((boss_victor_nefariusAI*)pCreature->AI())->BeginEvent(pPlayer);
370+
if (boss_victor_nefariusAI* pNefAI = dynamic_cast<boss_victor_nefariusAI*>(pCreature->AI()))
371+
pNefAI->BeginEvent(pPlayer);
371372
break;
372373
}
373374
return true;

scripts/eastern_kingdoms/boss_kruul.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct MANGOS_DLL_DECL boss_kruulAI : public ScriptedAI
8383
Rand = 0;
8484
Summoned = DoSpawnCreature(19207, RandX, RandY, 0, 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 300000);
8585
if (Summoned)
86-
((CreatureAI*)Summoned->AI())->AttackStart(victim);
86+
Summoned->AI()->AttackStart(victim);
8787
}
8888

8989
void UpdateAI(const uint32 diff)

scripts/eastern_kingdoms/karazhan/boss_midnight.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,11 @@ struct MANGOS_DLL_DECL boss_attumenAI : public ScriptedAI
307307
{
308308
if (m_creature->GetHealthPercent() < 25.0f)
309309
{
310-
Creature *pMidnight = m_creature->GetMap()->GetCreature(m_uiMidnightGUID);
311-
312-
if (pMidnight)
310+
if (Creature *pMidnight = m_creature->GetMap()->GetCreature(m_uiMidnightGUID))
313311
{
314-
((boss_midnightAI*)(pMidnight->AI()))->Mount(m_creature);
312+
if (boss_midnightAI* pMidnightAI = dynamic_cast<boss_midnightAI*>(pMidnight->AI()))
313+
pMidnightAI->Mount(m_creature);
314+
315315
m_creature->SetHealth(pMidnight->GetHealth());
316316
DoResetThreat();
317317
}
@@ -324,7 +324,8 @@ struct MANGOS_DLL_DECL boss_attumenAI : public ScriptedAI
324324

325325
void boss_midnightAI::SetMidnight(Creature* pAttumen, uint64 uiValue)
326326
{
327-
((boss_attumenAI*)pAttumen->AI())->m_uiMidnightGUID = uiValue;
327+
if (boss_attumenAI* pAttumenAI = dynamic_cast<boss_attumenAI*>(pAttumen->AI()))
328+
pAttumenAI->m_uiMidnightGUID = uiValue;
328329
}
329330

330331
CreatureAI* GetAI_boss_attumen(Creature* pCreature)

scripts/eastern_kingdoms/karazhan/boss_moroes.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,11 @@ struct MANGOS_DLL_DECL boss_moroes_guestAI : public ScriptedAI
355355
{
356356
for(uint8 i = 0; i < 3; ++i)
357357
{
358-
uint64 uiGUID = ((boss_moroesAI*)pMoroes->AI())->m_auiAddGUID[i];
358+
uint64 uiGUID = 0;
359+
360+
if (boss_moroesAI* pMoroesAI = dynamic_cast<boss_moroesAI*>(pMoroes->AI()))
361+
uiGUID = pMoroesAI->m_auiAddGUID[i];
362+
359363
if (uiGUID && uiGUID != m_creature->GetGUID())
360364
m_auiGuestGUID[i+1] = uiGUID;
361365
}

scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,16 @@ struct MANGOS_DLL_DECL boss_malchezaarAI : public ScriptedAI
357357
{
358358
Infernal->SetDisplayId(INFERNAL_MODEL_INVISIBLE);
359359
Infernal->setFaction(m_creature->getFaction());
360-
if (point)
361-
((netherspite_infernalAI*)Infernal->AI())->point=point;
362-
((netherspite_infernalAI*)Infernal->AI())->malchezaar=m_creature->GetGUID();
360+
361+
netherspite_infernalAI* pInfernalAI = dynamic_cast<netherspite_infernalAI*>(Infernal->AI());
362+
363+
if (pInfernalAI)
364+
{
365+
if (point)
366+
pInfernalAI->point = point;
367+
368+
pInfernalAI->malchezaar = m_creature->GetGUID();
369+
}
363370

364371
infernals.push_back(Infernal->GetGUID());
365372
DoCastSpellIfCan(Infernal, SPELL_INFERNAL_RELAY);
@@ -597,10 +604,13 @@ struct MANGOS_DLL_DECL boss_malchezaarAI : public ScriptedAI
597604

598605
void netherspite_infernalAI::Cleanup()
599606
{
600-
Creature *pMalchezaar = m_creature->GetMap()->GetCreature(malchezaar);
607+
Creature* pMalchezaar = m_creature->GetMap()->GetCreature(malchezaar);
601608

602609
if (pMalchezaar && pMalchezaar->isAlive())
603-
((boss_malchezaarAI*)pMalchezaar->AI())->Cleanup(m_creature, point);
610+
{
611+
if (boss_malchezaarAI* pMalAI = dynamic_cast<boss_malchezaarAI*>(pMalchezaar->AI()))
612+
pMalAI->Cleanup(m_creature, point);
613+
}
604614
}
605615

606616
CreatureAI* GetAI_netherspite_infernal(Creature* pCreature)

scripts/eastern_kingdoms/karazhan/boss_terestian_illhoof.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct MANGOS_DLL_DECL boss_terestianAI : public ScriptedAI
172172
{
173173
m_uiPortalGUID[1] = pSummoned->GetGUID();
174174

175-
if (npc_fiendish_portalAI* pPortalAI = (npc_fiendish_portalAI*)pSummoned->AI())
175+
if (npc_fiendish_portalAI* pPortalAI = dynamic_cast<npc_fiendish_portalAI*>(pSummoned->AI()))
176176
pPortalAI->m_uiSummonTimer = 10000;
177177
}
178178
else
@@ -245,10 +245,11 @@ struct MANGOS_DLL_DECL boss_terestianAI : public ScriptedAI
245245
{
246246
DoCastSpellIfCan(pTarget, SPELL_SACRIFICE, CAST_TRIGGERED);
247247

248-
Creature* pChains = m_creature->SummonCreature(NPC_DEMONCHAINS, pTarget->GetPositionX(), pTarget->GetPositionY(), pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 21000);
249-
if (pChains)
248+
if (Creature* pChains = m_creature->SummonCreature(NPC_DEMONCHAINS, pTarget->GetPositionX(), pTarget->GetPositionY(), pTarget->GetPositionZ(), 0, TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN, 21000))
250249
{
251-
((mob_demon_chainAI*)pChains->AI())->m_uiSacrificeGUID = pTarget->GetGUID();
250+
if (mob_demon_chainAI* pDemonAI = dynamic_cast<mob_demon_chainAI*>(pChains->AI()))
251+
pDemonAI->m_uiSacrificeGUID = pTarget->GetGUID();
252+
252253
pChains->CastSpell(pChains, SPELL_DEMON_CHAINS, true);
253254

254255
DoScriptText(urand(0, 1) ? SAY_SACRIFICE1 : SAY_SACRIFICE2, m_creature);

scripts/eastern_kingdoms/karazhan/bosses_opera.cpp

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ struct MANGOS_DLL_DECL mob_titoAI : public ScriptedAI
229229
Creature* Dorothee = m_creature->GetMap()->GetCreature(DorotheeGUID);
230230
if (Dorothee && Dorothee->isAlive())
231231
{
232-
((boss_dorotheeAI*)Dorothee->AI())->TitoDied = true;
232+
if (boss_dorotheeAI* pDoroAI = dynamic_cast<boss_dorotheeAI*>(Dorothee->AI()))
233+
pDoroAI->TitoDied = true;
234+
233235
DoScriptText(SAY_DOROTHEE_TITO_DEATH, Dorothee);
234236
}
235237
}
@@ -256,7 +258,9 @@ void boss_dorotheeAI::SummonTito()
256258
{
257259
DoScriptText(SAY_DOROTHEE_SUMMON, m_creature);
258260

259-
((mob_titoAI*)pTito->AI())->DorotheeGUID = m_creature->GetGUID();
261+
if (mob_titoAI* pTitoAI = dynamic_cast<mob_titoAI*>(pTito->AI()))
262+
pTitoAI->DorotheeGUID = m_creature->GetGUID();
263+
260264
pTito->AI()->AttackStart(m_creature->getVictim());
261265

262266
SummonedTito = true;
@@ -1172,8 +1176,13 @@ void boss_julianneAI::DamageTaken(Unit* done_by, uint32 &damage)
11721176
{
11731177
PretendToDie(m_creature);
11741178
IsFakingDeath = true;
1175-
((boss_romuloAI*)Romulo->AI())->ResurrectTimer = 10000;
1176-
((boss_romuloAI*)Romulo->AI())->JulianneDead = true;
1179+
1180+
if (boss_romuloAI* pRomAI = dynamic_cast<boss_romuloAI*>(Romulo->AI()))
1181+
{
1182+
pRomAI->ResurrectTimer = 10000;
1183+
pRomAI->JulianneDead = true;
1184+
}
1185+
11771186
damage = 0;
11781187
return;
11791188
}
@@ -1198,8 +1207,11 @@ void boss_romuloAI::DamageTaken(Unit* done_by, uint32 &damage)
11981207

11991208
if (Creature* Julianne = m_creature->GetMap()->GetCreature(JulianneGUID))
12001209
{
1201-
((boss_julianneAI*)Julianne->AI())->RomuloDead = true;
1202-
((boss_julianneAI*)Julianne->AI())->ResurrectSelfTimer = 10000;
1210+
if (boss_julianneAI* pJulAI = dynamic_cast<boss_julianneAI*>(Julianne->AI()))
1211+
{
1212+
pJulAI->ResurrectSelfTimer = 10000;
1213+
pJulAI->RomuloDead = true;
1214+
}
12031215
}
12041216

12051217
damage = 0;
@@ -1226,8 +1238,13 @@ void boss_romuloAI::DamageTaken(Unit* done_by, uint32 &damage)
12261238
{
12271239
PretendToDie(m_creature);
12281240
IsFakingDeath = true;
1229-
((boss_julianneAI*)Julianne->AI())->ResurrectTimer = 10000;
1230-
((boss_julianneAI*)Julianne->AI())->RomuloDead = true;
1241+
1242+
if (boss_julianneAI* pJulAI = dynamic_cast<boss_julianneAI*>(Julianne->AI()))
1243+
{
1244+
pJulAI->ResurrectTimer = 10000;
1245+
pJulAI->RomuloDead = true;
1246+
}
1247+
12311248
damage = 0;
12321249
return;
12331250
}
@@ -1277,8 +1294,13 @@ void boss_julianneAI::UpdateAI(const uint32 diff)
12771294
if (Creature* pRomulo = m_creature->SummonCreature(CREATURE_ROMULO, ROMULO_X, ROMULO_Y, m_creature->GetPositionZ(), 0, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, HOUR*2*IN_MILLISECONDS))
12781295
{
12791296
RomuloGUID = pRomulo->GetGUID();
1280-
((boss_romuloAI*)pRomulo->AI())->JulianneGUID = m_creature->GetGUID();
1281-
((boss_romuloAI*)pRomulo->AI())->Phase = PHASE_ROMULO;
1297+
1298+
if (boss_romuloAI* pRomAI = dynamic_cast<boss_romuloAI*>(pRomulo->AI()))
1299+
{
1300+
pRomAI->JulianneGUID = m_creature->GetGUID();
1301+
pRomAI->Phase = PHASE_ROMULO;
1302+
}
1303+
12821304
pRomulo->SetInCombatWithZone();
12831305

12841306
//why?
@@ -1311,12 +1333,16 @@ void boss_julianneAI::UpdateAI(const uint32 diff)
13111333
{
13121334
if (ResurrectTimer < diff)
13131335
{
1314-
Creature* Romulo = m_creature->GetMap()->GetCreature(RomuloGUID);
1315-
if (Romulo && ((boss_romuloAI*)Romulo->AI())->IsFakingDeath)
1336+
Creature* pRomulo = m_creature->GetMap()->GetCreature(RomuloGUID);
1337+
boss_romuloAI* pRomAI = dynamic_cast<boss_romuloAI*>(pRomulo->AI());
1338+
1339+
if (pRomulo && pRomAI && pRomAI->IsFakingDeath)
13161340
{
13171341
DoScriptText(SAY_JULIANNE_RESURRECT, m_creature);
1318-
Resurrect(Romulo);
1319-
((boss_romuloAI*)Romulo->AI())->IsFakingDeath = false;
1342+
Resurrect(pRomulo);
1343+
1344+
pRomAI->IsFakingDeath = false;
1345+
13201346
RomuloDead = false;
13211347
ResurrectTimer = 10000;
13221348
}
@@ -1369,12 +1395,16 @@ void boss_romuloAI::UpdateAI(const uint32 diff)
13691395
{
13701396
if (ResurrectTimer < diff)
13711397
{
1372-
Creature* Julianne = m_creature->GetMap()->GetCreature(JulianneGUID);
1373-
if (Julianne && ((boss_julianneAI*)Julianne->AI())->IsFakingDeath)
1398+
Creature* pJulianne = m_creature->GetMap()->GetCreature(JulianneGUID);
1399+
boss_julianneAI* pJulAI = dynamic_cast<boss_julianneAI*>(pJulianne->AI());
1400+
1401+
if (pJulianne && pJulAI && pJulAI->IsFakingDeath)
13741402
{
13751403
DoScriptText(SAY_ROMULO_RESURRECT, m_creature);
1376-
Resurrect(Julianne);
1377-
((boss_julianneAI*)Julianne->AI())->IsFakingDeath = false;
1404+
Resurrect(pJulianne);
1405+
1406+
pJulAI->IsFakingDeath = false;
1407+
13781408
JulianneDead = false;
13791409
ResurrectTimer = 10000;
13801410
}

scripts/eastern_kingdoms/magisters_terrace/boss_priestess_delrissa.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,13 @@ struct MANGOS_DLL_DECL boss_priestess_lackey_commonAI : public ScriptedAI
448448

449449
if (Creature* pDelrissa = m_creature->GetMap()->GetCreature(m_pInstance->GetData64(DATA_DELRISSA)))
450450
{
451+
boss_priestess_delrissaAI* pDelrissaAI = dynamic_cast<boss_priestess_delrissaAI*>(pDelrissa->AI());
452+
453+
if (!pDelrissaAI)
454+
return;
455+
451456
for(uint8 i = 0; i < MAX_ACTIVE_LACKEY; ++i)
452-
m_auiLackeyGUIDs[i] = ((boss_priestess_delrissaAI*)pDelrissa->AI())->m_auiLackeyGUID[i];
457+
m_auiLackeyGUIDs[i] = pDelrissaAI->m_auiLackeyGUID[i];
453458
}
454459
}
455460

0 commit comments

Comments
 (0)