• 🏆 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!

IsPointWalkable

Hello.
This is my 1st resource. Admins, be gentle:D
I did it before I found --Check Walkability by PurgeandFire--, but I decided to share with community. Mine works diffrent way and maybe someone will need to check pathability for diffrent size units. Point can be walkable for peon[16size] unit, but not for tauren[48size].
With this snippet you can check it.

This snippet allows to check if point is walkable for unit 16size / 32size / 48size. Its very small and uses one custom ability and 3 custom dummy units.

It uses SetUnitPosition() and then second check by blink-ability trick to determine if unit is on walkable point or its trapped on cliff or deep water for example.

All information about implement in Test Map.
Zibi


Check walkability:

JASS:
//------------------------------------------------------------------------------------------
// Check Walkability 1.08 (by ZibiTheWand3r3r)
// Thanks Almia, IcemanBo, Chaosy, BPower for help and tips.
//
// This snippet allows to check if given point is walkable for 48-size unit, 32-size unit and 16-size unit.
// It uses 3 dummy units + 1 custom ability. It checks walkability by: SetUnitPosition + Blink ability.
// 
// How to import:
// 1. Copy this this trigger to your map.
// 2. From Object Editor copy custom ability named: Blink-PathChecker (A000) and
// three custom units: Dummy16 (o000), Dummy32 (o001) and Dummy48 (o002).
// 3. Use Ctrl+D to check copied units/ability numbers. If they differ from those given in () 
// then modify in globals section.
//
// --API--
// function CheckPathing takes real x, real y, integer collisionSize returns boolean
// use argument collisionSize: COLLISION_SIZE_16 or COLLISION_SIZE_32 or COLLISION_SIZE_48
// function returns true if point (x, y) is walkable for given-size units
//------------------------------------------------------------------------------------------

library CheckWalkability initializer CheckWalkabilityInit
    globals
        // user configuration: use Ctrl-D in ObjectEditor to see id of ability:
        // if Blink-PathChecker ability id diffrent then A000, then type here the actual value:
        private constant integer ABILITY_ID = 'A000'
        // if Dummy16(peon) unit id diffrent then o000, then type here the actual value:
        private constant integer DUMMY_ID_16 = 'o000'
        // if Dummy32(grunt) unit id diffrent then o001, then type here the actual value:
        private constant integer DUMMY_ID_32 = 'o001'
        // if Dummy48(tauren) unit id diffrent then o002, then type here the actual value:
        private constant integer DUMMY_ID_48 = 'o002'
        //----------------------- don't change anything below -------------------------------------------
        constant integer COLLISION_SIZE_16 = 16
        constant integer COLLISION_SIZE_32 = 32
        constant integer COLLISION_SIZE_48 = 48
        private unit array checker
    endglobals
    //---------------------- initialization function -----------------------------------------------------
    function CheckWalkabilityInit takes nothing returns nothing
        set checker[COLLISION_SIZE_16] = CreateUnit(Player(15), DUMMY_ID_16, 0.00, 0.00, 0.00)
        set checker[COLLISION_SIZE_32] = CreateUnit(Player(15), DUMMY_ID_32, 0.00, 0.00, 0.00)
        set checker[COLLISION_SIZE_48] = CreateUnit(Player(15), DUMMY_ID_48, 0.00, 0.00, 0.00)
        call UnitAddAbility(checker[COLLISION_SIZE_16], ABILITY_ID)
        call UnitAddAbility(checker[COLLISION_SIZE_16], 'Avul')
        call ShowUnit(checker[COLLISION_SIZE_16], false)
        call UnitAddAbility(checker[COLLISION_SIZE_32], ABILITY_ID)
        call UnitAddAbility(checker[COLLISION_SIZE_32], 'Avul')
        call ShowUnit(checker[COLLISION_SIZE_32], false)
        call UnitAddAbility(checker[COLLISION_SIZE_48], ABILITY_ID)
        call UnitAddAbility(checker[COLLISION_SIZE_48], 'Avul')
        call ShowUnit(checker[COLLISION_SIZE_48], false)
    endfunction
    //------------------------ main function -------------------------------------------------
    function CheckPathing takes real x, real y, integer collisionSize returns boolean
        debug if checker[collisionSize] == null then
        debug call BJDebugMsg(" Invalid argument, allowed is 16, 32, 48, use pre-defined keys to avoid malfunction")
        debug return false
        debug endif

        call SetUnitPosition(checker[collisionSize], x, y)
        if RAbsBJ(x-GetUnitX(checker[collisionSize])) <= 0.02 then
            if RAbsBJ(y-GetUnitY(checker[collisionSize])) <= 0.02 then
                call SetUnitX(checker[collisionSize], 0.00)
                call SetUnitY(checker[collisionSize], 0.00)
                return IssuePointOrder(checker[collisionSize], "blink", x, y)
            endif
        endif

        return false
    endfunction

