[READY] Giving circuits possibility to load item while in assembly (#39454)

* Letting circuits get items in assembly

This adds a proc so that certain circuits can have an item inserted once they are in the assembly. Also gets rid of the second list in the attack_self() proc and removes that pesky list.Find() proc by turning the first list into an associative list, which should make the proc more reliable and slightly more optimized.

* Letting circuits get items in assembly 

Add a boolean var and an additem proc so that you can insert items inside some circuits after they are inside the assembly, while it is still open

* Fixed indentation error

Happens when I use copypaste for new code, sorry folks.

* fixed a little error due to false object path

* Fixed single-input assemblies

The choice variable detected the name of the association rather than the circuit associated to it in the list.

* Added a fix for batteries

There was this bug, where the battery would be transferred into the location of the assembly rather than its contents when putting it inside.

* fixed a little issue with analyzers

* Indentation error due to copy paste again

* fixing nonreactivity on input circuits

hey, it's not easy reworking a whole proc like this...

* further simplifications

* Adding new var

can_input_object_when_closed, which should make it possible for people to take items from an assembly.

* Adding the code to the corresponding new var

* small correction

forgot to make the var reference the circuit

* since most stuff just calls attackby(), why not let it relay directly?

* Whelp, since no one's reviewing, let's add onto this

* seeing if another travis check will still result in errors

* done it, Naksu!

thanks for giving this another chance!
This commit is contained in:
Shdorsh
2018-09-03 23:31:13 +02:00
committed by vuonojenmustaturska
parent 4c12431111
commit 6f24f5bd4b
3 changed files with 57 additions and 17 deletions
@@ -470,23 +470,50 @@
for(var/obj/item/integrated_circuit/input/S in assembly_components)
S.attackby_react(I,user,user.a_intent)
return ..()
var/obj/item/stock_parts/cell = I
user.transferItemToLoc(I, loc)
cell.forceMove(src)
battery = cell
I.forceMove(src)
battery = I
diag_hud_set_circuitstat() //update diagnostic hud
playsound(get_turf(src), 'sound/items/Deconstruct.ogg', 50, 1)
to_chat(user, "<span class='notice'>You slot \the [cell] inside \the [src]'s power supplier.</span>")
to_chat(user, "<span class='notice'>You slot the [I] inside \the [src]'s power supplier.</span>")
return TRUE
else if(istype(I, /obj/item/integrated_electronics/detailer))
var/obj/item/integrated_electronics/detailer/D = I
detail_color = D.detail_color
update_icon()
else
for(var/obj/item/integrated_circuit/input/S in assembly_components)
S.attackby_react(I,user,user.a_intent)
if(user.a_intent != INTENT_HELP)
return ..()
var/list/input_selection = list()
//Check all the components asking for an input
for(var/obj/item/integrated_circuit/input in assembly_components)
if((input.demands_object_input && opened) || (input.demands_object_input && input.can_input_object_when_closed))
var/i = 0
//Check if there is another component with the same name and append a number for identification
for(var/s in input_selection)
var/obj/item/integrated_circuit/s_circuit = input_selection[s]
if(s_circuit.name == input.name && s_circuit.displayed_name == input.displayed_name && s_circuit != input)
i++
var/disp_name= "[input.displayed_name] \[[input]\]"
if(i)
disp_name += " ([i+1])"
//Associative lists prevent me from needing another list and using a Find proc
input_selection[disp_name] = input
var/obj/item/integrated_circuit/choice
if(input_selection)
if(input_selection.len == 1)
choice = input_selection[input_selection[1]]
else
var/selection = input(user, "Where do you want to insert that item?", "Interaction") as null|anything in input_selection
if(!check_interactivity(user))
return ..()
if(selection)
choice = input_selection[selection]
if(choice)
choice.additem(I, user)
for(var/obj/item/integrated_circuit/input/S in assembly_components)
S.attackby_react(I,user,user.a_intent)
return ..()
/obj/item/electronic_assembly/attack_self(mob/user)
@@ -496,30 +523,33 @@
interact(user)
var/list/input_selection = list()
var/list/available_inputs = list()
//Check all the components asking for an input
for(var/obj/item/integrated_circuit/input/input in assembly_components)
if(input.can_be_asked_input)
available_inputs.Add(input)
var/i = 0
for(var/obj/item/integrated_circuit/s in available_inputs)
if(s.name == input.name && s.displayed_name == input.displayed_name && s != input)
//Check if there is another component with the same name and append a number for identification
for(var/s in input_selection)
var/obj/item/integrated_circuit/s_circuit = input_selection[s]
if(s_circuit.name == input.name && s_circuit.displayed_name == input.displayed_name && s_circuit != input)
i++
var/disp_name= "[input.displayed_name] \[[input]\]"
if(i)
disp_name += " ([i+1])"
input_selection.Add(disp_name)
//Associative lists prevent me from needing another list and using a Find proc
input_selection[disp_name] = input
var/obj/item/integrated_circuit/input/choice
if(available_inputs)
if(available_inputs.len ==1)
choice = available_inputs[1]
if(input_selection)
if(input_selection.len ==1)
choice = input_selection[input_selection[1]]
else
var/selection = input(user, "What do you want to interact with?", "Interaction") as null|anything in input_selection
if(!check_interactivity(user))
return
if(selection)
var/index = input_selection.Find(selection)
choice = available_inputs[index]
choice = input_selection[selection]
if(choice)
choice.ask_for_input(user)
@@ -24,6 +24,9 @@
var/category_text = "NO CATEGORY THIS IS A BUG" // To show up on circuit printer, and perhaps other places.
var/removable = TRUE // Determines if a circuit is removable from the assembly.
var/displayed_name = ""
var/demands_object_input = FALSE
var/can_input_object_when_closed = FALSE
/*
Integrated circuits are essentially modular machines. Each circuit has a specific function, and combining them inside Electronic Assemblies allows
@@ -35,6 +38,10 @@ a creative player the means to solve many problems. Circuits are held inside an
external_examine(user)
. = ..()
// Can be called via electronic_assembly/attackby()
/obj/item/integrated_circuit/proc/additem(var/obj/item/I, var/mob/living/user)
attackby(I, user)
// This should be used when someone is examining while the case is opened.
/obj/item/integrated_circuit/proc/internal_examine(mob/user)
to_chat(user, "This board has [inputs.len] input pin\s, [outputs.len] output pin\s and [activators.len] activation pin\s.")
@@ -34,6 +34,8 @@
var/lethal_projectile = null //lethal mode projectile type
var/lethal_projectile_sound
demands_object_input = TRUE // You can put stuff in once the circuit is in assembly,passed down from additem and handled by attackby()
/obj/item/integrated_circuit/manipulation/weapon_firing/Destroy()
@@ -185,6 +187,7 @@
action_flags = IC_ACTION_COMBAT
var/obj/item/grenade/attached_grenade
var/pre_attached_grenade_type
demands_object_input = TRUE // You can put stuff in once the circuit is in assembly,passed down from additem and handled by attackby()
/obj/item/integrated_circuit/manipulation/grenade/Initialize()
. = ..()