Makes viewers() defines (#82767)

This commit is contained in:
Jeremiah
2024-04-20 01:39:50 -06:00
committed by GitHub
parent 686cbd96da
commit 31d5b272cc
4 changed files with 23 additions and 8 deletions
+20 -5
View File
@@ -20,8 +20,23 @@
view_info[2] *= world.icon_size
return view_info
/proc/in_view_range(mob/user, atom/A)
var/list/view_range = getviewsize(user.client.view)
var/turf/source = get_turf(user)
var/turf/target = get_turf(A)
return ISINRANGE(target.x, source.x - view_range[1], source.x + view_range[1]) && ISINRANGE(target.y, source.y - view_range[1], source.y + view_range[1])
/**
* Frustrated with bugs in can_see(), this instead uses viewers for a much more effective approach.
* ### Things to note:
* - Src/source must be a mob. `viewers()` returns mobs.
* - Adjacent objects are always considered visible.
*/
/// The default tile-distance between two atoms for one to consider the other as visible.
#define DEFAULT_SIGHT_DISTANCE 7
/// Basic check to see if the src object can see the target object.
#define CAN_I_SEE(target) ((src in viewers(DEFAULT_SIGHT_DISTANCE, target)) || in_range(target, src))
/// Checks the visibility between two other objects.
#define CAN_THEY_SEE(target, source) ((source in viewers(DEFAULT_SIGHT_DISTANCE, target)) || in_range(target, source))
/// Further checks distance between source and target.
#define CAN_SEE_RANGED(target, source, dist) ((source in viewers(dist, target)) || in_range(target, source))
+1 -1
View File
@@ -249,7 +249,7 @@
if(get_dist(shooter, target) <= 0)
target = get_step(shooter, shooter.dir) //Shoot in the direction faced if the mouse is on the same tile as we are.
target_loc = target
else if(!in_view_range(shooter, target))
else if(!CAN_THEY_SEE(target, shooter))
stop_autofiring() //Elvis has left the building.
return FALSE
shooter.face_atom(target)
@@ -56,7 +56,7 @@
if (get_dist(living_parent, target) <= 0)
set_target(get_step(living_parent, living_parent.dir)) // Shoot in the direction faced if the mouse is on the same tile as we are.
target_loc = target
else if (!in_view_range(living_parent, target))
else if (!CAN_THEY_SEE(target, living_parent))
stop_firing()
return FALSE // Can't see shit
@@ -409,7 +409,7 @@
COOLDOWN_START(src, coin_regen_cd, coin_regen_rate)
/obj/item/gun/energy/marksman_revolver/afterattack_secondary(atom/target, mob/living/user, params)
if(!can_see(user, get_turf(target), length = 9))
if(!CAN_THEY_SEE(target, user))
return ..()
if(max_coins && coin_count <= 0)