Files
Bubberstation/code/game/machinery/constructable_frame.dm
phil235 5f835bfc26 Obj damaging system, acid damage, and fire damage refactor (WIP) (#20793)
Please refer to #20867 and #20870 for a easier view of the changes. Those two PRs show all meaningful changes (hopefully) and doesn't show the files changed with just 3 lines changed.

This PR does three things:

    It makes all children of /obj/ use the same damage system.
    Previously to make your new machine/structure be destroyable you needed to give it a var/health, and its own version of many damage related proc such as bullet_act(), take_damage(), attacked_by(), attack_animal(), attack_hulk(), ex_act(), etc... But now, all /obj/ use the same version of those procs at the /obj/ level in code/game/obj_defense.dm. All these obj share the same necessary vars: obj_integrity (health), max_integrity, integrity_failure (optional, below that health level failure happens), and the armor list var which was previously only for items, as well as the resistance_flags bitfield. When you want your new object to be destroyable, you only have to give it a value for those vars and maybe override one proc if you want a special behavior but that's it. This reorganization removes a lot of copypasta (most bullet_act() version for each obj were nearly identical). Two new elements are added to the armor list var: fire and acid armor values.
    How much damage an obj take depends on the armor value for each damage category. But some objects are INDESTRUCTIBLE and simply never take any damage no matter the type.
    The armor categories are:
    -melee(punches, item attacks, xeno/animal/hulk attacks, blob attacks, thrown weapons)
    -bullet
    -laser
    -energy (used by projectiles like ionrifle, taser, and also by EMPs)
    -bio (unused for this, only here because clothes use them when worn)
    -rad (same)
    -bomb (self-explanatory)
    -fire (for fire damage, not for heat damage though)
    -acid
    For machines and structures, when their health reaches zero the object is not just deleted but gets somewhat forcedeconstructed (the proc used is shared with the actual deconstruction system) which can drops things. To not frustrates players most of these objects drop most of the elements necessary to rebuild them (think window dropping shards). Machines drop a machine frame and all components for example (but the frame can then be itself smashed to pieces).
    For clothes, when they are damaged, they get a "damaged" overlay, which can also be seen when worn, similar to the "bloody" overlay.

    It refactors acid. See #20537.
    Some objects are ACID_PROOF and take no damage from acid, while others take varying amounts
    of damage depending on their acid armor value. Some objects are even UNACIDABLE, no acid effect can even land on them. Acid on objects can be washed off using water.

    It changes some aspect of damage from fires.
    All /obj/ can now take fire damage and be flammable, instead of just items. And instead of having just FLAMMABLE objs that become ON_FIRE as soon as some fire touch them (paper), we now have objects that are non flammable but do take damage from fire and become ashes if their health reaches zero (only for items). The damage taken varies depending on the obj's fire armor value and total health. There's also still obj and items that are FIRE_PROOF (although some might still be melted by lava if they're not LAVA_PROOF).
    When a mob is on fire, its clothes now take fire damage and can turn to ashes. Similarly, when a mob takes melee damages, its clothes gets damaged a bit and can turn to shreds. You can repair clothes with cloth that is produceable by botany's biogenerator.

    It also does many minor things:
        Clicking a structure/machine with an item on help intent never results in an attack (so you don't destroy a structure while trying to figure out which tool to use).
        I moved a lot of objects away from /obj/effect, it should only be used for visual effects, decals and stuff, not for things you can hit and destroy.
        I tweaked a bit how clothes shredding from bombs work.
        I made a machine or structure un/anchorable with the wrench, I don't remember which object...
        Since I changed the meaning of the FIRE_PROOF bitflag to actually mean fire immune, I'm buffing the slime extract that you apply on items to make them fire proof. well now they're really 100% fire proof!
        animals with environment_smash = 1 no longer one-hit destroy tables and stuff, we give them a decent obj_damage value so they can destroy most obj relatively fast depending on the animal.
        Probably a million things I forgot.

If you want to know how the damage system works all you need is the three obj vars "obj_integrity", "max_integrity", "integrity_failure", as well as the armor list var and the resistance_flags bitfield, and read the file obj_defense.dm
2016-10-10 11:14:59 +13:00

312 lines
10 KiB
Plaintext

/obj/structure/frame
name = "frame"
icon = 'icons/obj/stock_parts.dmi'
icon_state = "box_0"
density = 1
anchored = 1
obj_integrity = 250
max_integrity = 250
var/obj/item/weapon/circuitboard/circuit = null
var/state = 1
/obj/structure/frame/examine(user)
..()
if(circuit)
user << "It has \a [circuit] installed."
/obj/structure/frame/deconstruct(disassembled = TRUE)
if(!(flags & NODECONSTRUCT))
new /obj/item/stack/sheet/metal(loc, 5)
if(circuit)
circuit.forceMove(loc)
circuit = null
qdel(src)
/obj/structure/frame/machine
name = "machine frame"
var/list/components = null
var/list/req_components = null
var/list/req_component_names = null // user-friendly names of components
/obj/structure/frame/machine/examine(user)
..()
if(state == 3 && req_components && req_component_names)
var/hasContent = 0
var/requires = "It requires"
for(var/i = 1 to req_components.len)
var/tname = req_components[i]
var/amt = req_components[tname]
if(amt == 0)
continue
var/use_and = i == req_components.len
requires += "[(hasContent ? (use_and ? ", and" : ",") : "")] [amt] [amt == 1 ? req_component_names[tname] : "[req_component_names[tname]]\s"]"
hasContent = 1
if(hasContent)
user << requires + "."
else
user << "It does not require any more components."
/obj/structure/frame/machine/proc/update_namelist()
if(!req_components)
return
req_component_names = new()
for(var/tname in req_components)
if(ispath(tname, /obj/item/stack))
var/obj/item/stack/S = tname
var/singular_name = initial(S.singular_name)
if(singular_name)
req_component_names[tname] = singular_name
else
req_component_names[tname] = initial(S.name)
else
var/obj/O = tname
req_component_names[tname] = initial(O.name)
/obj/structure/frame/machine/proc/get_req_components_amt()
var/amt = 0
for(var/path in req_components)
amt += req_components[path]
return amt
/obj/structure/frame/machine/attackby(obj/item/P, mob/user, params)
switch(state)
if(1)
if(istype(P, /obj/item/weapon/circuitboard/machine))
user << "<span class='warning'>The frame needs wiring first!</span>"
return
else if(istype(P, /obj/item/weapon/circuitboard))
user << "<span class='warning'>This frame does not accept circuit boards of this type!</span>"
return
if(istype(P, /obj/item/stack/cable_coil))
var/obj/item/stack/cable_coil/C = P
if(C.get_amount() >= 5)
playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
user << "<span class='notice'>You start to add cables to the frame...</span>"
if(do_after(user, 20/P.toolspeed, target = src))
if(C.get_amount() >= 5 && state == 1)
C.use(5)
user << "<span class='notice'>You add cables to the frame.</span>"
state = 2
icon_state = "box_1"
else
user << "<span class='warning'>You need five length of cable to wire the frame!</span>"
return
if(istype(P, /obj/item/weapon/screwdriver) && !anchored)
playsound(src.loc, 'sound/items/Screwdriver.ogg', 50, 1)
user.visible_message("<span class='warning'>[user] disassembles the frame.</span>", \
"<span class='notice'>You start to disassemble the frame...</span>", "You hear banging and clanking.")
if(do_after(user, 40/P.toolspeed, target = src))
if(state == 1)
user << "<span class='notice'>You disassemble the frame.</span>"
var/obj/item/stack/sheet/metal/M = new (loc, 5)
M.add_fingerprint(user)
qdel(src)
return
if(istype(P, /obj/item/weapon/wrench))
user << "<span class='notice'>You start [anchored ? "un" : ""]securing [name]...</span>"
playsound(src.loc, 'sound/items/Ratchet.ogg', 75, 1)
if(do_after(user, 40/P.toolspeed, target = src))
if(state == 1)
user << "<span class='notice'>You [anchored ? "un" : ""]secure [name].</span>"
anchored = !anchored
return
if(2)
if(istype(P, /obj/item/weapon/wrench))
user << "<span class='notice'>You start [anchored ? "un" : ""]securing [name]...</span>"
playsound(src.loc, 'sound/items/Ratchet.ogg', 75, 1)
if(do_after(user, 40/P.toolspeed, target = src))
user << "<span class='notice'>You [anchored ? "un" : ""]secure [name].</span>"
anchored = !anchored
return
if(istype(P, /obj/item/weapon/circuitboard/machine))
if(!anchored)
user << "<span class='warning'>The frame needs to be secured first!</span>"
return
var/obj/item/weapon/circuitboard/machine/B = P
if(!user.drop_item())
return
playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
user << "<span class='notice'>You add the circuit board to the frame.</span>"
circuit = B
B.loc = src
icon_state = "box_2"
state = 3
components = list()
req_components = B.req_components.Copy()
update_namelist()
return
else if(istype(P, /obj/item/weapon/circuitboard))
user << "<span class='warning'>This frame does not accept circuit boards of this type!</span>"
return
if(istype(P, /obj/item/weapon/wirecutters))
playsound(src.loc, 'sound/items/Wirecutter.ogg', 50, 1)
user << "<span class='notice'>You remove the cables.</span>"
state = 1
icon_state = "box_0"
var/obj/item/stack/cable_coil/A = new /obj/item/stack/cable_coil( src.loc )
A.amount = 5
return
if(3)
if(istype(P, /obj/item/weapon/crowbar))
playsound(src.loc, 'sound/items/Crowbar.ogg', 50, 1)
state = 2
circuit.loc = src.loc
components.Remove(circuit)
circuit = null
if(components.len == 0)
user << "<span class='notice'>You remove the circuit board.</span>"
else
user << "<span class='notice'>You remove the circuit board and other components.</span>"
for(var/atom/movable/A in components)
A.loc = src.loc
desc = initial(desc)
req_components = null
components = null
icon_state = "box_1"
return
if(istype(P, /obj/item/weapon/screwdriver))
var/component_check = 1
for(var/R in req_components)
if(req_components[R] > 0)
component_check = 0
break
if(component_check)
playsound(src.loc, 'sound/items/Screwdriver.ogg', 50, 1)
var/obj/machinery/new_machine = new src.circuit.build_path(src.loc, 1)
new_machine.on_construction()
for(var/obj/O in new_machine.component_parts)
qdel(O)
new_machine.component_parts = list()
for(var/obj/O in src)
O.loc = null
new_machine.component_parts += O
circuit.loc = null
new_machine.RefreshParts()
qdel(src)
return
if(istype(P, /obj/item/weapon/storage/part_replacer) && P.contents.len && get_req_components_amt())
var/obj/item/weapon/storage/part_replacer/replacer = P
var/list/added_components = list()
var/list/part_list = list()
//Assemble a list of current parts, then sort them by their rating!
for(var/obj/item/weapon/stock_parts/co in replacer)
part_list += co
//Sort the parts. This ensures that higher tier items are applied first.
part_list = sortTim(part_list, /proc/cmp_rped_sort)
for(var/path in req_components)
while(req_components[path] > 0 && (locate(path) in part_list))
var/obj/item/part = (locate(path) in part_list)
added_components[part] = path
replacer.remove_from_storage(part, src)
req_components[path]--
part_list -= part
for(var/obj/item/weapon/stock_parts/part in added_components)
components += part
user << "<span class='notice'>[part.name] applied.</span>"
if(added_components.len)
replacer.play_rped_sound()
return
if(istype(P, /obj/item) && get_req_components_amt())
for(var/I in req_components)
if(istype(P, I) && (req_components[I] > 0))
if(istype(P, /obj/item/stack))
var/obj/item/stack/S = P
var/used_amt = min(round(S.get_amount()), req_components[I])
if(used_amt && S.use(used_amt))
var/obj/item/stack/NS = locate(S.merge_type) in components
if(!NS)
NS = new S.merge_type(src, used_amt)
components += NS
else
NS.add(used_amt)
req_components[I] -= used_amt
user << "<span class='notice'>You add [P] to [src].</span>"
return
if(!user.drop_item())
break
user << "<span class='notice'>You add [P] to [src].</span>"
P.forceMove(src)
components += P
req_components[I]--
return 1
user << "<span class='warning'>You cannot add that to the machine!</span>"
return 0
if(user.a_intent == "harm")
return ..()
/obj/structure/frame/machine/deconstruct(disassembled = TRUE)
if(!(flags & NODECONSTRUCT))
if(state >= 2)
new /obj/item/stack/cable_coil(loc , 5)
for(var/X in components)
var/obj/item/I = X
I.forceMove(loc)
..()
//Machine Frame Circuit Boards
/*Common Parts: Parts List: Ignitor, Timer, Infra-red laser, Infra-red sensor, t_scanner, Capacitor, Valve, sensor unit,
micro-manipulator, console screen, beaker, Microlaser, matter bin, power cells.
*/
/obj/item/weapon/circuitboard/machine
var/list/req_components = null
// Components required by the machine.
// Example: list(/obj/item/weapon/stock_parts/matter_bin = 5)
var/list/def_components = null
// Default replacements for req_components, to be used in apply_default_parts instead of req_components types
// Example: list(/obj/item/weapon/stock_parts/matter_bin = /obj/item/weapon/stock_parts/matter_bin/super)
/obj/item/weapon/circuitboard/machine/proc/apply_default_parts(obj/machinery/M)
if(!req_components)
return
M.component_parts = list(src) // List of components always contains a board
loc = null
for(var/comp_path in req_components)
var/comp_amt = req_components[comp_path]
if(!comp_amt)
continue
if(def_components && def_components[comp_path])
comp_path = def_components[comp_path]
if(ispath(comp_path, /obj/item/stack))
M.component_parts += new comp_path(null, comp_amt)
else
for(var/i in 1 to comp_amt)
M.component_parts += new comp_path(null)
M.RefreshParts()
/obj/item/weapon/circuitboard/machine/abductor
name = "alien board (Report This)"
icon_state = "abductor_mod"
origin_tech = "programming=5;abductor=3"
/obj/item/weapon/circuitboard/machine/clockwork
name = "clockwork board (Report This)"
icon_state = "clock_mod"