diff --git a/code/citadel/custom_loadout/load_to_mob.dm b/code/citadel/custom_loadout/load_to_mob.dm index 830c1a4171..e0913cd383 100644 --- a/code/citadel/custom_loadout/load_to_mob.dm +++ b/code/citadel/custom_loadout/load_to_mob.dm @@ -9,10 +9,17 @@ /proc/handle_roundstart_items(mob/living/M) world << "handle_roundstart_items([M])" - if(!istype(M) || !M.ckey) - world << "handle_roundstart_items: [M] has no ckey." + if(!istype(M) || !M.ckey || !M.mind) + world << "handle_roundstart_items: [M] has either no ckey or no mind!" return FALSE - var/list/items = parse_custom_items_by_key(M.ckey) + var/list/items = parse_custom_items_by_key_and_job(M.ckey, M.mind.assigned_role) + if(M.mind.special_role) + var/list/items_special = parse_custom_items_by_key_and_job(M.ckey, M.mind.special_role) //And this way you can have snowflake antags! + for(var/thing in items_special) + if(!items[thing]) + items[thing] = items_special[thing] //don't have it, make it have it! + else + items[thing] += items_special[thing] //More~ if(isnull(items)) world << "handle_roundstart_items: itemlist null." return FALSE @@ -45,7 +52,8 @@ return FALSE var/turf/T = get_turf(H) for(var/item in itemlist) - var/path = text2path(item) + if(!ispath(item)) + item = text2path(item) if(!path) continue var/amount = itemlist[item] diff --git a/code/citadel/custom_loadout/read_from_file.dm b/code/citadel/custom_loadout/read_from_file.dm index 5c3f670762..dbca069cb7 100644 --- a/code/citadel/custom_loadout/read_from_file.dm +++ b/code/citadel/custom_loadout/read_from_file.dm @@ -1,67 +1,78 @@ -GLOBAL_LIST(custom_item_list) //Assoc list in form of ckey = delimited paramlist. +GLOBAL_LIST(custom_item_list) +//Layered list in form of custom_item_list[ckey][job][items][amounts] +//ckey is key, job is specific jobs, or "ALL" for all jobs, items for items, amounts for amount of item. -//File should be in the format of Ckey|things, where things is in the form of itempath1=amount;itempath2=amount;itempath3=amount -//Each ckey should be on a different line!! +//File should be in the format of ckey|exact job name/exact job name/or put ALL instead of any job names|/path/to/item=amount;/path/to/item=amount +//Each ckey should be in a different line +//if there's multiple entries of a single ckey the later ones will add to the earlier definitions. -/proc/reload_custom_item_list(custom_filelist) +/proc/reload_custom_roundstart_items_list(custom_filelist) if(!custom_filelist) - custom_filelist = "config/custom_items.txt" + custom_filelist = "config/custom_roundstart_items.txt" GLOB.custom_item_list = list() var/list/file_lines = world.file2list(custom_filelist) for(var/line in file_lines) - var/list/key_separation = splittext(line, "|") - if((!istype(key_separation))||(key_separation.len > 2)||(key_separation.len < 1)) - stack_trace("Warning: Roundstart items configuration file improperly formatted!") - continue - var/key = key_separation[1] - var/items = key_separation[2] - if(!key) - continue - if(!items) - GLOB.custom_item_list[key] = "ERROR" - continue - GLOB.custom_item_list[key] = list() - var/list/item_separation = splittext(items, ";") - if((!istype(item_separation))||(item_separation.len < 1)) - stack_trace("Warning: Roundstart items configuration file improperly formatted!") - continue - for(var/item_string in item_separation) - world << "itemstring [item_string]" - var/list/amount_separation = splittext(item_string, "=") - world << "separated [item_string] == [english_list(amount_separation)]" - if((!istype(amount_separation))||(amount_separation.len > 2)||(amount_separation.len < 1)) - stack_trace("Warning: Roundstart items configuration file improperly formatted!") + try //Lazy as fuck. + if(length(line) == 0) //Emptyline, no one cares. continue - var/path_to_item = amount_separation[1] - if(!ispath(text2path(path_to_item))) - GLOB.custom_item_list[key] += "ERROR" - var/amount_of_item = amount_separation[2] - if(!amount_of_item) - GLOB.custom_item_list[key][path_to_item] = "ERROR" - var/amount_of_item_num = 0 - if(isnum(amount_of_item)) - amount_of_item_num = amount_of_item - else - amount_of_item_num = text2num(amount_of_item) - if(!isnum(amount_of_item) || (amount_of_item < 1)) - GLOB.custom_item_list[key][path_to_item] = "ERROR" - GLOB.custom_item_list[key][path_to_item] = amount_of_item_num + if(copytext(line,1,3) == "//") //Commented line, ignore. + continue + var/ckey_str_sep = findtext(line, "|") //Process our stuff.. + var/job_str_sep = findtext(line, "|", ckey_str_sep+1) + var/item_str_sep = findtext(line, "|", job_str_sep+1) + var/ckey_str = ckey(copytext(line, 1, ckey_str_sep)) + var/job_str = copytext(line, ckey_str_sep+1, job_str_sep) + var/item_str = copytext(line, job_str_sep+1, item_str_sep) + world << "DEBUG: Line process: [line]" + world << "DEBUG: [ckey_str_sep], [job_str_sep], [item_str_sep], [ckey_str], [job_str], [item_str]." + if(!islist(GLOB.custom_item_list[ckey_str])) + GLOB.custom_item_list[ckey_str] = list() //Initialize list for this ckey if it isn't initialized.. + var/list/jobs = splittext(job_str, "/") + world << "DEBUG: Job string processed." + world << "DEBUG: JOBS: [english_list(jobs)]" + for(var/job in jobs) + if(!islist(GLOB.custom_item_list[ckey_str][job])) + GLOB.custom_item_list[ckey_str][job] = list() //Initialize item list for this job of this ckey if not already initialized. + var/list/item_strings = splittext(item_str, ";") //Get item strings in format of /path/to/item=amount + for(var/item_string in item_strings) + var/path_str_sep = findtext(item_string, "=") + var/path = copytext(item_string, 1, path_str_sep) //Path to spawn + var/amount = copytext(item_string, path_str_sep+1) //Amount to spawn + world << "DEBUG: Item string [item_string] processed" + path = text2path(path) + world << "DEBUG: [path_str_sep], [path], [amount]" + for(var/job in jobs) + if(GLOB.custom_item_list[ckey_str][job][path]) //Doesn't exist, make it exist! + GLOB.custom_item_list[ckey_str][job][path] = amount + else + GLOB.custom_item_list[ckey_str][job][path] += amount //Exists, we want more~ + catch //Uh oh. + var/msg = "Error processing line in [custom_filelist]. Line : [line]" + message_admins(msg) + log_game(msg) + stack_trace(msg) + continue return GLOB.custom_item_list -/proc/parse_custom_items_by_key(ckey) - world << "parse_custom_items_by_key([ckey])" +/proc/parse_custom_item_list_key_to_joblist(ckey) //First stage if(!ckey || !GLOB.custom_item_list[ckey]) - world << "parse_custom_items_by_key: no ckey match" return null - var/list/items = GLOB.custom_item_list[ckey] - for(var/I in items) - if(items[I] == "ERROR") - items -= I - continue - return items + return GLOB.custom_item_list[ckey] + +/proc/parse_custom_item_list_joblist_to_items(list, job) //Second stage + var/list/ret = list() + for(var/j in list) //for job in ckey-job-item list + if((j == job) || (j == "ALL") || (job == "ALL")) //job matches or is all jobs or we want everything. + for(var/i in list[j]) //for item in job-item list + if(!ret[i]) + ret[i] = list[j][i] //add to return with return value if not there + else + ret[i] += list[j][i] //else, add to that item in return value! + return ret //If done properly, you'll have a list of item typepaths with how many to spawn. + +/proc/parse_custom_items_by_key_and_job(ckey, job) + return parse_custom_item_list_joblist_to_items(parse_custom_item_list_key_to_joblist(ckey), job) /proc/debug_roundstart_items() - reload_custom_item_list() - for(var/mob/M in world) - handle_roundstart_items(M) + reload_custom_roundstart_items_list() diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index 5236cdbb03..6fd3969cd3 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -284,7 +284,6 @@ load("config/config.txt") load("config/game_options.txt","game_options") loadsql("config/dbconfig.txt") - reload_custom_item_list() if (maprotation) loadmaplist("config/maps.txt") diff --git a/config/custom_items.txt b/config/custom_items.txt deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/config/custom_roundstart_items.txt b/config/custom_roundstart_items.txt new file mode 100644 index 0000000000..227015e9e1 --- /dev/null +++ b/config/custom_roundstart_items.txt @@ -0,0 +1,8 @@ +//File should be in the format of ckey|exact job name/exact job name/or put ALL instead of any job names|/path/to/item=amount;/path/to/item=amount +//Each ckey should be in a different line +//if there's multiple entries of a single ckey the later ones will add to the earlier definitions. +//is obviously a comment. +//Recommend defining one job per line, but do what you want. +test1|testjob1/test job 2/ALL|/obj/item/weapon/gun/energy/laser=3;/obj/item/weapon/gun/energy/laser/retro=1;/obj/item/weapon/gun/energy=2 +test1|testjob1|/obj/item/device/aicard=3;/obj/item/device/flightpack=1;/obj/item/weapon/gun/energy=3 +