Skip to content

Commit

Permalink
Stage 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Stakks committed Apr 27, 2018
1 parent 9baf20a commit 7ad5c08
Show file tree
Hide file tree
Showing 52 changed files with 2,108 additions and 878 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/obj/item/weapon/implant/integrated_circuit
name = "electronic implant"
desc = "It's a case, for building very tiny electronics with."
icon = 'icons/obj/electronic_assemblies.dmi'
icon_state = "setup_implant"
var/obj/item/device/electronic_assembly/implant/IC = null
Expand Down
40 changes: 35 additions & 5 deletions code/modules/integrated_electronics/_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,44 @@
#define IC_OUTPUT "output"
#define IC_ACTIVATOR "activator"

// Pin functionality.
#define DATA_CHANNEL "data channel"
#define PULSE_CHANNEL "pulse channel"

#define IC_SPAWN_DEFAULT 1 // If the circuit comes in the default circuit box.
#define IC_SPAWN_RESEARCH 2 // If the circuit design will be autogenerated for RnD.
// Methods of obtaining a circuit.
#define IC_SPAWN_DEFAULT 1 // If the circuit comes in the default circuit box and able to be printed in the IC printer.
#define IC_SPAWN_RESEARCH 2 // If the circuit design will be available in the IC printer after upgrading it.

// Displayed along with the pin name to show what type of pin it is.
#define IC_FORMAT_ANY "\<ANY\>"
#define IC_FORMAT_STRING "\<TEXT\>"
#define IC_FORMAT_CHAR "\<CHAR\>"
#define IC_FORMAT_COLOR "\<COLOR\>"
#define IC_FORMAT_NUMBER "\<NUM\>"
#define IC_FORMAT_DIR "\<DIR\>"
#define IC_FORMAT_BOOLEAN "\<BOOL\>"
#define IC_FORMAT_REF "\<REF\>"
#define IC_FORMAT_LIST "\<LIST\>"
#define IC_FORMAT_ANY "\<ANY\>"
#define IC_FORMAT_PULSE "\<PULSE\>"

// Used inside input/output list to tell the constructor what pin to make.
#define IC_PINTYPE_ANY /datum/integrated_io
#define IC_PINTYPE_STRING /datum/integrated_io/string
#define IC_PINTYPE_CHAR /datum/integrated_io/char
#define IC_PINTYPE_COLOR /datum/integrated_io/color
#define IC_PINTYPE_NUMBER /datum/integrated_io/number
#define IC_PINTYPE_DIR /datum/integrated_io/dir
#define IC_PINTYPE_BOOLEAN /datum/integrated_io/boolean
#define IC_PINTYPE_REF /datum/integrated_io/ref
#define IC_PINTYPE_LIST /datum/integrated_io/list

#define IC_PINTYPE_PULSE_IN /datum/integrated_io/activate
#define IC_PINTYPE_PULSE_OUT /datum/integrated_io/activate/out

// Data limits.
#define IC_MAX_LIST_LENGTH 200

//Some colors

#define COLOR_WHITE "#ffffff"
Expand Down Expand Up @@ -52,6 +77,8 @@
#define COLOR_PURPLE_GRAY "#a2819e"
#define COLOR_SUN "#ec8b2f"

var/global/list/alphabet_uppercase = list("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")

var/list/all_integrated_circuits = list()

/proc/initialize_integrated_circuits_list()
Expand All @@ -67,16 +94,19 @@ var/list/all_integrated_circuits = list()
var/obj/item/device/electronic_assembly/assembly = null // Reference to the assembly holding this circuit, if any.
var/extended_desc = null
var/list/inputs = list()
var/list/inputs_default = list() // Assoc list which will fill a pin with data upon creation. e.g. "2" = 0 will set input pin 2 to equal 0 instead of null.
var/list/outputs = list()
var/list/outputs_default = list() // Ditto, for output.
var/list/activators = list()
var/next_use = 0 //Uses world.time
var/complexity = 1 //This acts as a limitation on building machines, more resource-intensive components cost more 'space'.
var/size = null //This acts as a limitation on building machines, bigger components cost more 'space'. -1 for size 0
var/cooldown_per_use = 1 SECONDS // Circuits are limited in how many times they can be work()'d by this variable.
var/power_draw_per_use = 0 // How much power is drawn when work()'d.
var/power_draw_idle = 0 // How much power is drawn when doing nothing.
var/spawn_flags = null // Used for world initializing, see the #defines above.
var/category_text = "NO CATEGORY THIS IS A BUG" // To show up on circuit printer, and perhaps other places.
var/autopulse = -1 // When input is received, the circuit will pulse itself if set to 1. 0 means it won't. -1 means it is permanently off.
var/removable = TRUE // Determines if a circuit is removable from the assembly.


var/displayed_name = ""
var/allow_multitool = 1 // Allows additional multitool functionality
// Used as a global var, (Do not set manually in children).
4 changes: 2 additions & 2 deletions code/modules/integrated_electronics/coordinate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
result_x.data = T.x
result_y.data = T.y

for(var/datum/integrated_io/output/O in outputs)
for(var/datum/integrated_io/O in outputs)
O.push_data()

/obj/item/integrated_circuit/abs_to_rel_coords
Expand All @@ -46,5 +46,5 @@
result_x.data = x1.data - x2.data
result_y.data = y1.data - y2.data

for(var/datum/integrated_io/output/O in outputs)
for(var/datum/integrated_io/O in outputs)
O.push_data()
82 changes: 64 additions & 18 deletions code/modules/integrated_electronics/core/assemblies.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@
/obj/item/device/electronic_assembly/medium
name = "electronic mechanism"
icon_state = "setup_medium"
desc = "It's a case, for building medium-sized electronics with."
w_class = 3
max_components = IC_COMPONENTS_BASE * 2
max_complexity = IC_COMPLEXITY_BASE * 2

/obj/item/device/electronic_assembly/large
name = "electronic machine"
icon_state = "setup_large"
desc = "It's a case, for building large electronics with."
w_class = 4
max_components = IC_COMPONENTS_BASE * 4
max_complexity = IC_COMPLEXITY_BASE * 4

/obj/item/device/electronic_assembly/drone
name = "electronic drone"
icon_state = "setup_drone"
desc = "It's a case, for building mobile electronics with."
w_class = 3
max_components = IC_COMPONENTS_BASE * 1.5
max_complexity = IC_COMPLEXITY_BASE * 1.5

/obj/item/device/electronic_assembly/implant
name = "electronic implant"
icon_state = "setup_implant"
desc = "It's a case, for building very tiny electronics with."
w_class = 1
max_components = IC_COMPONENTS_BASE / 2
max_complexity = IC_COMPLEXITY_BASE / 2
Expand All @@ -45,11 +49,11 @@
/obj/item/device/electronic_assembly/New()
..()
battery = new(src)
SSmachine.processing |= src
SSobj.processing |= src

/obj/item/device/electronic_assembly/Destroy()
battery = null
SSmachine.processing -= src
SSobj.processing -= src
for(var/atom/movable/AM in contents)
qdel(AM)
..()
Expand Down Expand Up @@ -82,14 +86,19 @@
/obj/item/device/electronic_assembly/implant/resolve_nano_host()
return implant

/obj/item/device/electronic_assembly/interact(mob/user)
/obj/item/device/electronic_assembly/proc/check_interactivity(mob/user)
if(!CanInteract(user, src))
return 0
return 1

/obj/item/device/electronic_assembly/interact(mob/user)
if(!check_interactivity(user))
return

var/total_parts = 0
var/total_complexity = 0
for(var/obj/item/integrated_circuit/part in contents)
total_parts++
total_parts += part.size
total_complexity = total_complexity + part.complexity
var/HTML = list()

Expand All @@ -103,14 +112,30 @@
else
HTML += "<span class='danger'>No powercell detected!</span>"
HTML += "<br><br>"
HTML += "Components;<br>"
HTML += "Components:<hr>"
HTML += "Built in:<br>"


