Skip to content

refactor is_blocked_turf #29324

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 0 additions & 17 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -641,23 +641,6 @@ Returns 1 if the chain up to the area contains the given typepath

return 1

/proc/is_blocked_turf(turf/T, exclude_mobs, list/excluded_objs)
if(T.density)
return TRUE
if(locate(/mob/living/silicon/ai) in T) //Prevents jaunting onto the AI core cheese, AI should always block a turf due to being a dense mob even when unanchored
return TRUE
if(!exclude_mobs)
for(var/mob/living/L in T)
if(L.density)
return TRUE
var/any_excluded_objs = length(excluded_objs)
for(var/obj/O in T)
if(any_excluded_objs && (O in excluded_objs))
continue
if(O.density)
return TRUE
return FALSE

//Returns: all the areas in the world
/proc/return_areas()
var/list/area/areas = list()
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/SSshuttles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ SUBSYSTEM_DEF(shuttle)

if(!length(supply_shuttle_turfs))
for(var/turf/simulated/T in supply.areaInstance)
if(is_blocked_turf(T))
if(T.is_blocked_turf())
continue
supply_shuttle_turfs += T
if(!length(supply_shuttle_turfs)) // In case some nutjob walled the supply shuttle 10 minutes into the round
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
var/turf/target_turf = get_step(our_turf, direction)
if(isnull(target_turf))
continue
if(is_blocked_turf(target_turf) || get_dist(target_turf, target) > get_dist(living_pawn, target))
if(target_turf.is_blocked_turf() || get_dist(target_turf, target) > get_dist(living_pawn, target))
continue
possible_turfs += target_turf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
var/turf/return_turf
for(var/i in 1 to run_distance)
var/turf/test_destination = get_ranged_target_turf_direct(source, target, range = i, offset = angle)
if(is_blocked_turf(test_destination, excluded_objs = GLOB.airlocks + src))
if(test_destination.is_blocked_turf(source_atom = source, ignore_atoms = GLOB.airlocks))
break
return_turf = test_destination
return return_turf
Expand Down
8 changes: 6 additions & 2 deletions code/datums/components/shelved.dm
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@
for(var/turf/turf_in_view in view(2, get_turf(structure_parent)))
if(!isfloorturf(turf_in_view))
continue
var/blocked_los = FALSE
for(var/turf/potential_blockage as anything in get_line(get_turf(structure_parent), turf_in_view))
if(!is_blocked_turf(potential_blockage, exclude_mobs = TRUE, excluded_objs = list(parent)))
nearby_empty_tiles += turf_in_view
if(potential_blockage.is_blocked_turf(exclude_mobs = TRUE, source_atom = parent))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(potential_blockage.is_blocked_turf(exclude_mobs = TRUE, source_atom = parent))
if(potential_blockage.is_blocked_turf(TRUE, parent))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally lean towards leaving these args in place, it never hurts to be a little more verbose about what the arguments to a proc are

blocked_los = TRUE
break
if(!blocked_los)
nearby_empty_tiles += turf_in_view

var/itemcount = 1
for(var/obj/item/I in structure_parent.loc)
Expand Down
2 changes: 1 addition & 1 deletion code/datums/spells/ethereal_jaunt.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
sleep(jaunt_in_time)
qdel(holder)
if(!QDELETED(target))
if(is_blocked_turf(mobloc, TRUE))
if(mobloc.is_blocked_turf(exclude_mobs = TRUE))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(mobloc.is_blocked_turf(exclude_mobs = TRUE))
if(mobloc.is_blocked_turf(TRUE))

for(var/turf/T in orange(7))
if(isspaceturf(T))
continue
Expand Down
2 changes: 1 addition & 1 deletion code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@

var/has_tried_to_move = FALSE

