//===========================================================================
// 
// Plains of Snow
// 
//   Warcraft III map script
//   Generated by the Warcraft III World Editor
//   Date: Sat Apr 07 17:05:19 2012
//   Map Author: Blizzard Entertainment
// 
//===========================================================================

//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************

globals
    // User-defined
    real                    udg_x                      = 0
    real                    udg_y                      = 0
    player                  udg_p                      = null

    // Generated
    trigger                 gg_trg_Melee_Initialization = null
    trigger                 gg_trg_Init                = null
    trigger                 gg_trg_ReturnBuildingSpaces = null
    trigger                 gg_trg_Volcano_Temple      = null
    trigger                 gg_trg_DEMONPORTAL         = null
    trigger                 gg_trg_DEMONPORTAL_CANCEL  = null
    trigger                 gg_trg_Exploding_Buildings = null
    trigger                 gg_trg_ClearUp_Buildings   = null
    trigger                 gg_trg_Destroy             = null
    trigger                 gg_trg_SunRescur           = null
    trigger                 gg_trg_TurnToAsh           = null
    trigger                 gg_trg_ReviveAshes         = null
    trigger                 gg_trg_StartHarvest        = null
endglobals

function InitGlobals takes nothing returns nothing
    set udg_x = 0
    set udg_y = 0
endfunction

//***************************************************************************
//*
//*  Unit Item Tables
//*
//***************************************************************************

function Unit000030_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000031_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 6 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000035_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000036_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 6 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000037_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 4 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000039_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000042_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 4 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000044_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000047_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 4 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000048_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 3 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000051_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 1 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000053_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 3 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000054_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 4 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000057_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 1 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000059_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000060_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 3 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000063_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 1 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000065_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 4 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000066_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 3 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000069_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 1 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000073_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000076_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000079_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000082_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000085_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000088_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000091_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000094_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000096_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000099_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000102_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000105_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000108_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000111_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000114_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000117_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 2 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000119_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 6 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000120_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 3 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000125_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 4 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000129_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 3 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000130_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 3 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000134_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 4 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000136_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000137_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000139_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 4 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000147_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000150_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000153_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000156_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function Unit000159_DropItems takes nothing returns nothing
    local widget  trigWidget = null
    local unit    trigUnit   = null
    local integer itemID     = 0
    local boolean canDrop    = true

    set trigWidget = bj_lastDyingWidget
    if (trigWidget == null) then
        set trigUnit = GetTriggerUnit()
    endif

    if (trigUnit != null) then
        set canDrop = not IsUnitHidden(trigUnit)
        if (canDrop and GetChangingUnit() != null) then
            set canDrop = (GetChangingUnitPrevOwner() == Player(PLAYER_NEUTRAL_AGGRESSIVE))
        endif
    endif

    if (canDrop) then
        // Item set 0
        call RandomDistReset(  )
        call RandomDistAddItem( ChooseRandomItem( 5 ), 100 )
        set itemID = RandomDistChoose(  )
        if (trigUnit != null) then
            call UnitDropItem( trigUnit, itemID )
        else
            call WidgetDropItem( trigWidget, itemID )
        endif

    endif

    set bj_lastDyingWidget = null
    call DestroyTrigger(GetTriggeringTrigger())
endfunction


//***************************************************************************
//*
//*  Unit Creation
//*
//***************************************************************************

//===========================================================================
function CreateNeutralHostile takes nothing returns nothing
    local player p = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u = CreateUnit( p, 'nwns', 335.9, -4691.3, 89.060 )
    call SetUnitState( u, UNIT_STATE_MANA, 0 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000031_DropItems )
    set u = CreateUnit( p, 'nfrp', 131.3, -4743.7, 87.791 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nfrp', 569.1, -4711.8, 90.513 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nfrp', 213.1, -4535.3, 88.259 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000030_DropItems )
    set u = CreateUnit( p, 'nfrp', 503.9, -4543.3, 90.109 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nfrp', 705.3, 4897.8, 252.195 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nfrp', 350.1, 4685.1, 321.375 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nfrp', 627.4, 4652.3, 229.815 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nfrp', 249.9, 4897.0, 292.018 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000035_DropItems )
    set u = CreateUnit( p, 'nwns', 490.1, 4834.9, 279.310 )
    call SetUnitState( u, UNIT_STATE_MANA, 0 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000036_DropItems )
    set u = CreateUnit( p, 'nitw', -2121.3, -535.6, 227.220 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000037_DropItems )
    set u = CreateUnit( p, 'nith', -2054.5, -381.1, 351.057 )
    call SetUnitState( u, UNIT_STATE_MANA, 0 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nith', -2057.0, -689.5, 148.250 )
    call SetUnitState( u, UNIT_STATE_MANA, 0 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000039_DropItems )
    set u = CreateUnit( p, 'nitr', -2227.7, -431.6, 215.437 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nitr', -2206.3, -643.2, 102.582 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nitw', 2276.2, -478.6, 227.220 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000042_DropItems )
    set u = CreateUnit( p, 'nith', 2210.0, -259.2, 351.057 )
    call SetUnitState( u, UNIT_STATE_MANA, 0 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nith', 2216.2, -682.4, 148.250 )
    call SetUnitState( u, UNIT_STATE_MANA, 0 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000044_DropItems )
    set u = CreateUnit( p, 'nitr', 2364.1, -297.5, 215.437 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nitr', 2381.1, -613.9, 102.582 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nith', -1614.8, -2145.7, 26.265 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000047_DropItems )
    set u = CreateUnit( p, 'nith', -1308.9, -2399.7, 67.228 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000048_DropItems )
    set u = CreateUnit( p, 'nits', -1454.4, -2021.7, 20.239 )
    set u = CreateUnit( p, 'nits', -1240.9, -2177.1, 63.065 )
    set u = CreateUnit( p, 'nitt', -1405.2, -2208.3, 45.786 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000051_DropItems )
    set u = CreateUnit( p, 'nitt', -1293.6, -2007.3, 30.718 )
    set u = CreateUnit( p, 'nith', 2121.1, -2345.9, 121.455 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000053_DropItems )
    set u = CreateUnit( p, 'nith', 2339.2, -2069.4, 157.645 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000139_DropItems )
    set u = CreateUnit( p, 'nits', 1985.4, -2195.3, 115.790 )
    set u = CreateUnit( p, 'nits', 2124.4, -1970.8, 159.325 )
    set u = CreateUnit( p, 'nitt', 2167.8, -2132.3, 141.457 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000057_DropItems )
    set u = CreateUnit( p, 'nitt', 1959.0, -2036.0, 127.416 )
    set u = CreateUnit( p, 'nith', 2427.7, 1358.0, 220.358 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000054_DropItems )
    set u = CreateUnit( p, 'nith', 2129.2, 1623.6, 255.008 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000060_DropItems )
    set u = CreateUnit( p, 'nits', 2274.3, 1245.4, 222.130 )
    set u = CreateUnit( p, 'nits', 2061.0, 1401.0, 256.043 )
    set u = CreateUnit( p, 'nitt', 2225.3, 1432.1, 240.130 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000063_DropItems )
    set u = CreateUnit( p, 'nitt', 2113.4, 1231.2, 239.593 )
    set u = CreateUnit( p, 'nith', -1425.3, 1397.6, 285.913 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000065_DropItems )
    set u = CreateUnit( p, 'nith', -1788.3, 1235.4, 318.504 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000066_DropItems )
    set u = CreateUnit( p, 'nits', -1384.9, 1199.0, 287.811 )
    set u = CreateUnit( p, 'nits', -1618.6, 1076.1, 319.302 )
    set u = CreateUnit( p, 'nitt', -1574.0, 1237.3, 304.421 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000069_DropItems )
    set u = CreateUnit( p, 'nitt', -1443.0, 1048.3, 304.218 )
    set u = CreateUnit( p, 'nwen', -6747.8, -2360.7, 78.752 )
    set u = CreateUnit( p, 'nwen', -6768.9, -2045.1, 56.351 )
    set u = CreateUnit( p, 'nwnr', -6667.9, -2187.4, 40.980 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000073_DropItems )
    set u = CreateUnit( p, 'nwen', -6666.0, -6831.0, 78.752 )
    set u = CreateUnit( p, 'nwen', -6687.1, -6515.4, 56.351 )
    set u = CreateUnit( p, 'nwnr', -6586.1, -6657.7, 40.980 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000076_DropItems )
    set u = CreateUnit( p, 'nwen', -6842.7, 1979.9, 304.582 )
    set u = CreateUnit( p, 'nwen', -6863.8, 2295.5, 295.554 )
    set u = CreateUnit( p, 'nwnr', -6762.8, 2153.2, 0.000 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000079_DropItems )
    set u = CreateUnit( p, 'nwen', -6412.1, 7096.7, 320.919 )
    set u = CreateUnit( p, 'nwen', -6433.3, 7412.3, 308.702 )
    set u = CreateUnit( p, 'nwnr', -6332.2, 7270.0, 309.334 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000082_DropItems )
    set u = CreateUnit( p, 'nwen', 5781.6, 7112.4, 179.503 )
    set u = CreateUnit( p, 'nwen', 5760.5, 7428.0, 228.200 )
    set u = CreateUnit( p, 'nwnr', 5684.5, 7298.7, 222.027 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000085_DropItems )
    set u = CreateUnit( p, 'nwen', 6944.3, 2290.8, 179.503 )
    set u = CreateUnit( p, 'nwen', 6923.2, 2606.4, 228.200 )
    set u = CreateUnit( p, 'nwnr', 6847.2, 2477.1, 222.027 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000088_DropItems )
    set u = CreateUnit( p, 'nwen', 7333.8, -4251.1, 179.503 )
    set u = CreateUnit( p, 'nwen', 7312.7, -3935.5, 228.200 )
    set u = CreateUnit( p, 'nwnr', 7236.7, -4064.8, 222.027 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000091_DropItems )
    set u = CreateUnit( p, 'nwen', 5724.5, -7482.6, 179.503 )
    set u = CreateUnit( p, 'nwen', 5703.4, -7167.0, 228.200 )
    set u = CreateUnit( p, 'nwnr', 5627.4, -7296.3, 222.027 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000094_DropItems )
    set u = CreateUnit( p, 'nwwf', 3880.5, -5593.6, 305.704 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', 3974.9, -5381.7, 282.910 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000096_DropItems )
    set u = CreateUnit( p, 'nwwf', 4145.5, -5554.8, 79.203 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', 4434.5, -4416.3, 305.704 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', 4563.3, -4351.9, 282.910 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000099_DropItems )
    set u = CreateUnit( p, 'nwwf', 4636.2, -4546.3, 79.203 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', 6702.5, 570.9, 305.704 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', 6556.9, 779.8, 282.910 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000102_DropItems )
    set u = CreateUnit( p, 'nwwf', 6859.7, 868.2, 79.203 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', 2628.5, 7067.1, 305.704 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', 2722.9, 7279.0, 282.910 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000105_DropItems )
    set u = CreateUnit( p, 'nwwf', 2893.5, 7105.9, 79.203 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', -3148.4, 6990.8, 289.379 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', -3049.0, 7210.1, 277.040 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000108_DropItems )
    set u = CreateUnit( p, 'nwwf', -2911.9, 6972.8, 265.574 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', -5873.4, 96.4, 59.107 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', -5713.2, 199.4, 71.945 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000111_DropItems )
    set u = CreateUnit( p, 'nwwf', -5638.2, 5.8, 85.570 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', -5032.4, -4257.9, 305.704 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', -4938.0, -4046.0, 282.910 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000114_DropItems )
    set u = CreateUnit( p, 'nwwf', -4767.4, -4219.1, 79.203 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', -3939.5, -7829.5, 71.752 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwwf', -3845.1, -7617.6, 74.343 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000117_DropItems )
    set u = CreateUnit( p, 'nwwf', -3674.5, -7790.8, 92.695 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nadk', 28.1, -270.7, 97.570 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000119_DropItems )
    set u = CreateUnit( p, 'nadk', 356.8, -608.8, 139.150 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000120_DropItems )
    set u = CreateUnit( p, 'nadw', -73.5, -467.6, 41.563 )
    set u = CreateUnit( p, 'nadw', 208.3, -182.3, 12.624 )
    set u = CreateUnit( p, 'nadw', 474.0, -381.2, 344.443 )
    set u = CreateUnit( p, 'nadw', 123.6, -743.1, 148.518 )
    set u = CreateUnit( p, 'nadk', 310.8, 7686.9, 200.660 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000125_DropItems )
    set u = CreateUnit( p, 'nadw', 188.6, 7796.6, 103.077 )
    set u = CreateUnit( p, 'nadw', 446.2, 7533.0, 92.870 )
    set u = CreateUnit( p, 'nadk', 643.1, 7721.9, 0.000 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000129_DropItems )
    set u = CreateUnit( p, 'nadk', 314.4, -7781.6, 200.660 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000130_DropItems )
    set u = CreateUnit( p, 'nadw', 752.7, 7791.7, 62.756 )
    set u = CreateUnit( p, 'nadw', 192.3, -7671.9, 103.077 )
    set u = CreateUnit( p, 'nadw', 423.1, -7618.9, 92.870 )
    set u = CreateUnit( p, 'nadw', 761.1, -7709.4, 62.756 )
    set u = CreateUnit( p, 'nadk', 646.7, -7746.6, 0.000 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000134_DropItems )
    set u = CreateUnit( p, 'nadw', 201.9, -455.0, 123.380 )
    set u = CreateUnit( p, 'nwnr', -697.0, -6458.9, 154.583 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwen', -980.2, -6486.0, 119.452 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', -935.4, -6786.0, 139.302 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000156_DropItems )
    set u = CreateUnit( p, 'nwnr', -384.3, 6310.9, 181.712 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', 1677.2, -6234.8, 38.736 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000159_DropItems )
    set u = CreateUnit( p, 'nwen', -616.4, 6342.3, 232.760 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', 1956.0, -6520.5, 61.466 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwen', 1944.4, -6236.3, 26.335 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', -685.5, 6556.4, 231.304 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000147_DropItems )
    set u = CreateUnit( p, 'nwnr', 1312.1, 6401.2, 331.635 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwen', 1596.3, 6413.7, 296.503 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', 1537.6, 6655.2, 299.357 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000150_DropItems )
    set u = CreateUnit( p, 'nwnr', 6918.5, 4898.4, 212.041 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwen', 6624.4, 4835.9, 242.338 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', 6661.3, 5127.5, 226.927 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000059_DropItems )
    set u = CreateUnit( p, 'nwnr', -6716.9, 4119.3, 342.211 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwen', -6439.8, 4183.7, 307.080 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', -6538.7, 4384.5, 312.380 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000137_DropItems )
    set u = CreateUnit( p, 'nwnr', -7291.8, -4293.2, 61.466 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwen', -7112.5, -4127.2, 26.335 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', -7334.0, -4033.3, 354.053 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000153_DropItems )
    set u = CreateUnit( p, 'nwnr', 6867.4, -1490.4, 190.564 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwen', 6634.2, -1549.8, 186.667 )
    call SetUnitAcquireRange( u, 200.0 )
    set u = CreateUnit( p, 'nwnr', 6634.5, -1287.2, 228.374 )
    call SetUnitAcquireRange( u, 200.0 )
    set t = CreateTrigger(  )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_DEATH )
    call TriggerRegisterUnitEvent( t, u, EVENT_UNIT_CHANGE_OWNER )
    call TriggerAddAction( t, function Unit000136_DropItems )
endfunction

//===========================================================================
function CreateNeutralPassiveBuildings takes nothing returns nothing
    local player p = Player(PLAYER_NEUTRAL_PASSIVE)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u = CreateUnit( p, 'ngol', -7168.0, -2240.0, 270.000 )
    call SetResourceAmount( u, 19000 )
    set u = CreateUnit( p, 'ngol', -7104.0, -6720.0, 270.000 )
    call SetResourceAmount( u, 19000 )
    set u = CreateUnit( p, 'ngol', -7296.0, 2368.0, 270.000 )
    call SetResourceAmount( u, 19000 )
    set u = CreateUnit( p, 'ngol', -6848.0, 7296.0, 270.000 )
    call SetResourceAmount( u, 19000 )
    set u = CreateUnit( p, 'ngol', 6208.0, 7232.0, 270.000 )
    call SetResourceAmount( u, 19000 )
    set u = CreateUnit( p, 'ngol', 7424.0, 2560.0, 270.000 )
    call SetResourceAmount( u, 19000 )
    set u = CreateUnit( p, 'ngol', 7808.0, -4224.0, 270.000 )
    call SetResourceAmount( u, 19000 )
    set u = CreateUnit( p, 'ngol', 6272.0, -7232.0, 270.000 )
    call SetResourceAmount( u, 19000 )
    set u = CreateUnit( p, 'ngol', 192.0, -448.0, 270.000 )
    call SetResourceAmount( u, 30000 )
    set u = CreateUnit( p, 'ngol', 2496.0, 1792.0, 270.000 )
    call SetResourceAmount( u, 20000 )
    set u = CreateUnit( p, 'ngol', 2496.0, -2432.0, 270.000 )
    call SetResourceAmount( u, 20000 )
    set u = CreateUnit( p, 'ngol', -1856.0, 1600.0, 270.000 )
    call SetResourceAmount( u, 20000 )
    set u = CreateUnit( p, 'ngol', -1664.0, -2560.0, 270.000 )
    call SetResourceAmount( u, 20000 )
    set u = CreateUnit( p, 'ngol', 448.0, -7808.0, 270.000 )
    call SetResourceAmount( u, 20000 )
    set u = CreateUnit( p, 'ngol', 448.0, 7808.0, 270.000 )
    call SetResourceAmount( u, 20000 )
    set u = CreateUnit( p, 'nfoh', -1792.0, -512.0, 270.000 )
    set u = CreateUnit( p, 'nfoh', 1920.0, -512.0, 270.000 )
    set u = CreateUnit( p, 'nmr7', 512.0, 5184.0, 270.000 )
    call SetUnitColor( u, ConvertPlayerColor(3) )
    set u = CreateUnit( p, 'nmr7', 320.0, -4928.0, 270.000 )
    call SetUnitColor( u, ConvertPlayerColor(3) )
endfunction

//===========================================================================
function CreatePlayerBuildings takes nothing returns nothing
endfunction

//===========================================================================
function CreatePlayerUnits takes nothing returns nothing
endfunction

//===========================================================================
function CreateAllUnits takes nothing returns nothing
    call CreateNeutralPassiveBuildings(  )
    call CreatePlayerBuildings(  )
    call CreateNeutralHostile(  )
    call CreatePlayerUnits(  )
endfunction

//***************************************************************************
//*
//*  Triggers
//*
//***************************************************************************

//===========================================================================
// Trigger: Melee Initialization
//
// Default melee game initialization for all players
//===========================================================================
function Trig_Melee_Initialization_Actions takes nothing returns nothing
    call MeleeStartingVisibility(  )
    call MeleeStartingHeroLimit(  )
    call MeleeGrantHeroItems(  )
    call MeleeStartingResources(  )
    call MeleeClearExcessUnits(  )
    call MeleeStartingUnits(  )
    call MeleeStartingAI(  )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call SetPlayerTechMaxAllowedSwap( 'h00D', 1, ConvertedPlayer(GetForLoopIndexA()) )
        call SetPlayerTechMaxAllowedSwap( 'o007', 5, ConvertedPlayer(GetForLoopIndexA()) )
        call SetPlayerTechMaxAllowedSwap( 'H001', 1, ConvertedPlayer(GetForLoopIndexA()) )
        call SetPlayerTechMaxAllowedSwap( 'N003', 1, ConvertedPlayer(GetForLoopIndexA()) )
        call SetPlayerTechMaxAllowedSwap( 'O006', 1, ConvertedPlayer(GetForLoopIndexA()) )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    set gg_trg_Melee_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions )
endfunction

//===========================================================================
// Trigger: Init
//===========================================================================
//TESH.scrollpos=26
//TESH.alwaysfold=0
package Init
    public hashtable prizes
    
    function newvolcanosend()
        if GetUnitTypeId(GetConstructedStructure()) == 'h000' 
            newvolcano(GetConstructedStructure(),GetOwningPlayer(GetConstructedStructure()))
        
    function newvolcano(unit volcano,player p)
        real x = GetUnitX(volcano)
        real y = GetUnitY(volcano)
        SetBlightLoc(p, Location(x,y), 750.00 , true )
        unit plot1 = CreateUnit(p,'h007',x+256,y,bj_UNIT_FACING)
        plot1 = CreateUnit(p,'h007',x-256,y,bj_UNIT_FACING)
        plot1 = CreateUnit(p,'h007',x+192,y-192,bj_UNIT_FACING)
        plot1 = CreateUnit(p,'h007',x-192,y-192,bj_UNIT_FACING)
        plot1 = CreateUnit(p,'h007',x,y-256,bj_UNIT_FACING)
        plot1 = CreateUnit(p,'h007',x-128,y+192,bj_UNIT_FACING)
        plot1 = CreateUnit(p,'h007',x+128,y+192,bj_UNIT_FACING)
        //SetTerrainType( x,y, 'Ndrd', -1, 6, 0 )
        for int i=0 to 15
            SetTerrainType( GetRandomReal(x-512,x+512),GetRandomReal(y-512,y+512), 'Dlvc', -1, 1, 0 )
    
    function fireSetUp(player p)
        if GetPlayerController(p) == MAP_CONTROL_USER
            ForGroup( GetUnitsOfPlayerAll(p), function remove)
            unit volcano = CreateUnit(p,'h000',GetStartLocationX(GetPlayerStartLocation(p)),GetStartLocationY(GetPlayerStartLocation(p)),bj_UNIT_FACING)
            newvolcano(volcano,p)
            for int i = 0 to 3
                CreateUnit(p,'e001',GetStartLocationX(GetPlayerStartLocation(p))+300,GetStartLocationY(GetPlayerStartLocation(p)),bj_UNIT_FACING)
                
    function remove()
        if GetUnitTypeId(GetEnumUnit()) != '0000' 
            RemoveUnit(GetEnumUnit())
    
    function initPrizes()
        prizes = InitHashtable()
        SaveInteger(prizes,'h004',0,15)
        SaveInteger(prizes,'h004',1,10)
    init
        initPrizes()
        fireSetUp(Player(0))
        fireSetUp(Player(1))
        trigger t = CreateTrigger()
        TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_CONSTRUCT_FINISH)
        TriggerAddAction(t,function newvolcanosend)

endpackage //===========================================================================
// Trigger: ReturnBuildingSpaces
//===========================================================================
function Trig_ReturnBuildingSpaces_Func002C takes nothing returns boolean
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h008' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h005' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h00A' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h006' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h004' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'u002' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'u003' ) ) then
        return true
    endif
    return false
endfunction

function Trig_ReturnBuildingSpaces_Conditions takes nothing returns boolean
    if ( not Trig_ReturnBuildingSpaces_Func002C() ) then
        return false
    endif
    return true
endfunction

function Trig_ReturnBuildingSpaces_Func001Func003Func003C takes nothing returns boolean
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h00A' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h005' ) ) then
        return true
    endif
    return false
endfunction

function Trig_ReturnBuildingSpaces_Func001Func003C takes nothing returns boolean
    if ( not Trig_ReturnBuildingSpaces_Func001Func003Func003C() ) then
        return false
    endif
    return true
endfunction

function Trig_ReturnBuildingSpaces_Func001Func004C takes nothing returns boolean
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h009' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'o005' ) ) then
        return true
    endif
    return false
endfunction

function Trig_ReturnBuildingSpaces_Func001C takes nothing returns boolean
    if ( not Trig_ReturnBuildingSpaces_Func001Func004C() ) then
        return false
    endif
    return true
endfunction

function Trig_ReturnBuildingSpaces_Actions takes nothing returns nothing
    if ( Trig_ReturnBuildingSpaces_Func001C() ) then
        call AddSpecialEffectLocBJ( GetUnitLoc(GetDyingUnit()), "Objects\\Spawnmodels\\Human\\HCancelDeath\\HCancelDeath.mdl" )
        call RemoveUnit( GetDyingUnit() )
    else
        if ( Trig_ReturnBuildingSpaces_Func001Func003C() ) then
            call AddSpecialEffectLocBJ( GetUnitLoc(GetDyingUnit()), "Objects\\Spawnmodels\\Human\\HCancelDeath\\HCancelDeath.mdl" )
            set udg_x = GetLocationX(GetUnitLoc(GetDyingUnit()))
            set udg_y = GetLocationY(GetUnitLoc(GetDyingUnit()))
            set udg_p = GetOwningPlayer(GetDyingUnit())
            call RemoveUnit( GetDyingUnit() )
            call TriggerSleepAction( 3.00 )
            call CreateNUnitsAtLoc( 1, 'h007', udg_p, Location(udg_x, udg_y), bj_UNIT_FACING )
        else
            call TriggerSleepAction( 3.00 )
            call CreateNUnitsAtLoc( 1, 'h007', GetOwningPlayer(GetDyingUnit()), GetUnitLoc(GetDyingUnit()), bj_UNIT_FACING )
        endif
    endif
endfunction

//===========================================================================
function InitTrig_ReturnBuildingSpaces takes nothing returns nothing
    set gg_trg_ReturnBuildingSpaces = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ReturnBuildingSpaces, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_ReturnBuildingSpaces, Condition( function Trig_ReturnBuildingSpaces_Conditions ) )
    call TriggerAddAction( gg_trg_ReturnBuildingSpaces, function Trig_ReturnBuildingSpaces_Actions )
endfunction

//===========================================================================
// Trigger: Volcano Temple
//===========================================================================
function Trig_Volcano_Temple_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTrainedUnit()) == 'h00D' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Volcano_Temple_Actions takes nothing returns nothing
    call SetUnitPositionLoc( GetTrainedUnit(), GetUnitLoc(GetTriggerUnit()) )
    call SetUnitAnimation( GetTrainedUnit(), "stand" )
    call TriggerSleepAction( 2 )
    call RemoveUnitFromStockBJ( 'h00D', GetTriggerUnit() )
