clean up imprint and build functions by reducing nesting and removing g2g variable

This commit is contained in:
nicetoolbox
2020-10-02 01:26:34 -07:00
parent c9e60e63d5
commit 551c3973c4
+118 -118
View File
@@ -452,137 +452,137 @@ won't update every console in existence) but it's more of a hassle to do. Also,
sync = !sync
if("build") //Causes the Protolathe to build something.
if(linked_lathe)
if(linked_lathe.busy)
to_chat(usr, "<span class='danger'>[linked_lathe] is busy at the moment.</span>")
return TRUE
var/coeff = linked_lathe.efficiency_coeff
var/g2g = 1
var/datum/design/being_built = files.known_designs[params["id"]]
if(being_built)
var/power = 2000
var/amount = text2num(params["amount"])
if(being_built.make_reagents.len)
return FALSE
amount = max(1, min(10, amount))
for(var/M in being_built.materials)
power += round(being_built.materials[M] * amount / 5)
power = max(2000, power)
var/key = usr.key //so we don't lose the info during the spawn delay
if(!(being_built.build_type & PROTOLATHE))
g2g = 0
message_admins("Protolathe exploit attempted by [key_name(usr, TRUE)]!")
if(!linked_lathe)
return
if(linked_lathe.busy)
to_chat(usr, "<span class='danger'>[linked_lathe] is busy at the moment.</span>")
return
var/coeff = linked_lathe.efficiency_coeff
var/datum/design/being_built = files.known_designs[params["id"]]
if(!being_built)
return
var/power = BUILD_POWER
var/amount = text2num(params["amount"])
if(being_built.make_reagents.len)
return FALSE
amount = max(1, min(10, amount))
for(var/M in being_built.materials)
power += round(being_built.materials[M] * amount / 5)
power = max(BUILD_POWER, power)
var/key = usr.key //so we don't lose the info during the spawn delay
if(!(being_built.build_type & PROTOLATHE))
message_admins("Protolathe exploit attempted by [key_name(usr, TRUE)]!")
return
if(g2g) //If input is incorrect, nothing happens
var/new_coeff = coeff * being_built.lathe_time_factor
var/time_to_construct = PROTOLATHE_CONSTRUCT_DELAY * new_coeff * amount ** 0.8
var/enough_materials = 1
var/new_coeff = coeff * being_built.lathe_time_factor
var/time_to_construct = PROTOLATHE_CONSTRUCT_DELAY * new_coeff * amount ** 0.8
var/enough_materials = TRUE
add_wait_message("Constructing Prototype. Please Wait...", time_to_construct)
linked_lathe.busy = TRUE
flick("protolathe_n", linked_lathe)
use_power(power)
add_wait_message("Constructing Prototype. Please Wait...", time_to_construct)
linked_lathe.busy = TRUE
flick("protolathe_n", linked_lathe)
use_power(power)
var/list/efficient_mats = list()
for(var/MAT in being_built.materials)
efficient_mats[MAT] = being_built.materials[MAT] * coeff
var/list/efficient_mats = list()
for(var/MAT in being_built.materials)
efficient_mats[MAT] = being_built.materials[MAT] * coeff
if(!linked_lathe.materials.has_materials(efficient_mats, amount))
atom_say("Not enough materials to complete prototype.")
enough_materials = FALSE
g2g = FALSE
if(!linked_lathe.materials.has_materials(efficient_mats, amount))
atom_say("Not enough materials to complete prototype.")
enough_materials = FALSE
else
for(var/R in being_built.reagents_list)
if(!linked_lathe.reagents.has_reagent(R, being_built.reagents_list[R]) * coeff)
atom_say("Not enough reagents to complete prototype.")
enough_materials = FALSE
if(enough_materials)
linked_lathe.materials.use_amount(efficient_mats, amount)
for(var/R in being_built.reagents_list)
linked_lathe.reagents.remove_reagent(R, being_built.reagents_list[R]*coeff)
var/P = being_built.build_path //lets save these values before the spawn() just in case. Nobody likes runtimes.
var/O = being_built.locked
spawn(time_to_construct)
if(enough_materials) //And if we only fail the material requirements, we still spend time and power
for(var/i = 0, i<amount, i++)
var/obj/item/new_item = new P(src)
if(istype(new_item, /obj/item/storage/backpack/holding))
new_item.investigate_log("built by [key]","singulo")
if(!istype(new_item, /obj/item/stack/sheet)) // To avoid materials dupe glitches
new_item.materials = efficient_mats.Copy()
if(O)
var/obj/item/storage/lockbox/research/L = new/obj/item/storage/lockbox/research(linked_lathe.loc)
new_item.forceMove(L)
L.name += " ([new_item.name])"
L.origin_tech = new_item.origin_tech
L.req_access = being_built.access_requirement
var/list/lockbox_access
for(var/A in L.req_access)
lockbox_access += "[get_access_desc(A)] "
L.desc = "A locked box. It is locked to [lockbox_access]access."
else
for(var/R in being_built.reagents_list)
if(!linked_lathe.reagents.has_reagent(R, being_built.reagents_list[R]) * coeff)
atom_say("Not enough reagents to complete prototype.")
enough_materials = FALSE
g2g = FALSE
if(enough_materials)
linked_lathe.materials.use_amount(efficient_mats, amount)
for(var/R in being_built.reagents_list)
linked_lathe.reagents.remove_reagent(R, being_built.reagents_list[R]*coeff)
var/P = being_built.build_path //lets save these values before the spawn() just in case. Nobody likes runtimes.
var/O = being_built.locked
spawn(time_to_construct)
if(g2g) //And if we only fail the material requirements, we still spend time and power
for(var/i = 0, i<amount, i++)
var/obj/item/new_item = new P(src)
if(istype(new_item, /obj/item/storage/backpack/holding))
new_item.investigate_log("built by [key]","singulo")
if(!istype(new_item, /obj/item/stack/sheet)) // To avoid materials dupe glitches
new_item.materials = efficient_mats.Copy()
if(O)
var/obj/item/storage/lockbox/research/L = new/obj/item/storage/lockbox/research(linked_lathe.loc)
new_item.forceMove(L)
L.name += " ([new_item.name])"
L.origin_tech = new_item.origin_tech
L.req_access = being_built.access_requirement
var/list/lockbox_access
for(var/A in L.req_access)
lockbox_access += "[get_access_desc(A)] "
L.desc = "A locked box. It is locked to [lockbox_access]access."
else
new_item.loc = linked_lathe.loc
clear_wait_message()
linked_lathe.busy = FALSE
SStgui.update_uis(src)
new_item.loc = linked_lathe.loc
clear_wait_message()
linked_lathe.busy = FALSE
SStgui.update_uis(src)
if("imprint") //Causes the Circuit Imprinter to build something.
var/coeff = linked_imprinter.efficiency_coeff
var/g2g = 1
var/enough_materials = 1
if(linked_imprinter)
if(linked_imprinter.busy)
to_chat(usr, "<span class='danger'>Circuit Imprinter is busy at the moment.</span>")
return
var/datum/design/being_built = null
being_built = files.known_designs[params["id"]]
if(being_built)
var/power = 2000
for(var/M in being_built.materials)
power += round(being_built.materials[M] / 5)
power = max(2000, power)
if(!(being_built.build_type & IMPRINTER))
g2g = 0
message_admins("Circuit imprinter exploit attempted by [key_name(usr, TRUE)]!")
var/enough_materials = TRUE
if(!linked_imprinter)
return
if(g2g) //Again, if input is wrong, do nothing
add_wait_message("Imprinting Circuit. Please Wait...", IMPRINTER_DELAY)
linked_imprinter.busy = 1
flick("circuit_imprinter_ani",linked_imprinter)
use_power(power)
if(linked_imprinter.busy)
to_chat(usr, "<span class='danger'>Circuit Imprinter is busy at the moment.</span>")
return
var/list/efficient_mats = list()
for(var/MAT in being_built.materials)
efficient_mats[MAT] = being_built.materials[MAT]/coeff
var/datum/design/being_built = null
being_built = files.known_designs[params["id"]]
if(!being_built)
return
if(!linked_imprinter.materials.has_materials(efficient_mats))
visible_message("<span class='notice'>The [src.name] beeps, \"Not enough materials to complete prototype.\"</span>")
enough_materials = 0
g2g = 0
else
for(var/R in being_built.reagents_list)
if(!linked_imprinter.reagents.has_reagent(R, being_built.reagents_list[R]/coeff))
visible_message("<span class='notice'>The [name] beeps, \"Not enough reagents to complete prototype.\"</span>")
enough_materials = 0
g2g = 0
if(!(being_built.build_type & IMPRINTER))
message_admins("Circuit imprinter exploit attempted by [key_name(usr, TRUE)]!")
return
if(enough_materials)
linked_imprinter.materials.use_amount(efficient_mats)
for(var/R in being_built.reagents_list)
linked_imprinter.reagents.remove_reagent(R, being_built.reagents_list[R]/coeff)
var/power = BUILD_POWER
for(var/M in being_built.materials)
power += round(being_built.materials[M] / 5)
power = max(BUILD_POWER, power)
var/P = being_built.build_path //lets save these values before the spawn() just in case. Nobody likes runtimes.
spawn(IMPRINTER_DELAY)
if(g2g)
var/obj/item/new_item = new P(src)
new_item.loc = linked_imprinter.loc
linked_imprinter.busy = 0
clear_wait_message()
SStgui.update_uis(src)
add_wait_message("Imprinting Circuit. Please Wait...", IMPRINTER_DELAY)
linked_imprinter.busy = TRUE
flick("circuit_imprinter_ani", linked_imprinter)
use_power(power)
var/list/efficient_mats = list()
for(var/MAT in being_built.materials)
efficient_mats[MAT] = being_built.materials[MAT] / coeff
if(!linked_imprinter.materials.has_materials(efficient_mats))
visible_message("<span class='notice'>The [src.name] beeps, \"Not enough materials to complete prototype.\"</span>")
enough_materials = FALSE
else
for(var/R in being_built.reagents_list)
if(!linked_imprinter.reagents.has_reagent(R, being_built.reagents_list[R] / coeff))
visible_message("<span class='notice'>The [name] beeps, \"Not enough reagents to complete prototype.\"</span>")
enough_materials = FALSE
if(enough_materials)
linked_imprinter.materials.use_amount(efficient_mats)
for(var/R in being_built.reagents_list)
linked_imprinter.reagents.remove_reagent(R, being_built.reagents_list[R]/coeff)
var/P = being_built.build_path //lets save these values before the spawn() just in case. Nobody likes runtimes.
spawn(IMPRINTER_DELAY)
if(enough_materials)
var/obj/item/new_item = new P(src)
new_item.loc = linked_imprinter.loc
linked_imprinter.busy = FALSE
clear_wait_message()
SStgui.update_uis(src)
if("disposeI") //Causes the circuit imprinter to dispose of a single reagent (all of it)
if(linked_imprinter)