diff --git a/scripts/scr_company_order/scr_company_order.gml b/scripts/scr_company_order/scr_company_order.gml index 92361e9588..64a1775436 100644 --- a/scripts/scr_company_order/scr_company_order.gml +++ b/scripts/scr_company_order/scr_company_order.gml @@ -4,20 +4,25 @@ function temp_marine_variables(co, unit_num){ if (unit.squad != "none"){ var squad_member; var found = false; - for (var r=0;r=0;i--){ + unit = fetch_unit([co, i]); + if (!is_struct(unit)){ + TTRPG[co][i] = new TTRPG_stats("chapter", co, i, "blank"); + unit = fetch_unit([co, i]); + } + if (unit.name()=="") then continue; + + unit = fetch_unit([co, i]); + + if (unit.squad=="none"){ if (!struct_exists(squadless, unit.role())){ squadless[$ unit.role()] = [i]; } else { @@ -126,14 +140,14 @@ function scr_company_order(company) { //at this point check that all squads have the right types and numbers of units in them var squad, wanted_roles; - for (i=0;i=0;r--){ + var _wanted_role = wanted_roles[r]; + if (struct_exists(squadless,_wanted_role)){ - if (struct_exists(squadless,wanted_roles[r])){ - if (!squad.fulfilled){ + var _wanted_role_number = squad.space[$ _wanted_role]; + var _squadless_with_role = squadless[$ _wanted_role]; + var _squadless_with_role_count = array_length(squadless[$ _wanted_role]); - if (struct_exists(squad.required,wanted_roles[r])){ + if (!squad.fulfilled){ + + if (struct_exists(squad.required,_wanted_role)){ - while (array_length(squadless[$ wanted_roles[r]])>0) and (squad.required[$ wanted_roles[r]] > 0){ + var _needed_role_number = squad.required[$ _wanted_role]; + while (_squadless_with_role_count>0) and (_needed_role_number > 0){ - array_push(squad.members,[company,squadless[$ wanted_roles[r]][0]]); + var _marine_id = array_pop(_squadless_with_role); + unit = fetch_unit([co, _marine_id]); - TTRPG[co,squadless[$ wanted_roles[r]][0]].squad=i; + unit.add_to_squad(i); - array_delete(squadless[$ wanted_roles[r]],0,1); + _squadless_with_role_count--; - squad.required[$ wanted_roles[r]]--; - - squad.space[$ wanted_roles[r]]--; + _needed_role_number--; + _wanted_role_number--; } } } - if (struct_exists(squad.space,wanted_roles[r])){ - while (array_length(squadless[$ wanted_roles[r]])> 0) and (squad.space[$ wanted_roles[r]] > 0){ - array_push(squad.members,[company,squadless[$ wanted_roles[r]][0]]); - TTRPG[co,squadless[$ wanted_roles[r]][0]].squad=i; - array_delete(squadless[$ wanted_roles[r]],0,1); - squad.space[$ wanted_roles[r]]--; + if (struct_exists(squad.space,_wanted_role)){ + while (_squadless_with_role_count> 0) and (_wanted_role_number > 0){ + var _marine_id = array_pop(_squadless_with_role); + unit = fetch_unit([co, _marine_id]); + unit.add_to_squad(i) + _wanted_role_number--; } } } } //if no new sergeants are found for squad someone gets promoted - //find a new_sergeant - if (struct_exists(squad.required, role[100][18])){ - if (squad.required[$ role[100][18]] > 0){ + //find a new_sergeant + var _sarge = _roles[Role.SERGEANT] + if (struct_exists(squad.required, _sarge)){ + if (squad.required[$ _sarge] > 0){ squad.new_sergeant(); - squad.required[$ role[100][18]]--; + squad.required[$ _sarge]--; } } //find a new veteran sergeant - if (struct_exists(squad.required, role[100][19])){ - if (squad.required[$ role[100][19]] > 0){ + var _vet_sarge = _roles[Role.VETERAN_SERGEANT]; + if (struct_exists(squad.required, _vet_sarge)){ + if (squad.required[$ _vet_sarge] > 0){ squad.new_sergeant(true); - squad.required[$ role[100][19]]--; + squad.required[$ _vet_sarge]--; + } + } + for (var r = array_length(wanted_roles)-1;r >=0;r--){ + var _wanted_role = wanted_roles[r]; + if (struct_exists(squad.required,_wanted_role)){ + if (squad.required[$struct_exists] > 0){ + var _mems = squad.get_members(); + squad.empty_squad(); + for (var m=0;m0) && (array_length(squadless[$role[100,7]])>0) && (array_length(squadless[$role[100][11]])>0){ + if (struct_exists(squadless,_roles[Role.CAPTAIN])) && (struct_exists(squadless,_roles[Role.CHAMPION])) && (struct_exists(squadless,_roles[Role.ANCIENT])){ + if (array_length(squadless[$_roles[Role.CAPTAIN]])>0) && (array_length(squadless[$_roles[Role.CHAMPION]])>0) && (array_length(squadless[$_roles[Role.ANCIENT]])>0){ new_squad_index=false; if (array_length(empty_squads)>0){ new_squad_index = empty_squads[0]; @@ -253,7 +294,7 @@ function scr_company_order(company) { i--; sort_length--; //if unit is part of a squad make sure rest of squad is grouped next to unit - if (unit.squad !="none"){ + if (unit.squad != "none"){ var cur_squad = unit.squad; var r = -1; while (r < sort_length){ @@ -273,7 +314,7 @@ function scr_company_order(company) { //position 2 in role order /*if (global.chapter_name!="Space Wolves") and (global.chapter_name!="Iron Hands"){ i=0;repeat(300){i+=1; - if (role[co][i]=role[100][14]){v+=1; + if (role[co][i]=_roles[Roles.CHAPLAIN]){v+=1; temp_marine_variables(co, i ,v); } }*/ @@ -319,41 +360,41 @@ function scr_company_order(company) { } function role_hierarchy(){ - + var _roles = obj_ini.role[100]; var hierarchy = [ "Chapter Master", "Forge Master", "Master of Sanctity", "Master of the Apothecarion", - string("Chief {0}",obj_ini.role[100,17]), - obj_ini.role[100][2], - obj_ini.role[100][5], - obj_ini.role[100][14], - string("{0} Aspirant",obj_ini.role[100][14]), + string("Chief {0}",_roles[Role.LIBRARIAN]), + _roles[Role.HONOUR_GUARD], + _roles[Role.CAPTAIN], + _roles[Role.CHAPLAIN], + string("{0} Aspirant",_roles[Role.CHAPLAIN]), "Death Company", - obj_ini.role[100][16], - string("{0} Aspirant",obj_ini.role[100][16]), + _roles[Role.TECHMARINE], + string("{0} Aspirant",_roles[Role.TECHMARINE]), "Techpriest", - obj_ini.role[100][15], - string("{0} Aspirant",obj_ini.role[100][15]), + _roles[Role.APOTHECARY], + string("{0} Aspirant",_roles[Role.APOTHECARY]), "Sister Hospitaler", - obj_ini.role[100,17], + _roles[Role.LIBRARIAN], "Codiciery", "Lexicanum", - string("{0} Aspirant",obj_ini.role[100,17]), - obj_ini.role[100][11], - obj_ini.role[100][7], + string("{0} Aspirant",_roles[Role.LIBRARIAN]), + _roles[Role.ANCIENT], + _roles[Role.CHAMPION], "Death Company", - obj_ini.role[100][19], - obj_ini.role[100][18], - obj_ini.role[100][4], - obj_ini.role[100][3], - obj_ini.role[100][8], - obj_ini.role[100][10], - obj_ini.role[100][9], - obj_ini.role[100][12], - "Venerable "+string(obj_ini.role[100][6]), - obj_ini.role[100][6], + _roles[Role.VETERAN_SERGEANT], + _roles[Role.SERGEANT], + _roles[Role.TERMINATOR], + _roles[Role.VETERAN], + _roles[Role.TACTICAL], + _roles[Role.ASSAULT], + _roles[Role.DEVASTATOR], + _roles[Role.SCOUT], + $"Venerable {_roles[Role.DREADNOUGHT]}", + _roles[Role.DREADNOUGHT], "Skitarii", "Crusader", "Ranger", diff --git a/scripts/scr_company_view/scr_company_view.gml b/scripts/scr_company_view/scr_company_view.gml index 623c520268..5b9b182cde 100644 --- a/scripts/scr_company_view/scr_company_view.gml +++ b/scripts/scr_company_view/scr_company_view.gml @@ -429,8 +429,9 @@ function filter_and_sort_company(type, specific){ } function switch_view_company(new_view){ + with (obj_controller){ - if (new_view<1) then exit; + if (new_view<1) then exit; filter_mode = false; text_bar=0; if (managing<=10 && managing>=0){ @@ -449,6 +450,9 @@ function switch_view_company(new_view){ company_data={}; scr_special_view(new_view); } else { + with (obj_ini){ + scr_company_order(new_view); + } scr_company_view(new_view); company_data = new CompanyStruct(managing); } diff --git a/scripts/scr_manage_task_selector/scr_manage_task_selector.gml b/scripts/scr_manage_task_selector/scr_manage_task_selector.gml index 812c80b757..3774cd66e1 100644 --- a/scripts/scr_manage_task_selector/scr_manage_task_selector.gml +++ b/scripts/scr_manage_task_selector/scr_manage_task_selector.gml @@ -37,6 +37,7 @@ function scr_manage_task_selector(){ case "captain_promote": unit = display_unit[i]; unit.update_role(obj_ini.role[100][Role.CAPTAIN]); + unit.squad="none"; var start_company = unit.company; var end_company = selection_data.system; var endslot = 0; @@ -58,6 +59,7 @@ function scr_manage_task_selector(){ case "champion_promote": unit = display_unit[i]; unit.update_role(obj_ini.role[100][Role.CHAMPION]); + unit.squad="none"; with (obj_ini){ scr_company_order(unit.company); @@ -70,6 +72,7 @@ function scr_manage_task_selector(){ case "ancient_promote": unit = display_unit[i]; unit.update_role(obj_ini.role[100][Role.ANCIENT]); + unit.squad="none"; with (obj_ini){ diff --git a/scripts/scr_marine_struct/scr_marine_struct.gml b/scripts/scr_marine_struct/scr_marine_struct.gml index b219687617..e6d55cb862 100644 --- a/scripts/scr_marine_struct/scr_marine_struct.gml +++ b/scripts/scr_marine_struct/scr_marine_struct.gml @@ -2098,6 +2098,15 @@ function TTRPG_stats(faction, comp, mar, class = "marine", other_spawn_data={}) squad = "none" } } + static add_to_squad = function(new_squad){ + if (squad != "none"){ + if (new_squad==squad) then exit; + remove_from_squad(); + } + squad = new_squad; + var _squad = fetch_squad(squad); + _squad.add_member(company, marine_number); + } static marine_location = function(){ var location_id,location_name; var location_type = planet_location; diff --git a/scripts/scr_squads/scr_squads.gml b/scripts/scr_squads/scr_squads.gml index a8e15cfe35..8c173c677e 100644 --- a/scripts/scr_squads/scr_squads.gml +++ b/scripts/scr_squads/scr_squads.gml @@ -5,7 +5,9 @@ the requested squad type , if the squad is not possible it will not be made*/ // company : the company you wish to create the squad in (int) //squad_loadout: true if you want to use the squad loadout sorting algorithem to re-equip the squad in accordance with the squad type loadout - +function fetch_squad(array_id){ + return obj_ini.squads[array_id]; +} function create_squad(squad_type, company, squad_loadout = true, squad_index=false){ var squad_unit_types, fulfilled,unit, squad; @@ -303,16 +305,18 @@ function UnitSquad(squad_type = undefined, company = undefined) constructor{ static find_squad_unit_types = function (){//find out what type of units squad consists of var fill_squad = obj_ini.squad_types[$ type]; - squad_unit_types = struct_get_names(fill_squad); - var unit_type_count = array_length(squad_unit_types); + squad_unit_types = struct_get_names(fill_squad); + var _wanted_unit_role; + var unit_type_count = array_length(squad_unit_types); for (var i = 0;i < unit_type_count;i++){ - if (squad_unit_types[i] == "type_data"){ + _wanted_unit_role = squad_unit_types[i]; + if (_wanted_unit_role == "type_data"){ array_delete(squad_unit_types, i, 1); unit_type_count--; i--; continue; } - squad_fulfilment[$ squad_unit_types[i]] =0; //create a fulfilment structure to log members of squad + squad_fulfilment[$ _wanted_unit_role] =0; //create a fulfilment structure to log members of squad } return squad_unit_types; } @@ -365,28 +369,26 @@ function UnitSquad(squad_type = undefined, company = undefined) constructor{ deleted if there are no longer enough members ot make a squad*/ static update_fulfilment = function(){ var unit; + squad_fulfilment ={}; var fill_squad = obj_ini.squad_types[$ type]; //grab all the squad struct info from the squad_types struct - var squad_fulfilment = {}; + var squad_unit_types = struct_get_names(fill_squad); //find out what type of units squad consists of var unit_type_count = array_length(squad_unit_types); - for (var i = 0;i < unit_type_count;i++){ - if (squad_unit_types[i] == "type_data"){ + for (var i = unit_type_count-1;i>=0;i--){ + var _wanted_unit_role = squad_unit_types[i]; + if (_wanted_unit_role == "type_data"){ array_delete(squad_unit_types, i, 1); - unit_type_count--; - i--; continue; } - squad_fulfilment[$ squad_unit_types[i]] = 0; //create a fulfilment structure to log members of squad + squad_fulfilment[$ _wanted_unit_role] = 0; //create a fulfilment structure to log members of squad } var member_length = array_length(members); - for (var i=0;i=0;i--){ //checks squad member is still valid - unit = fetch_unit(members[i]); + unit = fetch_member(i); if (unit.name() == ""){ array_delete(members, i, 1); - member_length--; - i--; continue; } if (struct_exists(squad_fulfilment, unit.role())){ @@ -400,17 +402,33 @@ function UnitSquad(squad_type = undefined, company = undefined) constructor{ space = {}; has_space = false; for (i = 0;i < array_length(squad_unit_types);i++){ - if (squad_fulfilment[$ squad_unit_types[i]] < fill_squad[$ squad_unit_types[i]][$ "max"]){ - space[$ squad_unit_types[i]] = fill_squad[$ squad_unit_types[i]][$ "max"] - squad_fulfilment[$ squad_unit_types[i]]; + var _wanted_unit_role = squad_unit_types[i]; + var _max_role_count = fill_squad[$ _wanted_unit_role][$ "max"]; + var _squad_role_current = squad_fulfilment[$ _wanted_unit_role]; + + var _min_role_allowed = fill_squad[$ _wanted_unit_role][$ "min"]; + + if (_squad_role_current < _max_role_count){ + space[$ _wanted_unit_role] = _max_role_count - _squad_role_current; + has_space = true; } - has_space = true - if (squad_fulfilment[$ squad_unit_types[i]] < fill_squad[$ squad_unit_types[i]][$ "min"]){ + + if (squad_fulfilment[$ _wanted_unit_role] < _min_role_allowed){ fulfilled = false; - required[$ squad_unit_types[i]] = fill_squad[$ squad_unit_types[i]][$ "min"] - squad_fulfilment[$ squad_unit_types[i]]; + required[$ _wanted_unit_role] = _min_role_allowed - _squad_role_current; } } } + static empty_squad = function(){ + for (var r=array_length(members)-1;r>=0;r--){ + fetch_member(r).squad = "none"; + } + members = []; + } + static fetch_member= function(index){ + return fetch_unit(members[index]); + } static add_member = function(comp, unit_number){ array_push(members, [comp, unit_number]); life_members++; @@ -613,6 +631,14 @@ function UnitSquad(squad_type = undefined, company = undefined) constructor{ return data_pack; } + + static get_members = function(){ + var mems = []; + for (var i=0;i