Advertisement
Guest User

Untitled

a guest
Jun 1st, 2022
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.34 KB | None | 0 0
  1. #include "zcommon.acs"
  2.  
  3. function int wall (int move, int width, int height)
  4. {
  5. if (move > height * (width-1) && move != height * (width-1) +1 && move != height * width)
  6. {
  7. return 1;
  8. //print(s:"wallhug =",d:wall);
  9. }
  10. if (move%45 == 0 && move != height * width && move != width)
  11. {
  12. return 2;
  13. //print(s:"wallhug =",d:wall);
  14. }
  15. if (move<width && move != 1)
  16. {
  17. return 3;
  18. //print(s:"wallhug =",d:wall);
  19. }
  20. if (move%45 == 1 && move != 1 && move != height * (width-1)+1)
  21. {
  22. return 4;
  23. //print(s:"wallhug =",d:wall);
  24. }
  25. if (move == 1)
  26. {
  27. return 5;
  28. //print(s:"wallhug =",d:wall);
  29. }
  30. if (move == width)
  31. {
  32. return 6;
  33. //print(s:"wallhug =",d:wall);
  34. }
  35. if (move == height * (width-1)+1)
  36. {
  37. return 7;
  38. //print(s:"wallhug =",d:wall);
  39. }
  40. if (move == height * width)
  41. {
  42. return 8;
  43. //print(s:"wallhug =",d:wall);
  44. }
  45. return 0;
  46. }
  47. //wallhug
  48. //if we are at the wall of the maze, the new direction cannot go into the direction of the maze.
  49. //We will define this similarly to moving
  50. //0 we are not at a wall
  51. //1 we are at the top wall
  52. //2 we are at the right wall
  53. //3 we are the bottom wall
  54. //4 we are at the left wall
  55. //5 bottom left
  56. //6 bottom right
  57. //7 top left
  58. //8 top right
  59.  
  60.  
  61. script 1 OPEN
  62. {
  63.  
  64. int height = 45;
  65. int width = 45;
  66. int spawnxy[2] = {0,0};
  67. int exitxy[2] = {0,0};
  68. //Calculation from x,y to sector tag:
  69. // tag = roomx+(roomy-1)*height
  70.  
  71.  
  72.  
  73. while (spawnxy[0]%2 == 0) // check if spawnx is on the odd grid
  74. {
  75. spawnxy[0] = random(1,width);
  76. delay(1);
  77. //print(s:"spawn x =", i:spawnxy[0]);
  78.  
  79. }
  80.  
  81. while (spawnxy[1]%2 == 0) // check if spawny is on the odd grid
  82. {
  83. spawnxy[1] = random(1,height);
  84. delay(1);
  85. //print(s:"spawn y =", i:spawnxy[1]);
  86.  
  87. }
  88.  
  89.  
  90. while(exitxy[0]%2 == 0 || exitxy[0] == spawnxy[0]) // check if exit x is on the odd grid and not in same room as end
  91. {
  92. exitxy[0] = random(1,width);
  93. delay(1);
  94. //print(s:"exit x =", i:exitxy[0]);
  95.  
  96. }
  97.  
  98. while(exitxy[1]%2 == 0 || exitxy[1] == spawnxy[1]) // check if y is on the odd grid and not in same room as end
  99. {
  100. exitxy[1] = random(1,height);
  101. delay(1);
  102. //print(s:"exit y =", i:exitxy[1]);
  103.  
  104. }
  105.  
  106. int spawntag = spawnxy[0] + (spawnxy[1]-1) * height;
  107. int exittag = exitxy[0] + (exitxy[1]-1)* height;
  108.  
  109. spawntag = 1193;
  110. exittag = 45;
  111. Ceiling_MoveToValue(spawntag, 128, 128, 0);
  112. Ceiling_MoveToValue(exittag, 128, 128,0);
  113.  
  114.  
  115.  
  116. //we define moving with random switch
  117. //1 as up: +height*2
  118. //2 as right: +2
  119. //3 as down: -height*2
  120. //4 as left: -2
  121. //If we are at an edge, we cannot move in that direction, we cannot move back in the direction we came
  122.  
  123.  
  124.  
  125. int move = spawntag;
  126. int directionold = 0;
  127. int directionnew = 0;
  128. int wallhug = wall(move, width, height);
  129.  
  130.  
  131. while (move != exittag)
  132. {
  133. print(s:"while move != exittag begins");
  134. delay(1);
  135. directionold = directionnew;
  136. switch(directionold) //We apply the move
  137. {
  138. case 0:
  139. break;
  140.  
  141. case 1:
  142. Ceiling_MoveToValue(move+height, 128, 128, 0);
  143. Ceiling_MoveToValue(move+height*2, 128, 128, 0);
  144. move = move+height*2;
  145. break;
  146.  
  147. case 2:
  148. Ceiling_MoveToValue(move+1, 128, 128, 0);
  149. Ceiling_MoveToValue(move+2, 128, 128, 0);
  150. move = move+2;
  151. break;
  152.  
  153. case 3:
  154. Ceiling_MoveToValue(move-height, 128, 128, 0);
  155. Ceiling_MoveToValue(move-height*2, 128, 128, 0);
  156. move = move-height*2;
  157. break;
  158.  
  159. case 4:
  160. Ceiling_MoveToValue(move-1, 128, 128, 0);
  161. Ceiling_MoveToValue(move-2, 128, 128, 0);
  162. move = move-2;
  163. break;
  164. }
  165.  
  166. //int movexy[2] = {move%width, ceil(move/height)};
  167. //Delay(50);
  168. //print(s:"move is now at ", i:movexy[0], s:", ", i:movexy[1]);
  169.  
  170. wallhug = wall(move, width, height);
  171.  
  172. directionnew = random(1,4);
  173. while (directionnew == 1 && directionold == 3) //no moving back, no moving through the wall
  174. {
  175. print(s:"we are now in directionnew loop");
  176. while (wallhug == 1 && directionnew == 1)
  177. {
  178. directionnew = random(1,4);
  179. }
  180. directionnew = random(1,4);
  181. while (wallhug == 2 && directionnew == 2)
  182. {
  183. directionnew = random(1,4);
  184. }
  185. directionnew = random(1,4);
  186. while (wallhug == 3 && directionnew == 3)
  187. {
  188. directionnew = random(1,4);
  189. }
  190. directionnew = random(1,4);
  191. while (wallhug == 4 && directionnew == 4)
  192. {
  193. directionnew = random(1,4);
  194. }
  195. directionnew = random(1,4);
  196. while (wallhug == 5 && (directionnew == 3 || 4))
  197. {
  198. directionnew = random(1,4);
  199. }
  200. directionnew = random(1,4);
  201. while (wallhug == 6 && (directionnew == 2 || 3))
  202. {
  203. directionnew = random(1,4);
  204. }
  205. directionnew = random(1,4);
  206. while (wallhug == 7 && (directionnew == 1 || 4))
  207. {
  208. directionnew = random(1,4);
  209. }
  210. directionnew = random(1,4);
  211. while (wallhug == 8 && (directionnew == 1 || 2))
  212. {
  213. directionnew = random(1,4);
  214. }
  215. }
  216.  
  217. while (directionnew == 2 && directionold == 4) //no moving back, no moving through the wall
  218. {
  219. while (wallhug == 1 && directionnew == 1)
  220. {
  221. directionnew = random(1,4);
  222. }
  223. directionnew = random(1,4);
  224. while (wallhug == 2 && directionnew == 2)
  225. {
  226. directionnew = random(1,4);
  227. }
  228. directionnew = random(1,4);
  229. while (wallhug == 3 && directionnew == 3)
  230. {
  231. directionnew = random(1,4);
  232. }
  233. directionnew = random(1,4);
  234. while (wallhug == 4 && directionnew == 4)
  235. {
  236. directionnew = random(1,4);
  237. }
  238. directionnew = random(1,4);
  239. while (wallhug == 5 && (directionnew == 3 || 4))
  240. {
  241. directionnew = random(1,4);
  242. }
  243. directionnew = random(1,4);
  244. while (wallhug == 6 && (directionnew == 2 || 3))
  245. {
  246. directionnew = random(1,4);
  247. }
  248. directionnew = random(1,4);
  249. while (wallhug == 7 && (directionnew == 1 || 4))
  250. {
  251. directionnew = random(1,4);
  252. }
  253. directionnew = random(1,4);
  254. while (wallhug == 8 && (directionnew == 1 || 2))
  255. {
  256. directionnew = random(1,4);
  257. }
  258. }
  259.  
  260. while (directionnew == 3 && directionold == 1) //no moving back, no moving through the wall
  261. {
  262. while (wallhug == 1 && directionnew == 1)
  263. {
  264. directionnew = random(1,4);
  265. }
  266. directionnew = random(1,4);
  267. while (wallhug == 2 && directionnew == 2)
  268. {
  269. directionnew = random(1,4);
  270. }
  271. directionnew = random(1,4);
  272. while (wallhug == 3 && directionnew == 3)
  273. {
  274. directionnew = random(1,4);
  275. }
  276. directionnew = random(1,4);
  277. while (wallhug == 4 && directionnew == 4)
  278. {
  279. directionnew = random(1,4);
  280. }
  281. directionnew = random(1,4);
  282. while (wallhug == 5 && (directionnew == 3 || 4))
  283. {
  284. directionnew = random(1,4);
  285. }
  286. directionnew = random(1,4);
  287. while (wallhug == 6 && (directionnew == 2 || 3))
  288. {
  289. directionnew = random(1,4);
  290. }
  291. directionnew = random(1,4);
  292. while (wallhug == 7 && (directionnew == 1 || 4))
  293. {
  294. directionnew = random(1,4);
  295. }
  296. directionnew = random(1,4);
  297. while (wallhug == 8 && (directionnew == 1 || 2))
  298. {
  299. directionnew = random(1,4);
  300. }
  301. }
  302.  
  303. while (directionnew == 4 && directionold == 2) //no moving back, no moving through the wall
  304. {
  305. while (wallhug == 1 && directionnew == 1)
  306. {
  307. directionnew = random(1,4);
  308. }
  309. directionnew = random(1,4);
  310. while (wallhug == 2 && directionnew == 2)
  311. {
  312. directionnew = random(1,4);
  313. }
  314. directionnew = random(1,4);
  315. while (wallhug == 3 && directionnew == 3)
  316. {
  317. directionnew = random(1,4);
  318. }
  319. directionnew = random(1,4);
  320. while (wallhug == 4 && directionnew == 4)
  321. {
  322. directionnew = random(1,4);
  323. }
  324. directionnew = random(1,4);
  325. while (wallhug == 5 && (directionnew == 3 || 4))
  326. {
  327. directionnew = random(1,4);
  328. }
  329. directionnew = random(1,4);
  330. while (wallhug == 6 && (directionnew == 2 || 3))
  331. {
  332. directionnew = random(1,4);
  333. }
  334. directionnew = random(1,4);
  335. while (wallhug == 7 && (directionnew == 1 || 4))
  336. {
  337. directionnew = random(1,4);
  338. }
  339. directionnew = random(1,4);
  340. while (wallhug == 8 && (directionnew == 1 || 2))
  341. {
  342. directionnew = random(1,4);
  343. }
  344. }
  345. }
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement