Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Makes viewers() defines #2993

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions code/__HELPERS/view.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion code/datums/components/fullauto.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/ranged_mob_full_auto.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion code/modules/projectiles/guns/energy/special.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading