Snippet Artificial Pathing Blockers

Azlier

Old World Ghost
Reaction score
461
Well, you know those pathing blockers everybody loves right? This little script takes all of the preplaced ones and removes them, but leaves the pathing just as you wanted it.

That way, your handle count is lowered and the computer doesn't need to use CPU to take care of those destructables that you probably won't ever touch.

Also, you can create some artificial pathing blockers dynamically with these functions. Artificial pathing blockers don't even exist, so destroying them isn't all that possible.

JASS:
CreateWalkabilityBlocker takes real x, y, boolean walkable
//Creates a 64x64 pathing blocker that turns whether you can walk there on or off.

CreateFlyabilityBlocker takes real x, y, boolean walkable
//Creates a 64x64 pathing blocker that turns whether you can fly there on or off.

CreateMoveabilityBlocker takes real x, y, boolean moveable
//Creates a 64x64 pathing blocker that turns whether you can move there on or off.

CreateLargeWalkabilityBlocker takes real x, y, boolean walkable
//Creates a 128x128 pathing blocker that turns whether you can walk there on or off.

CreateLargeFlyabilityBlocker takes real x, y, boolean walkable
//Creates a 128x128 pathing blocker that turns whether you can fly there on or off.

CreateLargeMoveabilityBlocker takes real x, y, boolean moveable
//Creates a 128x128 pathing blocker that turns whether you can move there on or off.


JASS:
library APB initializer Init
//                       ** ! ** READ ME ** ! **
//These ObjectMerger commands will create walkable pathing blockers.

//! external ObjectMerger w3b YTpb YTwb bnam "Pathing Blocker (Walkable)" bwal 1 bptx "PathTextures\2x2Unbuildable.tga"
//! external ObjectMerger w3b YTpc YTwc bnam "Pathing Blocker (Walkable) (Large)" bwal 1 bptx "PathTextures\4x4Unbuildable.tga"

//Save the map with this, close the map, and open it again. Delete the ObjectMerger calls, and save again.

globals
    private constant integer UNWALKABLE = 'YTpb'
    private constant integer UNWALKABLE_LARGE = 'YTpc'
    private constant integer UNFLYABLE = 'YTab'
    private constant integer UNFLYABLE_LARGE = 'YTac'
    private constant integer NO_MOVEMENT = 'YTfb'
    private constant integer NO_MOVEMENT_LARGE = 'YTfc'
    private constant integer WALKABLE = 'YTwb'
    private constant integer WALKABLE_LARGE = 'YTwc'
endglobals

function CreateWalkabilityBlocker takes real x, real y, boolean walkable returns nothing
    call SetTerrainPathable(x, y, PATHING_TYPE_WALKABILITY, walkable)
endfunction

function CreateFlyabilityBlocker takes real x, real y, boolean flyable returns nothing
    call SetTerrainPathable(x, y, PATHING_TYPE_FLYABILITY, flyable)
endfunction

function CreateMoveabilityBlocker takes real x, real y, boolean moveable returns nothing
    call CreateWalkabilityBlocker(x, y, moveable)
    call CreateFlyabilityBlocker(x, y, moveable)
endfunction

function CreateLargeWalkabilityBlocker takes real x, real y, boolean walkable returns nothing
    call CreateWalkabilityBlocker(x + 16, y + 16, walkable)
    call CreateWalkabilityBlocker(x - 16, y - 16, walkable)
    call CreateWalkabilityBlocker(x + 16, y - 16, walkable)
    call CreateWalkabilityBlocker(x - 16, y + 16, walkable)
endfunction

function CreateLargeFlyabilityBlocker takes real x, real y, boolean flyable returns nothing
    call CreateFlyabilityBlocker(x + 16, y + 16, flyable)
    call CreateFlyabilityBlocker(x - 16, y - 16, flyable)
    call CreateFlyabilityBlocker(x + 16, y - 16, flyable)
    call CreateFlyabilityBlocker(x - 16, y + 16, flyable)
endfunction

function CreateLargeMoveabilityBlocker takes real x, real y, boolean moveable returns nothing
    call CreateWalkabilityBlocker(x + 16, y + 16, moveable)
    call CreateWalkabilityBlocker(x - 16, y - 16, moveable)
    call CreateWalkabilityBlocker(x + 16, y - 16, moveable)
    call CreateWalkabilityBlocker(x - 16, y + 16, moveable)
    call CreateFlyabilityBlocker(x + 16, y + 16, moveable)
    call CreateFlyabilityBlocker(x - 16, y - 16, moveable)
    call CreateFlyabilityBlocker(x + 16, y - 16, moveable)
    call CreateFlyabilityBlocker(x - 16, y + 16, moveable)
endfunction

