Files
Bubberstation/code/modules/vehicles/vehicle.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

174 lines
4.0 KiB
Plaintext

/obj/vehicle
name = "vehicle"
desc = "A basic vehicle, vroom"
icon = 'icons/obj/vehicles.dmi'
icon_state = "fuckyou"
density = 1
anchored = 0
can_buckle = 1
buckle_lying = 0
obj_integrity = 300
max_integrity = 300
armor = list(melee = 30, bullet = 30, laser = 30, energy = 0, bomb = 30, bio = 0, rad = 0, fire = 60, acid = 60)
var/keytype = null //item typepath, if non-null an item of this type is needed in your hands to drive this vehicle
var/next_vehicle_move = 0 //used for move delays
var/vehicle_move_delay = 2 //tick delay between movements, lower = faster, higher = slower
var/auto_door_open = TRUE
var/view_range = 7
//Pixels
var/generic_pixel_x = 0 //All dirs show this pixel_x for the driver
var/generic_pixel_y = 0 //All dirs shwo this pixel_y for the driver
/obj/vehicle/New()
..()
handle_vehicle_layer()
//APPEARANCE
/obj/vehicle/proc/handle_vehicle_layer()
if(dir != NORTH)
layer = ABOVE_MOB_LAYER
else
layer = OBJ_LAYER
//Override this to set your vehicle's various pixel offsets
//if they differ between directions, otherwise use the
//generic variables
/obj/vehicle/proc/handle_vehicle_offsets()
if(has_buckled_mobs())
for(var/m in buckled_mobs)
var/mob/living/buckled_mob = m
buckled_mob.setDir(dir)
buckled_mob.pixel_x = generic_pixel_x
buckled_mob.pixel_y = generic_pixel_y
/obj/vehicle/update_icon()
return
//KEYS
/obj/vehicle/proc/keycheck(mob/user)
if(keytype)
if(user.is_holding_item_of_type(keytype))
return 1
else
return 1
return 0
/obj/item/key
name = "key"
desc = "A small grey key."
icon = 'icons/obj/vehicles.dmi'
icon_state = "key"
w_class = 1
//BUCKLE HOOKS
/obj/vehicle/unbuckle_mob(mob/living/buckled_mob,force = 0)
if(istype(buckled_mob))
buckled_mob.pixel_x = 0
buckled_mob.pixel_y = 0
if(buckled_mob.client)
buckled_mob.client.view = world.view
. = ..()
/obj/vehicle/user_buckle_mob(mob/living/M, mob/user)
if(user.incapacitated())
return
for(var/atom/movable/A in get_turf(src))
if(A.density)
if(A != src && A != M)
return
M.loc = get_turf(src)
..()
handle_vehicle_offsets()
if(user.client)
user.client.view = view_range
//MOVEMENT
/obj/vehicle/relaymove(mob/user, direction)
if(user.incapacitated())
unbuckle_mob(user)
return
if(world.time < next_vehicle_move)
return
next_vehicle_move = world.time + vehicle_move_delay
if(keycheck(user))
if(!Process_Spacemove(direction) || !isturf(loc))
return
step(src, direction)
handle_vehicle_layer()
handle_vehicle_offsets()
else
user << "<span class='notice'>You'll need the keys in one of your hands to drive \the [name].</span>"
/obj/vehicle/Move(NewLoc,Dir=0,step_x=0,step_y=0)
. = ..()
handle_vehicle_layer()
handle_vehicle_offsets()
/obj/vehicle/attackby(obj/item/I, mob/user, params)
if(keytype && istype(I, keytype))
user << "Hold [I] in one of your hands while you drive \the [name]."
else
return ..()
/obj/vehicle/Bump(atom/movable/M)
. = ..()
if(auto_door_open)
if(istype(M, /obj/machinery/door) && has_buckled_mobs())
for(var/m in buckled_mobs)
M.Bumped(m)
/obj/vehicle/Process_Spacemove(direction)
if(has_gravity())
return 1
if(pulledby)
return 1
return 0
/obj/vehicle/space
pressure_resistance = INFINITY
/obj/vehicle/space/Process_Spacemove(direction)
return 1
/obj/vehicle/run_obj_armor(damage_amount, damage_type, damage_flag = 0, attack_dir)
if(damage_flag == "melee" && damage_amount < 20)
return 0
. = ..()
/obj/vehicle/deconstruct(disassembled = TRUE)
new /obj/item/stack/sheet/metal (loc, 5)
qdel(src)
/obj/vehicle/examine(mob/user)
..()
if(!(resistance_flags & INDESTRUCTIBLE))
if(resistance_flags & ON_FIRE)
user << "<span class='warning'>It's on fire!</span>"
var/healthpercent = (obj_integrity/max_integrity) * 100
switch(healthpercent)
if(100 to INFINITY)
user << "It seems pristine and undamaged."
if(50 to 100)
user << "It looks slightly damaged."
if(25 to 50)
user << "It appears heavily damaged."
if(0 to 25)
user << "<span class='warning'>It's falling apart!</span>"