//Put removable circuits in separate categories from non-removable
for(var/obj/item/integrated_circuit/circuit in contents)
if(!circuit.removable)
HTML += "<a href=?src=\ref[circuit];examine=1;from_assembly=1>[circuit.displayed_name]</a> | "
HTML += "<a href=?src=\ref[circuit];rename=1;from_assembly=1>\[Rename\]</a> | "
HTML += "<a href=?src=\ref[circuit];scan=1;from_assembly=1>\[Scan with Debugger\]</a> | "
HTML += "<a href=?src=\ref[circuit];bottom=\ref[circuit];from_assembly=1>\[Move to Bottom\]</a>"
HTML += "<br>"

HTML += "<hr>"
HTML += "Removable:<br>"

for(var/obj/item/integrated_circuit/circuit in contents)
HTML += "<a href=?src=\ref[circuit];examine=1>[circuit.name]</a> | "
HTML += "<a href=?src=\ref[circuit];rename=1>\[Rename\]</a> | "
HTML += "<a href=?src=\ref[circuit];scan=1>\[Scan with Debugger\]</a> | "
if(circuit.removable)
HTML += "<a href=?src=\ref[circuit];remove=1>\[Remove\]</a>"
HTML += "<br>"
HTML += "<a href=?src=\ref[circuit];examine=1;from_assembly=1>[circuit.displayed_name]</a> | "
HTML += "<a href=?src=\ref[circuit];rename=1;from_assembly=1>\[Rename\]</a> | "
HTML += "<a href=?src=\ref[circuit];scan=1;from_assembly=1>\[Scan with Debugger\]</a> | "
HTML += "<a href=?src=\ref[circuit];remove=1;from_assembly=1>\[Remove\]</a> | "
HTML += "<a href=?src=\ref[circuit];bottom=\ref[circuit];from_assembly=1>\[Move to Bottom\]</a>"
HTML += "<br>"

HTML += "</body></html>"
user << browse(jointext(HTML,null), "window=assembly-\ref[src];size=600x350;border=1;can_resize=1;can_close=1;can_minimize=1")
Expand Down Expand Up @@ -140,7 +165,7 @@
set desc = "Rename your circuit, useful to stay organized."

var/mob/M = usr
if(!CanInteract(M, src))
if(!check_interactivity(M))
return

var/input = sanitize_text(input("What do you want to name this?", "Rename", src.name) as null|text, MAX_NAME_LEN)
Expand Down Expand Up @@ -179,7 +204,7 @@
/obj/item/device/electronic_assembly/proc/get_part_size()
. = 0
for(var/obj/item/integrated_circuit/part in contents)
. += part.w_class
. += part.size

// Returns true if the circuit made it inside.
/obj/item/device/electronic_assembly/proc/add_circuit(var/obj/item/integrated_circuit/IC, var/mob/user)
Expand All @@ -194,7 +219,7 @@
var/total_part_size = get_part_size()
var/total_complexity = get_part_complexity()

if((total_part_size + IC.w_class) > max_components)
if((total_part_size + IC.size) > max_components)
to_chat(user, "<span class='warning'>You can't seem to add the '[IC.name]', as there's insufficient space.</span>")
return FALSE
if((total_complexity + IC.complexity) > max_complexity)
Expand Down Expand Up @@ -222,16 +247,18 @@
/obj/item/device/electronic_assembly/attackby(var/obj/item/I, var/mob/user)
if(istype(I, /obj/item/integrated_circuit))
if(!user.unEquip(I))
return 0
return FALSE
if(add_circuit(I, user))
to_chat(user, "<span class='notice'>You slide \the [I] inside \the [src].</span>")
playsound(get_turf(src), 'sound/items/Deconstruct.ogg', 50, 1)
interact(user)
return TRUE
else if(istype(I, /obj/item/weapon/crowbar))
playsound(get_turf(src), 'sound/items/Crowbar.ogg', 50, 1)
opened = !opened
user << "<span class='notice'>You [opened ? "opened" : "closed"] \the [src].</span>"
update_icon()
return TRUE
else if(istype(I, /obj/item/device/integrated_electronics/wirer) || istype(I, /obj/item/device/integrated_electronics/debugger) || istype(I, /obj/item/weapon/screwdriver))
if(opened)
interact(user)
Expand All @@ -252,20 +279,38 @@
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>")
interact(user)