private function Replace takes nothing returns boolean
    local destructable d = GetFilterDestructable()
    local integer i = GetDestructableTypeId(d)
    local real x
    local real y
    if i == UNWALKABLE then
        call SetTerrainPathable(GetWidgetX(d), GetWidgetY(d), PATHING_TYPE_WALKABILITY, false)
        call RemoveDestructable(d)
    elseif i == UNWALKABLE_LARGE then
        set x = GetWidgetX(d)
        set y = GetWidgetY(d)
        call SetTerrainPathable(x + 16, y + 16, PATHING_TYPE_WALKABILITY, false)
        call SetTerrainPathable(x - 16, y - 16, PATHING_TYPE_WALKABILITY, false)
        call SetTerrainPathable(x + 16, y - 16, PATHING_TYPE_WALKABILITY, false)
        call SetTerrainPathable(x - 16, y + 16, PATHING_TYPE_WALKABILITY, false)
        call RemoveDestructable(d)
    elseif i == UNFLYABLE then
        call SetTerrainPathable(GetWidgetX(d), GetWidgetY(d), PATHING_TYPE_FLYABILITY, false)
        call RemoveDestructable(d)
    elseif i == UNFLYABLE_LARGE then
        set x = GetWidgetX(d)
        set y = GetWidgetY(d)
        call SetTerrainPathable(x + 16, y + 16, PATHING_TYPE_FLYABILITY, false)
        call SetTerrainPathable(x - 16, y - 16, PATHING_TYPE_FLYABILITY, false)
        call SetTerrainPathable(x + 16, y - 16, PATHING_TYPE_FLYABILITY, false)
        call SetTerrainPathable(x - 16, y + 16, PATHING_TYPE_FLYABILITY, false)
        call RemoveDestructable(d)
    elseif i == WALKABLE then
        call SetTerrainPathable(GetWidgetX(d), GetWidgetY(d), PATHING_TYPE_WALKABILITY, true)
        call RemoveDestructable(d)
    elseif i == WALKABLE_LARGE then
        set x = GetWidgetX(d)
        set y = GetWidgetY(d)
        call SetTerrainPathable(x + 16, y + 16, PATHING_TYPE_WALKABILITY, true)
        call SetTerrainPathable(x - 16, y - 16, PATHING_TYPE_WALKABILITY, true)
        call SetTerrainPathable(x + 16, y - 16, PATHING_TYPE_WALKABILITY, true)
        call SetTerrainPathable(x - 16, y + 16, PATHING_TYPE_WALKABILITY, true)
        call RemoveDestructable(d)
    elseif i == NO_MOVEMENT then
        set x = GetWidgetX(d)
        set y = GetWidgetY(d)
        call SetTerrainPathable(x, y, PATHING_TYPE_WALKABILITY, false)
        call SetTerrainPathable(x, y, PATHING_TYPE_FLYABILITY, false)
        call RemoveDestructable(d)
    elseif i == NO_MOVEMENT_LARGE then
        set x = GetWidgetX(d)
        set y = GetWidgetY(d)
        call SetTerrainPathable(x + 16, y + 16, PATHING_TYPE_WALKABILITY, false)
        call SetTerrainPathable(x - 16, y - 16, PATHING_TYPE_WALKABILITY, false)
        call SetTerrainPathable(x + 16, y - 16, PATHING_TYPE_WALKABILITY, false)
        call SetTerrainPathable(x - 16, y + 16, PATHING_TYPE_WALKABILITY, false)
        call SetTerrainPathable(x + 16, y + 16, PATHING_TYPE_FLYABILITY, false)
        call SetTerrainPathable(x - 16, y - 16, PATHING_TYPE_FLYABILITY, false)
        call SetTerrainPathable(x + 16, y - 16, PATHING_TYPE_FLYABILITY, false)
        call SetTerrainPathable(x - 16, y + 16, PATHING_TYPE_FLYABILITY, false)
        call RemoveDestructable(d)
    endif
    set d = null
    return false
endfunction

private function Init takes nothing returns nothing
    local rect r = GetWorldBounds()
    call EnumDestructablesInRect(r, Filter(function Replace), null)
    call DestroyBoolExpr(Filter(function Replace))
    call RemoveRect(r)
    set r = null
endfunction

endlibrary
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
library APB initializer Init

Since it's 100% private, it will never need to be referenced. So extend this to "library ArtificialPathingBlockers initializer Init"? Seems nicer than just APB. :thup:

By the way, you should note that you added a "walkable" pathing blocker. That, in my opinion, is cool. :)

Actually, can this support pathing blocker creation at runtime? ie. detect creation and destroy it and make it artificial. Maybe a "refresh" function is necessary.

PS.
JASS:
private function Init takes nothing returns nothing
    local rect r = GetWorldBounds()
    call EnumDestructablesInRect(r, Filter(function Replace), null)
    call DestroyBoolExpr(Filter(function Replace))
    call RemoveRect(r)
    set r = null
endfunction

I like it. :D
 

