Skip to content

Commit

Permalink
[11556] Implement spell 42005 proper target seelction.
Browse files Browse the repository at this point in the history
Also
* added TargetDistanceOrderFarAway ordering function and
* renamed TargetDistanceOrder -> TargetDistanceOrderFarAway

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
  • Loading branch information
breakwater authored and VladimirMangos committed May 28, 2011
1 parent a6997a8 commit 4bb524e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
47 changes: 35 additions & 12 deletions src/game/Spell.cpp
Expand Up @@ -1500,17 +1500,30 @@ class ChainHealingFullHealth: std::unary_function<const Unit*, bool>

// Helper for targets nearest to the spell target
// The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
struct TargetDistanceOrder : public std::binary_function<const Unit, const Unit, bool>
struct TargetDistanceOrderNear : public std::binary_function<const Unit, const Unit, bool>
{
const Unit* MainTarget;
TargetDistanceOrder(const Unit* Target) : MainTarget(Target) {};
TargetDistanceOrderNear(const Unit* Target) : MainTarget(Target) {};
// functor for operator ">"
bool operator()(const Unit* _Left, const Unit* _Right) const
{
return MainTarget->GetDistanceOrder(_Left, _Right);
}
};

// Helper for targets furthest away to the spell target
// The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
struct TargetDistanceOrderFarAway : public std::binary_function<const Unit, const Unit, bool>
{
const Unit* MainTarget;
TargetDistanceOrderFarAway(const Unit* Target) : MainTarget(Target) {};
// functor for operator "<"
bool operator()(const Unit* _Left, const Unit* _Right) const
{
return !MainTarget->GetDistanceOrder(_Left, _Right);
}
};

void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList& targetUnitMap)
{
float radius;
Expand Down Expand Up @@ -1676,7 +1689,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
if(tempTargetUnitMap.empty())
break;

tempTargetUnitMap.sort(TargetDistanceOrder(m_caster));
tempTargetUnitMap.sort(TargetDistanceOrderNear(m_caster));

//Now to get us a random target that's in the initial range of the spell
uint32 t = 0;
Expand All @@ -1694,7 +1707,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&

tempTargetUnitMap.erase(itr);

tempTargetUnitMap.sort(TargetDistanceOrder(pUnitTarget));
tempTargetUnitMap.sort(TargetDistanceOrderNear(pUnitTarget));

t = unMaxTargets - 1;
Unit *prev = pUnitTarget;
Expand All @@ -1714,7 +1727,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
prev = *next;
targetUnitMap.push_back(prev);
tempTargetUnitMap.erase(next);
tempTargetUnitMap.sort(TargetDistanceOrder(prev));
tempTargetUnitMap.sort(TargetDistanceOrderNear(prev));
next = tempTargetUnitMap.begin();

--t;
Expand All @@ -1736,7 +1749,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
if(tempTargetUnitMap.empty())
break;

tempTargetUnitMap.sort(TargetDistanceOrder(m_caster));
tempTargetUnitMap.sort(TargetDistanceOrderNear(m_caster));

//Now to get us a random target that's in the initial range of the spell
uint32 t = 0;
Expand All @@ -1754,7 +1767,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&

tempTargetUnitMap.erase(itr);

tempTargetUnitMap.sort(TargetDistanceOrder(pUnitTarget));
tempTargetUnitMap.sort(TargetDistanceOrderNear(pUnitTarget));

t = unMaxTargets - 1;
Unit *prev = pUnitTarget;
Expand All @@ -1773,7 +1786,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
prev = *next;
targetUnitMap.push_back(prev);
tempTargetUnitMap.erase(next);
tempTargetUnitMap.sort(TargetDistanceOrder(prev));
tempTargetUnitMap.sort(TargetDistanceOrderNear(prev));
next = tempTargetUnitMap.begin();
--t;
}
Expand Down Expand Up @@ -1821,7 +1834,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
if (tempTargetUnitMap.empty())
break;

tempTargetUnitMap.sort(TargetDistanceOrder(pUnitTarget));
tempTargetUnitMap.sort(TargetDistanceOrderNear(pUnitTarget));

if (*tempTargetUnitMap.begin() == pUnitTarget)
tempTargetUnitMap.erase(tempTargetUnitMap.begin());
Expand All @@ -1843,7 +1856,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
prev = *next;
targetUnitMap.push_back(prev);
tempTargetUnitMap.erase(next);
tempTargetUnitMap.sort(TargetDistanceOrder(prev));
tempTargetUnitMap.sort(TargetDistanceOrderNear(prev));
next = tempTargetUnitMap.begin();
--t;
}
Expand All @@ -1852,6 +1865,16 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
}
case TARGET_ALL_ENEMY_IN_AREA:
FillAreaTargets(targetUnitMap, radius, PUSH_DEST_CENTER, SPELL_TARGETS_AOE_DAMAGE);

if (m_spellInfo->Id == 42005) // Bloodboil
{
// manually cuting, because the spell hits only the 5 furthest away targets
if (targetUnitMap.size() > unMaxTargets)
{
targetUnitMap.sort(TargetDistanceOrderFarAway(m_caster));
targetUnitMap.resize(unMaxTargets);
}
}
break;
case TARGET_AREAEFFECT_INSTANT:
{
Expand Down Expand Up @@ -2358,7 +2381,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
if (m_caster != pUnitTarget && std::find(tempTargetUnitMap.begin(), tempTargetUnitMap.end(), m_caster) == tempTargetUnitMap.end())
tempTargetUnitMap.push_front(m_caster);

tempTargetUnitMap.sort(TargetDistanceOrder(pUnitTarget));
tempTargetUnitMap.sort(TargetDistanceOrderNear(pUnitTarget));

if (tempTargetUnitMap.empty())
break;
Expand Down Expand Up @@ -2391,7 +2414,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
prev = *next;
targetUnitMap.push_back(prev);
tempTargetUnitMap.erase(next);
tempTargetUnitMap.sort(TargetDistanceOrder(prev));
tempTargetUnitMap.sort(TargetDistanceOrderNear(prev));
next = tempTargetUnitMap.begin();

--t;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11555"
#define REVISION_NR "11556"
#endif // __REVISION_NR_H__

0 comments on commit 4bb524e

Please sign in to comment.