• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

CR - MISC

JASS:
library MISC requires Main

//globals
    private sound udg_SimError = null
    private bool Stop = false
    unit ForFilter1, ForFilter2, SOURCE_UNIT
    
 
    bool AllFilter(){
        return (GetHp(GetFilterUnit()) > 0.045)
    }
 
    bool EnemiesFilter(){
        return (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(ForFilter1)) and GetHp(GetFilterUnit()) > 0.045 and GetUnitAbilityLevel(GetFilterUnit(), 'Avul') == 0 and GetUnitAbilityLevel(GetFilterUnit(), IGNORE_ID) == 0 and not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE))
    }

    bool EnemiesFilterEx(){
        return (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(ForFilter1)) and GetHp(GetFilterUnit()) > 0.045 and IsUnitVisible(GetFilterUnit(), GetOwningPlayer(ForFilter1))and not IsUnitInvisible(GetFilterUnit(), GetOwningPlayer(ForFilter1)) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE))
    }
// 


    bool AllyFilter(){
        return (not IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(ForFilter1)) and GetHp(GetFilterUnit()) > 0.045 and ForFilter1 != GetFilterUnit() and GetUnitAbilityLevel(GetFilterUnit(), IGNORE_ID) == 0 and not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE))
    }

    bool GetMaxAvailableDistanceFilter(){
        if (GetDestructableTypeId(GetFilterDestructable()) == 'YTfb' or GetDestructableTypeId(GetFilterDestructable()) == 'YTab' or GetDestructableTypeId(GetFilterDestructable()) == 'YTpc' or GetDestructableTypeId(GetFilterDestructable()) == 'CTtr' or GetDestructableTypeId(GetFilterDestructable()) == 'CTtc' or GetDestructableTypeId(GetFilterDestructable()) == 'ATtr' or GetDestructableTypeId(GetFilterDestructable()) == 'ATtc') {
            Stop = true
        }
    return false
    }

    bool IsCoordsNotFree(real x,real y){
        rect rct = Rect(x - 50., y - 50., x + 50., y + 50.)
        bool b
            MoveRectTo(rct, x, y)
            Stop = false
            EnumDestructablesInRect(rct, Filter(function GetMaxAvailableDistanceFilter), null)
            b = Stop
            Stop = false
        RemoveRect(rct)
        rct = null
        return b
    }

    real GetMaxAvailableDistanceEx(unit a, real range, real ang){
        int steps = R2I(range / 25.)
        real current_range = 25., x = Gx(a), y = Gy(a)
        rect rct = Rect(x - 50., y - 50., x + 50., y + 50.)

            while(steps != 0){
                MoveRectTo(rct, GetRectCenterX(rct) + Rx(25.,ang),GetRectCenterY(rct) + Ry(25.,ang))
                Stop = false
                EnumDestructablesInRect(rct, Filter(function GetMaxAvailableDistanceFilter), null)
                if Stop { break }
                current_range += 25.
                steps--
            }
            
            Stop = false
            RemoveRect(rct)
            rct = null
            debug msg(R2S(current_range))
            if steps == 0 { current_range = range }
    return current_range
    }

    function nearest_filt takes nothing returns boolean
        return (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(SOURCE_UNIT)) and GetHp(GetFilterUnit()) > 0.045)
    endfunction

    real ABU (unit A, unit B) {
        return Atan2(GetUnitY(B)-GetUnitY(A), GetUnitX(B)-GetUnitX(A))*bj_RADTODEG
    }

    real ABUC (unit A, real B_x, real B_y) {
        return Atan2(B_y-GetUnitY(A), B_x-GetUnitX(A))*bj_RADTODEG
    }

    real ABUC2 (real A_x, real A_y, real B_x, real B_y) {
        return Atan2(B_y - A_y, B_x - A_x) * bj_RADTODEG
    }

    real DBU (unit A, unit B) {
    real dx = GetUnitX(B) - GetUnitX(A)
    real dy = GetUnitY(B) - GetUnitY(A)
        return SquareRoot((dx * dx) + (dy * dy))
    }

    real DBC (unit A, real B_x, real B_y) {
    real dx = B_x - GetUnitX(A)
    real dy = B_y - GetUnitY(A)
        return SquareRoot((dx * dx) + (dy * dy))
    }

    real DBC2 (real A_x, real A_y, real B_x, real B_y) {
    real dx = B_x - A_x
    real dy = B_y - A_y
        return SquareRoot((dx * dx) + (dy * dy))
    }

    real DBC_Ex (unit A, real B_x, real B_y) {
    real dx = B_x - GetUnitX(A)
    real dy = B_y - GetUnitY(A)
        return GetMaxAvailableDistanceEx(A, SquareRoot((dx * dx) + (dy * dy)), ABUC(A, B_x, B_y))
    }

    real TBU (unit A, unit B, real speed) {
    real dx = GetUnitX(B) - GetUnitX(A)
    real dy = GetUnitY(B) - GetUnitY(A)
        return (SquareRoot((dx * dx) + (dy * dy)) / speed)
    }

    real TBC (unit A, real B_x, real B_y, real speed) {
    real dx = B_x - GetUnitX(A)
    real dy = B_y - GetUnitY(A)
        return (SquareRoot((dx * dx) + (dy * dy)) / speed)
    }

    real TBC_Ex (unit A, real B_x, real B_y, real speed) {
    real dx = B_x - GetUnitX(A)
    real dy = B_y - GetUnitY(A)
        return (GetMaxAvailableDistanceEx(A, SquareRoot((dx * dx) + (dy * dy)), ABUC(A, B_x, B_y))/speed)
    }

    real ParabolaZ(real h, real d, real x){
      return (4 * h / d) * (d - x) * (x / d)
    }

    real GetAngleOfRebound(real current_angle, real angle_between_unit_and_bound, real range){
        return (-current_angle + 180. + 2. * angle_between_unit_and_bound) + GetRandomReal(-range, range)
    }