if(is_blocked_turf(target_turf, TRUE, excluded_objs = list(src)))
if(target_turf.is_blocked_turf(exclude_mobs = TRUE, ignore_atoms = list(src)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(target_turf.is_blocked_turf(exclude_mobs = TRUE, ignore_atoms = list(src)))
if(target_turf.is_blocked_turf(TRUE, ignore_atoms = list(src)))

has_tried_to_move = TRUE
if(!Move(target_turf, crush_dir))
// we'll try to move, and if we didn't end up going anywhere, then we do nothing.
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/malfunction/Malf_Modules.dm
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@
to_chat(src, "<span class='warning'>You don't have camera vision of this location!</span>")
addtimer(CALLBACK(src, PROC_REF(remove_transformer_image), client, I, deploylocation), 3 SECONDS)
return FALSE
if(is_blocked_turf(deploylocation))
if(deploylocation.is_blocked_turf())
to_chat(src, "<span class='warning'>That area must be clear of objects!</span>")
addtimer(CALLBACK(src, PROC_REF(remove_transformer_image), client, I, deploylocation), 3 SECONDS)
return FALSE
Expand Down
6 changes: 3 additions & 3 deletions code/game/gamemodes/wizard/magic_tarot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
/datum/tarot/the_emperor/activate(mob/living/target)
var/list/L = list()
for(var/turf/T in get_area_turfs(/area/station/command/bridge))
if(is_blocked_turf(T))
if(T.is_blocked_turf())
continue
L.Add(T)

Expand Down Expand Up @@ -576,7 +576,7 @@
/datum/tarot/the_stars/activate(mob/living/target)
var/list/L = list()
for(var/turf/T in get_area_turfs(/area/station/security/evidence))
if(is_blocked_turf(T))
if(T.is_blocked_turf())
continue
L.Add(T)

Expand Down Expand Up @@ -1007,7 +1007,7 @@
/datum/tarot/reversed/the_world/activate(mob/living/target)
var/list/L = list()
for(var/turf/T in get_area_turfs(/area/mine/outpost)) //Lavaland is the abyss, but also too hot to send people too. Mining base should be fair!
if(is_blocked_turf(T))
if(T.is_blocked_turf())
continue
L.Add(T)

Expand Down
24 changes: 12 additions & 12 deletions code/game/machinery/deployable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,20 @@
new /obj/structure/barricade/security(get_turf(loc))
switch(mode)
if(VERTICAL)
var/target_turf = get_step(src, NORTH)
if(!(is_blocked_turf(target_turf)))
var/turf/target_turf = get_step(src, NORTH)
if(!(target_turf.is_blocked_turf()))
new /obj/structure/barricade/security(target_turf)

var/target_turf2 = get_step(src, SOUTH)
if(!(is_blocked_turf(target_turf2)))
var/turf/target_turf2 = get_step(src, SOUTH)
if(!(target_turf2.is_blocked_turf()))
new /obj/structure/barricade/security(target_turf2)
if(HORIZONTAL)
var/target_turf = get_step(src, EAST)
if(!(is_blocked_turf(target_turf)))
var/turf/target_turf = get_step(src, EAST)
if(!(target_turf.is_blocked_turf()))
new /obj/structure/barricade/security(target_turf)

var/target_turf2 = get_step(src, WEST)
if(!(is_blocked_turf(target_turf2)))
var/turf/target_turf2 = get_step(src, WEST)
if(!(target_turf2.is_blocked_turf()))
new /obj/structure/barricade/security(target_turf2)
qdel(src)

Expand Down Expand Up @@ -367,12 +367,12 @@

var/dir_left = turn(direction, -90)
var/dir_right = turn(direction, 90)
var/target_turf = get_step(src, dir_left)
if(!is_blocked_turf(target_turf))
var/turf/target_turf = get_step(src, dir_left)
if(!target_turf.is_blocked_turf())
connected_shields += new barricade_type(target_turf, src, FALSE, direction, dir_left)

var/target_turf2 = get_step(src, dir_right)
if(!is_blocked_turf(target_turf2))
var/turf/target_turf2 = get_step(src, dir_right)
if(!target_turf2.is_blocked_turf())
connected_shields += new barricade_type(target_turf2, src, FALSE, direction, dir_right)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@

/obj/effect/spawner/random/proc/has_unblocked_line(destination)
for(var/turf/potential_blockage as anything in get_line(get_turf(src), destination))
if(!is_blocked_turf(potential_blockage, exclude_mobs = TRUE))
if(!potential_blockage.is_blocked_turf(exclude_mobs = TRUE))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!potential_blockage.is_blocked_turf(exclude_mobs = TRUE))
if(!potential_blockage.is_blocked_turf(TRUE))

continue
return FALSE
return TRUE
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/caution.dm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
return
var/turf/T = get_turf(target)

if(is_blocked_turf(T, TRUE)) //can't put mines on a tile that has dense stuff
if(T.is_blocked_turf(exclude_mobs = TRUE)) //can't put mines on a tile that has dense stuff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(T.is_blocked_turf(exclude_mobs = TRUE)) //can't put mines on a tile that has dense stuff
if(T.is_blocked_turf(TRUE)) //can't put mines on a tile that has dense stuff

to_chat(user, "<span class='notice'>The space is occupied! You cannot place a mine there!</span>")
return
if(!use(1)) //Can't place a landmine if you don't have a landmine
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/holosign_projector.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
to_chat(user, "<span class='notice'>You use [src] to deactivate [H].</span>")
qdel(H)
else
if(!is_blocked_turf(T, TRUE)) //can't put holograms on a tile that has dense stuff
if(!T.is_blocked_turf(exclude_mobs = TRUE)) //can't put holograms on a tile that has dense stuff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!T.is_blocked_turf(exclude_mobs = TRUE)) //can't put holograms on a tile that has dense stuff
if(!T.is_blocked_turf(TRUE)) //can't put holograms on a tile that has dense stuff

if(holocreator_busy)
to_chat(user, "<span class='notice'>[src] is busy creating a hologram.</span>")
return
Expand All @@ -42,7 +42,7 @@
holocreator_busy = FALSE
if(length(signs) >= max_signs)
return
if(is_blocked_turf(T, TRUE)) //don't try to sneak dense stuff on our tile during the wait.
if(T.is_blocked_turf(exclude_mobs = TRUE)) //don't try to sneak dense stuff on our tile during the wait.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(T.is_blocked_turf(exclude_mobs = TRUE)) //don't try to sneak dense stuff on our tile during the wait.
if(T.is_blocked_turf(TRUE)) //don't try to sneak dense stuff on our tile during the wait.

return
H = new holosign_type(get_turf(target), src)
to_chat(user, "<span class='notice'>You create [H] with [src].</span>")
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/melee/melee_misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@
return
var/list/turfs = list()
for(var/turf/T in orange(1, get_turf(target)))
if(is_blocked_turf(T, TRUE))
if(T.is_blocked_turf(exclude_mobs = TRUE))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(T.is_blocked_turf(exclude_mobs = TRUE))
if(T.is_blocked_turf(TRUE))

continue
turfs += T

Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/scrolls.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
var/list/L = list()

for(var/turf/T in get_area_turfs(thearea.type))
if(is_blocked_turf(T))
if(T.is_blocked_turf())
continue
L.Add(T)

Expand Down
42 changes: 42 additions & 0 deletions code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -875,3 +875,45 @@
/// encounter lava
/turf/proc/can_cross_safely(atom/movable/crossing)
return TRUE

/**
* Check whether we are blocked by something dense in our contents with respect to a specific atom.
*
* Arguments:
* * exclude_mobs - If TRUE, ignores dense mobs on the turf.
* * source_atom - If this is not null, will check whether any contents on the
* turf can block this atom specifically. Also ignores itself on the turf.
* * ignore_atoms - Check will ignore any atoms in this list. Useful to prevent
* an atom from blocking itself on the turf.
* * type_list - are we checking for types of atoms to ignore and not physical atoms
*/
/turf/proc/is_blocked_turf(exclude_mobs = FALSE, source_atom = null, list/ignore_atoms, type_list = FALSE)
if(density)
return TRUE

for(var/atom/movable/movable_content as anything in contents)
// If a source_atom is specified, that's what we're checking
// blockage with respect to, so we ignore it
if(movable_content == source_atom)
continue

// Prevents jaunting onto the AI core cheese, AI should always block a
// turf due to being a dense mob even when unanchored
if(is_ai(movable_content))
return TRUE

// don't consider ignored atoms or their types
if(length(ignore_atoms))
if(!type_list && (movable_content in ignore_atoms))
continue
else if(type_list && is_type_in_list(movable_content, ignore_atoms))
continue

// If the thing is dense AND we're including mobs or the thing isn't a
// mob AND if there's a source atom and it cannot pass through the thing
// on the turf, we consider the turf blocked.
if(movable_content.density && (!exclude_mobs || !ismob(movable_content)))
if(source_atom && movable_content.CanPass(source_atom, get_dir(src, source_atom)))
continue
return TRUE
return FALSE
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
/datum/syndicate_contract/proc/handle_target_return(mob/living/M)
var/list/turf/possible_turfs = list()
for(var/turf/T in contract.extraction_zone.contents)
if(!isspaceturf(T) && !is_blocked_turf(T))
if(!isspaceturf(T) && !T.is_blocked_turf())
possible_turfs += T

var/turf/destination = length(possible_turfs) ? pick(possible_turfs) : pick(GLOB.latejoin)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/events/anomaly_event.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var/list/candidate_turfs = get_area_turfs(impact_area)
while(length(candidate_turfs))
var/turf/candidate = pick_n_take(candidate_turfs)
if(!is_blocked_turf(candidate,TRUE))
if(!candidate.is_blocked_turf(exclude_mobs = TRUE))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!candidate.is_blocked_turf(exclude_mobs = TRUE))
if(!candidate.is_blocked_turf(TRUE))

