Files
Bubberstation/code/modules/wiremod/components/admin/proccall.dm
John Willard 1880003270 Reworks silicon/ai access checking & fixes some ui_act's (#84964)
## About The Pull Request

Currently to check for Silicon access, we do:
``if is silicon or is admin ghost or has unlimited silicon privileges or
has machine remote in hand``
What has unlimited silicon privileges? Bots, Drones, and admin ghosts.
To check for AI access, it just checks for AI instead of silicon, and
doesnt check for unlimited silicon privileges.

This was kinda silly, so I thought I should make this a little easier to
understand.
Now all silicon/ai traits come from ``AI_ACCESS_TRAIT`` or
``SILICON_ACCESS_TRAIT``. I made a single exception to keep Admin ghost,
since now instead of being a var on the client, we moved it to using the
same trait but giving it to the client instead, but since we have to
keep parity with previous functionality (admins can spawn in and not
have this on, it only works while as a ghost), I kept previous checks as
well.

No more type checks, removes a silly var on the mob level and another on
the client.

Now while I was doing this, I found a lot of tgui's ``ui_act`` still
uses ``usr`` and the wrong args, so I fixed those wherever I saw them,
and used a mass replace for the args.

Other changes:

- machinery's ``ui_act`` from
https://github.com/tgstation/tgstation/pull/81250 had ``isAI`` replaced
with ``HAS_AI_ACCESS``, this has been reverted. Machine wands and admin
ghosts no longer get kicked off things not on cameras. This was my
fault, I overlooked this when adding Human AI.
- Human AI's wand gives AI control as long as it's in your hand, you can
swap to your offhand. I hope this doesn't end up going horribly,
otherwise I'll revert this part. It should let human AIs not have their
UI closed on them when swapping to eat food or use their door wand or
whatnot.
- Bots previously had special checks to scan reagents and be
unobservant, I replaced this with giving them the trait. I also fixed an
instance of unobservant not being used, so now statues don't affect the
basic creature, whatever that is.

## Why It's Good For The Game

This is an easier to understand way of handling silicon access and makes
these mobs more consistent between eachother.
Other than what I've mentioned above, this should have no impact on
gameplay itself.

## Changelog

🆑
fix: Statues don't count as eyes to creatures.
fix: Human AIs and Admin ghosts no longer get kicked off of machines
that aren't on cameranets.
/🆑
2024-08-19 10:43:45 +00:00

191 lines
5.7 KiB
Plaintext

