Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: [Snippet] IsLineWalkable  (Read 2945 times)

  • Newbie - level 1
  • *
  • Posts: 13
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 0
  • Just a Man in the Back
    • View Profile
[Snippet] IsLineWalkable
« on: August 27, 2016, 10:29:10 PM »
This simple snippet allows you to check for the walkability of the terrain between two points.


Code: jass  [Select]
  1. library IsLineWalkable /*
  2.  
  3.     */uses /*
  4.  
  5.     */TerrainPathability /*
  6.           - http://www.wc3c.net/showthread.php?t=103862 */
  7.  
  8. //! novjass
  9.      ________________
  10.     |                |
  11.     | Written by AGD |
  12.     |________________|
  13.  
  14.  
  15.     |=====|
  16.     | API |
  17.     |=====|
  18.  
  19.         function IsLineWalkable takes real x1, real y1, real x2, real y2 returns boolean/*
  20.         - Checks if the line between points P1(x1, y1) and P2(x2, y2) does not contain any
  21.           any unwalkable coordinates including some doodads, cliffs, mapboundary, and other similar stuffs
  22.  
  23.       */function GetLastWalkableX takes nothing returns real/*
  24.         - Returns the value of the x-coordinate of the last walkable terrain when using IsLineWalkable
  25.  
  26.       */function GetLastWalkableY takes nothing returns real/*
  27.         - Returns the value of the y-coordinate of the last walkable terrain when using IsLineWalkable
  28.  
  29. *///! endnovjass
  30.  
  31.     globals
  32.         ///////////////////////////////////////////
  33.         // The path walkability check distance   //
  34.         // interval. Lower value increases       //
  35.         // precision but may cost performance.   //
  36.         // Suggested value limit (10.00 - 25.00) //
  37.         ///////////////////////////////////////////
  38.         private constant real checkInterval = 20.00
  39.     endglobals
  40.  
  41.     //==============================================================================
  42.  
  43.     globals
  44.         private real X
  45.         private real Y
  46.     endglobals
  47.  
  48.     function IsLineWalkable takes real x1, real y1, real x2, real y2 returns boolean
  49.         local real dx = x2 - x1
  50.         local real dy = y2 - y1
  51.         local real angle
  52.         local real x
  53.         local real y
  54.         if dx*dx + dy*dy < checkInterval*checkInterval then
  55.             if not IsTerrainWalkable(x2, y2) then
  56.                 set X = TerrainPathability_X
  57.                 set Y = TerrainPathability_Y
  58.                 return false
  59.             endif
  60.         else
  61.             set angle = Atan2(dy, dx)
  62.             set x = checkInterval*Cos(angle)
  63.             set y = checkInterval*Sin(angle)
  64.             loop
  65.                 set x1 = x1 + x
  66.                 set y1 = y1 + y
  67.                 exitwhen x1 > x2 or y1 > y2
  68.                 if not IsTerrainWalkable(x1, y1) then
  69.                     set X = TerrainPathability_X
  70.                     set Y = TerrainPathability_Y
  71.                     return false
  72.                 endif
  73.             endloop
  74.         endif
  75.         set X = TerrainPathability_X
  76.         set Y = TerrainPathability_Y
  77.         return true
  78.     endfunction
  79.  
  80.     function GetLastWalkableX takes nothing returns real
  81.         return X
  82.     endfunction
  83.  
  84.     function GetLastWalkableY takes nothing returns real
  85.         return Y
  86.     endfunction
  87.  
  88.  
  89. endlibrary

 

[Snippet] Group Units in line, with distance and optional spread-value

Started by rvonsonsnadtzBoard Codes & Snippets

Replies: 5
Views: 11607
Last post March 13, 2013, 06:52:16 PM
by rvonsonsnadtz
[Snippet] Single Player Detector

Started by moyackBoard Codes & Snippets

Replies: 12
Views: 21215
Last post March 13, 2013, 12:48:49 PM
by Magtheridon96
[Snippet] Simple Unit Indexer

Started by moyackBoard Codes & Snippets

Replies: 17
Views: 26120
Last post September 30, 2013, 08:07:19 AM
by moyack
[Snippet] Disable Transmission Skip

Started by PurgeandfireBoard Codes & Snippets

Replies: 2
Views: 8850
Last post July 02, 2013, 01:34:55 PM
by Purgeandfire
[Snippet] Timed Effects

Started by moyackBoard Codes & Snippets

Replies: 0
Views: 7548
Last post January 09, 2012, 07:03:32 PM
by moyack
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!