armark1ng

Untitled

May 28th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.20 KB | None | 0 0
  1. package com.rs.game;
  2.  
  3.  
  4. /*
  5. * Author Alex(Also known as dragonkk)
  6. */
  7. public class RegionMap {
  8.  
  9. private int regionX;
  10. private int regionY;
  11. private int masks[][][];
  12. private boolean clipedOnly;
  13.  
  14. public RegionMap(int regionId, boolean clipedOnly) {
  15. regionX = (regionId >> 8) * 64;
  16. regionY = (regionId & 0xff) * 64;
  17. masks = new int[4][64][64];
  18. this.clipedOnly = clipedOnly;
  19. }
  20.  
  21. public int[][][] getMasks() {
  22. return masks;
  23. }
  24.  
  25. public int getRegionX() {
  26. return regionX;
  27. }
  28.  
  29. public int getRegionY() {
  30. return regionY;
  31. }
  32.  
  33. public void addUnwalkable(int plane, int x, int y) {
  34. addMask(plane, x, y, 2097152);
  35. }
  36.  
  37. public void addFloor(int plane, int x, int y) {
  38. addMask(plane, x, y, 262144);
  39. }
  40.  
  41. public void removeFloor(int plane, int x, int y) {
  42. removeMask(plane, x, y, 262144);
  43. }
  44.  
  45. public void addObject(int plane, int x, int y, int sizeX, int sizeY, boolean solid, boolean notAlternative) {
  46. int mask = 256;
  47. if (solid)
  48. mask |= 131072;
  49. if (notAlternative)
  50. mask |= 1073741824;
  51. for (int tileX = x; tileX < x + sizeX; tileX++)
  52. for (int tileY = y; tileY < y + sizeY; tileY++)
  53. addMask(plane, tileX, tileY, mask);
  54. }
  55.  
  56. public void removeObject(int plane, int x, int y, int sizeX, int sizeY, boolean solid, boolean notAlternative) {
  57. int mask = 256;
  58. if (solid)
  59. mask |= 131072;
  60. if (notAlternative)
  61. mask |= 1073741824;
  62. for (int tileX = x; tileX < x + sizeX; tileX++)
  63. for (int tileY = y; tileY < y + sizeY; tileY++)
  64. removeMask(plane, tileX, tileY, mask);
  65.  
  66. }
  67.  
  68.  
  69.  
  70. public void addWall(int plane, int x, int y, int type, int rotation, boolean solid, boolean notAlternative) {
  71. if (type == 0) {
  72. if (rotation == 0) {
  73. addMask(plane, x, y, 128);
  74. addMask(plane, x - 1, y, 8);
  75. }
  76. if (rotation == 1) {
  77. addMask(plane, x, y, 2);
  78. addMask(plane, x, 1 + y, 32);
  79. }
  80. if (rotation == 2) {
  81. addMask(plane, x, y, 8);
  82. addMask(plane, 1 + x, y, 128);
  83. }
  84. if (rotation == 3) {
  85. addMask(plane, x, y, 32);
  86. addMask(plane, x, -1 + y, 2);
  87. }
  88. }
  89. if (type == 1 || type == 3) {
  90. if (rotation == 0) {
  91. addMask(plane, x, y, 1);
  92. addMask(plane, -1 + x, 1 + y, 16);
  93. }
  94. if (rotation == 1) {
  95. addMask(plane, x, y, 4);
  96. addMask(plane, 1 + x, 1 + y, 64);
  97. }
  98. if (rotation == 2) {
  99. addMask(plane, x, y, 16);
  100. addMask(plane, x + 1, -1 + y, 1);
  101. }
  102. if (rotation == 3) {
  103. addMask(plane, x, y, 64);
  104. addMask(plane, x - 1, -1 + y, 4);
  105. }
  106. }
  107. if (type == 2) {
  108. if (rotation == 0) {
  109. addMask(plane, x, y, 130);
  110. addMask(plane, -1 + x, y, 8);
  111. addMask(plane, x, y + 1, 32);
  112. }
  113. if (rotation == 1) {
  114. addMask(plane, x, y, 10);
  115. addMask(plane, x, 1 + y, 32);
  116. addMask(plane, 1 + x, y, 128);
  117. }
  118. if (rotation == 2) {
  119. addMask(plane, x, y, 40);
  120. addMask(plane, 1 + x, y, 128);
  121. addMask(plane, x, -1 + y, 2);
  122. }
  123. if (rotation == 3) {
  124. addMask(plane, x, y, 160);
  125. addMask(plane, x, -1 + y, 2);
  126. addMask(plane, -1 + x, y, 8);
  127. }
  128. }
  129. if (solid) {
  130. if (type == 0) {
  131. if (rotation == 0) {
  132. addMask(plane, x, y, 0x10000);
  133. addMask(plane, x - 1, y, 4096);
  134. }
  135. if (rotation == 1) {
  136. addMask(plane, x, y, 1024);
  137. addMask(plane, x, 1 + y, 16384);
  138. }
  139. if (rotation == 2) {
  140. addMask(plane, x, y, 4096);
  141. addMask(plane, x + 1, y, 0x10000);
  142. }
  143. if (rotation == 3) {
  144. addMask(plane, x, y, 16384);
  145. addMask(plane, x, -1 + y, 1024);
  146. }
  147. }
  148. if (type == 1 || type == 3) {
  149. if (rotation == 0) {
  150. addMask(plane, x, y, 512);
  151. addMask(plane, x - 1, y + 1, 8192);
  152. }
  153. if (rotation == 1) {
  154. addMask(plane, x, y, 2048);
  155. addMask(plane, x + 1, 1 + y, 32768);
  156. }
  157. if (rotation == 2) {
  158. addMask(plane, x, y, 8192);
  159. addMask(plane, x + 1, y - 1, 512);
  160. }
  161. if (rotation == 3) {
  162. addMask(plane, x, y, 32768);
  163. addMask(plane, x - 1, -1 + y, 2048);
  164. }
  165. }
  166. if (type == 2) {
  167. if (rotation == 0) {
  168. addMask(plane, x, y, 0x10400);
  169. addMask(plane, -1 + x, y, 4096);
  170. addMask(plane, x, y + 1, 16384);
  171. }
  172. if (rotation == 1) {
  173. addMask(plane, x, y, 5120);
  174. addMask(plane, x, y + 1, 16384);
  175. addMask(plane, 1 + x, y, 0x10000);
  176. }
  177. if (rotation == 2) {
  178. addMask(plane, x, y, 20480);
  179. addMask(plane, x + 1, y, 0x10000);
  180. addMask(plane, x, y - 1, 1024);
  181. }
  182. if (rotation == 3) {
  183. addMask(plane, x, y, 0x14000);
  184. addMask(plane, x, -1 + y, 1024);
  185. addMask(plane, x - 1, y, 4096);
  186. }
  187. }
  188. }
  189. if (notAlternative) {
  190. if (type == 0) {
  191. if (rotation == 0) {
  192. addMask(plane, x, y, 0x20000000);
  193. addMask(plane, x - 1, y, 0x2000000);
  194. }
  195. if (rotation == 1) {
  196. addMask(plane, x, y, 0x800000);
  197. addMask(plane, x, y + 1, 0x8000000);
  198. }
  199. if (rotation == 2) {
  200. addMask(plane, x, y, 0x2000000);
  201. addMask(plane, x + 1, y, 0x20000000);
  202. }
  203. if (rotation == 3) {
  204. addMask(plane, x, y, 0x8000000);
  205. addMask(plane, x, y - 1, 0x800000);
  206. }
  207. }
  208. if (type == 1 || type == 3) {
  209. if (rotation == 0) {
  210. addMask(plane, x, y, 0x400000);
  211. addMask(plane, x - 1, y + 1, 0x4000000);
  212. }
  213. if (rotation == 1) {
  214. addMask(plane, x, y, 0x1000000);
  215. addMask(plane, 1 + x, 1 + y, 0x10000000);
  216. }
  217. if (rotation == 2) {
  218. addMask(plane, x, y, 0x4000000);
  219. addMask(plane, x + 1, -1 + y, 0x400000);
  220. }
  221. if (rotation == 3) {
  222. addMask(plane, x, y, 0x10000000);
  223. addMask(plane, -1 + x, y - 1, 0x1000000);
  224. }
  225. }
  226. if (type == 2) {
  227. if (rotation == 0) {
  228. addMask(plane, x, y, 0x20800000);
  229. addMask(plane, -1 + x, y, 0x2000000);
  230. addMask(plane, x, 1 + y, 0x8000000);
  231. }
  232. if (rotation == 1) {
  233. addMask(plane, x, y, 0x2800000);
  234. addMask(plane, x, 1 + y, 0x8000000);
  235. addMask(plane, x + 1, y, 0x20000000);
  236. }
  237. if (rotation == 2) {
  238. addMask(plane, x, y, 0xa000000);
  239. addMask(plane, 1 + x, y, 0x20000000);
  240. addMask(plane, x, y - 1, 0x800000);
  241. }
  242. if (rotation == 3) {
  243. addMask(plane, x, y, 0x28000000);
  244. addMask(plane, x, y - 1, 0x800000);
  245. addMask(plane, -1 + x, y, 0x2000000);
  246. }
  247. }
  248. }
  249. }
  250.  
  251. public void removeWall(int plane, int x, int y, int type, int rotation, boolean solid, boolean notAlternative) {
  252. if (type == 0) {
  253. if (rotation == 0) {
  254. removeMask(plane, x, y, 128);
  255. removeMask(plane, x - 1, y, 8);
  256. }
  257. if (rotation == 1) {
  258. removeMask(plane, x, y, 2);
  259. removeMask(plane, x, 1 + y, 32);
  260. }
  261. if (rotation == 2) {
  262. removeMask(plane, x, y, 8);
  263. removeMask(plane, 1 + x, y, 128);
  264. }
  265. if (rotation == 3) {
  266. removeMask(plane, x, y, 32);
  267. removeMask(plane, x, -1 + y, 2);
  268. }
  269. }
  270. if (type == 1 || type == 3) {
  271. if (rotation == 0) {
  272. removeMask(plane, x, y, 1);
  273. removeMask(plane, -1 + x, 1 + y, 16);
  274. }
  275. if (rotation == 1) {
  276. removeMask(plane, x, y, 4);
  277. removeMask(plane, 1 + x, 1 + y, 64);
  278. }
  279. if (rotation == 2) {
  280. removeMask(plane, x, y, 16);
  281. removeMask(plane, x + 1, -1 + y, 1);
  282. }
  283. if (rotation == 3) {
  284. removeMask(plane, x, y, 64);
  285. removeMask(plane, x - 1, -1 + y, 4);
  286. }
  287. }
  288. if (type == 2) {
  289. if (rotation == 0) {
  290. addMask(plane, x, y, 130);
  291. removeMask(plane, -1 + x, y, 8);
  292. removeMask(plane, x, y + 1, 32);
  293. }
  294. if (rotation == 1) {
  295. removeMask(plane, x, y, 10);
  296. removeMask(plane, x, 1 + y, 32);
  297. removeMask(plane, 1 + x, y, 128);
  298. }
  299. if (rotation == 2) {
  300. removeMask(plane, x, y, 40);
  301. removeMask(plane, 1 + x, y, 128);
  302. removeMask(plane, x, -1 + y, 2);
  303. }
  304. if (rotation == 3) {
  305. removeMask(plane, x, y, 160);
  306. removeMask(plane, x, -1 + y, 2);
  307. removeMask(plane, -1 + x, y, 8);
  308. }
  309. }
  310. if (solid) {
  311. if (type == 0) {
  312. if (rotation == 0) {
  313. removeMask(plane, x, y, 0x10000);
  314. removeMask(plane, x - 1, y, 4096);
  315. }
  316. if (rotation == 1) {
  317. removeMask(plane, x, y, 1024);
  318. removeMask(plane, x, 1 + y, 16384);
  319. }
  320. if (rotation == 2) {
  321. removeMask(plane, x, y, 4096);
  322. removeMask(plane, x + 1, y, 0x10000);
  323. }
  324. if (rotation == 3) {
  325. removeMask(plane, x, y, 16384);
  326. removeMask(plane, x, -1 + y, 1024);
  327. }
  328. }
  329. if (type == 1 || type == 3) {
  330. if (rotation == 0) {
  331. removeMask(plane, x, y, 512);
  332. removeMask(plane, x - 1, y + 1, 8192);
  333. }
  334. if (rotation == 1) {
  335. removeMask(plane, x, y, 2048);
  336. removeMask(plane, x + 1, 1 + y, 32768);
  337. }
  338. if (rotation == 2) {
  339. removeMask(plane, x, y, 8192);
  340. removeMask(plane, x + 1, y - 1, 512);
  341. }
  342. if (rotation == 3) {
  343. removeMask(plane, x, y, 32768);
  344. removeMask(plane, x - 1, -1 + y, 2048);
  345. }
  346. }
  347. if (type == 2) {
  348. if (rotation == 0) {
  349. removeMask(plane, x, y, 0x10400);
  350. removeMask(plane, -1 + x, y, 4096);
  351. removeMask(plane, x, y + 1, 16384);
  352. }
  353. if (rotation == 1) {
  354. removeMask(plane, x, y, 5120);
  355. removeMask(plane, x, y + 1, 16384);
  356. removeMask(plane, 1 + x, y, 0x10000);
  357. }
  358. if (rotation == 2) {
  359. removeMask(plane, x, y, 20480);
  360. removeMask(plane, x + 1, y, 0x10000);
  361. removeMask(plane, x, y - 1, 1024);
  362. }
  363. if (rotation == 3) {
  364. removeMask(plane, x, y, 0x14000);
  365. removeMask(plane, x, -1 + y, 1024);
  366. removeMask(plane, x - 1, y, 4096);
  367. }
  368. }
  369. }
  370. if (notAlternative) {
  371. if (type == 0) {
  372. if (rotation == 0) {
  373. removeMask(plane, x, y, 0x20000000);
  374. removeMask(plane, x - 1, y, 0x2000000);
  375. }
  376. if (rotation == 1) {
  377. removeMask(plane, x, y, 0x800000);
  378. removeMask(plane, x, y + 1, 0x8000000);
  379. }
  380. if (rotation == 2) {
  381. removeMask(plane, x, y, 0x2000000);
  382. removeMask(plane, x + 1, y, 0x20000000);
  383. }
  384. if (rotation == 3) {
  385. removeMask(plane, x, y, 0x8000000);
  386. removeMask(plane, x, y - 1, 0x800000);
  387. }
  388. }
  389. if (type == 1 || type == 3) {
  390. if (rotation == 0) {
  391. removeMask(plane, x, y, 0x400000);
  392. removeMask(plane, x - 1, y + 1, 0x4000000);
  393. }
  394. if (rotation == 1) {
  395. removeMask(plane, x, y, 0x1000000);
  396. removeMask(plane, 1 + x, 1 + y, 0x10000000);
  397. }
  398. if (rotation == 2) {
  399. removeMask(plane, x, y, 0x4000000);
  400. removeMask(plane, x + 1, -1 + y, 0x400000);
  401. }
  402. if (rotation == 3) {
  403. removeMask(plane, x, y, 0x10000000);
  404. removeMask(plane, -1 + x, y - 1, 0x1000000);
  405. }
  406. }
  407. if (type == 2) {
  408. if (rotation == 0) {
  409. removeMask(plane, x, y, 0x20800000);
  410. removeMask(plane, -1 + x, y, 0x2000000);
  411. removeMask(plane, x, 1 + y, 0x8000000);
  412. }
  413. if (rotation == 1) {
  414. removeMask(plane, x, y, 0x2800000);
  415. removeMask(plane, x, 1 + y, 0x8000000);
  416. removeMask(plane, x + 1, y, 0x20000000);
  417. }
  418. if (rotation == 2) {
  419. removeMask(plane, x, y, 0xa000000);
  420. removeMask(plane, 1 + x, y, 0x20000000);
  421. removeMask(plane, x, y - 1, 0x800000);
  422. }
  423. if (rotation == 3) {
  424. removeMask(plane, x, y, 0x28000000);
  425. removeMask(plane, x, y - 1, 0x800000);
  426. removeMask(plane, -1 + x, y, 0x2000000);
  427. }
  428. }
  429. }
  430. }
  431.  
  432. public void setMask(int plane, int x, int y, int mask) {
  433. if (x >= 64 || y >= 64 || x < 0 || y < 0) {
  434. WorldTile tile = new WorldTile(regionX + x, regionY + y, plane);
  435. int regionId = tile.getRegionId();
  436. int newRegionX = (regionId >> 8) * 64;
  437. int newRegionY = (regionId & 0xff) * 64;
  438. if (clipedOnly)
  439. World.getRegion(tile.getRegionId()).forceGetRegionMapClipedOnly().setMask(plane, tile.getX() - newRegionX, tile.getY() - newRegionY, mask);
  440. else
  441. World.getRegion(tile.getRegionId()).forceGetRegionMap().setMask(plane, tile.getX() - newRegionX, tile.getY() - newRegionY, mask);
  442. return;
  443. }
  444. masks[plane][x][y] = mask;
  445. }
  446.  
  447. public void addMask(int plane, int x, int y, int mask) {
  448. if (x >= 64 || y >= 64 || x < 0 || y < 0) {
  449. WorldTile tile = new WorldTile(regionX + x, regionY + y, plane);
  450. int regionId = tile.getRegionId();
  451. int newRegionX = (regionId >> 8) * 64;
  452. int newRegionY = (regionId & 0xff) * 64;
  453. if (clipedOnly)
  454. World.getRegion(tile.getRegionId()).forceGetRegionMapClipedOnly().addMask(plane, tile.getX() - newRegionX, tile.getY() - newRegionY, mask);
  455. else
  456. World.getRegion(tile.getRegionId()).forceGetRegionMap().addMask(plane, tile.getX() - newRegionX, tile.getY() - newRegionY, mask);
  457. return;
  458. }
  459. masks[plane][x][y] = masks[plane][x][y] | mask;
  460. }
  461.  
  462. public void removeMask(int plane, int x, int y, int mask) {
  463. if (x >= 64 || y >= 64 || x < 0 || y < 0) {
  464. WorldTile tile = new WorldTile(regionX + x, regionY + y, plane);
  465. int regionId = tile.getRegionId();
  466. int newRegionX = (regionId >> 8) * 64;
  467. int newRegionY = (regionId & 0xff) * 64;
  468. if (clipedOnly)
  469. World.getRegion(tile.getRegionId()).forceGetRegionMapClipedOnly().removeMask(plane, tile.getX() - newRegionX, tile.getY() - newRegionY, mask);
  470. else
  471. World.getRegion(tile.getRegionId()).forceGetRegionMap().removeMask(plane, tile.getX() - newRegionX, tile.getY() - newRegionY, mask);
  472. return;
  473. }
  474. masks[plane][x][y] &= (~mask);
  475. }
  476.  
  477.  
  478. }
Advertisement
Add Comment
Please, Sign In to add comment