diff --git a/code/modules/projectiles/guns/smartgun.dm b/code/modules/projectiles/guns/smartgun.dm index 8c6ff50b30..43ddf30f7d 100644 --- a/code/modules/projectiles/guns/smartgun.dm +++ b/code/modules/projectiles/guns/smartgun.dm @@ -341,14 +341,30 @@ var/extended_target_turf = get_angle_target_turf(user, angle, range_to_check) - var/turf/current_turf = get_turf(user) + var/turf/user_turf = get_turf(user) - if(!current_turf || !extended_target_turf) + if(!user_turf || !extended_target_turf) return COMPONENT_CANCEL_GUN_BEFORE_FIRE - var/list/checked_turfs = getline2(current_turf, extended_target_turf) + var/list/checked_turfs = getline2(user_turf, extended_target_turf) - checked_turfs -= current_turf + checked_turfs -= user_turf + + //At some angles (scatter or otherwise) the original target is not in checked_turfs so we put it in there in order based on distance from user + //If we are literally clicking on someone with IFF then we don't want to fire, feels funny as a user otherwise + if(projectile_to_fire.original) + var/turf/original_target_turf = get_turf(projectile_to_fire.original) + + if(original_target_turf && !(original_target_turf in checked_turfs)) + var/user_to_target_dist = get_dist(user_turf, original_target_turf) + var/list/temp_checked_turfs = checked_turfs + checked_turfs = list() + + for(var/turf/checked_turf as anything in temp_checked_turfs) + if(!(original_target_turf in checked_turfs) && user_to_target_dist < get_dist(user_turf, checked_turf)) + checked_turfs += original_target_turf + + checked_turfs += checked_turf for(var/turf/checked_turf as anything in checked_turfs) @@ -357,7 +373,10 @@ return for(var/mob/living/checked_living in checked_turf) - if(!checked_living.lying && checked_living.get_target_lock(user.faction_group)) + if(checked_living.lying && projectile_to_fire.original != checked_living) + continue + + if(checked_living.get_target_lock(user.faction_group)) if(COOLDOWN_FINISHED(src, iff_halt_cooldown)) playsound_client(user.client, 'sound/weapons/smartgun_fail.ogg', src, 25) to_chat(user, SPAN_WARNING("[src] halts firing as an IFF marked target crosses your field of fire!"))