Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if global.room_before = rm_creation_menu
- {
- //init ticker
- alarm[0] = room_speed/4;
- global.ticker = 0;
- global.room_before = noone;
- global.overlays = 0;
- with (obj_unit and obj_body)
- {
- instance_destroy();
- }
- cur_team = 0;
- global.handler = id
- grid_columns = 28;
- grid_rows = 16;
- grid_size = 32;
- define_grid(128,128,32,grid_columns,grid_rows);
- add_gridspacers(grid_rows,grid_columns);
- file = get_open_filename_ext("straticon file|*.stc", "", working_directory, "Open a saved level!");
- if file != ""
- {
- ini_open(file);
- increment = 0;
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- stringcrement = string(increment);
- straticon[n,m] = ini_read_real("straticons","straticon_" + stringcrement,noone);
- team[n,m] = ini_read_real("straticons","team_" + stringcrement,noone);
- parent_n_[n,m] = ini_read_real("straticons","parent_n_" + stringcrement,noone);
- parent_m_[n,m] = ini_read_real("straticons","parent_m_" + stringcrement, noone);
- int_left_connector = ini_read_real("straticons","left_connector_" + stringcrement, 0);
- if int_left_connector = 0
- {
- left_connector[n,m] = false;
- }
- else
- {
- left_connector[n,m] = true;
- }
- int_right_connector= ini_read_real("straticons","right_connector_" + stringcrement, 0);
- if int_right_connector = 0
- {
- right_connector[n,m] = false;
- }
- else
- {
- right_connector[n,m] = true;
- }
- int_up_connector= ini_read_real("straticons","up_connector_" + stringcrement, 0);
- if int_up_connector = 0
- {
- up_connector[n,m] = false;
- }
- else
- {
- up_connector[n,m] = true;
- }
- int_down_connector= ini_read_real("straticons","down_connector_" + stringcrement, 0);
- if int_down_connector = 0
- {
- down_connector[n,m] = false;
- }
- else
- {
- down_connector[n,m] = true;
- }
- increment++;
- }
- }
- ini_close();
- }
- else
- {
- room_goto(rm_creation_menu);
- }
- //define heads
- units = ds_list_create();
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- switch(straticon[n,m]){
- case 1: //worm head
- unit = instance_create(gridspace_x[n],gridspace_y[m],obj_unit);
- unit.team = team[n,m];
- unit.kind = "Worm 1.0";
- unit.type_id = 1;
- unit.sprite = spr_worm;
- unit.bodyparts = ds_list_create();
- unit.n = n;
- unit.m = m;
- unit.max_size = 2;
- unit.movement_per_turn = 2;
- unit.attack_range[0] = 1;
- unit.armor = 0;
- unit.attack[0] = 0; //attack
- unit.attack_string[0] = "Byte";
- unit.effect[0] = 2; //2 damage
- unit.attack[1] = noone;//no secondary move
- unit.attack[2] = noone; //no tretrary move
- unit.attack[3]= noone; //no quadrary move
- unit.cur_attack_range = unit.attack_range[0];
- unit.action_ammount = 1;
- unit.child_left = false;
- unit.child_right = false;
- unit.child_up = false;
- unit.child_down = false;
- unit.grid_rows = grid_rows;
- unit.grid_columns = grid_columns;
- ds_list_add(units,unit);
- break;
- default:
- break;
- }
- }
- }
- //now define bodies and link them to heads and to each other.
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- if straticon[n,m] = 2
- {
- body = instance_create(gridspace_x[n],gridspace_y[m],obj_body);
- body.n = n
- body.m = m
- body.left = false;
- body.right = false;
- body.up = false;
- body.down = false;
- body.child_left = false;
- body.child_right = false;
- body.child_up = false;
- body.child_down = false;
- body.type_id = straticon[n,m];
- body.grid_rows = grid_rows;
- body.grid_columns = grid_columns;
- }
- }
- }
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- if straticon[n,m] = 2
- {
- body = instance_nearest(gridspace_x[n],gridspace_y[m],obj_body);
- cur_part = straticon[n,m];
- cur_n = n;
- cur_m = m;
- while (cur_part != 1)
- {
- cur_part = straticon[parent_n_[cur_n,cur_m],parent_m_[cur_n,cur_m]]
- saved = cur_n;
- cur_n = parent_n_[cur_n,cur_m];
- cur_m = parent_m_[saved,cur_m];
- }
- body.head = instance_nearest(gridspace_x[cur_n],gridspace_y[cur_m],obj_unit);
- ds_list_add(body.head.bodyparts,body.id);
- body.team = body.head.team;
- if straticon[parent_n_[n,m],parent_m_[n,m]] = 1
- {
- body.parent = body.head;
- }
- else
- {
- body.parent = instance_nearest(gridspace_x[parent_n_[n,m]],gridspace_y[parent_m_[n,m]],obj_body);
- }
- if body.parent.n > body.n
- {
- body.right = true;
- body.parent.child_left = true;
- }
- if body.parent.n < body.n
- {
- body.left = true;
- body.parent.child_right = true
- }
- if body.parent.m > body.m
- {
- body.down = true;
- body.parent.child_up = true;
- }
- if body.parent.m < body.m
- {
- body.up = true;
- body.parent.child_down = true;
- }
- }
- }
- }
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- if straticon[n,m] = 2
- {
- body = instance_nearest(gridspace_x[n],gridspace_y[m],obj_body);
- body.parent_n = body.parent.n;
- body.parent_m = body.parent.m;
- endbubble = false;
- while(endbubble == false)
- {
- endbubble = true;
- with(obj_body)
- {
- if self.depth >= self.parent.depth
- {
- endbubble = false;
- self.depth --;
- if self.depth = -10000
- {
- self.depth = 0;
- }
- }
- }
- }
- }
- }
- }
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- if straticon[n,m] != noone
- {
- straticon[n,m] = 0;
- }
- }
- }
- player_team = ds_list_create();
- ally_team = ds_list_create();
- enemy_team_1 = ds_list_create();
- enemy_team_2 = ds_list_create();
- //fill team ds lists
- for (cur_unit = 0; cur_unit < ds_list_size(units); cur_unit++)
- {
- unit = ds_list_find_value(units,cur_unit);
- switch(unit.team){
- case 0:
- ds_list_add(player_team,unit);
- break;
- case 1:
- ds_list_add(ally_team,unit);
- break;
- case 2:
- ds_list_add(enemy_team_1,unit);
- break;
- case 3:
- ds_list_add(enemy_team_2,unit);
- break;
- }
- }
- //init turns
- global.cur_turn = 0 //player turn
- global.selected = noone;
- global.movedone = true;
- global.finished_moved = ds_list_create();
- init[0] = false;
- init[1] = false;
- init[2] = false;
- init[3] = false;
- //GRIDSPACERS
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- if m > 0
- {
- up_possible[n,m] = true;
- up_tiled[n,m] = false;
- up_connected[n,m] = false;
- }
- else
- {
- up_possible[n,m] = false;
- up_tiled[n,m] = false;
- up_connected[n,m] = false;
- }
- if m < grid_rows - 1
- {
- down_possible[n,m] = true;
- down_tiled[n,m] = false;
- down_connected[n,m] = false;
- }
- else
- {
- down_possible[n,m] = false;
- down_tiled[n,m] = false;
- down_connected[n,m] = false;
- }
- if n > 0
- {
- left_possible[n,m] = true;
- left_tiled[n,m] = false;
- left_connected[n,m] = false;
- }
- else
- {
- left_possible[n,m] = false;
- left_tiled[n,m] = false;
- left_connected[n,m] = false;
- }
- if n < grid_columns - 1
- {
- right_possible[n,m] = true;
- right_tiled[n,m] = false;
- right_connected[n,m] = false;
- }
- else
- {
- right_possible[n,m] = false;
- right_tiled[n,m] = false;
- right_connected[n,m] = false;
- }
- }
- }
- resset_n_and_m();
- global.fields_generated = false;
- if global.fields_generated = false
- {
- global.fields_generated = true;
- with (obj_unit)
- {
- for (cur_m = 0; cur_m < grid_rows; cur_m++)
- {
- for (cur_n = 0; cur_n < grid_columns; cur_n ++)
- {
- if global.handler.straticon[cur_n,cur_m] = 0
- {
- walkable[cur_n,cur_m] = true;
- }
- else if global.handler.straticon[cur_n,cur_m] = type_id + 1
- {
- cur_body = instance_nearest(global.handler.gridspace_x[cur_n],global.handler.gridspace_y[cur_m],obj_body);
- if cur_body.head = id
- {
- walkable[cur_n,cur_m] = true;
- }
- else
- {
- walkable[cur_n,cur_m] = false;
- }
- }
- else
- {
- walkable[cur_n,cur_m] = false;
- }
- }
- }
- }
- }
- resset_units();
- side_button_start_x = room_width - 192;
- side_button_start_y = 128;
- button_width = 256;
- button_height = 32;
- for(button_index = 0; button_index < 6; button_index++)
- {
- side_button_x[button_index] = side_button_start_x;
- side_button_y[button_index] = side_button_start_y + ((64)*button_index);
- side_button_left_x[button_index] = side_button_x[button_index] - button_width/2;
- side_button_right_x[button_index] = side_button_x[button_index] + button_width/2;
- side_button_top_y[button_index] = side_button_y[button_index] - button_height/2;
- side_button_bottom_y[button_index] = side_button_y[button_index] + button_height/2;
- }
- title_text_x = side_button_start_x;
- title_text_y = side_button_start_y - 64;
- }
- if global.overlays = 0
- {
- if global.cur_turn = 0
- {
- ai = false;
- cur_team = 0;
- if init[0] = false
- {
- init[0] = true;
- for (cur_index = 0; cur_index < ds_list_size(player_team); cur_index ++)
- {
- cur_unit = ds_list_find_value(player_team,cur_index);
- if cur_unit = 0
- {
- global.selected = cur_unit;
- }
- cur_unit.movement_left = cur_unit.movement_per_turn;
- cur_unit.done = false;
- ds_list_destroy(global.finished_moved);
- global.finished_moved = ds_list_create();
- }
- }
- if global.movedone //automatically select next avaliable unit. if none avalible, move on to next turn
- {
- global.movedone = false;
- endnow = false;
- goodindex = false;
- index = -1
- while (endnow = false)
- { //while ending condition is not met, loop through player_team.
- index ++;
- finished_moved_cur_index = 0;
- endnestedwhile = false;
- while (endnestedwhile = false)
- {
- 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
- {
- endnestedwhile = true;
- goodindex = false;
- }
- if finished_moved_cur_index = ds_list_size(global.finished_moved) //none equal player team, so this is good index
- {
- endnestedwhile = true;
- goodindex = true;
- }
- finished_moved_cur_index += 1;
- }
- if goodindex = true
- {
- global.selected = ds_list_find_value(player_team,index);
- endnow = true;
- }
- else if index = ds_list_size(player_team) - 1//if end of player_team is hit, end loop and move to next turn
- {
- endnow = true;
- global.cur_turn += 1;
- }
- }
- }
- }
- if global.cur_turn = 1
- {
- ai = true;
- cur_team = 1;
- cur_ds = ally_team;
- if ds_list_size(cur_ds) = 0
- {
- global.cur_turn ++;
- }
- }
- if global.cur_turn = 2
- {
- ai = true;
- cur_team = 2;
- cur_ds = enemy_team_1;
- if ds_list_size(cur_ds) = 0
- {
- global.cur_turn ++;
- }
- }
- if global.cur_turn = 3
- {
- ai = true;
- cur_team = 3;
- cur_ds = enemy_team_2;
- if ds_list_size(cur_ds) = 0
- {
- global.cur_turn ++;
- }
- }
- if global.cur_turn = 4
- {
- ai = false;
- global.cur_turn = 0 //player turn
- global.selected = noone;
- global.movedone = true;
- init[0] = false;
- init[1] = false;
- init[2] = false;
- init[3] = false;
- }
- if ai = true
- {
- if init[global.cur_turn] = false
- {
- init[global.cur_turn] = true;
- for (cur_index = 0; cur_index < ds_list_size(cur_ds); cur_index ++)
- {
- cur_unit = ds_list_find_value(cur_ds,cur_index);
- if cur_unit = 0
- {
- global.selected = cur_unit;
- }
- cur_unit.movement_left = cur_unit.movement_per_turn;
- cur_unit.done = false;
- }
- ds_list_destroy(global.finished_moved);
- global.finished_moved = ds_list_create();
- }
- if global.movedone //automatically select next avaliable unit. if none avalible, move on to next turn
- {
- global.movedone = false;
- endnow = false;
- goodindex = false;
- index = -1
- while (endnow = false)
- { //while ending condition is not met, loop through player_team.
- index ++;
- finished_moved_cur_index = 0;
- endnestedwhile = false;
- while (endnestedwhile = false)
- {
- 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
- {
- endnestedwhile = true;
- goodindex = false;
- }
- if finished_moved_cur_index = ds_list_size(global.finished_moved) //none equal player team, so this is good index
- {
- endnestedwhile = true;
- goodindex = true;
- }
- finished_moved_cur_index += 1;
- }
- if goodindex = true
- {
- global.selected = ds_list_find_value(cur_ds,index);
- endnow = true;
- }
- else if index = ds_list_size(cur_ds) - 1//if end of team is hit, end loop and move to next turn
- {
- endnow = true;
- global.cur_turn += 1;
- }
- }
- }
- }
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- 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);
- }
- }
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- if up_possible[n,m]
- {
- if straticon[n,m-1] = 0
- {
- up_tiled[n,m] = true;
- }
- else
- {
- up_tiled[n,m] = false;
- }
- }
- if down_possible[n,m]
- {
- if straticon[n,m+1] = 0
- {
- down_tiled[n,m] = true;
- }
- else
- {
- down_tiled[n,m] = false;
- }
- }
- if left_possible[n,m]
- {
- if straticon[n-1,m] = 0
- {
- left_tiled[n,m] = true;
- }
- else
- {
- left_tiled[n,m] = false;
- }
- }
- if right_possible[n,m]
- {
- if straticon[n+1,m] = 0
- {
- right_tiled[n,m] = true;
- }
- else
- {
- right_tiled[n,m] = false;
- }
- }
- }
- }
- if global.fields_generated = false
- {
- with (obj_unit)
- {
- global.fields_generated = true;
- for (cur_m = 0; cur_m < grid_rows; cur_m++)
- {
- for (cur_n = 0; cur_n < grid_columns; cur_n ++)
- {
- if global.handler.straticon[cur_n,cur_m] = 0
- {
- walkable[cur_n,cur_m] = true;
- }
- else if global.handler.straticon[cur_n,cur_m] = type_id + 1
- {
- cur_body = instance_nearest(global.handler.gridspace_x[cur_n],global.handler.gridspace_y[cur_m],obj_body);
- if cur_body.head = id
- {
- walkable[cur_n,cur_m] = true;
- }
- else
- {
- walkable[cur_n,cur_m] = false;
- }
- }
- else
- {
- walkable[cur_n,cur_m] = false;
- }
- }
- }
- }
- }
- //side buttons
- if global.selected != noone and global.cur_turn = 0
- {
- for(button_index = 0; button_index < 6; button_index ++)
- {
- if button_index < 4 and button_index > 0 and global.selected.attack[button_index - 1] != noone
- {
- 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]);
- }
- else if button_index = 0 or button_index = 5
- {
- 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]);
- }
- else
- {
- hover_side_button[button_index] = false;
- }
- if hover_side_button[button_index] and mouse_check_button_released(mb_left) and button_index != 5
- {
- global.selected.mode = button_index - 1;
- global.selected.select_init = false;
- }
- else if hover_side_button[button_index] and mouse_check_button_released(mb_left) and button_index = 5
- {
- ds_list_add(global.finished_moved,global.selected);
- global.movedone = true;
- wipe_nodes();
- global.selected = noone;
- }
- }
- }
- button_text[0] = "Movement";
- if global.selected != noone
- {
- button_text[1] = global.selected.attack_string[0];
- if global.selected.attack[1] != noone
- {
- button_text[2] = global.selected.attack_string[1];
- }
- if global.selected.attack[2] != noone
- {
- button_text[3] = global.selected.attack_string[2];
- }
- if global.selected.attack[3] != noone
- {
- button_text[4] = global.selected.attack_string[3];
- }
- }
- button_text[5] = "End Move";
- if global.selected != noone
- {
- movement_left_string = "Movement Left: " + string(global.selected.movement_left);
- }
- }
- else if global.overlays = 1
- {
- for (m = 0; m < grid_rows; m++)
- {
- for (n = 0; n < grid_columns; n ++)
- {
- global.hover[n,m] = false;
- }
- }
- for(button_index = 0; button_index < 6; button_index ++)
- {
- hover_side_button[button_index] = false
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment