ID:195055
 
//Title: Nulliparous Type Paths
//Credit to: Jtgibson
//Contributed by: Jtgibson


/*
nulˇlipˇaˇra (nuh-lip'-er-uh)
- plural -aˇrae (-uh-ree)

(obstetrics) a woman who has never borne a child.

nullipara. (n.d.). Dictionary.com Unabridged (v 1.1).
Retrieved April 03, 2008, http://dictionary.reference.com/browse/nullipara


These procs are intended to allow you to determine whether a type has no
child nodes, returning true if it does not. For instance, the nulliparous
types are flagged by asterisks in the following example:

/mob
/mob/person
/mob/person/player *
/mob/person/nonplayer *
/mob/monster
/mob/monster/goblin
/mob/monster/goblin/green_goblin *
/mob/monster/goblin/red_goblin *
/mob/monster/hobgoblin *

Very handy for systems where you use types as "folders" instead of as
"generic" objects; only the nulliparous types in the above list should be
placeable on the map.
*/



//Returns 1 if the specified parameter is nulliparous, 0 otherwise.
proc/nulliparous(type)
var/tmp/list/types = typesof(type); return (types.len == 1)


//Returns a list of all of the nulliparous types derived from the
// given type path (excluding the type itself).
proc/nulliparae(type)
var/list/types = typesof(type) - type; . = list()
for(var/nutype in types) if(nulliparous(nutype)) . += nutype



///*
//Testing code/sample implementation

//Asterisks have been placed for sake of example. Any node without
// an asterisk will never show up as nulliparous.

mob
person
player // *
nonplayer // *

monster
goblin
green_goblin // *
red_goblin // *

hobgoblin // *

obj
item
equipment
weapon
sword
short_sword // *
bow
long_bow // *
short_bow // *
crossbow
heavy_crossbow // *
light_crossbow // *
shieldbow // *
tool
adze // *
axe // *
chisel // *
drill // *
article
clothing
shirt // *
pants // *
armour
body
plate_mail // *
chain_mail // *
legs
plate_leggings // *
chain_leggings // *


mob/verb/test_nulliparae(type in typesof(/datum))
usr << "Nulliparae of [type]:"
var/list/types = nulliparae(type)
for(var/nutype in types)
usr << nutype
usr << "Total nulliparous / total derived nodes: [length(types)] / \
[length(typesof(type) - type)]"
usr << ""

mob/verb/test_nulliparous(type in typesof(/datum))
if(nulliparous(type)) usr << "[type] is nulliparous"
else usr << "[type] is not nulliparous"

//*/
That is quite useful. *nods head in approval*