Files
Bubberstation/code/modules/mining/machine_stacking.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

172 lines
5.7 KiB
Plaintext

/**********************Mineral stacking unit console**************************/
/obj/machinery/mineral/stacking_unit_console
name = "stacking machine console"
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "console"
desc = "Controls a stacking machine... in theory."
density = FALSE
circuit = /obj/item/circuitboard/machine/stacking_unit_console
/// Connected stacking machine
var/obj/machinery/mineral/stacking_machine/machine
/obj/machinery/mineral/stacking_unit_console/Initialize(mapload)
. = ..()
var/area/our_area = get_area(src)
if(isnull(our_area))
return
var/list/turf_list = our_area.get_turfs_by_zlevel(z)
if(!islist(turf_list))
return
for (var/turf/area_turf as anything in turf_list)
var/obj/machinery/mineral/stacking_machine/found_machine = locate(/obj/machinery/mineral/stacking_machine) in area_turf
if(!isnull(found_machine) && isnull(found_machine.console))
found_machine.console = src
machine = found_machine
break
/obj/machinery/mineral/stacking_unit_console/Destroy()
if(!isnull(machine))
machine.console = null
machine = null
return ..()
/obj/machinery/mineral/stacking_unit_console/multitool_act(mob/living/user, obj/item/multitool/M)
M.set_buffer(src)
balloon_alert(user, "saved to multitool buffer")
return ITEM_INTERACT_SUCCESS
/obj/machinery/mineral/stacking_unit_console/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "StackingConsole", name)
ui.open()
/obj/machinery/mineral/stacking_unit_console/ui_data(mob/user)
var/list/data = list()
data["machine"] = machine ? TRUE : FALSE
data["stacking_amount"] = null
data["contents"] = list()
if(machine)
data["stacking_amount"] = machine.stack_amt
data["input_direction"] = dir2text(machine.input_dir)
data["output_direction"] = dir2text(machine.output_dir)
for(var/stack_type in machine.stack_list)
var/obj/item/stack/sheet/stored_sheet = machine.stack_list[stack_type]
if(stored_sheet.amount <= 0)
continue
data["contents"] += list(list(
"type" = stored_sheet.type,
"name" = capitalize(stored_sheet.name),
"amount" = stored_sheet.amount,
))
return data
/obj/machinery/mineral/stacking_unit_console/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
switch(action)
if("release")
var/obj/item/stack/sheet/released_type = text2path(params["type"])
if(!released_type || !(initial(released_type.merge_type) in machine.stack_list))
return //someone tried to spawn materials by spoofing hrefs
var/obj/item/stack/sheet/inp = machine.stack_list[initial(released_type.merge_type)]
var/obj/item/stack/sheet/out = new inp.type(null, inp.amount)
inp.amount = 0
machine.unload_mineral(out)
return TRUE
if("rotate")
var/input = text2num(params["input"])
machine.rotate(input)
return TRUE
/**********************Mineral stacking unit**************************/
/obj/machinery/mineral/stacking_machine
name = "stacking machine"
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "stacker"
desc = "A machine that automatically stacks acquired materials. Controlled by a nearby console."
density = TRUE
circuit = /obj/item/circuitboard/machine/stacking_machine
input_dir = EAST
output_dir = WEST
var/obj/machinery/mineral/stacking_unit_console/console
var/stk_types = list()
var/stk_amt = list()
var/stack_list[0] //Key: Type. Value: Instance of type.
var/stack_amt = 50 //amount to stack before releassing
var/datum/component/remote_materials/materials
var/force_connect = FALSE
///Proximity monitor associated with this atom, needed for proximity checks.
var/datum/proximity_monitor/proximity_monitor
/obj/machinery/mineral/stacking_machine/Initialize(mapload)
. = ..()
proximity_monitor = new(src, 1)
materials = AddComponent(
/datum/component/remote_materials, \
mapload, \
FALSE, \
(mapload && force_connect) \
)
/obj/machinery/mineral/stacking_machine/Destroy()
if(!isnull(console))
console.machine = null
console = null
materials = null
return ..()
/obj/machinery/mineral/stacking_machine/HasProximity(atom/movable/AM)
if(QDELETED(AM))
return
if(istype(AM, /obj/item/stack/sheet) && AM.loc == get_step(src, input_dir))
process_sheet(AM)
/obj/machinery/mineral/stacking_machine/multitool_act(mob/living/user, obj/item/multitool/multi_tool)
if(user.combat_mode || multi_tool.item_flags & ABSTRACT || multi_tool.flags_1 & HOLOGRAM_1)
return ITEM_INTERACT_SKIP_TO_ATTACK
. = ITEM_INTERACT_BLOCKING
if(istype(multi_tool.buffer, /obj/machinery/mineral/stacking_unit_console))
console = multi_tool.buffer
console.machine = src
to_chat(user, span_notice("You link [src] to the console in [multi_tool]'s buffer."))
return ITEM_INTERACT_SUCCESS
/obj/machinery/mineral/stacking_machine/proc/rotate(input)
if (input)
input_dir = turn(input_dir, 90)
else
output_dir = turn(output_dir, 90)
if (input_dir == output_dir)
rotate(input)
/obj/machinery/mineral/stacking_machine/proc/process_sheet(obj/item/stack/sheet/input)
if(QDELETED(input))
return
// Dump the sheets to the silo if attached
if(materials.silo && !materials.on_hold())
var/matlist = input.custom_materials & materials.mat_container.materials
if (length(matlist))
materials.insert_item(input)
return
// No silo attached process to internal storage
var/key = input.merge_type
var/obj/item/stack/sheet/storage = stack_list[key]
if(!storage) //It's the first of this sheet added
stack_list[key] = storage = new input.type(src, 0)
storage.amount += input.amount //Stack the sheets
qdel(input)
while(storage.amount >= stack_amt) //Get rid of excessive stackage
var/obj/item/stack/sheet/out = new input.type(null, stack_amt)
unload_mineral(out)
storage.amount -= stack_amt