Refactors projectile ricochets (#25764)

* same taste, twice the speed

* pulls proc/handle_ricochet() to the atom level. adds var/flags_ricochet and related defines.

* space indentation sneaks its way in yet again

---------

Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com>
This commit is contained in:
chuga-git
2024-06-12 19:08:57 +00:00
committed by GitHub
co-authored by Luc
parent c46630b1ea
commit 438faac253
10 changed files with 86 additions and 37 deletions
+21 -2
View File
@@ -4,6 +4,8 @@
var/level = 2
var/flags = NONE
var/flags_2 = NONE
/// how the atom should handle ricochet behavior
var/flags_ricochet = NONE
var/list/fingerprints
var/list/fingerprintshidden
var/fingerprintslast = null
@@ -107,6 +109,11 @@
/// Contains the world.time of when we start dragging something with our mouse. Used to prevent weird situations where you fail to click on something
var/drag_start = 0
///When a projectile tries to ricochet off this atom, the projectile ricochet chance is multiplied by this
var/receive_ricochet_chance_mod = 1
///When a projectile ricochets off this atom, it deals the normal damage * this modifier to this atom
var/receive_ricochet_damage_coeff = 0.33
/atom/New(loc, ...)
SHOULD_CALL_PARENT(TRUE)
if(GLOB.use_preloader && (src.type == GLOB._preloader.target_path))//in case the instanciated atom is creating other atoms in New()
@@ -1107,8 +1114,20 @@ GLOBAL_LIST_EMPTY(blood_splatter_icons)
/atom/proc/zap_act(power, zap_flags)
return
/atom/proc/handle_ricochet(obj/item/projectile/P)
return
/atom/proc/handle_ricochet(obj/item/projectile/ricocheting_projectile)
var/turf/p_turf = get_turf(ricocheting_projectile)
var/face_direction = get_dir(src, p_turf) || get_dir(src, ricocheting_projectile)
var/face_angle = dir2angle(face_direction)
var/incidence_s = GET_ANGLE_OF_INCIDENCE(face_angle, (ricocheting_projectile.Angle + 180))
var/a_incidence_s = abs(incidence_s)
if(a_incidence_s > 90 && a_incidence_s < 270)
return FALSE
if((ricocheting_projectile.flag in list(BULLET, BOMB)) && ricocheting_projectile.ricochet_incidence_leeway)
if((a_incidence_s < 90 && a_incidence_s < 90 - ricocheting_projectile.ricochet_incidence_leeway) || (a_incidence_s > 270 && a_incidence_s -270 > ricocheting_projectile.ricochet_incidence_leeway))
return FALSE
var/new_angle_s = SIMPLIFY_DEGREES(face_angle + incidence_s)
ricocheting_projectile.set_angle(new_angle_s)
return TRUE
//This proc is called on the location of an atom when the atom is Destroy()'d
/atom/proc/handle_atom_del(atom/A)
+2
View File
@@ -7,6 +7,8 @@
layer = BELOW_OBJ_LAYER
armor = list(melee = 25, bullet = 10, laser = 10, energy = 0, bomb = 0, rad = 0, fire = 50, acid = 70)
atom_say_verb = "beeps"
flags_ricochet = RICOCHET_HARD
receive_ricochet_chance_mod = 0.3
var/stat = 0
/// How is this machine currently passively consuming power?
+7 -1
View File
@@ -115,7 +115,7 @@
air = environment
if(isnull(air))
return
var/breath_percentage = BREATH_VOLUME / air.return_volume()
return air.remove(air.total_moles() * breath_percentage)
else
@@ -303,6 +303,12 @@
else
C.KnockDown(3 SECONDS)
/obj/handle_ricochet(obj/item/projectile/P)
. = ..()
if(. && receive_ricochet_damage_coeff)
// pass along receive_ricochet_damage_coeff damage to the structure for the ricochet
take_damage(P.damage * receive_ricochet_damage_coeff, P.damage_type, P.flag, 0, REVERSE_DIR(P.dir), P.armour_penetration_flat, P.armour_penetration_percentage)
/obj/proc/return_obj_air()
RETURN_TYPE(/datum/gas_mixture)
if(isobj(loc))
+2
View File
@@ -3,6 +3,8 @@
pressure_resistance = 8
max_integrity = 300
face_while_pulling = TRUE
flags_ricochet = RICOCHET_HARD
receive_ricochet_chance_mod = 0.6
var/climbable
/// Determines if a structure adds the TRAIT_TURF_COVERED to its turf.
var/creates_cover = FALSE
+2
View File
@@ -8,6 +8,8 @@
anchored = TRUE
flags = ON_BORDER
flags_2 = RAD_PROTECT_CONTENTS_2
flags_ricochet = RICOCHET_HARD
receive_ricochet_chance_mod = 0.5
can_be_unanchored = TRUE
max_integrity = 25
resistance_flags = ACID_PROOF
+1 -11
View File
@@ -24,6 +24,7 @@
explosion_block = 1
flags_2 = RAD_PROTECT_CONTENTS_2 | RAD_NO_CONTAMINATE_2
flags_ricochet = RICOCHET_HARD
rad_insulation = RAD_MEDIUM_INSULATION
thermal_conductivity = WALL_HEAT_TRANSFER_COEFFICIENT
@@ -154,17 +155,6 @@
else
update_icon()
/turf/simulated/wall/handle_ricochet(obj/item/projectile/P) //A huge pile of shitcode!
var/turf/p_turf = get_turf(P)
var/face_direction = get_dir(src, p_turf)
var/face_angle = dir2angle(face_direction)
var/incidence_s = GET_ANGLE_OF_INCIDENCE(face_angle, (P.Angle + 180))
if(abs(incidence_s) > 90 && abs(incidence_s) < 270)
return FALSE
var/new_angle_s = SIMPLIFY_DEGREES(face_angle + incidence_s)
P.set_angle(new_angle_s)
return TRUE
/turf/simulated/wall/dismantle_wall(devastated = FALSE, explode = FALSE)
if(devastated)
devastate_wall()
+1 -1
View File
@@ -220,7 +220,7 @@
icon_state = "plastinum_wall-0"
base_icon_state = "plastinum_wall"
explosion_block = 3
flags_2 = CHECK_RICOCHET_2
flags_ricochet = RICOCHET_SHINY | RICOCHET_HARD
sheet_type = /obj/item/stack/sheet/mineral/titanium
smoothing_flags = SMOOTH_BITMASK | SMOOTH_DIAGONAL_CORNERS
smoothing_groups = list(SMOOTH_GROUP_TITANIUM_WALLS, SMOOTH_GROUP_WINDOW_FULLTILE_SHUTTLE)