Azlier

Old World Ghost
Reaction score
461
>Actually, can this support pathing blocker creation at runtime?
I could add functions to create artificial pathing blockers directly. Would that suffice?

>So extend this to "library ArtificialPathingBlockers initializer Init"?
Done.

>By the way, you should note that you added a "walkable" pathing blocker.
It's on the third line of the script.

EDIT:
Added some pathing blocker creation functions. Also had to name the library back to the original now that it might need to be referenced.
 
Reaction score
91
O mai ghaaad, yesterday I wanted someone to make such a thing since I needed it but was lazy to do it on my own. Good job
 

black.sheep

Active Member
Reaction score
24
Question.
Would this fuck over abilities that change pathing in areas?
Say Fissure from DotA, would that remove the pathing blockers due to it changing pathing?
 

Azlier

Old World Ghost
Reaction score
461
>Would this fuck over abilities that change pathing in areas?
Yes. What sort of ability changes pathing in an area, though? :confused:
 

quraji

zap
Reaction score
144
Nice, but maybe you should think of a new name for the functions? It's kind of weird to use "CreateWalkabilityBlocker" if I'm trying to make an area walkable :p

Or, create a blocker struct, everyone loves structs.

Also, can you do me a favor and explain this to me:
JASS:
call EnumDestructablesInRect(r, Filter(function Replace), null)
call DestroyBoolExpr(Filter(function Replace))


It's been a while since I've JASS'd, and I know this has to do with something I should remember about boolexprs..
 

Azlier

Old World Ghost
Reaction score
461
>It's kind of weird to use "CreateWalkabilityBlocker" if I'm trying to make an area walkable.
Well, it is exactly what it is. A walkability "blocker". :nuts:

>Or, create a blocker struct, everyone loves structs.
It's not as simple as "making a struct". You can't really store what doesn't exist.

>Also, can you do me a favor and explain this to me:
I'm enumerating all the map's destructables and destroying the filter. It's one handle that I'll never use again anyways. Might as well keep handle count lower, with handle allocation being O(n) and all.
 

quraji

zap
Reaction score
144
>It's kind of weird to use "CreateWalkabilityBlocker" if I'm trying to make an area walkable.
Well, it is exactly what it is. A walkability "blocker". :nuts:

>Or, create a blocker struct, everyone loves structs.
It's not as simple as "making a struct". You can't really store what doesn't exist.

>Also, can you do me a favor and explain this to me:
I'm enumerating all the map's destructables and destroying the filter. It's one handle that I'll never use again anyways. Might as well keep handle count lower, with handle allocation being O(n) and all.

>>Well, it is exactly what it is. A walkability "blocker".
I'm just saying it's weird to call it a "blocker" if you can block or unblock an area :p

>>It's not as simple as "making a struct". You can't really store what doesn't exist.
Not sure what you mean...I meant you can create one. Myself, I'd prefer treating these 'blockers' as actual objects rather than using the wrapper functions..

>>I'm enumerating all the map's destructables and destroying the filter. It's one handle that I'll never use again anyways. Might as well keep handle count lower, with handle allocation being O(n) and all.

I was talking specifically about the following bolded parts:
Code:
call EnumDestructablesInRect(r, [B]Filter[/B](function Replace), null)
call [B]DestroyBoolExpr[/B]([B]Filter[/B](function Replace))
What does the above do, opposed to this:
JASS:
local boolexpr b = Filter(function Replace)
call EnumDestructablesInRect(r, b, null)
call DestroyBoolExpr(b)


It seems like yours, instead of destroying the boolexpr used in the first statement, is just creating one to destroy immediately after. Unless I'm missing something of course.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Filter(function SomeFunc) will always return the same filter. The only difference is yours leaks the handle because you forgotz to null. :p

In this script, "blockers" are no longer objects. They don't exist and have no handle. When you "create" one using this, if you want to reverse the effect, you simply create the opposite one over the top. :)
 

quraji

zap
Reaction score
144
>>Filter(function SomeFunc) will always return the same filter.
Okay, that's what I was wondering (hoping).

>>The only difference is yours leaks the handle because you forgotz to null. :p
I didn't figure that line was necessary.

>>In this script, "blockers" are no longer objects. They don't exist and have no handle. When you "create" one using this, if you want to reverse the effect, you simply create the opposite one over the top.
Yes I know, but I'm just saying in the interest of readability and ease of use, a struct could be created :thup:
 

Rushhour

New Member
Reaction score
46
I don't know what's wrong at my map, but since I had quite a lot of pathing blockers I decided to use this.
Yea creating the walkable pathing "blocker" with the object merger went fine. Testing the map showed that the pathing blockers were removed properly, but the terrain changed to walkable and I can walk to points that are unreachable without this snippet 0o.
I checked the Id's of the pathing blockers (blockers are all default).

Any ideas??
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top