From 87b84cedf0c0c18613564b89ec1ab120c195acba Mon Sep 17 00:00:00 2001 From: kevinz000 Date: Tue, 17 Oct 2017 01:50:17 -0700 Subject: [PATCH] Fixes vehicles granting projectile immunity and YET AGAIN reworks projectile targetting priorities (#31660) * Update projectile.dm * fixes projectiles --- code/_globalvars/lists/typecache.dm | 2 +- code/modules/mob/mob_helpers.dm | 7 +++- code/modules/projectiles/projectile.dm | 55 +++++++++++++------------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/code/_globalvars/lists/typecache.dm b/code/_globalvars/lists/typecache.dm index d83c708131..c6893542a3 100644 --- a/code/_globalvars/lists/typecache.dm +++ b/code/_globalvars/lists/typecache.dm @@ -4,6 +4,6 @@ //Note: typecache can only replace istype if you know for sure the thing is at least a datum. GLOBAL_LIST_INIT(typecache_mob, typecacheof(list(/mob))) - +GLOBAL_LIST_INIT(typecache_machine_or_structure, typecacheof(list(/obj/machinery))|typecacheof(list(/obj/structure))) diff --git a/code/modules/mob/mob_helpers.dm b/code/modules/mob/mob_helpers.dm index cb086b7115..9447b32daa 100644 --- a/code/modules/mob/mob_helpers.dm +++ b/code/modules/mob/mob_helpers.dm @@ -6,8 +6,13 @@ /mob/living/carbon/isloyal() for(var/obj/item/implant/mindshield/L in implants) - return 1 + return TRUE +/mob/proc/lowest_buckled_mob() + . = src + if(buckled && ismob(buckled)) + var/mob/Buckled = buckled + . = Buckled.lowest_buckled_mob() /proc/check_zone(zone) if(!zone) diff --git a/code/modules/projectiles/projectile.dm b/code/modules/projectiles/projectile.dm index f7357207da..aaa3a3e637 100644 --- a/code/modules/projectiles/projectile.dm +++ b/code/modules/projectiles/projectile.dm @@ -187,41 +187,42 @@ if(forcedodge) loc = target_turf return FALSE - var/permutation = select_target(A,target_turf) // searches for return value, could be deleted after run so check A isn't null + + var/permutation = A.bullet_act(src, def_zone) // searches for return value, could be deleted after run so check A isn't null if(permutation == -1 || forcedodge)// the bullet passes through a dense object! loc = target_turf if(A) permutated.Add(A) return FALSE + else + var/atom/alt = select_target(A) + if(alt) + if(!prehit(alt)) + return FALSE + alt.bullet_act(src, def_zone) qdel(src) return TRUE -/obj/item/projectile/proc/select_target(atom/A,target_turf) - if((A && A.density && !(A.flags_1 & ON_BORDER_1)) && (istype(A,/obj/machinery) || isturf(A))) //if we hit a dense non-border obj or dense turf then we also hit one of the mobs on that tile. - var/list/mobs_list = list() - var/list/machine_list = list() - for(var/mob/living/L in target_turf) - mobs_list += L - for(var/obj/machinery/m in target_turf) - if(m.density) - machine_list += m - var/permutationbackup - if(isturf(A)) - permutationbackup = A.bullet_act(src, def_zone) // Just in case the turf can deflect bullets - if(mobs_list.len || machine_list.len) - var/atom/movable/selected_target - if(mobs_list.Find(original) || machine_list.Find(original)) - selected_target = original - else if(mobs_list.len) - selected_target = pick(mobs_list) - else - selected_target = pick(machine_list) - if(!prehit(selected_target)) - return FALSE - return selected_target.bullet_act(src, def_zone) - return permutationbackup - else - return A.bullet_act(src, def_zone) + +/obj/item/projectile/proc/select_target(atom/A) //Selects another target from a wall if we hit a wall. + if(!A || !A.density || (A.flags_1 & ON_BORDER_1) || ismob(A)) //if we hit a dense non-border obj or dense turf then we also hit one of the mobs or machines/structures on that tile. + return + if(A == original || original in A) + return original + var/list/mob/possible_mobs = typecache_filter_list(A, GLOB.typecache_mob) + var/list/mob/mobs = list() + for(var/i in possible_mobs) + var/mob/M = i + if(M.lying) + continue + mobs += M + var/mob/M = safepick(mobs) + if(M) + return M.lowest_buckled_mob() + var/obj/O = safepick(typecache_filter_list(A, GLOB.typecache_machine_or_structure)) + if(O) + return O + return A /obj/item/projectile/proc/check_ricochet() if(prob(ricochet_chance))