Number_War_Spawn()
set desc = "Start a Number War"
set category = "Tournament"
for(var/mob/M in world)
if(has_item(M,"/obj/items/card/number"))
alert(usr,"Numbers are detected in the world, please purge the existing Numbers before beginning.","Number War")
return
var/list/num_icons = icon_states('items_number.dmi')
num_icons -= "XXX"
num_icons -= "Blank"
var/num_x = 0
var/num_y = 0
while(num_icons.len)
for(var/X in num_icons)
num_x = rand(1,159)
num_y = rand(8,159)
var/turf/T = locate(num_x,num_y,1)
if(!T.density)
var/obj/items/card/number/O = new /obj/items/card/number
O.c_num = X
O.icon_state = "Blank"
O.Move(locate(num_x,num_y,1))
num_icons -= X
var/debug_num = 0
for(var/obj/items/card/number in world)
debug_num += 1
world << {"<font color=#9F9F9F size=+2><center><br><br>Numbers have been scattered around the world!<br><br></center></font>"}
world << "DEBUG: Number War - [debug_num] in world."
return
Problem description:
I have this verb that is spawning roughly 80 objects randomly around the map. I'm running in to a few issues I'm trying to work out. Mainly how to prevent the objs from spawning in obstructed locations for the players.
I have 2 main issues,
Is there a way to detect if there is an obj overlapping the spawn location when the obj is using a bound_width or bound_height larger than 32? Basically if the object is bound_width 64, is there a way to prevent the new obj from spawning on either of the tiles occupied by the existing obj?
Is there a way to detect if there is something overlapping a location layer-wise. Like, I have a few trees where the tops of them are a higher layer than the objs and mobs, is there a way to detect when a location has something layering over it, even if it's a large icon from another location?
Probably what makes the most sense, though, is simply to choose at random and then have some kind of proc that checks if the turf is obstructed/unreachable in some way (maybe mark those on the map with a var, or make all of those turfs dense if they're never gonna be reachable), and then looks for any nearby objs/turfs with big icons such as trees that might overlap the chosen turf. If the random choice fails, try again. (This can be made foolproof by keeping a list of possibilities and removing from it as you go, which also means you can remove all nearby turfs so the objects aren't placed close together.)
Ultimately there's no simple way to determine if, for instance, a turf is being visually obstructed by a tree. That's something you'd want to plan for via some vars or something, like maybe have a var called "big" and if that's true, you'd also include some stats about the object's extent.
Then when you pick a turf for a potential object placement, you look for any atoms within a certain range that are marked as big. Then you check to see if the turf you picked is covered by that big atom, using those big_x/y/width/height vars. If there are no obstructions, you're good; otherwise, keep searching.