Merge pull request #5125 from GinjaNinja32/crew-monitor

Crew monitor
This commit is contained in:
Zuhayr
2014-06-03 20:26:04 +09:30
4 changed files with 102 additions and 43 deletions

View File

@@ -297,6 +297,31 @@ proc/listclearnulls(list/list)
return (result + R.Copy(Ri, 0))
// List of lists, sorts by element[key] - for things like crew monitoring computer sorting records by name.
/proc/sortByKey(var/list/L, var/key)
if(L.len < 2)
return L
var/middle = L.len / 2 + 1
return mergeKeyedLists(sortByKey(L.Copy(0, middle), key), sortByKey(L.Copy(middle), key), key)
/proc/mergeKeyedLists(var/list/L, var/list/R, var/key)
var/Li=1
var/Ri=1
var/list/result = new()
while(Li <= L.len && Ri <= R.len)
if(sorttext(L[Li][key], R[Ri][key]) < 1)
// Works around list += list2 merging lists; it's not pretty but it works
result += "temp item"
result[result.len] = R[Ri++]
else
result += "temp item"
result[result.len] = L[Li++]
if(Li <= L.len)
return (result + L.Copy(Li, 0))
return (result + R.Copy(Ri, 0))
//Mergesort: any value in a list, preserves key=value structure
/proc/sortAssoc(var/list/L)
if(L.len < 2)

View File

@@ -16,14 +16,14 @@
/obj/machinery/computer/crew/attack_ai(mob/user)
attack_hand(user)
interact(user)
ui_interact(user)
/obj/machinery/computer/crew/attack_hand(mob/user)
add_fingerprint(user)
if(stat & (BROKEN|NOPOWER))
return
interact(user)
ui_interact(user)
/obj/machinery/computer/crew/update_icon()
@@ -43,67 +43,68 @@
if(..()) return
if (src.z > 6)
usr << "\red <b>Unable to establish a connection</b>: \black You're too far away from the station!"
return
return 0
if( href_list["close"] )
usr << browse(null, "window=crewcomp")
var/mob/user = usr
var/datum/nanoui/ui = nanomanager.get_open_ui(user, src, "main")
usr.unset_machine()
return
ui.close()
return 0
if(href_list["update"])
src.updateDialog()
return
return 1
/obj/machinery/computer/crew/interact(mob/user)
ui_interact(user)
/obj/machinery/computer/crew/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null)
if(stat & (BROKEN|NOPOWER))
return
if(!istype(user, /mob/living/silicon) && get_dist(src, user) > 1)
user.unset_machine()
user << browse(null, "window=powcomp")
return
user.set_machine(src)
src.scan()
var/t = "<TT><B>Crew Monitoring</B><HR>"
t += "<BR><A href='?src=\ref[src];update=1'>Refresh</A> "
t += "<A href='?src=\ref[src];close=1'>Close</A><BR>"
t += "<table><tr><td width='40%'>Name</td><td width='20%'>Vitals</td><td width='40%'>Position</td></tr>"
var/list/logs = list()
var/data[0]
var/list/crewmembers = list()
for(var/obj/item/clothing/under/C in src.tracked)
var/log = ""
var/turf/pos = get_turf(C)
if((C) && (C.has_sensor) && (pos) && (pos.z == src.z) && C.sensor_mode)
if(istype(C.loc, /mob/living/carbon/human))
var/mob/living/carbon/human/H = C.loc
var/dam1 = round(H.getOxyLoss(),1)
var/dam2 = round(H.getToxLoss(),1)
var/dam3 = round(H.getFireLoss(),1)
var/dam4 = round(H.getBruteLoss(),1)
var/list/crewmemberData = list()
var/life_status = "[H.stat > 1 ? "<font color=red>Deceased</font>" : "Living"]"
var/damage_report = "(<font color='blue'>[dam1]</font>/<font color='green'>[dam2]</font>/<font color='orange'>[dam3]</font>/<font color='red'>[dam4]</font>)"
crewmemberData["sensor_type"] = C.sensor_mode
crewmemberData["dead"] = H.stat > 1
crewmemberData["oxy"] = round(H.getOxyLoss(), 1)
crewmemberData["tox"] = round(H.getToxLoss(), 1)
crewmemberData["fire"] = round(H.getFireLoss(), 1)
crewmemberData["brute"] = round(H.getBruteLoss(), 1)
crewmemberData["name"] = (H.wear_id ? H.wear_id.name : "Unknown")
crewmemberData["area"] = get_area(H)
crewmemberData["x"] = pos.x
crewmemberData["y"] = pos.y
if(H.wear_id)
log += "<tr><td width='40%'>[H.wear_id.name]</td>"
else
log += "<tr><td width='40%'>Unknown</td>"
// Works around list += list2 merging lists; it's not pretty but it works
crewmembers += "temporary item"
crewmembers[crewmembers.len] = crewmemberData
switch(C.sensor_mode)
if(1)
log += "<td width='15%'>[life_status]</td><td width='40%'>Not Available</td></tr>"
if(2)
log += "<td width='20%'>[life_status] [damage_report]</td><td width='40%'>Not Available</td></tr>"
if(3)
var/area/player_area = get_area(H)
log += "<td width='20%'>[life_status] [damage_report]</td><td width='40%'>[player_area.name] ([pos.x], [pos.y])</td></tr>"
logs += log
logs = sortList(logs)
for(var/log in logs)
t += log
t += "</table>"
t += "</FONT></PRE></TT>"
user << browse(t, "window=crewcomp;size=900x600")
onclose(user, "crewcomp")
crewmembers = sortByKey(crewmembers, "name")
data["crewmembers"] = crewmembers
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data)
if(!ui)
ui = new(user, src, ui_key, "crew_monitor.tmpl", "Crew Monitoring Computer", 900, 600)
ui.set_initial_data(data)
ui.open()
// should make the UI auto-update; doesn't seem to?
ui.set_auto_update(1)
/obj/machinery/computer/crew/proc/scan()