ID:195136
 
//Title: Type Path Children
//Credit to: Jtgibson
//Contributed by: Jtgibson


//This function reveals all of the direct children of a particular object type.
// For example, if you had the following object types in your code:

// /obj/weapon
// /obj/weapon/firearm
// /obj/weapon/firearm/pistol
// /obj/weapon/firearm/rifle
// /obj/weapon/melee
// /obj/weapon/melee/knife
// /obj/weapon/melee/club

// ...and you used pathchildren(/obj/weapon), you would receive:

// /obj/weapon/firearm
// /obj/weapon/melee

//A /obj/weapon/firearm/pistol does not directly inherit from /obj/weapon
// while /obj/weapon/firearm does.

//You probably won't find a use for this procedure in normal circumstances,
// but high-tech datum architectures might need it. If that sounds complex, that's
// because it is. ;-)


proc/pathchildren(type)
//This is a soft-coded alternative until/unless Dantom makes a hard-coded
// version. It is inefficient -- it's nice and quick, granted, but it can
// only really be considered inefficient when compared to a hard-coded alternative.
ASSERT(ispath(type))
var/type_string = "[type]"

var/list/types = typesof(type)
var/list/final = list()
for(var/X in types)
var/string = "[X]"
var/last_pos
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 the strings match, then it's a child
break

return(final)