building utilities #21
Aliases: building utilities, building, utils
10 verbs · 7 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
make_exit | this none this | rxd | #21 | 37 |
set_names | this none this | rxd | #21 | 6 |
recreate | this none this | rxd | #21 | 43 |
parse_names | this none this | rxd | #21 | 11 |
audit_object_category | this none this | rxd | #21 | 10 |
object_audit_string | this none this | rxd | #21 | 87 |
do_audit do_prospectus | this none this | rxd | #21 | 42 |
do_audit_item | this none this | rxd | #21 | 18 |
size_string | this none this | rxd | #21 | 10 |
init_for_core | this none this | rxd | #21 | 4 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
classes | #21 | rc | #2 | list of 12{#6, #3, #7, #9, #8, #5, #74, #45, #30, #37, #79, #68} |
class_string | #21 | rc | #2 | list of 12{"p", "R", "E", "N", "C", "T", "F", "M", "H", "D", "U", "O"} |
help_msg | #79 | rc | #2 | list of 13{"Verbs useful for building. For a complete description of a given verb, do `help $building_utils:verbname'.", "", "make_exit(spec,source,dest[,don't-really-create]) => a new exit", " spec is an exit-spec as described in `help @dig'", "", "set_names(object, spec) - sets name and aliases for an object", "parse_names(spec) => list of {name, aliases}", " in both of these, spec is of the form", " <name>[[,:]<alias>,<alias>,...]", " (as described in `help @rename')", "", "recreate(object, newparent) - effectively recycle and recreate object", " as a child of newparent"} |
key | #1 | c | #2 | <clear> |
aliases | #1 | rc | #2 | {"building utilities", "building", "utils"} |
description | #1 | rc | #2 | {"This is the building utilities utility package. See `help $building_utils' for more details."} |
object_size | #1 | r | #36 | {12613, 1539462952} |
Ancestry
Ancestors (nearest first): #79 Generic Utilities Package → #1 Root Class
Children: none
Call graph
Source
make_exit
Referenced by
Source
1"make_exit(spec, source, dest[, use-$recycler-pool [, kind]])"; 2""; 3"Uses $recycler by default; supplying fourth arg as 0 suppresses this."; 4"Optional 5th arg gives a parent for the object to be created"; 5"(i.e., distinct from $exit)"; 6"Returns the object number as a list if successful, 0 if not."; 7set_task_perms(caller_perms()); 8{spec, source, dest, ?use_recycler, ?exit_kind = $exit} = args; 9exit = player:_create(exit_kind); 10if (typeof(exit) == ERR) 11player:notify(tostr("Cannot create new exit as a child of ", $string_utils:nn(exit_kind), ": ", exit, ". See `help @build-options' for information on how to specify the kind of exit this command tries to create.")); 12return; 13endif 14for f in ($string_utils:char_list(player:build_option("create_flags") || "")) 15exit.(f) = 1; 16endfor 17$building_utils:set_names(exit, spec); 18exit.source = source; 19exit.dest = dest; 20source_ok = source:add_exit(exit); 21dest_ok = dest:add_entrance(exit); 22move(exit, $nothing); 23via = $string_utils:from_value(setadd(exit.aliases, exit.name), 1); 24if (source_ok) 25player:tell("Exit from ", source.name, " (", source, ") to ", dest.name, " (", dest, ") via ", via, " created with id ", exit, "."); 26if (!dest_ok) 27player:tell("However, I couldn't add ", exit, " as a legal entrance to ", dest.name, ". You may have to get its owner, ", dest.owner.name, " to add it for you."); 28endif 29return {exit}; 30elseif (dest_ok) 31player:tell("Exit to ", dest.name, " (", dest, ") via ", via, " created with id ", exit, ". However, I couldn't add ", exit, " as a legal exit from ", source.name, ". Get its owner, ", source.owner.name, " to add it for you."); 32return {exit}; 33else 34player:_recycle(exit); 35player:tell("I couldn't add a new exit as EITHER a legal exit from ", source.name, " OR as a legal entrance to ", dest.name, ". Get their owners, ", source.owner.name, " and ", dest.owner.name, ", respectively, to add it for you."); 36return 0; 37endif
set_names
Referenced by
- #4:@create line 43:
$building_utils:set_names - #4:@recreate line 41:
$building_utils:set_names - #6:@rename*# line 64:
$building_utils:set_names - #21:make_exit line 17:
$building_utils:set_names - #57:@untoad line 8:
$building_utils:set_names - #91:dump_goodies line 32:
$building_utils:set_names - #91:transfer_ammo line 18:
$building_utils:set_names - #107:dump_goodies line 28:
$building_utils:set_names - #108:replicate line 12:
$building_utils:set_names - #108:replicate line 24:
$building_utils:set_names - #108:replicate line 26:
$building_utils:set_names - #123:do_burn line 6:
$building_utils:set_names
Source
1"$building_utils:set_names(object, spec)"; 2set_task_perms(caller_perms()); 3object = args[1]; 4names = this:parse_names(args[2]); 5name = names[1] || object.name; 6return object:set_name(name) && object:set_aliases(names[2]);
recreate
Referenced by
- #4:@recreate line 32:
$building_utils:recreate - #63:_recycle line 14:
$building_utils:recreate - #63:setup_toad line 15:
$building_utils:recreate - #100:do_reap line 37:
$building_utils:recreate
Source
1":recreate(object,newparent) -- effectively recycle and recreate the specified object as a child of parent. Returns true if successful."; 2{object, parent} = args; 3who = caller_perms(); 4if (!(valid(object) && valid(parent))) 5return E_INVARG; 6elseif (who.wizard) 7"no problemo"; 8elseif ((who != object.owner) || ((who != parent.owner) && (!parent.f))) 9return E_PERM; 10endif 11"Chparent any children to their grandparent instead of orphaning them horribly. Have to do the chparent with wizperms, in case the children are owned by others, so do this before set_task_perms."; 12"Because this is done before set_task_perms() -- thus with wizard perms -- we save ticks and use chparent() instead of #0:chparent(). This will save many more ticks, if this is an object with many children."; 13grandpa = parent(object); 14for c in (children(object)) 15chparent(c, grandpa); 16endfor 17for item in (object.contents) 18if (!is_player(item)) 19move(item, #-1); 20else 21move(item, $player_start); 22endif 23endfor 24set_task_perms(who); 25if ($object_utils:has_callable_verb(object, "recycle")) 26object:recycle(); 27endif 28chparent(object, #-1); 29for p in (properties(object)) 30delete_property(object, p); 31endfor 32for v in (verbs(object)) 33delete_verb(object, 1); 34endfor 35chparent(object, parent); 36object.name = ""; 37object.r = 0; 38object.f = 0; 39object.w = 0; 40if ($object_utils:has_callable_verb(parent, "initialize")) 41object:initialize(); 42endif 43return 1;
parse_names
Referenced by
- #21:set_names line 4:
this:parse_names - #39:why_bad_name line 3:
$building_utils:parse_names - #118:add_virtual_exit line 2:
$building_utils:parse_names
Source
1"$building_utils:parse_names(spec)"; 2"Return {name, {alias, alias, ...}} from name,alias,alias or name:alias,alias"; 3spec = args[1]; 4if (!(colon = index(spec, ":"))) 5aliases = $string_utils:explode(spec, ","); 6name = aliases[1]; 7else 8aliases = $string_utils:explode(spec[colon + 1..$], ","); 9name = spec[1..colon - 1]; 10endif 11return {name, $list_utils:map_arg($string_utils, "trim", aliases)};
audit_object_category
Referenced by
- #21:object_audit_string line 35:
$building_utils:audit_object_category
Source
1if (is_player(what = args[1])) 2return "P"; 3endif 4while (valid(what)) 5if (i = what in this.classes) 6return this.class_string[i]; 7endif 8what = parent(what); 9endwhile 10return " ";
object_audit_string
Referenced by
- #21:do_audit_item line 14:
$building_utils:object_audit_string
Source
1":object_audit_string(object [,prospectus-style])"; 2{o, ?prospectus = 0} = args; 3olen = length(tostr(max_object())); 4if (!$recycler:valid(o)) 5return tostr(prospectus ? " " | "", $quota_utils.byte_based ? " " | "", $string_utils:right(o, olen), " Invalid Object!"); 6endif 7if (prospectus) 8kids = 0; 9for k in (children(o)) 10(ticks_left() < 4000) && suspend(0); 11if (k.owner != o.owner) 12kids = 2; 13break k; 14elseif (kids == 0) 15kids = 1; 16endif 17endfor 18"The verbs() call below might fail, but that's OK"; 19"Well, actually it won't cuz we seem to be a wizard. Since you can get the number of verbs information from @verbs anyway, it seems kind of pointless to hide it here."; 20v = verbs(o); 21if (v) 22vstr = tostr("[", $string_utils:right(length(v), 3), "] "); 23else 24vstr = " "; 25endif 26if (o.r && o.f) 27r = "f"; 28elseif (o.r) 29r = "r"; 30elseif (o.f) 31r = "F"; 32else 33r = " "; 34endif 35vstr = tostr(" kK"[kids + 1], r, $building_utils:audit_object_category(o), vstr); 36else 37vstr = ""; 38endif 39if ($quota_utils.byte_based) 40vstr = tostr(this:size_string(o.object_size[1]), " ", vstr); 41name_field_len = 26; 42else 43name_field_len = 30; 44endif 45if (valid(o.location)) 46loc = ((((o.location.owner == o.owner) ? " " | "*") + "[") + o.location.name) + "]"; 47elseif ($object_utils:has_property(o, "dest") && $object_utils:has_property(o, "source")) 48if (typeof(o.source) != OBJ) 49source = " <non-object> "; 50elseif (!valid(o.source)) 51source = "<invalid>"; 52else 53source = o.source.name; 54if (o.source.owner != o.owner) 55source = "*" + source; 56endif 57endif 58if (typeof(o.dest) != OBJ) 59destin = " <non-object> "; 60elseif (!valid(o.dest)) 61destin = "<invalid>"; 62else 63destin = o.dest.name; 64if (o.dest.owner != o.owner) 65destin = "*" + destin; 66endif 67endif 68srclen = min(length(source), 19); 69destlen = min(length(destin), 19); 70loc = ((" " + source[1..srclen]) + "->") + destin[1..destlen]; 71elseif ($object_utils:isa(o, $room)) 72loc = ""; 73for x in (o.entrances) 74if (((((typeof(x) == OBJ) && valid(x)) && (x.owner != o.owner)) && $object_utils:has_property(x, "dest")) && (x.dest == o)) 75loc = ((loc + (loc ? ", " | "")) + "<-*") + x.name; 76endif 77(ticks_left() < 4000) && suspend(0); 78endfor 79else 80loc = " [Nowhere]"; 81endif 82if (length(loc) > 41) 83loc = loc[1..37] + "..]"; 84endif 85namelen = min(length(o.name), name_field_len - 1); 86(ticks_left() < 4600) && suspend(0); 87return tostr(vstr, $string_utils:right(o, olen), " ", $string_utils:left(o.name[1..namelen], name_field_len), loc);
do_audit do_prospectus
Referenced by
- #4:@audit line 17:
$building_utils:do_audit - #58:@pros*pectus line 15:
$building_utils:do_prospectus
Source
1":do_audit(who, start, end, match)"; 2"audit who, with objects from start to end that match 'match'"; 3":do_prospectus(...)"; 4"same, but with verb counts"; 5{who, start, end, match} = args; 6pros = verb == "do_prospectus"; 7"the set_task_perms is to make the task owned by the player. There are no other security aspects"; 8set_task_perms(caller_perms()); 9if ((((((start == 0) && (end == toint(max_object()))) && (!match)) && (typeof(who.owned_objects) == LIST)) && (length(who.owned_objects) > 100)) && (!$command_utils:yes_or_no(tostr(who.name, " has ", length(who.owned_objects), " objects. This will be a very long list. Do you wish to proceed?")))) 10v = pros ? "@prospectus" | "@audit"; 11return player:tell(v, " aborted. Usage: ", v, " [player] [from <start>] [to <end>] [for <match>]"); 12endif 13player:tell(tostr("Objects owned by ", who.name, " (from #", start, " to #", end, match ? " matching " + match | "", ")", ":")); 14count = bytes = 0; 15if (typeof(who.owned_objects) == LIST) 16for o in (who.owned_objects) 17((ticks_left() < 6000) || (seconds_left() < 3)) && suspend(1); 18if (!player:is_listening()) 19return; 20endif 21if ((toint(o) >= start) && (toint(o) <= end)) 22didit = this:do_audit_item(o, match, pros); 23count = count + didit; 24if ((didit && $quota_utils.byte_based) && $object_utils:has_property(o, "object_size")) 25bytes = bytes + o.object_size[1]; 26endif 27endif 28endfor 29else 30for i in [start..end] 31((ticks_left() < 6000) || (seconds_left() < 3)) && suspend(1); 32o = toobj(i); 33if ($recycler:valid(o) && (o.owner == who)) 34didit = this:do_audit_item(o, match, pros); 35count = count + didit; 36if ((didit && $quota_utils.byte_based) && $object_utils:has_property(o, "object_size")) 37bytes = bytes + o.object_size[1]; 38endif 39endif 40endfor 41endif 42player:tell($string_utils:left(tostr("-- ", count, " object", (count == 1) ? "." | "s.", $quota_utils.byte_based ? tostr(" Total bytes: ", $string_utils:group_number(bytes), ".") | ""), player:linelen() - 1, "-"));
do_audit_item
Referenced by
- #21:do_audit line 22:
this:do_audit_item - #21:do_audit line 34:
this:do_audit_item
Source
1":do_audit_item(object, match-name-string, prospectus-flag)"; 2{o, match, pros} = args; 3found = match ? 0 | 1; 4names = `{o.name, @o.aliases} ! ANY => {o.name}'; 5"Above to get rid of screwed up aliases"; 6while (names && (!found)) 7if (index(names[1], match) == 1) 8found = 1; 9endif 10names = listdelete(names, 1); 11endwhile 12if (found) 13"From Dred---don't wrap long lines."; 14line = $building_utils:object_audit_string(o, pros); 15player:tell(line[1..min($, player:linelen())]); 16return 1; 17endif 18return 0;
size_string
Referenced by
- #21:object_audit_string line 40:
this:size_string
Source
1size = args[1]; 2if (!size) 3return " ???"; 4elseif (size < 1000) 5return " <1K"; 6elseif (size < 1000000) 7return tostr($string_utils:right(size / 1000, 3), "K"); 8else 9return tostr($string_utils:right(size / 1000000, 3), "M"); 10endif
init_for_core
Referenced by
none
Source
1if (caller_perms().wizard) 2pass(); 3this.classes = {$player, $room, $exit, $note, $container, $thing, $feature, $mail_recipient, $generic_help, $generic_db, $generic_utils, $generic_options}; 4endif