aboutsummaryrefslogtreecommitdiff
path: root/src/bindings/scripts
diff options
context:
space:
mode:
authormaximius <none@none>2009-11-01 17:53:07 -0800
committermaximius <none@none>2009-11-01 17:53:07 -0800
commitb257a28fa9a9177df32845db8171d376bd6d4404 (patch)
treed1093029c66fc36a705aa0f344ba3a4fb77e36d5 /src/bindings/scripts
parent2b2b2a1d0ec0e8942b27047f6706f29775a00eb8 (diff)
*Cleanup, fix many cases of unoptimized loops, potential crashes, excessively large data types, unnecessary or wrong casts, non-standardized function calls, and so on..
*Proper Maexxna Web Spray locations (old locations sent players flying into the air) --HG-- branch : trunk
Diffstat (limited to 'src/bindings/scripts')
-rw-r--r--src/bindings/scripts/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp66
-rw-r--r--src/bindings/scripts/scripts/northrend/azjol_nerub/ahnkahet/boss_amanitar.cpp18
-rw-r--r--src/bindings/scripts/scripts/northrend/naxxramas/boss_maexxna.cpp14
-rw-r--r--src/bindings/scripts/scripts/world/npc_professions.cpp8
4 files changed, 49 insertions, 57 deletions
diff --git a/src/bindings/scripts/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp b/src/bindings/scripts/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp
index 3e61cd8ec20..892a7765cd1 100644
--- a/src/bindings/scripts/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp
+++ b/src/bindings/scripts/scripts/eastern_kingdoms/karazhan/boss_prince_malchezaar.cpp
@@ -188,7 +188,7 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
InfernalCleanup();
positions.clear();
- for (uint8 i =0; i < 5; ++i)
+ for (uint8 i = 0; i < 5; ++i)
enfeeble_targets[i] = 0;
for (uint8 i = 0; i < TOTAL_INFERNAL_POINTS; ++i)
@@ -202,8 +202,8 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
Cleave_Timer = 8000;
InfernalTimer = 45000;
InfernalCleanupTimer = 47000;
- AxesTargetSwitchTimer = 7500 + rand()%12500;
- SunderArmorTimer = 5000 + rand()%5000;
+ AxesTargetSwitchTimer = urand(7500,20000);
+ SunderArmorTimer = urand(5000,10000);
phase = 1;
if (pInstance)
@@ -242,21 +242,20 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
void InfernalCleanup()
{
//Infernal Cleanup
- for (std::vector<uint64>::iterator itr = infernals.begin(); itr!= infernals.end(); ++itr)
- {
- Unit *pInfernal = Unit::GetUnit(*m_creature, *itr);
- if (pInfernal && pInfernal->isAlive())
- {
- pInfernal->SetVisibility(VISIBILITY_OFF);
- pInfernal->setDeathState(JUST_DIED);
- }
- }
+ for (std::vector<uint64>::iterator itr = infernals.begin(); itr != infernals.end(); ++itr)
+ if (Unit *pInfernal = Unit::GetUnit(*m_creature, *itr))
+ if (pInfernal->isAlive())
+ {
+ pInfernal->SetVisibility(VISIBILITY_OFF);
+ pInfernal->setDeathState(JUST_DIED);
+ }
+
infernals.clear();
}
void AxesCleanup()
{
- for (uint8 i=0; i<2; ++i)
+ for (uint8 i = 0; i < 2; ++i)
{
Unit *axe = Unit::GetUnit(*m_creature, axes[i]);
if (axe && axe->isAlive())
@@ -291,23 +290,18 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
//begin + 1, so we don't target the one with the highest threat
std::list<HostilReference *>::iterator itr = t_list.begin();
std::advance(itr, 1);
- for (; itr!= t_list.end(); ++itr) //store the threat list in a different container
- {
- Unit *pTarget = Unit::GetUnit(*m_creature, (*itr)->getUnitGuid());
- //only on alive players
- if (pTarget && pTarget->isAlive() && pTarget->GetTypeId() == TYPEID_PLAYER)
- targets.push_back(pTarget);
- }
+ for (; itr != t_list.end(); ++itr) //store the threat list in a different container
+ if (Unit *pTarget = Unit::GetUnit(*m_creature, (*itr)->getUnitGuid()))
+ if (pTarget->isAlive() && pTarget->GetTypeId() == TYPEID_PLAYER)
+ targets.push_back(pTarget);
//cut down to size if we have more than 5 targets
- while(targets.size() > 5)
+ while (targets.size() > 5)
targets.erase(targets.begin()+rand()%targets.size());
- int i = 0;
- for (std::vector<Unit *>::iterator iter = targets.begin(); iter!= targets.end(); ++iter, ++i)
- {
- Unit *pTarget = *iter;
- if (pTarget)
+ uint32 i = 0;
+ for (std::vector<Unit *>::iterator iter = targets.begin(); iter != targets.end(); ++iter, ++i)
+ if (Unit *pTarget = *iter)
{
enfeeble_targets[i] = pTarget->GetGUID();
enfeeble_health[i] = pTarget->GetHealth();
@@ -315,8 +309,6 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
pTarget->CastSpell(pTarget, SPELL_ENFEEBLE, true, 0, 0, m_creature->GetGUID());
pTarget->SetHealth(1);
}
- }
-
}
void EnfeebleResetHealth()
@@ -367,17 +359,16 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
if (!UpdateVictim())
return;
- if (EnfeebleResetTimer)
- if (EnfeebleResetTimer <= diff) //Let's not forget to reset that
+ if (EnfeebleResetTimer && EnfeebleResetTimer <= diff) // Let's not forget to reset that
{
EnfeebleResetHealth();
- EnfeebleResetTimer=0;
+ EnfeebleResetTimer = 0;
} else EnfeebleResetTimer -= diff;
- if (m_creature->hasUnitState(UNIT_STAT_STUNNED)) //While shifting to phase 2 malchezaar stuns himself
+ if (m_creature->hasUnitState(UNIT_STAT_STUNNED)) // While shifting to phase 2 malchezaar stuns himself
return;
- if (m_creature->GetUInt64Value(UNIT_FIELD_TARGET)!=m_creature->getVictim()->GetGUID())
+ if (m_creature->GetUInt64Value(UNIT_FIELD_TARGET) != m_creature->getVictim()->GetGUID())
m_creature->SetUInt64Value(UNIT_FIELD_TARGET, m_creature->getVictim()->GetGUID());
if (phase == 1)
@@ -481,11 +472,10 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
{
if (Unit *axe = Unit::GetUnit(*m_creature, axes[i]))
{
- float threat = 1000000.0f;
if (axe->getVictim())
DoModifyThreatPercent(axe->getVictim(), -100);
if (pTarget)
- axe->AddThreat(pTarget, threat);
+ axe->AddThreat(pTarget, 1000000.0f);
//axe->getThreatManager().tauntFadeOut(axe->getVictim());
//axe->getThreatManager().tauntApply(pTarget);
}
@@ -505,13 +495,13 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
if (InfernalTimer <= diff)
{
SummonInfernal(diff);
- InfernalTimer = phase == 3 ? 14500 : 44500; //15 secs in phase 3, 45 otherwise
+ InfernalTimer = phase == 3 ? 14500 : 44500; // 15 secs in phase 3, 45 otherwise
} else InfernalTimer -= diff;
if (ShadowNovaTimer <= diff)
{
DoCast(m_creature->getVictim(), SPELL_SHADOWNOVA);
- ShadowNovaTimer = phase == 3 ? 31000 : 4294967295;
+ ShadowNovaTimer = phase == 3 ? 31000 : uint32(-1);
} else ShadowNovaTimer -= diff;
if (phase != 2)
@@ -521,7 +511,7 @@ struct TRINITY_DLL_DECL boss_malchezaarAI : public ScriptedAI
Unit *pTarget = NULL;
if (phase == 1)
pTarget = m_creature->getVictim(); // the tank
- else // anyone but the tank
+ else // anyone but the tank
pTarget = SelectTarget(SELECT_TARGET_RANDOM, 1, 100, true);
if (pTarget)
diff --git a/src/bindings/scripts/scripts/northrend/azjol_nerub/ahnkahet/boss_amanitar.cpp b/src/bindings/scripts/scripts/northrend/azjol_nerub/ahnkahet/boss_amanitar.cpp
index bbdc55321b8..58115b7e0fc 100644
--- a/src/bindings/scripts/scripts/northrend/azjol_nerub/ahnkahet/boss_amanitar.cpp
+++ b/src/bindings/scripts/scripts/northrend/azjol_nerub/ahnkahet/boss_amanitar.cpp
@@ -125,7 +125,8 @@ struct MANGOS_DLL_DECL boss_amanitarAI : public ScriptedAI
void UpdateAI(const uint32 diff)
{
//Return since we have no target
- if (!UpdateVictim()) return;
+ if (!UpdateVictim())
+ return;
if (spawntimer <= diff)
{
@@ -136,20 +137,20 @@ struct MANGOS_DLL_DECL boss_amanitarAI : public ScriptedAI
if (roottimer <= diff)
{
if (Unit *pTarget = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true))
- m_creature->CastSpell(pTarget, SPELL_ENTANGLING_ROOTS, false);
+ DoCast(pTarget, SPELL_ENTANGLING_ROOTS);
roottimer = urand(15000,30000);
}
if (bashtimer <= diff)
{
- m_creature->CastSpell(m_creature->getVictim(), SPELL_BASH, false);
+ DoCastVictim(SPELL_BASH);
bashtimer = urand(15000,30000);
} else bashtimer -= diff;
if (bolttimer <= diff)
{
if (Unit *pTarget = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true))
- m_creature->CastSpell(pTarget, SPELL_VENOM_BOLT_VOLLEY, false);
+ DoCast(pTarget, SPELL_VENOM_BOLT_VOLLEY);
bolttimer = urand(15000,30000);
} else bolttimer -= diff;
@@ -169,9 +170,10 @@ struct MANGOS_DLL_DECL mob_amanitar_mushroomsAI : public Scripted_NoMovementAI
void Reset()
{
- m_creature->CastSpell(m_creature, SPELL_PUTRID_MUSHROOM, true); // Hack, to make the mushrooms visible, can't find orig. spell...
+ DoCast(m_creature, SPELL_PUTRID_MUSHROOM, true); // Hack, to make the mushrooms visible, can't find orig. spell...
- if (m_creature->GetEntry() == NPC_POISONOUS_MUSHROOM) m_creature->CastSpell(m_creature, POISONOUS_MUSHROOM_SPELL_VISUAL_AURA, true);
+ if (m_creature->GetEntry() == NPC_POISONOUS_MUSHROOM)
+ DoCast(m_creature, POISONOUS_MUSHROOM_SPELL_VISUAL_AURA, true);
auratimer = 0;
deathtimer = 30000;
@@ -198,8 +200,8 @@ struct MANGOS_DLL_DECL mob_amanitar_mushroomsAI : public Scripted_NoMovementAI
{
if (auratimer <= diff)
{
- m_creature->CastSpell(m_creature, POISONOUS_MUSHROOM_SPELL_VISUAL_AREA, true);
- m_creature->CastSpell(m_creature, POISONOUS_MUSHROOM_SPELL_POISON_CLOUD, false);
+ DoCast(m_creature, POISONOUS_MUSHROOM_SPELL_VISUAL_AREA, true);
+ DoCast(m_creature, POISONOUS_MUSHROOM_SPELL_POISON_CLOUD, false);
auratimer = 7000;
} else auratimer -= diff;
}
diff --git a/src/bindings/scripts/scripts/northrend/naxxramas/boss_maexxna.cpp b/src/bindings/scripts/scripts/northrend/naxxramas/boss_maexxna.cpp
index 70d8912d1d5..9b71a8063d5 100644
--- a/src/bindings/scripts/scripts/northrend/naxxramas/boss_maexxna.cpp
+++ b/src/bindings/scripts/scripts/northrend/naxxramas/boss_maexxna.cpp
@@ -31,9 +31,9 @@
#define MAX_POS_WRAP 3
const float PosWrap[MAX_POS_WRAP][3] =
{
- {3546.796, -3869.082, 296.450+20},
- {3531.271, -3847.424, 299.450+20},
- {3497.067, -3843.384, 302.384+20},
+ {3546.796, -3869.082, 296.450},
+ {3531.271, -3847.424, 299.450},
+ {3497.067, -3843.384, 302.384},
};
enum Events
@@ -74,12 +74,12 @@ struct TRINITY_DLL_DECL boss_maexxnaAI : public BossAI
switch(eventId)
{
case EVENT_WRAP:
- for (uint32 i = 0; i < HEROIC(1,2); ++i)
+ for (uint8 i = 0; i < HEROIC(1,2); ++i)
{
if (Unit *pTarget = SelectTarget(SELECT_TARGET_RANDOM, 1, 0, true, -SPELL_WEB_WRAP))
{
pTarget->RemoveAura(SPELL_WEB_SPRAY);
- uint32 pos = rand()%MAX_POS_WRAP;
+ uint8 pos = rand()%MAX_POS_WRAP;
pTarget->GetMotionMaster()->MoveJump(PosWrap[pos][0], PosWrap[pos][1], PosWrap[pos][2], 20, 20);
if (Creature *wrap = DoSummon(MOB_WEB_WRAP, pTarget, 0, 60000))
{
@@ -104,8 +104,8 @@ struct TRINITY_DLL_DECL boss_maexxnaAI : public BossAI
return;
case EVENT_SUMMON:
{
- uint32 amount = 8+rand()%2;
- for (uint32 i = 0; i < amount; ++i)
+ uint8 amount = urand(8,10);
+ for (uint8 i = 0; i < amount; ++i)
DoSummon(MOB_SPIDERLING, me);
events.ScheduleEvent(EVENT_SUMMON, 40000);
break;
diff --git a/src/bindings/scripts/scripts/world/npc_professions.cpp b/src/bindings/scripts/scripts/world/npc_professions.cpp
index 08822f58ecd..ad4cd3bd1f2 100644
--- a/src/bindings/scripts/scripts/world/npc_professions.cpp
+++ b/src/bindings/scripts/scripts/world/npc_professions.cpp
@@ -195,7 +195,7 @@ int32 DoHighUnlearnCost(Player* pPlayer) //tailor, alchemy
int32 DoMedUnlearnCost(Player* pPlayer) //blacksmith, leatherwork
{
- uint32 level = pPlayer->getLevel();
+ uint8 level = pPlayer->getLevel();
if (level < 51)
return 250000;
else if (level < 66)
@@ -206,7 +206,7 @@ int32 DoMedUnlearnCost(Player* pPlayer) //blacksmith, leath
int32 DoLowUnlearnCost(Player* pPlayer) //blacksmith
{
- uint32 level = pPlayer->getLevel();
+ uint8 level = pPlayer->getLevel();
if (level < 66)
return 50000;
else
@@ -224,14 +224,14 @@ bool EquippedOk(Player* pPlayer, uint32 spellId)
if (!spell)
return false;
- for (uint8 i=0; i<3; ++i)
+ for (uint8 i = 0; i < 3; ++i)
{
uint32 reqSpell = spell->EffectTriggerSpell[i];
if (!reqSpell)
continue;
Item* pItem;
- for (uint8 j = EQUIPMENT_SLOT_START; j < EQUIPMENT_SLOT_END; j++)
+ for (uint8 j = EQUIPMENT_SLOT_START; j < EQUIPMENT_SLOT_END; ++j)
{
pItem = pPlayer->GetItemByPos(INVENTORY_SLOT_BAG_0, j);
if (pItem)