endfunction

//===========================================================================
function InitTrig_Volcano_Temple takes nothing returns nothing
    set gg_trg_Volcano_Temple = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Volcano_Temple, EVENT_PLAYER_UNIT_TRAIN_FINISH )
    call TriggerAddCondition( gg_trg_Volcano_Temple, Condition( function Trig_Volcano_Temple_Conditions ) )
    call TriggerAddAction( gg_trg_Volcano_Temple, function Trig_Volcano_Temple_Actions )
endfunction

//===========================================================================
// Trigger: DEMONPORTAL
//===========================================================================
function Trig_DEMONPORTAL_Func001Func001Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'u002' ) ) then
        return false
    endif
    return true
endfunction

function Trig_DEMONPORTAL_Func001Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'h004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_DEMONPORTAL_Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'h00A' ) ) then
        return false
    endif
    return true
endfunction

function Trig_DEMONPORTAL_Func001Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'h008' ) ) then
        return false
    endif
    return true
endfunction

function Trig_DEMONPORTAL_Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'u003' ) ) then
        return false
    endif
    return true
endfunction

function Trig_DEMONPORTAL_Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'h005' ) ) then
        return false
    endif
    return true
endfunction

function Trig_DEMONPORTAL_Actions takes nothing returns nothing
    if ( Trig_DEMONPORTAL_Func001C() ) then
        call SetUnitScalePercent( GetTriggerUnit(), 30.00, 30.00, 30.00 )
    else
        if ( Trig_DEMONPORTAL_Func001Func001C() ) then
            call SetUnitScalePercent( GetTriggerUnit(), 80.00, 80.00, 80.00 )
        else
            if ( Trig_DEMONPORTAL_Func001Func001Func001C() ) then
                call SetUnitScalePercent( GetTriggerUnit(), 90.00, 90.00, 90.00 )
            else
                if ( Trig_DEMONPORTAL_Func001Func001Func001Func001C() ) then
                    call SetUnitScalePercent( GetTriggerUnit(), 100.00, 100.00, 100.00 )
                else
                    if ( Trig_DEMONPORTAL_Func001Func001Func001Func001Func001C() ) then
                        call SetUnitScalePercent( GetTriggerUnit(), 90.00, 90.00, 90.00 )
                    else
                        if ( Trig_DEMONPORTAL_Func001Func001Func001Func001Func001Func001C() ) then
                            call SetUnitScalePercent( GetTriggerUnit(), 90.00, 90.00, 90.00 )
                        else
                        endif
                    endif
                endif
            endif
        endif
    endif
