Datum-based huds! Lays down the framework not only for data huds but also for antag huds.

This commit is contained in:
tkdrg
2014-11-17 19:38:29 -03:00
parent e9ec8645bb
commit fae2ffc3ee
11 changed files with 113 additions and 157 deletions
-6
View File
@@ -54,12 +54,6 @@
//data HUD (medhud, sechud) defines
//Don't forget to update human/New() if you change these!
#define DATA_HUD_SECURITY 1
#define DATA_HUD_MEDICAL 2
#define DATA_HUD_BASIC 1
#define DATA_HUD_ADVANCED 2
#define DATA_HUD_SECURITY_BASIC 1
#define DATA_HUD_SECURITY_ADVANCED 2
#define DATA_HUD_MEDICAL_BASIC 3
+3 -1
View File
@@ -22,7 +22,9 @@
#define BORGTHERM 2
#define BORGXRAY 4
// for secHUDs and medHUDs and variants. The number is the location of the image on the list hud_list of humans.
// for secHUDs and medHUDs and variants. The number is the location of the image on the list hud_list
// note: if you add more HUDs, even for non-human atoms, make sure to use unique numbers for the defines!
// /datum/hud expects these to be unique
#define HEALTH_HUD 1 // dead, alive, sick, health status
#define STATUS_HUD 2 // a simple line rounding the mob's number health
#define ID_HUD 3 // the job asigned to your ID
+51
View File
@@ -0,0 +1,51 @@
/* HUD DATUMS */
var/datum/hud/huds = list( \
DATA_HUD_SECURITY_BASIC = new/datum/hud/data/security/basic(), \
DATA_HUD_SECURITY_ADVANCED = new/datum/hud/data/security/advanced(), \
DATA_HUD_MEDICAL_BASIC = new/datum/hud/data/medical/basic(), \
DATA_HUD_MEDICAL_ADVANCED = new/datum/hud/data/medical/advanced() \
)
/atom/proc/add_to_all_huds()
for(var/datum/hud/hud in huds) hud.add_to_hud(src)
/atom/proc/remove_from_all_huds()
for(var/datum/hud/hud in huds) hud.remove_from_hud(src)
/datum/hud
var/list/atom/hudatoms = list() //list of all atoms which display this hud
var/list/mob/hudusers = list() //list with all mobs who can see the hud
var/list/hud_icons = list() //these will be the indexes for the atom's hud_list
/datum/hud/proc/remove_hud_from(var/mob/M)
for(var/atom/A in hudatoms)
remove_from_single_hud(M, A)
hudusers -= M
/datum/hud/proc/remove_from_hud(var/atom/A)
for(var/mob/M in hudusers)
remove_from_single_hud(M, A)
hudatoms -= A
/datum/hud/proc/remove_from_single_hud(var/mob/M, var/atom/A) //unsafe, no sanity apart from client
if(!M.client)
return
for(var/i in hud_icons)
M.client.images -= A.hud_list[i]
/datum/hud/proc/add_hud_to(var/mob/M)
hudusers |= M
for(var/atom/A in hudatoms)
add_to_single_hud(M, A)
/datum/hud/proc/add_to_hud(var/atom/A)
hudatoms |= A
for(var/mob/M in hudusers)
add_to_single_hud(M, A)
/datum/hud/proc/add_to_single_hud(var/mob/M, var/atom/A) //unsafe, no sanity apart from client
if(!M.client)
return
for(var/i in hud_icons)
M.client.images |= A.hud_list[i]
+26 -128
View File
@@ -1,136 +1,35 @@
/*
/*
* Data HUDs are now passive in order to reduce lag.
* Add then to a mob using add_data_hud.
* Update them when needed with the appropriate proc. (see below)
*/
/* HUD DATUMS */
var/datum/hud/huds = list( \
DATA_HUD_SECURITY_BASIC = new/datum/hud/data/security/basic(), \
DATA_HUD_SECURITY_ADVANCED = new/datum/hud/data/security/advanced(), \
DATA_HUD_MEDICAL_BASIC = new/datum/hud/data/medical/basic(), \
DATA_HUD_MEDICAL_ADVANCED = new/datum/hud/data/medical/advanced() \
)
/atom/proc/add_to_all_huds()
for(var/datum/hud/hud in huds) hud.add_to_hud(src)
/atom/proc/remove_from_all_huds()
for(var/datum/hud/hud in huds) hud.remove_from_hud(src)
//this is ugly
//don't use these if you don't need to
/proc/get_data_hud_datum(hud_type, hud_level)
var/myhud = 0
switch(hud_type)
if(DATA_HUD_SECURITY)
switch(hud_level)
if(DATA_HUD_BASIC)
myhud = DATA_HUD_SECURITY_BASIC
if(DATA_HUD_ADVANCED)
myhud = DATA_HUD_SECURITY_ADVANCED
if(DATA_HUD_MEDICAL)
switch(hud_level)
if(DATA_HUD_BASIC)
myhud = DATA_HUD_MEDICAL_BASIC
if(DATA_HUD_ADVANCED)
myhud = DATA_HUD_MEDICAL_ADVANCED
return myhud
/mob/proc/access_data_hud(hud_type, hud_level)
var/myhud = get_data_hud_datum(hud_type, hud_level)
if(myhud)
var/datum/hud/data/H = huds[myhud]
H.add_hud_to(src)
/mob/proc/reset_data_hud(hud_type, hud_level)
var/myhud = get_data_hud_datum(hud_type, hud_level)
if(myhud)
var/datum/hud/data/H = huds[myhud]
H.remove_hud_from(src)
/datum/hud
var/list/image/hudimages = list() //list of all hud image overlays
var/list/mob/hudusers = list() //list with all mobs who can see the hud
var/hud_type = 0 //hud_list[hud_type] will have icons to be shown. see __DEFINES/misc.dm for a list of the available types
var/list/hud_icons = list() //these will be the indexes for hud_list[hud_type][]
/datum/hud/proc/remove_hud_from(var/mob/M)
if(!M.client)
return
M.client.images -= hudimages
hudusers -= M
/datum/hud/proc/remove_from_hud(var/atom/A)
for(var/image/I in hudimages)
if(I.loc == A)
hudimages -= I
for(var/mob/M in hudusers)
M.client.images -= I
/datum/hud/proc/remove_from_single_hud(var/mob/M, var/atom/A)
if(!M.client || !(hud_type in A.hud_list) || !(M in hudusers))
return
for(var/icontype in hud_icons)
M.client.images -= A.hud_list[hud_type][hud_icons]
/datum/hud/proc/add_hud_to(var/mob/M)
if(!M.client)
return
hudusers |= M
add_images_to(M)
/datum/hud/proc/add_images_to(var/mob/M)
M.client.images += hudimages
/datum/hud/proc/add_to_hud(var/atom/A)
if(hud_type in A.hud_list)
for(var/icontype in hud_icons)
var/list/image/AH = A.hud_list[hud_type][hud_icons]
hudimages += AH
for(var/mob/M in hudusers)
if(M.client)
M.client.images += AH
/datum/hud/proc/add_to_single_hud(var/mob/M, var/atom/A)
if(!M.client || !(hud_type in A.hud_list) || !(M in hudusers))
return
for(var/icontype in hud_icons)
M.client.images |= A.hud_list[hud_type][hud_icons]
//see code/datum/hud.dm for the generic hud datum
/datum/hud/data
/datum/hud/data/medical
hud_type = DATA_HUD_MEDICAL
hud_icons = list(HEALTH_HUD, STATUS_HUD)
/datum/hud/data/medical/basic
/datum/hud/data/medical/basic/add_images_to(var/mob/M)
for(var/image/I in hudimages)
var/mob/living/carbon/human/H = I.loc
var/obj/item/clothing/under/U = H.w_uniform
if(!istype(U)) continue
if(U.sensor_mode <= 2) continue
M.client.images += I
/datum/hud/data/medical/basic/proc/check_sensors(var/mob/living/carbon/human/H)
if(!istype(H)) return 0
var/obj/item/clothing/under/U = H.w_uniform
if(!istype(U)) return 0
if(U.sensor_mode <= 2) return 0
return 1
/datum/hud/data/medical/basic/proc/update_suit_sensors(var/mob/living/carbon/human/H, sensor_level)
if(!istype(H)) return
var/list/image/Himages = list()
for(var/image/I in hudimages)
if(I.loc == H) Himages |= I
for(var/mob/M in hudusers)
if(!M.client) continue
if(sensor_level <= 2)
M.client.images -= Himages
else
M.client.images |= Himages
/datum/hud/data/medical/basic/add_to_single_hud(var/mob/M, var/mob/living/carbon/human/H)
if(check_sensors(H))
..()
/datum/hud/data/medical/basic/proc/update_suit_sensors(var/mob/living/carbon/human/H)
check_sensors(H) ? add_to_hud(H) : remove_from_hud(H)
/datum/hud/data/medical/advanced
/datum/hud/data/security
hud_type = DATA_HUD_SECURITY
/datum/hud/data/security/basic
hud_icons = list(ID_HUD)
@@ -183,15 +82,13 @@ var/datum/hud/huds = list( \
//HOOKS
//called when a human changes suit sensors
/mob/living/carbon/human/proc/update_suit_sensors(var/obj/item/clothing/under/w_uniform)
var/sensor_level = 0
if(w_uniform) sensor_level = w_uniform.sensor_mode
/mob/living/carbon/human/proc/update_suit_sensors()
var/datum/hud/data/medical/basic/B = huds[DATA_HUD_MEDICAL_BASIC]
B.update_suit_sensors(src, sensor_level)
B.update_suit_sensors(src)
//called when a human changes health
/mob/living/carbon/human/proc/med_hud_set_health()
var/image/holder = hud_list[DATA_HUD_MEDICAL][HEALTH_HUD]
var/image/holder = hud_list[HEALTH_HUD]
if(stat == 2)
holder.icon_state = "hudhealth-100"
else
@@ -199,7 +96,7 @@ var/datum/hud/huds = list( \
//called when a human changes stat, virus or XENO_HOST
/mob/living/carbon/human/proc/med_hud_set_status()
var/image/holder = hud_list[DATA_HUD_MEDICAL][STATUS_HUD]
var/image/holder = hud_list[STATUS_HUD]
if(stat == 2)
holder.icon_state = "huddead"
else if(status_flags & XENO_HOST)
@@ -217,26 +114,26 @@ var/datum/hud/huds = list( \
//HOOKS
/mob/living/carbon/human/proc/sec_hud_set_ID()
var/image/holder = hud_list[DATA_HUD_SECURITY][ID_HUD]
var/image/holder = hud_list[ID_HUD]
holder.icon_state = "hudno_id"
if(wear_id)
holder.icon_state = "hud[ckey(wear_id.GetJobName())]"
/mob/living/carbon/human/proc/sec_hud_set_implants()
var/image/holder
for(var/I in list(IMPTRACK_HUD, IMPLOYAL_HUD, IMPCHEM_HUD))
holder = hud_list[DATA_HUD_SECURITY][I]
for(var/i in list(IMPTRACK_HUD, IMPLOYAL_HUD, IMPCHEM_HUD))
holder = hud_list[i]
holder.icon_state = null
for(var/obj/item/weapon/implant/I in src)
if(I.implanted)
if(istype(I,/obj/item/weapon/implant/tracking))
holder = hud_list[DATA_HUD_SECURITY][IMPTRACK_HUD]
holder = hud_list[IMPTRACK_HUD]
holder.icon_state = "hud_imp_tracking"
else if(istype(I,/obj/item/weapon/implant/loyalty))
holder = hud_list[DATA_HUD_SECURITY][IMPLOYAL_HUD]
holder = hud_list[IMPLOYAL_HUD]
holder.icon_state = "hud_imp_loyal"
else if(istype(I,/obj/item/weapon/implant/chem))
holder = hud_list[DATA_HUD_SECURITY][IMPCHEM_HUD]
holder = hud_list[IMPCHEM_HUD]
holder.icon_state = "hud_imp_chem"
/mob/living/carbon/human/proc/sec_hud_set_security_status()
@@ -245,10 +142,11 @@ var/datum/hud/huds = list( \
if(perpname)
var/datum/data/record/R = find_record("name", perpname, data_core.security)
if(R)
holder = hud_list[DATA_HUD_SECURITY][WANTED_HUD]
holder = hud_list[WANTED_HUD]
switch(R.fields["criminal"])
if("*Arrest*") holder.icon_state = "hudwanted"
if("Incarcerated") holder.icon_state = "hudincarcerated"
if("Parolled") holder.icon_state = "hudparolled"
if("Discharged") holder.icon_state = "huddischarged"
else holder.icon_state = null
+1 -1
View File
@@ -287,7 +287,7 @@ atom/proc/generate_female_clothing(index,t_color,icon)
if(istype(M,/mob/living/carbon/human))
var/mob/living/carbon/human/H = M
if(H.w_uniform == src)
H.update_suit_sensors(src)
H.update_suit_sensors()
..()
/obj/item/clothing/under/verb/rolldown()
+2 -10
View File
@@ -36,15 +36,8 @@
..()
/mob/living/carbon/human/proc/prepare_data_huds()
//Populates the human hud_list
for(var/i=1;i<=2;i++) // Humans have 2 sets of data hud icons
hud_list[i] = list()
for(var/i=1;i<=2;i++) // 2 icons for medHUDs...
hud_list[DATA_HUD_MEDICAL] += image('icons/mob/hud.dmi', src, "")
for(var/i=1;i<=5;i++) // ...and 5 for secHUDs
hud_list[DATA_HUD_SECURITY] += image('icons/mob/hud.dmi', src, "")
for(var/i=1;i<=7;i++) // 2 icons for medHUDs and 5 for secHUDs
hud_list += image('icons/mob/hud.dmi', src, "")
//Update all our hud images...
med_hud_set_health()
@@ -55,7 +48,6 @@
//...and display them
add_to_all_huds()
/mob/living/carbon/human/Destroy()
for(var/atom/movable/organelle in organs)
qdel(organelle)
@@ -260,7 +260,7 @@
if(belt)
unEquip(belt)
w_uniform = null
update_suit_sensors(w_uniform)
update_suit_sensors()
update_inv_w_uniform(0)
else if(I == gloves)
gloves = null
@@ -378,7 +378,7 @@
update_inv_wear_suit(redraw_mob)
if(slot_w_uniform)
w_uniform = I
update_suit_sensors(w_uniform)
update_suit_sensors()
update_inv_w_uniform(redraw_mob)
if(slot_l_store)
l_store = I
@@ -396,5 +396,4 @@
else
src << "<span class='danger'>You are trying to equip this item to an unsupported inventory slot. Report this to a coder!</span>"
return
update_action_buttons()
+2 -1
View File
@@ -20,7 +20,8 @@ var/list/ai_list = list()
density = 1
status_flags = CANSTUN|CANPARALYSE|CANPUSH
force_compose = 1 //This ensures that the AI always composes it's own hear message. Needed for hrefs and job display.
sensor_level = DATA_HUD_BASIC
med_hud = DATA_HUD_MEDICAL_BASIC
sec_hud = DATA_HUD_SECURITY_BASIC
var/list/network = list("SS13")
var/obj/machinery/camera/current = null
var/list/connected_robots = list()
@@ -239,11 +239,15 @@
if("securityhud")
if(href_list["toggle"])
secHUD = !secHUD
secHUD ? access_data_hud(DATA_HUD_SECURITY,sensor_level) : reset_data_hud(DATA_HUD_SECURITY,sensor_level)
remove_med_sec_hud()
if(secHUD)
add_sec_hud()
if("medicalhud")
if(href_list["toggle"])
medHUD = !medHUD
medHUD ? access_data_hud(DATA_HUD_MEDICAL,sensor_level) : reset_data_hud(DATA_HUD_MEDICAL,sensor_level)
remove_med_sec_hud()
if(medHUD)
add_med_hud()
if("translator")
if(href_list["toggle"])
languages = languages == ALL ? HUMAN & ROBOT : ALL
+19 -5
View File
@@ -15,7 +15,8 @@
var/lawcheck[1]
var/ioncheck[1]
var/sensor_level = DATA_HUD_ADVANCED //Determines the sensor level to use
var/med_hud = DATA_HUD_MEDICAL_ADVANCED //Determines the med hud to use
var/sec_hud = DATA_HUD_SECURITY_ADVANCED //Determines the sec hud to use
/mob/living/silicon/proc/cancelAlarm()
return
@@ -317,17 +318,30 @@
/mob/living/silicon/assess_threat() //Secbots won't hunt silicon units
return -10
/mob/living/silicon/proc/remove_med_sec_hud()
var/datum/hud/secsensor = huds[sec_hud]
var/datum/hud/medsensor = huds[med_hud]
secsensor.remove_hud_from(src)
medsensor.remove_hud_from(src)
/mob/living/silicon/proc/add_sec_hud()
var/datum/hud/secsensor = huds[sec_hud]
secsensor.add_hud_to(src)
/mob/living/silicon/proc/add_med_hud()
var/datum/hud/medsensor = huds[med_hud]
medsensor.add_hud_to(src)
/mob/living/silicon/verb/sensor_mode()
set name = "Set Sensor Augmentation"
var/sensor_type = input("Please select sensor type.", "Sensor Integration", null) in list("Security", "Medical","Disable")
reset_data_hud(DATA_HUD_SECURITY, sensor_level)
reset_data_hud(DATA_HUD_MEDICAL, sensor_level)
remove_med_sec_hud()
switch(sensor_type)
if ("Security")
access_data_hud(DATA_HUD_SECURITY,sensor_level)
add_sec_hud()
src << "<span class='notice'>Security records overlay enabled.</span>"
if ("Medical")
access_data_hud(DATA_HUD_MEDICAL,sensor_level)
add_med_hud()
src << "<span class='notice'>Life signs monitor overlay enabled.</span>"
if ("Disable")
src << "Sensor augmentations disabled."
+1
View File
@@ -129,6 +129,7 @@
#include "code\datums\datacore.dm"
#include "code\datums\datumvars.dm"
#include "code\datums\gas_mixture.dm"
#include "code\datums\hud.dm"
#include "code\datums\mind.dm"
#include "code\datums\mixed.dm"
#include "code\datums\modules.dm"