mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-29 18:40:42 +00:00
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
354 lines
10 KiB
Plaintext
354 lines
10 KiB
Plaintext
//This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:33
|
|
|
|
|
|
/*
|
|
field_generator power level display
|
|
The icon used for the field_generator need to have 'num_power_levels' number of icon states
|
|
named 'Field_Gen +p[num]' where 'num' ranges from 1 to 'num_power_levels'
|
|
|
|
The power level is displayed using overlays. The current displayed power level is stored in 'powerlevel'.
|
|
The overlay in use and the powerlevel variable must be kept in sync. A powerlevel equal to 0 means that
|
|
no power level overlay is currently in the overlays list.
|
|
-Aygar
|
|
*/
|
|
|
|
#define field_generator_max_power 250
|
|
|
|
#define FG_UNSECURED 0
|
|
#define FG_SECURED 1
|
|
#define FG_WELDED 2
|
|
|
|
#define FG_OFFLINE 0
|
|
#define FG_CHARGING 1
|
|
#define FG_ONLINE 2
|
|
|
|
/obj/machinery/field/generator
|
|
name = "field generator"
|
|
desc = "A large thermal battery that projects a high amount of energy when powered."
|
|
icon = 'icons/obj/machines/field_generator.dmi'
|
|
icon_state = "Field_Gen"
|
|
anchored = 0
|
|
density = 1
|
|
use_power = 0
|
|
obj_integrity = 500
|
|
max_integrity = 500
|
|
//100% immune to lasers and energy projectiles since it absorbs their energy.
|
|
armor = list(melee = 25, bullet = 10, laser = 100, energy = 100, bomb = 0, bio = 0, rad = 0, fire = 50, acid = 70)
|
|
var/const/num_power_levels = 6 // Total number of power level icon has
|
|
var/power_level = 0
|
|
var/active = FG_OFFLINE
|
|
var/power = 20 // Current amount of power
|
|
var/state = FG_UNSECURED
|
|
var/warming_up = 0
|
|
var/list/obj/machinery/field/containment/fields
|
|
var/list/obj/machinery/field/generator/connected_gens
|
|
var/clean_up = 0
|
|
|
|
/obj/machinery/field/generator/update_icon()
|
|
cut_overlays()
|
|
if(warming_up)
|
|
add_overlay("+a[warming_up]")
|
|
if(fields.len)
|
|
add_overlay("+on")
|
|
if(power_level)
|
|
add_overlay("+p[power_level]")
|
|
|
|
|
|
/obj/machinery/field/generator/New()
|
|
..()
|
|
fields = list()
|
|
connected_gens = list()
|
|
|
|
|
|
/obj/machinery/field/generator/process()
|
|
if(active == FG_ONLINE)
|
|
calc_power()
|
|
|
|
/obj/machinery/field/generator/attack_hand(mob/user)
|
|
if(state == FG_WELDED)
|
|
if(get_dist(src, user) <= 1)//Need to actually touch the thing to turn it on
|
|
if(active >= FG_CHARGING)
|
|
user << "<span class='warning'>You are unable to turn off the [name] once it is online!</span>"
|
|
return 1
|
|
else
|
|
user.visible_message("[user.name] turns on the [name].", \
|
|
"<span class='notice'>You turn on the [name].</span>", \
|
|
"<span class='italics'>You hear heavy droning.</span>")
|
|
turn_on()
|
|
investigate_log("<font color='green'>activated</font> by [user.key].","singulo")
|
|
|
|
add_fingerprint(user)
|
|
else
|
|
user << "<span class='warning'>The [src] needs to be firmly secured to the floor first!</span>"
|
|
|
|
|
|
/obj/machinery/field/generator/attackby(obj/item/W, mob/user, params)
|
|
if(active)
|
|
user << "<span class='warning'>The [src] needs to be off!</span>"
|
|
return
|
|
else if(istype(W, /obj/item/weapon/wrench))
|
|
switch(state)
|
|
if(FG_UNSECURED)
|
|
if(isinspace()) return
|
|
state = FG_SECURED
|
|
playsound(loc, 'sound/items/Ratchet.ogg', 75, 1)
|
|
user.visible_message("[user.name] secures [name] to the floor.", \
|
|
"<span class='notice'>You secure the external reinforcing bolts to the floor.</span>", \
|
|
"<span class='italics'>You hear ratchet.</span>")
|
|
anchored = 1
|
|
if(FG_SECURED)
|
|
state = FG_UNSECURED
|
|
playsound(loc, 'sound/items/Ratchet.ogg', 75, 1)
|
|
user.visible_message("[user.name] unsecures [name] reinforcing bolts from the floor.", \
|
|
"<span class='notice'>You undo the external reinforcing bolts.</span>", \
|
|
"<span class='italics'>You hear ratchet.</span>")
|
|
anchored = 0
|
|
if(FG_WELDED)
|
|
user << "<span class='warning'>The [name] needs to be unwelded from the floor!</span>"
|
|
|
|
else if(istype(W, /obj/item/weapon/weldingtool))
|
|
var/obj/item/weapon/weldingtool/WT = W
|
|
switch(state)
|
|
if(FG_UNSECURED)
|
|
user << "<span class='warning'>The [name] needs to be wrenched to the floor!</span>"
|
|
|
|
if(FG_SECURED)
|
|
if (WT.remove_fuel(0,user))
|
|
playsound(loc, 'sound/items/Welder2.ogg', 50, 1)
|
|
user.visible_message("[user.name] starts to weld the [name] to the floor.", \
|
|
"<span class='notice'>You start to weld \the [src] to the floor...</span>", \
|
|
"<span class='italics'>You hear welding.</span>")
|
|
if (do_after(user,20/W.toolspeed, target = src))
|
|
if(!src || !WT.isOn()) return
|
|
state = FG_WELDED
|
|
user << "<span class='notice'>You weld the field generator to the floor.</span>"
|
|
|
|
if(FG_WELDED)
|
|
if (WT.remove_fuel(0,user))
|
|
playsound(loc, 'sound/items/Welder2.ogg', 50, 1)
|
|
user.visible_message("[user.name] starts to cut the [name] free from the floor.", \
|
|
"<span class='notice'>You start to cut \the [src] free from the floor...</span>", \
|
|
"<span class='italics'>You hear welding.</span>")
|
|
if (do_after(user,20/W.toolspeed, target = src))
|
|
if(!src || !WT.isOn()) return
|
|
state = FG_SECURED
|
|
user << "<span class='notice'>You cut \the [src] free from the floor.</span>"
|
|
|
|
else
|
|
return ..()
|
|
|
|
/obj/machinery/field/generator/attack_animal(mob/living/simple_animal/M)
|
|
if(M.environment_smash >= 3 && active == FG_OFFLINE && state != FG_UNSECURED)
|
|
state = FG_UNSECURED
|
|
anchored = FALSE
|
|
M.visible_message("<span class='warning'>[M] rips [src] free from its moorings!</span>")
|
|
else
|
|
..()
|
|
if(!anchored)
|
|
step(src, get_dir(M, src))
|
|
|
|
/obj/machinery/field/generator/emp_act()
|
|
return 0
|
|
|
|
|
|
/obj/machinery/field/generator/blob_act(obj/structure/blob/B)
|
|
if(active)
|
|
return 0
|
|
else
|
|
..()
|
|
|
|
/obj/machinery/field/generator/bullet_act(obj/item/projectile/Proj)
|
|
if(Proj.flag != "bullet")
|
|
power = min(power + Proj.damage, field_generator_max_power)
|
|
check_power_level()
|
|
..()
|
|
|
|
|
|
/obj/machinery/field/generator/Destroy()
|
|
cleanup()
|
|
return ..()
|
|
|
|
|
|
/obj/machinery/field/generator/proc/check_power_level()
|
|
var/new_level = round(num_power_levels * power / field_generator_max_power)
|
|
if(new_level != power_level)
|
|
power_level = new_level
|
|
update_icon()
|
|
|
|
/obj/machinery/field/generator/proc/turn_off()
|
|
active = FG_OFFLINE
|
|
spawn(1)
|
|
cleanup()
|
|
while (warming_up>0 && !active)
|
|
sleep(50)
|
|
warming_up--
|
|
update_icon()
|
|
|
|
/obj/machinery/field/generator/proc/turn_on()
|
|
active = FG_CHARGING
|
|
spawn(1)
|
|
while (warming_up<3 && active)
|
|
sleep(50)
|
|
warming_up++
|
|
update_icon()
|
|
if(warming_up >= 3)
|
|
start_fields()
|
|
|
|
|
|
/obj/machinery/field/generator/proc/calc_power(set_power_draw)
|
|
var/power_draw = 2 + fields.len
|
|
if(set_power_draw)
|
|
power_draw = set_power_draw
|
|
|
|
if(draw_power(round(power_draw/2,1)))
|
|
check_power_level()
|
|
return 1
|
|
else
|
|
visible_message("<span class='danger'>The [name] shuts down!</span>", "<span class='italics'>You hear something shutting down.</span>")
|
|
turn_off()
|
|
investigate_log("ran out of power and <font color='red'>deactivated</font>","singulo")
|
|
power = 0
|
|
check_power_level()
|
|
return 0
|
|
|
|
//This could likely be better, it tends to start loopin if you have a complex generator loop setup. Still works well enough to run the engine fields will likely recode the field gens and fields sometime -Mport
|
|
/obj/machinery/field/generator/proc/draw_power(draw = 0, failsafe = 0, obj/machinery/field/generator/G = null, obj/machinery/field/generator/last = null)
|
|
if((G && (G == src)) || (failsafe >= 8))//Loopin, set fail
|
|
return 0
|
|
else
|
|
failsafe++
|
|
|
|
if(power >= draw)//We have enough power
|
|
power -= draw
|
|
return 1
|
|
|
|
else//Need more power
|
|
draw -= power
|
|
power = 0
|
|
for(var/CG in connected_gens)
|
|
var/obj/machinery/field/generator/FG = CG
|
|
if(FG == last)//We just asked you
|
|
continue
|
|
if(G)//Another gen is askin for power and we dont have it
|
|
if(FG.draw_power(draw,failsafe,G,src))//Can you take the load
|
|
return 1
|
|
else
|
|
return 0
|
|
else//We are askin another for power
|
|
if(FG.draw_power(draw,failsafe,src,src))
|
|
return 1
|
|
else
|
|
return 0
|
|
|
|
|
|
/obj/machinery/field/generator/proc/start_fields()
|
|
if(state != FG_WELDED || !anchored)
|
|
turn_off()
|
|
return
|
|
spawn(1)
|
|
setup_field(1)
|
|
spawn(2)
|
|
setup_field(2)
|
|
spawn(3)
|
|
setup_field(4)
|
|
spawn(4)
|
|
setup_field(8)
|
|
spawn(5)
|
|
active = FG_ONLINE
|
|
|
|
|
|
/obj/machinery/field/generator/proc/setup_field(NSEW)
|
|
var/turf/T = loc
|
|
if(!istype(T))
|
|
return 0
|
|
|
|
var/obj/machinery/field/generator/G = null
|
|
var/steps = 0
|
|
if(!NSEW)//Make sure its ran right
|
|
return 0
|
|
for(var/dist in 0 to 7) // checks out to 8 tiles away for another generator
|
|
T = get_step(T, NSEW)
|
|
if(T.density)//We cant shoot a field though this
|
|
return 0
|
|
|
|
G = locate(/obj/machinery/field/generator) in T
|
|
if(G)
|
|
steps -= 1
|
|
if(!G.active)
|
|
return 0
|
|
break
|
|
|
|
for(var/TC in T.contents)
|
|
var/atom/A = TC
|
|
if(ismob(A))
|
|
continue
|
|
if(A.density)
|
|
return 0
|
|
|
|
steps++
|
|
|
|
if(!G)
|
|
return 0
|
|
|
|
T = loc
|
|
for(var/dist in 0 to steps) // creates each field tile
|
|
var/field_dir = get_dir(T,get_step(G.loc, NSEW))
|
|
T = get_step(T, NSEW)
|
|
if(!locate(/obj/machinery/field/containment) in T)
|
|
var/obj/machinery/field/containment/CF = new/obj/machinery/field/containment()
|
|
CF.set_master(src,G)
|
|
CF.loc = T
|
|
CF.setDir(field_dir)
|
|
fields += CF
|
|
G.fields += CF
|
|
for(var/mob/living/L in T)
|
|
CF.Crossed(L)
|
|
|
|
connected_gens |= G
|
|
G.connected_gens |= src
|
|
update_icon()
|
|
|
|
|
|
/obj/machinery/field/generator/proc/cleanup()
|
|
clean_up = 1
|
|
for (var/F in fields)
|
|
qdel(F)
|
|
|
|
for(var/CG in connected_gens)
|
|
var/obj/machinery/field/generator/FG = CG
|
|
FG.connected_gens -= src
|
|
if(!FG.clean_up)//Makes the other gens clean up as well
|
|
FG.cleanup()
|
|
connected_gens -= FG
|
|
clean_up = 0
|
|
update_icon()
|
|
|
|
//This is here to help fight the "hurr durr, release singulo cos nobody will notice before the
|
|
//singulo eats the evidence". It's not fool-proof but better than nothing.
|
|
//I want to avoid using global variables.
|
|
spawn(1)
|
|
var/temp = 1 //stops spam
|
|
for(var/obj/singularity/O in world)
|
|
if(O.last_warning && temp)
|
|
if((world.time - O.last_warning) > 50) //to stop message-spam
|
|
temp = 0
|
|
message_admins("A singulo exists and a containment field has failed.",1)
|
|
investigate_log("has <font color='red'>failed</font> whilst a singulo exists.","singulo")
|
|
O.last_warning = world.time
|
|
|
|
/obj/machinery/field/generator/shock(mob/living/user)
|
|
if(fields.len)
|
|
..()
|
|
|
|
/obj/machinery/field/generator/bump_field(atom/movable/AM as mob|obj)
|
|
if(fields.len)
|
|
..()
|
|
|
|
#undef FG_UNSECURED
|
|
#undef FG_SECURED
|
|
#undef FG_WELDED
|
|
|
|
#undef FG_OFFLINE
|
|
#undef FG_CHARGING
|
|
#undef FG_ONLINE
|