endfunction

//===========================================================================
function InitTrig_DEMONPORTAL takes nothing returns nothing
    set gg_trg_DEMONPORTAL = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_DEMONPORTAL, EVENT_PLAYER_UNIT_UPGRADE_START )
    call TriggerAddAction( gg_trg_DEMONPORTAL, function Trig_DEMONPORTAL_Actions )
endfunction

//===========================================================================
// Trigger: DEMONPORTAL CANCEL
//===========================================================================
function Trig_DEMONPORTAL_CANCEL_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'h007' ) ) then
        return false
    endif
    return true
endfunction

function Trig_DEMONPORTAL_CANCEL_Actions takes nothing returns nothing
    call SetUnitScalePercent( GetTriggerUnit(), 120.00, 120.00, 120.00 )
endfunction

//===========================================================================
function InitTrig_DEMONPORTAL_CANCEL takes nothing returns nothing
    set gg_trg_DEMONPORTAL_CANCEL = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_DEMONPORTAL_CANCEL, EVENT_PLAYER_UNIT_UPGRADE_CANCEL )
    call TriggerAddCondition( gg_trg_DEMONPORTAL_CANCEL, Condition( function Trig_DEMONPORTAL_CANCEL_Conditions ) )
    call TriggerAddAction( gg_trg_DEMONPORTAL_CANCEL, function Trig_DEMONPORTAL_CANCEL_Actions )
