[JASS] How to check for deep and shallow water ?

Status
Not open for further replies.

Ardenian

A

Ardenian

Thanks, so it is:
JASS:
 if IsTerrainPathable(x,y,PATHING_TYPE_FLOATABILITY) or not IsTerrainPathable(x,y,PATHING_TYPE_WALKABILITY) then
I test it, thanks alot!


EDIT: Bah, I am too stupid for this.

JASS:
if not IsTerrainPathable(x,y,PATHING_TYPE_FLOATABILITY)then

This gives correctly all deep water, but only partly shallow water ( due to cliffs, I assume).
What do I have to add to include all shallow water ?
 
Last edited by a moderator:
Level 14
Joined
Jul 1, 2008
Messages
1,314
What do I have to add to include all shallow water ?

try this :)

JASS:
function CheckLocationWaterType takes real x, real y returns integer
        // this function checks the pathability of a point for being shallow or deep water
        /*returns   0 - solid ground; 1 - shallow water; 2 - deep water; */
        local boolean pathable  = not IsTerrainPathable( x, y, PATHING_TYPE_WALKABILITY)
        local boolean floatable = not IsTerrainPathable( x, y, PATHING_TYPE_FLOATABILITY)
        if pathable and ( not floatable) then
            return 0 // location is solid ground
        elseif pathable and floatable then
            return 1 // location is shallow water
        elseif ( not pathable) and floatable then
            return 2 // location is deep water
        endif
        return 0
    endfunction
 
I told you to view this: http://www.hiveworkshop.com/forums/jass-resources-412/snippet-zlibrary-237821/

Because this lib does the functionality you want :)

JASS:
function GetWaterDepth takes real x, real y returns real
        local real z
        local destructable d
        call MoveLocation(p, x, y)
        set z = GetLocationZ(p)
        set d = CreateDestructable(PLATFORM, x, y, 0.0, 10.0, 0)
        set z = z + PLATFORM_HEIGHT - GetLocationZ(p)
        call RemoveDestructable(d)
        set d = null
        if z >= 0.0 then // Small negative results may occur such as -0.0001
            return z
        endif
        return 0.0
    endfunction
    
    function GetWaterType takes real x, real y returns integer
        local real d = GetWaterDepth(x, y)
        if d == 0.0 then
            return WATER_TYPE_NONE
        elseif d < WATER_DEPTH_SHALLOW then
            return WATER_TYPE_SHALLOW
        endif
        return WATER_TYPE_DEEP
    endfunction
 

Ardenian

A

Ardenian

@Emm-A- Thanks a lot, however, there seems to be an issue preventing the display of my test, I have to debug what it is.

@Almia Yes, thank you, however, it uses a dummy, I don't want to be petty, but I hope it can be solved only with conditions, as in Emm-A-'s solution

By the why, it doesn't matter to me if it is deep or shallow, only if there is none or any of both

EDIT:

Alright, Emm-A-'s function only gives parts of the shallow water ( that cliff relation issue). I try Almia's now.
 

Ardenian

A

Ardenian

Never mind what I said before Almia. I tried to use the one from the library:

JASS:
function GetWaterDepth takes real x, real y returns real
    local real z
    local integer PLATFORM = 'OTip'
    local real PLATFORM_HEIGHT = 2745.46265
    local destructable d
    local location p = Location(0.0, 0.0)
    call MoveLocation(p, x, y)
    set z = GetLocationZ(p)
    set d = CreateDestructable(PLATFORM, x, y, 0.0, 10.0, 0)
    set z = z + PLATFORM_HEIGHT - GetLocationZ(p)
    call RemoveDestructable(d)
    set d = null
    if z >= 0.0 then // Small negative results may occur such as -0.0001
        return z
    endif
    return 0.0
endfunction
   
function GetWaterType takes real x, real y returns integer
    local real d = GetWaterDepth(x, y)
    local real WATER_DEPTH_SHALLOW = 52.0
    local integer WATER_TYPE_DEEP = 2
    local integer WATER_TYPE_SHALLOW = 1
    local integer WATER_TYPE_NONE = 0
    if d == 0.0 then
        return WATER_TYPE_NONE
    elseif d < WATER_DEPTH_SHALLOW then
        return WATER_TYPE_SHALLOW
    endif
    return WATER_TYPE_DEEP
endfunction

calling it with:
JASS:
if GetWaterType(x,y) > 0 then

However, it always triggers/counts, doesn't differ between ground and water
 
Level 5
Joined
Mar 6, 2015
Messages
130
use this as a checking condition
JASS:
GetTerrainCliffLevel(GetLocationX(where),GetLocationY(where))

this function returns an integer:
0 means deep water
1 means shallow water
2 means Ground

you can combine it with
JASS:
GetLocationZ(where)
for some special circumstances
 

Ardenian

A

Ardenian

This solution would only work if the map's initial cliff level is 2 and it would also not work for water being played on a higher cliff, would it ?
 
Level 5
Joined
Mar 6, 2015
Messages
130
This solution would only work if the map's initial cliff level is 2 and it would also not work for water being played on a higher cliff, would it ?

I haven't test that already I think the worldedit still count them as level 1 or 0 other technique that I suggest is to use the getlocationz inorder to recognize the difference between water level and ground I think shallow and deep waters both have -89 Z combine it with cliff level function for creating a general method
 

Ardenian

A

Ardenian

I don't think this method works, Skyflash. You would not only have to know the initial cliff level of the map, there is also no way to check for water on higher cliff levels than intial.
 

