Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 117 additions & 76 deletions scripts/scr_company_order/scr_company_order.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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<array_length(squads[unit.squad].members);r++){
squad_member = squads[unit.squad].members[r];
var _squad_members = squads[unit.squad].members;
for (var r=0;r<array_length(_squad_members);r++){
squad_member = _squad_members[r];
try{
if (squad_member[0] == unit.company) and (squad_member[1] == unit.marine_number){
squads[unit.squad].members[r] = [co,array_length(temp_name)];
found = true;
break;
if (is_array(squad_member)){
if (squad_member[0] == unit.company) and (squad_member[1] == unit.marine_number){
squads[unit.squad].members[r] = [co,array_length(temp_name)];
found = true;
break;
}
}
} catch( _exception) {
handle_exception(_exception);
unit.squad="none";
}
}
if (!found){unit.squad = "none"}
if (!found){
unit.squad = "none"
}
}
array_push(temp_race,race[co][unit_num]);
array_push(temp_loc,loc[co][unit_num]);
Expand Down Expand Up @@ -111,11 +116,20 @@ function scr_company_order(company) {
var role_shuffle_length = array_length(role_orders);
var company_length = array_length(name[co]);
var squadless={};

var _roles = obj_ini.role[100];
// find units not in a squad
for (i=0;i<company_length;i++){
if (!is_struct(TTRPG[co][i])) then TTRPG[co][i] = new TTRPG_stats("chapter", co, i, "blank");
unit = TTRPG[co][i];
if (unit.squad=="none") and (unit.name()!=""){
for (i=company_length-1;i>=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 {
Expand All @@ -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<array_length(squads);i++){
if (squads[i].base_company != co){
if (array_length(squads[i].members)==0){
for (i=0;i<array_length(obj_ini.squads);i++){
if (obj_ini.squads[i].base_company != co){
if (array_length(obj_ini.squads[i].members)==0){
array_push(empty_squads,i);
}
continue;
}
squad = squads[i];
squad = obj_ini.squads[i];
squad.update_fulfilment();

//squad has role spaces to fill
Expand All @@ -143,66 +157,93 @@ function scr_company_order(company) {
/* this finds sqauds that are in need of members and checks ot see if there
are any squadless units in the chapter with
the right role to fill the gap*/
for (var r = 0;r < array_length(wanted_roles);r++){
for (var r = array_length(wanted_roles)-1;r >=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;m<array_length(_mems);m++){
unit = _mems[m];
if (unit.squad=="none"){
if (!struct_exists(squadless, unit.role())){
squadless[$ unit.role()] = [i];
} else {
array_push(squadless[$ unit.role()],i);
}
}
}
}
}
}
}
}
}

var squadless_and_squad_spaces = [squadless,empty_squads];

var squad_builder = [
["tactical_squad",role[100][8],5],
["devastator_squad",role[100][9],5],
["sternguard_veteran_squad",role[100][3],5],
["vanguard_veteran_squad",role[100][3],5],
["terminator_squad",role[100][4],4],
["terminator_assault_squad",role[100][4],4],
["assault_squad",role[100][10],5],
["scout_squad",role[100][12],5],
["tactical_squad",_roles[Role.TACTICAL],5],
["devastator_squad",_roles[Role.DEVASTATOR],5],
["sternguard_veteran_squad",_roles[Role.VETERAN],5],
["vanguard_veteran_squad",_roles[Role.VETERAN],5],
["terminator_squad",_roles[Role.TERMINATOR],4],
["terminator_assault_squad",_roles[Role.TERMINATOR],4],
["assault_squad",_roles[Role.ASSAULT],5],
["scout_squad",_roles[Role.SCOUT],5],
]

for (i=0;i<array_length(squad_builder);i++){
Expand All @@ -214,8 +255,8 @@ function scr_company_order(company) {
}

//comand squads only get built to a max of one and are specialist so sit outside of general squad creation
if (struct_exists(squadless,role[100,5])) && (struct_exists(squadless,role[100,7])) && (struct_exists(squadless,role[100][11])){
if (array_length(squadless[$role[100,5]])>0) && (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];
Expand Down Expand Up @@ -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){
Expand All @@ -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);
}
}*/
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion scripts/scr_company_view/scr_company_view.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions scripts/scr_manage_task_selector/scr_manage_task_selector.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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){
Expand Down
9 changes: 9 additions & 0 deletions scripts/scr_marine_struct/scr_marine_struct.gml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading