Assembly Code Clean-up (#10146)

This commit is contained in:
Geeves
2020-10-07 15:11:18 +02:00
committed by GitHub
parent 228df7679e
commit 75cb1d2bdf
17 changed files with 894 additions and 959 deletions
+72 -137
View File
@@ -10,13 +10,13 @@
throw_speed = 3
throw_range = 10
drop_sound = 'sound/items/drop/component.ogg'
pickup_sound = 'sound/items/pickup/component.ogg'
pickup_sound = 'sound/items/pickup/component.ogg'
origin_tech = list(TECH_MAGNET = 1)
var/secured = 1
var/secured = TRUE
var/list/attached_overlays = null
var/obj/item/device/assembly_holder/holder = null
var/cooldown = 0//To prevent spam
var/cooldown = 0 //To prevent spam
var/wires = WIRE_RECEIVE | WIRE_PULSE
var/const/WIRE_RECEIVE = 1 //Allows Pulsed(0) to call Activate()
@@ -25,152 +25,87 @@
var/const/WIRE_RADIO_RECEIVE = 8 //Allows Pulsed(1) to call Activate()
var/const/WIRE_RADIO_PULSE = 16 //Allows Pulse(1) to send a radio message
proc/activate() //What the device does when turned on
return
/obj/item/device/assembly/proc/holder_movement()
return
proc/pulsed(var/radio = 0) //Called when another assembly acts on this one, var/radio will determine where it came from for wire calcs
return
//Called via spawn(10) to have it count down the cooldown var
/obj/item/device/assembly/proc/process_cooldown()
cooldown--
if(cooldown <= 0)
return FALSE
addtimer(CALLBACK(src, .proc/process_cooldown), 1 SECOND)
return TRUE
proc/pulse(var/radio = 0) //Called when this device attempts to act on another device, var/radio determines if it was sent via radio or direct
return
// Called when another assembly acts on this one, var/radio will determine where it came from for wire calcs
/obj/item/device/assembly/proc/pulsed(var/radio = 0)
if(holder && (wires & WIRE_RECEIVE))
activate()
if(radio && (wires & WIRE_RADIO_RECEIVE))
activate()
return TRUE
proc/toggle_secure() //Code that has to happen when the assembly is un\secured goes here
return
// Called when this device attempts to act on another device, var/radio determines if it was sent via radio or direct
/obj/item/device/assembly/proc/pulse(var/radio = 0)
if(holder && (wires & WIRE_PULSE))
holder.process_activation(src, TRUE, FALSE)
if(holder && (wires & WIRE_PULSE_SPECIAL))
holder.process_activation(src, FALSE, TRUE)
return TRUE
proc/attach_assembly(var/obj/A, var/mob/user) //Called when an assembly is attacked by another
return
/obj/item/device/assembly/proc/activate()
if(!secured || cooldown)
return FALSE
cooldown = 2
addtimer(CALLBACK(src, .proc/process_cooldown), 1 SECOND)
return TRUE
proc/process_cooldown() //Called via spawn(10) to have it count down the cooldown var
return
/obj/item/device/assembly/proc/toggle_secure()
secured = !secured
update_icon()
return secured
proc/holder_movement() //Called when the holder is moved
return
// Called when an assembly is attacked by another
/obj/item/device/assembly/proc/attach_assembly(var/obj/item/device/assembly/A, var/mob/user)
holder = new /obj/item/device/assembly_holder(get_turf(src))
if(holder.attach(A, src, user))
to_chat(user, SPAN_NOTICE("You attach \the [A] to \the [src]!"))
return TRUE
return FALSE
interact(mob/user as mob) //Called when attack_self is called
return
process_cooldown()
cooldown--
if(cooldown <= 0) return 0
addtimer(CALLBACK(src, .proc/process_cooldown), 10)
return 1
pulsed(var/radio = 0)
if(holder && (wires & WIRE_RECEIVE))
activate()
if(radio && (wires & WIRE_RADIO_RECEIVE))
activate()
return 1
pulse(var/radio = 0)
if(holder && (wires & WIRE_PULSE))
holder.process_activation(src, 1, 0)
if(holder && (wires & WIRE_PULSE_SPECIAL))
holder.process_activation(src, 0, 1)
// if(radio && (wires & WIRE_RADIO_PULSE))
//Not sure what goes here quite yet send signal?
return 1
activate()
if(!secured || (cooldown > 0)) return 0
cooldown = 2
addtimer(CALLBACK(src, .proc/process_cooldown), 10)
return 1
toggle_secure()
secured = !secured
update_icon()
return secured
attach_assembly(var/obj/item/device/assembly/A, var/mob/user)
holder = new/obj/item/device/assembly_holder(get_turf(src))
if(holder.attach(A,src,user))
to_chat(user, "<span class='notice'>You attach \the [A] to \the [src]!</span>")
return 1
return 0
attackby(obj/item/W as obj, mob/user as mob)
if(isassembly(W))
var/obj/item/device/assembly/A = W
if((!A.secured) && (!secured))
attach_assembly(A,user)
return
if(W.isscrewdriver())
if(toggle_secure())
to_chat(user, "<span class='notice'>\The [src] is ready!</span>")
else
to_chat(user, "<span class='notice'>\The [src] can now be attached!</span>")
/obj/item/device/assembly/attackby(obj/item/W, mob/user)
if(isassembly(W))
var/obj/item/device/assembly/A = W
if(!A.secured && !secured)
attach_assembly(A, user)
return
..()
if(W.isscrewdriver())
if(toggle_secure())
to_chat(user, SPAN_NOTICE("\The [src] is ready!"))
else
to_chat(user, SPAN_NOTICE("\The [src] can now be attached!"))
return
return ..()
/obj/item/device/assembly/process()
STOP_PROCESSING(SSprocessing, src)
return
process()
STOP_PROCESSING(SSprocessing, src)
return
/obj/item/device/assembly/examine(mob/user)
. = ..()
if(. && (in_range(src, user) || loc == user))
if(secured)
to_chat(user, "\The [src] is ready!")
else
to_chat(user, "\The [src] can be attached!")
examine(mob/user)
..(user)
if((in_range(src, user) || loc == user))
if(secured)
to_chat(user, "\The [src] is ready!")
else
to_chat(user, "\The [src] can be attached!")
return
/obj/item/device/assembly/attack_self(mob/user)
if(!user)
return FALSE
interact(user)
return TRUE
attack_self(mob/user as mob)
if(!user) return 0
user.set_machine(src)
interact(user)
return 1
interact(mob/user as mob)
return //HTML MENU FOR WIRES GOES HERE
/*
var/small_icon_state = null//If this obj will go inside the assembly use this for icons
var/list/small_icon_state_overlays = null//Same here
var/obj/holder = null
var/cooldown = 0//To prevent spam
proc
Activate()//Called when this assembly is pulsed by another one
Process_cooldown()//Call this via spawn(10) to have it count down the cooldown var
Attach_Holder(var/obj/H, var/mob/user)//Called when an assembly holder attempts to attach, sets src's loc in here
Activate()
if(cooldown > 0)
return 0
cooldown = 2
spawn(10)
Process_cooldown()
//Rest of code here
return 0
Process_cooldown()
cooldown--
if(cooldown <= 0) return 0
spawn(10)
Process_cooldown()
return 1
Attach_Holder(var/obj/H, var/mob/user)
if(!H) return 0
if(!H.IsAssemblyHolder()) return 0
//Remember to have it set its loc somewhere in here
*/
/obj/item/device/assembly/interact(mob/user)
return