object utilities #52

Parent #79Owner #2Flags readSource RPG Core/rpgcore-patched.db

Aliases: object utilities

30 verbs · 6 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
has_propertythis none thisrxd#5210
all_properties all_verbsthis none thisrxd#5214
has_verbthis none thisrxd#5214
has_callable_verbthis none thisrxd#5212
match_verbthis none thisrxd#5212
isathis none thisrxd#529
ancestorsthis none thisrxd#5211
ordered_descendantsthis none thisrxd#529
containsthis none thisrxd#5211
all_contentsthis none thisrxd#526
findable_propertiesthis none thisrxd#5212
owned_propertiesthis none thisrxd#5215
property_conflictsthis none thisrxd#5231
descendants_with_property_suspendedthis none thisrxd#5217
locationsthis none thisrxd#528
all_properties_suspended all_verbs_suspendedthis none thisrxd#5215
connectedthis none thisrxd#524
isoneofthis none thisrxd#529
defines_verbthis none thisrxd#523
defines_propertythis none thisrxd#528
has_any_verb has_any_propertythis none thisrxd#523
has_readable_prop*erty hrpthis none thisrxd#528
descendants descendentsthis none thisrxd#5210
leavesthis none thisrxd#5211
branchesthis none thisrxd#5212
descendants_suspended descendents_suspendedthis none thisrxd#5212
leaves_suspendedthis none thisrxd#5214
branches_suspendedthis none thisrxd#5215
disown disinheritthis none thisrxd#5221
accessible_verbsthis none thisrxd#5210

Properties

PropertyDefinerFlagsOwnerValue
help_msg#79rc#2
list of 45{"These routines are useful for finding out information about individual objects.", "", "Examining everything an object has defined on it:", " all_verbs (object) => like it says", " all_properties (object) => likewise", " findable_properties(object) => tests to see if caller can \"find\" them", " owned_properties (object[, owner]) => tests for ownership", "", "Investigating inheritance:", " ancestors(object[,object...]) => all ancestors", " descendants (object) => all descendants", " ordered_descendants(object) => descendants, in a different order", " leaves (object) => descendants with no children", " branches (object) => descendants with children ", " isa (object,class) => true iff object is a descendant of class (or ==)", " property_conflicts (object,newparent) => can object chparent to newparent?", " isoneof (object,list) => true if object :isa class in list of parents", "", "Considering containment:", " contains (obj1, obj2) => Does obj1 contain obj2 (nested)?", " all_contents (object) => return all the (nested) contents of object", " locations (object) => list of location hierarchy above object", "", "Verifying verbs and properties:", " has_property(object,pname) => false/true according as object.(pname) exists", " has_readable_property(object,pname) => false/true if prop exists and is +r", " defines_property(object,pname) => does object *define* this property", " has_verb (object,vname) => false/{#obj} according as object:(vname) exists", " has_callable_verb => same, but verb must be callable from a program", " defines_verb(object,vname) => does this object *define* this verb", " match_verb (object,vname) => false/{location, newvname}", " (identify location and usable name of verb)", " accessible_verbs(object) => a list of verb names (or E_PERM) regardless of ", " readability of object", "", "Player checking:", " connected (object) => true if object is a player and is connected", "", "Suspending:", " Many of the above verbs have ..._suspended versions to assist with very large object hierarchies. The following exist:", " descendants_suspended ", " branches_suspended ", " leaves_suspended ", " all_properties_suspended ", " descendants_with_property_suspended"}
key#1c#2<clear>
aliases#1rc#2{"object utilities"}
description#1rc#2{"This is the object utilities utility package. See `help $object_utils' for more details."}
object_size#1r#36{22448, -1090650497}
html#1rc#2<clear>

Ancestry

Ancestors (nearest first): #79 Generic Utilities Package#1 Root Class

Children: none

Call graph

calls n52_9 #52:all_contents n52_9->n52_9 n52_12 #52:property_conflicts n42_0 #42:controls n52_12->n42_0 n52_25 #52:descendants_suspended n52_12->n52_25 n56_8 #56:suspend_if_needed n52_12->n56_8 n52_13 #52:descendants_with_property_suspended n52_13->n42_0 n52_13->n52_13 n52_19 #52:defines_property n52_0 #52:has_property n52_19->n52_0 n52_28 #52:disown n52_28->n42_0

Source

has_property

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1"Syntax:  has_property(OBJ, STR) => INT 0|1";
2"";
3"Does object have the specified property? Returns true if it is defined on the object or a parent.";
4{object, prop} = args;
5try
6object.(prop);
7return 1;
8except (E_PROPNF, E_INVIND)
9return 0;
10endtry

all_properties all_verbs

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1"Syntax:  all_properties (OBJ what)";
2"         all_verbs      (OBJ what)";
3"";
4"Returns all properties or verbs defined on `what' and all of its ancestors. Uses wizperms to get properties or verbs if the caller of this verb owns what, otherwise, uses caller's perms.";
5what = args[1];
6if (what.owner != caller_perms())
7set_task_perms(caller_perms());
8endif
9bif = (verb == "all_verbs") ? "verbs" | "properties";
10res = `call_function(bif, what) ! E_PERM => {}';
11while (valid(what = parent(what)))
12res = {@`call_function(bif, what) ! E_PERM => {}', @res};
13endwhile
14return res;

has_verb

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1":has_verb(OBJ object, STR verbname)";
2"Find out if an object has a verb matching the given verbname.";
3"Returns {location} if so, 0 if not, where location is the object or the ancestor on which the verb is actually defined.";
4{object, verbname} = args;
5while (valid(object))
6try
7if (verb_info(object, verbname))
8return {object};
9endif
10except (E_VERBNF)
11object = parent(object);
12endtry
13endwhile
14return 0;

has_callable_verb

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1"Usage:  has_callable_verb(object, verb)";
2"See if an object has a verb that can be called by another verb (i.e., that has its x permission bit set).";
3"Return {location}, where location is the object that defines the verb, or 0 if the object doesn't have the verb.";
4{object, verbname} = args;
5while (valid(object))
6if (`index(verb_info(object, verbname)[2], "x") ! E_VERBNF => 0' && verb_code(object, verbname))
7"Don't need to catch E_VERBNF in verb_code(), since it will never get there with the 0 &&";
8return {object};
9endif
10object = parent(object);
11endwhile
12return 0;

match_verb

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

none

Source

1":match_verb(OBJ object, STR verb)";
2"Find out if an object has a given verb, and some information about it.";
3"Returns {OBJ location, STR verb} if matched, 0 if not.";
4"Location is the object on which it is actually defined, verb is a name";
5"for the verb which can subsequently be used in verb_info (i.e., no";
6"asterisks).";
7verbname = strsub(args[2], "*", "");
8object = args[1];
9while (E_VERBNF == (info = `verb_info(object, verbname) ! E_VERBNF, E_INVARG'))
10object = parent(object);
11endwhile
12return info ? {object, verbname} | 0;

isa

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

Source

1":isa(x,y) == valid(x) && (y==x || y in :ancestors(x))";
2{what, targ} = args;
3while (valid(what))
4if (what == targ)
5return 1;
6endif
7what = parent(what);
8endwhile
9return 0;

ancestors

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

Source

1"Usage:  ancestors(object[, object...])";
2"Return a list of all ancestors of the object(s) in args, with no duplicates.";
3"If called with a single object, the result will be in order ascending up the inheritance hierarchy.  If called with multiple objects, it probably won't.";
4ret = {};
5for o in (args)
6what = o;
7while (valid(what = parent(what)))
8ret = setadd(ret, what);
9endwhile
10endfor
11return ret;

ordered_descendants

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

none

Source

1r = {what = args[1]};
2for k in (children(what))
3if (children(k))
4r = {@r, @this:(verb)(k)};
5else
6r = {@r, k};
7endif
8endfor
9return r;

contains

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

Source

1"$object_utils:contains(obj1, obj2) -- does obj1 contain obj2?";
2"";
3"Return true iff obj2 is under obj1 in the containment hierarchy; that is, if obj1 is obj2's location, or its location's location, or ...";
4{loc, what} = args;
5while (valid(what))
6what = what.location;
7if (what == loc)
8return valid(loc);
9endif
10endwhile
11return 0;

all_contents

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

Source

1"all_contents(object)";
2"Return a list of all objects contained (at some level) by object.";
3for y in (res = args[1].contents)
4y.contents && (res = {@res, @this:all_contents(y)});
5endfor
6return res;

findable_properties

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

none

Source

1"findable_properties(object)";
2"Return a list of properties on those members of object's ancestor list that are readable or are owned by the caller (or all properties if the caller is a wizard).";
3what = args[1];
4props = {};
5who = caller_perms();
6while (what != $nothing)
7if ((what.r || (who == what.owner)) || who.wizard)
8props = {@properties(what), @props};
9endif
10what = parent(what);
11endwhile
12return props;

owned_properties

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

none

Source

1"owned_properties(what[, who])";
2"Return a list of all properties on WHAT owned by WHO.";
3"Only wizardly verbs can specify WHO; mortal verbs can only search for properties owned by their own owners.  For more information, talk to Gary_Severn.";
4what = anc = args[1];
5who = ((c = caller_perms()).wizard && (length(args) > 1)) ? args[2] | c;
6props = {};
7while (anc != $nothing)
8for k in (properties(anc))
9if (property_info(what, k)[1] == who)
10props = listappend(props, k);
11endif
12endfor
13anc = parent(anc);
14endwhile
15return props;

property_conflicts

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1":property_conflicts(object,newparent)";
2"Looks for propertyname conflicts that would keep chparent(object,newparent)";
3"  from working.";
4"Returns a list of elements of the form {<propname>, @<objectlist>}";
5"where <objectlist> is list of descendents of object defining <propname>.";
6if (!valid(object = args[1]))
7return E_INVARG;
8elseif (!valid(newparent = args[2]))
9return (newparent == #-1) ? {} | E_INVARG;
10elseif (!($perm_utils:controls(caller_perms(), object) && (newparent.f || $perm_utils:controls(caller_perms(), newparent))))
11"... if you couldn't chparent anyway, you don't need to know...";
12return E_PERM;
13endif
14"... properties existing on newparent";
15"... cannot be present on object or any descendent...";
16props = conflicts = {};
17for o in ({object, @$object_utils:descendents_suspended(object)})
18for p in (properties(o))
19if (`property_info(newparent, p) ! E_PROPNF => 0')
20if (i = p in props)
21conflicts[i] = {@conflicts[i], o};
22else
23props = {@props, p};
24conflicts = {@conflicts, {p, o}};
25endif
26endif
27$command_utils:suspend_if_needed(0);
28endfor
29$command_utils:suspend_if_needed(0);
30endfor
31return conflicts;

descendants_with_property_suspended

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1":descendants_with_property_suspended(object,property)";
2" => list of descendants of object on which property is defined.";
3"calls suspend(0) as needed";
4{object, prop} = args;
5if ((caller == this) || (object.w || $perm_utils:controls(caller_perms(), object)))
6(ticks_left() < 4000) && suspend(0);
7if (`property_info(object, prop) ! E_PROPNF => 0')
8return {object};
9endif
10r = {};
11for c in (children(object))
12r = {@r, @this:descendants_with_property_suspended(c, prop)};
13endfor
14return r;
15else
16return E_PERM;
17endif

locations

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1"Usage:  locations(object)";
2"Return a listing of the location hierarchy above object.";
3ret = {};
4what = args[1];
5while (valid(what = what.location))
6ret = {@ret, what};
7endwhile
8return ret;

all_properties_suspended all_verbs_suspended

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1"Syntax:  all_properties_suspended (OBJ what)";
2"         all_verbs_suspended      (OBJ what)";
3"";
4"Returns all properties or verbs defined on `what' and all of its ancestors. Uses wizperms to get properties or verbs if the caller of this verb owns what, otherwise, uses caller's perms. Suspends as necessary";
5what = args[1];
6if (what.owner != caller_perms())
7set_task_perms(caller_perms());
8endif
9bif = (verb == "all_verbs") ? "verbs" | "properties";
10res = `call_function(bif, what) ! E_PERM => {}';
11while (valid(what = parent(what)))
12res = {@`call_function(bif, what) ! E_PERM => {}', @res};
13(ticks_left() < 4000) && suspend(0);
14endwhile
15return res;

connected

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

Source

1":connected(object) => true if object is a connected player.";
2"equivalent to (object in connected_players()) for valid players, perhaps with less server overhead.";
3"use object:is_listening() if you want to allow for puppets and other non-player objects that still 'care' about what's said.";
4return typeof(`connected_seconds(@args) ! E_INVARG') == INT;

isoneof

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

none

Source

1":isoneof(x,y) = x isa z, for some z in list y";
2{what, targ} = args;
3while (valid(what))
4if (what in targ)
5return 1;
6endif
7what = parent(what);
8endwhile
9return 0;

defines_verb

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1"Returns 1 if the verb is actually *defined* on this object, 0 else.";
2"Use this instead of :has_verb if your aim is to manipulate that verb code or whatever.";
3return `verb_info(@args) ! ANY => 0' && 1;

defines_property

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1":defines_property(OBJ object, STR property name) => Returns 1 if the property is actually *defined* on the object given";
2if (!valid(o = args[1]))
3return 0;
4elseif (!valid(p = parent(o)))
5return this:has_property(o, args[2]);
6else
7return (!this:has_property(p, args[2])) && this:has_property(o, args[2]);
8endif

has_any_verb has_any_property

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

none

Source

1":has_any_verb(object) / :has_any_property(object)";
2" -- does `object' have any verbs/properties?";
3return !(!`(verb == "has_any_verb") ? verbs(args[1]) | properties(args[1]) ! E_INVARG => 0');

has_readable_prop*erty hrp

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

none

Source

1":has_readable_property(OBJ object, STR property name) => 1 if property exists and is publically readable (has the r flag set true).";
2{object, prop} = args;
3try
4pinfo = property_info(object, prop);
5return index(pinfo[2], "r") != 0;
6except (E_PROPNF)
7return (prop in $code_utils.builtin_props) > 0;
8endtry

descendants descendents

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

Source

1":descendants (OBJ object) => {OBJs} all nested children of <object>";
2r = children(args[1]);
3i = 1;
4while (i <= length(r))
5if (kids = children(r[i]))
6r = {@r, @kids};
7endif
8i = i + 1;
9endwhile
10return r;

leaves

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

Source

1":leaves (OBJ object) => {OBJs} descendants of <object> that have no children";
2r = {args[1]};
3i = 1;
4while (i <= length(r))
5if (kids = children(r[i]))
6r[i..i] = kids;
7else
8i = i + 1;
9endif
10endwhile
11return r;

branches

Spec this none thisFlags rxdOwner #36Definer #52

Referenced by

none

Source

1":branches (OBJ object) => {OBJs} descendants of <object> that have children";
2r = args[1..1];
3i = 1;
4while (i <= length(r))
5if (kids = children(r[i]))
6r[i + 1..i] = kids;
7i = i + 1;
8else
9r[i..i] = {};
10endif
11endwhile
12return r;

descendants_suspended descendents_suspended

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1":descendants_suspended (OBJ object) => {OBJs} all nested children of <object>";
2set_task_perms(caller_perms());
3r = children(args[1]);
4i = 1;
5while (i <= length(r))
6if (kids = children(r[i]))
7r = {@r, @kids};
8endif
9i = i + 1;
10(ticks_left() < 4000) && suspend(0);
11endwhile
12return r;

leaves_suspended

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1":leaves_suspended (OBJ object) => {OBJs} descendants of <object> that have";
2"                                         no children";
3set_task_perms(caller_perms());
4r = {args[1]};
5i = 1;
6while (i <= length(r))
7if (kids = children(r[i]))
8r[i..i] = kids;
9else
10i = i + 1;
11endif
12(ticks_left() < 4000) && suspend(0);
13endwhile
14return r;

branches_suspended

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

none

Source

1":branches_suspended (OBJ object) => {OBJs} all descendants of <object> that";
2"                                           have children.";
3set_task_perms(caller_perms());
4r = args[1..1];
5i = 1;
6while (i <= length(r))
7if (kids = children(r[i]))
8r[i + 1..i] = kids;
9i = i + 1;
10else
11r[i..i] = {};
12endif
13(ticks_left() < 4000) && suspend(0);
14endwhile
15return r;

disown disinherit

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

none

Source

1":disown(object) / :disinherit(object)";
2" => 1 (for a successful disinheritance)";
3" raises E_PERM, E_INVARG, E_ARGS";
4cp = caller_perms();
5"     no set_task_perms() because we need to be able to";
6"     chparent() an object we don't own";
7{victim} = args;
8parent = parent(victim);
9if ($perm_utils:controls(cp, victim))
10raise(E_INVARG, tostr(victim.name, " (", victim, ") is yours.  Use @chparent."));
11elseif (!valid(parent))
12raise(E_INVARG, tostr(victim.name, " (", victim, ") is already an orphan."));
13elseif (!$perm_utils:controls(cp, parent))
14raise(E_PERM, tostr(parent.name, " (", parent, "), the parent of ", victim.name, " (", victim, "), is not yours."));
15elseif (!valid(grandparent = parent(parent)))
16"... still not sure about this... do we care?  --Rog...";
17raise(E_INVARG, tostr(victim.name, " (", victim, ") has no grandparent to take custody."));
18else
19chparent(victim, grandparent);
20return 1;
21endif

accessible_verbs

Spec this none thisFlags rxdOwner #2Definer #52

Referenced by

Source

1"  accessible_verbs(object)   => a list of verb names (or E_PERM) regardless of readability of object";
2set_task_perms(caller_perms());
3thing = args[1];
4verbs = {};
5i = 1;
6while ((info = `verb_info(thing, i) ! ANY') != E_VERBNF)
7verbs = {@verbs, info ? info[3] | E_PERM};
8i = i + 1;
9endwhile
10return verbs;