return TRUE
else
return ..()

/obj/item/device/electronic_assembly/attack_self(mob/user)
if(!check_interactivity(user))
return
if(opened)
interact(user)

var/list/input_selection = list()
var/list/available_inputs = list()
for(var/obj/item/integrated_circuit/input/input in contents)
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 && CanInteract(user, src))
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)
i++
var/disp_name= "[input.displayed_name] \[[input.name]\]"
if(i)
disp_name += " ([i+1])"
input_selection.Add(disp_name)

var/obj/item/integrated_circuit/input/choice
if(available_inputs)
var/selection = input(user, "What do you want to interact with?", "Interaction") as null|anything in input_selection
if(selection)
var/index = input_selection.Find(selection)
choice = available_inputs[index]

if(choice)
choice.ask_for_input(user)

/obj/item/device/electronic_assembly/emp_act(severity)
Expand All @@ -283,4 +328,5 @@
/obj/item/device/electronic_assembly/proc/give_power(amount)
if(battery && battery.give(amount * CELLRATE))
return TRUE
return FALSE
return FALSE

84 changes: 84 additions & 0 deletions code/modules/integrated_electronics/core/device.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/obj/item/device/assembly/electronic_assembly
name = "electronic device"
desc = "It's a case for building electronics with. It can be attached to other small devices."
icon_state = "setup_device"
var/opened = 0

var/obj/item/device/electronic_assembly/device/EA

/obj/item/device/assembly/electronic_assembly/New()
EA = new(src)
EA.holder = src
..()

/obj/item/device/assembly/electronic_assembly/attackby(obj/item/I as obj, mob/user as mob)
if (istype(I, /obj/item/weapon/crowbar))
toggle_open(user)
else if (opened)
EA.attackby(I, user)
else
..()

/obj/item/device/assembly/electronic_assembly/proc/toggle_open(mob/user)
playsound(get_turf(src), 'sound/items/Crowbar.ogg', 50, 1)
opened = !opened
EA.opened = opened
to_chat(user, "<span class='notice'>You [opened ? "opened" : "closed"] \the [src].</span>")
secured = 1
update_icon()

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

/obj/item/device/assembly/electronic_assembly/attack_self(mob/user as mob)
if(EA)
EA.attack_self(user)

/obj/item/device/assembly/electronic_assembly/pulsed(var/radio = 0) //Called when another assembly acts on this one, var/radio will determine where it came from for wire calcs
if(EA)
for(var/obj/item/integrated_circuit/built_in/device_input/I in EA.contents)
I.do_work()
return

/obj/item/device/assembly/electronic_assembly/examine(mob/user)
.=..(user, 1)
if(EA)
for(var/obj/item/integrated_circuit/IC in EA.contents)
IC.external_examine(user)

/obj/item/device/assembly/electronic_assembly/verb/toggle()
set src in usr
set category = "Object"
set name = "Open/Close Device Assembly"
set desc = "Open or close device assembly!"

toggle_open(usr)


/obj/item/device/electronic_assembly/device
name = "electronic device"
icon_state = "setup_device"
desc = "It's a tiny electronic device with specific use for attaching to other devices."
var/obj/item/device/assembly/electronic_assembly/holder
w_class = 1
max_components = IC_COMPONENTS_BASE * 3/4
max_complexity = IC_COMPLEXITY_BASE * 3/4


/obj/item/device/electronic_assembly/device/New()
..()
var/obj/item/integrated_circuit/built_in/device_input/input = new(src)
var/obj/item/integrated_circuit/built_in/device_output/output = new(src)
input.assembly = src
output.assembly = src

/obj/item/device/electronic_assembly/device/check_interactivity(mob/user)
if(!CanInteract(user,src))
return 0
return 1

Loading

0 comments on commit 7ad5c08

Please sign in to comment.