Skip to content
Open
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
44 changes: 34 additions & 10 deletions code/modules/mining/ore_veins.dm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ GLOBAL_LIST_EMPTY(ore_veins)
return

var/turf/open/spawning_tile = pick_tile()
if(!spawning_tile) // PENTEST EDIT - No valid tile found, skip this spawn
continue // PENTEST EDUT

var/obj/effect/drill_spawner/bug_breach = new /obj/effect/drill_spawner(spawning_tile)
active_spawners += bug_breach
Expand All @@ -153,16 +155,38 @@ GLOBAL_LIST_EMPTY(ore_veins)
if(!length(peel))
peel = turf_peel(spawn_distance_max, spawn_distance_min, src, TRUE)
var/turf/open/spawning_tile
if(length(peel))
spawning_tile = pick(peel)
else
spawning_tile = pick(circleviewturfs(loc, spawn_distance_max))
if(istype(spawning_tile, /turf/closed))
return pick_tile(peel)
for(var/obj/object in spawning_tile.contents)
if(object.density || istype(object, /obj/effect/drill_spawner))
return pick_tile(peel)
return spawning_tile

// PENTEST EDIT START - Try up to 50 times to find a valid turf to prevent infinite recursion
var/attempts = 0
while(attempts < 50)
attempts++

if(length(peel))
spawning_tile = pick(peel)
peel -= spawning_tile // Remove from list to avoid picking same invalid turf again
else
// Fallback to full circle if peel is exhausted
var/list/circle_turfs = circleviewturfs(loc, spawn_distance_max)
if(!length(circle_turfs))
return null // No turfs available at all
spawning_tile = pick(circle_turfs)

// Check if turf is valid
if(istype(spawning_tile, /turf/closed))
continue // Try next turf

var/is_blocked = FALSE
for(var/obj/object in spawning_tile.contents)
if(object.density || istype(object, /obj/effect/drill_spawner))
is_blocked = TRUE
break

if(!is_blocked)
return spawning_tile // Found a valid turf!

// If we couldn't find a valid turf after 50 attempts, return null
return null
// PENTEST EDIT END

/obj/structure/vein/proc/increment_wave_tally()
if(!our_drill || !our_drill.active)
Expand Down
Loading