ID:136448
 
I'd be ecstatic if we could have a proc like it. It would return a list of all types that are direct children of the node fed into the procedure.

For example, if a game had the following types:

/mob
/mob/vehicle/car
/mob/vehicle/city_bus
/mob/vehicle/scooter
/mob/person

...then children(/mob) would result in a list containing:

/mob/vehicle
/mob/person

...without including any nodes that aren't the current node's direct children.

As far as I'm aware, there's no way to do this manually within DM without using typesof(), converting the types into strings, and then cutting off the excess. An alternate method involves using typesof(), converting the types into instances, and then checking to see if their parent_type matches the type fed into the procedure. Either way is extremely inefficient.

Some other wording than plain old "children" might be necessary to avoid name conflicts, since "children" is a fairly common word. "pathchildren" comes to mind.
proc/pathchildren(type)
//Soft-coded alternative until/unless Dantom makes a hard-coded version.
//This procedure is inefficient -- it's nice and quick, granted, but it
// is far less efficient than it should be.
ASSERT(ispath(type))
var/type_string = "[type]"

var/list/types = typesof(type)
var/list/final = list()
for(var/X in types)
var/string = "[X]"
for(var/i = lentext(string), i > 1, i--) //find the last '/' in the string
if(copytext(string,i,i+1) == "/")
string = copytext(string,1,i) //cut off string after that point
if(string == type_string) final += X //if they match, then it's a child
break

return(final)


mob/verb/test_children(type in typesof(/atom))
for(var/X in pathchildren(type))
usr << X
I use the children() function so much on lpmuds, its pathetic. :)

Seriously, though, it is extremely useful.