#define COMP_PROC_GLOBAL "Global"
#define COMP_PROC_OBJECT "Object"
/**
* # Proc Call Component
*
* A component that calls a proc on an object and outputs the return value
*/
/obj/item/circuit_component/proccall
display_name = "Proc Call"
desc = "A component that calls a proc on an object."
category = "Admin"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
var/datum/port/input/option/proccall_options
/// Entity to proccall on
var/datum/port/input/entity
/// Proc to call
var/datum/port/input/proc_name
/// A list of arguments
var/list/datum/port/input/arguments = list()
/// Returns the output from the proccall
var/datum/port/output/output_value
/// Whether we resolve all the weakrefs passed as arguments
var/resolve_weakref = TRUE
ui_buttons = list(
"cog" = "configure",
)
/obj/item/circuit_component/proccall/ui_perform_action(mob/user, action)
if(action == "configure")
interact(user)
/obj/item/circuit_component/proccall/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "ProcCallMenu", "ProcCall Configuration Menu")
ui.open()
ui.set_autoupdate(FALSE)
/obj/item/circuit_component/proccall/populate_options()
var/static/list/component_options = list(
COMP_PROC_OBJECT,
COMP_PROC_GLOBAL,
)
proccall_options = add_option_port("Proccall Options", component_options)
/obj/item/circuit_component/proccall/populate_ports()
entity = add_input_port("Target", PORT_TYPE_DATUM, order = 0.5)
proc_name = add_input_port("Proc Name", PORT_TYPE_STRING)
output_value = add_output_port("Output Value", PORT_TYPE_ANY)
/obj/item/circuit_component/proccall/pre_input_received(datum/port/input/port)
if(proccall_options.value == COMP_PROC_GLOBAL)
if(entity)
remove_input_port(entity)
entity = null
else
if(!entity)
entity = add_input_port("Target", PORT_TYPE_DATUM, order = 0.5)
/obj/item/circuit_component/proccall/ui_data(mob/user)
. = list()
var/list/input_ports = list()
for(var/datum/port/input/port as anything in arguments)
input_ports += list(list(
"name" = port.name,
"color" = port.color,
"datatype" = port.datatype,
))
.["input_ports"] = input_ports
.["expected_output"] = output_value.datatype
.["expected_output_color"] = output_value.color
.["resolve_weakref"] = resolve_weakref
/obj/item/circuit_component/proccall/ui_static_data(mob/user)
. = list()
.["possible_types"] = GLOB.wiremod_fundamental_types
/obj/item/circuit_component/proccall/ui_status(mob/user, datum/ui_state/state)
if(!check_rights_for(user.client, R_VAREDIT))
return UI_CLOSE
return UI_INTERACTIVE
/obj/item/circuit_component/proccall/save_data_to_list(list/component_data)
. = ..()
var/list/input_ports = list()
for(var/datum/port/input/port as anything in arguments)
input_ports += list(list(
"name" = port.name,
"datatype" = port.datatype,
))
component_data["input_ports"] = input_ports
component_data["expected_output_type"] = output_value.datatype
component_data["resolve_weakref"] = resolve_weakref
/obj/item/circuit_component/proccall/load_data_from_list(list/component_data)
if(component_data["resolve_weakref"] != null)
resolve_weakref = component_data["resolve_weakref"]
if(component_data["expected_output_type"])
output_value.set_datatype(component_data["expected_output_type"])
for(var/list/data as anything in component_data["input_ports"])
arguments += add_input_port(data["name"], data["datatype"])
return ..()
/obj/item/circuit_component/proccall/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
. = TRUE
switch(action)
if("set_expected_output")
var/new_type = params["datatype"]
if(!(new_type in GLOB.wiremod_fundamental_types))
return
output_value.set_datatype(new_type)
if("resolve_weakref")
resolve_weakref = !resolve_weakref
if("add_argument")
arguments += add_input_port("Port [length(arguments)]", PORT_TYPE_ANY)
if("remove_argument")
var/index = round(text2num(params["index"]))
if(index < 1 || index > length(arguments))
return
remove_input_port(arguments[index])
arguments.Splice(index, index+1)
if("rename_argument")
var/index = round(text2num(params["index"]))
if(index < 1 || index > length(arguments))
return
var/datum/port/input/argument = arguments[index]
argument.name = trim(copytext(params["name"], 1, PORT_MAX_NAME_LENGTH))
SStgui.update_uis(parent)
if("set_argument_datatype")
var/index = round(text2num(params["index"]))
if(index < 1 || index > length(arguments))
return
var/datum/port/input/argument = arguments[index]
var/new_type = params["datatype"]
if(!(new_type in GLOB.wiremod_fundamental_types))
return
argument.set_datatype(new_type)
/obj/item/circuit_component/proccall/input_received(datum/port/input/port)
var/called_on
if(proccall_options.value == COMP_PROC_OBJECT)
called_on = entity.value
else
called_on = GLOBAL_PROC
if(!called_on)
return
var/to_invoke = proc_name.value
var/list/params = list()
for(var/datum/port/input/argument_port as anything in arguments)
params += list(argument_port.value)
if(!to_invoke)
return
if(called_on != GLOBAL_PROC && !hascall(called_on, to_invoke))
return
if(resolve_weakref)
params = recursive_list_resolve(params)
log_admin_circuit("[parent.get_creator()] proccalled '[to_invoke]' on [called_on] with params \[[params.Join(", ")]].")
INVOKE_ASYNC(src, PROC_REF(do_proccall), called_on, to_invoke, params)
/obj/item/circuit_component/proccall/proc/do_proccall(called_on, to_invoke, params)
var/result = HandleUserlessProcCall(parent.get_creator(), called_on, to_invoke, params)
output_value.set_output(result)
#undef COMP_PROC_GLOBAL
#undef COMP_PROC_OBJECT