Created
November 6, 2023 04:10
-
-
Save ilobmirt/ab47b7b092e1e303fc8081a8d2419e41 to your computer and use it in GitHub Desktop.
Mindustry Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#==================================================================================================# | |
#Unit_Factory_Partner.mlog | |
#------------------------- | |
#By Ilobmirt - 2023NOV05 | |
#Manage associates to get Items into storage unit. This is to make units remotely without conveyors | |
#==================================================================================================# | |
globals: | |
#Imports | |
# [-1|disabled] [0|copper] [1|lead] [2|metaglass] [3|graphite] [4|sand] [5|coal] | |
# [6|titanium] [7|thorium] [8|scrap] [9|silicon] [10|plastinium] [11|phase-fabric] | |
# [12|surge-alloy] [13|spore-pod] [14|blast-compound] [15|pyratite] [16|beryllium] [17|fissile-matter] | |
# [18|dormant-cyst] [19|tungsten] [20|carbide] [21|oxide] | |
set glob_imp1_id 9 | |
set glob_imp2_id 3 | |
set glob_imp3_id 6 | |
set glob_imp4_id 2 | |
set glob_imp5_id -1 | |
set glob_imp_needed -1 | |
set glob_exp_needed -1 | |
set glob_imp1_curr -1 | |
set glob_imp1_pct 0 | |
set glob_imp2_curr -1 | |
set glob_imp2_pct 0 | |
set glob_imp3_curr -1 | |
set glob_imp3_pct 0 | |
set glob_imp4_curr -1 | |
set glob_imp4_pct 0 | |
set glob_imp5_curr -1 | |
set glob_imp5_pct 0 | |
# Workload | |
set glob_workload_calc -1 | |
set glob_workload_max -1 | |
set glob_workload_pct -1 | |
#Partnership | |
set glob_partner_id -1 | |
set glob_associates_needed -1 | |
set glob_associates_checkin 0 | |
set glob_associates_missing 0 | |
set glob_associates_collaborating -1 | |
set glob_associates_max 8 | |
set glob_best_unit_type 22 | |
set glob_worst_unit_type 20 | |
# Message Block | |
set glob_type_message 137 | |
set glob_index_message -1 | |
set glob_link_message -1 | |
set glob_is_debug 0 | |
# Storage Block | |
# [94 | Container] [93| Vault] | |
set glob_type_storage 94 | |
set glob_index_storage -1 | |
set glob_link_storage -1 | |
#Function handling | |
set glob_in_var1 -1 | |
set glob_in_var2 -1 | |
set glob_in_var3 -1 | |
set glob_in_var4 -1 | |
set glob_ret_addr -1 | |
set glob_ret_val -1 | |
set glob_ret_val2 -1 | |
set glob_ret_val3 -1 | |
set glob_ret_val4 -1 | |
#Let's just jump over all the functions and get to the meat and potatoes of our program | |
jump init always | |
#==================================================================================================# | |
func_get_next_link: | |
set gnl_curr_index glob_in_var1 | |
set gnl_match_type glob_in_var2 | |
set glob_ret_val -1 | |
gnl_loop1: | |
op add gnl_curr_index gnl_curr_index 1 | |
jump end_get_next_link greaterThanEq gnl_curr_index @links | |
getlink gnl_curr_link gnl_curr_index | |
sensor gnl_curr_type gnl_curr_link @type | |
sensor gnl_curr_id gnl_curr_type @id | |
jump gnl_loop1 notEqual gnl_curr_id gnl_match_type | |
set glob_ret_val gnl_curr_index | |
end_get_next_link: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
# How many associates are actually needed for this workload? | |
func_workload: | |
op mul glob_associates_needed glob_workload_pct glob_associates_max | |
op div glob_associates_needed glob_associates_needed 100 | |
op ceil glob_associates_needed glob_associates_needed | |
end_workload: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
func_hmi: | |
print "UNIT FACTORY PARTNER:" | |
print "\n PARTNER ID: " | |
print glob_partner_id | |
jump hmi_yes_import notEqual glob_imp1_id -1 | |
jump hmi_yes_import notEqual glob_imp2_id -1 | |
jump hmi_yes_import notEqual glob_imp3_id -1 | |
jump hmi_yes_import notEqual glob_imp4_id -1 | |
jump hmi_yes_import notEqual glob_imp5_id -1 | |
jump hmi_no_import always | |
hmi_yes_import: | |
print "\n\n IMPORT MATERIALS: " | |
jump hmi_no_imp1 equal glob_imp1_id -1 | |
lookup item hmi_mat glob_imp1_id | |
print "\n " | |
print hmi_mat | |
print " [" | |
print glob_imp1_pct | |
print "%]" | |
hmi_no_imp1: | |
jump hmi_no_imp2 equal glob_imp2_id -1 | |
lookup item hmi_mat glob_imp2_id | |
print "\n " | |
print hmi_mat | |
print " [" | |
print glob_imp2_pct | |
print "%]" | |
hmi_no_imp2: | |
jump hmi_no_imp3 equal glob_imp3_id -1 | |
lookup item hmi_mat glob_imp3_id | |
print "\n " | |
print hmi_mat | |
print " [" | |
print glob_imp3_pct | |
print "%]" | |
hmi_no_imp3: | |
jump hmi_no_imp4 equal glob_imp4_id -1 | |
lookup item hmi_mat glob_imp4_id | |
print "\n " | |
print hmi_mat | |
print " [" | |
print glob_imp4_pct | |
print "%]" | |
hmi_no_imp4: | |
jump hmi_no_imp5 equal glob_imp5_id -1 | |
lookup item hmi_mat glob_imp5_id | |
print "\n " | |
print hmi_mat | |
print " [" | |
print glob_imp5_pct | |
print "%]" | |
hmi_no_imp5: | |
print "\n" | |
hmi_no_import: | |
print "\n # ASSOCIATES: " | |
print glob_associates_collaborating | |
print "\n WORKLOAD: " | |
print glob_workload_pct | |
print "%" | |
printflush glob_link_message | |
end_hmi: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#Partners are a random 12-bit id (1-4095) | |
func_generate_partner_id: | |
gpi_loop1: | |
op rand glob_partner_id 4095 | |
op idiv glob_partner_id glob_partner_id 1 | |
jump gpi_loop1 equal glob_partner_id 0 | |
end_generate_partner_id: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
# Generate a flag that would be set on the associate | |
# Partner id [12 bits] , Associate id [4 bits] , Step id [8 bits] , and Param id [8 bits] | |
func_gen_flag: | |
op shl glob_ret_val glob_in_var1 4 | |
op sub glob_in_var2 glob_in_var2 1 | |
op or glob_ret_val glob_ret_val glob_in_var2 | |
op shl glob_ret_val glob_ret_val 8 | |
op or glob_ret_val glob_ret_val glob_in_var3 | |
op shl glob_ret_val glob_ret_val 8 | |
op or glob_ret_val glob_ret_val glob_in_var4 | |
end_gen_flag: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
func_parse_flag: | |
# Parse information about a unit from the flag given | |
op and glob_ret_val4 glob_in_var1 255 | |
op shr glob_in_var1 glob_in_var1 8 | |
op and glob_ret_val3 glob_in_var1 255 | |
op shr glob_in_var1 glob_in_var1 8 | |
op and glob_ret_val2 glob_in_var1 15 | |
op add glob_ret_val2 glob_ret_val2 1 | |
op shr glob_ret_val glob_in_var1 4 | |
end_parse_flag: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#Sets the step of the current @unit | |
func_set_step: | |
op not sst_mask 65280 | |
op shl sst_step glob_in_var1 8 | |
sensor sst_flag @unit @flag | |
op and sst_flag sst_flag sst_mask | |
op or sst_flag sst_flag sst_step | |
ucontrol flag sst_flag | |
end_set_step: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#Set the param of current unit | |
func_set_param: | |
op not sp_mask 255 | |
set sp_param glob_in_var1 | |
sensor sp_flag @unit @flag | |
op and sp_flag sp_flag sp_mask | |
op or sp_flag sp_flag sp_param | |
ucontrol flag sp_flag | |
end_set_param: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
func_stat_material: | |
#Get the status of the material in the container | |
set glob_ret_val 0 | |
set glob_ret_val2 0 | |
jump end_stat_material lessThan glob_in_var1 0 | |
sensor sm_divisor glob_link_storage @itemCapacity | |
op idiv sm_divisor sm_divisor 100 | |
lookup item sm_mat glob_in_var1 | |
sensor glob_ret_val glob_link_storage sm_mat | |
op idiv glob_ret_val2 glob_ret_val sm_divisor | |
end_stat_material: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
func_stat_import_export: | |
set sie_caller_addr glob_ret_addr | |
set glob_workload_max 0 | |
set glob_workload_calc 0 | |
set sie_imp_least 999 | |
set sie_exp_most 0 | |
sensor sie_capacity glob_link_storage @itemCapacity | |
jump sie_no_imp1 lessThan glob_imp1_id 0 | |
set glob_in_var1 glob_imp1_id | |
op add glob_ret_addr @counter 1 | |
jump func_stat_material always | |
set glob_imp1_curr glob_ret_val | |
set glob_imp1_pct glob_ret_val2 | |
op add glob_workload_max glob_workload_max sie_capacity | |
op add glob_workload_calc glob_workload_calc sie_capacity | |
op sub glob_workload_calc glob_workload_calc glob_imp1_curr | |
jump sie_no_needed_imp1 greaterThan glob_imp1_curr sie_imp_least | |
set sie_imp_least glob_imp1_curr | |
set glob_imp_needed glob_imp1_id | |
sie_no_needed_imp1: | |
sie_no_imp1: | |
jump sie_no_imp2 lessThan glob_imp2_id 0 | |
set glob_in_var1 glob_imp2_id | |
op add glob_ret_addr @counter 1 | |
jump func_stat_material always | |
set glob_imp2_curr glob_ret_val | |
set glob_imp2_pct glob_ret_val2 | |
op add glob_workload_max glob_workload_max sie_capacity | |
op add glob_workload_calc glob_workload_calc sie_capacity | |
op sub glob_workload_calc glob_workload_calc glob_imp2_curr | |
jump sie_no_needed_imp2 greaterThan glob_imp2_curr sie_imp_least | |
set sie_imp_least glob_imp2_curr | |
set glob_imp_needed glob_imp2_id | |
sie_no_needed_imp2: | |
sie_no_imp2: | |
jump sie_no_imp3 lessThan glob_imp3_id 0 | |
set glob_in_var1 glob_imp3_id | |
op add glob_ret_addr @counter 1 | |
jump func_stat_material always | |
set glob_imp3_curr glob_ret_val | |
set glob_imp3_pct glob_ret_val2 | |
op add glob_workload_max glob_workload_max sie_capacity | |
op add glob_workload_calc glob_workload_calc sie_capacity | |
op sub glob_workload_calc glob_workload_calc glob_imp3_curr | |
jump sie_no_needed_imp3 greaterThan glob_imp3_curr sie_imp_least | |
set sie_imp_least glob_imp3_curr | |
set glob_imp_needed glob_imp3_id | |
sie_no_needed_imp3: | |
sie_no_imp3: | |
jump sie_no_imp4 lessThan glob_imp4_id 0 | |
set glob_in_var1 glob_imp4_id | |
op add glob_ret_addr @counter 1 | |
jump func_stat_material always | |
set glob_imp4_curr glob_ret_val | |
set glob_imp4_pct glob_ret_val2 | |
op add glob_workload_max glob_workload_max sie_capacity | |
op add glob_workload_calc glob_workload_calc sie_capacity | |
op sub glob_workload_calc glob_workload_calc glob_imp4_curr | |
jump sie_no_needed_imp4 greaterThan glob_imp4_curr sie_imp_least | |
set sie_imp_least glob_imp4_curr | |
set glob_imp_needed glob_imp4_id | |
sie_no_needed_imp4: | |
sie_no_imp4: | |
jump sie_no_imp5 lessThan glob_imp5_id 0 | |
set glob_in_var1 glob_imp5_id | |
op add glob_ret_addr @counter 1 | |
jump func_stat_material always | |
set glob_imp5_curr glob_ret_val | |
set glob_imp5_pct glob_ret_val2 | |
op add glob_workload_max glob_workload_max sie_capacity | |
op add glob_workload_calc glob_workload_calc sie_capacity | |
op sub glob_workload_calc glob_workload_calc glob_imp5_curr | |
jump sie_no_needed_imp5 greaterThan glob_imp5_curr sie_imp_least | |
set sie_imp_least glob_imp5_curr | |
set glob_imp_needed glob_imp5_id | |
sie_no_needed_imp5: | |
sie_no_imp5: | |
op div glob_workload_pct glob_workload_calc glob_workload_max | |
op mul glob_workload_pct glob_workload_pct 100 | |
op idiv glob_workload_pct glob_workload_pct 1 | |
end_stat_import_export: | |
set glob_ret_addr sie_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#Manages all the associates that could be possible in the game, calls a more refined unit type loop | |
func_associate_management: | |
set am_caller_addr glob_ret_addr | |
set am_loop_index glob_best_unit_type | |
#Reset our associate check in - They check in every cycle | |
set glob_associates_checkin 0 | |
#If we dont need anyone, why bother with the loop? | |
jump end_associate_loop equal glob_associates_collaborating 0 | |
am_loop1: | |
jump end_associate_loop lessThan am_loop_index glob_worst_unit_type | |
set glob_in_var1 am_loop_index | |
op add glob_ret_addr @counter 1 | |
jump function_unit_loop always | |
op sub am_loop_index am_loop_index 1 | |
jump am_loop1 always | |
end_associate_loop: | |
set glob_ret_addr am_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#calculate the missing associate mask from number being employed vs who checked in | |
func_calc_missing: | |
op pow cm_mask 2 glob_associates_collaborating | |
op sub cm_mask cm_mask 1 | |
op not cm_missing glob_associates_checkin | |
op and glob_associates_missing cm_missing cm_mask | |
end_calc_missing: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#Get biggest base 10 decimal from missing bitmask | |
func_top_missing: | |
set tm_index glob_associates_max | |
set glob_ret_val 0 | |
tm_loop1: | |
jump end_top_missing lessThan tm_index 1 | |
op sub tm_mask tm_index 1 | |
op pow tm_mask 2 tm_mask | |
op and tm_mask tm_mask glob_associates_missing | |
jump tm_sucess notEqual tm_mask 0 | |
op sub tm_index tm_index 1 | |
jump tm_loop1 always | |
tm_sucess: | |
set glob_ret_val tm_index | |
end_top_missing: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#Check an associate in by id - Turn on the respective bit based on associate number | |
func_checkin: | |
op sub ci_num glob_in_var1 1 | |
op pow ci_num 2 ci_num | |
op or glob_associates_checkin glob_associates_checkin ci_num | |
# When we check in, we are no longer considered missing | |
op not ci_num ci_num | |
op and glob_associates_missing glob_associates_missing ci_num | |
end_checkin: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#Manages all units of a certain type, checks in and does step cycles | |
function_unit_loop: | |
set ul_caller_addr glob_ret_addr | |
lookup unit ul_type glob_in_var1 | |
set ul_first_unit -1 | |
set ul_is_start_loop 0 | |
set ul_flag 0 | |
set ul_partner_id 0 | |
set ul_associate_id 0 | |
set ul_step_num 0 | |
set ul_param_num 0 | |
set ul_loop_counter 0 | |
ul_loop1: | |
ubind ul_type | |
jump end_unit_loop equal @unit null | |
jump ul_first_defined notEqual ul_first_unit -1 | |
set ul_first_unit @unit | |
set ul_is_start_loop 1 | |
ul_first_defined: | |
#Parse flag on device if any | |
sensor ul_flag @unit @flag | |
#We only manage our own | |
set glob_in_var1 ul_flag | |
op add glob_ret_addr @counter 1 | |
jump func_parse_flag always | |
set ul_partner_id glob_ret_val | |
set ul_associate_id glob_ret_val2 | |
set ul_step_num glob_ret_val3 | |
set ul_param_num glob_ret_val4 | |
#handle if related to us or not | |
jump ul_our_associate equal ul_partner_id glob_partner_id | |
jump ul_not_associated lessThanEq ul_partner_id 0 | |
jump ul_end_loop1 always | |
ul_our_associate: | |
#Checkin time | |
set glob_in_var1 ul_associate_id | |
op add glob_ret_addr @counter 1 | |
jump func_checkin always | |
#Let's do a step with this unit | |
set glob_in_var1 ul_associate_id | |
set glob_in_var2 ul_step_num | |
set glob_in_var3 ul_param_num | |
op add glob_ret_addr @counter 1 | |
jump func_step_engine always | |
jump ul_end_loop1 always | |
ul_not_associated: | |
#If we missed, or lost an associate, or even just waited for one to be added... | |
jump ul_end_loop1 equal glob_associates_missing 0 | |
#What's the ID of the associate to add? | |
op add glob_ret_addr @counter 1 | |
jump func_top_missing always | |
#Add the associate to our system | |
set glob_in_var1 glob_ret_val | |
op add glob_ret_addr @counter 1 | |
jump func_add_associate always | |
ul_end_loop1: | |
op add ul_loop_counter ul_loop_counter 1 | |
jump ul_loop1 notEqual @unit ul_first_unit | |
jump ul_loop1 equal ul_loop_counter 1 | |
end_unit_loop: | |
set glob_ret_addr ul_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
# This is the step engine, it handles the current @unit and makes it do a thing based on what | |
# Is going on with the unit | |
func_step_engine: | |
set se_caller_addr glob_ret_addr | |
set se_unit_id glob_in_var1 | |
set se_unit_step glob_in_var2 | |
set se_unit_param glob_in_var3 | |
jump se_no_debug equal glob_is_debug 0 | |
print " Associate " | |
print se_unit_id | |
print ": step " | |
print se_unit_step | |
print " param " | |
print se_unit_param | |
print "\n" | |
se_no_debug: | |
#STEP 0 - WHAT DO? New associates start here | |
jump se_no_step0 notEqual se_unit_step 0 | |
op add glob_ret_addr @counter 1 | |
jump func_step0 always | |
jump end_step_engine always | |
se_no_step0: | |
#STEP 1 - Move to HQ | |
jump se_no_step1 notEqual se_unit_step 1 | |
op add glob_ret_addr @counter 1 | |
jump func_step1 always | |
jump end_step_engine always | |
se_no_step1: | |
#STEP 2 - Move to the linked Container | |
jump se_no_step2 notEqual se_unit_step 2 | |
op add glob_ret_addr @counter 1 | |
jump func_step2 always | |
jump end_step_engine always | |
se_no_step2: | |
#STEP 3 - Pick up Item | |
jump se_no_step3 notEqual se_unit_step 3 | |
set glob_in_var1 se_unit_param | |
op add glob_ret_addr @counter 1 | |
jump func_step3 always | |
jump end_step_engine always | |
se_no_step3: | |
#STEP 4 - Drop off Item | |
jump se_no_step4 notEqual se_unit_step 4 | |
set glob_in_var1 se_unit_id | |
set glob_in_var2 se_unit_param | |
op add glob_ret_addr @counter 1 | |
jump func_step4 always | |
jump end_step_engine always | |
se_no_step4: | |
end_step_engine: | |
set glob_ret_addr se_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#STEP 0 - WHAT DO? | |
# ---> STEP 1 - Has item, but not wanted item / Has no item | |
# ---> STEP 2 - Has item that we want | |
func_step0: | |
set s0_caller_addr glob_ret_addr | |
#Get Item Type from unit, if holding anything | |
sensor s0_held_type @unit @firstItem | |
lookup item s0_imp_needed_type glob_imp_needed | |
jump s0_to_s2 equal s0_held_type s0_imp_needed_type | |
s0_to_s1: | |
set glob_in_var1 1 | |
jump s0_proceed always | |
s0_to_s2: | |
set glob_in_var1 2 | |
s0_proceed: | |
op add glob_ret_addr @counter 1 | |
jump func_set_step always | |
end_step0: | |
set glob_ret_addr s0_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#STEP 1 - Move to HQ | |
# ---> STEP 3 (Param 1) - If holding no items | |
# ---> STEP 4 (Param 1) - If holding items | |
func_step1: | |
set s1_caller_addr glob_ret_addr | |
#What's the range of this unit? | |
#sensor s1_range @unit @range | |
set s1_range 5 | |
#Get the location of HQ | |
ulocate building core false 0 s1_target_x s1_target_y s1_found s1_building | |
#Move to Building | |
ucontrol approach s1_target_x s1_target_y s1_range | |
#We wont proceed till we're in range | |
ucontrol within s1_target_x s1_target_y s1_range s1_in_range 0 | |
jump end_step1 equal s1_in_range 0 | |
#Got anything? | |
set s1_held_amount 0 | |
sensor s1_held_type @unit @firstItem | |
sensor s1_held_amount @unit s1_held_type | |
jump s1_to_s4 notEqual s1_held_amount 0 | |
s1_to_s3: | |
set glob_in_var1 3 | |
jump s1_proceed always | |
s1_to_s4: | |
set glob_in_var1 4 | |
s1_proceed: | |
op add glob_ret_addr @counter 1 | |
jump func_set_step always | |
set glob_in_var1 1 | |
op add glob_ret_addr @counter 1 | |
jump func_set_param always | |
end_step1: | |
set glob_ret_addr s1_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#STEP 2 - Move to linked Container | |
# ---> STEP 3 (Param 2) - If holding no items | |
# ---> STEP 4 (Param 2) - If holding items | |
func_step2: | |
set s2_caller_addr glob_ret_addr | |
#What's the range of this unit? | |
#sensor s2_range @unit @range | |
set s2_range 5 | |
#Get the location of container | |
sensor s2_target_x glob_link_storage @x | |
sensor s2_target_y glob_link_storage @y | |
#Move to Building | |
ucontrol approach s2_target_x s2_target_y s2_range | |
#We wont proceed till we're in range | |
ucontrol within s2_target_x s2_target_y s2_range s2_in_range 0 | |
jump end_step2 equal s2_in_range 0 | |
#Got anything? | |
set s2_held_amount 0 | |
sensor s2_held_type @unit @firstItem | |
sensor s2_held_amount @unit s2_held_type | |
jump s2_to_s4 notEqual s2_held_amount 0 | |
s2_to_s3: | |
set glob_in_var1 3 | |
jump s2_proceed always | |
s2_to_s4: | |
set glob_in_var1 4 | |
s2_proceed: | |
op add glob_ret_addr @counter 1 | |
jump func_set_step always | |
set glob_in_var1 2 | |
op add glob_ret_addr @counter 1 | |
jump func_set_param always | |
end_step2: | |
set glob_ret_addr s2_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#STEP 3 - Pick up item from location to unit (1 = Hq, 2 = Container) | |
# ---> STEP 1 - We were at place 2 (Container), and now need to move to place 1 (Hq) | |
# ---> STEP 2 - We were at place 1 (Hq), and now need to move to place 2 (Container) | |
func_step3: | |
set s3_caller_addr glob_ret_addr | |
set s3_unit_param glob_in_var1 | |
jump s3_at_container equal s3_unit_param 2 | |
jump s3_at_hq equal s3_unit_param 1 | |
jump end_step3 always | |
s3_at_hq: | |
ulocate building core false 0 s3_target_x s3_target_y s3_found s3_building | |
lookup item s3_pickup_type glob_imp_needed | |
set glob_in_var1 2 | |
op add glob_ret_addr @counter 1 | |
jump func_set_step always | |
jump s3_end_at_place always | |
s3_at_container: | |
set s3_building glob_link_storage | |
lookup item s3_pickup_type glob_exp_needed | |
set glob_in_var1 1 | |
op add glob_ret_addr @counter 1 | |
jump func_set_step always | |
s3_end_at_place: | |
jump s3_no_pickup equal s3_pickup_type null | |
sensor s3_held s3_building s3_pickup_type | |
jump s3_no_pickup equal s3_held 0 | |
sensor s3_load_max @unit @itemCapacity | |
op min s3_pick_amt s3_held s3_load_max | |
ucontrol itemTake s3_building s3_pickup_type s3_pick_amt | |
s3_no_pickup: | |
set glob_in_var1 0 | |
op add glob_ret_addr @counter 1 | |
jump func_set_param always | |
end_step3: | |
set glob_ret_addr s3_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#STEP 4 - Drop off item from unit to location (1 = Hq, 2 = Container) | |
# ---> LET GO - Needed Associates < Associate ID | |
# ---> STEP 3 - (Place 1- Needs Import, Place 2 - Needs Export) | |
func_step4: | |
set s4_caller_addr glob_ret_addr | |
set s4_unit_id glob_in_var1 | |
set s4_unit_param glob_in_var2 | |
jump s4_at_container equal s4_unit_param 2 | |
jump s4_at_hq equal s4_unit_param 1 | |
jump end_step4 always | |
s4_at_hq: | |
ulocate building core false 0 s4_target_x s4_target_y s4_found s4_building | |
jump s4_end_at_place always | |
s4_at_container: | |
set s4_building glob_link_storage | |
s4_end_at_place: | |
#Got anything? | |
set s4_held_amount 0 | |
sensor s4_held_type @unit @firstItem | |
sensor s4_held_amount @unit s4_held_type | |
jump s4_is_empty equal s4_held_amount 0 | |
#How about the building? | |
sensor s4_building_amt s4_building s4_held_type | |
sensor s4_building_max s4_building @itemCapacity | |
#So how much can we give? | |
op sub s4_can_give s4_building_max s4_building_amt | |
op min s4_can_give s4_can_give s4_held_amount | |
jump s4_plz_empty equal s4_can_give 0 | |
#Give the item to building | |
ucontrol itemDrop s4_building s4_can_give | |
#If not empty, destroy the rest | |
s4_plz_empty: | |
sensor s4_held_amount @unit s4_held_type | |
jump s4_is_empty equal s4_held_amount 0 | |
ucontrol itemDrop @air s4_held_amount | |
s4_is_empty: | |
#We definitely need to be empty to proceed | |
sensor s4_held_amount @unit s4_held_type | |
jump end_step4 greaterThan s4_held_amount 0 | |
#We either tell the associate to get some rest, or we ask them to keep working | |
jump s4_continue_working lessThanEq s4_unit_id glob_associates_needed | |
set glob_in_var1 s4_unit_id | |
op add glob_ret_addr @counter 1 | |
jump func_rem_associate always | |
jump end_step4 always | |
s4_continue_working: | |
set glob_in_var1 3 | |
op add glob_ret_addr @counter 1 | |
jump func_set_step always | |
end_step4: | |
set glob_ret_addr s4_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
func_add_associate: | |
set aa_caller_addr glob_ret_addr | |
set aa_associate_id glob_in_var1 | |
set aa_associate_flag -1 | |
#Set flag for associate | |
set glob_in_var1 glob_partner_id | |
set glob_in_var2 aa_associate_id | |
set glob_in_var3 0 | |
set glob_in_var4 0 | |
op add glob_ret_addr @counter 1 | |
jump func_gen_flag always | |
set aa_associate_flag glob_ret_val | |
ucontrol flag glob_ret_val | |
#Check in with the partner | |
set glob_in_var1 aa_associate_id | |
op add glob_ret_addr @counter 1 | |
jump func_checkin always | |
end_add_associate: | |
set glob_ret_addr aa_caller_addr | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
func_rem_associate: | |
set ra_associate_id glob_in_var1 | |
#Remove association flag | |
ucontrol flag 0 | |
#Take a chill pill, you did good, take a break | |
ucontrol idle | |
#Release to the wilds | |
ucontrol unbind | |
#And thus, let's show that we have one less associate collaborating | |
op sub glob_associates_collaborating glob_associates_collaborating 1 | |
end_rem_associate: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
func_unit_mats: | |
sensor um_conf_id factory1 @config | |
sensor um_conf_id um_conf_id @id | |
jump um_dagger equal um_conf_id 0 | |
jump um_nova equal um_conf_id 5 | |
jump um_crawler equal um_conf_id 10 | |
jump um_mono equal um_conf_id 20 | |
jump um_no_idea always | |
um_dagger: | |
set glob_imp5_id 1 | |
jump end_unit_mats always | |
um_crawler: | |
set glob_imp5_id 5 | |
jump end_unit_mats always | |
um_nova: | |
set glob_imp5_id 1 | |
jump end_unit_mats | |
um_mono: | |
set glob_imp5_id 1 | |
jump end_unit_mats always | |
um_no_idea: | |
set glob_imp5_id -1 | |
end_unit_mats: | |
set @counter glob_ret_addr | |
#==================================================================================================# | |
#The initialization of the software happens here | |
init: | |
#We need a partner id | |
op add glob_ret_addr @counter 1 | |
jump func_generate_partner_id always | |
#Lets get our linked objects | |
init_links: | |
set glob_in_var1 -1 | |
set glob_in_var2 glob_type_message | |
op add glob_ret_addr @counter 1 | |
jump func_get_next_link always | |
jump init_no_hmi equal glob_ret_val -1 | |
set glob_index_message glob_ret_val | |
getlink glob_link_message glob_index_message | |
init_no_hmi: | |
set glob_in_var1 -1 | |
set glob_in_var2 glob_type_storage | |
op add glob_ret_addr @counter 1 | |
jump func_get_next_link always | |
#We definitely need a container to link to | |
jump init_links equal glob_ret_val -1 | |
set glob_index_storage glob_ret_val | |
getlink glob_link_storage glob_index_storage | |
#==================================================================================================# | |
#The eternal main loop <3 | |
main_loop: | |
#Get our materials | |
op add glob_ret_addr @counter 1 | |
jump func_stat_import_export always | |
#Collaborate with associates | |
op add glob_ret_addr @counter 1 | |
jump func_associate_management always | |
#How many associates do we need? | |
op add glob_ret_addr @counter 1 | |
jump func_workload always | |
# Increase associates if we need to | |
jump main_no_increase_associates greaterThanEq glob_associates_collaborating glob_associates_needed | |
set glob_associates_collaborating glob_associates_needed | |
main_no_increase_associates: | |
# Who's missing? | |
op add glob_ret_addr @counter 1 | |
jump func_calc_missing always | |
#Configure our mats based on 1st tier unit config | |
op add glob_ret_addr @counter 1 | |
jump func_unit_mats always | |
# If we have an hmi, output state to it | |
jump main_loop equal glob_index_message -1 | |
op add glob_ret_addr @counter 1 | |
jump func_hmi always | |
jump main_loop always |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment