Files
Bubberstation/code/game/machinery/computer/atmos_computers/_atmos_control.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

245 lines
8.2 KiB
Plaintext

/// GENERAL AIR CONTROL (a.k.a atmos computer)
/obj/machinery/computer/atmos_control
name = "atmospherics monitoring"
desc = "Used to monitor the station's atmospherics sensors."
icon_screen = "tank"
icon_keyboard = "atmos_key"
circuit = /obj/item/circuitboard/computer/atmos_control
light_color = LIGHT_COLOR_CYAN
/// Which sensors do we want to listen to.
/// Assoc of list[chamber_id] = readable_chamber_name
var/list/atmos_chambers
/// Used when control = FALSE to store the original atmos chambers so they dont get lost when reconnecting
var/list/always_displayed_chambers
/// Whether we can actually adjust the chambers or not.
var/control = TRUE
/// Whether we are allowed to reconnect.
var/reconnecting = TRUE
/// Was this computer multitooled before. If so copy the list connected_sensors as it now maintain's its own sensors independent of the map loaded one's
var/was_multi_tooled = FALSE
/// list of all sensors[key is chamber id, value is id of air sensor linked to this chamber] monitered by this computer
var/list/connected_sensors
/obj/machinery/computer/atmos_control/Initialize(mapload, obj/item/circuitboard/C)
. = ..()
var/static/list/multitool_tips = list(
TOOL_MULTITOOL = list(
SCREENTIP_CONTEXT_LMB = "Link Sensor",
)
)
AddElement(/datum/element/contextual_screentip_tools, multitool_tips)
//all newly constructed/round start computers by default have access to this list
connected_sensors = GLOB.map_loaded_sensors
//special case for the station monitering console. We dont want to loose these chambers during reconnecting
if(!control && !isnull(atmos_chambers))
always_displayed_chambers = atmos_chambers.Copy()
/obj/machinery/computer/atmos_control/examine(mob/user)
. = ..()
. += span_notice("Use a multitool to link a air sensor to this computer")
/// Reconnect only works for station based chambers.
/obj/machinery/computer/atmos_control/proc/reconnect(mob/user)
if(!reconnecting)
return FALSE
// We only prompt the user with the sensors that are actually available.
var/available_devices = list()
for (var/chamber_identifier in connected_sensors)
//this sensor was destroyed at the time of reconnecting
var/obj/machinery/sensor = GLOB.objects_by_id_tag[connected_sensors[chamber_identifier]]
if(QDELETED(sensor))
continue
//non master computers don't have access to these station moniters. Only done to give master computer's special access to these chambers and make them feel special or something
if(chamber_identifier == ATMOS_GAS_MONITOR_DISTRO)
continue
if(chamber_identifier == ATMOS_GAS_MONITOR_WASTE)
continue
available_devices[GLOB.station_gas_chambers[chamber_identifier]] = chamber_identifier
// As long as we dont put any funny chars in the strings it should match.
var/new_name = tgui_input_list(user, "Select the device set", "Reconnect", available_devices)
if(isnull(new_name))
return FALSE
var/new_id = available_devices[new_name]
if(isnull(new_id))
return FALSE
atmos_chambers = list()
//these are chambers we always want to display even after reconnecting
if(always_displayed_chambers)
for(var/chamber_id in always_displayed_chambers)
atmos_chambers[chamber_id] = always_displayed_chambers[chamber_id]
atmos_chambers[new_id] = new_name
name = new_name + (control ? " Control" : " Monitor")
return TRUE
/obj/machinery/computer/atmos_control/multitool_act(mob/living/user, obj/item/multitool/multi_tool)
. = ..()
if(istype(multi_tool.buffer, /obj/machinery/air_sensor))
var/obj/machinery/air_sensor/sensor = multi_tool.buffer
//computers reference a global map loaded list of sensor's but as soon a user attempt's to edit it, make a copy of that list so other computers aren't affected
if(!was_multi_tooled)
connected_sensors = connected_sensors.Copy()
was_multi_tooled = TRUE
//register the sensor's unique ID with its assositated chamber
connected_sensors[sensor.chamber_id] = sensor.id_tag
user.balloon_alert(user, "sensor connected to [src]")
return ITEM_INTERACT_SUCCESS
return
/obj/machinery/computer/atmos_control/ui_interact(mob/user, datum/tgui/ui)
. = ..()
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "AtmosControlConsole", name)
ui.open()
/obj/machinery/computer/atmos_control/ui_static_data(mob/user)
var/data = list()
data["maxInput"] = MAX_TRANSFER_RATE
data["maxOutput"] = MAX_OUTPUT_PRESSURE
data["control"] = control
data["reconnecting"] = reconnecting
data += return_atmos_handbooks()
return data
/obj/machinery/computer/atmos_control/ui_data(mob/user)
var/data = list()
data["chambers"] = list()
for(var/chamber_id in atmos_chambers)
var/list/chamber_info = list()
chamber_info["id"] = chamber_id
chamber_info["name"] = atmos_chambers[chamber_id]
var/obj/machinery/sensor = GLOB.objects_by_id_tag[connected_sensors[chamber_id]]
if(!QDELETED(sensor))
chamber_info["gasmix"] = gas_mixture_parser(sensor.return_air())
if(istype(sensor, /obj/machinery/air_sensor)) //distro & waste loop are not air sensors and don't have these functions
var/obj/machinery/air_sensor/air_sensor = sensor
var/obj/machinery/atmospherics/components/unary/outlet_injector/input = GLOB.objects_by_id_tag[air_sensor.inlet_id || ""]
if (!QDELETED(input))
chamber_info["input_info"] = list(
"active" = input.on,
"amount" = input.volume_rate,
)
var/obj/machinery/atmospherics/components/unary/vent_pump/output = GLOB.objects_by_id_tag[air_sensor.outlet_id || ""]
if (!QDELETED(output))
chamber_info["output_info"] = list(
"active" = output.on,
"amount" = output.internal_pressure_bound,
)
data["chambers"] += list(chamber_info)
return data
/obj/machinery/computer/atmos_control/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(. || !(control || reconnecting))
return
var/chamber = params["chamber"]
switch(action)
if("toggle_input")
if (!(chamber in atmos_chambers))
return TRUE
var/obj/machinery/air_sensor/sensor = GLOB.objects_by_id_tag[connected_sensors[chamber]]
if(QDELETED(sensor))
return TRUE
var/obj/machinery/atmospherics/components/unary/outlet_injector/input = GLOB.objects_by_id_tag[sensor.inlet_id || ""]
if(QDELETED(input))
return TRUE
input.on = !input.on
input.update_appearance(UPDATE_ICON)
if("toggle_output")
if (!(chamber in atmos_chambers))
return TRUE
var/obj/machinery/air_sensor/sensor = GLOB.objects_by_id_tag[connected_sensors[chamber]]
if(QDELETED(sensor))
return TRUE
var/obj/machinery/atmospherics/components/unary/vent_pump/output = GLOB.objects_by_id_tag[sensor.outlet_id || ""]
if(QDELETED(output))
return TRUE
output.on = !output.on
output.update_appearance(UPDATE_ICON)
if("adjust_input")
if (!(chamber in atmos_chambers))
return TRUE
var/obj/machinery/air_sensor/sensor = GLOB.objects_by_id_tag[connected_sensors[chamber]]
if(QDELETED(sensor))
return TRUE
var/obj/machinery/atmospherics/components/unary/outlet_injector/input = GLOB.objects_by_id_tag[sensor.inlet_id || ""]
if(QDELETED(input))
return TRUE
var/target = text2num(params["rate"])
if(isnull(target))
return TRUE
target = clamp(target, 0, MAX_TRANSFER_RATE)
input.volume_rate = clamp(target, 0, min(input.airs[1].volume, MAX_TRANSFER_RATE))
if("adjust_output")
if (!(chamber in atmos_chambers))
return TRUE
var/obj/machinery/air_sensor/sensor = GLOB.objects_by_id_tag[connected_sensors[chamber]]
if(QDELETED(sensor))
return TRUE
var/obj/machinery/atmospherics/components/unary/vent_pump/output = GLOB.objects_by_id_tag[sensor.outlet_id || ""]
if(QDELETED(output))
return TRUE
var/target = text2num(params["rate"])
if(isnull(target))
return TRUE
target = clamp(target, 0, ATMOS_PUMP_MAX_PRESSURE)
output.internal_pressure_bound = target
if("reconnect")
reconnect(usr)
return TRUE
/obj/machinery/computer/atmos_control/nocontrol
control = FALSE
circuit = /obj/item/circuitboard/computer/atmos_control/nocontrol
/obj/machinery/computer/atmos_control/noreconnect
reconnecting = FALSE
circuit = /obj/item/circuitboard/computer/atmos_control/noreconnect
/// Vegetable
/obj/machinery/computer/atmos_control/fixed
control = FALSE
reconnecting = FALSE
circuit = /obj/item/circuitboard/computer/atmos_control/fixed