diff --git a/objects/obj_centerline/Step_0.gml b/objects/obj_centerline/Step_0.gml index ba65dc90c0..d05a341736 100644 --- a/objects/obj_centerline/Step_0.gml +++ b/objects/obj_centerline/Step_0.gml @@ -1,7 +1,7 @@ - +/* if (instance_exists(obj_pnunit)){ var _nearest = instance_nearest(-100,240,obj_pnunit); if (instance_exists(_nearest)){ x = _nearest.x; } -} +} */ diff --git a/objects/obj_enunit/Alarm_0.gml b/objects/obj_enunit/Alarm_0.gml index ed57151427..51479cc94d 100644 --- a/objects/obj_enunit/Alarm_0.gml +++ b/objects/obj_enunit/Alarm_0.gml @@ -129,7 +129,7 @@ if (!engaged){ // Shooting continue; } else if (instance_number(obj_pnunit) > 1) { // There were no marines in the first column, looking behind; - var _column_size_value = (enemy.veh * 2.5) + (enemy.dreads * 2) + (enemy.men * 0.5); + var _column_size_value = enemy.column_size; var x2 = enemy.x; repeat (instance_number(obj_pnunit) - 1) { @@ -145,7 +145,7 @@ if (!engaged){ // Shooting break; } - var _back_column_size_value = (enemy2.veh * 2.5) + (enemy2.dreads * 2) + (enemy2.men * 0.5); + var _back_column_size_value = enemy2.column_size; if (_back_column_size_value < _column_size_value) { // show_debug_message($"Protection value is too big!"); continue; diff --git a/objects/obj_enunit/Create_0.gml b/objects/obj_enunit/Create_0.gml index 5c129c30b6..17482e5622 100644 --- a/objects/obj_enunit/Create_0.gml +++ b/objects/obj_enunit/Create_0.gml @@ -11,9 +11,19 @@ flank=0; flyer=0;// Works same as flank, but does not get denoted as such neww=0; -highlight=0; -highlight2=0; -highlight3=""; +column_size=0; + +unit_count=0; +unit_count_old=0; +composition_string=""; + +pos = 880; +centerline_offset = 0; +draw_size = 0; +x1 = pos + (centerline_offset * 2); +y1 = 450 - (draw_size / 2); +x2 = pos + (centerline_offset * 2) + 10; +y2 = 450 + (draw_size / 2); enemy=0; enemy2=0; @@ -73,6 +83,6 @@ if (obj_ncombat.enemy=1) then alarm[6]=10; // if (obj_ncombat.enemy=1){alarm[1]=8;alarm[5]=10;} -pos = 0; -diff = 0; -siz = 0; +hit = function() { + return scr_hit(x1, y1, x2, y2) && obj_ncombat.fadein <= 0; +}; diff --git a/objects/obj_enunit/Draw_0.gml b/objects/obj_enunit/Draw_0.gml index acc1e69544..791cfcc9ac 100644 --- a/objects/obj_enunit/Draw_0.gml +++ b/objects/obj_enunit/Draw_0.gml @@ -1,43 +1,78 @@ +draw_size = min(400, column_size); -if (instance_exists(obj_pnunit)){ - diff=0;pos=880; - siz=min(400,(men*0.5)+(medi)+(veh*2.5)+(dreads*2)); -} +if (draw_size > 0){ + draw_set_alpha(1); + draw_set_color(global.star_name_colors[obj_ncombat.enemy]); + if (instance_exists(obj_centerline)){ + centerline_offset=x-obj_centerline.x; + } -draw_set_color(c_white); -if (instance_exists(obj_centerline)) and (instance_exists(obj_pnunit)){ - diff=x-obj_centerline.x; -} + x1 = pos + (centerline_offset * 2); + y1 = 450 - (draw_size / 2); + x2 = pos + (centerline_offset * 2) + 10; + y2 = 450 + (draw_size / 2); -draw_set_color(c_maroon); -if (obj_ncombat.enemy=2) then draw_set_color(8307806); -if (obj_ncombat.enemy=3) then draw_set_color(16512); -if (obj_ncombat.enemy=5) then draw_set_color(c_silver); -if (obj_ncombat.enemy=6) then draw_set_color(33023); -if (obj_ncombat.enemy=7) then draw_set_color(38144); -if (obj_ncombat.enemy=8) then draw_set_color(117758); -if (obj_ncombat.enemy=9) then draw_set_color(7492269); -if (obj_ncombat.enemy=10) then draw_set_color(c_purple); -if (obj_ncombat.enemy=13) then draw_set_color(65408); - -if (siz>0){ - draw_set_alpha(1); - if (highlight>0) then draw_set_alpha(0.8); - if ((pos+(diff*2))>817) and ((pos+(diff*2))<1575){ - draw_rectangle(pos+(diff*2),450-(siz/2),pos+(diff*2)+10,450+(siz/2),0); + if (hit()) { + draw_set_alpha(0.8); } - draw_set_alpha(1); -} -if (highlight>0) and (obj_ncombat.fadein<=0){ - draw_set_color(38144); - draw_line(pos+(diff*2)+5,450,817,685); - draw_set_font(fnt_40k_14b); - draw_text(817,688,string_hash_to_newline("Row Composition:")); - draw_set_font(fnt_40k_14); - draw_text_ext(817,706,string_hash_to_newline(string(highlight3)),-1,758); -} + draw_rectangle(x1, y1, x2, y2, 0); + if (hit()) { + if (unit_count != unit_count_old) { + unit_count_old = unit_count; + if (obj_ncombat.enemy!=1){ + composition_string += block_composition_string(); + } else { + var variety, variety_num, stop, sofar, compl, vas; + stop = 0; + variety = []; + variety_num = []; + sofar = 0; + compl = ""; + vas = ""; + + var variety_len = array_length(variety); + for (var q = 0; q < variety_len; q++) { + variety[q] = ""; + variety_num[q] = 0; + } + var dudes_len = array_length(dudes); + for (var q = 0; q < dudes_len; q++) { + if (dudes[q] != "") and(string_count(string(dudes[q]) + "|", compl) = 0) { + compl += string(dudes[q]) + "|"; + variety[sofar] = dudes[q]; + variety_num[sofar] = 0; + sofar += 1; + } + } + var dudes_len = array_length(dudes); + for (var q = 0; q < dudes_len; q++) { + if (dudes[q] != "") { + var variety_len = array_length(variety); + for (var i = 0; i < variety_len; i++) { + if (dudes[q] = variety[i]) then variety_num[i] += dudes_num[q]; + } + } + + } + stop = 0; + var variety_num_len = array_length(variety_num); + for (var i = 0; i < variety_num_len; i++) { + if (stop = 0) { + if (variety_num[i] > 0) and(variety_num[i + 1] > 0) then composition_string += string(variety_num[i]) + "x " + string(variety[i]) + ", "; + if (variety_num[i] > 0) and(variety_num[i + 1] <= 0) { + composition_string += string(variety_num[i]) + "x " + string(variety[i]) + ". "; + stop = 1; + } + } + } + } + } + draw_block_composition(x1, composition_string); + } + draw_block_fadein(); +} diff --git a/objects/obj_enunit/Step_0.gml b/objects/obj_enunit/Step_0.gml index 5332b33ae1..e73945c5f9 100644 --- a/objects/obj_enunit/Step_0.gml +++ b/objects/obj_enunit/Step_0.gml @@ -1,76 +1,2 @@ - -highlight=0; -var diff,siz,pos; -diff=0;pos=880;siz=min(400,(men*0.5)+(medi)+(veh*2.5)+(dreads*2)); -if (instance_exists(obj_centerline)){ - diff=x-obj_centerline.x; -} -if (siz>0){ - if ((pos+(diff*2))>817) and ((pos+(diff*2))<1575){ - if (mouse_x>=pos+(diff*2)) and (mouse_y>=450-(siz/2)) - and (mouse_x0) and (dudes_num[i+1]>0) then highlight3+=string(dudes_num[i])+"x "+string(dudes[i])+", "; - if (dudes_num[i]>0) and (dudes_num[i+1]<=0){highlight3+=string(dudes_num[i])+"x "+string(dudes[i])+". ";stop=1;} - } - } - } - - if (obj_ncombat.enemy = 1) { - var variety, variety_num, stop, sofar, compl, vas; - stop = 0; - variety = []; - variety_num = []; - sofar = 0; - compl = ""; - vas = ""; - - var variety_len = array_length(variety); - for (var q = 0; q < variety_len; q++) { - variety[q] = ""; - variety_num[q] = 0; - } - var dudes_len = array_length(dudes); - for (var q = 0; q < dudes_len; q++) { - if (dudes[q] != "") and(string_count(string(dudes[q]) + "|", compl) = 0) { - compl += string(dudes[q]) + "|"; - variety[sofar] = dudes[q]; - variety_num[sofar] = 0; - sofar += 1; - } - } - var dudes_len = array_length(dudes); - for (var q = 0; q < dudes_len; q++) { - if (dudes[q] != "") { - var variety_len = array_length(variety); - for (var i = 0; i < variety_len; i++) { - if (dudes[q] = variety[i]) then variety_num[i] += dudes_num[q]; - } - } - - } - stop = 0; - var variety_num_len = array_length(variety_num); - for (var i = 0; i < variety_num_len; i++) { - if (stop = 0) { - if (variety_num[i] > 0) and(variety_num[i + 1] > 0) then highlight3 += string(variety_num[i]) + "x " + string(variety[i]) + ", "; - if (variety_num[i] > 0) and(variety_num[i + 1] <= 0) { - highlight3 += string(variety_num[i]) + "x " + string(variety[i]) + ". "; - stop = 1; - } - } - } - } -} - - +update_block_size(); +update_block_unit_count(); diff --git a/objects/obj_pnunit/Create_0.gml b/objects/obj_pnunit/Create_0.gml index e4f8464563..9a02730af4 100644 --- a/objects/obj_pnunit/Create_0.gml +++ b/objects/obj_pnunit/Create_0.gml @@ -10,11 +10,21 @@ attacked_dudes=0; dreads=0; jetpack_destroy=0; defenses=0; -highlight=0; -highlight2=0; -highlight3=""; -siz = 0; -x_offset = 0; + +unit_count=0; +unit_count_old=0; +composition_string=""; + +column_size = 0; + +centerline_offset = 0; +pos = 880; +draw_size = 0; +x1 = pos + (centerline_offset * 2); +y1 = 450 - (draw_size / 2); +x2 = pos + (centerline_offset * 2) + 10; +y2 = 450 + (draw_size / 2); + // let="";let=string_delete(obj_ini.psy_powers,2,string_length(obj_ini.psy_powers)-1);let=string_upper(let); // LET might be different for each marine; need a way of determining this @@ -112,3 +122,7 @@ hostile_splash=0; alarm[1]=4; action_set_alarm(1, 3); + +hit = function() { + return scr_hit(x1, y1, x2, y2) && obj_ncombat.fadein <= 0; +}; diff --git a/objects/obj_pnunit/Draw_0.gml b/objects/obj_pnunit/Draw_0.gml index 78acb60174..124debc521 100644 --- a/objects/obj_pnunit/Draw_0.gml +++ b/objects/obj_pnunit/Draw_0.gml @@ -1,60 +1,38 @@ +draw_size = min(400, column_size); -/*if (engaged=1) then image_index=1; -if (engaged=0) then image_index=0; -draw_self();*/ - -var diff=0,pos=880; -if (veh_type[1]="Defenses"){ - siz=0; - if (instance_exists(obj_nfort)) then siz=400; -} -draw_set_color(c_white); -if (instance_exists(obj_centerline)){ - diff=x-obj_centerline.x; +if (draw_size > 0){ + draw_set_alpha(1); draw_set_color(c_red); + + if (instance_exists(obj_centerline)){ + centerline_offset=x-obj_centerline.x; + } + if (veh_type[1]=="Defenses"){ - diff=135; + draw_size=0; + if (instance_exists(obj_nfort)) then draw_size=400; + centerline_offset=135; draw_set_color(c_gray); } -} -siz=min(400,(men*0.5)+(veh*2.5)+(dreads*2)); -x_offset = pos+(diff*2); -if (siz>0){ - draw_set_alpha(1); - if (highlight>0) then draw_set_alpha(0.8); - if (x_offset>817) and (x_offset<1575){ - draw_rectangle(x_offset,450-(siz/2),x_offset+10,450+(siz/2),0); - } - draw_set_alpha(1); -} - -if (highlight>0) and (obj_ncombat.fadein<=0){ - draw_set_color(38144); - draw_line(x_offset+5,450,817,685); - draw_set_font(fnt_40k_14b); - draw_text(817,688,"Row Composition:"); - draw_set_font(fnt_40k_14); - draw_text_ext(817,706,string_hash_to_newline(string(highlight3)),-1,758); -} -// draw_text(800,(x*18)-400,string(diff)); + x1 = pos + (centerline_offset * 2); + y1 = 450 - (draw_size / 2); + x2 = pos + (centerline_offset * 2) + 10; + y2 = 450 + (draw_size / 2); + if (hit()) { + draw_set_alpha(0.8); + } + draw_rectangle(x1, y1, x2, y2, 0); -draw_set_color(c_black); -draw_set_alpha(obj_ncombat.fadein/30); -draw_rectangle(822,239,1574,662,0); -draw_set_alpha(1); - - - -exit; - -draw_set_color(255); -draw_text((x*18)-400,300,string_hash_to_newline(string(men)+"|"+string(veh)+"#"+string(dudes_num[1])+"x "+string(dudes[1])+"#"+string(dudes_num[2])+"x "+string(dudes[2])+"#"+string(dudes_num[3])+"x "+string(dudes[3])+"#"+string(dudes_num[4])+"x "+string(dudes[4])+"#"+string(dudes_num[5])+"x "+string(dudes[5]))); - - -draw_text((x*18)-400,420,string_hash_to_newline("1: "+string(veh_type[1])+"#2: "+string(veh_type[2])+"#3: "+string(veh_type[3])+"#4: "+string(veh_type[4])+"#5: "+string(veh_type[5])+"#6: "+string(veh_type[6]))); + if (hit()) { + if (unit_count != unit_count_old) { + unit_count_old = unit_count; + composition_string = block_composition_string(); + } + draw_block_composition(x1, composition_string); + } -/* */ -/* */ + draw_block_fadein() +} \ No newline at end of file diff --git a/objects/obj_pnunit/Step_0.gml b/objects/obj_pnunit/Step_0.gml index c97d5542bc..e7e5f44c3a 100644 --- a/objects/obj_pnunit/Step_0.gml +++ b/objects/obj_pnunit/Step_0.gml @@ -1,44 +1,9 @@ // These arrays are the losses on any one frame. // Instead of resetting in a bunch of places, we reset here. -array_resize(lost, 0) -array_resize(lost_num, 0) - -highlight=0; -var diff=0; -var pos=880; - -if (instance_exists(obj_centerline)){ - diff=x-obj_centerline.x; -} -if (instance_exists(obj_enunit)) { - siz=min(400,(men*0.5)+(medi)+(veh*2.5)+(dreads*2)); -} else { - siz = 0; -} -if (siz>0){ - if ((x_offset)>817) and ((x_offset)<1575){ - if (scr_hit([x_offset,450-(siz/2),x_offset+10,450+(siz/2)])){ - highlight=men+medi+dreads+veh; - } - } -} - -if (highlight2!=highlight){ - highlight2=highlight; - highlight3=""; - - var dudes_len = array_length(dudes_num); - for (var i = 0; i < dudes_len; i++){ - - if (dudes_num[i] > 0 and dudes_num[i+1] > 0) { - highlight3+=$"{dudes_num[i]}X {dudes[i]}, " - } else if (dudes_num[i] > 0 and dudes_num[i+1] <= 0) { - highlight3+=$"{dudes_num[i]}X {dudes[i]}."; - break; - } - - } -} +array_resize(lost, 0); +array_resize(lost_num, 0); +update_block_size(); +update_block_unit_count(); diff --git a/scripts/scr_punit_combat_heplers/scr_punit_combat_heplers.gml b/scripts/scr_punit_combat_heplers/scr_punit_combat_heplers.gml index 440712a2bc..85a685e60a 100644 --- a/scripts/scr_punit_combat_heplers/scr_punit_combat_heplers.gml +++ b/scripts/scr_punit_combat_heplers/scr_punit_combat_heplers.gml @@ -238,3 +238,67 @@ function move_enemy_blocks() { } ds_priority_destroy(_enemy_movement_queue); } + +/// @mixin +function block_composition_string() { + var _composition_string = ""; + + _composition_string = $"{unit_count}x Total; "; + if (men > 0) { + _composition_string += $"{string_plural_count("Normal Unit", men)}; "; + } + if (medi > 0) { + _composition_string += $"{string_plural_count("Big Unit", medi)}; "; + } + if (dreads > 0) { + _composition_string += $"{string_plural_count("Walker", dreads)}; "; + } + if (veh > 0) { + _composition_string += $"{string_plural_count("Vehicle", veh)}; "; + } + _composition_string += $"\n"; + + var dudes_len = array_length(dudes_num); + for(var i = 0; i < dudes_len; i++) { + if (dudes_num[i] == 0) { + continue; + } + _composition_string += $"{dudes_num[i]}x {dudes[i]}"; + if (i < dudes_len - 1) { + _composition_string += ", "; + } else { + _composition_string += ". "; + } + } + + return _composition_string; +} + +function draw_block_composition(_x1, _composition_string) { + draw_set_alpha(1); + draw_set_color(38144); + draw_line_width(_x1+5,450,817,685, 2); + draw_set_font(fnt_40k_14b); + draw_text(817,688,"Row Composition:"); + draw_set_font(fnt_40k_14); + draw_text_ext(817,710,_composition_string,-1,758); +} + +function draw_block_fadein() { + if (obj_ncombat.fadein > 0) { + draw_set_color(c_black); + draw_set_alpha(obj_ncombat.fadein/30); + draw_rectangle(822,239,1574,662,0); + draw_set_alpha(1); + } +} + +/// @mixin +function update_block_size() { + column_size = (men*0.5)+(medi)+(dreads*2)+(veh*2.5); +} + +/// @mixin +function update_block_unit_count() { + unit_count = men + medi + dreads + veh; +} diff --git a/scripts/scr_string_functions/scr_string_functions.gml b/scripts/scr_string_functions/scr_string_functions.gml index c2c86c5f7b..2c4569d909 100644 --- a/scripts/scr_string_functions/scr_string_functions.gml +++ b/scripts/scr_string_functions/scr_string_functions.gml @@ -45,6 +45,16 @@ function string_plural(_string, _variable = 2) { } } +/// @function string_plural_count +/// @description This function formats a string into a plural form by adding affixes following common rules, and adds the x(variable) text at the start. +/// @param {string} _string +/// @param {real} _variable Variable to check if more than 1 before converting to plural, and add at the start. +/// @returns {string} Modified string. +function string_plural_count(_string, _variable) { + var _modified_string = $"{_variable}x {string_plural(_string, _variable)}"; + return _modified_string; +} + /// @function string_truncate /// @description Truncates a string to fit within a specified pixel width, appending "..." if the string was truncated. /// @param {string} _string