Skip to content

Commit

Permalink
Stage 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Stakks committed Apr 9, 2018
1 parent 197e1b0 commit 4c3528a
Show file tree
Hide file tree
Showing 15 changed files with 1,192 additions and 195 deletions.
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/storage/belt.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
/obj/item/stack/cable_coil,
/obj/item/device/t_scanner,
/obj/item/device/analyzer,
/obj/item/weapon/extinguisher/mini
/obj/item/device/integrated_electronics/wirer,
/obj/item/weapon/extinguisher/mini,
/obj/item/device/integrated_electronics/wirer
)

/obj/item/weapon/storage/belt/utility/full/New()
Expand Down
75 changes: 53 additions & 22 deletions code/modules/integrated_electronics/_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
var/list/activator_names = list()
var/last_used = 0 //Uses world.time
var/complexity = 1 //This acts as a limitation on building machines, more resource-intensive components cost more 'space'.
var/power_required = 5 //w
var/cooldown_per_use = 1 SECONDS

/obj/item/integrated_circuit/examine(mob/user)
..()
Expand Down Expand Up @@ -72,6 +72,9 @@
A.name = "[activator_names[i]]"
i++

/obj/item/integrated_circuit/proc/on_data_written() //Override this for special behaviour when new data gets pushed to the circuit.
return

/obj/item/integrated_circuit/Destroy()
for(var/datum/integrated_io/I in inputs)
qdel(I)
Expand All @@ -92,7 +95,10 @@

var/mob/M = usr

var/input = sanitize_text(input("What do you want to name the circuit?", ,""))
if(!M.canmove || M.stat || M.restrained())
return

var/input = sanitize_text(input("What do you want to name the circuit?","Rename", src.name), MAX_NAME_LEN)

if(src && input)
M << "<span class='notice'>The circuit '[src.name]' is now labeled '[input]'.</span>"
Expand Down Expand Up @@ -156,13 +162,14 @@
words += "<a href=?src=\ref[src];wire=1;user=\ref[user];pin=\ref[io]>\[[linked.name]\]</a> \
@ <a href=?src=\ref[linked.holder];examine=1;user=\ref[user]>[linked.holder]</a><br>"
if(outputs.len > inputs.len)
height = Floor(outputs.len / inputs.len)
//world << "I wrote [words] at ([i],[j])."
// height = Floor(outputs.len / inputs.len)
height = 1 // Because of bugs, if there's more outputs than inputs, it causes the output side to be hidden.
//world << "I wrote [words] at ([i],[j]). Height = [height]."
if(2)
if(i == 1)
words = "[src.name]<br><br>[src.desc]"
height = row_height
//world << "I wrote the center piece because i was equal to 1, at ([i],[j])."
//world << "I wrote the center piece because i was equal to 1, at ([i],[j]). Height = [height]."
else
continue
if(3)
Expand All @@ -179,8 +186,9 @@
words += "<a href=?src=\ref[src];wire=1;user=\ref[user];pin=\ref[io]>\[[linked.name]\]</a> \
@ <a href=?src=\ref[linked.holder];examine=1;user=\ref[user]>[linked.holder]</a><br>"
if(inputs.len > outputs.len)
height = Floor(inputs.len / outputs.len)
//world << "I wrote [words] at ([i],[j])."
// height = Floor(inputs.len / outputs.len)
height = 1 // See above.
//world << "I wrote [words] at ([i],[j]). Height = [height]."
HTML += "<td align='center' rowspan='[height]'>[words]</td>"
//HTML += "<td align='center'>[words]</td>"
//world << "Writing to ([i],[j])."
Expand Down Expand Up @@ -209,11 +217,15 @@
HTML += "</table>"
HTML += "</div>"

HTML += "<br><font color='0000FF'>Complexity: [complexity]</font>"
HTML += "<br><font color='0000FF'>[extended_desc]</font>"

HTML += "</body></html>"
user << browse(HTML, "window=circuit-\ref[src];size=600x350;border=1;can_resize=1;can_close=1;can_minimize=1")

//user << sanitize_text(HTML, "window=debug;size=400x400;border=1;can_resize=1;can_close=1;can_minimize=1")
//world << sanitize_text(HTML)

user.set_machine(src)
onclose(user, "circuit-\ref[src]")

Expand All @@ -224,17 +236,31 @@
if(!user || !user.Adjacent(get_turf(src)) )
return 1

if(!user.canmove || user.stat || user.restrained())
return

if(href_list["wire"])
if(ishuman(user) && Adjacent(user))
var/mob/living/carbon/human/H = user
var/obj/item/device/integrated_electronics/wirer/wirer = null
if(istype(H.r_hand, /obj/item/device/integrated_electronics/wirer))
wirer = H.r_hand
else if(istype(H.l_hand, /obj/item/device/integrated_electronics/wirer))
wirer = H.l_hand

if(wirer && pin)
wirer.wire(pin, user)
var/obj/held_item = H.get_active_hand()

if(istype(held_item, /obj/item/device/integrated_electronics/wirer))
var/obj/item/device/integrated_electronics/wirer/wirer = held_item
if(pin)
wirer.wire(pin, user)

else if(istype(held_item, /obj/item/device/integrated_electronics/debugger))
var/obj/item/device/integrated_electronics/debugger/debugger = held_item
if(pin)
debugger.write_data(pin, user)

// if(istype(H.r_hand, /obj/item/device/integrated_electronics/wirer))
// wirer = H.r_hand
// else if(istype(H.l_hand, /obj/item/device/integrated_electronics/wirer))
// wirer = H.l_hand

// if(wirer && pin)
// wirer.wire(pin, user)
else
user << "<span class='warning'>You can't do a whole lot without tools.</span>"

Expand Down Expand Up @@ -265,7 +291,7 @@
..()

/datum/integrated_io/proc/display_data()
if(!data)
if(isnull(data))
return "(null)" // Empty data means nothing to show.
if(istext(data))
return "(\"[data]\")" // Wraps the 'string' in escaped quotes, so that people know it's a 'string'.
Expand All @@ -281,18 +307,23 @@
if(isnull(data))
return
if(isnum(data))
data = rand(-10000, 10000)
write_data_to_pin(rand(-10000, 10000))
if(istext(data))
data = "ERROR"
write_data_to_pin("ERROR")
push_data()

/datum/integrated_io/activate/scramble()
push_data()

/datum/integrated_io/proc/write_data_to_pin(var/new_data)
if(isnull(new_data) || isnum(new_data) || istext(new_data) || istype(new_data, /atom/) ) // Anything else is a type we don't want.
data = new_data
holder.on_data_written()

/datum/integrated_io/proc/push_data()
if(linked.len)
for(var/datum/integrated_io/io in linked)
io.data = data
io.write_data_to_pin(data)

/datum/integrated_io/activate/push_data()
if(linked.len)
Expand All @@ -302,7 +333,7 @@
/datum/integrated_io/proc/pull_data()
if(linked.len)
for(var/datum/integrated_io/io in linked)
data = io.data
write_data_to_pin(io.data)

/datum/integrated_io/proc/get_linked_to_desc()
if(linked.len)
Expand Down Expand Up @@ -341,8 +372,8 @@
for(var/datum/integrated_io/input/I in inputs)
I.push_data()

/obj/item/integrated_circuit/proc/work()
if(last_used + 2 SECONDS > world.time) // All intergrated circuits have an internal cooldown of two seconds to protect from spam.
/obj/item/integrated_circuit/proc/work(var/datum/integrated_io/io)
if(last_used + cooldown_per_use > world.time) // All intergrated circuits have an internal cooldown, to protect from spam.
return 0
last_used = world.time
return 1
Expand Down
28 changes: 27 additions & 1 deletion code/modules/integrated_electronics/arithmetic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,30 @@
if(..())
var/datum/integrated_io/output/O = outputs[1]
O.data = 3.14159
O.push_data()
O.push_data()

// Random //
/obj/item/integrated_circuit/arithmetic/random
name = "random number generator circuit"
desc = "This gives a random (integer) number between values A and B inclusive."
icon_state = "random"
number_of_inputs = 2
number_of_outputs = 1
number_of_activators = 1
input_names = list(
"L",
"H"
)

/obj/item/integrated_circuit/arithmetic/random/work()
if(..())
var/result = 0
var/datum/integrated_io/L = inputs[1]
var/datum/integrated_io/H = inputs[2]

if(isnum(L.data) && isnum(H.data))
result = rand(L.data, H.data)

for(var/datum/integrated_io/output/O in outputs)
O.data = result
O.push_data()
31 changes: 21 additions & 10 deletions code/modules/integrated_electronics/assemblies.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
desc = "It's a case, for building electronics with."
w_class = 2
icon = 'icons/obj/electronic_assemblies.dmi'
icon_state = "setup"
icon_state = "setup_small"
var/max_components = 10
var/max_complexity = 30
var/opened = 0

/obj/item/device/electronic_assembly/medium
name = "electronic mechanism"
icon_state = "setup_medium"
w_class = 3
max_components = 20
max_complexity = 50

/obj/item/device/electronic_assembly/large
name = "electronic machine"
icon_state = "setup"
w_class = 4
max_components = 30
max_complexity = 60
Expand All @@ -35,16 +37,23 @@
IC.work()
*/

/obj/item/device/electronic_assembly/update_icon()
if(opened)
icon_state = initial(icon_state) + "-open"
else
icon_state = initial(icon_state)

