mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-13 03:33:21 +00:00
AI NanoUI subsystems.
Allows sharing of NanoUI code between consoles and the AI (and just about anything else).
This commit is contained in:
@@ -1136,6 +1136,7 @@
|
|||||||
#include "code\modules\mob\living\silicon\ai\life.dm"
|
#include "code\modules\mob\living\silicon\ai\life.dm"
|
||||||
#include "code\modules\mob\living\silicon\ai\login.dm"
|
#include "code\modules\mob\living\silicon\ai\login.dm"
|
||||||
#include "code\modules\mob\living\silicon\ai\logout.dm"
|
#include "code\modules\mob\living\silicon\ai\logout.dm"
|
||||||
|
#include "code\modules\mob\living\silicon\ai\nano.dm"
|
||||||
#include "code\modules\mob\living\silicon\ai\say.dm"
|
#include "code\modules\mob\living\silicon\ai\say.dm"
|
||||||
#include "code\modules\mob\living\silicon\ai\freelook\cameranet.dm"
|
#include "code\modules\mob\living\silicon\ai\freelook\cameranet.dm"
|
||||||
#include "code\modules\mob\living\silicon\ai\freelook\chunk.dm"
|
#include "code\modules\mob\living\silicon\ai\freelook\chunk.dm"
|
||||||
@@ -1225,7 +1226,9 @@
|
|||||||
#include "code\modules\nano\nanoexternal.dm"
|
#include "code\modules\nano\nanoexternal.dm"
|
||||||
#include "code\modules\nano\nanomanager.dm"
|
#include "code\modules\nano\nanomanager.dm"
|
||||||
#include "code\modules\nano\nanomapgen.dm"
|
#include "code\modules\nano\nanomapgen.dm"
|
||||||
|
#include "code\modules\nano\nanoprocs.dm"
|
||||||
#include "code\modules\nano\nanoui.dm"
|
#include "code\modules\nano\nanoui.dm"
|
||||||
|
#include "code\modules\nano\modules\rcon.dm"
|
||||||
#include "code\modules\organs\blood.dm"
|
#include "code\modules\organs\blood.dm"
|
||||||
#include "code\modules\organs\organ.dm"
|
#include "code\modules\organs\organ.dm"
|
||||||
#include "code\modules\organs\organ_alien.dm"
|
#include "code\modules\organs\organ_alien.dm"
|
||||||
|
|||||||
@@ -12,12 +12,11 @@
|
|||||||
circuit = /obj/item/weapon/circuitboard/rcon_console
|
circuit = /obj/item/weapon/circuitboard/rcon_console
|
||||||
req_one_access = list(access_engine)
|
req_one_access = list(access_engine)
|
||||||
var/current_tag = null
|
var/current_tag = null
|
||||||
var/list/known_SMESs = null
|
var/obj/nano_module/rcon/rcon
|
||||||
var/list/known_breakers = null
|
|
||||||
// Allows you to hide specific parts of the UI
|
/obj/machinery/computer/rcon/New()
|
||||||
var/hide_SMES = 0
|
..()
|
||||||
var/hide_SMES_details = 0
|
rcon = new(src)
|
||||||
var/hide_breakers = 0
|
|
||||||
|
|
||||||
// Proc: attack_hand()
|
// Proc: attack_hand()
|
||||||
// Parameters: 1 (user - Person which clicked this computer)
|
// Parameters: 1 (user - Person which clicked this computer)
|
||||||
@@ -29,106 +28,5 @@
|
|||||||
// Proc: ui_interact()
|
// Proc: ui_interact()
|
||||||
// Parameters: 4 (standard NanoUI parameters)
|
// Parameters: 4 (standard NanoUI parameters)
|
||||||
// Description: Uses dark magic (NanoUI) to render this machine's UI
|
// Description: Uses dark magic (NanoUI) to render this machine's UI
|
||||||
/obj/machinery/computer/rcon/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
|
/obj/machinery/computer/rcon/ui_interact(mob/user, ui_key = "rcon", var/datum/nanoui/ui = null, var/force_open = 1)
|
||||||
FindDevices() // Update our devices list
|
rcon.ui_interact(user, ui_key, ui, force_open)
|
||||||
var/data[0]
|
|
||||||
|
|
||||||
// SMES DATA (simplified view)
|
|
||||||
var/list/smeslist[0]
|
|
||||||
for(var/obj/machinery/power/smes/buildable/SMES in known_SMESs)
|
|
||||||
smeslist.Add(list(list(
|
|
||||||
"charge" = round(SMES.Percentage()),
|
|
||||||
"input_set" = SMES.input_attempt,
|
|
||||||
"input_val" = round(SMES.input_level),
|
|
||||||
"output_set" = SMES.output_attempt,
|
|
||||||
"output_val" = round(SMES.output_level),
|
|
||||||
"output_load" = round(SMES.output_used),
|
|
||||||
"RCON_tag" = SMES.RCon_tag
|
|
||||||
)))
|
|
||||||
|
|
||||||
data["smes_info"] = sortByKey(smeslist, "RCON_tag")
|
|
||||||
|
|
||||||
// BREAKER DATA (simplified view)
|
|
||||||
var/list/breakerlist[0]
|
|
||||||
for(var/obj/machinery/power/breakerbox/BR in known_breakers)
|
|
||||||
breakerlist.Add(list(list(
|
|
||||||
"RCON_tag" = BR.RCon_tag,
|
|
||||||
"enabled" = BR.on
|
|
||||||
)))
|
|
||||||
data["breaker_info"] = breakerlist
|
|
||||||
data["hide_smes"] = hide_SMES
|
|
||||||
data["hide_smes_details"] = hide_SMES_details
|
|
||||||
data["hide_breakers"] = hide_breakers
|
|
||||||
|
|
||||||
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open)
|
|
||||||
if (!ui)
|
|
||||||
ui = new(user, src, ui_key, "rcon.tmpl", "RCON Console", 600, 400)
|
|
||||||
ui.set_initial_data(data)
|
|
||||||
ui.open()
|
|
||||||
ui.set_auto_update(1)
|
|
||||||
|
|
||||||
// Proc: Topic()
|
|
||||||
// Parameters: 2 (href, href_list - allows us to process UI clicks)
|
|
||||||
// Description: Allows us to process UI clicks, which are relayed in form of hrefs.
|
|
||||||
/obj/machinery/computer/rcon/Topic(href, href_list)
|
|
||||||
if(href_list["smes_in_toggle"])
|
|
||||||
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_in_toggle"])
|
|
||||||
if(SMES)
|
|
||||||
SMES.toggle_input()
|
|
||||||
if(href_list["smes_out_toggle"])
|
|
||||||
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_out_toggle"])
|
|
||||||
if(SMES)
|
|
||||||
SMES.toggle_output()
|
|
||||||
if(href_list["smes_in_set"])
|
|
||||||
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_in_set"])
|
|
||||||
if(SMES)
|
|
||||||
var/inputset = input(usr, "Enter new input level (0-[SMES.input_level_max])", "SMES Input Power Control") as num
|
|
||||||
SMES.set_input(inputset)
|
|
||||||
if(href_list["smes_out_set"])
|
|
||||||
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_out_set"])
|
|
||||||
if(SMES)
|
|
||||||
var/outputset = input(usr, "Enter new output level (0-[SMES.output_level_max])", "SMES Input Power Control") as num
|
|
||||||
SMES.set_output(outputset)
|
|
||||||
|
|
||||||
if(href_list["toggle_breaker"])
|
|
||||||
var/obj/machinery/power/breakerbox/toggle = null
|
|
||||||
for(var/obj/machinery/power/breakerbox/breaker in known_breakers)
|
|
||||||
if(breaker.RCon_tag == href_list["toggle_breaker"])
|
|
||||||
toggle = breaker
|
|
||||||
if(toggle)
|
|
||||||
if(toggle.update_locked)
|
|
||||||
usr << "The breaker box was recently toggled. Please wait before toggling it again."
|
|
||||||
else
|
|
||||||
toggle.auto_toggle()
|
|
||||||
if(href_list["hide_smes"])
|
|
||||||
hide_SMES = !hide_SMES
|
|
||||||
if(href_list["hide_smes_details"])
|
|
||||||
hide_SMES_details = !hide_SMES_details
|
|
||||||
if(href_list["hide_breakers"])
|
|
||||||
hide_breakers = !hide_breakers
|
|
||||||
|
|
||||||
|
|
||||||
// Proc: GetSMESByTag()
|
|
||||||
// Parameters: 1 (tag - RCON tag of SMES we want to look up)
|
|
||||||
// Description: Looks up and returns SMES which has matching RCON tag
|
|
||||||
/obj/machinery/computer/rcon/proc/GetSMESByTag(var/tag)
|
|
||||||
if(!tag)
|
|
||||||
return
|
|
||||||
|
|
||||||
for(var/obj/machinery/power/smes/buildable/S in known_SMESs)
|
|
||||||
if(S.RCon_tag == tag)
|
|
||||||
return S
|
|
||||||
|
|
||||||
// Proc: FindDevices()
|
|
||||||
// Parameters: None
|
|
||||||
// Description: Refreshes local list of known devices.
|
|
||||||
/obj/machinery/computer/rcon/proc/FindDevices()
|
|
||||||
known_SMESs = new /list()
|
|
||||||
for(var/obj/machinery/power/smes/buildable/SMES in machines)
|
|
||||||
if(SMES.RCon_tag && (SMES.RCon_tag != "NO_TAG") && SMES.RCon)
|
|
||||||
known_SMESs.Add(SMES)
|
|
||||||
|
|
||||||
known_breakers = new /list()
|
|
||||||
for(var/obj/machinery/power/breakerbox/breaker in machines)
|
|
||||||
if(breaker.RCon_tag != "NO_TAG")
|
|
||||||
known_breakers.Add(breaker)
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@
|
|||||||
// Calling Topic without a corresponding window open causes runtime errors
|
// Calling Topic without a corresponding window open causes runtime errors
|
||||||
if(!nowindow && ..())
|
if(!nowindow && ..())
|
||||||
return 1
|
return 1
|
||||||
if(usr.can_interact_with_interface(src, checkrange) != STATUS_INTERACTIVE)
|
|
||||||
|
if(usr.can_interact_with_interface(nano_host(), checkrange) != STATUS_INTERACTIVE)
|
||||||
return 1
|
return 1
|
||||||
add_fingerprint(usr)
|
add_fingerprint(usr)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ var/list/ai_verbs_default = list(
|
|||||||
/mob/living/silicon/ai/proc/sensor_mode,
|
/mob/living/silicon/ai/proc/sensor_mode,
|
||||||
/mob/living/silicon/ai/proc/show_laws_verb,
|
/mob/living/silicon/ai/proc/show_laws_verb,
|
||||||
/mob/living/silicon/ai/proc/toggle_acceleration,
|
/mob/living/silicon/ai/proc/toggle_acceleration,
|
||||||
/mob/living/silicon/ai/proc/toggle_camera_light
|
/mob/living/silicon/ai/proc/toggle_camera_light,
|
||||||
|
/mob/living/silicon/ai/proc/nano_rcon
|
||||||
)
|
)
|
||||||
|
|
||||||
//Not sure why this is necessary...
|
//Not sure why this is necessary...
|
||||||
@@ -163,6 +164,8 @@ var/list/ai_verbs_default = list(
|
|||||||
hud_list[IMPTRACK_HUD] = image('icons/mob/hud.dmi', src, "hudblank")
|
hud_list[IMPTRACK_HUD] = image('icons/mob/hud.dmi', src, "hudblank")
|
||||||
hud_list[SPECIALROLE_HUD] = image('icons/mob/hud.dmi', src, "hudblank")
|
hud_list[SPECIALROLE_HUD] = image('icons/mob/hud.dmi', src, "hudblank")
|
||||||
|
|
||||||
|
init_subsystems()
|
||||||
|
|
||||||
ai_list += src
|
ai_list += src
|
||||||
..()
|
..()
|
||||||
return
|
return
|
||||||
|
|||||||
10
code/modules/mob/living/silicon/ai/nano.dm
Normal file
10
code/modules/mob/living/silicon/ai/nano.dm
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
var/obj/nano_module/rcon/rcon
|
||||||
|
|
||||||
|
/mob/living/silicon/ai/proc/init_subsystems()
|
||||||
|
rcon = new(src)
|
||||||
|
|
||||||
|
/mob/living/silicon/ai/proc/nano_rcon()
|
||||||
|
set category = "AI Subystems"
|
||||||
|
set name = "RCON"
|
||||||
|
|
||||||
|
rcon.ui_interact(usr)
|
||||||
116
code/modules/nano/modules/rcon.dm
Normal file
116
code/modules/nano/modules/rcon.dm
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
/obj/nano_module/rcon
|
||||||
|
name = "RCON interface"
|
||||||
|
|
||||||
|
var/list/known_SMESs = null
|
||||||
|
var/list/known_breakers = null
|
||||||
|
// Allows you to hide specific parts of the UI
|
||||||
|
var/hide_SMES = 0
|
||||||
|
var/hide_SMES_details = 0
|
||||||
|
var/hide_breakers = 0
|
||||||
|
|
||||||
|
/obj/nano_module/rcon/ui_interact(mob/user, ui_key = "rcon", datum/nanoui/ui=null, force_open=1)
|
||||||
|
FindDevices() // Update our devices list
|
||||||
|
var/data[0]
|
||||||
|
|
||||||
|
// SMES DATA (simplified view)
|
||||||
|
var/list/smeslist[0]
|
||||||
|
for(var/obj/machinery/power/smes/buildable/SMES in known_SMESs)
|
||||||
|
smeslist.Add(list(list(
|
||||||
|
"charge" = round(SMES.Percentage()),
|
||||||
|
"input_set" = SMES.input_attempt,
|
||||||
|
"input_val" = round(SMES.input_level),
|
||||||
|
"output_set" = SMES.output_attempt,
|
||||||
|
"output_val" = round(SMES.output_level),
|
||||||
|
"output_load" = round(SMES.output_used),
|
||||||
|
"RCON_tag" = SMES.RCon_tag
|
||||||
|
)))
|
||||||
|
|
||||||
|
data["smes_info"] = sortByKey(smeslist, "RCON_tag")
|
||||||
|
|
||||||
|
// BREAKER DATA (simplified view)
|
||||||
|
var/list/breakerlist[0]
|
||||||
|
for(var/obj/machinery/power/breakerbox/BR in known_breakers)
|
||||||
|
breakerlist.Add(list(list(
|
||||||
|
"RCON_tag" = BR.RCon_tag,
|
||||||
|
"enabled" = BR.on
|
||||||
|
)))
|
||||||
|
data["breaker_info"] = breakerlist
|
||||||
|
data["hide_smes"] = hide_SMES
|
||||||
|
data["hide_smes_details"] = hide_SMES_details
|
||||||
|
data["hide_breakers"] = hide_breakers
|
||||||
|
|
||||||
|
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open)
|
||||||
|
if (!ui)
|
||||||
|
ui = new(user, src, ui_key, "rcon.tmpl", "RCON Console", 600, 400)
|
||||||
|
ui.set_initial_data(data)
|
||||||
|
ui.open()
|
||||||
|
ui.set_auto_update(1)
|
||||||
|
|
||||||
|
// Proc: Topic()
|
||||||
|
// Parameters: 2 (href, href_list - allows us to process UI clicks)
|
||||||
|
// Description: Allows us to process UI clicks, which are relayed in form of hrefs.
|
||||||
|
/obj/nano_module/rcon/Topic(href, href_list)
|
||||||
|
if(..())
|
||||||
|
return
|
||||||
|
|
||||||
|
if(href_list["smes_in_toggle"])
|
||||||
|
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_in_toggle"])
|
||||||
|
if(SMES)
|
||||||
|
SMES.toggle_input()
|
||||||
|
if(href_list["smes_out_toggle"])
|
||||||
|
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_out_toggle"])
|
||||||
|
if(SMES)
|
||||||
|
SMES.toggle_output()
|
||||||
|
if(href_list["smes_in_set"])
|
||||||
|
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_in_set"])
|
||||||
|
if(SMES)
|
||||||
|
var/inputset = input(usr, "Enter new input level (0-[SMES.input_level_max])", "SMES Input Power Control") as num
|
||||||
|
SMES.set_input(inputset)
|
||||||
|
if(href_list["smes_out_set"])
|
||||||
|
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(href_list["smes_out_set"])
|
||||||
|
if(SMES)
|
||||||
|
var/outputset = input(usr, "Enter new output level (0-[SMES.output_level_max])", "SMES Input Power Control") as num
|
||||||
|
SMES.set_output(outputset)
|
||||||
|
|
||||||
|
if(href_list["toggle_breaker"])
|
||||||
|
var/obj/machinery/power/breakerbox/toggle = null
|
||||||
|
for(var/obj/machinery/power/breakerbox/breaker in known_breakers)
|
||||||
|
if(breaker.RCon_tag == href_list["toggle_breaker"])
|
||||||
|
toggle = breaker
|
||||||
|
if(toggle)
|
||||||
|
if(toggle.update_locked)
|
||||||
|
usr << "The breaker box was recently toggled. Please wait before toggling it again."
|
||||||
|
else
|
||||||
|
toggle.auto_toggle()
|
||||||
|
if(href_list["hide_smes"])
|
||||||
|
hide_SMES = !hide_SMES
|
||||||
|
if(href_list["hide_smes_details"])
|
||||||
|
hide_SMES_details = !hide_SMES_details
|
||||||
|
if(href_list["hide_breakers"])
|
||||||
|
hide_breakers = !hide_breakers
|
||||||
|
|
||||||
|
|
||||||
|
// Proc: GetSMESByTag()
|
||||||
|
// Parameters: 1 (tag - RCON tag of SMES we want to look up)
|
||||||
|
// Description: Looks up and returns SMES which has matching RCON tag
|
||||||
|
/obj/nano_module/rcon/proc/GetSMESByTag(var/tag)
|
||||||
|
if(!tag)
|
||||||
|
return
|
||||||
|
|
||||||
|
for(var/obj/machinery/power/smes/buildable/S in known_SMESs)
|
||||||
|
if(S.RCon_tag == tag)
|
||||||
|
return S
|
||||||
|
|
||||||
|
// Proc: FindDevices()
|
||||||
|
// Parameters: None
|
||||||
|
// Description: Refreshes local list of known devices.
|
||||||
|
/obj/nano_module/rcon/proc/FindDevices()
|
||||||
|
known_SMESs = new /list()
|
||||||
|
for(var/obj/machinery/power/smes/buildable/SMES in machines)
|
||||||
|
if(SMES.RCon_tag && (SMES.RCon_tag != "NO_TAG") && SMES.RCon)
|
||||||
|
known_SMESs.Add(SMES)
|
||||||
|
|
||||||
|
known_breakers = new /list()
|
||||||
|
for(var/obj/machinery/power/breakerbox/breaker in machines)
|
||||||
|
if(breaker.RCon_tag != "NO_TAG")
|
||||||
|
known_breakers.Add(breaker)
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
var/update_count = 0
|
var/update_count = 0
|
||||||
for (var/ui_key in open_uis[src_object_key])
|
for (var/ui_key in open_uis[src_object_key])
|
||||||
for (var/datum/nanoui/ui in open_uis[src_object_key][ui_key])
|
for (var/datum/nanoui/ui in open_uis[src_object_key][ui_key])
|
||||||
if(ui && ui.src_object && ui.user)
|
if(ui && ui.src_object && ui.user && ui.src_object.nano_host())
|
||||||
ui.process(1)
|
ui.process(1)
|
||||||
update_count++
|
update_count++
|
||||||
return update_count
|
return update_count
|
||||||
|
|||||||
11
code/modules/nano/nanoprocs.dm
Normal file
11
code/modules/nano/nanoprocs.dm
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/atom/movable/proc/nano_host()
|
||||||
|
return src
|
||||||
|
|
||||||
|
/obj/nano_module/nano_host()
|
||||||
|
return loc
|
||||||
|
|
||||||
|
/atom/movable/proc/nano_can_update()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
/obj/machinery/nano_can_update()
|
||||||
|
return !(stat & (NOPOWER|BROKEN))
|
||||||
@@ -132,7 +132,12 @@ nanoui is used to open and update nano browser uis
|
|||||||
* @return nothing
|
* @return nothing
|
||||||
*/
|
*/
|
||||||
/datum/nanoui/proc/update_status(var/push_update = 0)
|
/datum/nanoui/proc/update_status(var/push_update = 0)
|
||||||
var/status = user.can_interact_with_interface(src_object)
|
var/atom/movable/host = src_object.nano_host()
|
||||||
|
if(!host.nano_can_update())
|
||||||
|
close()
|
||||||
|
return
|
||||||
|
|
||||||
|
var/status = user.can_interact_with_interface(host.nano_host())
|
||||||
if(status == STATUS_CLOSE)
|
if(status == STATUS_CLOSE)
|
||||||
close()
|
close()
|
||||||
else
|
else
|
||||||
@@ -181,7 +186,7 @@ nanoui is used to open and update nano browser uis
|
|||||||
return STATUS_UPDATE
|
return STATUS_UPDATE
|
||||||
|
|
||||||
/mob/living/silicon/ai/can_interact_with_interface(var/src_object)
|
/mob/living/silicon/ai/can_interact_with_interface(var/src_object)
|
||||||
if(stat || !client)
|
if(!client || check_unable(1))
|
||||||
return STATUS_CLOSE
|
return STATUS_CLOSE
|
||||||
// Prevents the AI from using Topic on admin levels (by for example viewing through the court/thunderdome cameras)
|
// Prevents the AI from using Topic on admin levels (by for example viewing through the court/thunderdome cameras)
|
||||||
// unless it's on the same level as the object it's interacting with.
|
// unless it's on the same level as the object it's interacting with.
|
||||||
|
|||||||
Reference in New Issue
Block a user