mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-12 15:45:25 +01:00
Robot_module and cyborg stack refactor (#13527)
* robot_module refactor * some fixes 1. adds medical stacks of 25 for the syndi medical borg 2. fixes various construction steps that weren't using `use()` or `get_amount()` * review tweaks + other stuff 1. Makes a bunch of for loops into istypeless loops 2. Adds a readout of the current out of stacks a borg has, in the status panel 3. Slightly reorganizes the medical, syndi medical, engineering and syndi engineering cyborgs items * fixes after upstream merge * blank line for travis * fixes and improvements 1. Fixed welder icon's not updating periodically if you were charging in a borg recharger 2. Fixes solar panels dropping /cyborg type glass when they were deconstructed. 3. Band-aid fix (incase #2 doesn't fix this) for cyborg stack's `source` var being null which resulted in tons of "cannot read null.energy" runtimes * more fixes + constructable frame runtime fix * removes toy sword placeholder remove comment * remove these as well * .amount to .get_amount(), really should have done this before * refactors robot_upgrades to work with the new system - more cleanup - adds documentation - fixed a bug I made where you could delete your robot stack via crafting * moves some unemag logic to the module file, makes more loops typless * farie review * fox review * affected review and more TM bugfixes * fixes comment Co-authored-by: SteelSlayer <SteelSlayer@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,16 @@
|
||||
*/
|
||||
/obj/item/stack
|
||||
origin_tech = "materials=1"
|
||||
var/list/recipes = list() // /datum/stack_recipe
|
||||
/// Whether this stack is a `/cyborg` subtype or not.
|
||||
var/is_cyborg = FALSE
|
||||
/// The energy storage datum that will be used with this stack. Used only with `/cyborg` type stacks.
|
||||
var/datum/robot_energy_storage/source
|
||||
/// Which `robot_energy_storage` to choose when this stack is created in cyborgs. Used only with `/cyborg` type stacks.
|
||||
var/energy_type
|
||||
/// How much energy using 1 sheet from the stack costs. Used only with `/cyborg` type stacks.
|
||||
var/cost = 1
|
||||
/// A list of recipes buildable with this stack.
|
||||
var/list/recipes = list()
|
||||
var/singular_name
|
||||
var/amount = 1
|
||||
var/to_transfer = 0
|
||||
@@ -52,15 +61,27 @@
|
||||
|
||||
/obj/item/stack/examine(mob/user)
|
||||
. = ..()
|
||||
if(in_range(user, src))
|
||||
if(!in_range(user, src))
|
||||
return
|
||||
|
||||
if(is_cyborg)
|
||||
if(singular_name)
|
||||
. += "There are [amount] [singular_name]\s in the stack."
|
||||
. += "There is enough energy for [get_amount()] [singular_name]\s."
|
||||
else
|
||||
. += "There are [amount] [name]\s in the stack."
|
||||
. +="<span class='notice'>Alt-click to take a custom amount.</span>"
|
||||
. += "There is enough energy for [get_amount()]."
|
||||
return
|
||||
|
||||
if(singular_name)
|
||||
. += "There are [amount] [singular_name]\s in the stack."
|
||||
else
|
||||
. += "There are [amount] [name]\s in the stack."
|
||||
. +="<span class='notice'>Alt-click to take a custom amount.</span>"
|
||||
|
||||
/obj/item/stack/proc/add(newamount)
|
||||
amount += newamount
|
||||
if(is_cyborg)
|
||||
source.add_charge(newamount * cost)
|
||||
else
|
||||
amount += newamount
|
||||
update_icon()
|
||||
|
||||
/obj/item/stack/attack_self(mob/user)
|
||||
@@ -87,8 +108,10 @@
|
||||
if(!recipes)
|
||||
return
|
||||
|
||||
if(amount <= 0)
|
||||
if(get_amount() <= 0)
|
||||
user << browse(null, "window=stack")
|
||||
if(is_cyborg)
|
||||
to_chat(user, "<span class='warning'>You don't have enough energy to dispense more [name]!</span>")
|
||||
return
|
||||
|
||||
user.set_machine(src) //for correct work of onclose
|
||||
@@ -98,7 +121,7 @@
|
||||
var/datum/stack_recipe_list/srl = recipe_list[recipes_sublist]
|
||||
recipe_list = srl.recipes
|
||||
|
||||
var/t1 = "Amount Left: [amount]<br>"
|
||||
var/t1 = "Amount Left: [get_amount()]<br>"
|
||||
for(var/i in 1 to recipe_list.len)
|
||||
var/E = recipe_list[i]
|
||||
if(isnull(E))
|
||||
@@ -114,7 +137,7 @@
|
||||
|
||||
if(istype(E, /datum/stack_recipe))
|
||||
var/datum/stack_recipe/R = E
|
||||
var/max_multiplier = round(amount / R.req_amount)
|
||||
var/max_multiplier = round(get_amount() / R.req_amount)
|
||||
var/title
|
||||
var/can_build = 1
|
||||
can_build = can_build && (max_multiplier > 0)
|
||||
@@ -154,7 +177,7 @@
|
||||
list_recipes(usr, text2num(href_list["sublist"]))
|
||||
|
||||
if(href_list["make"])
|
||||
if(amount < 1)
|
||||
if(amount < 0 && !is_cyborg)
|
||||
qdel(src) //Never should happen
|
||||
|
||||
var/list/recipes_list = recipes
|
||||
@@ -167,8 +190,8 @@
|
||||
if(!multiplier || multiplier <= 0 || multiplier > 50) // Href exploit checks
|
||||
multiplier = 1
|
||||
|
||||
if(amount < R.req_amount * multiplier)
|
||||
if(R.req_amount * multiplier>1)
|
||||
if(get_amount() < R.req_amount * multiplier)
|
||||
if(R.req_amount * multiplier > 1)
|
||||
to_chat(usr, "<span class='warning'>You haven't got enough [src] to build \the [R.req_amount * multiplier] [R.title]\s!</span>")
|
||||
else
|
||||
to_chat(usr, "<span class='warning'>You haven't got enough [src] to build \the [R.title]!</span>")
|
||||
@@ -195,7 +218,7 @@
|
||||
if(!do_after(usr, R.time, target = usr))
|
||||
return 0
|
||||
|
||||
if(amount < R.req_amount * multiplier)
|
||||
if(get_amount() < R.req_amount * multiplier)
|
||||
return
|
||||
|
||||
var/atom/O
|
||||
@@ -205,6 +228,7 @@
|
||||
O = new R.result_type(usr.drop_location())
|
||||
O.setDir(usr.dir)
|
||||
use(R.req_amount * multiplier)
|
||||
updateUsrDialog()
|
||||
|
||||
R.post_build(src, O)
|
||||
|
||||
@@ -231,6 +255,8 @@
|
||||
/obj/item/stack/use(used, check = TRUE)
|
||||
if(check && zero_amount())
|
||||
return FALSE
|
||||
if(is_cyborg)
|
||||
return source.use_charge(used * cost)
|
||||
if(amount < used)
|
||||
return FALSE
|
||||
amount -= used
|
||||
@@ -240,6 +266,8 @@
|
||||
return TRUE
|
||||
|
||||
/obj/item/stack/proc/get_amount()
|
||||
if(is_cyborg)
|
||||
return round(source.energy / cost)
|
||||
return amount
|
||||
|
||||
/obj/item/stack/proc/get_max_amount()
|
||||
@@ -258,7 +286,7 @@
|
||||
return F
|
||||
|
||||
/obj/item/stack/attack_hand(mob/user)
|
||||
if(user.is_in_inactive_hand(src) && amount > 1)
|
||||
if(user.is_in_inactive_hand(src) && get_amount() > 1)
|
||||
change_stack(user, 1)
|
||||
if(src && usr.machine == src)
|
||||
spawn(0)
|
||||
@@ -272,6 +300,8 @@
|
||||
return
|
||||
if(!in_range(src, user))
|
||||
return
|
||||
if(is_cyborg)
|
||||
return
|
||||
if(!ishuman(usr))
|
||||
return
|
||||
if(amount < 1)
|
||||
@@ -305,11 +335,9 @@
|
||||
// Returns TRUE if the stack amount is zero.
|
||||
// Also qdels the stack gracefully if it is.
|
||||
/obj/item/stack/proc/zero_amount()
|
||||
if(is_cyborg)
|
||||
return source.energy < cost
|
||||
if(amount < 1)
|
||||
if(isrobot(loc))
|
||||
var/mob/living/silicon/robot/R = loc
|
||||
if(locate(src) in R.module.modules)
|
||||
R.module.modules -= src
|
||||
if(ismob(loc))
|
||||
var/mob/living/L = loc // At this stage, stack code is so horrible and atrocious, I wouldn't be all surprised ghosts can somehow have stacks. If this happens, then the world deserves to burn.
|
||||
L.unEquip(src, TRUE)
|
||||
@@ -325,7 +353,10 @@
|
||||
if(QDELETED(S) || QDELETED(src) || S == src) //amusingly this can cause a stack to consume itself, let's not allow that.
|
||||
return FALSE
|
||||
var/transfer = get_amount()
|
||||
transfer = min(transfer, S.max_amount - S.amount)
|
||||
if(S.is_cyborg)
|
||||
transfer = min(transfer, round((S.source.max_energy - S.source.energy) / S.cost))
|
||||
else
|
||||
transfer = min(transfer, S.max_amount - S.amount)
|
||||
if(transfer <= 0)
|
||||
return
|
||||
if(pulledby)
|
||||
@@ -333,6 +364,7 @@
|
||||
S.copy_evidences(src)
|
||||
S.add(transfer)
|
||||
use(transfer)
|
||||
return transfer
|
||||
|
||||
/obj/item/stack/proc/copy_evidences(obj/item/stack/from)
|
||||
blood_DNA = from.blood_DNA
|
||||
|
||||
Reference in New Issue
Block a user