endfunction

//===========================================================================
// Trigger: Exploding Buildings
//===========================================================================
function Trig_Exploding_Buildings_Conditions takes nothing returns boolean
    if ( not ( GetUnitAbilityLevelSwapped('A00U', GetTriggerUnit()) > 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Exploding_Buildings_Func002Func001C takes nothing returns boolean
    if ( not ( IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(GetDyingUnit())) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Exploding_Buildings_Func002A takes nothing returns nothing
    if ( Trig_Exploding_Buildings_Func002Func001C() ) then
        call UnitDamageTargetBJ( GetDyingUnit(), GetEnumUnit(), 200.00, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_FIRE )
    else
    endif
endfunction

function Trig_Exploding_Buildings_Actions takes nothing returns nothing
    call AddSpecialEffectLocBJ( GetUnitLoc(GetDyingUnit()), "Abilities\\Spells\\Other\\Incinerate\\FireLordDeathExplode.mdl" )
    call ForGroupBJ( GetUnitsInRangeOfLocAll(250.00, GetUnitLoc(GetDyingUnit())), function Trig_Exploding_Buildings_Func002A )
endfunction

//===========================================================================
function InitTrig_Exploding_Buildings takes nothing returns nothing
    set gg_trg_Exploding_Buildings = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Exploding_Buildings, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Exploding_Buildings, Condition( function Trig_Exploding_Buildings_Conditions ) )
    call TriggerAddAction( gg_trg_Exploding_Buildings, function Trig_Exploding_Buildings_Actions )
endfunction

//===========================================================================
// Trigger: ClearUp Buildings
//===========================================================================
function Trig_ClearUp_Buildings_Func004C takes nothing returns boolean
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h000' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h00B' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(GetDyingUnit()) == 'h00C' ) ) then
        return true
    endif
    return false
endfunction

function Trig_ClearUp_Buildings_Conditions takes nothing returns boolean
    if ( not Trig_ClearUp_Buildings_Func004C() ) then
        return false
    endif
    return true
endfunction

function Trig_ClearUp_Buildings_Func001Func001C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetEnumUnit()) == GetOwningPlayer(GetDyingUnit()) ) ) then
        return false
    endif
    return true
endfunction

function Trig_ClearUp_Buildings_Func001A takes nothing returns nothing
    if ( Trig_ClearUp_Buildings_Func001Func001C() ) then
        call KillUnit( GetEnumUnit() )
    else
    endif
endfunction

function Trig_ClearUp_Buildings_Func003Func001C takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetEnumUnit()) == GetOwningPlayer(GetDyingUnit()) ) ) then
        return false
    endif
    if ( not ( GetUnitTypeId(GetEnumUnit()) == 'h007' ) ) then
        return false
    endif
    return true
endfunction

function Trig_ClearUp_Buildings_Func003A takes nothing returns nothing
    if ( Trig_ClearUp_Buildings_Func003Func001C() ) then
        call RemoveUnit( GetEnumUnit() )
    else
    endif
endfunction

function Trig_ClearUp_Buildings_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsInRangeOfLocAll(512, GetUnitLoc(GetDyingUnit())), function Trig_ClearUp_Buildings_Func001A )
    call TriggerSleepAction( 3.10 )
    call ForGroupBJ( GetUnitsInRangeOfLocAll(512, GetUnitLoc(GetDyingUnit())), function Trig_ClearUp_Buildings_Func003A )
endfunction

//===========================================================================
function InitTrig_ClearUp_Buildings takes nothing returns nothing
    set gg_trg_ClearUp_Buildings = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ClearUp_Buildings, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_ClearUp_Buildings, Condition( function Trig_ClearUp_Buildings_Conditions ) )
    call TriggerAddAction( gg_trg_ClearUp_Buildings, function Trig_ClearUp_Buildings_Actions )
endfunction

//===========================================================================
// Trigger: Destroy
//===========================================================================
function Trig_Destroy_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A011' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Destroy_Actions takes nothing returns nothing
    call KillUnit( GetSpellAbilityUnit() )
    call AdjustPlayerStateBJ( 113, GetOwningPlayer(GetSpellAbilityUnit()), PLAYER_STATE_RESOURCE_GOLD )
endfunction

//===========================================================================
function InitTrig_Destroy takes nothing returns nothing
    set gg_trg_Destroy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Destroy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Destroy, Condition( function Trig_Destroy_Conditions ) )
    call TriggerAddAction( gg_trg_Destroy, function Trig_Destroy_Actions )
endfunction

//===========================================================================
// Trigger: SunRescur
//===========================================================================
//TESH.scrollpos=12
//TESH.alwaysfold=0
package SunRescur
    import ReviveAshes
    int i

    function heal()
        if  IsUnitType(GetTriggerUnit(), UNIT_TYPE_UNDEAD) == false and IsPlayerAlly(GetOwningPlayer(GetSpellAbilityUnit()), GetOwningPlayer(GetEnumUnit())) == true and IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == false
            SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + 50.00 ) )
        else if IsUnitType(GetTriggerUnit(), UNIT_TYPE_UNDEAD) == true and IsPlayerAlly(GetOwningPlayer(GetSpellAbilityUnit()), GetOwningPlayer(GetEnumUnit())) == false
            SetUnitLifeBJ( GetEnumUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) - 30.00 ) )
