From 9e0866871ed3baa943dca981a5a27cb10e330df3 Mon Sep 17 00:00:00 2001 From: kevinz000 Date: Sat, 13 May 2017 11:26:07 -0700 Subject: [PATCH] lists and stuff --- code/citadel/custom_loadout/load_to_mob.dm | 8 +++ code/citadel/custom_loadout/read_from_file.dm | 50 +++++++++++++++++++ config/custom_items.txt | 0 tgstation.dme | 1 + 4 files changed, 59 insertions(+) create mode 100644 code/citadel/custom_loadout/read_from_file.dm create mode 100644 config/custom_items.txt diff --git a/code/citadel/custom_loadout/load_to_mob.dm b/code/citadel/custom_loadout/load_to_mob.dm index 654784bcb2..e8cde02cd0 100644 --- a/code/citadel/custom_loadout/load_to_mob.dm +++ b/code/citadel/custom_loadout/load_to_mob.dm @@ -7,6 +7,14 @@ #define DROP_TO_FLOOR 0 #define LOADING_TO_HUMAN 1 +/proc/handle_roundstart_items(mob/living/M) + if(!M.ckey || !istype(M)) + return FALSE + var/list/items = parse_custom_items_by_key(M.ckey) + if(isnull(items)) + return FALSE + load_itemlist_to_mob(M, items, TRUE, TRUE, FALSE) + //Just incase there's extra mob selections in the future..... /proc/load_itemlist_to_mob(mob/living/L, list/itemlist, drop_on_floor_if_full = TRUE, load_to_all_slots = TRUE, replace_slots = FALSE) if(!istype(L) || !islist(itemlist)) diff --git a/code/citadel/custom_loadout/read_from_file.dm b/code/citadel/custom_loadout/read_from_file.dm new file mode 100644 index 0000000000..97b621902e --- /dev/null +++ b/code/citadel/custom_loadout/read_from_file.dm @@ -0,0 +1,50 @@ + +#define CUSTOM_ITEM_LIST_FILE 'config/custom_items.txt' +GLOBAL_LIST(custom_item_list) //Assoc list in form of ckey = delimited paramlist. + +//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!! + +/proc/reload_custom_item_list(custom_filelist) + if(!custom_filelist) + custom_filelist = CUSTOM_ITEM_LIST_FILE + 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, "|") + 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, ";") + for(var/item_string in item_separation) + var/list/amount_separation = splittext(item_string, "=") + var/path_to_item = amount_separation[1] + if(!ispath(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 + return GLOB.custom_item_list + +/proc/parse_custom_items_by_key(ckey) + if(!ckey || !GLOB.custom_item_list[ckey]) + return null + var/list/items = GLOB.custom_item_list[ckey] + for(var/I in items) + if(items[I] == "ERROR") + items -= I + continue + return items diff --git a/config/custom_items.txt b/config/custom_items.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tgstation.dme b/tgstation.dme index 8f2d06c029..3a36f5cede 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -169,6 +169,7 @@ #include "code\citadel\dogborgstuff.dm" #include "code\citadel\custom_loadout\custom_items.dm" #include "code\citadel\custom_loadout\load_to_mob.dm" +#include "code\citadel\custom_loadout\read_from_file.dm" #include "code\citadel\organs\breasts.dm" #include "code\citadel\organs\eggsack.dm" #include "code\citadel\organs\genitals.dm"