Skip to content

Commit 61e825f

Browse files
refactor: Thinking with refs
Broken
1 parent 0b938a8 commit 61e825f

7 files changed

Lines changed: 52 additions & 29 deletions

File tree

scripts/scr_add_man/scr_add_man.gml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ function scr_add_man(man_role, target_company, spawn_exp, spawn_name, corruption
250250
}
251251
}
252252
}
253-
struct_set(UUID_marine, unit.UUID, unit)
254-
obj_ini.TTRPG[target_company][good] = UUID_marine[$ unit.UUID];
253+
set_unit(unit.UUID, unit);
254+
obj_ini.TTRPG[target_company][good] = unit;
255255
unit.add_exp(spawn_exp);
256256
unit.allocate_unit_to_fresh_spawn(home_spot);
257257
unit.update_role(man_role);

scripts/scr_company_order/scr_company_order.gml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function temp_marine_variables(co, unit_num){
3636
array_push(temp_mobi,mobi[co][unit_num]);
3737
array_push(temp_spe,spe[co][unit_num]);
3838
array_push(temp_god,god[co][unit_num]);
39-
array_push(temp_UUID, TTRPG[co][unit_num].UUID);
39+
array_push(temp_struct, TTRPG[co][unit_num]);
4040
scr_wipe_unit(co,unit_num);
4141
}
4242
function sort_all_companies(){
@@ -74,7 +74,7 @@ function scr_company_order(company) {
7474
temp_age=[];
7575
temp_spe=[];
7676
temp_god=[];
77-
temp_UUID=[];
77+
temp_struct=[];
7878

7979

8080
/*takes a template of a role, required role number and if there are enough
@@ -328,6 +328,9 @@ function scr_company_order(company) {
328328

329329
// Return here
330330
for (i=0;i<array_length(temp_name);i++){
331+
unit = temp_struct[i];
332+
unit.company = co;
333+
unit.marine_number = i;
331334
race[co][i]=temp_race[i];
332335
loc[co][i]=temp_loc[i];
333336
name[co][i]=temp_name[i];
@@ -340,10 +343,7 @@ function scr_company_order(company) {
340343
age[co][i]=temp_age[i];
341344
spe[co][i]=temp_spe[i];
342345
god[co][i]=temp_god[i];
343-
obj_ini.TTRPG[co][i] = obj_ini.UUID_marine[$ temp_UUID[i]];
344-
unit = fetch_unit([co, i]);
345-
unit.company = co;
346-
unit.marine_number = i;
346+
obj_ini.TTRPG[co][i] = unit;
347347
unit.movement_after_math();
348348
}
349349
/* i=0;repeat(300){i+=1;

scripts/scr_initialize_custom/scr_initialize_custom.gml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,19 +3256,18 @@ function add_veh_to_company(name, company, slot, wep1, wep2, wep3, upgrade, acce
32563256
/// Use "" if you want to set weapons and gear via squad layouts.
32573257
/// "default" will set it to the value in the default slot for the given role, see `load_default_gear`
32583258
function add_unit_to_company(ttrpg_name, company, slot, role_name, role_id, wep1="default", wep2="default", gear="default", mobi="default", armour="default"){
3259-
var _marine_ttrpg = new TTRPG_stats("chapter", company, slot, ttrpg_name);
3260-
struct_set(INI_UUNITROOT, _marine_ttrpg.UUID, _marine_ttrpg)
3259+
var spawn_unit = new TTRPG_stats("chapter", company, slot, ttrpg_name);
3260+
set_unit(spawn_unit.UUID, spawn_unit);
32613261

32623262
// log_message($"adding unit to company ttrpg_name {ttrpg_name}, company {company}, slot {slot}, role_name {role_name}, role_id {role_id}")
3263-
obj_ini.TTRPG[company][slot] = obj_ini.UUID_marine[$ _marine_ttrpg.UUID];
3263+
obj_ini.TTRPG[company][slot] = spawn_unit;
32643264
obj_ini.race[company][slot] = 1;
32653265
obj_ini.loc[company][slot] = obj_ini.home_name;
32663266
obj_ini.role[company][slot] = role_name;
32673267

32683268
if(obj_ini.name[company][slot] == ""){
32693269
obj_ini.name[company][slot] = global.name_generator.generate_space_marine_name();
32703270
}
3271-
var spawn_unit = fetch_unit(_marine_ttrpg.UUID);
32723271

32733272
if(wep1 != ""){
32743273
if(wep1 == "default"){

scripts/scr_marine_struct/scr_marine_struct.gml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,26 @@ function fetch_unit(funit) {
22962296
if (!is_string(funit)) {
22972297
return obj_ini.TTRPG[funit[0]][funit[1]];
22982298
} else {
2299-
return INI_UUNITROOT[$ funit];
2299+
return struct_get(INI_UUNITROOT, funit);
23002300
}
23012301
}
2302+
2303+
/// @param {<String>} funit where unit is a hash of a UUID
2304+
/// @returns {Struct.TTRPG_stats} unit
2305+
function fetch_unit_from_hash(funit) {
2306+
gml_pragma("forceinline");
2307+
return struct_get_from_hash(INI_UUNITROOT, funit);
2308+
}
2309+
2310+
/// @param {<String>} funit where unit is a UUID
2311+
function set_unit(funit, fdata) {
2312+
gml_pragma("forceinline");
2313+
struct_set(INI_UUNITROOT, funit, fdata);
2314+
}
2315+
2316+
/// @param {<String>} funit where unit is a hash of a UUID
2317+
/// @param {<Any>} fdata data for variable
2318+
function set_unit_from_hash(funit, fdata) {
2319+
gml_pragma("forceinline");
2320+
struct_set_from_hash(INI_UUNITROOT, funit, fdata);
2321+
}

scripts/scr_move_unit_info/scr_move_unit_info.gml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ function scr_move_unit_info(start_company,end_company, start_slot, end_slot, eva
1919
obj_ini.god[end_company][end_slot]=obj_ini.god[start_company][start_slot];
2020
obj_ini.age[end_company][end_slot]=obj_ini.age[start_company][start_slot];
2121
obj_ini.mobi[end_company][end_slot]=obj_ini.mobi[start_company][start_slot];
22-
obj_ini.TTRPG[end_company][end_slot] = new TTRPG_stats("chapter", end_company, end_slot, "blank"); // create new empty unit structure
23-
obj_ini.TTRPG[end_company][end_slot] = obj_ini.TTRPG[start_company][start_slot]; //load in originoal marine data
22+
obj_ini.TTRPG[end_company][end_slot] = unit; //load in originoal marine data
2423
obj_ini.TTRPG[end_company][end_slot].company = end_company;
2524
obj_ini.TTRPG[end_company][end_slot].marine_number = end_slot;
2625

scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,28 @@ function merge_player_fleets(main_fleet, merge_fleet) {
122122
}
123123

124124
function move_ship_between_player_fleets(out_fleet, in_fleet, fUUID) {
125-
var fUUID_hash = variable_get_hash(fUUID);
125+
var _UUID_hash = variable_get_hash(fUUID);
126126
var _class = player_ships_class(fUUID);
127127
switch _class {
128128
case "capital":
129-
struct_set_from_hash(in_fleet.capital, _fUUID_hash, out_fleet.capital[$ fUUID]);
130-
in_fleet.capital_number--;
129+
struct_set_from_hash(in_fleet.capital, _UUID_hash, struct_get_from_hash(out_fleet.capital, _UUID_hash));
130+
in_fleet.capital_number++;
131131

132-
struct_remove_from_hash(out_fleet.capital, _fUUID_hash);
132+
struct_remove_from_hash(out_fleet.capital, _UUID_hash);
133133
out_fleet.capital_number--;
134134
break;
135135
case "frigate":
136-
struct_set_from_hash(in_fleet.frigate, _fUUID_hash, out_fleet.frigate[$ fUUID]);
137-
in_fleet.frigate_number--;
136+
struct_set_from_hash(in_fleet.frigate, _UUID_hash, struct_get_from_hash(out_fleet.frigate, _UUID_hash));
137+
in_fleet.frigate_number++;
138138

139-
struct_remove_from_hash(out_fleet.frigate, _fUUID_hash);
139+
struct_remove_from_hash(out_fleet.frigate, _UUID_hash);
140140
out_fleet.frigate_number--;
141141
break;
142142
case "escort":
143-
struct_set_from_hash(in_fleet.escort, _fUUID_hash, out_fleet.escort[$ fUUID]);
144-
in_fleet.escort_number--;
143+
struct_set_from_hash(in_fleet.escort, _UUID_hash, struct_get_from_hash(out_fleet.escort, _UUID_hash));
144+
in_fleet.escort_number++;
145145

146-
struct_remove_from_hash(out_fleet.escort, _fUUID_hash);
146+
struct_remove_from_hash(out_fleet.escort, _UUID_hash);
147147
out_fleet.escort_number--;
148148
break;
149149
}

scripts/scr_player_ship_functions/scr_player_ship_functions.gml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
#macro USHIPROOT UUID_ship
33
function fetch_ship(fUUID) {
44
gml_pragma("forceinline");
5-
return INI_USHIPROOT[$ fUUID];
5+
return struct_get(INI_USHIPROOT, fUUID);
6+
}
7+
8+
function fetch_ship_from_hash(fUUID_hash) {
9+
gml_pragma("forceinline");
10+
return struct_get_from_hash(INI_USHIPROOT, fUUID_hash);
611
}
712

813
function return_lost_ships_chance(){
@@ -262,7 +267,7 @@ function new_player_ship(type, start_loc = "home", new_name = "") {
262267
var _ship_UUIDs = struct_get_names(INI_USHIPROOT);
263268
var _ship_count = array_length(_ship_UUIDs);
264269
for (var i = 0; i < _ship_count; i++) {
265-
array_push(_ship_names, INI_USHIPROOT[$ _ship_UUIDs[i]].name)
270+
array_push(_ship_names, fetch_ship(_ship_UUIDs[i]).name);
266271
}
267272

268273
if (new_name != "") {
@@ -412,9 +417,9 @@ function new_player_ship(type, start_loc = "home", new_name = "") {
412417
}
413418
_ship.health.hp = _ship.health.maxhp;
414419

415-
struct_set(USHIPROOT, _ship.UUID, _ship)
420+
struct_set(USHIPROOT, _ship.UUID, _ship);
416421

417-
return INI_USHIPROOT[$ _ship.UUID];
422+
return _ship;
418423
}
419424

420425
function ship_class_name(UUID) {

0 commit comments

Comments
 (0)