/////////////////////////////////////////
        if i >0
            if LoadInteger(fromash,GetUnitTypeId(GetEnumUnit()),0) != 0
                if GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()),PLAYER_STATE_RESOURCE_FOOD_CAP) > GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()),PLAYER_STATE_RESOURCE_FOOD_USED)+GetFoodUsed( LoadInteger(fromash,GetUnitTypeId(GetEnumUnit()),0)-1)
                    SetUnitOwner(GetEnumUnit(),GetOwningPlayer(GetSpellAbilityUnit()),true)
                    ReplaceUnitBJ( GetEnumUnit(), LoadInteger(fromash,GetUnitTypeId(GetEnumUnit()),0), bj_UNIT_STATE_METHOD_DEFAULTS )
                    AddSpecialEffectLocBJ( GetRectCenter(GetPlayableMapRect()), "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl" )
                    DestroyEffectBJ( GetLastCreatedEffectBJ() )
                    i--
    
    function pickgroup()
        if GetSpellAbilityId() == 'A00Q' 
            for int ii = 0 to 3
                ForGroupBJ( GetUnitsInRangeOfLocAll(900.00, GetUnitLoc(GetSpellAbilityUnit())), function heal )
                i = 2
                TriggerSleepAction(1.27)
//===========================================================================
    init
        gg_trg_SunRescur = CreateTrigger(  )
        TriggerRegisterAnyUnitEventBJ( gg_trg_SunRescur, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        TriggerAddAction( gg_trg_SunRescur, function pickgroup )

endpackage
//===========================================================================
// Trigger: TurnToAsh
//===========================================================================
//TESH.scrollpos=51
//TESH.alwaysfold=0
package TurnToAsh
    import TimerUtils
    hashtable toash
    hashtable ht
    integer counter

    function check1() returns boolean
        if LoadInteger(toash,GetUnitTypeId(GetFilterUnit()),0) != 0
            if not(UnitHasBuffBJ(GetFilterUnit(), 'B000'))
                return true
        return false

    function check2() returns boolean
        if LoadInteger(toash,GetUnitTypeId(GetFilterUnit()),0) != 0
            if UnitHasBuffBJ(GetFilterUnit(), 'B000')
                return true
        return false

    function burn1()
        unit u = GetEnumUnit()
        real substr = LoadReal(toash,GetUnitTypeId(u),1)
        if  GetPlayerTechCount(GetOwningPlayer(u),'R007',true) == 1
            substr = substr*0.8
        if GetPlayerState(GetOwningPlayer(GetEnumUnit()),PLAYER_STATE_RESOURCE_LUMBER) > 0
            SetPlayerState(GetOwningPlayer(GetEnumUnit()),PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(GetOwningPlayer(GetEnumUnit()),PLAYER_STATE_RESOURCE_LUMBER)-(GetUnitFoodUsed(GetEnumUnit())))
        else
            if GetUnitState(u,UNIT_STATE_LIFE) > substr
                SetUnitLifeBJ( u, ( GetUnitState(u,UNIT_STATE_LIFE)) - substr )
            else
                KillUnit(u)

    function burn2()
        if GetPlayerState(GetOwningPlayer(GetEnumUnit()),PLAYER_STATE_RESOURCE_LUMBER) > 0
            int i = R2I(I2R(GetUnitFoodUsed(GetEnumUnit()))/4+0.5)
            SetPlayerState(GetOwningPlayer(GetEnumUnit()),PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(GetOwningPlayer(GetEnumUnit()),PLAYER_STATE_RESOURCE_LUMBER)-i)
                                    
            
    function burnchoose()
        ForGroup( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function check1)), function burn1)
        ForGroup( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function check2)), function burn2)
        
    function turn(unit u)
        if LoadInteger(toash,GetUnitTypeId(u),0) != 0 and GetUnitTypeId(u) != 'u004'
            unit v = CreateUnit(GetOwningPlayer(u),LoadInteger(toash,GetUnitTypeId(u),0),GetUnitX(u),GetUnitY(u),GetUnitFacing(u))
            SetUnitTimeScale(v,0)
            RemoveUnit(u)
            
    function toturn()
        turn(GetDyingUnit())

    function turnToAshInit()
        ht = InitHashtable()
        toash = InitHashtable()
        SaveInteger(toash,'e002',0,'e003')
        SaveReal(toash,'e002',1, 6.)
        SaveInteger(toash,'o000',0,'o002')
        SaveReal(toash,'o000',1,8.)
        SaveInteger(toash,'o001',0,'o003')
        SaveReal(toash,'o001',1,20)
        SaveInteger(toash,'n001',0,'n004')
        SaveReal(toash,'n001',1,10)
        SaveInteger(toash,'u001',0,'u005')
        SaveReal(toash,'u001',1,9)
        SaveInteger(toash,'u004',0,'u000')
        SaveReal(toash,'u004',1,6)
        SaveInteger(toash,'o004',0,'o009')
        SaveReal(toash,'o001',1,6)
        SaveInteger(toash,'h002',0,'h00E')
        SaveReal(toash,'h002',1,8)
        SaveInteger(toash,'n000',0,'n005')
        SaveReal(toash,'n005',1,9)
    //===========================================================================
    init
        turnToAshInit()
        gg_trg_TurnToAsh = CreateTrigger(  )
        TriggerRegisterTimerEvent( gg_trg_TurnToAsh, 0.50 ,true)
        TriggerAddAction( gg_trg_TurnToAsh, function burnchoose )
        trigger t = CreateTrigger()
        TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DEATH)
        TriggerAddAction(t, function toturn)
        
endpackage

