Merge pull request #2419 from Crazylemon64/sleeper_ui

Sleeper NanoUI
This commit is contained in:
Mark van Alphen
2015-10-28 02:43:39 +01:00
6 changed files with 388 additions and 124 deletions
+150 -124
View File
@@ -7,6 +7,8 @@
icon = 'icons/obj/Cryogenic2.dmi'
icon_state = "console"
var/obj/machinery/sleeper/connected = null
var/ui_title = "Sleeper"
anchored = 1 //About time someone fixed this.
density = 1
var/orient = "LEFT"
@@ -39,10 +41,6 @@
/obj/machinery/sleep_console/RefreshParts()
/obj/machinery/sleep_console/process()
if(stat & (NOPOWER|BROKEN))
return
src.updateUsrDialog()
return
/obj/machinery/sleep_console/ex_act(severity)
switch(severity)
@@ -116,88 +114,137 @@
findsleeper()
if (src.connected)
var/mob/living/occupant = src.connected.occupant
var/dat = "<font color='blue'><B>Occupant Statistics:</B></FONT><BR>"
if (occupant)
var/t1
switch(occupant.stat)
if(0)
t1 = "Conscious"
if(1)
t1 = "<font color='blue'>Unconscious</font>"
if(2)
t1 = "<font color='red'>*dead*</font>"
else
dat += text("[]\tHealth %: [] ([])</FONT><BR>", (occupant.health > 50 ? "<font color='blue'>" : "<font color='red'>"), occupant.health, t1)
if(iscarbon(occupant))
var/mob/living/carbon/C = occupant
dat += text("[]\t-Pulse, bpm: []</FONT><BR>", (C.pulse == PULSE_NONE || C.pulse == PULSE_THREADY ? "<font color='red'>" : "<font color='blue'>"), C.get_pulse(GETPULSE_TOOL))
dat += text("[]\t-Brute Damage %: []</FONT><BR>", (occupant.getBruteLoss() < 60 ? "<font color='blue'>" : "<font color='red'>"), occupant.getBruteLoss())
dat += text("[]\t-Respiratory Damage %: []</FONT><BR>", (occupant.getOxyLoss() < 60 ? "<font color='blue'>" : "<font color='red'>"), occupant.getOxyLoss())
dat += text("[]\t-Toxin Content %: []</FONT><BR>", (occupant.getToxLoss() < 60 ? "<font color='blue'>" : "<font color='red'>"), occupant.getToxLoss())
dat += text("[]\t-Burn Severity %: []</FONT><BR>", (occupant.getFireLoss() < 60 ? "<font color='blue'>" : "<font color='red'>"), occupant.getFireLoss())
dat += text("<HR>Paralysis Summary %: [] ([] seconds left!)<BR>", occupant.paralysis, round(occupant.paralysis / 4))
if(occupant.reagents)
for(var/chemical in connected.injection_chems)
var/datum/reagent/C = chemical_reagents_list[chemical]
dat += "[C.name]: [occupant.reagents.get_reagent_amount(chemical)] units<br>"
dat += "<A href='?src=\ref[src];refresh=1'>Refresh Meter Readings</A><BR>"
if(src.connected.beaker)
dat += "<HR><A href='?src=\ref[src];removebeaker=1'>Remove Beaker</A><BR>"
if(src.connected.filtering)
dat += "<A href='?src=\ref[src];togglefilter=1'>Stop Dialysis</A><BR>"
dat += text("Output Beaker has [] units of free space remaining<BR><HR>", src.connected.beaker.reagents.maximum_volume - src.connected.beaker.reagents.total_volume)
else
dat += "<HR><A href='?src=\ref[src];togglefilter=1'>Start Dialysis</A><BR>"
dat += text("Output Beaker has [] units of free space remaining<BR><HR>", src.connected.beaker.reagents.maximum_volume - src.connected.beaker.reagents.total_volume)
else
dat += "<HR>No Dialysis Output Beaker is present.<BR><HR>"
for(var/chemical in connected.injection_chems)
var/datum/reagent/C = chemical_reagents_list[chemical]
dat += "Inject [C.name]: "
for(var/amount in connected.amounts)
dat += "<a href ='?src=\ref[src];chemical=[chemical];amount=[amount]'>[amount] units</a><br> "
dat += "<HR><A href='?src=\ref[src];ejectify=1'>Eject Patient</A>"
else
dat += "The sleeper is empty."
dat += text("<BR><BR><A href='?src=\ref[];mach_close=sleeper'>Close</A>", user)
user << browse(dat, "window=sleeper;size=400x500")
onclose(user, "sleeper")
return
ui_interact(user)
/obj/machinery/sleep_console/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
var/data[0]
var/mob/living/carbon/human/occupant = connected.occupant
data["hasOccupant"] = occupant ? 1 : 0
var/occupantData[0]
var/crisis = 0
if (occupant)
occupantData["name"] = occupant.name
occupantData["stat"] = occupant.stat
occupantData["health"] = occupant.health
occupantData["maxHealth"] = occupant.maxHealth
occupantData["minHealth"] = config.health_threshold_dead
occupantData["bruteLoss"] = occupant.getBruteLoss()
occupantData["oxyLoss"] = occupant.getOxyLoss()
occupantData["toxLoss"] = occupant.getToxLoss()
occupantData["fireLoss"] = occupant.getFireLoss()
occupantData["paralysis"] = occupant.paralysis
occupantData["hasBlood"] = 0
occupantData["bodyTemperature"] = occupant.bodytemperature
occupantData["maxTemp"] = 1000 // If you get a burning vox armalis into the sleeper, congratulations
// Because we can put simple_animals in here, we need to do something tricky to get things working nice
occupantData["temperatureSuitability"] = 0 // 0 is the baseline
if (ishuman(occupant) && occupant.species)
// I wanna do something where the bar gets bluer as the temperature gets lower
// For now, I'll just use the standard format for the temperature status
var/datum/species/sp = occupant.species
if (occupant.bodytemperature < sp.cold_level_3)
occupantData["temperatureSuitability"] = -3
else if (occupant.bodytemperature < sp.cold_level_2)
occupantData["temperatureSuitability"] = -2
else if (occupant.bodytemperature < sp.cold_level_1)
occupantData["temperatureSuitability"] = -1
else if (occupant.bodytemperature > sp.heat_level_3)
occupantData["temperatureSuitability"] = 3
else if (occupant.bodytemperature > sp.heat_level_2)
occupantData["temperatureSuitability"] = 2
else if (occupant.bodytemperature > sp.heat_level_1)
occupantData["temperatureSuitability"] = 1
else if (istype(occupant, /mob/living/simple_animal))
var/mob/living/simple_animal/silly = occupant
if (silly.bodytemperature < silly.minbodytemp)
occupantData["temperatureSuitability"] = -3
else if (silly.bodytemperature > silly.maxbodytemp)
occupantData["temperatureSuitability"] = 3
// Blast you, imperial measurement system
occupantData["btCelsius"] = occupant.bodytemperature - T0C
occupantData["btFaren"] = ((occupant.bodytemperature - T0C) * (9.0/5.0))+ 32
crisis = (occupant.health < connected.min_health)
// I'm not sure WHY you'd want to put a simple_animal in a sleeper, but precedent is precedent
// Runtime is aptly named, isn't she?
if (ishuman(occupant) && occupant.vessel && !(occupant.species && occupant.species.flags & NO_BLOOD))
occupantData["pulse"] = occupant.get_pulse(GETPULSE_TOOL)
occupantData["hasBlood"] = 1
occupantData["bloodLevel"] = round(occupant.vessel.get_reagent_amount("blood"))
occupantData["bloodMax"] = occupant.max_blood
occupantData["bloodPercent"] = round(100*(occupant.vessel.get_reagent_amount("blood")/occupant.max_blood), 0.01)
data["occupant"] = occupantData
data["maxchem"] = connected.max_chem
data["minhealth"] = connected.min_health
data["dialysis"] = connected.filtering
if (connected.beaker)
data["isBeakerLoaded"] = 1
data["beakerFreeSpace"] = round(connected.beaker.reagents.maximum_volume - connected.beaker.reagents.total_volume)
var/chemicals[0]
for (var/re in connected.injection_chems)
var/datum/reagent/temp = chemical_reagents_list[re]
if(temp)
var/reagent_amount = 0
var/pretty_amount
var/injectable = occupant ? 1 : 0
var/overdosing = 0
var/caution = 0 // To make things clear that you're coming close to an overdose
if (crisis && !(temp.id in connected.emergency_chems))
injectable = 0
if (occupant && occupant.reagents)
reagent_amount = occupant.reagents.get_reagent_amount(temp.id)
// If they're mashing the highest concentration, they get one warning
if (temp.overdose_threshold && reagent_amount + 10 > temp.overdose_threshold)
caution = 1
if (temp.id in occupant.reagents.overdose_list())
overdosing = 1
// Because I don't know how to do this on the nano side
pretty_amount = round(reagent_amount, 0.05)
chemicals.Add(list(list("title" = temp.name, "id" = temp.id, "commands" = list("chemical" = temp.id), "occ_amount" = reagent_amount, "pretty_amount" = pretty_amount, "injectable" = injectable, "overdosing" = overdosing, "od_warning" = caution)))
data["chemicals"] = chemicals
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "sleeper.tmpl", ui_title, 550, 655)
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)
/obj/machinery/sleep_console/Topic(href, href_list)
if(!connected | usr == connected.occupant)
return 0
if(..())
return 1
if(panel_open)
usr << "<span class='notice'>Close the maintenance panel first.</span>"
return 1
return 0
if ((usr.contents.Find(src) || ((get_dist(src, usr) <= 1) && istype(src.loc, /turf))) || (istype(usr, /mob/living/silicon/ai)))
usr.set_machine(src)
if (href_list["chemical"])
if (src.connected)
if (src.connected.occupant)
if (src.connected.occupant.stat == DEAD)
usr << "\red \b This person has no life for to preserve anymore. Take them to a department capable of reanimating them."
else if(src.connected.occupant.health > src.connected.min_health || href_list["chemical"] == "epinephrine")
usr << "<span class='danger'>This person has no life for to preserve anymore. Take them to a department capable of reanimating them.</span>"
else if(src.connected.occupant.health > src.connected.min_health || (href_list["chemical"] in connected.emergency_chems))
src.connected.inject_chemical(usr,href_list["chemical"],text2num(href_list["amount"]))
else
usr << "\red \b This person is not in good enough condition for sleepers to be effective! Use another means of treatment, such as cryogenics!"
src.updateUsrDialog()
if (href_list["refresh"])
src.updateUsrDialog()
usr << "<span class='danger'>This person is not in good enough condition for sleepers to be effective! Use another means of treatment, such as cryogenics!</span>"
if (href_list["removebeaker"])
src.connected.remove_beaker()
src.updateUsrDialog()
if (href_list["togglefilter"])
src.connected.toggle_filter()
src.updateUsrDialog()
if (href_list["ejectify"])
src.connected.eject()
src.updateUsrDialog()
src.add_fingerprint(usr)
return
return 1
/////////////////////////////////////////
// THE SLEEPER ITSELF
@@ -216,24 +263,25 @@
list("epinephrine", "ether", "salbutamol", "styptic_powder", "oculine"),
list("epinephrine", "ether", "salbutamol", "styptic_powder", "oculine", "charcoal", "mutadone", "mannitol"),
list("epinephrine", "ether", "salbutamol", "styptic_powder", "oculine", "charcoal", "mutadone", "mannitol", "pen_acid", "omnizine"))
var/emergency_chems = list("epinephrine") // Desnowflaking
var/amounts = list(5, 10)
var/obj/item/weapon/reagent_containers/glass/beaker = null
var/filtering = 0
var/efficiency
var/max_chem
var/initial_bin_rating = 1
var/min_health = 25
var/min_health = -25
var/injection_chems = list()
idle_power_usage = 1250
active_power_usage = 2500
light_color = LIGHT_COLOR_CYAN
power_change()
..()
if(!(stat & (BROKEN|NOPOWER)))
set_light(2)
else
set_light(0)
/obj/machinery/sleeper/power_change()
..()
if(!(stat & (BROKEN|NOPOWER)))
set_light(2)
else
set_light(0)
/obj/machinery/sleeper/New()
..()
@@ -271,16 +319,20 @@
I += M.rating
injection_chems = possible_chems[I]
efficiency = E
max_chem = E * 20
min_health = -E * 25
/obj/machinery/sleeper/process()
if(filtering > 0)
if(beaker)
// To prevent runtimes from drawing blood from runtime, and to prevent getting IPC blood.
if(!istype(occupant) || !occupant.dna || (occupant.species && occupant.species.flags & NO_BLOOD))
filtering = 0
return
if(beaker.reagents.total_volume < beaker.reagents.maximum_volume)
src.occupant.vessel.trans_to(beaker, 1)
for(var/datum/reagent/x in src.occupant.reagents.reagent_list)
// world << "FILTERING CHEMS"
src.occupant.reagents.trans_to(beaker, 3)
src.occupant.vessel.trans_to(beaker, 1)
src.updateDialog()
@@ -306,11 +358,10 @@
beaker = G
G.forceMove(src)
user.visible_message("[user] adds \a [G] to \the [src]!", "You add \a [G] to \the [src]!")
src.updateUsrDialog()
return
else
user << "\red The sleeper has a beaker already."
user << "<span class='warning'>The sleeper has a beaker already.</span>"
return
if (istype(G, /obj/item/weapon/screwdriver))
@@ -342,12 +393,12 @@
if(istype(G, /obj/item/weapon/grab))
if(panel_open)
user << "\blue <b>Close the maintenance panel first.</b>"
user << "<span class='boldnotice'>Close the maintenance panel first.</span>"
return
if(!ismob(G:affecting))
return
if(src.occupant)
user << "\blue <B>The sleeper is already occupied!</B>"
user << "<span class='boldnotice'>The sleeper is already occupied!</span>"
return
for(var/mob/living/carbon/slime/M in range(1,G:affecting))
if(M.Victim == G:affecting)
@@ -358,7 +409,7 @@
if(do_after(user, 20, target = G:affecting))
if(src.occupant)
user << "\blue <B>The sleeper is already occupied!</B>"
user << "<span class='boldnotice'>The sleeper is already occupied!</span>"
return
if(!G || !G:affecting) return
var/mob/M = G:affecting
@@ -368,7 +419,7 @@
M.forceMove(src)
src.occupant = M
src.icon_state = "sleeper"
M << "\blue <b>You feel cool air surround you. You go numb as your senses turn inward.</b>"
M << "<span class='boldnotice'>You feel cool air surround you. You go numb as your senses turn inward.</span>"
src.add_fingerprint(user)
qdel(G)
@@ -412,6 +463,8 @@
go_out()
..(severity)
// ???
// This looks cool, although mildly broken, should it be included again?
/obj/machinery/sleeper/alter_health(mob/living/M as mob)
if (M.health > 0)
if (M.getOxyLoss() >= 10)
@@ -447,11 +500,14 @@
return
/obj/machinery/sleeper/proc/inject_chemical(mob/living/user as mob, chemical, amount)
if (!(chemical in injection_chems))
user << "<span class='notice'>The sleeper does not offer that chemical!</notice>"
return
if(src.occupant)
if(src.occupant.reagents)
if(src.occupant.reagents.get_reagent_amount(chemical) + amount <= 20 * efficiency)
if(src.occupant.reagents.get_reagent_amount(chemical) + amount <= max_chem)
src.occupant.reagents.add_reagent(chemical, amount)
user << "Occupant now has [src.occupant.reagents.get_reagent_amount(chemical)] units of [chemical] in his/her bloodstream."
return
else
user << "You can not inject any more of this chemical."
@@ -463,39 +519,9 @@
user << "There's no occupant in the sleeper!"
return
/obj/machinery/sleeper/proc/check(mob/living/user as mob)
if(src.occupant)
user << text("\blue <B>Occupant ([]) Statistics:</B>", src.occupant)
var/t1
switch(src.occupant.stat)
if(0.0)
t1 = "Conscious"
if(1.0)
t1 = "Unconscious"
if(2.0)
t1 = "*dead*"
else
user << text("[]\t Health %: [] ([])", (src.occupant.health > 50 ? "\blue " : "\red "), src.occupant.health, t1)
user << text("[]\t -Core Temperature: []&deg;C ([]&deg;F)</FONT><BR>", (src.occupant.bodytemperature > 50 ? "<font color='blue'>" : "<font color='red'>"), src.occupant.bodytemperature-T0C, src.occupant.bodytemperature*1.8-459.67)
user << text("[]\t -Brute Damage %: []", (src.occupant.getBruteLoss() < 60 ? "\blue " : "\red "), src.occupant.getBruteLoss())
user << text("[]\t -Respiratory Damage %: []", (src.occupant.getOxyLoss() < 60 ? "\blue " : "\red "), src.occupant.getOxyLoss())
user << text("[]\t -Toxin Content %: []", (src.occupant.getToxLoss() < 60 ? "\blue " : "\red "), src.occupant.getToxLoss())
user << text("[]\t -Burn Severity %: []", (src.occupant.getFireLoss() < 60 ? "\blue " : "\red "), src.occupant.getFireLoss())
user << "\blue Expected time till occupant can safely awake: (note: If health is below 20% these times are inaccurate)"
user << text("\blue \t [] second\s (if around 1 or 2 the sleeper is keeping them asleep.)", src.occupant.paralysis / 5)
if(src.beaker)
user << text("\blue \t Dialysis Output Beaker has [] of free space remaining.", src.beaker.reagents.maximum_volume - src.beaker.reagents.total_volume)
else
user << "\blue No Dialysis Output Beaker loaded."
else
user << "\blue There is no one inside!"
return
/obj/machinery/sleeper/verb/eject()
set name = "Eject Sleeper"
set category = null
set category = "Object"
set src in oview(1)
if(usr.stat != 0)
return
@@ -506,7 +532,7 @@
/obj/machinery/sleeper/verb/remove_beaker()
set name = "Remove Beaker"
set category = null
set category = "Object"
set src in oview(1)
if(usr.stat != 0)
return
@@ -520,7 +546,7 @@
/obj/machinery/sleeper/MouseDrop_T(atom/movable/O as mob|obj, mob/user as mob)
if(O.loc == user) //no you can't pull things out of your ass
return
if(user.restrained() || user.stat || user.weakened || user.stunned || user.paralysis || user.resting) //are you cuffed, dying, lying, stunned or other
if(user.incapacitated()) //are you cuffed, dying, lying, stunned or other
return
if(get_dist(user, src) > 1 || get_dist(user, O) > 1 || user.contents.Find(src)) // is the mob anchored, too far away from you, or are you too far away from the source
return
@@ -535,10 +561,10 @@
if(!istype(user.loc, /turf) || !istype(O.loc, /turf)) // are you in a container/closet/pod/etc?
return
if(panel_open)
user << "\blue <B>Close the maintenance panel first.</B>"
user << "<span class='boldnotice'>Close the maintenance panel first.</span>"
return
if(occupant)
user << "\blue <B>The sleeper is already occupied!</B>"
user << "<span class='boldnotice'>The sleeper is already occupied!</span>"
return
/* if(isrobot(user))
if(!istype(user:module, /obj/item/weapon/robot_module/medical))
@@ -548,7 +574,7 @@
if(!istype(L) || L.buckled)
return
if(L.abiotic())
user << "\blue <B>Subject cannot have abiotic items on.</B>"
user << "<span class='boldnotice'>Subject cannot have abiotic items on.</span>"
return
for(var/mob/living/carbon/slime/M in range(1,L))
if(M.Victim == L)
@@ -561,7 +587,7 @@
if(do_after(user, 20, target = L))
if(src.occupant)
user << "\blue <B>The sleeper is already occupied!</B>"
user << "<span class='boldnotice'>>The sleeper is already occupied!</span>"
return
if(!L) return
@@ -571,7 +597,7 @@
L.forceMove(src)
src.occupant = L
src.icon_state = "sleeper"
L << "\blue <b>You feel cool air surround you. You go numb as your senses turn inward.</b>"
L << "<span class='boldnotice'>You feel cool air surround you. You go numb as your senses turn inward.</span>"
src.add_fingerprint(user)
if(user.pulling == L)
user.pulling = null
@@ -583,15 +609,15 @@
/obj/machinery/sleeper/verb/move_inside()
set name = "Enter Sleeper"
set category = null
set category = "Object"
set src in oview(1)
if(usr.stat != 0 || !(ishuman(usr)))
return
if(src.occupant)
usr << "\blue <B>The sleeper is already occupied!</B>"
usr << "<span class='boldnotice'>The sleeper is already occupied!</span>"
return
if (panel_open)
usr << "\blue <B>Close the maintenance panel first.</B>"
usr << "<span class='boldnotice'>Close the maintenance panel first.</span>"
return
if(usr.restrained() || usr.stat || usr.weakened || usr.stunned || usr.paralysis || usr.resting) //are you cuffed, dying, lying, stunned or other
return
@@ -602,7 +628,7 @@
visible_message("[usr] starts climbing into the sleeper.")
if(do_after(usr, 20, target = usr))
if(src.occupant)
usr << "\blue <B>The sleeper is already occupied!</B>"
usr << "<span class='boldnotice'>The sleeper is already occupied!</span>"
return
usr.stop_pulling()
usr.client.perspective = EYE_PERSPECTIVE
@@ -73,6 +73,7 @@
var/mob/remoteview_target = null
var/meatleft = 3 //For chef item
var/decaylevel = 0 // For rotting bodies
var/max_blood = 560 // For stuff in the vessel
var/slime_color = "blue" //For slime people this defines their color, it's blue by default to pay tribute to the old icons
var/check_mutations=0 // Check mutations on next life tick
@@ -98,6 +98,9 @@ About the Holder:
Returns the amount of the matching reagent inside the
holder. Returns 0 if the reagent is missing.
overdose_list()
Returns a list of all the chemical IDs in the reagent holder that are overdosing
Important variables:
total_volume
@@ -82,6 +82,14 @@ datum/reagents/proc/metabolize(var/mob/M)
addiction_tick++
update_total()
/datum/reagents/proc/overdose_list()
var/od_chems[0]
for(var/datum/reagent/R in reagent_list)
if(R.overdosed)
od_chems.Add(R.id)
return od_chems
datum/reagents/proc/reagent_on_tick()
for(var/datum/reagent/R in reagent_list)
R.on_tick()