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

[Snippet] TerrainCheck

For maze maps.

JASS:
library TerrainCheck /* v1.0.0.0
*************************************************************************************
*
*   */ uses /*
*
*       */ Tt       /*hiveworkshop.com/forums/jass-resources-412/system-timer-tools-201165/
*
************************************************************************************
*
*   struct TerrainCheck extends array
*       method register takes unit whichUnit returns nothing
*           -   Registers unit to be killed when it is on terrain
*           -   call TerrainCheck[terrainType].register(whichUnit)
*
*       method unregister takes unit whichUnit returns nothing
*           -   Unregisters unit from terrain (will no longer die on that terrain)
*           -   call TerrainCheck[terrainType].unregister(whichUnit)
*
************************************************************************************/
    globals
        private constant real RADIUS = 16
        private hashtable table = InitHashtable()
    endglobals
    
    private struct Check extends array
        private static constant real TIMEOUT = .03
        
        unit c
        integer t
        implement CTTC
            local unit u
            local real x
            local real y
            local integer m
        implement CTTCExpire
            set u = this.c
            set x = GetUnitX(u)
            set y = GetUnitY(u)
            set m = t
            
            if (GetTerrainType(x+RADIUS,y) == m and GetTerrainType(x-RADIUS, y) == m and GetTerrainType(x, y+RADIUS) == m and GetTerrainType(x, y-RADIUS) == m and /*
            */ GetTerrainType(x+RADIUS, y+RADIUS) == m and GetTerrainType(x+RADIUS, y-RADIUS) == m and GetTerrainType(x-RADIUS, y+RADIUS) == m and GetTerrainType(x-RADIUS, y-RADIUS) == m) then
                call KillUnit(u)
            endif
        implement CTTCNull
            set u = null
        implement CTTCEnd
    endstruct
    
    struct TerrainCheck extends array
        method register takes unit u returns nothing
            local Check check =  Check.create()
            call SaveInteger(table, check, GetHandleId(u), check)
            set check.c = u
            set check.t = this
        endmethod
        method unregister takes unit u returns nothing
            local integer h = GetHandleId(u)
            local Check c
            if (HaveSavedInteger(table, this, h)) then
                set c = LoadInteger(table, this, h)
                call RemoveSavedInteger(table, this, h)
                set c.c = null
                call c.destroy()
            endif
        endmethod
    endstruct
endlibrary
 
Last edited:
Top