Files
kiwistation/code/game/machinery/deployable.dm
T
silicons 160175ee8b pass_flags handling refactor + rewrites a part of projectiles for the n-th time (#54924)
Yeah uhh this'll probably need testmerging even after it's done because yeah it's a bit big.
If y'all want me to atomize this into two PRs (pass flags vs projectiles) tell me please. Pass flags would have to go in first though, in that case, as new projectile hit handling will rely on pass_flags_self.
Pass flags:

Pass flags handling now uses an atom variable named pass_flags_self.
If any of these match a pass_flag on a thing trying to pass through, it's allowed through by default.
This makes overriding CanAllowThrough unnecessary for the majority of things. I've however not removed overrides for very.. weird cases, like plastic flaps which uses a prob(60) for letting PASSGLASS things through for god knows why.
LETPASSTHROW is now on pass_flags_self
Projectiles:

Not finalized yet, need to do something to make the system I have in mind have less unneeded overhead + snowflake

Basically, for piercing/phasing/otherwise projectiles that go through things instead of hitting the first dense object, I have them use pass_flags flags for two new variables, projectile_phasing and projectile_piercing. Anything with pass_flags_self in the former gets phased through entirely. Anything in the latter gets hit, and the projectile then goes through. on_hit will also register a piercing hit vs a normal hit (so things like missiles can only explode on a normal hit or otherwise, instead of exploding multiple times. Not needed as missiles qdel(src) right now but it's nice to have for the future).

I still need to decide what to do for hit handling proper, as Bump() is still preferred due to it not being as high-overhead as something like scanning on Moved(). I'm thinking I'll make Moved() only scan for cases where it needs to hit a non-dense object - a prone human the user clicked on, anything special like that. Don't know the exact specifics yet, which is why this is still WIP.

Projectiles now use check_pierce() to determine if it goes through something and hits it, doesn't hit it, or doesn't go through something at all (should delete self after hitting). Will likely make an on_pierce proc to be called post-piercing something so you can have !fun! things like projectiles that go down in damage after piercing something. This will likely deprecate the process_hit proc, or at least make it less awful.

scan_for_hit() is now used to attempt to hit something and will return whether the projectile got deleted or not. It will delete the projectile if the projectile does hit something and fails to pierce through it.

scan_moved_turf() (WIP) will be used for handling moving onto a turf.

permutated has been renamed to impacted. Ricocheting projectiles get it reset, allowing projectiles to pierce and potentially hit something again if it goes back around.

A new unit test has been added checking for projectiles with movement type of PHASING. This is because PHASING completely causes projectiles to break down as projectiles mainly sense collisions through Bump. The small boost in performance from using PHASING instead of having all pass flags active/overriding check_pierce is in my opinion not worth the extra snowflake in scan_moved_turf() I'd have to do to deal with having to check for hits manually rather than Bump()ing things.
Movement types

UNSTOPPABLE renamed to PHASING to better describe what it is, going through and crossing everything but not actually bumping.
Why It's Good For The Game

Better pass flags handling allows for less proc overrides, bitflag checks are far less expensive in general.

Fixes penetrating projectiles like sniper penetrators

This system also allows for better handling of piercing projectiles (see above) without too much snowflake code, as you'd only need to modify on_pierce() if you needed to do special handling like dampening damage per target pierced, and otherwise you could just use the standardized system and just set pass flags to what's needed. If you really need a projectile that pierces almost everything, override check_pierce(), which is still going to be easier than what was done before (even with snowflake handling of UNSTOPPABLE flag process_hit() was extremely ugly, now we don't rely on movement types at all.)
2020-12-10 09:29:27 +13:00

203 lines
5.6 KiB
Plaintext

#define SINGLE "single"
#define VERTICAL "vertical"
#define HORIZONTAL "horizontal"
#define METAL 1
#define WOOD 2
#define SAND 3
//Barricades/cover
/obj/structure/barricade
name = "chest high wall"
desc = "Looks like this would make good cover."
anchored = TRUE
density = TRUE
max_integrity = 100
var/proj_pass_rate = 50 //How many projectiles will pass the cover. Lower means stronger cover
var/bar_material = METAL
/obj/structure/barricade/deconstruct(disassembled = TRUE)
if(!(flags_1 & NODECONSTRUCT_1))
make_debris()
qdel(src)
/obj/structure/barricade/proc/make_debris()
return
/obj/structure/barricade/attackby(obj/item/I, mob/user, params)
if(I.tool_behaviour == TOOL_WELDER && user.a_intent != INTENT_HARM && bar_material == METAL)
if(obj_integrity < max_integrity)
if(!I.tool_start_check(user, amount=0))
return
to_chat(user, "<span class='notice'>You begin repairing [src]...</span>")
if(I.use_tool(src, user, 40, volume=40))
obj_integrity = clamp(obj_integrity + 20, 0, max_integrity)
else
return ..()
/obj/structure/barricade/CanAllowThrough(atom/movable/mover, turf/target)//So bullets will fly over and stuff.
. = ..()
if(locate(/obj/structure/barricade) in get_turf(mover))
return TRUE
else if(istype(mover, /obj/projectile))
if(!anchored)
return TRUE
var/obj/projectile/proj = mover
if(proj.firer && Adjacent(proj.firer))
return TRUE
if(prob(proj_pass_rate))
return TRUE
return FALSE
/////BARRICADE TYPES///////
/obj/structure/barricade/wooden
name = "wooden barricade"
desc = "This space is blocked off by a wooden barricade."
icon = 'icons/obj/structures.dmi'
icon_state = "woodenbarricade"
bar_material = WOOD
var/drop_amount = 3
/obj/structure/barricade/wooden/attackby(obj/item/I, mob/user)
if(istype(I,/obj/item/stack/sheet/mineral/wood))
var/obj/item/stack/sheet/mineral/wood/W = I
if(W.amount < 5)
to_chat(user, "<span class='warning'>You need at least five wooden planks to make a wall!</span>")
return
else
to_chat(user, "<span class='notice'>You start adding [I] to [src]...</span>")
if(do_after(user, 50, target=src))
W.use(5)
var/turf/T = get_turf(src)
T.PlaceOnTop(/turf/closed/wall/mineral/wood/nonmetal)
qdel(src)
return
return ..()
/obj/structure/barricade/wooden/crude
name = "crude plank barricade"
desc = "This space is blocked off by a crude assortment of planks."
icon_state = "woodenbarricade-old"
drop_amount = 1
max_integrity = 50
proj_pass_rate = 65
/obj/structure/barricade/wooden/crude/snow
desc = "This space is blocked off by a crude assortment of planks. It seems to be covered in a layer of snow."
icon_state = "woodenbarricade-snow-old"
max_integrity = 75
/obj/structure/barricade/wooden/make_debris()
new /obj/item/stack/sheet/mineral/wood(get_turf(src), drop_amount)
/obj/structure/barricade/sandbags
name = "sandbags"
desc = "Bags of sand. Self explanatory."
icon = 'icons/obj/smooth_structures/sandbags.dmi'
icon_state = "sandbags-0"
base_icon_state = "sandbags"
max_integrity = 280
proj_pass_rate = 20
pass_flags_self = LETPASSTHROW
bar_material = SAND
climbable = TRUE
smoothing_flags = SMOOTH_BITMASK
smoothing_groups = list(SMOOTH_GROUP_SANDBAGS)
canSmoothWith = list(SMOOTH_GROUP_SANDBAGS, SMOOTH_GROUP_WALLS, SMOOTH_GROUP_SECURITY_BARRICADE)
/obj/structure/barricade/security
name = "security barrier"
desc = "A deployable barrier. Provides good cover in fire fights."
icon = 'icons/obj/objects.dmi'
icon_state = "barrier0"
density = FALSE
anchored = FALSE
max_integrity = 180
proj_pass_rate = 20
armor = list(MELEE = 10, BULLET = 50, LASER = 50, ENERGY = 50, BOMB = 10, BIO = 100, RAD = 100, FIRE = 10, ACID = 0)
var/deploy_time = 40
var/deploy_message = TRUE
/obj/structure/barricade/security/Initialize()
. = ..()
addtimer(CALLBACK(src, .proc/deploy), deploy_time)
/obj/structure/barricade/security/proc/deploy()
icon_state = "barrier1"
density = TRUE
anchored = TRUE
if(deploy_message)
visible_message("<span class='warning'>[src] deploys!</span>")
/obj/item/grenade/barrier
name = "barrier grenade"
desc = "Instant cover."
icon = 'icons/obj/grenade.dmi'
icon_state = "flashbang"
inhand_icon_state = "flashbang"
actions_types = list(/datum/action/item_action/toggle_barrier_spread)
var/mode = SINGLE
/obj/item/grenade/barrier/examine(mob/user)
. = ..()
. += "<span class='notice'>Alt-click to toggle modes.</span>"
/obj/item/grenade/barrier/AltClick(mob/living/carbon/user)
if(!istype(user) || !user.canUseTopic(src, BE_CLOSE))
return
toggle_mode(user)
/obj/item/grenade/barrier/proc/toggle_mode(mob/user)
switch(mode)
if(SINGLE)
mode = VERTICAL
if(VERTICAL)
mode = HORIZONTAL
if(HORIZONTAL)
mode = SINGLE
to_chat(user, "<span class='notice'>[src] is now in [mode] mode.</span>")
/obj/item/grenade/barrier/detonate(mob/living/lanced_by)
. = ..()
new /obj/structure/barricade/security(get_turf(src.loc))
switch(mode)
if(VERTICAL)
var/turf/target_turf = get_step(src, NORTH)
if(!target_turf.is_blocked_turf())
new /obj/structure/barricade/security(target_turf)
var/turf/target_turf2 = get_step(src, SOUTH)
if(!target_turf2.is_blocked_turf())
new /obj/structure/barricade/security(target_turf2)
if(HORIZONTAL)
var/turf/target_turf = get_step(src, EAST)
if(!target_turf.is_blocked_turf())
new /obj/structure/barricade/security(target_turf)
var/turf/target_turf2 = get_step(src, WEST)
if(!target_turf2.is_blocked_turf())
new /obj/structure/barricade/security(target_turf2)
qdel(src)
/obj/item/grenade/barrier/ui_action_click(mob/user)
toggle_mode(user)
#undef SINGLE
#undef VERTICAL
#undef HORIZONTAL
#undef METAL
#undef WOOD
#undef SAND