//===========================================================================
// Trigger: ReviveAshes
//===========================================================================
//TESH.scrollpos=6
//TESH.alwaysfold=0
package ReviveAshes
    public hashtable fromash
    
    function revive()
        if GetSpellAbilityId() == 'A00B'  or GetSpellAbilityId() == 'A00X'  
            if LoadInteger(fromash,GetUnitTypeId(GetSpellTargetUnit()),0) != 0
                if GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()),PLAYER_STATE_RESOURCE_FOOD_CAP) > GetPlayerState(GetOwningPlayer(GetSpellAbilityUnit()),PLAYER_STATE_RESOURCE_FOOD_USED)+GetFoodUsed( LoadInteger(fromash,GetUnitTypeId(GetSpellTargetUnit()),0)-1)
                    SetUnitOwner(GetEnumUnit(),GetOwningPlayer(GetSpellAbilityUnit()),true)
                    unit u = ReplaceUnitBJ( GetSpellTargetUnit(), LoadInteger(fromash,GetUnitTypeId(GetSpellTargetUnit()),0), bj_UNIT_STATE_METHOD_DEFAULTS )
                    SetUnitOwner(u,GetOwningPlayer(GetSpellAbilityUnit()),true)
                    if GetSpellAbilityId() == 'A00B'
                        RemoveUnit(GetSpellAbilityUnit())
                else
                    DisplayTimedTextToPlayer( GetOwningPlayer(GetSpellAbilityUnit()),100,100, 30, "|cffffcc00 Not Enough Food!|r" )
            else
                DisplayTimedTextToPlayer( GetOwningPlayer(GetSpellAbilityUnit()),0,0, 30, "|cffffcc00 Can't target this unit!|r" )
                
    function initReviveAshes()
        fromash = InitHashtable()
        SaveInteger(fromash,'e003',0,'e002')
        SaveInteger(fromash,'o003',0,'o001')
        SaveInteger(fromash,'o002',0,'o000')
        SaveInteger(fromash,'n004',0,'n001')
        SaveInteger(fromash,'u005',0,'u001')
        SaveInteger(fromash,'u000',0,'u004')
        SaveInteger(fromash,'o009',0,'o004')
        SaveInteger(fromash,'h00E',0,'h002')
        SaveInteger(fromash,'n005',0,'n000')
    //===========================================================================
    init
        initReviveAshes()
        gg_trg_ReviveAshes = CreateTrigger(  )
        TriggerRegisterAnyUnitEventBJ( gg_trg_ReviveAshes, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        TriggerAddAction( gg_trg_ReviveAshes, function revive )


endpackage //===========================================================================
// Trigger: StartHarvest
//===========================================================================
//TESH.scrollpos=66
//TESH.alwaysfold=0
package Harvest
    import Init
    import Maths
    import LinkedListModule
    import TimerUtils
    
    public class Burningtrees
        use LinkedListModule
        destructable d
        player p
        real rate
        unit harvester
        unit owner
        
        construct (unit u, destructable des,unit casting)
            d = des
            harvester = u
            p = GetOwningPlayer(u)
            rate = 2.5
            owner = casting
            
        function decreaselife()
            if GetDestructableLife(d) < rate
                KillDestructable(d)
            else
                SetDestructableLife(d,GetDestructableLife(d)-rate)
        
        ondestroy
            RemoveUnit(harvester)
//////////////////////////////////////////////////////////////////////////////////////Q\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
            
    function isBusy(destructable dest) returns boolean
        Burningtrees tree = Burningtrees.getFirst()
        while tree != null
            if tree.d == dest
                return false
            else
                tree = tree.next
        return true
        
    function checkifavailable() returns boolean
        if GetDestructableTypeId(GetFilterDestructable()) == 'WTst'
            if (GetDestructableLife(GetFilterDestructable()) > 0)
                if isBusy(GetFilterDestructable())
                    return true
        return false
    
    function startburning()
        unit caster = GetSpellAbilityUnit()
        if GetSpellAbilityId() == 'A00N' 
            destructable d = GetSpellTargetDestructable()
            SetDestructableLife(d,GetDestructableLife(d)-0.01)
            SetDestructableLife(d,GetDestructableLife(d)+0.01)
            unit u = CreateUnitAtLoc(GetOwningPlayer(caster), 'e000' , Location(GetDestructableX(d),GetDestructableY(d)),0.)
            Burningtrees tree = new Burningtrees(u,d, caster)
            SetBlightLoc(GetOwningPlayer(u), Location(GetDestructableX(d),GetDestructableY(d)), 64.00 , true )
            SetBlightLoc(GetOwningPlayer(u), Location(GetDestructableX(d),GetDestructableY(d)), 66.00 , false)
            TriggerSleepAction(0.01)
            IssueTargetOrder(u, "harvest", d)

            
    function extend(real x, real y,player p,unit owner)
        unit u2
        destructable d = RandomDestructableInRectBJ(Rect(x-180, y-180, x+180, y+180), Condition(function checkifavailable))
        if  distanceBetweenCoords(GetDestructableX(d),GetDestructableY(d),GetUnitX(owner),GetUnitY(owner)) < 1200. and d != null
            u2 = CreateUnitAtLoc(p, 'e000' , Location(GetDestructableX(d),GetDestructableY(d)),0.)
            SetBlightLoc(p, Location(GetDestructableX(d),GetDestructableY(d)), 64.00 , true )
            SetBlightLoc(p, Location(GetDestructableX(d),GetDestructableY(d)), 66.00 , false)
            TriggerSleepAction(0.01)
            IssueTargetOrder(u2, "harvest", d)
            Burningtrees tree = new Burningtrees(u2,d,owner)
        else 
            d = RandomDestructableInRectBJ(Rect(GetUnitX(owner)-700, GetUnitY(owner)-700, GetUnitX(owner)+700, GetUnitY(owner)+700), Condition(function checkifavailable))
            if d != null
                u2 = CreateUnitAtLoc(p, 'e000' , Location(GetDestructableX(d),GetDestructableY(d)),0.)
                SetBlightLoc(p, Location(GetDestructableX(d),GetDestructableY(d)), 64.00 , true )
                SetBlightLoc(p, Location(GetDestructableX(d),GetDestructableY(d)), 66.00 , false)
                TriggerSleepAction(0.01)
                IssueTargetOrder(u2, "harvest", d)
                Burningtrees tree = new Burningtrees(u2,d,owner)
    
    function foreachtree()
        Burningtrees tree = Burningtrees.getFirst()
        
        while tree != null
            if GetDestructableLife(tree.d) <= tree.rate 
                KillDestructable(tree.d)
                extend(GetUnitX(tree.harvester),GetUnitY(tree.harvester),tree.p,tree.owner)
                destroy tree
                tree = Burningtrees.getFirst()
            else
                tree.decreaselife()
                if GetRandomInt(1,400)<7 + 4*(GetPlayerTechCount(tree.p,'R009',true))
                    extend(GetDestructableX(tree.d),GetDestructableY(tree.d),tree.p,tree.owner)
                tree = tree.next
                
    function removefires()
        unit keyunit =GetDyingUnit()
        Burningtrees tree = Burningtrees.getFirst()

        while tree != null
            if tree.owner == keyunit
                destroy tree
                tree =Burningtrees.getFirst()
            else
                tree = tree.next

    init
        trigger t = CreateTrigger(  )
        trigger t2 = CreateTrigger()
        trigger t3 = CreateTrigger()
        TriggerRegisterTimerEvent(t2,1.8,true)
        //TriggerRegisterDestDeathInRegionEvent( t2, GetPlayableMapRect() )
        TriggerRegisterAnyUnitEventBJ( t3, EVENT_PLAYER_UNIT_DEATH)
        TriggerAddAction( t3, function removefires )
        TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        TriggerAddAction( t, function startburning )
        TriggerAddAction(t2,function foreachtree)

endpackage
//===========================================================================
function InitCustomTriggers takes nothing returns nothing
    call InitTrig_Melee_Initialization(  )
    call InitTrig_Init(  )
    call InitTrig_ReturnBuildingSpaces(  )
    call InitTrig_Volcano_Temple(  )
    call InitTrig_DEMONPORTAL(  )
    call InitTrig_DEMONPORTAL_CANCEL(  )
    call InitTrig_Exploding_Buildings(  )
    call InitTrig_ClearUp_Buildings(  )
    call InitTrig_Destroy(  )
    call InitTrig_SunRescur(  )
    call InitTrig_TurnToAsh(  )
    call InitTrig_ReviveAshes(  )
    call InitTrig_StartHarvest(  )
endfunction

//===========================================================================
function RunInitializationTriggers takes nothing returns nothing
    call ConditionalTriggerExecute( gg_trg_Melee_Initialization )
endfunction

//***************************************************************************
//*
//*  Players
//*
//***************************************************************************

function InitCustomPlayerSlots takes nothing returns nothing

    // Player 0
    call SetPlayerStartLocation( Player(0), 0 )
    call SetPlayerColor( Player(0), ConvertPlayerColor(0) )
    call SetPlayerRacePreference( Player(0), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(0), true )
    call SetPlayerController( Player(0), MAP_CONTROL_USER )

    // Player 1
    call SetPlayerStartLocation( Player(1), 1 )
    call SetPlayerColor( Player(1), ConvertPlayerColor(1) )
    call SetPlayerRacePreference( Player(1), RACE_PREF_ORC )
    call SetPlayerRaceSelectable( Player(1), true )
    call SetPlayerController( Player(1), MAP_CONTROL_USER )

    // Player 2
    call SetPlayerStartLocation( Player(2), 2 )
    call SetPlayerColor( Player(2), ConvertPlayerColor(2) )
    call SetPlayerRacePreference( Player(2), RACE_PREF_UNDEAD )
    call SetPlayerRaceSelectable( Player(2), true )
    call SetPlayerController( Player(2), MAP_CONTROL_USER )

    // Player 3
    call SetPlayerStartLocation( Player(3), 3 )
    call SetPlayerColor( Player(3), ConvertPlayerColor(3) )
    call SetPlayerRacePreference( Player(3), RACE_PREF_NIGHTELF )
    call SetPlayerRaceSelectable( Player(3), true )
    call SetPlayerController( Player(3), MAP_CONTROL_USER )

    // Player 4
    call SetPlayerStartLocation( Player(4), 4 )
    call SetPlayerColor( Player(4), ConvertPlayerColor(4) )
    call SetPlayerRacePreference( Player(4), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(4), true )
    call SetPlayerController( Player(4), MAP_CONTROL_USER )

    // Player 5
    call SetPlayerStartLocation( Player(5), 5 )
    call SetPlayerColor( Player(5), ConvertPlayerColor(5) )
    call SetPlayerRacePreference( Player(5), RACE_PREF_ORC )
    call SetPlayerRaceSelectable( Player(5), true )
    call SetPlayerController( Player(5), MAP_CONTROL_USER )

    // Player 6
    call SetPlayerStartLocation( Player(6), 6 )
    call SetPlayerColor( Player(6), ConvertPlayerColor(6) )
    call SetPlayerRacePreference( Player(6), RACE_PREF_UNDEAD )
    call SetPlayerRaceSelectable( Player(6), true )
    call SetPlayerController( Player(6), MAP_CONTROL_USER )

    // Player 7
    call SetPlayerStartLocation( Player(7), 7 )
    call SetPlayerColor( Player(7), ConvertPlayerColor(7) )
    call SetPlayerRacePreference( Player(7), RACE_PREF_NIGHTELF )
    call SetPlayerRaceSelectable( Player(7), true )
    call SetPlayerController( Player(7), MAP_CONTROL_USER )

endfunction

function InitCustomTeams takes nothing returns nothing
    // Force: TRIGSTR_012
    call SetPlayerTeam( Player(0), 0 )
    call SetPlayerTeam( Player(1), 0 )
    call SetPlayerTeam( Player(2), 0 )
    call SetPlayerTeam( Player(3), 0 )
    call SetPlayerTeam( Player(4), 0 )
    call SetPlayerTeam( Player(5), 0 )
    call SetPlayerTeam( Player(6), 0 )
    call SetPlayerTeam( Player(7), 0 )

endfunction

function InitAllyPriorities takes nothing returns nothing

    call SetStartLocPrioCount( 0, 2 )
    call SetStartLocPrio( 0, 0, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 1, 2, MAP_LOC_PRIO_LOW )

    call SetStartLocPrioCount( 1, 2 )
    call SetStartLocPrio( 1, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 1, 2, MAP_LOC_PRIO_LOW )

    call SetStartLocPrioCount( 2, 2 )
    call SetStartLocPrio( 2, 0, 1, MAP_LOC_PRIO_LOW )
    call SetStartLocPrio( 2, 1, 3, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 3, 2 )
    call SetStartLocPrio( 3, 0, 1, MAP_LOC_PRIO_LOW )
    call SetStartLocPrio( 3, 1, 2, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 4, 2 )
    call SetStartLocPrio( 4, 0, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 1, 6, MAP_LOC_PRIO_LOW )

    call SetStartLocPrioCount( 5, 2 )
    call SetStartLocPrio( 5, 0, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 1, 6, MAP_LOC_PRIO_LOW )

    call SetStartLocPrioCount( 6, 2 )
    call SetStartLocPrio( 6, 0, 5, MAP_LOC_PRIO_LOW )
    call SetStartLocPrio( 6, 1, 7, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 7, 2 )
    call SetStartLocPrio( 7, 0, 5, MAP_LOC_PRIO_LOW )
    call SetStartLocPrio( 7, 1, 6, MAP_LOC_PRIO_HIGH )
endfunction

//***************************************************************************
//*
//*  Main Initialization
//*
//***************************************************************************

//===========================================================================
function main takes nothing returns nothing
    call SetCameraBounds( -8192.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), -8192.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 8192.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 8192.0 - GetCameraMargin(CAMERA_MARGIN_TOP), -8192.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 8192.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 8192.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), -8192.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM) )
    call SetDayNightModels( "Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl", "Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl" )
    call NewSoundEnvironment( "Default" )
    call SetAmbientDaySound( "NorthrendDay" )
    call SetAmbientNightSound( "NorthrendNight" )
    call SetMapMusic( "Music", true, 0 )
    call CreateAllUnits(  )
    call InitBlizzard(  )
    call InitGlobals(  )
    call InitCustomTriggers(  )
    call RunInitializationTriggers(  )

