Jump to content

[11556] targetUnitMap with new sort (TargetDistanceOrderFarAway)


Guest breakwater

Recommended Posts

Hi all,

Some spells effects the furthest away target from caster. An Example Bloodboil (Spell from Bloodboil xD)

Therefor I have write a new Sortstructur and implement the Spell Bloodboil right.

I know that the structure TargetDistanceOrderFarAway looks equal to TargetDistanceOrder, but it has one little difference (behind the return is a "!").

I think a new TargetDistanceOrder structure is better then this way without this structure:

only partial( no REAL Code)

FillAreaTargets(temptargetUnitMap ....)
for (temptargetUnitMap begin(); ... end; itr ++)
targetUnitMap.push_front(*itr)
targetUnitMap.resize(5)

Maybe we can use this new TargetDistanceOrderFarAway for other spells. At the moment I don't know other spells.

if the mangos team take this into master, maybe we can rename the "old" TargetDistanceOrder to TargetDistanceOrderNear (I think thats more readable) or something like this.

OK and now the Code

diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp
index 30ba5c5..29b4fbe 100644
--- a/src/game/Spell.cpp
+++ b/src/game/Spell.cpp
@@ -1756,6 +1756,19 @@ struct TargetDistanceOrder : public std::binary_function<const Unit, const Unit,
    }
};

+// 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;
@@ -1845,7 +1858,6 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
                    unMaxTargets = 4;
                    break;
                case 30843:                                 // Enfeeble TODO: exclude top threat target from target selection
-                case 42005:                                 // Bloodboil TODO: need to be 5 targets(players) furthest away from caster
                case 55665:                                 // Life Drain (h)
                case 58917:                                 // Consume Minions
                case 64604:                                 // Nature Bomb Freya
@@ -2189,7 +2201,17 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
            else
            {
                FillAreaTargets(targetUnitMap, radius, PUSH_DEST_CENTER, SPELL_TARGETS_AOE_DAMAGE);
-                if (m_spellInfo->Id == 62240 || m_spellInfo->Id == 62920)
+                if (m_spellInfo->Id == 42005)                                       // Bloodboil
+                {
+                    if(!targetUnitMap.empty())
+                    {
+                        // sort the targets, that the furthest away target is at first position 
+                        targetUnitMap.sort(TargetDistanceOrderFarAway(m_caster));
+                        // manually cuting, because the spell hits only the 5 furthest away targets
+                        targetUnitMap.resize(5);
+                    }
+                }
+                else if (m_spellInfo->Id == 62240 || m_spellInfo->Id == 62920)      // Solar Flare
                {
                    if (SpellAuraHolder *holder = m_caster->GetSpellAuraHolder(62239))
                        unMaxTargets = holder->GetStackAmount();

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use