GeoData.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver;
  20. import java.io.FileInputStream;
  21. import java.lang.reflect.Constructor;
  22. import java.nio.file.Paths;
  23. import java.util.Properties;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import com.l2jserver.Config;
  27. import com.l2jserver.gameserver.datatables.DoorTable;
  28. import com.l2jserver.gameserver.geoengine.Direction;
  29. import com.l2jserver.gameserver.geoengine.NullDriver;
  30. import com.l2jserver.gameserver.geoengine.abstraction.IGeoDriver;
  31. import com.l2jserver.gameserver.model.L2Object;
  32. import com.l2jserver.gameserver.model.Location;
  33. import com.l2jserver.gameserver.model.interfaces.ILocational;
  34. import com.l2jserver.gameserver.util.GeoUtils;
  35. import com.l2jserver.gameserver.util.LinePointIterator;
  36. import com.l2jserver.gameserver.util.LinePointIterator3D;
  37. /**
  38. * @author -Nemesiss-, FBIagent
  39. */
  40. public class GeoData implements IGeoDriver
  41. {
  42. private static class SingletonHolder
  43. {
  44. protected final static GeoData _instance;
  45. static
  46. {
  47. _instance = new GeoData();
  48. }
  49. }
  50. private static final Logger LOGGER = Logger.getLogger(GeoData.class.getName());
  51. private static final int ELEVATED_SEE_OVER_DISTANCE = 2;
  52. private static final int MAX_SEE_OVER_HEIGHT = 48;
  53. public static GeoData getInstance()
  54. {
  55. return SingletonHolder._instance;
  56. }
  57. private final IGeoDriver _driver;
  58. protected GeoData()
  59. {
  60. if (Config.GEODATA > 0)
  61. {
  62. IGeoDriver driver = null;
  63. try
  64. {
  65. Class<?> cls = Class.forName(Config.GEODATA_DRIVER);
  66. if (!IGeoDriver.class.isAssignableFrom(cls))
  67. {
  68. throw new ClassCastException("Geodata driver class needs to implement IGeoDriver!");
  69. }
  70. Constructor<?> ctor = cls.getConstructor(Properties.class);
  71. Properties props = new Properties();
  72. try (FileInputStream fis = new FileInputStream(Paths.get("config", "GeoDriver.properties").toString()))
  73. {
  74. props.load(fis);
  75. }
  76. driver = (IGeoDriver) ctor.newInstance(props);
  77. }
  78. catch (Exception ex)
  79. {
  80. LOGGER.log(Level.SEVERE, "Failed to load geodata driver!", ex);
  81. System.exit(1);
  82. }
  83. // we do it this way so it's predictable for the compiler
  84. _driver = driver;
  85. }
  86. else
  87. {
  88. _driver = new NullDriver(null);
  89. }
  90. }
  91. @Override
  92. public int getGeoX(int worldX)
  93. {
  94. return _driver.getGeoX(worldX);
  95. }
  96. @Override
  97. public int getGeoY(int worldY)
  98. {
  99. return _driver.getGeoY(worldY);
  100. }
  101. @Override
  102. public int getWorldX(int geoX)
  103. {
  104. return _driver.getWorldX(geoX);
  105. }
  106. @Override
  107. public int getWorldY(int geoY)
  108. {
  109. return _driver.getWorldY(geoY);
  110. }
  111. @Override
  112. public boolean hasGeoPos(int geoX, int geoY)
  113. {
  114. return _driver.hasGeoPos(geoX, geoY);
  115. }
  116. @Override
  117. public int getNearestZ(int geoX, int geoY, int worldZ)
  118. {
  119. return _driver.getNearestZ(geoX, geoY, worldZ);
  120. }
  121. @Override
  122. public int getNextLowerZ(int geoX, int geoY, int worldZ)
  123. {
  124. return _driver.getNextLowerZ(geoX, geoY, worldZ);
  125. }
  126. @Override
  127. public int getNextHigherZ(int geoX, int geoY, int worldZ)
  128. {
  129. return _driver.getNextHigherZ(geoX, geoY, worldZ);
  130. }
  131. @Override
  132. public boolean canEnterNeighbors(int geoX, int geoY, int worldZ, Direction first, Direction... more)
  133. {
  134. return _driver.canEnterNeighbors(geoX, geoY, worldZ, first, more);
  135. }
  136. @Override
  137. public boolean canEnterAllNeighbors(int geoX, int geoY, int worldZ)
  138. {
  139. return _driver.canEnterAllNeighbors(geoX, geoY, worldZ);
  140. }
  141. // ///////////////////
  142. // L2J METHODS
  143. public boolean isNullDriver()
  144. {
  145. return _driver instanceof NullDriver;
  146. }
  147. /**
  148. * Gets the height.
  149. * @param x the x coordinate
  150. * @param y the y coordinate
  151. * @param z the z coordinate
  152. * @return the height
  153. */
  154. public int getHeight(int x, int y, int z)
  155. {
  156. return getNearestZ(getGeoX(x), getGeoY(y), z);
  157. }
  158. /**
  159. * Gets the spawn height.
  160. * @param x the x coordinate
  161. * @param y the y coordinate
  162. * @param zmin the minimum z coordinate
  163. * @param zmax the the maximum z coordinate
  164. * @return the spawn height
  165. */
  166. public int getSpawnHeight(int x, int y, int zmin, int zmax)
  167. {
  168. // + 30, defend against defective geodata and invalid spawn z :(
  169. return getNextLowerZ(getGeoX(x), getGeoY(y), zmax + 30);
  170. }
  171. /**
  172. * Can see target. Doors as target always return true. Checks doors between.
  173. * @param cha the character
  174. * @param target the target
  175. * @return {@code true} if the character can see the target (LOS), {@code false} otherwise
  176. */
  177. public boolean canSeeTarget(L2Object cha, L2Object target)
  178. {
  179. if (target.isDoor())
  180. {
  181. // can always see doors :o
  182. return true;
  183. }
  184. return canSeeTarget(cha.getX(), cha.getY(), cha.getZ(), cha.getInstanceId(), target.getX(), target.getY(), target.getZ(), target.getInstanceId());
  185. }
  186. /**
  187. * Can see target. Checks doors between.
  188. * @param cha the character
  189. * @param worldPosition the world position
  190. * @return {@code true} if the character can see the target at the given world position, {@code false} otherwise
  191. */
  192. public boolean canSeeTarget(L2Object cha, ILocational worldPosition)
  193. {
  194. return canSeeTarget(cha.getX(), cha.getY(), cha.getZ(), cha.getInstanceId(), worldPosition.getX(), worldPosition.getY(), worldPosition.getZ());
  195. }
  196. /**
  197. * Can see target. Checks doors between.
  198. * @param x the x coordinate
  199. * @param y the y coordinate
  200. * @param z the z coordinate
  201. * @param instanceId
  202. * @param tx the target's x coordinate
  203. * @param ty the target's y coordinate
  204. * @param tz the target's z coordinate
  205. * @param tInstanceId the target's instanceId
  206. * @return
  207. */
  208. public boolean canSeeTarget(int x, int y, int z, int instanceId, int tx, int ty, int tz, int tInstanceId)
  209. {
  210. if ((instanceId != tInstanceId))
  211. {
  212. return false;
  213. }
  214. return canSeeTarget(x, y, z, instanceId, tx, ty, tz);
  215. }
  216. /**
  217. * Can see target. Checks doors between.
  218. * @param x the x coordinate
  219. * @param y the y coordinate
  220. * @param z the z coordinate
  221. * @param instanceId
  222. * @param tx the target's x coordinate
  223. * @param ty the target's y coordinate
  224. * @param tz the target's z coordinate
  225. * @return {@code true} if there is line of sight between the given coordinate sets, {@code false} otherwise
  226. */
  227. public boolean canSeeTarget(int x, int y, int z, int instanceId, int tx, int ty, int tz)
  228. {
  229. if (DoorTable.getInstance().checkIfDoorsBetween(x, y, z, tx, ty, tz, instanceId, true))
  230. {
  231. return false;
  232. }
  233. return canSeeTarget(x, y, z, tx, ty, tz);
  234. }
  235. private int getLosGeoZ(int prevX, int prevY, int prevGeoZ, int curX, int curY, Direction dir)
  236. {
  237. boolean can = true;
  238. switch (dir)
  239. {
  240. case NORTH_EAST:
  241. can = canEnterNeighbors(prevX, prevY - 1, prevGeoZ, Direction.EAST) && canEnterNeighbors(prevX + 1, prevY, prevGeoZ, Direction.NORTH);
  242. break;
  243. case NORTH_WEST:
  244. can = canEnterNeighbors(prevX, prevY - 1, prevGeoZ, Direction.WEST) && canEnterNeighbors(prevX - 1, prevY, prevGeoZ, Direction.NORTH);
  245. break;
  246. case SOUTH_EAST:
  247. can = canEnterNeighbors(prevX, prevY + 1, prevGeoZ, Direction.EAST) && canEnterNeighbors(prevX + 1, prevY, prevGeoZ, Direction.SOUTH);
  248. break;
  249. case SOUTH_WEST:
  250. can = canEnterNeighbors(prevX, prevY + 1, prevGeoZ, Direction.WEST) && canEnterNeighbors(prevX - 1, prevY, prevGeoZ, Direction.SOUTH);
  251. break;
  252. }
  253. if (can && canEnterNeighbors(prevX, prevY, prevGeoZ, dir))
  254. {
  255. return getNearestZ(curX, curY, prevGeoZ);
  256. }
  257. return getNextHigherZ(curX, curY, prevGeoZ);
  258. }
  259. /**
  260. * Can see target. Does not check doors between.
  261. * @param x the x coordinate
  262. * @param y the y coordinate
  263. * @param z the z coordinate
  264. * @param tx the target's x coordinate
  265. * @param ty the target's y coordinate
  266. * @param tz the target's z coordinate
  267. * @return {@code true} if there is line of sight between the given coordinate sets, {@code false} otherwise
  268. */
  269. public boolean canSeeTarget(int x, int y, int z, int tx, int ty, int tz)
  270. {
  271. int geoX = getGeoX(x);
  272. int geoY = getGeoY(y);
  273. int tGeoX = getGeoX(tx);
  274. int tGeoY = getGeoY(ty);
  275. z = getNearestZ(geoX, geoY, z);
  276. tz = getNearestZ(tGeoX, tGeoY, tz);
  277. if ((geoX == tGeoX) && (geoY == tGeoY))
  278. {
  279. if (hasGeoPos(tGeoX, tGeoY))
  280. {
  281. return z == tz;
  282. }
  283. return true;
  284. }
  285. if (tz > z)
  286. {
  287. int tmp = tx;
  288. tx = x;
  289. x = tmp;
  290. tmp = ty;
  291. ty = y;
  292. y = tmp;
  293. tmp = tz;
  294. tz = z;
  295. z = tmp;
  296. tmp = tGeoX;
  297. tGeoX = geoX;
  298. geoX = tmp;
  299. tmp = tGeoY;
  300. tGeoY = geoY;
  301. geoY = tmp;
  302. }
  303. LinePointIterator3D pointIter = new LinePointIterator3D(geoX, geoY, z, tGeoX, tGeoY, tz);
  304. // first point is guaranteed to be available, skip it, we can always see our own position
  305. pointIter.next();
  306. int prevX = pointIter.x();
  307. int prevY = pointIter.y();
  308. int prevZ = pointIter.z();
  309. int prevGeoZ = prevZ;
  310. int ptIndex = 0;
  311. while (pointIter.next())
  312. {
  313. int curX = pointIter.x();
  314. int curY = pointIter.y();
  315. if ((curX == prevX) && (curY == prevY))
  316. {
  317. continue;
  318. }
  319. int beeCurZ = pointIter.z();
  320. int curGeoZ = prevGeoZ;
  321. // the current position has geodata
  322. if (hasGeoPos(curX, curY))
  323. {
  324. int beeCurGeoZ = getNearestZ(curX, curY, beeCurZ);
  325. Direction dir = GeoUtils.computeDirection(prevX, prevY, curX, curY);
  326. curGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, curX, curY, dir);
  327. int maxHeight;
  328. if (ptIndex < ELEVATED_SEE_OVER_DISTANCE)
  329. {
  330. maxHeight = z + MAX_SEE_OVER_HEIGHT;
  331. }
  332. else
  333. {
  334. maxHeight = beeCurZ + MAX_SEE_OVER_HEIGHT;
  335. }
  336. boolean canSeeThrough = false;
  337. if ((curGeoZ <= maxHeight) && (curGeoZ <= beeCurGeoZ))
  338. {
  339. switch (dir)
  340. {
  341. case NORTH_EAST:
  342. {
  343. int northGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, prevX, prevY - 1, Direction.EAST);
  344. int eastGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, prevX + 1, prevY, Direction.NORTH);
  345. canSeeThrough = (northGeoZ <= maxHeight) && (eastGeoZ <= maxHeight) && (northGeoZ <= getNearestZ(prevX, prevY - 1, beeCurZ)) && (eastGeoZ <= getNearestZ(prevX + 1, prevY, beeCurZ));
  346. break;
  347. }
  348. case NORTH_WEST:
  349. {
  350. int northGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, prevX, prevY - 1, Direction.WEST);
  351. int westGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, prevX - 1, prevY, Direction.NORTH);
  352. canSeeThrough = (northGeoZ <= maxHeight) && (westGeoZ <= maxHeight) && (northGeoZ <= getNearestZ(prevX, prevY - 1, beeCurZ)) && (westGeoZ <= getNearestZ(prevX - 1, prevY, beeCurZ));
  353. break;
  354. }
  355. case SOUTH_EAST:
  356. {
  357. int southGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, prevX, prevY + 1, Direction.EAST);
  358. int eastGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, prevX + 1, prevY, Direction.SOUTH);
  359. canSeeThrough = (southGeoZ <= maxHeight) && (eastGeoZ <= maxHeight) && (southGeoZ <= getNearestZ(prevX, prevY + 1, beeCurZ)) && (eastGeoZ <= getNearestZ(prevX + 1, prevY, beeCurZ));
  360. break;
  361. }
  362. case SOUTH_WEST:
  363. {
  364. int southGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, prevX, prevY + 1, Direction.WEST);
  365. int westGeoZ = getLosGeoZ(prevX, prevY, prevGeoZ, prevX - 1, prevY, Direction.SOUTH);
  366. canSeeThrough = (southGeoZ <= maxHeight) && (westGeoZ <= maxHeight) && (southGeoZ <= getNearestZ(prevX, prevY + 1, beeCurZ)) && (westGeoZ <= getNearestZ(prevX - 1, prevY, beeCurZ));
  367. break;
  368. }
  369. default:
  370. {
  371. canSeeThrough = true;
  372. break;
  373. }
  374. }
  375. }
  376. if (!canSeeThrough)
  377. {
  378. return false;
  379. }
  380. }
  381. prevX = curX;
  382. prevY = curY;
  383. prevGeoZ = curGeoZ;
  384. ++ptIndex;
  385. }
  386. return true;
  387. }
  388. /**
  389. * Move check.
  390. * @param x the x coordinate
  391. * @param y the y coordinate
  392. * @param z the z coordinate
  393. * @param tx the target's x coordinate
  394. * @param ty the target's y coordinate
  395. * @param tz the target's z coordinate
  396. * @param instanceId the instance id
  397. * @return the last Location (x,y,z) where player can walk - just before wall
  398. */
  399. public Location moveCheck(int x, int y, int z, int tx, int ty, int tz, int instanceId)
  400. {
  401. int geoX = getGeoX(x);
  402. int geoY = getGeoY(y);
  403. z = getNearestZ(geoX, geoY, z);
  404. int tGeoX = getGeoX(tx);
  405. int tGeoY = getGeoY(ty);
  406. tz = getNearestZ(tGeoX, tGeoY, tz);
  407. if (DoorTable.getInstance().checkIfDoorsBetween(x, y, z, tx, ty, tz, instanceId, false))
  408. {
  409. return new Location(x, y, getHeight(x, y, z));
  410. }
  411. LinePointIterator pointIter = new LinePointIterator(geoX, geoY, tGeoX, tGeoY);
  412. // first point is guaranteed to be available
  413. pointIter.next();
  414. int prevX = pointIter.x();
  415. int prevY = pointIter.y();
  416. int prevZ = z;
  417. while (pointIter.next())
  418. {
  419. int curX = pointIter.x();
  420. int curY = pointIter.y();
  421. int curZ = getNearestZ(curX, curY, prevZ);
  422. if (hasGeoPos(prevX, prevY))
  423. {
  424. Direction dir = GeoUtils.computeDirection(prevX, prevY, curX, curY);
  425. boolean canEnter = false;
  426. if (canEnterNeighbors(prevX, prevY, prevZ, dir))
  427. {
  428. // check diagonal movement
  429. switch (dir)
  430. {
  431. case NORTH_EAST:
  432. canEnter = canEnterNeighbors(prevX, prevY - 1, prevZ, Direction.EAST) && canEnterNeighbors(prevX + 1, prevY, prevZ, Direction.NORTH);
  433. break;
  434. case NORTH_WEST:
  435. canEnter = canEnterNeighbors(prevX, prevY - 1, prevZ, Direction.WEST) && canEnterNeighbors(prevX - 1, prevY, prevZ, Direction.NORTH);
  436. break;
  437. case SOUTH_EAST:
  438. canEnter = canEnterNeighbors(prevX, prevY + 1, prevZ, Direction.EAST) && canEnterNeighbors(prevX + 1, prevY, prevZ, Direction.SOUTH);
  439. break;
  440. case SOUTH_WEST:
  441. canEnter = canEnterNeighbors(prevX, prevY + 1, prevZ, Direction.WEST) && canEnterNeighbors(prevX - 1, prevY, prevZ, Direction.SOUTH);
  442. break;
  443. default:
  444. canEnter = true;
  445. break;
  446. }
  447. }
  448. if (!canEnter)
  449. {
  450. // can't move, return previous location
  451. return new Location(getWorldX(prevX), getWorldY(prevY), prevZ);
  452. }
  453. }
  454. prevX = curX;
  455. prevY = curY;
  456. prevZ = curZ;
  457. }
  458. if (hasGeoPos(prevX, prevY) && (prevZ != tz))
  459. {
  460. // different floors, return start location
  461. return new Location(x, y, z);
  462. }
  463. return new Location(tx, ty, tz);
  464. }
  465. /**
  466. * Checks if its possible to move from one location to another.
  467. * @param fromX the X coordinate to start checking from
  468. * @param fromY the Y coordinate to start checking from
  469. * @param fromZ the Z coordinate to start checking from
  470. * @param toX the X coordinate to end checking at
  471. * @param toY the Y coordinate to end checking at
  472. * @param toZ the Z coordinate to end checking at
  473. * @param instanceId the instance ID
  474. * @return {@code true} if the character at start coordinates can move to end coordinates, {@code false} otherwise
  475. */
  476. public boolean canMove(int fromX, int fromY, int fromZ, int toX, int toY, int toZ, int instanceId)
  477. {
  478. int geoX = getGeoX(fromX);
  479. int geoY = getGeoY(fromY);
  480. fromZ = getNearestZ(geoX, geoY, fromZ);
  481. int tGeoX = getGeoX(toX);
  482. int tGeoY = getGeoY(toY);
  483. toZ = getNearestZ(tGeoX, tGeoY, toZ);
  484. if (DoorTable.getInstance().checkIfDoorsBetween(fromX, fromY, fromZ, toX, toY, toZ, instanceId, false))
  485. {
  486. return false;
  487. }
  488. LinePointIterator pointIter = new LinePointIterator(geoX, geoY, tGeoX, tGeoY);
  489. // first point is guaranteed to be available
  490. pointIter.next();
  491. int prevX = pointIter.x();
  492. int prevY = pointIter.y();
  493. int prevZ = fromZ;
  494. while (pointIter.next())
  495. {
  496. int curX = pointIter.x();
  497. int curY = pointIter.y();
  498. int curZ = getNearestZ(curX, curY, prevZ);
  499. if (hasGeoPos(prevX, prevY))
  500. {
  501. Direction dir = GeoUtils.computeDirection(prevX, prevY, curX, curY);
  502. boolean canEnter = false;
  503. if (canEnterNeighbors(prevX, prevY, prevZ, dir))
  504. {
  505. // check diagonal movement
  506. switch (dir)
  507. {
  508. case NORTH_EAST:
  509. canEnter = canEnterNeighbors(prevX, prevY - 1, prevZ, Direction.EAST) && canEnterNeighbors(prevX + 1, prevY, prevZ, Direction.NORTH);
  510. break;
  511. case NORTH_WEST:
  512. canEnter = canEnterNeighbors(prevX, prevY - 1, prevZ, Direction.WEST) && canEnterNeighbors(prevX - 1, prevY, prevZ, Direction.NORTH);
  513. break;
  514. case SOUTH_EAST:
  515. canEnter = canEnterNeighbors(prevX, prevY + 1, prevZ, Direction.EAST) && canEnterNeighbors(prevX + 1, prevY, prevZ, Direction.SOUTH);
  516. break;
  517. case SOUTH_WEST:
  518. canEnter = canEnterNeighbors(prevX, prevY + 1, prevZ, Direction.WEST) && canEnterNeighbors(prevX - 1, prevY, prevZ, Direction.SOUTH);
  519. break;
  520. default:
  521. canEnter = true;
  522. break;
  523. }
  524. }
  525. if (!canEnter)
  526. {
  527. return false;
  528. }
  529. }
  530. prevX = curX;
  531. prevY = curY;
  532. prevZ = curZ;
  533. }
  534. if (hasGeoPos(prevX, prevY) && (prevZ != toZ))
  535. {
  536. // different floors
  537. return false;
  538. }
  539. return true;
  540. }
  541. public int traceTerrainZ(int x, int y, int z, int tx, int ty)
  542. {
  543. int geoX = getGeoX(x);
  544. int geoY = getGeoY(y);
  545. z = getNearestZ(geoX, geoY, z);
  546. int tGeoX = getGeoX(tx);
  547. int tGeoY = getGeoY(ty);
  548. LinePointIterator pointIter = new LinePointIterator(geoX, geoY, tGeoX, tGeoY);
  549. // first point is guaranteed to be available
  550. pointIter.next();
  551. int prevZ = z;
  552. while (pointIter.next())
  553. {
  554. int curX = pointIter.x();
  555. int curY = pointIter.y();
  556. int curZ = getNearestZ(curX, curY, prevZ);
  557. prevZ = curZ;
  558. }
  559. return prevZ;
  560. }
  561. /**
  562. * Checks if its possible to move from one location to another.
  563. * @param from the {@code ILocational} to start checking from
  564. * @param toX the X coordinate to end checking at
  565. * @param toY the Y coordinate to end checking at
  566. * @param toZ the Z coordinate to end checking at
  567. * @return {@code true} if the character at start coordinates can move to end coordinates, {@code false} otherwise
  568. */
  569. public boolean canMove(ILocational from, int toX, int toY, int toZ)
  570. {
  571. return canMove(from.getX(), from.getY(), from.getZ(), toX, toY, toZ, from.getInstanceId());
  572. }
  573. /**
  574. * Checks if its possible to move from one location to another.
  575. * @param from the {@code ILocational} to start checking from
  576. * @param to the {@code ILocational} to end checking at
  577. * @return {@code true} if the character at start coordinates can move to end coordinates, {@code false} otherwise
  578. */
  579. public boolean canMove(ILocational from, ILocational to)
  580. {
  581. return canMove(from, to.getX(), to.getY(), to.getZ());
  582. }
  583. /**
  584. * Checks the specified position for available geodata.
  585. * @param x the X coordinate
  586. * @param y the Y coordinate
  587. * @return {@code true} if there is geodata for the given coordinates, {@code false} otherwise
  588. */
  589. public boolean hasGeo(int x, int y)
  590. {
  591. return hasGeoPos(getGeoX(x), getGeoY(y));
  592. }
  593. }