target_turf = candidate
break
if(target_turf)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/events/infestation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if(!destination)
continue
for(var/turf/simulated/floor/F in destination.contents)
if(!is_blocked_turf(F))
if(!F.is_blocked_turf())
turfs += F
if(length(turfs))
spawn_area_type = area_type
Expand Down
2 changes: 1 addition & 1 deletion code/modules/events/tear.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var/list/area_turfs = get_area_turfs(impact_area)
while(length(area_turfs))
var/turf/T = pick_n_take(area_turfs)
if(is_blocked_turf(T))
if(T.is_blocked_turf())
continue

// Give ghosts some time to jump there before it begins.
Expand Down
8 changes: 4 additions & 4 deletions code/modules/hallucinations/effects/major.dm
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

var/list/locs = list()
for(var/turf/T in oview(world.view, target))
if(!is_blocked_turf(T))
if(!T.is_blocked_turf())
locs += T
if(!length(locs))
qdel(src)
Expand Down Expand Up @@ -124,7 +124,7 @@
// Find a spot for the scientist to spawn
var/list/locs = list()
for(var/turf/T in orange(1, target))
if(!is_blocked_turf(T))
if(!T.is_blocked_turf())
locs += T
locs -= get_turf(agent)
if(!length(locs))
Expand Down Expand Up @@ -278,7 +278,7 @@