endlibrary



  • TestSpellTargetGUI
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to TestAbility2
    • Actions
      • Set TempPoint = (Target point of ability being cast)
      • Custom script: set udg_isWalkable = CheckPathing( GetLocationX(udg_TempPoint), GetLocationY(udg_TempPoint), COLLISION_SIZE_48 )
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • isWalkable Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: Point is |cff00ff00...
        • Else - Actions
          • Game - Display to (All players) the text: Point is |cfffa8072...
      • Custom script: call RemoveLocation(udg_TempPoint)


updated Quilnez's prompt:)
updated IcemanBo's suggestions
updated 1.03, implemented BPower suggestions

Keywords:
is point walkable, walkability, is point pathable, unit size path
Contents

ZibiPathChecker1.08 (Map)

Reviews
IsPointWalkable | Reviewed by BPower | 15.06.2015 Concept[/COLOR]] Checks for walkability at a given coordinate. As bonus you can check for different collision size. Currently supported collision sizes are 16, 32, and 48. Big downside is...

Moderator

M

Moderator


IsPointWalkable | Reviewed by BPower | 15.06.2015

[COLOR="gray"

[COLOR="gray"

[COLOR="gray"

[COLOR="gray"

Concept[/COLOR]]
126248-albums6177-picture66521.png
Checks for walkability at a given coordinate.
As bonus you can check for different collision size.
Currently supported collision sizes are 16, 32, and 48.

Big downside is the usage of a dummy unit, as it may fire
unwanted secondary events when entering/leaving an area,
aswell as casting the blink ability.

That's why I recommend to only use this snippet,
if you wish to determine the between different collision sizes.
Code[/COLOR]]
126248-albums6177-picture66521.png
  • The system seems to work as intended.
Objects[/COLOR]]
126248-albums6177-picture66523.png
  • Objects appear to be ok.
Rating[/COLOR]]
CONCEPTCODEOBJECTSRATINGSTATUS
2.5/5
2.5/5
3/5
2.7/5
APPROVED
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Post the code into the description.
The idea of using SetUnitPosition is not new, however this native comes with some disadvantages (mainly unit enter region event).
For this reason using an item is better.

Check for different collision sizes can be useful. (Knockback, ...)
 
Level 18
Joined
Nov 21, 2012
Messages
835
The idea of using SetUnitPosition is not new, however this native comes with some disadvantages (mainly unit enter region event).
For this reason using an item is better.
Do you mean that native sometimes fails with checking path? Or what disadvantages you refer to?
I know SetUnitPosition can put unit on cliffs for example, thats why its double checked by blink trick I found.

Almia, why? Is it not working?
 
- Use your own dummy units, not default ones and put them into globals.
- Dummy variable does not necessatily to be an array.
- You cannot just put functions like this anywhere in JASS. They need to be in header or in a library.
- "ZibiCheckPathing" -> "ZibiCheckPathing48", because it's more consequent in naming.
- The "Zibi" in names is not descriptive for the purpose and is not needed.
- Fix the indention. Use "Tab" for it. Look in approved JASS spells for examples.

I'm not certain because of the site effect with entering event,
but on other side that's not only here a problem but in general when dummies are used for any movement.
So I have to think about it.

Make named changes for now. :)
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,182
Useful, I will give you that. Not exactly unique though.

In terms of actual code.. I fixed your structure a little. And I changed the initialize method.
JASS:
//------------------------------------------------------------------------------------------
// Check Walkability 1.02 (by ZibiTheWand3r3r)
//
// This snippet allows to check if given point is walkable for 48-size unit, 32-size unit and 16-size unit.
// It uses 3 dummy units + 1 custom ability. It checks by: SetUnitPosition + Blink ability.
// 
// How to import:
// 1. Copy this this trigger to your map.
// 2. From Object Editor copy custom ability named: Blink-PathChecker (A000) and
// three custom units: Dummy16 (o000), Dummy32 (o001) and Dummy48 (o002).
// 3. Use Ctrl+D to check copied units/ability numbers. If they differ from those given in () 
// then modify in CheckWalkabilityInit function.
//
// --API--
// function CheckPathing16 takes real x, real y returns boolean
// returns true if point (x, y) is walkable for 16-size units (peon size)
// function CheckPathing32 takes real x, real y returns boolean
// returns true if point (x, y) is walkable for 32-size units (grunt size)
// function CheckPathing48 takes real x, real y returns boolean
// returns true if point (x, y) is walkable for 48-size units (tauren size)
//
// Use function CheckPathing48 to be sure that point (x, y) is walkable for all units
//------------------------------------------------------------------------------------------


library CheckWalkability initializer CheckWalkabilityInit

    globals
        integer BlinkPathCheckerAbility
        unit udg_Dummy16
        unit udg_Dummy32
        unit udg_Dummy48
    endglobals
//----------------
function CheckWalkabilityInit takes nothing returns nothing
    //--------------------------------------------------------------------------------------------------
    // use Ctrl-D in ObjectEditor to see number of ability:
    // if Blink-PathChecker ability number diffrent then A000, then type here the actual value:
    set BlinkPathCheckerAbility = 'A000' // Blink-PathChecker ability
    // if Dummy16(peon) unit number diffrent then o000, then type here the actual value:
    set udg_Dummy16 = CreateUnit(Player(15), 'o000', 0.00, 0.00, 0.00) //Dummy16(peon)
    // if Dummy16(peon) unit number diffrent then o000, then type here the actual value:
    set udg_Dummy32 = CreateUnit(Player(15), 'o001', 0.00, 0.00, 0.00) //Dummy32(grunt)
    // if Dummy16(peon) unit number diffrent then o000, then type here the actual value:
    set udg_Dummy48 = CreateUnit(Player(15), 'o002', 0.00, 0.00, 0.00) //Dummy48(tauren)
    //---------------------------------------------------------------------------------------------------

    call UnitAddAbility(udg_Dummy48, BlinkPathCheckerAbility) //blink ability
    call UnitAddAbility(udg_Dummy48, 'Avul')
    call ShowUnit(udg_Dummy48, false)
    call UnitAddAbility(udg_Dummy32, BlinkPathCheckerAbility)
    call UnitAddAbility(udg_Dummy32, 'Avul')
    call ShowUnit(udg_Dummy32, false)
    call UnitAddAbility(udg_Dummy16, BlinkPathCheckerAbility)
    call UnitAddAbility(udg_Dummy16, 'Avul')
    call ShowUnit(udg_Dummy16, false)
endfunction

function CheckPathing16 takes real x, real y returns boolean
    call SetUnitPosition(udg_Dummy16, x, y)
    if x == GetUnitX(udg_Dummy16) and y == GetUnitY(udg_Dummy16) then
        return IssuePointOrder(udg_Dummy16, "blink", GetUnitX(udg_Dummy16)+1., GetUnitY(udg_Dummy16)+1.)
    endif
    return false
endfunction

