Projectile refactoring madness (#19878)

Refactored the projectile code, mostly in line with TG's now.
Refactored various procs that are used or depends on it.
Projectiles can now ricochet if enabled to.
Damage falloffs with distance.
Homing projectiles can now have accuracy falloff with distance.
Projectiles have a maximum range.
Muzzle flash is configurable per projectile.
Impact effect of the projectile is configurable per projectile.
Accuracy decreases with distance.
Projectiles work with signals and emits them, for easy hooking up from
other parts of the code.
Meatshielding is now less effective .
Impact sound is now configurable per projectile.

High risk.
This commit is contained in:
Fluffy
2024-09-23 10:12:57 +00:00
committed by GitHub
parent 914f69dcc8
commit c24b4c7097
203 changed files with 2925 additions and 1590 deletions
@@ -83,6 +83,8 @@
return prob(max(30,(100.0*health)/maxhealth))
/obj/structure/barricade/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(air_group || (height==0))
return TRUE
if(istype(mover, /obj/projectile))
@@ -197,11 +199,14 @@
playsound(src, barricade_hitsound, 25, 1)
hit_barricade(attacking_item, user)
/obj/structure/barricade/bullet_act(obj/projectile/P)
bullet_ping(P)
var/damage_to_take = P.damage * P.anti_materiel_potential
/obj/structure/barricade/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
bullet_ping(hitting_projectile)
var/damage_to_take = hitting_projectile.damage * hitting_projectile.anti_materiel_potential
take_damage(damage_to_take)
return TRUE
/obj/structure/barricade/proc/barricade_deconstruct(deconstruct)
if(deconstruct && is_wired)
+2
View File
@@ -382,6 +382,8 @@ GLOBAL_LIST_EMPTY(total_active_bonfires)
AddOverlays("fireplace_glow")
/obj/structure/bonfire/fireplace/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(get_dir(loc, target) == NORTH)
return !density
return TRUE
@@ -150,7 +150,8 @@
return content_size
/obj/structure/closet/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(air_group || (height==0 || wall_mounted)) return 1
if(air_group || (height==0 || wall_mounted))
return TRUE
return ..()
/obj/structure/closet/proc/can_open()
@@ -316,17 +317,19 @@
new /obj/item/stack/material/steel(get_turf(src))
qdel(src)
/obj/structure/closet/bullet_act(var/obj/projectile/Proj)
var/proj_damage = Proj.get_structure_damage()
/obj/structure/closet/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
var/proj_damage = hitting_projectile.get_structure_damage()
if(!proj_damage)
return
return BULLET_ACT_BLOCK
if(Proj.penetrating || istype(Proj, /obj/projectile/bullet))
var/distance = get_dist(Proj.starting, get_turf(loc))
if(hitting_projectile.penetrating || istype(hitting_projectile, /obj/projectile/bullet))
for(var/mob/living/L in contents)
Proj.attack_mob(L, distance)
hitting_projectile.Impact(L)
..()
damage(proj_damage)
/obj/structure/closet/attackby(obj/item/attacking_item, mob/user)
@@ -124,11 +124,13 @@
for(var/mob/M in src)
shatter(M)
/obj/structure/closet/statue/bullet_act(var/obj/projectile/Proj)
health -= Proj.get_structure_damage()
check_health()
/obj/structure/closet/statue/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
return
health -= hitting_projectile.get_structure_damage()
check_health()
/obj/structure/closet/statue/attack_generic(var/mob/user, damage, attacktext, environment_smash)
user.setClickCooldown(DEFAULT_ATTACK_COOLDOWN)
@@ -97,6 +97,8 @@
==========================
*/
/obj/structure/closet/crate/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if (istype(mover, /obj/structure/closet/crate))//Handle interaction with other crates
var/obj/structure/closet/crate/C = mover
if (tablestatus && tablestatus != C.tablestatus) // Crates can go under tables with crates on top of them, and vice versa
+7 -5
View File
@@ -20,12 +20,14 @@
layer = ABOVE_HUMAN_LAYER
opacity = 0
/obj/structure/curtain/bullet_act(obj/projectile/P, def_zone)
if(!P.nodamage)
visible_message(SPAN_WARNING("[P] tears [src] down!"))
/obj/structure/curtain/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
if(hitting_projectile.damage > 0)
visible_message(SPAN_WARNING("[hitting_projectile] tears [src] down!"))
qdel(src)
else
..(P, def_zone)
/obj/structure/curtain/attack_hand(mob/user)
playsound(get_turf(loc), 'sound/effects/curtain.ogg', 15, 1, -5)
+6 -3
View File
@@ -34,9 +34,12 @@
health_check()
/obj/structure/displaycase/bullet_act(var/obj/projectile/Proj)
health -= Proj.get_structure_damage()
..()
/obj/structure/displaycase/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
health -= hitting_projectile.get_structure_damage()
health_check()
/obj/structure/displaycase/proc/health_check()
@@ -48,6 +48,8 @@
/obj/structure/window_frame/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(air_group || (height == 0))
return TRUE
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover, /obj/structure/closet/crate))
return TRUE
if(istype(mover) && mover.pass_flags & PASSTABLE)
+8 -6
View File
@@ -41,16 +41,16 @@
health = 50
cover = 25
/obj/structure/girder/bullet_act(var/obj/projectile/Proj)
/obj/structure/girder/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
//Girders only provide partial cover. There's a chance that the projectiles will just pass through. (unless you are trying to shoot the girder)
if(Proj.original != src && !prob(cover))
return PROJECTILE_CONTINUE //pass through
if(hitting_projectile.original != src && !prob(cover))
return BULLET_ACT_HIT //pass through
var/damage = Proj.get_structure_damage()
var/damage = hitting_projectile.get_structure_damage()
if(!damage)
return
return BULLET_ACT_BLOCK
if(!istype(Proj, /obj/projectile/beam))
if(!istype(hitting_projectile, /obj/projectile/beam))
damage *= 0.4 //non beams do reduced damage
take_damage(damage)
@@ -376,6 +376,8 @@
/obj/structure/girder/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if (!mover)
return 1
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover,/obj/projectile) && density)
if (prob(50))
return 1
+8 -3
View File
@@ -31,10 +31,13 @@
visible_message(SPAN_WARNING(final_message))
qdel(src)
/obj/structure/gore/bullet_act(var/obj/projectile/Proj)
health -= Proj.damage
/obj/structure/gore/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
health -= hitting_projectile.damage
healthcheck()
return ..()
/obj/structure/gore/ex_act(severity)
switch(severity)
@@ -78,6 +81,8 @@
/obj/structure/gore/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(air_group)
return FALSE
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover) && mover.pass_flags & PASSGLASS)
return !opacity
return !density
+24 -18
View File
@@ -103,45 +103,54 @@
attack_generic(user,damage_dealt,attack_message)
/obj/structure/grille/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(air_group || (height==0)) return 1
if(air_group || (height==0))
return TRUE
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover) && mover.pass_flags & PASSGRILLE)
return 1
return TRUE
else
if(istype(mover, /obj/projectile))
return prob(30)
else
return !density
/obj/structure/grille/bullet_act(var/obj/projectile/Proj)
if(!Proj) return
/obj/structure/grille/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
if(!hitting_projectile)
return BULLET_ACT_BLOCK
//Flimsy grilles aren't so great at stopping projectiles. However they can absorb some of the impact
var/damage = Proj.get_structure_damage()
var/damage = hitting_projectile.get_structure_damage()
var/passthrough = 0
if(!damage) return
if(!damage)
return BULLET_ACT_BLOCK
//20% chance that the grille provides a bit more cover than usual. Support structure for example might take up 20% of the grille's area.
//If they click on the grille itself then we assume they are aiming at the grille itself and the extra cover behaviour is always used.
switch(Proj.damage_type)
switch(hitting_projectile.damage_type)
if(DAMAGE_BRUTE)
//bullets
if(Proj.original == src || prob(20))
Proj.damage *= between(0, Proj.damage/60, 0.5)
if(hitting_projectile.original == src || prob(20))
hitting_projectile.damage *= between(0, hitting_projectile.damage/60, 0.5)
if(prob(max((damage-10)/25, 0))*100)
passthrough = 1
else
Proj.damage *= between(0, Proj.damage/60, 1)
hitting_projectile.damage *= between(0, hitting_projectile.damage/60, 1)
passthrough = 1
if(DAMAGE_BURN)
//beams and other projectiles are either blocked completely by grilles or stop half the damage.
if(!(Proj.original == src || prob(20)))
Proj.damage *= 0.5
if(!(hitting_projectile.original == src || prob(20)))
hitting_projectile.damage *= 0.5
passthrough = 1
if(passthrough)
. = PROJECTILE_CONTINUE
damage = between(0, (damage - Proj.damage)*(Proj.damage_type == DAMAGE_BRUTE? 0.4 : 1), 10) //if the bullet passes through then the grille avoids most of the damage
. = BULLET_ACT_HIT
damage = between(0, (damage - hitting_projectile.damage)*(hitting_projectile.damage_type == DAMAGE_BRUTE? 0.4 : 1), 10) //if the bullet passes through then the grille avoids most of the damage
src.health -= damage*0.2
spawn(0) healthcheck() //spawn to make sure we return properly if the grille is deleted
@@ -313,7 +322,7 @@
/obj/structure/grille/cult/CanPass(atom/movable/mover, turf/target, height = 1.5, air_group = 0)
if(air_group)
return 0 //Make sure air doesn't drain
..()
. = ..()
/obj/structure/grille/crescent/attack_hand()
return
@@ -329,6 +338,3 @@
/obj/structure/grille/crescent/hitby(atom/movable/hitting_atom, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum)
return
/obj/structure/grille/crescent/bullet_act()
return
+14 -9
View File
@@ -63,13 +63,18 @@
if(health <= 0)
topple()
/obj/structure/hadii_statue/bullet_act(var/obj/projectile/Proj)
/obj/structure/hadii_statue/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
if(toppled)
return
if(!Proj)
return
if(!Proj.damage)
visible_message(SPAN_WARNING("\The [Proj] bounces off \the [src]!"))
return
visible_message(SPAN_WARNING("\The [Proj] hits \the [src]!"))
do_integrity_check(Proj.damage)
return BULLET_ACT_BLOCK
if(!hitting_projectile)
return BULLET_ACT_BLOCK
if(!hitting_projectile.damage)
visible_message(SPAN_WARNING("\The [hitting_projectile] bounces off \the [src]!"))
return BULLET_ACT_BLOCK
. = ..()
if(. != BULLET_ACT_HIT)
return .
visible_message(SPAN_WARNING("\The [hitting_projectile] hits \the [src]!"))
do_integrity_check(hitting_projectile.damage)
+13 -4
View File
@@ -60,21 +60,28 @@
return ..()
/obj/structure/inflatable/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(isprojectile(mover))
visible_message(SPAN_DANGER("\The [src] rapidly deflates!"))
deflate(TRUE)
return TRUE
return FALSE
/obj/structure/inflatable/bullet_act(var/obj/projectile/Proj)
var/proj_damage = Proj.get_structure_damage()
/obj/structure/inflatable/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
var/proj_damage = hitting_projectile.get_structure_damage()
if(!proj_damage)
return
bullet_ping(Proj)
. = ..()
if(. != BULLET_ACT_HIT)
return .
bullet_ping(hitting_projectile)
health -= proj_damage
..()
if(health <= 0)
deflate(TRUE)
return
@@ -203,6 +210,8 @@
/obj/structure/inflatable/door/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(air_group)
return state
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover, /obj/effect/beam))
return !opacity
if(isprojectile(mover))
+6 -3
View File
@@ -423,11 +423,14 @@
return
/obj/structure/janitorialcart/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(air_group || (height==0)) return 1
if(air_group || (height==0))
return TRUE
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover) && mover.pass_flags & PASSTABLE)
return 1
return TRUE
if(istype(mover, /mob/living) && mover == pulling)
return 1
return TRUE
else
if(istype(mover, /obj/projectile))
return prob(30)
@@ -67,6 +67,9 @@
if (!mover)
return 1
if(mover.movement_type & PHASING)
return TRUE
if(istype(mover,/obj/projectile) && density)
if (!occupied && prob(80))
//Wiry frame, usually wont be cover
+6 -3
View File
@@ -57,13 +57,16 @@
reflection.update_mirror_filters()
/obj/structure/mirror/bullet_act(var/obj/projectile/Proj)
if(prob(Proj.get_structure_damage() * 2))
/obj/structure/mirror/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
if(prob(hitting_projectile.get_structure_damage() * 2))
if(!shattered)
shatter()
else
playsound(src, 'sound/effects/hit_on_shattered_glass.ogg', 70, 1)
..()
/obj/structure/mirror/attackby(obj/item/attacking_item, mob/user)
if(shattered)
+11 -8
View File
@@ -56,27 +56,30 @@
return AIR_BLOCKED
return FALSE
/obj/structure/plasticflaps/CanPass(atom/A, turf/T)
if(istype(A) && A.pass_flags & PASSGLASS)
/obj/structure/plasticflaps/CanPass(atom/movable/mover, turf/target)
if(istype(mover) && mover.pass_flags & PASSGLASS)
return prob(60)
var/obj/structure/bed/B = A
if (istype(A, /obj/structure/bed) && B.buckled)//if it's a bed/chair and someone is buckled, it will not pass
if(mover?.movement_type & PHASING)
return TRUE
var/obj/structure/bed/B = mover
if (istype(mover, /obj/structure/bed) && B.buckled)//if it's a bed/chair and someone is buckled, it will not pass
return 0
if(istype(A, /obj/vehicle)) //no vehicles
if(istype(mover, /obj/vehicle)) //no vehicles
return 0
//Bots can always pass
if(isbot(A))
if(isbot(mover))
return TRUE
var/mob/living/M = A
var/mob/living/M = mover
if(istype(M))
if(M.lying)
return ..()
for(var/mob_type in mobs_can_pass)
if(istype(A, mob_type))
if(istype(mover, mob_type))
return ..()
return issmall(M)
+3 -1
View File
@@ -8,7 +8,7 @@
climbable = TRUE
layer = OBJ_LAYER
anchored = FALSE
pass_flags_self = LETPASSTHROW|PASSSTRUCTURE
pass_flags_self = LETPASSTHROW|PASSSTRUCTURE|PASSRAILING
atom_flags = ATOM_FLAG_CHECKS_BORDER
obj_flags = OBJ_FLAG_ROTATABLE|OBJ_FLAG_MOVES_UNSUPPORTED
@@ -88,6 +88,8 @@
. += FONT_SMALL(SPAN_NOTICE("\The [src] is <b>[anchored ? "" : "not"] screwed</b> to the floor."))
/obj/structure/railing/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover,/obj/projectile))
return TRUE
if(!istype(mover) || mover.pass_flags & PASSRAILING)
+11 -4
View File
@@ -86,7 +86,10 @@
return
/obj/structure/simple_door/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(air_group) return 0
if(air_group)
return FALSE
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover, /obj/effect/beam))
return !opacity
return !density
@@ -193,9 +196,13 @@
attack_hand(user)
return
/obj/structure/simple_door/bullet_act(var/obj/projectile/Proj)
health -= Proj.damage
bullet_ping(Proj)
/obj/structure/simple_door/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
. = ..()
if(. != BULLET_ACT_HIT)
return .
health -= hitting_projectile.damage
bullet_ping(hitting_projectile)
CheckHealth()
/obj/structure/simple_door/proc/CheckHealth()
@@ -127,9 +127,6 @@
if(buckled)
buckled.forceMove(dest)
/obj/structure/bed/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
return ..()
/obj/structure/bed/ex_act(severity)
switch(severity)
if(1.0)
+8
View File
@@ -261,6 +261,8 @@ ABSTRACT_TYPE(/obj/structure/stairs/urban/road_ramp)
anchored = TRUE
/obj/structure/rod_railing/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover,/obj/projectile))
return TRUE
if(!istype(mover) || mover.pass_flags & PASSRAILING)
@@ -313,6 +315,8 @@ ABSTRACT_TYPE(/obj/structure/stairs/urban/road_ramp)
icon_state = "guard_top_end"
/obj/structure/road_barrier/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover,/obj/projectile))
return TRUE
if(!istype(mover) || mover.pass_flags & PASSRAILING)
@@ -343,6 +347,8 @@ ABSTRACT_TYPE(/obj/structure/stairs/urban/road_ramp)
can_be_unanchored = FALSE
/obj/structure/chainlink_fence/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)//So bullets will fly over and stuff.
if(mover?.movement_type & PHASING)
return TRUE
if(air_group || (height==0))
return TRUE
if(istype(mover, /obj/projectile))
@@ -378,6 +384,8 @@ ABSTRACT_TYPE(/obj/structure/stairs/urban/road_ramp)
can_be_unanchored = FALSE
/obj/structure/rope_railing/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover,/obj/projectile))
return TRUE
if(!istype(mover) || mover.pass_flags & PASSRAILING)
@@ -49,6 +49,8 @@
icon_state = "[facing]_[secure]windoor_assembly[state]"
/obj/structure/windoor_assembly/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover) && mover.pass_flags & PASSGLASS)
return 1
if(get_dir(loc, target) == dir) //Make sure looking at appropriate border
+9 -4
View File
@@ -138,12 +138,15 @@
qdel(src)
return
/obj/structure/window/bullet_act(var/obj/projectile/Proj)
var/proj_damage = Proj.get_structure_damage()
/obj/structure/window/bullet_act(obj/projectile/hitting_projectile, def_zone, piercing_hit)
var/proj_damage = hitting_projectile.get_structure_damage()
if(!proj_damage)
return
return BULLET_ACT_BLOCK
. = ..()
if(. != BULLET_ACT_HIT)
return .
..()
take_damage(proj_damage)
return
@@ -167,6 +170,8 @@
return (dir == SOUTHWEST || dir == SOUTHEAST || dir == NORTHWEST || dir == NORTHEAST)
/obj/structure/window/CanPass(atom/movable/mover, turf/target, height=0, air_group=0)
if(mover?.movement_type & PHASING)
return TRUE
if(istype(mover) && mover.pass_flags & PASSGLASS)
return 1
if(is_full_window())