Wc3C.net

Wc3C.net (http://www.wc3c.net/forums.php)
-   Scripts (http://www.wc3c.net/forumdisplay.php?f=737)
-   -   TerrainPathability (http://www.wc3c.net/showthread.php?t=103862)

Rising_Dusk 12-30-2008 05:57 AM

TerrainPathability
 
1 Attachment(s)
TerrainPathability Library

Background:
This is a library of code that allows users to detect whether a given point of terrain is land, shallow water, deep water, or walkable with great simplicity.

Requirements:
  • (None)
Credits:Code:
Expand Library:

Function List:
This library provides the following functions to the user.
  • function IsTerrainDeepWater takes real x, real y returns boolean
  • function IsTerrainShallowWater takes real x, real y returns boolean
  • function IsTerrainLand takes real x, real y returns boolean
  • function IsTerrainPlatform takes real x, real y returns boolean
  • function IsTerrainWalkable takes real x, real y returns boolean
I also attached a testmap that shows my method in action. Originally, this library used a windwalk'd unit to detect walkability of terrain, but after some benchmarks, the item method proved to be reliably and significantly faster. Anitarf then agreed that I should use that version of the walkability check in this library, as originally used in his resource, so here it is. If you used the older version of this library, you can go ahead and delete the windwalk dummy ability, it's no longer necessary. Fly the Gryphon around and you can see what the system returns for wherever it is at any given time.

Backwards Compatibility:
In the event that you used IsTerrainWalkable in your map, the following backwards compatibility library has been provided for your convenience. Simply replace the old library with the library below and it will work fine.
Expand IsTerrainWalkable:

Enjoy!

Troll-Brain 12-30-2008 11:51 AM

Nice resource.
Few points :

- You should add a constant dummy player.
- What about move the unit outside the playable map area if it was moved ?
I mean she is insivible, with no collision and all, but the unit still can be enumed.

emjlr3 12-30-2008 01:58 PM

Collapse JASS:
not (not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY)

huh...don't they cancel out, like a double negative?

Vexorian 12-30-2008 02:05 PM

emjlr3 double check that expression ...
--
I think the bunch of other things to detect are a little useless. All that was needed was walkable, the rest we already had natives for, I think it is simpler to just call IsTerrainPathable in cases when we want to detect land or water. Just saying this so it could just remain 'IsTerrainWalkable' but using the new method so that migration would be easy, both things do the same and detecting true on deep water was just a bug so, it is natural to "fix it" by using this new method. Though I think that having to use a dummy ability is a little too much, aren't there passive abilities that do the same windwalk does? Or you could add the IsTerrainWalkable function to what you have now and also a library library IsTerrainWalkable that requires this new one that has all these constants.

Quote:

I mean she is insivible, with no collision and all, but the unit still can be enumed.
Should probably hide the unit.

emjlr3 12-30-2008 02:58 PM

yea I figured I had missed the other )

Quote:

Should probably hide the unit.

or 'Aloc' it (not sure what 'Avul' does - i assume its for invulnerability)

Troll-Brain 12-30-2008 04:49 PM

Use 'Aloc' will not work since an unit witch have this ability can be on every pathing, that would be a nice function witch always return true, but hide/unhide the unit is the way to go i think.
Hmm but for some reasons if a player use a group for filter hidden units in a range R on X/Y, then the hidden unit would be enumed so.
And if you place the unit outside the playable map area, i don't see any problem, but correct me if i'm wrong.

emjlr3 12-30-2008 05:59 PM

doesn't that crash maps online? - thus the needed for map border checks when using SetUnitX/Y

Rising_Dusk 12-30-2008 06:01 PM

Quote:

Originally Posted by Troll-Brain
- You should add a constant dummy player.

It is unnecessary, but I will do it anyways for completeness of constants.
Quote:

Originally Posted by Vexorian
I think the bunch of other things to detect are a little useless.

If you look at my knockback system in the database, being able to differentiate between shallow water and land is incredibly useful. It is also useful if you want spells to do different things on shallow water as opposed to land, which can be practical for different map types. I only included deep water because I had shallow water and land and wanted the complete spectrum.
Quote:

Originally Posted by Vexorian
the rest we already had natives for

I am aware that we can check the tile, but I was not aware that we could check shallow water/land/etc. What native is it?
Quote:

Originally Posted by Vexorian
Should probably hide the unit.

Generally, most mapmakers exclude their dummy units from enumeration, but I can hide it.
Quote:

Originally Posted by Vexorian
I think it is simpler to just call IsTerrainPathable in cases when we want to detect land or water

If WALKABILITY and FLOATABILITY and AMPHIBIOUS returned reliably for shallow water/deep water/land, this wouldn't be a problem. The issue is that the native is incredibly counterintuitive and most people would never guess that FLOATABILITY is the only reliable way to detect land and vice versa.
Quote:

Originally Posted by Vexorian
aren't there passive abilities that do the same windwalk does?

I wish. It is the passing through units behavior of Windwalk that makes it so necessary. It is the only spell or manner to properly do it without walking through trees and so forth.

Vex, it seems you want an IsTerrainWalkable function, but I thought we didn't want to have function name conflicts in the database? I was originally going to separate walkable from the rest, but I remember once you got angry for me using a function name already in the database. I am not sure.
Quote:

Originally Posted by Troll-Brain
And if you place the unit outside the playable map area, i don't see any problem, but correct me if i'm wrong.

SetUnitPosition won't go out of map area, and SetUnitX/Y crashes if you tell it to go out of map bounds. I think hiding the unit will suffice.

Troll-Brain 12-30-2008 06:33 PM

No you don't get it i said outside the playable map area not the entire map

Collapse JASS:
library GetWorldBoundsMin initializer init

globals
    private real Xmin
    private real Ymin
endglobals

    
public function init takes nothing returns nothing
    local rect r= GetWorldBounds()
    
    set Xmin= GetRectMinX(r)
    set Ymin= GetRectMinY(r)
    
    call RemoveRect(r)
    set r=null
endfunction
    
    
endlibrary

And with the function SetUnitX/Y the unit will be outside the playable map area with no crash, i already used it for other stuff.

Rising_Dusk 12-30-2008 07:20 PM

That does not fix the enumeration issue, though, it only makes it less likely. Hiding it will fix the enumeration problem, I believe.

moyack 12-30-2008 07:25 PM

With only adding and removing 'Aloc' you can enumerate units...

Rising_Dusk 12-30-2008 07:27 PM

Aloc interferes with the collisional properties of the dummy unit, though.

Troll-Brain 12-30-2008 07:52 PM

Quote:

Originally Posted by Rising_Dusk
That does not fix the enumeration issue, though, it only makes it less likely. Hiding it will fix the enumeration problem, I believe.

Or do both :p

Rising_Dusk 12-30-2008 07:56 PM

I want to avoid as much unnecessary unit handling as possible. I think I will hide the unit only.

Troll-Brain 12-30-2008 08:01 PM

Just a question, is it possible to know with a native fuction if an unit is hidden by an ability or by the action ShowUnit ?
Yes i know we could link a boolean to the unit, or add it in a group when we hide it with ShowUnit, and after check if the unit is in or not, and so one, that's not the question.


All times are GMT. The time now is 10:32 PM.

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services