function CheckPathing32 takes real x, real y returns boolean
    call SetUnitPosition(udg_Dummy32, x, y)
    if x == GetUnitX(udg_Dummy32) and y == GetUnitY(udg_Dummy32) then
        return IssuePointOrder(udg_Dummy32, "blink", GetUnitX(udg_Dummy32)+1., GetUnitY(udg_Dummy32)+1.)
    endif
    return false
endfunction

function CheckPathing48 takes real x, real y returns boolean
    call SetUnitPosition(udg_Dummy48, x, y)
    if x == GetUnitX(udg_Dummy48) and y == GetUnitY(udg_Dummy48) then
        return IssuePointOrder(udg_Dummy48, "blink", GetUnitX(udg_Dummy48)+1., GetUnitY(udg_Dummy48)+1.)
    endif
    return false
endfunction

endlibrary
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Moving a unit will never be the best approach for checking path-ability.
However if working its a valid submission.

I would merge the functions and use an array for the path checker unit.
Add the collision size as argument and check if the argument is valid.
For this define 3 keys or better 3 constant key like integers: 16, 32 and 48
IsTerrainPathable(x, y, key)

debug if checker[key] == null then
debug error: Invalid argument, allowed is 16, 32, 48, use pre-defined keys to avoid malfunction.
debug endif
Call SetUnitPosition(checker[key], x, y)
 
Level 18
Joined
Nov 21, 2012
Messages
835
Thank you Chaosy, BPower.
Im not sure how to use this
debug error: Invalid argument, allowed is 16, 32, 48
. Got compile error. Used BJDebugMsg. Is this script ok:
JASS:
function CheckPathing takes real x, real y, integer size returns boolean
local integer s=48
if size==16 or size==32 or size==48 then
    set s=size
else
    call BJDebugMsg(" Invalid argument, allowed is 16, 32, 48. Now script used 48 insted of " + I2S(size))
endif

call SetUnitPosition(udg_DummyPath[s], x, y)
if x == GetUnitX(udg_DummyPath[s]) and y == GetUnitY(udg_DummyPath[s]) then
return IssuePointOrder(udg_DummyPath[s], "blink", GetUnitX(udg_DummyPath[s])+1., GetUnitY(udg_DummyPath[s])+1.)
endif

return false
endfunction
Allowed to run 48size check if user used wrong size argument. You think its ok?
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Name the readable constants as generic as possible. Use the public keyword if you want.
They are part of your API.
JASS:
globals
    constant integer COLLISION_SIZE_16 = 16
    // 32, 48
    private unit array checker// Create on init checker[16], checker[32], and checker[48]
endglobals
    // Valid arguments for collisionSize are 16, 32, 48
    // Define constants as they can be use, instead of magic numbers.
    function CheckPathing takes real x, real y, integer collisionSize return boolean
        debug if checker[collisionSize] == null then
            debug call (ErrorMsg)// debug only prints error.
            debug return false
        debug endif
        call SetUnitPosition(checker[collisionSize], x, y)
        // continue your script as before.
    endfunction
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
indentation is the keyword.
Example:
JASS:
// Good and read-able
library x
    globals
    endglobals

    function Ex takes nothing returns nothing
        return
    endfunction

endlibrary

// Shitty format, hard to read
// Conclusion: spacing is very important.
library x1
globals
endglobals

function ex takes nothing returns nothing
return
endfunction
endlibrary

You have to store all raws of the dummy units in constant.
In your demo map they might be 'o000', 'o001', etc
but if I import your stuff into my map these raws might already been taken.

BTW your code is not JASS, it's vJass.
JASS doesn't support either keyword library nor globals

Dummy units using locust don't require 'Avul'
 
I think you should use external object to create both units and ability.
What do you mean with it?

Heyho, ZiBitheWand3r3r. :)

I kind of repeat BPower, but,
Could you fix the indentation, please?

Just always use tab for easy indenting. If you don't know what we mean, it's explained here,
under the chapter "indention": http://www.hiveworkshop.com/forums/...80/jpag-jass-proper-application-guide-204383/

It was bit better if internal init code and configuration was more seperated.
It's quite simple to achieve in JASS, and should be used to gain readability and a bit of structure.
(I mean the object types, unit/spells)