function IsUnitBack takes unit uF, unit uWhichBack returns boolean
real r1 = bj_RADTODEG * Atan2(GetUnitY(uWhichBack) - GetUnitY(uF), GetUnitX(uWhichBack) - GetUnitX(uF)) + 360.
real r2 = GetUnitFacing(uWhichBack) + 360.
   if GetUnitY(uWhichBack) < GetUnitY(uF) then
       set r1 = r1 + 360.
   endif
   return (r1<=(r2+45.) and r1>=(r2-45.))
endfunction

bool IsSide(unit ataker,unit victim) {
real angle1 = GetUnitFacing(victim)
real angle2 = ABU(ataker,victim)

    if not (GetUnitY(victim) > GetUnitY(ataker)) {
        angle1 -= 360.
    }
    
    if (angle2 <= ( angle1 + 135.00 ) and angle2 >= ( angle1 + 45.00 ))\\
    or (angle2 <= ( angle1 - 45.00 ) and angle2 >= ( angle1 - 135.00 ))\\
    or (GetUnitY(victim) > GetUnitY(ataker) and GetUnitX(victim) > GetUnitX(ataker) and angle2 <= ( angle1 - 225.00 ) and angle2 >= ( angle1 - 315.00 ) )\\
    or (GetUnitY(victim) < GetUnitY(ataker) and GetUnitX(victim) > GetUnitX(ataker) and angle2 >= ( angle1 + 225.00 ) and angle2 <= ( angle1 + 315.00 ))
    {
        return true
    }
return false
}

function SimError takes string msg1 returns nothing
    if udg_SimError==null then
        set udg_SimError=CreateSoundFromLabel( "InterfaceError",false,false,false,10,10)
    endif
        call DisplayTimedTextToPlayer( Player(0), 0.52, -1.00, 2.00, "|cffffcc00"+msg1+"|r" )
        call StartSound( udg_SimError )