endfunction

//***************************************************************************
//*
//*  Map Configuration
//*
//***************************************************************************

function config takes nothing returns nothing
    call SetMapName( "TRIGSTR_001" )
    call SetMapDescription( "TRIGSTR_013" )
    call SetPlayers( 8 )
    call SetTeams( 8 )
    call SetGamePlacement( MAP_PLACEMENT_TEAMS_TOGETHER )

    call DefineStartLocation( 0, 5440.0, -7296.0 )
    call DefineStartLocation( 1, 7040.0, -4160.0 )
    call DefineStartLocation( 2, 6656.0, 2368.0 )
    call DefineStartLocation( 3, 5440.0, 6976.0 )
    call DefineStartLocation( 4, -6080.0, 7168.0 )
    call DefineStartLocation( 5, -6592.0, 1920.0 )
    call DefineStartLocation( 6, -6400.0, -2112.0 )
    call DefineStartLocation( 7, -6336.0, -6656.0 )

    // Player setup
    call InitCustomPlayerSlots(  )
    call SetPlayerSlotAvailable( Player(0), MAP_CONTROL_USER )
    call SetPlayerSlotAvailable( Player(1), MAP_CONTROL_USER )
    call SetPlayerSlotAvailable( Player(2), MAP_CONTROL_USER )
    call SetPlayerSlotAvailable( Player(3), MAP_CONTROL_USER )
    call SetPlayerSlotAvailable( Player(4), MAP_CONTROL_USER )
    call SetPlayerSlotAvailable( Player(5), MAP_CONTROL_USER )
    call SetPlayerSlotAvailable( Player(6), MAP_CONTROL_USER )
    call SetPlayerSlotAvailable( Player(7), MAP_CONTROL_USER )
    call InitGenericPlayerSlots(  )
    call InitAllyPriorities(  )
endfunction

