# WC3 JASS.com"The Jass Vault" plus vJASS and Zinc

 Warcraft III: Maps Models Skins Icons Spells / Systems Tools Tutorials vJASS & Zinc DocumentationFor the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links: Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

### [Snippet] IsLineWalkable Codes & Snippets

Started by
AGD

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

« Created: February 01, 2018, 10:22:12 PM by moyack »

##### [Snippet] IsLineWalkable
on: August 27, 2016, 10:29:10 PM
Category: Variables
Language: vJASS

This simple snippet allows you to check for the walkability of the terrain between two points.

Code: jass
1. library IsLineWalkable /*
2.
3.     */uses /*
4.
5.     */TerrainPathability /*
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
« Last Edit: December 19, 2017, 10:55:56 PM by moyack »

##### Re: [Snippet] IsLineWalkable
Reply #1 on: August 12, 2018, 01:32:46 AM

What do you mean by "publishing"?

##### Re: [Snippet] IsLineWalkable
Reply #2 on: August 12, 2018, 09:50:27 PM

What do you mean by "publishing"?
Hmm, it seems to be a fool bot.

EDIT: Yes, effectively. User removed.

 Started by PitzerMike Replies: 0Views: 1151 Codes & Snippets Started by Purgeandfire Replies: 0Views: 1179 Codes & Snippets Started by Bribe Replies: 0Views: 1489 Codes & Snippets Started by moyack Replies: 0Views: 9394 Codes & Snippets Started by Magtheridon96 Replies: 1Views: 8217 Codes & Snippets