Ramaraunt1

Untitled

Nov 18th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.83 KB | None | 0 0
  1. if global.room_before = rm_creation_menu
  2. {
  3. //init ticker
  4. alarm[0] = room_speed/4;
  5. global.ticker = 0;
  6. global.room_before = noone;
  7. global.overlays = 0;
  8. with (obj_unit and obj_body)
  9. {
  10. instance_destroy();
  11. }
  12. cur_team = 0;
  13. global.handler = id
  14. grid_columns = 28;
  15. grid_rows = 16;
  16. grid_size = 32;
  17. define_grid(128,128,32,grid_columns,grid_rows);
  18. add_gridspacers(grid_rows,grid_columns);
  19. file = get_open_filename_ext("straticon file|*.stc", "", working_directory, "Open a saved level!");
  20. if file != ""
  21. {
  22. ini_open(file);
  23. increment = 0;
  24. for (m = 0; m < grid_rows; m++)
  25. {
  26. for (n = 0; n < grid_columns; n ++)
  27. {
  28. stringcrement = string(increment);
  29. straticon[n,m] = ini_read_real("straticons","straticon_" + stringcrement,noone);
  30. team[n,m] = ini_read_real("straticons","team_" + stringcrement,noone);
  31. parent_n_[n,m] = ini_read_real("straticons","parent_n_" + stringcrement,noone);
  32. parent_m_[n,m] = ini_read_real("straticons","parent_m_" + stringcrement, noone);
  33. int_left_connector = ini_read_real("straticons","left_connector_" + stringcrement, 0);
  34. if int_left_connector = 0
  35. {
  36. left_connector[n,m] = false;
  37. }
  38. else
  39. {
  40. left_connector[n,m] = true;
  41. }
  42. int_right_connector= ini_read_real("straticons","right_connector_" + stringcrement, 0);
  43. if int_right_connector = 0
  44. {
  45. right_connector[n,m] = false;
  46. }
  47. else
  48. {
  49. right_connector[n,m] = true;
  50. }
  51.  
  52. int_up_connector= ini_read_real("straticons","up_connector_" + stringcrement, 0);
  53. if int_up_connector = 0
  54. {
  55. up_connector[n,m] = false;
  56. }
  57. else
  58. {
  59. up_connector[n,m] = true;
  60. }
  61.  
  62. int_down_connector= ini_read_real("straticons","down_connector_" + stringcrement, 0);
  63. if int_down_connector = 0
  64. {
  65. down_connector[n,m] = false;
  66. }
  67. else
  68. {
  69. down_connector[n,m] = true;
  70. }
  71. increment++;
  72. }
  73. }
  74. ini_close();
  75. }
  76. else
  77. {
  78. room_goto(rm_creation_menu);
  79. }
  80.  
  81. //define heads
  82. units = ds_list_create();
  83. for (m = 0; m < grid_rows; m++)
  84. {
  85. for (n = 0; n < grid_columns; n ++)
  86. {
  87. switch(straticon[n,m]){
  88. case 1: //worm head
  89. unit = instance_create(gridspace_x[n],gridspace_y[m],obj_unit);
  90. unit.team = team[n,m];
  91. unit.kind = "Worm 1.0";
  92. unit.type_id = 1;
  93. unit.sprite = spr_worm;
  94. unit.bodyparts = ds_list_create();
  95. unit.n = n;
  96. unit.m = m;
  97. unit.max_size = 2;
  98. unit.movement_per_turn = 2;
  99. unit.attack_range[0] = 1;
  100. unit.armor = 0;
  101. unit.attack[0] = 0; //attack
  102. unit.attack_string[0] = "Byte";
  103. unit.effect[0] = 2; //2 damage
  104. unit.attack[1] = noone;//no secondary move
  105. unit.attack[2] = noone; //no tretrary move
  106. unit.attack[3]= noone; //no quadrary move
  107. unit.cur_attack_range = unit.attack_range[0];
  108. unit.action_ammount = 1;
  109. unit.child_left = false;
  110. unit.child_right = false;
  111. unit.child_up = false;
  112. unit.child_down = false;
  113. unit.grid_rows = grid_rows;
  114. unit.grid_columns = grid_columns;
  115. ds_list_add(units,unit);
  116. break;
  117. default:
  118. break;
  119.  
  120. }
  121. }
  122. }
  123.  
  124. //now define bodies and link them to heads and to each other.
  125. for (m = 0; m < grid_rows; m++)
  126. {
  127. for (n = 0; n < grid_columns; n ++)
  128. {
  129. if straticon[n,m] = 2
  130. {
  131. body = instance_create(gridspace_x[n],gridspace_y[m],obj_body);
  132. body.n = n
  133. body.m = m
  134. body.left = false;
  135. body.right = false;
  136. body.up = false;
  137. body.down = false;
  138. body.child_left = false;
  139. body.child_right = false;
  140. body.child_up = false;
  141. body.child_down = false;
  142. body.type_id = straticon[n,m];
  143. body.grid_rows = grid_rows;
  144. body.grid_columns = grid_columns;
  145. }
  146. }
  147. }
  148. for (m = 0; m < grid_rows; m++)
  149. {
  150. for (n = 0; n < grid_columns; n ++)
  151. {
  152. if straticon[n,m] = 2
  153. {
  154. body = instance_nearest(gridspace_x[n],gridspace_y[m],obj_body);
  155. cur_part = straticon[n,m];
  156. cur_n = n;
  157. cur_m = m;
  158. while (cur_part != 1)
  159. {
  160. cur_part = straticon[parent_n_[cur_n,cur_m],parent_m_[cur_n,cur_m]]
  161. saved = cur_n;
  162. cur_n = parent_n_[cur_n,cur_m];
  163. cur_m = parent_m_[saved,cur_m];
  164. }
  165. body.head = instance_nearest(gridspace_x[cur_n],gridspace_y[cur_m],obj_unit);
  166. ds_list_add(body.head.bodyparts,body.id);
  167. body.team = body.head.team;
  168. if straticon[parent_n_[n,m],parent_m_[n,m]] = 1
  169. {
  170. body.parent = body.head;
  171. }
  172. else
  173. {
  174. body.parent = instance_nearest(gridspace_x[parent_n_[n,m]],gridspace_y[parent_m_[n,m]],obj_body);
  175. }
  176. if body.parent.n > body.n
  177. {
  178. body.right = true;
  179. body.parent.child_left = true;
  180. }
  181. if body.parent.n < body.n
  182. {
  183. body.left = true;
  184. body.parent.child_right = true
  185. }
  186. if body.parent.m > body.m
  187. {
  188. body.down = true;
  189. body.parent.child_up = true;
  190. }
  191. if body.parent.m < body.m
  192. {
  193. body.up = true;
  194. body.parent.child_down = true;
  195. }
  196. }
  197. }
  198. }
  199.  
  200. for (m = 0; m < grid_rows; m++)
  201. {
  202. for (n = 0; n < grid_columns; n ++)
  203. {
  204. if straticon[n,m] = 2
  205. {
  206. body = instance_nearest(gridspace_x[n],gridspace_y[m],obj_body);
  207. body.parent_n = body.parent.n;
  208. body.parent_m = body.parent.m;
  209.  
  210. endbubble = false;
  211. while(endbubble == false)
  212. {
  213. endbubble = true;
  214. with(obj_body)
  215. {
  216. if self.depth >= self.parent.depth
  217. {
  218. endbubble = false;
  219. self.depth --;
  220. if self.depth = -10000
  221. {
  222. self.depth = 0;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230.  
  231. for (m = 0; m < grid_rows; m++)
  232. {
  233. for (n = 0; n < grid_columns; n ++)
  234. {
  235. if straticon[n,m] != noone
  236. {
  237. straticon[n,m] = 0;
  238. }
  239. }
  240. }
  241.  
  242.  
  243. player_team = ds_list_create();
  244. ally_team = ds_list_create();
  245. enemy_team_1 = ds_list_create();
  246. enemy_team_2 = ds_list_create();
  247.  
  248. //fill team ds lists
  249. for (cur_unit = 0; cur_unit < ds_list_size(units); cur_unit++)
  250. {
  251. unit = ds_list_find_value(units,cur_unit);
  252. switch(unit.team){
  253. case 0:
  254. ds_list_add(player_team,unit);
  255. break;
  256. case 1:
  257. ds_list_add(ally_team,unit);
  258. break;
  259. case 2:
  260. ds_list_add(enemy_team_1,unit);
  261. break;
  262. case 3:
  263. ds_list_add(enemy_team_2,unit);
  264. break;
  265. }
  266.  
  267. }
  268.  
  269. //init turns
  270. global.cur_turn = 0 //player turn
  271. global.selected = noone;
  272. global.movedone = true;
  273. global.finished_moved = ds_list_create();
  274. init[0] = false;
  275. init[1] = false;
  276. init[2] = false;
  277. init[3] = false;
  278.  
  279.  
  280. //GRIDSPACERS
  281. for (m = 0; m < grid_rows; m++)
  282. {
  283. for (n = 0; n < grid_columns; n ++)
  284. {
  285. if m > 0
  286. {
  287. up_possible[n,m] = true;
  288. up_tiled[n,m] = false;
  289. up_connected[n,m] = false;
  290. }
  291. else
  292. {
  293. up_possible[n,m] = false;
  294. up_tiled[n,m] = false;
  295. up_connected[n,m] = false;
  296. }
  297.  
  298. if m < grid_rows - 1
  299. {
  300. down_possible[n,m] = true;
  301. down_tiled[n,m] = false;
  302. down_connected[n,m] = false;
  303. }
  304. else
  305. {
  306. down_possible[n,m] = false;
  307. down_tiled[n,m] = false;
  308. down_connected[n,m] = false;
  309. }
  310.  
  311. if n > 0
  312. {
  313. left_possible[n,m] = true;
  314. left_tiled[n,m] = false;
  315. left_connected[n,m] = false;
  316. }
  317. else
  318. {
  319. left_possible[n,m] = false;
  320. left_tiled[n,m] = false;
  321. left_connected[n,m] = false;
  322. }
  323.  
  324. if n < grid_columns - 1
  325. {
  326. right_possible[n,m] = true;
  327. right_tiled[n,m] = false;
  328. right_connected[n,m] = false;
  329. }
  330. else
  331. {
  332. right_possible[n,m] = false;
  333. right_tiled[n,m] = false;
  334. right_connected[n,m] = false;
  335. }
  336. }
  337. }
  338.  
  339. resset_n_and_m();
  340.  
  341. global.fields_generated = false;
  342. if global.fields_generated = false
  343. {
  344. global.fields_generated = true;
  345. with (obj_unit)
  346. {
  347.  
  348. for (cur_m = 0; cur_m < grid_rows; cur_m++)
  349. {
  350. for (cur_n = 0; cur_n < grid_columns; cur_n ++)
  351. {
  352. if global.handler.straticon[cur_n,cur_m] = 0
  353. {
  354. walkable[cur_n,cur_m] = true;
  355. }
  356. else if global.handler.straticon[cur_n,cur_m] = type_id + 1
  357. {
  358. cur_body = instance_nearest(global.handler.gridspace_x[cur_n],global.handler.gridspace_y[cur_m],obj_body);
  359. if cur_body.head = id
  360. {
  361. walkable[cur_n,cur_m] = true;
  362. }
  363. else
  364. {
  365. walkable[cur_n,cur_m] = false;
  366. }
  367.  
  368. }
  369. else
  370. {
  371. walkable[cur_n,cur_m] = false;
  372. }
  373. }
  374. }
  375. }
  376. }
  377.  
  378. resset_units();
  379.  
  380. side_button_start_x = room_width - 192;
  381. side_button_start_y = 128;
  382. button_width = 256;
  383. button_height = 32;
  384.  
  385. for(button_index = 0; button_index < 6; button_index++)
  386. {
  387. side_button_x[button_index] = side_button_start_x;
  388. side_button_y[button_index] = side_button_start_y + ((64)*button_index);
  389. side_button_left_x[button_index] = side_button_x[button_index] - button_width/2;
  390. side_button_right_x[button_index] = side_button_x[button_index] + button_width/2;
  391. side_button_top_y[button_index] = side_button_y[button_index] - button_height/2;
  392. side_button_bottom_y[button_index] = side_button_y[button_index] + button_height/2;
  393. }
  394.  
  395. title_text_x = side_button_start_x;
  396. title_text_y = side_button_start_y - 64;
  397. }
  398.  
  399. if global.overlays = 0
  400. {
  401. if global.cur_turn = 0
  402. {
  403. ai = false;
  404. cur_team = 0;
  405. if init[0] = false
  406. {
  407. init[0] = true;
  408. for (cur_index = 0; cur_index < ds_list_size(player_team); cur_index ++)
  409. {
  410. cur_unit = ds_list_find_value(player_team,cur_index);
  411. if cur_unit = 0
  412. {
  413. global.selected = cur_unit;
  414. }
  415. cur_unit.movement_left = cur_unit.movement_per_turn;
  416. cur_unit.done = false;
  417. ds_list_destroy(global.finished_moved);
  418. global.finished_moved = ds_list_create();
  419. }
  420. }
  421. if global.movedone //automatically select next avaliable unit. if none avalible, move on to next turn
  422. {
  423. global.movedone = false;
  424. endnow = false;
  425. goodindex = false;
  426. index = -1
  427. while (endnow = false)
  428. { //while ending condition is not met, loop through player_team.
  429. index ++;
  430. finished_moved_cur_index = 0;
  431. endnestedwhile = false;
  432. while (endnestedwhile = false)
  433. {
  434. if ds_list_find_value(global.finished_moved,finished_moved_cur_index) = ds_list_find_value(player_team,index) //player team unit has been found in used units, so it wont be used again
  435. {
  436. endnestedwhile = true;
  437. goodindex = false;
  438. }
  439. if finished_moved_cur_index = ds_list_size(global.finished_moved) //none equal player team, so this is good index
  440. {
  441. endnestedwhile = true;
  442. goodindex = true;
  443. }
  444. finished_moved_cur_index += 1;
  445. }
  446. if goodindex = true
  447. {
  448. global.selected = ds_list_find_value(player_team,index);
  449. endnow = true;
  450. }
  451. else if index = ds_list_size(player_team) - 1//if end of player_team is hit, end loop and move to next turn
  452. {
  453. endnow = true;
  454. global.cur_turn += 1;
  455. }
  456.  
  457.  
  458. }
  459.  
  460. }
  461. }
  462. if global.cur_turn = 1
  463. {
  464. ai = true;
  465. cur_team = 1;
  466. cur_ds = ally_team;
  467. if ds_list_size(cur_ds) = 0
  468. {
  469. global.cur_turn ++;
  470. }
  471. }
  472. if global.cur_turn = 2
  473. {
  474. ai = true;
  475. cur_team = 2;
  476. cur_ds = enemy_team_1;
  477. if ds_list_size(cur_ds) = 0
  478. {
  479. global.cur_turn ++;
  480. }
  481. }
  482. if global.cur_turn = 3
  483. {
  484. ai = true;
  485. cur_team = 3;
  486. cur_ds = enemy_team_2;
  487. if ds_list_size(cur_ds) = 0
  488. {
  489. global.cur_turn ++;
  490. }
  491. }
  492. if global.cur_turn = 4
  493. {
  494. ai = false;
  495. global.cur_turn = 0 //player turn
  496. global.selected = noone;
  497. global.movedone = true;
  498. init[0] = false;
  499. init[1] = false;
  500. init[2] = false;
  501. init[3] = false;
  502. }
  503. if ai = true
  504. {
  505. if init[global.cur_turn] = false
  506. {
  507. init[global.cur_turn] = true;
  508. for (cur_index = 0; cur_index < ds_list_size(cur_ds); cur_index ++)
  509. {
  510. cur_unit = ds_list_find_value(cur_ds,cur_index);
  511. if cur_unit = 0
  512. {
  513. global.selected = cur_unit;
  514. }
  515. cur_unit.movement_left = cur_unit.movement_per_turn;
  516. cur_unit.done = false;
  517. }
  518. ds_list_destroy(global.finished_moved);
  519. global.finished_moved = ds_list_create();
  520. }
  521. if global.movedone //automatically select next avaliable unit. if none avalible, move on to next turn
  522. {
  523. global.movedone = false;
  524. endnow = false;
  525. goodindex = false;
  526. index = -1
  527. while (endnow = false)
  528. { //while ending condition is not met, loop through player_team.
  529. index ++;
  530. finished_moved_cur_index = 0;
  531. endnestedwhile = false;
  532. while (endnestedwhile = false)
  533. {
  534. if ds_list_find_value(global.finished_moved,finished_moved_cur_index) = ds_list_find_value(player_team,index) //player team unit has been found in used units, so it wont be used again
  535. {
  536. endnestedwhile = true;
  537. goodindex = false;
  538. }
  539. if finished_moved_cur_index = ds_list_size(global.finished_moved) //none equal player team, so this is good index
  540. {
  541. endnestedwhile = true;
  542. goodindex = true;
  543. }
  544. finished_moved_cur_index += 1;
  545. }
  546. if goodindex = true
  547. {
  548. global.selected = ds_list_find_value(cur_ds,index);
  549. endnow = true;
  550. }
  551. else if index = ds_list_size(cur_ds) - 1//if end of team is hit, end loop and move to next turn
  552. {
  553. endnow = true;
  554. global.cur_turn += 1;
  555. }
  556.  
  557.  
  558. }
  559.  
  560. }
  561.  
  562. }
  563.  
  564. for (m = 0; m < grid_rows; m++)
  565. {
  566. for (n = 0; n < grid_columns; n ++)
  567. {
  568. global.hover[n,m] = mouse_in_region(global.handler.gridspace_x[n] - 16, global.handler.gridspace_y[m] - 16, global.handler.gridspace_x[n] + 16, global.handler.gridspace_y[m] + 16);
  569. }
  570. }
  571.  
  572. for (m = 0; m < grid_rows; m++)
  573. {
  574. for (n = 0; n < grid_columns; n ++)
  575. {
  576. if up_possible[n,m]
  577. {
  578. if straticon[n,m-1] = 0
  579. {
  580. up_tiled[n,m] = true;
  581. }
  582. else
  583. {
  584. up_tiled[n,m] = false;
  585. }
  586. }
  587.  
  588. if down_possible[n,m]
  589. {
  590. if straticon[n,m+1] = 0
  591. {
  592. down_tiled[n,m] = true;
  593. }
  594. else
  595. {
  596. down_tiled[n,m] = false;
  597. }
  598. }
  599.  
  600. if left_possible[n,m]
  601. {
  602. if straticon[n-1,m] = 0
  603. {
  604. left_tiled[n,m] = true;
  605. }
  606. else
  607. {
  608. left_tiled[n,m] = false;
  609. }
  610. }
  611. if right_possible[n,m]
  612. {
  613. if straticon[n+1,m] = 0
  614. {
  615. right_tiled[n,m] = true;
  616. }
  617. else
  618. {
  619. right_tiled[n,m] = false;
  620. }
  621. }
  622. }
  623. }
  624.  
  625.  
  626. if global.fields_generated = false
  627. {
  628. with (obj_unit)
  629. {
  630. global.fields_generated = true;
  631. for (cur_m = 0; cur_m < grid_rows; cur_m++)
  632. {
  633. for (cur_n = 0; cur_n < grid_columns; cur_n ++)
  634. {
  635. if global.handler.straticon[cur_n,cur_m] = 0
  636. {
  637. walkable[cur_n,cur_m] = true;
  638. }
  639. else if global.handler.straticon[cur_n,cur_m] = type_id + 1
  640. {
  641. cur_body = instance_nearest(global.handler.gridspace_x[cur_n],global.handler.gridspace_y[cur_m],obj_body);
  642. if cur_body.head = id
  643. {
  644. walkable[cur_n,cur_m] = true;
  645. }
  646. else
  647. {
  648. walkable[cur_n,cur_m] = false;
  649. }
  650.  
  651. }
  652. else
  653. {
  654. walkable[cur_n,cur_m] = false;
  655. }
  656. }
  657. }
  658. }
  659. }
  660. //side buttons
  661. if global.selected != noone and global.cur_turn = 0
  662. {
  663. for(button_index = 0; button_index < 6; button_index ++)
  664. {
  665. if button_index < 4 and button_index > 0 and global.selected.attack[button_index - 1] != noone
  666. {
  667. hover_side_button[button_index] = mouse_in_region(side_button_left_x[button_index],side_button_top_y[button_index],side_button_right_x[button_index],side_button_bottom_y[button_index]);
  668. }
  669. else if button_index = 0 or button_index = 5
  670. {
  671. hover_side_button[button_index] = mouse_in_region(side_button_left_x[button_index],side_button_top_y[button_index],side_button_right_x[button_index],side_button_bottom_y[button_index]);
  672. }
  673. else
  674. {
  675. hover_side_button[button_index] = false;
  676. }
  677. if hover_side_button[button_index] and mouse_check_button_released(mb_left) and button_index != 5
  678. {
  679. global.selected.mode = button_index - 1;
  680. global.selected.select_init = false;
  681. }
  682. else if hover_side_button[button_index] and mouse_check_button_released(mb_left) and button_index = 5
  683. {
  684. ds_list_add(global.finished_moved,global.selected);
  685. global.movedone = true;
  686. wipe_nodes();
  687. global.selected = noone;
  688. }
  689. }
  690. }
  691.  
  692. button_text[0] = "Movement";
  693. if global.selected != noone
  694. {
  695. button_text[1] = global.selected.attack_string[0];
  696. if global.selected.attack[1] != noone
  697. {
  698. button_text[2] = global.selected.attack_string[1];
  699. }
  700. if global.selected.attack[2] != noone
  701. {
  702. button_text[3] = global.selected.attack_string[2];
  703. }
  704. if global.selected.attack[3] != noone
  705. {
  706. button_text[4] = global.selected.attack_string[3];
  707. }
  708. }
  709. button_text[5] = "End Move";
  710.  
  711. if global.selected != noone
  712. {
  713. movement_left_string = "Movement Left: " + string(global.selected.movement_left);
  714. }
  715. }
  716. else if global.overlays = 1
  717. {
  718. for (m = 0; m < grid_rows; m++)
  719. {
  720. for (n = 0; n < grid_columns; n ++)
  721. {
  722. global.hover[n,m] = false;
  723. }
  724. }
  725. for(button_index = 0; button_index < 6; button_index ++)
  726. {
  727. hover_side_button[button_index] = false
  728. }
  729. }
Advertisement
Add Comment
Please, Sign In to add comment