Files
kiwistation/code/modules/recycling/disposal-construction.dm
T
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

286 lines
7.9 KiB
Plaintext

// Disposal pipe construction
// This is the pipe that you drag around, not the attached ones.
/obj/structure/disposalconstruct
name = "disposal pipe segment"
desc = "A huge pipe segment used for constructing disposal systems."
icon = 'icons/obj/atmospherics/pipes/disposal.dmi'
icon_state = "conpipe-s"
anchored = 0
density = 0
pressure_resistance = 5*ONE_ATMOSPHERE
level = 2
obj_integrity = 200
max_integrity = 200
var/ptype = 0
var/dpdir = 0 // directions as disposalpipe
var/base_state = "pipe-s"
/obj/structure/disposalconstruct/examine(mob/user)
..()
user << "<span class='notice'>Alt-click to rotate it clockwise.</span>"
/obj/structure/disposalconstruct/New(var/loc, var/pipe_type, var/direction = 1)
..(loc)
if(pipe_type)
ptype = pipe_type
setDir(direction)
// update iconstate and dpdir due to dir and type
/obj/structure/disposalconstruct/update_icon()
var/flip = turn(dir, 180)
var/left = turn(dir, 90)
var/right = turn(dir, -90)
switch(ptype)
if(DISP_PIPE_STRAIGHT)
base_state = "pipe-s"
dpdir = dir | flip
if(DISP_PIPE_BENT)
base_state = "pipe-c"
dpdir = dir | right
if(DISP_JUNCTION)
base_state = "pipe-j1"
dpdir = dir | right | flip
if(DISP_JUNCTION_FLIP)
base_state = "pipe-j2"
dpdir = dir | left | flip
if(DISP_YJUNCTION)
base_state = "pipe-y"
dpdir = dir | left | right
if(DISP_END_TRUNK)
base_state = "pipe-t"
dpdir = dir
// disposal bin has only one dir, thus we don't need to care about setting it
if(DISP_END_BIN)
if(anchored)
base_state = "disposal"
else
base_state = "condisposal"
if(DISP_END_OUTLET)
base_state = "outlet"
dpdir = dir
if(DISP_END_CHUTE)
base_state = "intake"
dpdir = dir
if(DISP_SORTJUNCTION)
base_state = "pipe-j1s"
dpdir = dir | right | flip
if(DISP_SORTJUNCTION_FLIP)
base_state = "pipe-j2s"
dpdir = dir | left | flip
if(is_pipe())
icon_state = "con[base_state]"
else
icon_state = base_state
// if invisible, fade icon
alpha = (invisibility ? 0 : 255)
// hide called by levelupdate if turf intact status changes
// change visibility status and force update of icon
/obj/structure/disposalconstruct/hide(var/intact)
invisibility = (intact && level==1) ? INVISIBILITY_MAXIMUM: 0 // hide if floor is intact
update_icon()
// flip and rotate verbs
/obj/structure/disposalconstruct/verb/rotate()
set name = "Rotate Pipe"
set category = "Object"
set src in view(1)
if(usr.stat || !usr.canmove || usr.restrained())
return
if(anchored)
usr << "<span class='warning'>You must unfasten the pipe before rotating it!</span>"
return
setDir(turn(dir, -90))
update_icon()
/obj/structure/disposalconstruct/AltClick(mob/user)
..()
if(user.incapacitated())
user << "<span class='warning'>You can't do that right now!</span>"
return
if(!in_range(src, user))
return
else
rotate()
/obj/structure/disposalconstruct/verb/flip()
set name = "Flip Pipe"
set category = "Object"
set src in view(1)
if(usr.stat || !usr.canmove || usr.restrained())
return
if(anchored)
usr << "<span class='warning'>You must unfasten the pipe before flipping it!</span>"
return
setDir(turn(dir, 180))
switch(ptype)
if(DISP_JUNCTION)
ptype = DISP_JUNCTION_FLIP
if(DISP_JUNCTION_FLIP)
ptype = DISP_JUNCTION
if(DISP_SORTJUNCTION)
ptype = DISP_SORTJUNCTION_FLIP
if(DISP_SORTJUNCTION_FLIP)
ptype = DISP_SORTJUNCTION
update_icon()
// returns the type path of disposalpipe corresponding to this item dtype
/obj/structure/disposalconstruct/proc/dpipetype()
switch(ptype)
if(DISP_PIPE_STRAIGHT,DISP_PIPE_BENT)
return /obj/structure/disposalpipe/segment
if(DISP_JUNCTION, DISP_JUNCTION_FLIP, DISP_YJUNCTION)
return /obj/structure/disposalpipe/junction
if(DISP_END_TRUNK)
return /obj/structure/disposalpipe/trunk
if(DISP_END_BIN)
return /obj/machinery/disposal/bin
if(DISP_END_OUTLET)
return /obj/structure/disposaloutlet
if(DISP_END_CHUTE)
return /obj/machinery/disposal/deliveryChute
if(DISP_SORTJUNCTION, DISP_SORTJUNCTION_FLIP)
return /obj/structure/disposalpipe/sortjunction
return
// attackby item
// wrench: (un)anchor
// weldingtool: convert to real pipe
/obj/structure/disposalconstruct/attackby(obj/item/I, mob/user, params)
var/nicetype = "pipe"
var/ispipe = is_pipe() // Indicates if we should change the level of this pipe
add_fingerprint(user)
switch(ptype)
if(DISP_END_BIN)
nicetype = "disposal bin"
if(DISP_END_OUTLET)
nicetype = "disposal outlet"
if(DISP_END_CHUTE)
nicetype = "delivery chute"
if(DISP_SORTJUNCTION, DISP_SORTJUNCTION_FLIP)
nicetype = "sorting pipe"
else
nicetype = "pipe"
var/turf/T = loc
if(T.intact && isfloorturf(T))
user << "<span class='warning'>You can only attach the [nicetype] if the floor plating is removed!</span>"
return
if(!ispipe && iswallturf(T))
user << "<span class='warning'>You can't build [nicetype]s on walls, only disposal pipes!</span>"
return
var/obj/structure/disposalpipe/CP = locate() in T
if(istype(I, /obj/item/weapon/wrench))
if(anchored)
anchored = 0
if(ispipe)
level = 2
density = 0
user << "<span class='notice'>You detach the [nicetype] from the underfloor.</span>"
else
if(!is_pipe()) // Disposal or outlet
if(CP) // There's something there
if(!istype(CP,/obj/structure/disposalpipe/trunk))
user << "<span class='warning'>The [nicetype] requires a trunk underneath it in order to work!</span>"
return
else // Nothing under, fuck.
user << "<span class='warning'>The [nicetype] requires a trunk underneath it in order to work!</span>"
return
else
if(CP)
update_icon()
var/pdir = CP.dpdir
if(istype(CP, /obj/structure/disposalpipe/broken))
pdir = CP.dir
if(pdir & dpdir)
user << "<span class='warning'>There is already a [nicetype] at that location!</span>"
return
anchored = 1
if(ispipe)
level = 1 // We don't want disposal bins to disappear under the floors
density = 0
user << "<span class='notice'>You attach the [nicetype] to the underfloor.</span>"
playsound(loc, 'sound/items/Ratchet.ogg', 100, 1)
update_icon()
else if(istype(I, /obj/item/weapon/weldingtool))
if(anchored)
var/obj/item/weapon/weldingtool/W = I
if(W.remove_fuel(0,user))
playsound(loc, 'sound/items/Welder2.ogg', 100, 1)
user << "<span class='notice'>You start welding the [nicetype] in place...</span>"
if(do_after(user, 20/I.toolspeed, target = src))
if(!loc || !W.isOn())
return
user << "<span class='notice'>The [nicetype] has been welded in place.</span>"
update_icon() // TODO: Make this neat
if(ispipe)
var/pipetype = dpipetype()
var/obj/structure/disposalpipe/P = new pipetype(loc, src)
P.updateicon()
transfer_fingerprints_to(P)
if(ptype == DISP_SORTJUNCTION || ptype == DISP_SORTJUNCTION_FLIP)
var/obj/structure/disposalpipe/sortjunction/SortP = P
SortP.updatedir()
else if(ptype == DISP_END_BIN)
var/obj/machinery/disposal/bin/B = new /obj/machinery/disposal/bin(loc,src)
B.mode = 0 // start with pump off
transfer_fingerprints_to(B)
else if(ptype == DISP_END_OUTLET)
var/obj/structure/disposaloutlet/P = new /obj/structure/disposaloutlet(loc,src)
transfer_fingerprints_to(P)
else if(ptype == DISP_END_CHUTE)
var/obj/machinery/disposal/deliveryChute/P = new /obj/machinery/disposal/deliveryChute(loc,src)
transfer_fingerprints_to(P)
return
else
user << "<span class='warning'>You need to attach it to the plating first!</span>"
return
/obj/structure/disposalconstruct/proc/is_pipe()
return !(ptype >=DISP_END_BIN && ptype <= DISP_END_CHUTE)
//helper proc that makes sure you can place the construct (i.e no dense objects stacking)
/obj/structure/disposalconstruct/proc/can_place()
if(is_pipe())
return 1
for(var/obj/structure/disposalconstruct/DC in get_turf(src))
if(DC == src)
continue
if(!DC.is_pipe()) //there's already a chute/outlet/bin there
return 0
return 1