And yes, with this solution with integers for collision the unit array is a neater solution now. :)
 
Level 7
Joined
Oct 11, 2008
Messages
304
JASS:
function CheckWalkabilityInit takes nothing returns nothing
    set checker[16] = CreateUnit(Player(15), dummy16Id, 0.00, 0.00, 0.00) //Dummy16(peon)
    set checker[32] = CreateUnit(Player(15), dummy32Id, 0.00, 0.00, 0.00) //Dummy32(grunt)
    set checker[48] = CreateUnit(Player(15), dummy48Id, 0.00, 0.00, 0.00) //Dummy48(tauren)
    call UnitAddAbility(checker[16], blinkPathCheckerAbility)
    call UnitAddAbility(checker[16], 'Avul')
    call ShowUnit(checker[16], false)
    call UnitAddAbility(checker[32], blinkPathCheckerAbility)
    call UnitAddAbility(checker[32], 'Avul')
    call ShowUnit(checker[32], false)
    call UnitAddAbility(checker[48], blinkPathCheckerAbility)
    call UnitAddAbility(checker[48], 'Avul')
    call ShowUnit(checker[48], false)
endfunction

>>

JASS:
private function CheckWalkabilityInit takes nothing returns nothing
    set checker[COLLISION_SIZE_16] = CreateUnit(Player(15), dummy16Id, 0.00, 0.00, 0.00) //Dummy16(peon)
    set checker[COLLISION_SIZE_32] = CreateUnit(Player(15), dummy32Id, 0.00, 0.00, 0.00) //Dummy32(grunt)
    set checker[COLLISION_SIZE_48] = CreateUnit(Player(15), dummy48Id, 0.00, 0.00, 0.00) //Dummy48(tauren)
    call UnitAddAbility(checker[COLLISION_SIZE_16], blinkPathCheckerAbility)
    call UnitAddAbility(checker[COLLISION_SIZE_16], 'Avul')
    call ShowUnit(checker[COLLISION_SIZE_16], false)
    call UnitAddAbility(checker[COLLISION_SIZE_32], blinkPathCheckerAbility)
    call UnitAddAbility(checker[COLLISION_SIZE_32], 'Avul')
    call ShowUnit(checker[COLLISION_SIZE_32], false)
    call UnitAddAbility(checker[COLLISION_SIZE_48], blinkPathCheckerAbility)
    call UnitAddAbility(checker[COLLISION_SIZE_48], 'Avul')
    call ShowUnit(checker[COLLISION_SIZE_48], false)
endfunction

Also, locust will not work instead of ShowUnit and 'avul'??
 
JASS:
        call UnitAddAbility(checker[16], blinkPathCheckerAbility)
        call UnitAddAbility(checker[16], 'Avul')
        call ShowUnit(checker[16], false)
        call UnitAddAbility(checker[32], blinkPathCheckerAbility)
        call UnitAddAbility(checker[32], 'Avul')
        call ShowUnit(checker[32], false)
        call UnitAddAbility(checker[48], blinkPathCheckerAbility)
        call UnitAddAbility(checker[48], 'Avul')
        call ShowUnit(checker[48], false)
This can be optimized actually, for better readability.

Just for insurance, is it possible that unit enters region triggers when dummies enter them? I can't confirm that one check.
 
Level 18
Joined
Nov 21, 2012
Messages
835
Why does the blink location has to differ by an offset of 1 from the location in question? ( honest question )
Could you explain this to me?
Blink cannot be executed to the same location where caster is. I set minimum range=0 for Blink ability in Object Editor, but target point must be shifted by any small value.

Also, locust will not work instead of ShowUnit and 'avul' ??
ShowUnit+Avul works, locust don't.

Just for insurance, is it possible that unit enters region triggers when dummies enter them?
Unfortunately snippet can fire events like Unit enter/leaves region
 
