Skip to content

Commit 45e88ff

Browse files
refactor is_blocked_turf (#29324)
1 parent 7faed06 commit 45e88ff

File tree

33 files changed

+107
-75
lines changed

33 files changed

+107
-75
lines changed

code/__HELPERS/unsorted.dm

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -641,23 +641,6 @@ Returns 1 if the chain up to the area contains the given typepath
641641

642642
return 1
643643

644-
/proc/is_blocked_turf(turf/T, exclude_mobs, list/excluded_objs)
645-
if(T.density)
646-
return TRUE
647-
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
648-
return TRUE
649-
if(!exclude_mobs)
650-
for(var/mob/living/L in T)
651-
if(L.density)
652-
return TRUE
653-
var/any_excluded_objs = length(excluded_objs)
654-
for(var/obj/O in T)
655-
if(any_excluded_objs && (O in excluded_objs))
656-
continue
657-
if(O.density)
658-
return TRUE
659-
return FALSE
660-
661644
//Returns: all the areas in the world
662645
/proc/return_areas()
663646
var/list/area/areas = list()

code/controllers/subsystem/SSshuttles.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ SUBSYSTEM_DEF(shuttle)
361361

362362
if(!length(supply_shuttle_turfs))
363363
for(var/turf/simulated/T in supply.areaInstance)
364-
if(is_blocked_turf(T))
364+
if(T.is_blocked_turf())
365365
continue
366366
supply_shuttle_turfs += T
367367
if(!length(supply_shuttle_turfs)) // In case some nutjob walled the supply shuttle 10 minutes into the round

code/datums/ai/basic_mobs/basic_ai_behaviors/basic_attacking.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
var/turf/target_turf = get_step(our_turf, direction)
116116
if(isnull(target_turf))
117117
continue
118-
if(is_blocked_turf(target_turf) || get_dist(target_turf, target) > get_dist(living_pawn, target))
118+
if(target_turf.is_blocked_turf() || get_dist(target_turf, target) > get_dist(living_pawn, target))
119119
continue
120120
possible_turfs += target_turf
121121

code/datums/ai/basic_mobs/basic_ai_behaviors/run_away_from_target.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
var/turf/return_turf
5353
for(var/i in 1 to run_distance)
5454
var/turf/test_destination = get_ranged_target_turf_direct(source, target, range = i, offset = angle)
55-
if(is_blocked_turf(test_destination, excluded_objs = GLOB.airlocks + src))
55+
if(test_destination.is_blocked_turf(source_atom = source, ignore_atoms = GLOB.airlocks))
5656
break
5757
return_turf = test_destination
5858
return return_turf

code/datums/components/shelved.dm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@
5959
for(var/turf/turf_in_view in view(2, get_turf(structure_parent)))
6060
if(!isfloorturf(turf_in_view))
6161
continue
62+
var/blocked_los = FALSE
6263
for(var/turf/potential_blockage as anything in get_line(get_turf(structure_parent), turf_in_view))
63-
if(!is_blocked_turf(potential_blockage, exclude_mobs = TRUE, excluded_objs = list(parent)))
64-
nearby_empty_tiles += turf_in_view
64+
if(potential_blockage.is_blocked_turf(exclude_mobs = TRUE, source_atom = parent))
65+
blocked_los = TRUE
66+
break
67+
if(!blocked_los)
68+
nearby_empty_tiles += turf_in_view
6569

6670
var/itemcount = 1
6771
for(var/obj/item/I in structure_parent.loc)

code/datums/spells/ethereal_jaunt.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
sleep(jaunt_in_time)
6262
qdel(holder)
6363
if(!QDELETED(target))
64-
if(is_blocked_turf(mobloc, TRUE))
64+
if(mobloc.is_blocked_turf(exclude_mobs = TRUE))
6565
for(var/turf/T in orange(7))
6666
if(isspaceturf(T))
6767
continue

code/game/atoms_movable.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@
10531053

10541054
var/has_tried_to_move = FALSE
10551055

1056-
if(is_blocked_turf(target_turf, TRUE, excluded_objs = list(src)))
1056+
if(target_turf.is_blocked_turf(exclude_mobs = TRUE, ignore_atoms = list(src)))
10571057
has_tried_to_move = TRUE
10581058
if(!Move(target_turf, crush_dir))
10591059
// we'll try to move, and if we didn't end up going anywhere, then we do nothing.

code/game/gamemodes/malfunction/Malf_Modules.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@
710710
to_chat(src, "<span class='warning'>You don't have camera vision of this location!</span>")
711711
addtimer(CALLBACK(src, PROC_REF(remove_transformer_image), client, I, deploylocation), 3 SECONDS)
712712
return FALSE
713-
if(is_blocked_turf(deploylocation))
713+
if(deploylocation.is_blocked_turf())
714714
to_chat(src, "<span class='warning'>That area must be clear of objects!</span>")
715715
addtimer(CALLBACK(src, PROC_REF(remove_transformer_image), client, I, deploylocation), 3 SECONDS)
716716
return FALSE

code/game/gamemodes/wizard/magic_tarot.dm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@
384384
/datum/tarot/the_emperor/activate(mob/living/target)
385385
var/list/L = list()
386386
for(var/turf/T in get_area_turfs(/area/station/command/bridge))
387-
if(is_blocked_turf(T))
387+
if(T.is_blocked_turf())
388388
continue
389389
L.Add(T)
390390

@@ -576,7 +576,7 @@
576576
/datum/tarot/the_stars/activate(mob/living/target)
577577
var/list/L = list()
578578
for(var/turf/T in get_area_turfs(/area/station/security/evidence))
579-
if(is_blocked_turf(T))
579+
if(T.is_blocked_turf())
580580
continue
581581
L.Add(T)
582582

@@ -1007,7 +1007,7 @@
10071007
/datum/tarot/reversed/the_world/activate(mob/living/target)
10081008
var/list/L = list()
10091009
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!
1010-
if(is_blocked_turf(T))
1010+
if(T.is_blocked_turf())
10111011
continue
10121012
L.Add(T)
10131013

code/game/machinery/deployable.dm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,20 @@
209209
new /obj/structure/barricade/security(get_turf(loc))
210210
switch(mode)
211211
if(VERTICAL)
212-
var/target_turf = get_step(src, NORTH)
213-
if(!(is_blocked_turf(target_turf)))
212+
var/turf/target_turf = get_step(src, NORTH)
213+
if(!(target_turf.is_blocked_turf()))
214214
new /obj/structure/barricade/security(target_turf)
215215

216-
var/target_turf2 = get_step(src, SOUTH)
217-
if(!(is_blocked_turf(target_turf2)))
216+
var/turf/target_turf2 = get_step(src, SOUTH)
217+
if(!(target_turf2.is_blocked_turf()))
218218
new /obj/structure/barricade/security(target_turf2)
219219
if(HORIZONTAL)
220-
var/target_turf = get_step(src, EAST)
221-
if(!(is_blocked_turf(target_turf)))
220+
var/turf/target_turf = get_step(src, EAST)
221+
if(!(target_turf.is_blocked_turf()))
222222
new /obj/structure/barricade/security(target_turf)
223223

224-
var/target_turf2 = get_step(src, WEST)
225-
if(!(is_blocked_turf(target_turf2)))
224+
var/turf/target_turf2 = get_step(src, WEST)
225+
if(!(target_turf2.is_blocked_turf()))
226226
new /obj/structure/barricade/security(target_turf2)
227227
qdel(src)
228228

@@ -367,12 +367,12 @@
367367

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

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

378378

code/game/objects/effects/spawners/random/random_spawner.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180

181181
/obj/effect/spawner/random/proc/has_unblocked_line(destination)
182182
for(var/turf/potential_blockage as anything in get_line(get_turf(src), destination))
183-
if(!is_blocked_turf(potential_blockage, exclude_mobs = TRUE))
183+
if(!potential_blockage.is_blocked_turf(exclude_mobs = TRUE))
184184
continue
185185
return FALSE
186186
return TRUE

code/game/objects/items/weapons/caution.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
return
8383
var/turf/T = get_turf(target)
8484

85-
if(is_blocked_turf(T, TRUE)) //can't put mines on a tile that has dense stuff
85+
if(T.is_blocked_turf(exclude_mobs = TRUE)) //can't put mines on a tile that has dense stuff
8686
to_chat(user, "<span class='notice'>The space is occupied! You cannot place a mine there!</span>")
8787
return
8888
if(!use(1)) //Can't place a landmine if you don't have a landmine

code/game/objects/items/weapons/holosign_projector.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
to_chat(user, "<span class='notice'>You use [src] to deactivate [H].</span>")
2929
qdel(H)
3030
else
31-
if(!is_blocked_turf(T, TRUE)) //can't put holograms on a tile that has dense stuff
31+
if(!T.is_blocked_turf(exclude_mobs = TRUE)) //can't put holograms on a tile that has dense stuff
3232
if(holocreator_busy)
3333
to_chat(user, "<span class='notice'>[src] is busy creating a hologram.</span>")
3434
return
@@ -42,7 +42,7 @@
4242
holocreator_busy = FALSE
4343
if(length(signs) >= max_signs)
4444
return
45-
if(is_blocked_turf(T, TRUE)) //don't try to sneak dense stuff on our tile during the wait.
45+
if(T.is_blocked_turf(exclude_mobs = TRUE)) //don't try to sneak dense stuff on our tile during the wait.
4646
return
4747
H = new holosign_type(get_turf(target), src)
4848
to_chat(user, "<span class='notice'>You create [H] with [src].</span>")

code/game/objects/items/weapons/melee/melee_misc.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@
512512
return
513513
var/list/turfs = list()
514514
for(var/turf/T in orange(1, get_turf(target)))
515-
if(is_blocked_turf(T, TRUE))
515+
if(T.is_blocked_turf(exclude_mobs = TRUE))
516516
continue
517517
turfs += T
518518

code/game/objects/items/weapons/scrolls.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
var/list/L = list()
5151

5252
for(var/turf/T in get_area_turfs(thearea.type))
53-
if(is_blocked_turf(T))
53+
if(T.is_blocked_turf())
5454
continue
5555
L.Add(T)
5656

code/game/turfs/turf.dm

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,3 +875,45 @@
875875
/// encounter lava
876876
/turf/proc/can_cross_safely(atom/movable/crossing)
877877
return TRUE
878+
879+
/**
880+
* Check whether we are blocked by something dense in our contents with respect to a specific atom.
881+
*
882+
* Arguments:
883+
* * exclude_mobs - If TRUE, ignores dense mobs on the turf.
884+
* * source_atom - If this is not null, will check whether any contents on the
885+
* turf can block this atom specifically. Also ignores itself on the turf.
886+
* * ignore_atoms - Check will ignore any atoms in this list. Useful to prevent
887+
* an atom from blocking itself on the turf.
888+
* * type_list - are we checking for types of atoms to ignore and not physical atoms
889+
*/
890+
/turf/proc/is_blocked_turf(exclude_mobs = FALSE, source_atom = null, list/ignore_atoms, type_list = FALSE)
891+
if(density)
892+
return TRUE
893+
894+
for(var/atom/movable/movable_content as anything in contents)
895+
// If a source_atom is specified, that's what we're checking
896+
// blockage with respect to, so we ignore it
897+
if(movable_content == source_atom)
898+
continue
899+
900+
// Prevents jaunting onto the AI core cheese, AI should always block a
901+
// turf due to being a dense mob even when unanchored
902+
if(is_ai(movable_content))
903+
return TRUE
904+
905+
// don't consider ignored atoms or their types
906+
if(length(ignore_atoms))
907+
if(!type_list && (movable_content in ignore_atoms))
908+
continue
909+
else if(type_list && is_type_in_list(movable_content, ignore_atoms))
910+
continue
911+
912+
// If the thing is dense AND we're including mobs or the thing isn't a
913+
// mob AND if there's a source atom and it cannot pass through the thing
914+
// on the turf, we consider the turf blocked.
915+
if(movable_content.density && (!exclude_mobs || !ismob(movable_content)))
916+
if(source_atom && movable_content.CanPass(source_atom, get_dir(src, source_atom)))
917+
continue
918+
return TRUE
919+
return FALSE

code/modules/antagonists/traitor/contractor/datums/syndicate_contract.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@
534534
/datum/syndicate_contract/proc/handle_target_return(mob/living/M)
535535
var/list/turf/possible_turfs = list()
536536
for(var/turf/T in contract.extraction_zone.contents)
537-
if(!isspaceturf(T) && !is_blocked_turf(T))
537+
if(!isspaceturf(T) && !T.is_blocked_turf())
538538
possible_turfs += T
539539

540540
var/turf/destination = length(possible_turfs) ? pick(possible_turfs) : pick(GLOB.latejoin)

code/modules/events/anomaly_event.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
var/list/candidate_turfs = get_area_turfs(impact_area)
2626
while(length(candidate_turfs))
2727
var/turf/candidate = pick_n_take(candidate_turfs)
28-
if(!is_blocked_turf(candidate,TRUE))
28+
if(!candidate.is_blocked_turf(exclude_mobs = TRUE))
2929
target_turf = candidate
3030
break
3131
if(target_turf)

code/modules/events/infestation.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
if(!destination)
3838
continue
3939
for(var/turf/simulated/floor/F in destination.contents)
40-
if(!is_blocked_turf(F))
40+
if(!F.is_blocked_turf())
4141
turfs += F
4242
if(length(turfs))
4343
spawn_area_type = area_type

code/modules/events/tear.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var/list/area_turfs = get_area_turfs(impact_area)
2424
while(length(area_turfs))
2525
var/turf/T = pick_n_take(area_turfs)
26-
if(is_blocked_turf(T))
26+
if(T.is_blocked_turf())
2727
continue
2828

2929
// Give ghosts some time to jump there before it begins.

code/modules/hallucinations/effects/major.dm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696
var/list/locs = list()
9797
for(var/turf/T in oview(world.view, target))
98-
if(!is_blocked_turf(T))
98+
if(!T.is_blocked_turf())
9999
locs += T
100100
if(!length(locs))
101101
qdel(src)
@@ -124,7 +124,7 @@
124124
// Find a spot for the scientist to spawn
125125
var/list/locs = list()
126126
for(var/turf/T in orange(1, target))
127-
if(!is_blocked_turf(T))
127+
if(!T.is_blocked_turf())
128128
locs += T
129129
locs -= get_turf(agent)
130130
if(!length(locs))
@@ -278,7 +278,7 @@
278278

279279
var/list/locs = list()
280280
for(var/turf/T in oview(world.view / 2, target))
281-
if(!is_blocked_turf(T))
281+
if(!T.is_blocked_turf())
282282
locs += T
283283
if(!length(locs))
284284
qdel(src)
@@ -357,7 +357,7 @@
357357
var/list/locs = list()
358358
for(var/turf/T in oview(world.view / 2, target))
359359
var/light_amount = T.get_lumcount()
360-
if(!is_blocked_turf(T) && light_amount <= 0.5)
360+
if(!T.is_blocked_turf() && light_amount <= 0.5)
361361
locs += T
362362
if(!length(locs))
363363
return INITIALIZE_HINT_QDEL

code/modules/hallucinations/effects/moderate.dm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
var/list/locs = list()
8383
for(var/turf/T in oview(world.view, target))
84-
if(!is_blocked_turf(T))
84+
if(!T.is_blocked_turf())
8585
locs += T
8686
if(!length(locs))
8787
qdel(src)
@@ -195,7 +195,7 @@
195195
// Let's check if we can spawn somewhere first
196196
var/list/locs = list()
197197
for(var/turf/T in oview(world.view, target))
198-
if(isfloorturf(T) && !is_blocked_turf(T))
198+
if(isfloorturf(T) && !T.is_blocked_turf())
199199
locs += T
200200
if(!length(locs))
201201
qdel(src)
@@ -257,7 +257,8 @@
257257

258258
var/list/vents = list()
259259
for(var/obj/machinery/atmospherics/unary/vent_pump/vent in oview(world.view, target))
260-
if(!is_blocked_turf(vent) && !vent.welded)
260+
var/turf/vent_turf = get_turf(vent)
261+
if(!vent_turf.is_blocked_turf() && !vent.welded)
261262
vents += vent
262263
if(!length(vents))
263264
qdel(src)
@@ -320,7 +321,7 @@
320321

321322
var/list/locs = list()
322323
for(var/turf/T in oview(world.view, target))
323-
if(isfloorturf(T) && !is_blocked_turf(T))
324+
if(isfloorturf(T) && !T.is_blocked_turf())
324325
locs += T
325326
if(!length(locs))
326327
qdel(src)
@@ -512,7 +513,7 @@
512513

513514
var/list/locs = list()
514515
for(var/turf/T in oview(world.view / 2, target))
515-
if(!is_blocked_turf(T))
516+
if(!T.is_blocked_turf())
516517
locs += T
517518
if(!length(locs))
518519
return INITIALIZE_HINT_QDEL

code/modules/mining/lavaland/loot/colossus_loot.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
var/turf/T = Stuff
118118
if((isspaceturf(T) || isfloorturf(T)) && NewTerrainFloors)
119119
var/turf/simulated/O = T.ChangeTurf(NewTerrainFloors, keep_icon = FALSE)
120-
if(prob(florachance) && length(NewFlora) && !is_blocked_turf(O))
120+
if(prob(florachance) && length(NewFlora) && !O.is_blocked_turf())
121121
var/atom/Picked = pick(NewFlora)
122122
new Picked(O)
123123
continue

0 commit comments

Comments
 (0)