/obj/item/device/electronic_assembly/examine(mob/user)
..()
if(!opened)
for(var/obj/item/integrated_circuit/output/screen/S in contents)
if(S.stuff_to_display)
user << "There's a little screen labeled '[S.name]', which displays '[S.stuff_to_display]'."
else
var/obj/item/integrated_circuit/IC = input(user, "Which circuit do you want to examine?", "Examination") as null|anything in contents
if(IC)
IC.examine(user)
if(user.Adjacent(src))
if(!opened)
for(var/obj/item/integrated_circuit/output/screen/S in contents)
if(S.stuff_to_display)
user << "There's a little screen labeled '[S.name]', which displays '[S.stuff_to_display]'."
else
var/obj/item/integrated_circuit/IC = input(user, "Which circuit do you want to examine?", "Examination") as null|anything in contents
if(IC)
IC.examine(user)

/obj/item/device/electronic_assembly/attackby(var/obj/item/I, var/mob/user)
if(istype(I, /obj/item/integrated_circuit))
Expand Down Expand Up @@ -86,6 +95,7 @@
playsound(src.loc, 'sound/items/Crowbar.ogg', 50, 1)
opened = !opened
user << "<span class='notice'>You [opened ? "opened" : "closed"] \the [src].</span>"
update_icon()
if(istype(I, /obj/item/device/integrated_electronics/wirer))
if(opened)
var/obj/item/integrated_circuit/IC = input(user, "Which circuit do you want to examine?", "Examination") as null|anything in contents
Expand All @@ -98,7 +108,8 @@
/obj/item/device/electronic_assembly/attack_self(mob/user)
var/list/available_inputs = list()
for(var/obj/item/integrated_circuit/input/input in contents)
available_inputs.Add(input)
if(input.can_be_asked_input)
available_inputs.Add(input)
var/obj/item/integrated_circuit/input/choice = input(user, "What do you want to interact with?", "Interaction") as null|anything in available_inputs
if(choice)
choice.ask_for_input(user)
Expand Down
47 changes: 42 additions & 5 deletions code/modules/integrated_electronics/converters.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/obj/item/integrated_circuit/converter/num2text
name = "number to string"
desc = "This circuit can convert a number variable into a string."
icon_state = "addition"
icon_state = "num-string"

/obj/item/integrated_circuit/converter/num2text/work()
if(..())
Expand All @@ -33,7 +33,7 @@
/obj/item/integrated_circuit/converter/text2num
name = "string to number"
desc = "This circuit can convert a string variable into a number."
icon_state = "addition"
icon_state = "string-num"

/obj/item/integrated_circuit/converter/text2num/work()
if(..())
Expand All @@ -49,7 +49,7 @@
/obj/item/integrated_circuit/converter/ref2text
name = "reference to string"
desc = "This circuit can convert a reference to something else to a string, specifically the name of that reference."
icon_state = "addition"
icon_state = "ref-string"

/obj/item/integrated_circuit/converter/ref2text/work()
if(..())
Expand All @@ -66,7 +66,7 @@
/obj/item/integrated_circuit/converter/lowercase
name = "lowercase string converter"
desc = "this will cause a string to come out in all lowercase."
icon_state = "addition"
icon_state = "lowercase"

/obj/item/integrated_circuit/converter/lowercase/work()
if(..())
Expand All @@ -82,7 +82,7 @@
/obj/item/integrated_circuit/converter/uppercase
name = "uppercase string converter"
desc = "THIS WILL CAUSE A STRING TO COME OUT IN ALL UPPERCASE."
icon_state = "addition"
icon_state = "uppercase"

/obj/item/integrated_circuit/converter/uppercase/work()
if(..())
Expand All @@ -92,5 +92,42 @@
if(incoming.data && istext(incoming.data))
result = uppertext(incoming.data)

outgoing.data = result
outgoing.push_data()

/obj/item/integrated_circuit/converter/concatenatior
name = "concatenatior"
desc = "This joins many strings together to get one big string."
complexity = 4
number_of_inputs = 8
number_of_outputs = 1
number_of_activators = 1
input_names = list(
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H"
)
output_names = list(
"result"
)
activator_names = list(
"concatenate"
)


/obj/item/integrated_circuit/converter/concatenatior/work()
if(..())
var/result = null
for(var/datum/integrated_io/input/I in inputs)
I.pull_data()
if(istext(I.data))
result = result + I.data

var/datum/integrated_io/outgoing = outputs[1]
outgoing.data = result
outgoing.push_data()
1 change: 1 addition & 0 deletions code/modules/integrated_electronics/coordinate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/obj/item/integrated_circuit/gps
name = "global positioning system"
desc = "This allows you to easily know the position of a machine containing this device."
icon_state = "gps"
complexity = 4
number_of_inputs = 0
number_of_outputs = 2
Expand Down
Loading

0 comments on commit 4c3528a

Please sign in to comment.