item utilities #254

Parent #72Owner #361Flags readSource hellcore/hellcore.db

Aliases: item utilities, iu

9 verbs · 15 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
plural_to_typethis none thisrxd#2548
type_to_pluralthis none thisrxd#2547
typeofthis none thisrxd#25418
name_to_typethis none thisrxd#2548
type_to_namethis none thisrxd#2547
plurals names pluralsc namescthis none thisrxd#25413
group_by_typethis none thisrxd#25413
add_typethis none thisrxd#25416
is_athis none thisrxd#25411

Properties

PropertyDefinerFlagsOwnerValue
classes#254rc#361
list of 11{#107, #288, #306, {#804, #723, #835}, {#868, #877, #890, #1086, #1423, #1570, #5287, #9701, #48018, #103253, #217130, #287228, #306253, #409798}, #5714, {#659, #38845}, #931, #27317, #2044, #665}
names#254rc#361
list of 11{"weapon", "ammo", "clothing", "medical", "consumable", "chemical", "artifact", "container", "trophy", "recipe", "part"}
plurals#254rc#361
list of 11{"weapons", "ammo", "clothing", "medical", "consumables", "chemicals", "artifacts", "containers", "trophies", "recipes", "parts"}
matches#254rc#361
list of 11{{"weapon", "weapons"}, {"ammo"}, {"clothes", "clothing", "armor", "cloth"}, {"medical", "med"}, {"foods", "food", "consumables"}, {"chemical"}, {"artifact", "artifacts", "arts"}, {"containers"}, {"trophies", "trophy"}, {"recipe", "recipes"}, {"part", "parts"}}
help_msg#72rc#361
list of 25{"", " Item types are integers.", "", " Getting item types:", " :typeof(obj) => int", "", " :group_by_type(list of objs) => ", " {list of type 1, list of type 2, ... , ", " list of unclassified objs}", "", " Information about types (index # == item type #):", " :plurals() => list of plural names of item classes.", " :names() => list of singular names of item classes.", "", " (also :pluralsc() and namesc() for capitalized.)", "", " :type_to_plural(int itemtype) => plural for this type.", " :type_to_name(int itemtype) => singular for this type.", "", " Matching:", " :plural_to_type(str) => itemtype if any match, or 0", " :name_to_type(str) => itemtype if any match, or 0", "", " Adding new item types, wizards:", " Use a verb so you can modify all 3 props at once. Add things to the END of lists, only, and start with .names and .plurals, then finally .classes. The format of the props is simple and self-explanatory."}
aliases#1rc#361{"item utilities", "iu"}
description#1rc#361<clear>
object_size#1r#29{7191, 1298434413}
hidden_verbs#1rc#361<clear>
phelp_msg#1rc#361<clear>
weight#1rc#361<clear>
owner_verbs#1rc#361<clear>
plural_name#1rc#361<clear>
client_image#1rc#361<clear>
listening#1rc#361<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n254_6 #254:group_by_type n47_0 #47:make n254_6->n47_0 n254_2 #254:typeof n254_6->n254_2

Source

plural_to_type

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

none

Source

1"$iu:plural_to_type(STR plural item class) => INT itemtype";
2{s} = args;
3for i in [1..length(this.plurals)]
4if (s == this.plurals[i])
5return i;
6endif
7endfor
8return 0;

type_to_plural

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

none

Source

1"$iu:type_to_plural(INT itemtype) => STR plural name for item class";
2{i} = args;
3if ((i < 1) || (i > length(this.plurals)))
4raise(E_INVARG, "Invalid item type", i);
5return "";
6endif
7return this.plurals[i];

typeof

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

Source

1"$iu:typeof(OBJ item) => INT itemtype";
2{o} = args;
3o = is_a(o, $glob) ? o.item | o;
4for i in [1..length(this.classes)]
5class = this.classes[i];
6if (typeof(class) == OBJ)
7if (is_a(o, class))
8return i;
9endif
10else
11for c in (class)
12if (is_a(o, c))
13return i;
14endif
15endfor
16endif
17endfor
18return 0;

name_to_type

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

none

Source

1"$iu:name_to_type(STR singular name of item class) => INT itemtype";
2{s} = args;
3for i in [1..length(this.names)]
4if (s == this.names[i])
5return i;
6endif
7endfor
8return 0;

type_to_name

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

none

Source

1"$iu:type_to_name(INT itemtype) => STR singular name for item class";
2{i} = args;
3if ((i < 1) || (i > length(this.names)))
4raise(E_INVARG, "Invalid item type", i);
5return "";
6endif
7return this.names[i];

plurals names pluralsc namesc

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

Source

1capitalize = 0;
2if (verb[$] == "c")
3prop = verb[1..$ - 1];
4l = {};
5for x in (this.(prop))
6i = index("abcdefghijklmnopqrstuvwxyz", x[1]);
7x[1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i];
8l = {@l, x};
9endfor
10return l;
11else
12return this.(verb);
13endif

group_by_type

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

Source

1"$iu:group_by_type(LIST objs) => {LIST type1objs, LIST type2objs, ..., LIST unclassified objs}";
2{objs} = args;
3buckets = $lu:make(length(this.classes) + 1, {});
4for o in (objs)
5yield;
6type = this:typeof(o);
7if (type)
8buckets[type] = {@buckets[type], o};
9else
10buckets[$] = {@buckets[$], o};
11endif
12endfor
13return buckets;

add_type

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

none

Source

1if (!caller_perms().wizard)
2return E_PERM;
3endif
4{name, plural, matches, class} = args;
5if (!(typeof(class) in {OBJ, LIST}))
6return E_INVARG;
7endif
8if ((name in this.names) || (plural in this.plurals))
9return E_INVARG;
10endif
11matches = setadd(matches, name);
12matches = setadd(matches, plural);
13this.names = {@this.names, name};
14this.plurals = {@this.plurals, plural};
15this.matches = {@this.matches, matches};
16this.classes = {@this.classes, class};

is_a

Spec this none thisFlags rxdOwner #361Definer #254

Referenced by

Source

1":is_a(OBJ what, INT class) => Is what a member of class?";
2{what, classnum} = args;
3class = this.classes[classnum];
4class = (typeof(class) == OBJ) ? {class} | class;
5matchtype = is_a(what, $glob) ? what.item | what;
6for c in (class)
7if (is_a(matchtype, c))
8return 1;
9endif
10endfor
11return 0;