generic weapon forge #307

Parent #5Owner #361Flags read, fertileSource hellcore/hellcore.db

Aliases: generic weapon forge, forge

7 verbs · 33 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
forgethis none thisrxd#30722
make_candidatethis none thisrxd#30710
is_legalthis none thisrxd#30711
pick_partthis none thisrxd#30722
forge_namethis none thisrxd#30751
name_prioritythis none thisrxd#3078
make_modelsthis none thisrxd#30715

Properties

PropertyDefinerFlagsOwnerValue
parts#307rc#361{}
generic_legendary#307rc#361#-1
models#307rc#361{}
handed#5rc#361<clear>
wield_msg#5rc#361<clear>
unwield_msg#5rc#361<clear>
size#5rc#361<clear>
look_place_msg#5rc#361<clear>
value#5rc#361<clear>
get_msg#5rc#361<clear>
drop_msg#5rc#361<clear>
get_fail_msg#5rc#361<clear>
junk_ok#5rc#361<clear>
floats#5rc#361<clear>
long_name_msg#5rc#361<clear>
article#5rc#361<clear>
setup_list#5rc#361<clear>
health#5rc#361<clear>
health_max#5rc#361<clear>
min_skill#5rc#361<clear>
skill#5rc#361<clear>
recipe_for#5rc#361<clear>
carried_msg#5rc#361<clear>
aliases#1rc#361{"generic weapon forge", "forge"}
description#1rc#361<clear>
object_size#1r#29{5398, 1298434595}
hidden_verbs#1rc#361<clear>
phelp_msg#1rc#361<clear>
weight#1rwc#361-1
owner_verbs#1rc#361<clear>
plural_name#1rc#361<clear>
client_image#1rc#361<clear>
listening#1rc#361<clear>

Ancestry

Ancestors (nearest first): #5 generic thing#1 root

Children: none

Call graph

calls n307_0 #307:forge n307_2 #307:is_legal n307_0->n307_2 n307_1 #307:make_candidate n307_0->n307_1 n47_23 #47:sort_alist n307_0->n47_23 n107_43 #107:tell n307_0->n107_43 n307_4 #307:forge_name n307_0->n307_4 n20_59 #20:name_and_number n307_0->n20_59 n47_25 #47:randomly_permute n307_1->n47_25 n307_3 #307:pick_part n307_1->n307_3 n307_4->n47_23 n45_23 #45:leaves n307_4->n45_23 n20_38 #20:explode n307_4->n20_38 n307_5 #307:name_priority n307_4->n307_5 n20_14 #20:uppercase n307_4->n20_14 n268_2 #268:gil n307_4->n268_2 n307_3->n45_23 n307_6 #307:make_models n307_6->n307_2 n307_6->n307_1

Source

forge

Spec this none thisFlags rxdOwner #361Definer #307

Referenced by

none

Source

1":forge(INT quality) => Forge a weapon of given quality.";
2{quality} = args;
3weapons = {};
4for i in [1..4]
5parts = {};
6while (!this:is_legal(parts))
7parts = this:make_candidate(quality);
8endwhile
9q = 0;
10for x in (parts)
11q = q + x.quality;
12endfor
13weapons = {@weapons, {q, parts}};
14suspend(0);
15endfor
16weapons = $lu:sort_alist(weapons, 1);
17parts = weapons[$][2];
18player:tell($ansi.bold_on, this:forge_name(parts), $ansi.reset, " (quality ", weapons[$][1], ")");
19for x in (parts)
20player:tell($su:nn(x), "  ", x:tree_tag());
21endfor
22return parts;

make_candidate

Spec this none thisFlags rxdOwner #361Definer #307

Referenced by

Source

1":(INT quality) => Generate a weapon of the given quality and return the parts list. Might not be a legal weapon.";
2{quality} = args;
3parts = {};
4qleft = quality;
5for ptype in ($lu:randomly_permute(this.parts))
6part = this:pick_part(ptype, qleft);
7qleft = qleft - part.quality;
8parts = {@parts, part};
9endfor
10return parts;

Spec this none thisFlags rxdOwner #361Definer #307

Referenced by

Source

1":is_legal(LIST parts) => Is this a legal weapon?";
2{parts} = args;
3if (!parts)
4return 0;
5endif
6for x in (parts)
7if (!x:compatible_with(parts))
8return 0;
9endif
10endfor
11return 1;

pick_part

Spec this none thisFlags rxdOwner #361Definer #307

Referenced by

Source

1":pick_part(OBJ parent, INT quality[, INT weapon_quality]) => Pick a random part of the given parent of no more than the given quality.";
2{parent, quality, ?weapon_quality = $maxint} = args;
3poss = {};
4bucket = $ou:leaves(parent);
5weakest = bucket[1];
6for x in (bucket)
7if (weapon_quality >= x.min_quality)
8if (x.quality <= quality)
9if ((!x.rarity) || (random(100) > x.rarity))
10poss = {@poss, x};
11endif
12endif
13if (x.quality < weakest.quality)
14weakest = x;
15endif
16endif
17endfor
18if (poss)
19return poss[random($)];
20else
21return weakest;
22endif

forge_name

Spec this none thisFlags rxdOwner #361Definer #307

Referenced by

Source

1{parts} = args;
2n1 = {};
3n2 = {};
4magic = 0;
5q = 0;
6for x in (parts)
7if (x.subname_msg)
8{x1, x2} = $su:explode(x.subname_msg, "_");
9if (x1 != "*")
10n1 = {@n1, {x1, this:name_priority(x1)}};
11endif
12if (x2 != "*")
13n2 = {@n2, {x2, this:name_priority(x2)}};
14endif
15endif
16magic = magic + tonum(x);
17q = q + x.quality;
18endfor
19name = "";
20for x in ($ou:leaves(this.generic_legendary))
21found = 1;
22for y in (x.required_parts[1..$])
23if (!(y in parts))
24found = 0;
25endif
26endfor
27if (found)
28name = $ansi.yellow + $ansi.bold_on;
29{x1, x2} = $su:explode(x.subname_msg, "_");
30if (x1 != "*")
31n1 = {{x1, 2}};
32endif
33if (x2 != "*")
34n2 = {{x2, 2}};
35endif
36endif
37endfor
38n1 = $lu:sort_alist(n1, 2);
39n1 = n1[$][1];
40n2 = $lu:sort_alist(n2, 2);
41n2 = n2[$][1];
42name = (name + (n1 + " ")) + n2;
43name = $su:lowercase(name);
44num_let = $rng:gil(2, magic);
45code = "";
46for i in [1..num_let]
47code = code + "CXJZREVMBDGTNPL"[$rng:gil(15, magic + i)];
48endfor
49code = code + tostr(q / 10);
50name = (code + " ") + name;
51return name;

name_priority

Spec this none thisFlags rxdOwner #361Definer #307

Referenced by

Source

1name = args[1];
2if (index($su.alphabet, name[1], 1))
3return 0;
4elseif (index($su.alphabet, name[2], 1))
5return 1;
6else
7return 2;
8endif

make_models

Spec this none thisFlags rxdOwner #361Definer #307

Referenced by

none

Source

1this.models = {};
2for i in [10..100]
3quality = i * 10;
4parts = {};
5while (!this:is_legal(parts))
6parts = this:make_candidate(quality);
7yield;
8endwhile
9quality = 0;
10for x in (parts)
11quality = quality + x.quality;
12endfor
13this.models = {@this.models, {quality, parts}};
14yield;
15endfor