Core: Some optimizations

- Declare some functions const
- Fix some mem leak
- Fix some resource leak
- Remove unused variables and functions
- Remove duplicate functions
- Reduce the scope of some variables
- Remove unused file

--HG--
branch : trunk
This commit is contained in:
Spp
2010-12-06 02:07:53 +01:00
parent e226c4ac34
commit 408fce1de6
73 changed files with 200 additions and 712 deletions
@@ -299,14 +299,11 @@ public:
if (DispelTimer <= diff)
{
Unit *pTarget = NULL;
bool friendly = false;
if (urand(0,1))
pTarget = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true);
else
{
friendly = true;
if (urand(0,1))
pTarget = me;
else
@@ -229,10 +229,9 @@ enum mograine
SPELL_THUNDER = 53630
};
struct Locations
struct Location
{
float x, y, z, o;
uint32 id;
};
void UpdateWorldState(Map *map, uint32 id, uint32 state)
@@ -249,38 +248,38 @@ void UpdateWorldState(Map *map, uint32 id, uint32 state)
}
}
static Locations LightofDawnLoc[]=
static Location LightofDawnLoc[]=
{
{2281.335f, -5300.409f, 85.170f, 0 ,0}, // 0 Tirion Fordring loc
{2283.896f, -5287.914f, 83.066f, 1.55f ,0}, // 1 Tirion Fordring loc2
{2281.461f, -5263.014f, 81.164f, 0 ,0}, // 2 Tirion charges
{2262.277f, -5293.477f, 82.167f, 0 ,0}, // 3 Tirion run
{2270.286f, -5287.73f, 82.262f, 0 ,0}, // 4 Tirion relocate
{2269.511f, -5288.289f, 82.225f, 0 ,0}, // 5 Tirion forward
{2262.277f, -5293.477f, 82.167f, 0 ,0}, // 6 Tirion runs to Darion
{2270.286f, -5287.73f, 82.262f, 0 ,0},
{2269.511f, -5288.289f, 82.225f, 0 ,0},
{2273.205f, -5288.848f, 82.617f, 0 ,0}, // 9 Korfax loc1
{2274.739f, -5287.926f, 82.684f, 0 ,0}, // 10 Korfax loc2
{2253.673f, -5318.004f, 81.724f, 0 ,0}, // 11 Korfax kicked
{2287.028f, -5309.644f, 87.253f, 0 ,0}, // 12 Maxwell loc1
{2286.978f, -5308.025f, 86.83f, 0 ,0}, // 13 Maxwell loc2
{2248.877f, -5307.586f, 82.166f, 0 ,0}, // 14 maxwell kicked
{2278.58f, -5316.933f, 88.319f, 0 ,0}, // 15 Eligor loc1
{2278.535f, -5315.479f, 88.08f, 0 ,0}, // 16 Eligor loc2
{2259.416f, -5304.505f, 82.149f, 0 ,0}, // 17 eligor kicked
{2289.259f, -5280.355f, 82.112f, 0 ,0}, // 18 Koltira loc1
{2289.02f, -5281.985f, 82.207f, 0 ,0}, // 19 Koltira loc2
{2273.289f, -5273.675f, 81.701f, 0 ,0}, // 20 Thassarian loc1
{2273.332f, -5275.544f, 81.849f, 0 ,0}, // 21 Thassarian loc2
{2281.198f, -5257.397f, 80.224f, 4.66f ,0}, // 22 Alexandros loc1
{2281.156f, -5259.934f, 80.647f, 0 ,0}, // 23 Alexandros loc2
{2281.294f, -5281.895f, 82.445f, 1.35f ,0}, // 24 Darion loc1
{2281.093f, -5263.013f, 81.125f, 0 ,0}, // 25 Darion loc1
{2281.313f, -5250.282f, 79.322f, 4.69f ,0}, // 26 Lich King spawns
{2281.523f, -5261.058f, 80.877f, 0 ,0}, // 27 Lich king move forwards
{2272.709f, -5255.552f, 78.226f, 0 ,0}, // 28 Lich king kicked
{2273.972f, -5257.676f, 78.862f, 0, 0}, // 29 Lich king moves forward
{2281.335f, -5300.409f, 85.170f, 0}, // 0 Tirion Fordring loc
{2283.896f, -5287.914f, 83.066f, 1.55f}, // 1 Tirion Fordring loc2
{2281.461f, -5263.014f, 81.164f, 0}, // 2 Tirion charges
{2262.277f, -5293.477f, 82.167f, 0}, // 3 Tirion run
{2270.286f, -5287.73f, 82.262f, 0}, // 4 Tirion relocate
{2269.511f, -5288.289f, 82.225f, 0}, // 5 Tirion forward
{2262.277f, -5293.477f, 82.167f, 0}, // 6 Tirion runs to Darion
{2270.286f, -5287.73f, 82.262f, 0},
{2269.511f, -5288.289f, 82.225f, 0},
{2273.205f, -5288.848f, 82.617f, 0}, // 9 Korfax loc1
{2274.739f, -5287.926f, 82.684f, 0}, // 10 Korfax loc2
{2253.673f, -5318.004f, 81.724f, 0}, // 11 Korfax kicked
{2287.028f, -5309.644f, 87.253f, 0}, // 12 Maxwell loc1
{2286.978f, -5308.025f, 86.83f, 0}, // 13 Maxwell loc2
{2248.877f, -5307.586f, 82.166f, 0}, // 14 maxwell kicked
{2278.58f, -5316.933f, 88.319f, 0}, // 15 Eligor loc1
{2278.535f, -5315.479f, 88.08f, 0}, // 16 Eligor loc2
{2259.416f, -5304.505f, 82.149f, 0}, // 17 eligor kicked
{2289.259f, -5280.355f, 82.112f, 0}, // 18 Koltira loc1
{2289.02f, -5281.985f, 82.207f, 0}, // 19 Koltira loc2
{2273.289f, -5273.675f, 81.701f, 0}, // 20 Thassarian loc1
{2273.332f, -5275.544f, 81.849f, 0}, // 21 Thassarian loc2
{2281.198f, -5257.397f, 80.224f, 4.66f}, // 22 Alexandros loc1
{2281.156f, -5259.934f, 80.647f, 0}, // 23 Alexandros loc2
{2281.294f, -5281.895f, 82.445f, 1.35f}, // 24 Darion loc1
{2281.093f, -5263.013f, 81.125f, 0}, // 25 Darion loc1
{2281.313f, -5250.282f, 79.322f, 4.69f}, // 26 Lich King spawns
{2281.523f, -5261.058f, 80.877f, 0}, // 27 Lich king move forwards
{2272.709f, -5255.552f, 78.226f, 0}, // 28 Lich king kicked
{2273.972f, -5257.676f, 78.862f, 0}, // 29 Lich king moves forward
};
class npc_highlord_darion_mograine : public CreatureScript
@@ -128,7 +128,7 @@ struct PlayerAbilityStruct
{
uint32 spell;
AbilityTarget target;
uint32 cooldown;
uint32 cooldown; //FIXME - it's never used
};
static PlayerAbilityStruct PlayerAbility[][3] =
@@ -38,7 +38,7 @@ EndScriptData */
// But we cannot add loots to gameobject, so we have to use the fixed loot_template
struct SHostageInfo
{
uint32 npc, go;
uint32 npc, go; // FIXME go Not used
float x, y, z, o;
};
@@ -78,6 +78,7 @@ enum eSeat
SEAT_ID_0 = 0
};
/*
struct Point
{
float x,y,z;
@@ -89,7 +90,7 @@ const Point MovementPoint[] =
{747.96f,620.29f,411.09f},
{750.23f,618.35f,411.09f}
};
*/
void AggroAllPlayers(Creature* pTemp)
{
Map::PlayerList const &PlList = pTemp->GetMap()->GetPlayers();
@@ -275,9 +275,7 @@ struct boss_faction_championsAI : public ScriptedAI
void UpdateThreat()
{
std::list<HostileReference*> const& tList = me->getThreatManager().getThreatList();
std::list<HostileReference*>::const_iterator itr;
bool empty = true;
for (itr = tList.begin(); itr!=tList.end(); ++itr)
for (std::list<HostileReference*>::const_iterator itr = tList.begin(); itr != tList.end(); ++itr)
{
Unit* pUnit = Unit::GetUnit((*me), (*itr)->getUnitGuid());
if (pUnit && me->getThreatManager().getThreat(pUnit))
@@ -287,7 +285,6 @@ struct boss_faction_championsAI : public ScriptedAI
float threat = CalculateThreat(me->GetDistance2d(pUnit), (float)pUnit->GetArmor(), pUnit->GetHealth());
me->getThreatManager().modifyThreatPercent(pUnit, -100);
me->AddThreat(pUnit, 1000000.0f * threat);
empty = false;
}
}
}
@@ -452,6 +452,7 @@ struct boss_jormungarAI : public ScriptedAI
case 4:
m_uiStage = 5;
m_uiSubmergeTimer = 5*IN_MILLISECONDS;
break;
default:
m_uiStage = 7;
}
@@ -384,7 +384,7 @@ public:
void UpdateAI(const uint32 diff)
{
if (!UpdateCombatState() || !CheckInRoom())
if (!UpdateVictim() || !CheckInRoom())
return;
events.Update(diff);
@@ -377,7 +377,7 @@ public:
void UpdateAI(const uint32 diff)
{
if (!UpdateCombatState())
if (!UpdateVictim())
return;
events.Update(diff);
@@ -142,7 +142,7 @@ public:
void UpdateAI(const uint32 diff)
{
if (!UpdateCombatState() || !CheckInRoom())
if (!UpdateVictim() || !CheckInRoom())
return;
events.Update(diff);
@@ -228,7 +228,7 @@ public:
events.Update(diff);
if ((phase != PHASE_BIRTH && !UpdateCombatState()) || !CheckInRoom())
if ((phase != PHASE_BIRTH && !UpdateVictim()) || !CheckInRoom())
return;
if (CanTheHundredClub)
@@ -492,8 +492,7 @@ public:
//EnchantedElemental_Timer
if (EnchantedElemental_Timer <= diff)
{
Creature *Elemental;
Elemental = me->SummonCreature(ENCHANTED_ELEMENTAL, ElementPos[EnchantedElemental_Pos][0], ElementPos[EnchantedElemental_Pos][1], ElementPos[EnchantedElemental_Pos][2], ElementPos[EnchantedElemental_Pos][3], TEMPSUMMON_CORPSE_DESPAWN, 0);
me->SummonCreature(ENCHANTED_ELEMENTAL, ElementPos[EnchantedElemental_Pos][0], ElementPos[EnchantedElemental_Pos][1], ElementPos[EnchantedElemental_Pos][2], ElementPos[EnchantedElemental_Pos][3], TEMPSUMMON_CORPSE_DESPAWN, 0);
if (EnchantedElemental_Pos == 7)
EnchantedElemental_Pos = 0;
@@ -506,9 +505,8 @@ public:
//TaintedElemental_Timer
if (TaintedElemental_Timer <= diff)
{
Creature *Tain_Elemental;
uint32 pos = rand()%8;
Tain_Elemental = me->SummonCreature(TAINTED_ELEMENTAL, ElementPos[pos][0], ElementPos[pos][1], ElementPos[pos][2], ElementPos[pos][3], TEMPSUMMON_DEAD_DESPAWN, 0);
me->SummonCreature(TAINTED_ELEMENTAL, ElementPos[pos][0], ElementPos[pos][1], ElementPos[pos][2], ElementPos[pos][3], TEMPSUMMON_DEAD_DESPAWN, 0);
TaintedElemental_Timer = 120000;
} else TaintedElemental_Timer -= diff;
@@ -312,7 +312,7 @@ public:
} else WaterboltTimer -= diff;
}
if (!UpdateCombatState())
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
+11 -15
View File
@@ -820,9 +820,6 @@ void npc_doctor::npc_doctorAI::UpdateAI(const uint32 diff)
{
if (SummonPatient_Timer <= diff)
{
Creature* Patient = NULL;
Location* Point = NULL;
if (Coordinates.empty())
return;
@@ -838,22 +835,21 @@ void npc_doctor::npc_doctorAI::UpdateAI(const uint32 diff)
return;
}
Point = *itr;
Patient = me->SummonCreature(patientEntry, Point->x, Point->y, Point->z, Point->o, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 5000);
if (Patient)
if (Location* Point = *itr)
{
//303, this flag appear to be required for client side item->spell to work (TARGET_SINGLE_FRIEND)
Patient->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
if (Creature* Patient = me->SummonCreature(patientEntry, Point->x, Point->y, Point->z, Point->o, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 5000))
{
//303, this flag appear to be required for client side item->spell to work (TARGET_SINGLE_FRIEND)
Patient->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
Patients.push_back(Patient->GetGUID());
CAST_AI(npc_injured_patient::npc_injured_patientAI, Patient->AI())->Doctorguid = me->GetGUID();
Patients.push_back(Patient->GetGUID());
CAST_AI(npc_injured_patient::npc_injured_patientAI, Patient->AI())->Doctorguid = me->GetGUID();
if (Point)
CAST_AI(npc_injured_patient::npc_injured_patientAI, Patient->AI())->Coord = Point;
if (Point)
CAST_AI(npc_injured_patient::npc_injured_patientAI, Patient->AI())->Coord = Point;
Coordinates.erase(itr);
Coordinates.erase(itr);
}
}
SummonPatient_Timer = 10000;
++SummonPatientCount;