Level 18
Joined
Nov 21, 2012
Messages
835
may i ask why it should be really small? can't we just make a dummy on the edge of the map, have the Blink a global range and so on? How about SetUnitPosition?
Made few tests and your idea works well, code will be a bit diffrent:

JASS:
    function CheckPathing takes real x, real y, integer collisionSize returns boolean
        debug if checker[collisionSize] == null then
        debug call BJDebugMsg(" Invalid argument, allowed is 16, 32, 48, use pre-defined keys to avoid malfunction")
        debug return false
        debug elseif IsUnitPaused(checker[collisionSize]) then
        debug call BJDebugMsg(" Error: path checker unit is paused.")
        debug return false
        debug endif

        call SetUnitPosition(checker[collisionSize], x, y)
        if x == GetUnitX(checker[collisionSize]) and y == GetUnitY(checker[collisionSize]) then
            call SetUnitX(checker[collisionSize], 0.00)
            call SetUnitY(checker[collisionSize], 0.00)
            return IssuePointOrder(checker[collisionSize], "blink", x, y)
        endif

        return false
    endfunction

So according to Almia suggestion script will be 100% accurate in this new version.

Moreover I added
JASS:
RAbsBJ(x-GetUnitX(checker[collisionSize])) <= 0.02
because on big maps (more then 224x224) when compare reals like
JASS:
if x == GetUnitX(checker[collisionSize]) then
game sometimes treats this as true, sometimes as false which generate error
on small maps if x==y then works fine, only on bigger maps there are errors.
But with RAbsBJ snippet works fine, and is 100% accurate. Thanks Almia;]
 
Last edited:
Level 19
Joined
Mar 18, 2012
Messages
1,716
I have a few questions towards how this system is working.

Why do we need the coimbination of SetUnitPosition and blink?
I'm aware of possible SetUnitPosition failures, but since the finally outcome
is based on the capability of blinking to x/y, why do we need SetUnitPosition in
the first place?
 
Level 33
Joined
Apr 24, 2012
Messages
5,113
I have a few questions towards how this system is working.

Why do we need the coimbination of SetUnitPosition and blink?
I'm aware of possible SetUnitPosition failures, but since the finally outcome
is based on the capability of blinking to x/y, why do we need SetUnitPosition in
the first place?

SetUnitPosition detects collision and Blink relocates the unit itself.

Well, I think Blink is much better.

@ZiBitTheWand3r3r

Edge of the map:
call SetUnitPosition(u, 2147483647, 2147483647)

Well that's an idea but thanks for making tests which I haven't personally made :D