Ardenian

A

Ardenian

I changed it to 'LT06', Doodads\Terrain\WoodBridgeLarge0\WoodBridgeLarge0, but now it seems to reverse the count ( water is ground, ground is water) and I am sure my code is correct.

JASS:
function GetTileCenterCoordinate takes real a returns real
    if (a >= 0.) then
        set a = R2I((a/128) + .5)
    else
        set a = R2I((a/128) - .5)
    endif
    return a*128
endfunction

//GetTerrainTypeInRange by Ardenian

function GetWaterDepth takes real x, real y returns real
    local real z
    local integer PLATFORM = 'LT06'
    local real PLATFORM_HEIGHT = 2745.46265
    local destructable d
    local location p = Location(0.0, 0.0)
    call MoveLocation(p, x, y)
    set z = GetLocationZ(p)
    set d = CreateDestructable(PLATFORM, x, y, 0.0, 10.0, 0)
    set z = z + PLATFORM_HEIGHT - GetLocationZ(p)
    call RemoveDestructable(d)
    set d = null
    if z >= 0.0 then // Small negative results may occur such as -0.0001
        return z
    endif
    return 0.0
endfunction
   
function GetWaterType takes real x, real y returns integer
    local real d = GetWaterDepth(x, y)
    local real WATER_DEPTH_SHALLOW = 52.0
    local integer WATER_TYPE_DEEP = 2
    local integer WATER_TYPE_SHALLOW = 1
    local integer WATER_TYPE_NONE = 0
    if d == 0.0 then
        return WATER_TYPE_NONE
    elseif d < WATER_DEPTH_SHALLOW then
        return WATER_TYPE_SHALLOW
    endif
    return WATER_TYPE_DEEP
endfunction


function IsTerrainType takes real x, real y, string tt, integer ic returns integer
    if tt == "blight" then
        if IsPointBlighted( x, y) == true then
            set ic = ic + 1
        endif
        return ic
    elseif tt == "water" then
        if GetWaterType(x,y) > 0 then
            set ic = ic + 1
        endif
        return ic
    elseif GetTerrainType( x, y) == S2I(tt) then
        set ic = ic + 1
        return ic
    endif
    return ic
endfunction

function GetTerrainTypeInRange takes location p, string tt, real range returns integer
    local integer pn = 1 // algebraic sign +/-
    local integer ic = 0 // counts matching tiles
    local real x
    local real y  
    local real y2
    local real y3
    local real px = GetTileCenterCoordinate(GetLocationX(p))// x of the next tile center to a point
    local real py = GetTileCenterCoordinate(GetLocationY(p))// y of the next tile center to a point
    set x = px
    set y = py
    set ic = IsTerrainType( x, y, tt, ic) // check the initial tile
    loop // decide direction, first positive, then negative  
    exitwhen pn < -1 // runs two times, once positive and once negative
   
        set x = px // reset to inital tile
        set y = py // reset to inital tile                
   
        loop // update x tile, moving along the x axis dependent on pn
        exitwhen SquareRoot((x - px)*(x - px) + (y - py)*(y - py)) > range
            set x = x + 128*pn
            set ic = IsTerrainType( x, y, tt, ic) // check tiles on the x axis
            set y2 = y
            set y3 = y
            // go up and down in y direction
            loop
            exitwhen SquareRoot((x - px)*(x - px) + (y2 - py)*(y2 - py)) > range
                   
                set y2 = y2 + 128
                set ic = IsTerrainType( x, y2, tt, ic) // check tiles on the positive y branch
               
            endloop
            loop
            exitwhen SquareRoot((x - px)*(x - px) + (y3 - py)*(y3 - py)) > range    
                   
                set y3 = y3 - 128
                set ic = IsTerrainType( x, y3, tt, ic) // check tiles on the negative y branch
           
            endloop    
     
        endloop
        set x = px
        // go up and down y from initial x tile
        loop
        exitwhen SquareRoot((x - px)*(x - px) + (y - py)*(y - py)) > range
            set y = y + 128*pn
            set ic = IsTerrainType( x, y, tt, ic)
        endloop
        set pn = pn-2 // reverse direction, run again once
    endloop
    return ic
   
endfunction

Might the problem be with that object merger thingy ?

D.O.G. says
Functions require 1 custom destructable.
Object Merger script for generating destructable is inside code, demo map is attached to the post.
 
Last edited by a moderator:

Ardenian

A

Ardenian

Great, Almia! I altered the object data of OTis to the one from the custom system and now it works!
Thanks a lot, Almia, and thanks to everyone who helped!
 

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,267
I might be late to butt in but

IsTerrainPathableBJ(udg_TempPoint1,PATHING_TYPE_WALKABILITY) == true (walkable?)

and in GUI it shows up like this:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Terrain pathing at TempPoint1 of type Walkability is off) Equal to true
walkability = off.
not a place to walk.

___________

Then

IsTerrainPathableBJ(udg_TempPoint1,PATHING_TYPE_WALKABILITY) == false (not walkable?)

In GUI its like this:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Terrain pathing at TempPoint1 of type Walkability is off) Equal to False
This is walkable. You cannot walk and its false... eeehmmm you can walk there.


I am right? Seems like blizzard mixed and mirrored this.
 

Ardenian

A

Ardenian

Yes, TKF, I read that somewhere, too, it is quite confusing
 
Status
Not open for further replies.
Top