From 8fcc1d4e2d7a5493cbf97e1e975b4c9fa442f88c Mon Sep 17 00:00:00 2001 From: AnturK Date: Wed, 11 Dec 2019 12:16:55 +0100 Subject: [PATCH] Cleans up round end json (#48188) * Cleans up round end json * lefotver comment --- code/__HELPERS/roundend.dm | 106 +++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/code/__HELPERS/roundend.dm b/code/__HELPERS/roundend.dm index 2656df9d14d..710cda4e2e8 100644 --- a/code/__HELPERS/roundend.dm +++ b/code/__HELPERS/roundend.dm @@ -6,73 +6,85 @@ gather_antag_data() record_nuke_disk_location() var/json_file = file("[GLOB.log_directory]/round_end_data.json") + // All but npcs sublists and ghost category contain only mobs with minds var/list/file_data = list("escapees" = list("humans" = list(), "silicons" = list(), "others" = list(), "npcs" = list()), "abandoned" = list("humans" = list(), "silicons" = list(), "others" = list(), "npcs" = list()), "ghosts" = list(), "additional data" = list()) - var/num_survivors = 0 - var/num_escapees = 0 - var/num_shuttle_escapees = 0 + var/num_survivors = 0 //Count of non-brain non-camera mobs with mind that are alive + var/num_escapees = 0 //Above and on centcom z + var/num_shuttle_escapees = 0 //Above and on escape shuttle var/list/area/shuttle_areas if(SSshuttle && SSshuttle.emergency) shuttle_areas = SSshuttle.emergency.shuttle_areas - for(var/mob/m in GLOB.mob_list) - var/escaped - var/category + + for(var/mob/M in GLOB.mob_list) var/list/mob_data = list() - if(isnewplayer(m)) + if(isnewplayer(M)) continue - if(m.mind) - if(m.stat != DEAD && !isbrain(m) && !iscameramob(m)) + + var/escape_status = "abandoned" //default to abandoned + var/category = "npcs" //Default to simple count only bracket + var/count_only = TRUE //Count by name only or full info + + mob_data["name"] = M.name + if(M.mind) + count_only = FALSE + mob_data["ckey"] = M.mind.key + if(M.stat != DEAD && !isbrain(M) && !iscameramob(M)) num_survivors++ - mob_data += list("name" = m.name, "ckey" = ckey(m.mind.key)) - if(isobserver(m)) - escaped = "ghosts" - else if(isliving(m)) - var/mob/living/L = m - mob_data += list("location" = get_area(L), "health" = L.health) + if(EMERGENCY_ESCAPED_OR_ENDGAMED && (M.onCentCom() || M.onSyndieBase())) + num_escapees++ + escape_status = "escapees" + if(shuttle_areas[get_area(M)]) + num_shuttle_escapees++ + if(isliving(M)) + var/mob/living/L = M + mob_data["location"] = get_area(L) + mob_data["health"] = L.health if(ishuman(L)) var/mob/living/carbon/human/H = L category = "humans" - mob_data += list("job" = H.mind.assigned_role, "species" = H.dna.species.name) + if(H.mind) + mob_data["job"] = H.mind.assigned_role + else + mob_data["job"] = "Unknown" + mob_data["species"] = H.dna.species.name else if(issilicon(L)) category = "silicons" if(isAI(L)) - mob_data += list("module" = "AI") - if(isAI(L)) - mob_data += list("module" = "pAI") - if(iscyborg(L)) + mob_data["module"] = "AI" + else if(ispAI(L)) + mob_data["module"] = "pAI" + else if(iscyborg(L)) var/mob/living/silicon/robot/R = L - mob_data += list("module" = R.module) - else - category = "others" - mob_data += list("typepath" = m.type) - if(!escaped) - if(EMERGENCY_ESCAPED_OR_ENDGAMED && (m.onCentCom() || m.onSyndieBase())) - escaped = "escapees" - num_escapees++ - if(shuttle_areas[get_area(m)]) - num_shuttle_escapees++ - else - escaped = "abandoned" - if(!m.mind && (!ishuman(m) || !issilicon(m))) - var/list/npc_nest = file_data["[escaped]"]["npcs"] - if(npc_nest.Find(initial(m.name))) - file_data["[escaped]"]["npcs"]["[initial(m.name)]"] += 1 - else - file_data["[escaped]"]["npcs"]["[initial(m.name)]"] = 1 - else - if(isobserver(m)) - var/pos = length(file_data["[escaped]"]) + 1 - file_data["[escaped]"]["[pos]"] = mob_data - else - if(!category) + mob_data["module"] = R.module.name + else category = "others" - mob_data += list("name" = m.name, "typepath" = m.type) - var/pos = length(file_data["[escaped]"]["[category]"]) + 1 - file_data["[escaped]"]["[category]"]["[pos]"] = mob_data + mob_data["typepath"] = M.type + //Ghosts don't care about minds, we want to retain ckey data etc + if(isobserver(M)) + count_only = FALSE + escape_status = "ghosts" + category = length(file_data["ghosts"]) + 1 + //All other mindless stuff just gets counts by name + if(count_only) + var/list/npc_nest = file_data["[escape_status]"]["npcs"] + var/name_to_use = initial(M.name) + if(ishuman(M)) + name_to_use = "Unknown Human" //Monkeymen and other mindless corpses + if(npc_nest.Find(name_to_use)) + file_data["[escape_status]"]["npcs"][name_to_use] += 1 + else + file_data["[escape_status]"]["npcs"][name_to_use] = 1 + else + //Mobs with minds and ghosts get detailed data + var/pos = length(file_data["[escape_status]"]["[category]"]) + 1 + file_data["[escape_status]"]["[category]"]["[pos]"] = mob_data + var/datum/station_state/end_state = new /datum/station_state() end_state.count() var/station_integrity = min(PERCENT(GLOB.start_state.score(end_state)), 100) file_data["additional data"]["station integrity"] = station_integrity WRITE_FILE(json_file, json_encode(file_data)) + SSblackbox.record_feedback("nested tally", "round_end_stats", num_survivors, list("survivors", "total")) SSblackbox.record_feedback("nested tally", "round_end_stats", num_escapees, list("escapees", "total")) SSblackbox.record_feedback("nested tally", "round_end_stats", GLOB.joined_player_list.len, list("players", "total"))