and also the credits for the method LOL (jk it's a small thing)
 
Level 18
Joined
Nov 21, 2012
Messages
835
Why do we need the coimbination of SetUnitPosition and blink?
I'm aware of possible SetUnitPosition failures, but since the finally outcome
is based on the capability of blinking to x/y, why do we need SetUnitPosition in
the first place?

Omission SetUnitPosition save us 1 line of code and a little faster snippet execution. So it would looks like:
JASS:
call SetUnitPosition(checker[collisionSize], 0.00, 0.00)
  call IssuePointOrder(checker[collisionSize], "blink", x, y)
    if RAbsBJ(x-GetUnitX(checker[collisionSize])) <= 0.02 then
    if RAbsBJ(y-GetUnitY(checker[collisionSize])) <= 0.02 then
      return true            
    endif
    endif
return false
But, please note that we cannot GetUnitX/Y immediately right after issued blink order. It will return "home position" (0.00, 0.00). There is field in ObjectEditor in Abilities section: Stats-Duration: 0.33sec default value for blink. I belive its a time game needs to determine pathing for target point after blink. Thats mean we have to wait 0.33sec to see if target point is pathable...

From very begining I tryed double check by SetUnitPosition + blink.
So we setting checker unit by SetUnitPosition which fails in, lets say, 40%. But if it fails and trap checker unit on cliff/deep water then 2nd part begins. Becouse blink cannot be executed to those not available location it will return false. And despite the fact that 1st check returns true, 2nd check(blink) return false.

//---------
Why I used RAbsBJ ?
On big maps (more then 224x224) comparison reals like (when compating unit and targetPoin coordinates)
if 100.000 == 100.002 then
will return sometimes true, sometimes false.
On normal-size maps its always true..
Theres nice explanation in this thread by Ezekiel12

http://www.hiveworkshop.com/forums/triggers-scripts-269/issuing-orders-effectively-doing-nothing-266636/index2.html#post2696067

zibi
 
Level 18
Joined
Nov 21, 2012
Messages
835
  • Actions
    • Unit - Pause all units
now you can't check pathing

Im really lost with all these vJAss rules, when private when public when constant..
JASS:
globals
        constant integer blinkPathCheckerAbility = 'A000'
        constant integer dummy16Id = 'o000'
        constant integer dummy32Id = 'o001'
        constant integer dummy48Id = 'o002'
        constant integer COLLISION_SIZE_16 = 16
        constant integer COLLISION_SIZE_32 = 32
        constant integer COLLISION_SIZE_48 = 48
        constant unit array checker
endglobals
Can you point me which line to change and to what
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
JASS:
globals
        private constant integer ABILITY_ID = 'A000'// Capital letters, JPAG code convention.
        private constant integer DUMMY_ID_16 = 'o000'
        private constant integer DUMMY_ID_32 = 'o001'
        private constant integer DUMMY_ID_48 = 'o002'
        constant integer COLLISION_SIZE_16 = 16// public? See explanation below.
        constant integer COLLISION_SIZE_32 = 32
        constant integer COLLISION_SIZE_48 = 48
        private unit array checker// Can not be constant, obviously
endglobals

What usage do I gain from the public keyword:
Simple example
JASS:
    public constant integer EXAMPLE = 1
    // Use from somewhere:
    checker[Library_EXAMPLE]// Variable added library prefix to be unique.
   
    constant integer EXAMPLE = 1
    // Use from somewhere
    checker[EXAMPLE]// No prefix, may conflic with another global named EXMAPLE

Conclusion:

The only difference is a chance for conflicting code, if not using the public keyword.
It depends on you, what you imagine as cleaner code.
Some also do constant integer LIBRARY_EXMAPLE = 1 to imitate what the public keyword does.

Edit: Don't check if the dummy unit is paused. We can't protect users from making any mistake.
Checking for paused units is as random as checking if the pathing dummy does exist at all.
 
Last edited:
Level 9
Joined
Jun 21, 2012
Messages
432
Why not just use a single dummy unit? Also you can change the function name to IsPointWalkable?

Other thing, I tested the 'zsmc' with collision 0 and works perfect.

JASS:
//------------------------------------------------------------------------------------------
// Check Walkability 1.08 (by ZibiTheWand3r3r)
// Thanks Almia, IcemanBo, Chaosy, BPower for help and tips.
//
// This snippet allows to check if given point is walkable for 48-size unit, 32-size unit and 16-size unit.
// It uses 3 dummy units + 1 custom ability. It checks walkability by: SetUnitPosition + Blink ability.
// 
// How to import:
// 1. Copy this this trigger to your map.
// 2. From Object Editor copy custom ability named: Blink-PathChecker (A000) and
// three custom units: Dummy16 (o000), Dummy32 (o001) and Dummy48 (o002).
// 3. Use Ctrl+D to check copied units/ability numbers. If they differ from those given in () 
// then modify in globals section.
//
// --API--
// function CheckPathing takes real x, real y, integer collisionSize returns boolean
// use argument collisionSize: COLLISION_SIZE_16 or COLLISION_SIZE_32 or COLLISION_SIZE_48
// function returns true if point (x, y) is walkable for given-size units
//------------------------------------------------------------------------------------------

library CheckWalkability// initializer Init
    globals
        // user configuration: use Ctrl-D in ObjectEditor to see id of ability:
        // if Blink-PathChecker ability id diffrent then A000, then type here the actual value:
        private constant integer ABILITY_ID = 'A000'
        // if Dummy16(peon) unit id diffrent then o000, then type here the actual value:
        private constant integer DUMMY_ID = 'zsmc'//'o000'
        // if Dummy32(grunt) unit id diffrent then o001, then type here the actual value:
        //private constant integer DUMMY_ID_32 = 'o001'
        // if Dummy48(tauren) unit id diffrent then o002, then type here the actual value:
        //private constant integer DUMMY_ID_48 = 'o002'
        //----------------------- don't change anything below -------------------------------------------
        //constant integer COLLISION_SIZE_16 = 16
        //constant integer COLLISION_SIZE_32 = 32
        //constant integer COLLISION_SIZE_48 = 48
        //private unit array checker
        
        private unit u=null
    endglobals
   
    //------------------------ main function -------------------------------------------------
    function IsPointWalkable/*CheckPathing*/ takes real x, real y/*, integer collisionSize*/ returns boolean
        /*debug if checker[collisionSize] == null then
        debug call BJDebugMsg(" Invalid argument, allowed is 16, 32, 48, use pre-defined keys to avoid malfunction")
        debug return false
        debug endif

        call SetUnitPosition(checker[collisionSize], x, y)
        if RAbsBJ(x-GetUnitX(checker[collisionSize])) <= 0.02 then
            if RAbsBJ(y-GetUnitY(checker[collisionSize])) <= 0.02 then
                call SetUnitX(checker[collisionSize], 0.00)
                call SetUnitY(checker[collisionSize], 0.00)
                return IssuePointOrder(checker[collisionSize], "blink", x, y)
            endif
        endif*/
        
        call SetUnitPosition(u,x,y)
        if(RAbsBJ(x-GetUnitX(u))<=.02 and RAbsBJ(y-GetUnitY(u))<=.02)then
            //if RAbsBJ(y-GetUnitY(checker[collisionSize])) <= 0.02 then
                call SetUnitX(u,0)
                call SetUnitY(u,0)
                return IssuePointOrderById(u,852525,x,y) and IssueImmediateOrderById(u,851973)//IssuePointOrder(u, "blink", x, y)
            //endif
        endif
        return false
    endfunction

     //---------------------- initialization function -----------------------------------------------------
    private module Init
        static method onInit takes nothing returns nothing
            /*set checker[COLLISION_SIZE_16] = CreateUnit(Player(15), DUMMY_ID_16, 0.00, 0.00, 0.00)
            set checker[COLLISION_SIZE_32] = CreateUnit(Player(15), DUMMY_ID_32, 0.00, 0.00, 0.00)
            set checker[COLLISION_SIZE_48] = CreateUnit(Player(15), DUMMY_ID_48, 0.00, 0.00, 0.00)
            call UnitAddAbility(checker[COLLISION_SIZE_16], ABILITY_ID)
            call UnitAddAbility(checker[COLLISION_SIZE_16], 'Avul')
            call ShowUnit(checker[COLLISION_SIZE_16], false)
            call UnitAddAbility(checker[COLLISION_SIZE_32], ABILITY_ID)
            call UnitAddAbility(checker[COLLISION_SIZE_32], 'Avul')
            call ShowUnit(checker[COLLISION_SIZE_32], false)
            call UnitAddAbility(checker[COLLISION_SIZE_48], ABILITY_ID)
            call UnitAddAbility(checker[COLLISION_SIZE_48], 'Avul')
            call ShowUnit(checker[COLLISION_SIZE_48], false)*/
            set u=CreateUnit(Player(15),DUMMY_ID,0,0,0)
            call UnitAddAbility(u,ABILITY_ID)
            call UnitAddAbility(u,'Avul')
            call UnitRemoveAbility(u,'Aatk')
            call ShowUnit(u,false)
        endmethod
    endmodule
    private struct i extends array
        implement Init
    endstruct
endlibrary
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I would use indexes 0, 1 and 2. Or 1, 2 and 3. But not 16, 32 and 48.

What you would gain is less memory usage but at the cost of computation time. However both of these are insignificant.

I would gain peace of mind also, just can't stand so many unused indexes increasing the array size ;)
 
Top