endfunction

    function TextUp takes string s, unit u, real size,real r,real g, real b returns nothing
    //real sp =(64 * 0.071) / 128
        real x1 = 0.0355 * Cos(90. * DEGTORAD)
        real y1 = 0.0355 * Sin(90. * DEGTORAD)
            bj_lastCreatedTextTag = CreateTextTag()
            SetTextTagText(bj_lastCreatedTextTag, s, (size * 0.023) / 10)
            SetTextTagPosUnit(bj_lastCreatedTextTag, u, 7)
            SetTextTagColor(bj_lastCreatedTextTag, PercentToInt(r, 255), PercentToInt(g, 255), PercentToInt(b,255), 0)
            SetTextTagVelocity(bj_lastCreatedTextTag, x1,y1)
            SetTextTagPermanent(bj_lastCreatedTextTag, false)
            SetTextTagLifespan(bj_lastCreatedTextTag, 2.5)
            SetTextTagFadepoint(bj_lastCreatedTextTag, 0)
    endfunction

    function Text takes string s, unit u, unit u2, real size,real r,real g, real b returns nothing
        //real sp =(64 * 0.071) / 128
        real x1 = 0.0355 * Cos(ABU(u,u2) * DEGTORAD)
        real y1 = 0.0355 * Sin(ABU(u,u2) * DEGTORAD)
            bj_lastCreatedTextTag = CreateTextTag()
            SetTextTagText(bj_lastCreatedTextTag, s, (size * 0.023) / 10)
            //SetTextTagPos(bj_lastCreatedTextTag, x, y, 7)
            SetTextTagPosUnit(bj_lastCreatedTextTag, u2, 7)
            SetTextTagColor(bj_lastCreatedTextTag, PercentToInt(r, 255), PercentToInt(g, 255), PercentToInt(b,255), 0)
            SetTextTagVelocity(bj_lastCreatedTextTag, x1,y1)
            SetTextTagPermanent(bj_lastCreatedTextTag, false)
            SetTextTagLifespan(bj_lastCreatedTextTag, 2.5)
            SetTextTagFadepoint(bj_lastCreatedTextTag, 0)
    endfunction


    texttag AddTextEx(string s, real x, real y, real size){
        texttag new_txt = CreateTextTag()
            SetTextTagText(new_txt, s, (size * 0.023) / 10.)
            SetTextTagPos(new_txt, x, y, 7.)
            SetTextTagColor(new_txt, PercentToInt(100., 255), PercentToInt(100., 255), PercentToInt(100., 255), 0)
        return new_txt
    }
    
    texttag AddText(string s, real x, real y, real size, real r, real g, real b){
            bj_lastCreatedTextTag = CreateTextTag()
            SetTextTagText(bj_lastCreatedTextTag, s, (size * 0.023) / 10.)
            SetTextTagPos(bj_lastCreatedTextTag, x, y, 5.)
            SetTextTagColor(bj_lastCreatedTextTag, PercentToInt(r, 255), PercentToInt(g, 255), PercentToInt(b,255), 0)
        return bj_lastCreatedTextTag
    }

    void PreloadSound(string s){ //подгрузка звука 3D
        sound snd = CreateSound(s,false,true,true,10,10,"CombatSoundsEAX")
            SetSoundChannel(snd,5)
            SetSoundVolume(snd,127)
            SetSoundPitch(snd, 1)
            SetSoundDistances(snd,999999,99999)
            SetSoundDistanceCutoff(snd,99999)
            SetSoundConeAngles(snd,0.0,0.0,127)
            SetSoundConeOrientation(snd,0.0,0.0,0.0)
            SetSoundPosition(snd,0.0,0.0,50.0)
            StartSound(snd)
            StopSound(snd, false, false)
        snd = null
    }

    void AddSound(string s, real x, real y) {
        sound snd = CreateSound(s, false, true, true, 10, 10, "CombatSoundsEAX")
            SetSoundChannel(snd, 35)
            SetSoundVolume(snd, 127)
            SetSoundPitch(snd, 1)
            SetSoundDistances(snd, 600, 10000)
            SetSoundDistanceCutoff(snd, 2100)
            SetSoundConeAngles(snd, 0.0, 0.0, 127)
            SetSoundConeOrientation(snd, 0.0, 0.0, 0.0)
            SetSoundPosition(snd, x, y, 50.)
            StartSound(snd)
            KillSoundWhenDone(snd)
        snd = null
    }

    void PlaySimpleSound(string s) {
        sound snd = CreateSound(s, false, false, false, 10, 10, "CombatSoundsEAX")
            SetSoundChannel(snd, 36)
            SetSoundVolume(snd, 127)
            SetSoundPitch(snd, 1)
            StartSound(snd)
            KillSoundWhenDone(snd)
        snd = null
    }

function CountGroup takes group g returns integer
    set bj_groupCountUnits = 0
    call ForGroup(g, function CountUnitsInGroupEnum)
    return bj_groupCountUnits
endfunction

function RandomFromGroup takes group whichGroup returns unit
    bj_groupRandomConsidered = 0
    bj_groupRandomCurrentPick = null
    ForGroup(whichGroup, function GroupPickRandomUnitEnum)
    return bj_groupRandomCurrentPick
endfunction

function CopyGroup takes group g returns group
    set bj_groupAddGroupDest = CreateGroup()
    call ForGroup(g, function GroupAddGroupEnum)
    return bj_groupAddGroupDest
endfunction

unit GetNearestUnit(unit source, real range) {
real r = 50.00, x = GetUnitX(source), y = GetUnitY(source)
group g = CreateGroup()
unit victim = null
SOURCE_UNIT = source
    while (r < range) {
        GroupEnumUnitsInRange(g, x, y, r, Filter(function nearest_filt))
        if FirstOfGroup(g) != null {
            victim = GroupPickRandomUnit(g)
            break
        }
        else { r += 50.00 }
    }
GroupClear(g)
DestroyGroup(g)
g = null
return victim
}

bool IsUnitInHeight(unit A, unit B){
//UnitData ud = GetData(B)
location loc = Location(0.,0.)
real min_h_A, max_h_A, min_h_B, max_h_B
    MoveLocation(loc, Gx(A), Gy(A))
    min_h_A = GetLocationZ(loc) + GetUnitFlyHeight(A) - 15.
    max_h_A = GetLocationZ(loc) + GetUnitFlyHeight(A) + 15.
    MoveLocation(loc, Gx(B), Gy(B))
    min_h_B = GetLocationZ(loc) + GetUnitFlyHeight(B)
    max_h_B = min_h_B + 80.//ud.UnitHeight
RemoveLocation(loc)
loc = null
return ((min_h_A >= min_h_B and min_h_A <= max_h_B) or (max_h_A <= max_h_B and max_h_A >= min_h_B))
}

bool IsUnitInMatchingZ(unit A, unit B){
    location loc = Location(0.,0.)
    real max_z, current_z, current_range = 0., x = Gx(A), y = Gy(A), ang = ABU(A, B)
    int step_count = R2I(DBU(A, B) / 10.)
    bool b = true
        MoveLocation(loc, x, y)
        max_z = GetLocationZ(loc) + 60.
        MoveLocation(loc, Gx(B), Gy(B))
        max_z += (GetLocationZ(loc) + 60.)
            while(step_count != 0){
                MoveLocation(loc, x, y)
                current_z = GetLocationZ(loc) + 60.
                    if current_z >= max_z { b = false; break }
                x += Rx(10.,ang)
                y += Ry(10.,ang)
                current_range += 10.
                step_count--
            }
        RemoveLocation(loc)
    loc = null
    return b
}

real GetOffsetByZ(unit A, unit B){
    location loc = Location(0.,0.)
    real max_z, current_z, current_range = 0., x = Gx(A), y = Gy(A), ang = ABU(A, B)
    int step_count = R2I(DBU(A, B) / 25.)
        MoveLocation(loc, x, y)
        max_z = GetLocationZ(loc) + 60.
        MoveLocation(loc, Gx(B), Gy(B))
        max_z += (GetLocationZ(loc) + 60.)
            while(step_count != 0){
                MoveLocation(loc, x, y)
                current_z = GetLocationZ(loc) + 60.
                    if current_z >= max_z { break }
                x += Rx(25.,ang)
                y += Ry(25.,ang)
                current_range += 25.
                step_count--
            }
        RemoveLocation(loc)
    loc = null
    return current_range
}


enum { ALL, ENEMIES }

void DamageUnitsInRange(unit source, real x, real y, real range, real damage, attacktype at, int filter_type) {
unit victim
group g = CG
    if filter_type == ALL { 
        GroupEnumUnitsInRange(g, x, y, range, Filter(function AllFilter)) 
    }
    elseif filter_type == ENEMIES { 
        ForFilter1 = source 
        GroupEnumUnitsInRange(g, x, y, range, Filter(function EnemiesFilter)) 
    }
        while(FirstOfGroup(g) != null) {
            victim = FirstOfGroup(g)
            UnitDamageTarget(source, victim, damage, true, false, at, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            GroupRemoveUnit(g, victim)
        }
    GC(g)
    DG(g)
g = null
victim = null
}
endlibrary
Top