var/list/locs = list()
for(var/turf/T in oview(world.view / 2, target))
if(!is_blocked_turf(T))
if(!T.is_blocked_turf())
locs += T
if(!length(locs))
qdel(src)
Expand Down Expand Up @@ -357,7 +357,7 @@
var/list/locs = list()
for(var/turf/T in oview(world.view / 2, target))
var/light_amount = T.get_lumcount()
if(!is_blocked_turf(T) && light_amount <= 0.5)
if(!T.is_blocked_turf() && light_amount <= 0.5)
locs += T
if(!length(locs))
return INITIALIZE_HINT_QDEL
Expand Down
11 changes: 6 additions & 5 deletions code/modules/hallucinations/effects/moderate.dm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

var/list/locs = list()
for(var/turf/T in oview(world.view, target))
if(!is_blocked_turf(T))
if(!T.is_blocked_turf())
locs += T
if(!length(locs))
qdel(src)
Expand Down Expand Up @@ -195,7 +195,7 @@
// Let's check if we can spawn somewhere first
var/list/locs = list()
for(var/turf/T in oview(world.view, target))
if(isfloorturf(T) && !is_blocked_turf(T))
if(isfloorturf(T) && !T.is_blocked_turf())
locs += T
if(!length(locs))
qdel(src)
Expand Down Expand Up @@ -257,7 +257,8 @@

var/list/vents = list()
for(var/obj/machinery/atmospherics/unary/vent_pump/vent in oview(world.view, target))
if(!is_blocked_turf(vent) && !vent.welded)
var/turf/vent_turf = get_turf(vent)
if(!vent_turf.is_blocked_turf() && !vent.welded)
vents += vent
if(!length(vents))
qdel(src)
Expand Down Expand Up @@ -320,7 +321,7 @@

var/list/locs = list()
for(var/turf/T in oview(world.view, target))
if(isfloorturf(T) && !is_blocked_turf(T))
if(isfloorturf(T) && !T.is_blocked_turf())
locs += T
if(!length(locs))
qdel(src)
Expand Down Expand Up @@ -512,7 +513,7 @@

var/list/locs = list()
for(var/turf/T in oview(world.view / 2, target))
if(!is_blocked_turf(T))
if(!T.is_blocked_turf())
locs += T
if(!length(locs))
return INITIALIZE_HINT_QDEL
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mining/lavaland/loot/colossus_loot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
var/turf/T = Stuff
if((isspaceturf(T) || isfloorturf(T)) && NewTerrainFloors)
var/turf/simulated/O = T.ChangeTurf(NewTerrainFloors, keep_icon = FALSE)
if(prob(florachance) && length(NewFlora) && !is_blocked_turf(O))
if(prob(florachance) && length(NewFlora) && !O.is_blocked_turf())
var/atom/Picked = pick(NewFlora)
new Picked(O)
continue
Expand Down
Loading