• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Is Way Walkable System / Maze check system v.3.0

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
  • Like
Reactions: baassee
This is my "Is Way Walkable?" system

You're asking: Whats this???

well this system is what every TD / Maze creator may need!

it can check whether ground units can walk from rect a to rect b.

BUT it isn't using a unit to check this! it works without ANY user created objects and is extremely fast:
where a system with a unit needs all the time the unit is walking through your maze, my system checks this immediately!!

Its guaranteed working on every map and without anything the user has to create!

How to import?
just copy the system trigger into your map and youre done!!
you don't have to adjust any variables!!


Update v.2.0: System uses a global item now and small performance improvements

Update v.3.0: THX to D4RK_G4ND4LF
Overflow is now completly beaten^^ the system works now without delay and returns the check result at once.
Improved the Test map


JASS:
library IsWayWalkable initializer Init
// Is Way Walkable system by The_Witcher
//
// well it's a system that checks whether units can walk from a specific rect to another...
//
// FAQ:
//  Thats useless!! everyone can let a unit run the way and check whether it reaches the finish or not!!
//    - Yes but my system checks within max. 0.3 seconds and it uses no units!!
//
//  OK maybe i will use it but for what?
//    - Best use is for a TD. It would check whether the creeps can run from spawn to finish
//      so you can check whether a player blocks or not...
//
//  And how to use it?
//    - well just use:
//            call IsWayWalkable(spawn, finish)     returns a boolean
//                                rect   rect
//
//  Ok, ok but how can I import your system??
//    - one of the easiest things ever^^
//      just copy this trigger in your map and you're done!!
//



// ----- do not edit anything below this line -----
globals
    private real MINx
    private real MAXx
    private real MINy
    private real MAXy
    private real minx
    private real maxx
    private real miny
    private real maxy
    private integer array x
    private integer array y
    private integer total = 0
    private hashtable h = InitHashtable()
    private boolean checking = true
    private item u
    private trigger t = CreateTrigger()
endglobals

private function IsCoordPathable takes real xx, real yy returns boolean
    local real xxx
    local real yyy
    call SetItemVisible(u,true)
    call SetItemPosition(u,xx,yy)
    set xxx = GetItemX( u ) - xx
    set yyy = GetItemY( u ) - yy
    call SetItemVisible(u,false)
    if xxx < 1 and xxx > -1 and  yyy < 1 and yyy > -1 then
        return true
    endif
    return false
endfunction

private function InMapArea takes integer xx, integer yy returns boolean
    return (MINx <= xx) and (xx <= MAXx) and (MINy <= yy) and (yy <= MAXy)
endfunction

private function InWinArea takes integer xx, integer yy returns boolean
    return (minx <= xx) and (xx <= maxx) and (miny <= yy) and (yy <= maxy)
endfunction

private function IsRunable takes integer xx, integer yy returns boolean
    return (not( LoadInteger(h,xx,yy) == 1) and InMapArea(xx,yy) and IsCoordPathable(xx,yy) and checking)
endfunction

private function Check takes nothing returns nothing
    local integer AntiLeak = 0
    loop
        exitwhen total == -1 or checking == false
        if InWinArea(x[0],y[0]) then
            set checking = false
        else
            if IsRunable(x[0]+64,y[0]) and not(LoadInteger(h,x[0]+64,y[0]) == 2) then
                set total = total + 1
                set x[total] = x[0]+64
                set y[total] = y[0]
                call SaveInteger(h,x[0]+64,y[0],2)
            endif
            if IsRunable(x[0],y[0]+64) and not(LoadInteger(h,x[0],y[0]+64) == 2) then
                set total = total + 1
                set x[total] = x[0]
                set y[total] = y[0]+64
                call SaveInteger(h,x[0],y[0]+64,2)
            endif
            if IsRunable(x[0],y[0]-64) and not(LoadInteger(h,x[0],y[0]-64) == 2) then
                set total = total + 1
                set x[total] = x[0]
                set y[total] = y[0]-64
                call SaveInteger(h,x[0],y[0]-64,2)
            endif
            if IsRunable(x[0]-64,y[0]) and not(LoadInteger(h,x[0]-64,y[0]) == 2) then
                set total = total + 1
                set x[total] = x[0]-64
                set y[total] = y[0]
                call SaveInteger(h,x[0]-64,y[0],2)
            endif
            call SaveInteger(h,x[0],y[0],1)
            
            loop
                exitwhen total == -1 or IsRunable(x[0],y[0])
                set x[0] = x[total]
                set y[0] = y[total]
                set total = total - 1
            endloop
        endif
        set AntiLeak = AntiLeak+1
        if AntiLeak > 150 then
            call TriggerExecute(t)
            set AntiLeak = 0
        endif
    endloop
endfunction

function IsWayWalkable takes rect spawn, rect finish returns boolean
    local integer xx = R2I(GetRectCenterX(spawn))
    local integer yy = R2I(GetRectCenterY(spawn))
    set maxx = GetRectMaxX(finish)
    set minx = GetRectMinX(finish)
    set maxy = GetRectMaxY(finish)
    set miny = GetRectMinY(finish)
    set checking = true
    set total = 0
    call FlushParentHashtable(h)
    set h = InitHashtable()
    set x[total] = xx
    set y[total] = yy
    set total = total + 1
    set x[total] = xx+64
    set y[total] = yy
    set total = total + 1
    set x[total] = xx
    set y[total] = yy+64
    set total = total + 1
    set x[total] = xx
    set y[total] = yy-64
    set total = total + 1
    set x[total] = xx-64
    set y[total] = yy
    call Check()
    return not checking
endfunction

private function Init takes nothing returns nothing
    local rect r = GetPlayableMapRect()
    set MINx = GetRectMinX(r)
    set MAXx = GetRectMaxX(r)
    set MINy = GetRectMinY(r)
    set MAXy = GetRectMaxY(r)
    set u = CreateItem( 'wolg', 0,0 )
    call SetItemVisible(u,false)
    call TriggerAddAction(t,function Check)
endfunction
endlibrary

Give Credits when used (and +rep if you think i deserve it ^^)

Keywords:
unit, walk, way, maze, td, tower, defence, system, check, vjass
Contents

Is Way Walkable System (Map)

Reviews
18:28, 8th Dec 2009 TriggerHappy: Review for IsWayWalkable The coding is fairly inefficient. Please looks at dusks TerrainPathablity script to see how you should be optimizing this. Furthermore this is a straight jass script and...

Moderator

M

Moderator

18:28, 8th Dec 2009
TriggerHappy:


Review for IsWayWalkable

The coding is fairly inefficient. Please looks at
dusks TerrainPathablity script to see how you should
be optimizing this. Furthermore this is a straight jass
script and should be submitted in the jass forum.

Status

Rejected
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
I hate math unless I am doing it myself
so I think this is kinda awesome until I understood how this is doing what it is doing :grin:
5/5

some things:
-there are buildings with 32x32 pathing so you should add some variable to define the checking size
-there is a function to get the min/max of a region in gui so I think there might be one in JASS
-and I don't like waits...I bet your function would be nearly instant if you would use something faster as timers and probably you can bypass the operation limit just by calling another function and if that does not work another trigger will probably do it
-I don't speak JASS so everything I wrote might be crap
 
I hate math unless I am doing it myself
so I think this is kinda awesome until I understood how this is doing what it is doing :grin:
5/5

some things:
-there are buildings with 32x32 pathing so you should add some variable to define the checking size
-there is a function to get the min/max of a region in gui so I think there might be one in JASS
-and I don't like waits...I bet your function would be nearly instant if you would use something faster as timers and probably you can bypass the operation limit just by calling another function and if that does not work another trigger will probably do it
-I don't speak JASS so everything I wrote might be crap

you're right. it's crap^^
i explained in the documentation why i use the TriggerSleepAction(not the wait). there are no 32x32 units. i checked that! in addition i use GetRectMinX, GetRectMaxX, GetRectMinY and GetRectMaxY so i don't know what you want at that point...

HINT: learn Jass^^
it helps a lot
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
:eekani: you are right....
however I checked myself and found out that the wc3 grid size is 32x32 and that the smallest pathing map is "PathTextures\2x2Default.tga"
so I think it is possible to import your own which is 1x1
(it would not make much sense to start enumerating with 2 x)
but nobody will do this so it is ok...

and I also made some tests regarding the op limit

this one returns one million + 1:
JASS:
function count takes nothing returns nothing
    if udg_i < 1000000 then
        set udg_i = udg_i + 1
        if ModuloInteger(udg_i,5000) == 0 then
             set udg_i = udg_i + 1
             call TriggerExecute( gg_trg_count )
        else
            call count()
        endif
    endif
endfunction
-it laggs since 1 million operations is a lot but it is adjustable of cause
and the operation limit is at 23k (at least a loop in GUI with ifs and +1 counted up to 23k)

JASS:
function count takes nothing returns nothing
    set udg_i = udg_i + 1
    if udg_i > 100000 then
        return
    endif
    if ModuloInteger(udg_i,20000) == 0 then
        call TriggerSleepAction(0.01)
    endif
    call count()
endfunction
this ended up at 5k+ something after 1 second -> 200 times less

same with this:
JASS:
call TriggerSleepAction(0.01)

that proves that the wait is constant no matter what
and the wait is to long
I'd recommend using TriggerExecute(trigger)
it bypasses the operation limit but is very fast

damn hive...why does this page always have to collapse when I'm trying to post! update at night or something! :cry: (well....you probably are doing that but it is 11 o'clock in the morning at mine....)
 
Top