/
CDC-1.2b/
CDC-1.2b/src/
parent $utilities
object $name_generator

var $root dbref 'name_generator
var $root child_index 0
var $root fertile 0
var $root manager $name_generator
var $root owned [$name_generator]
var $root owners [$name_generator]
var $root writable [$]
var $root readable ['parameters, 'methods, 'code]
var $root inited 1
var $name_generator lovecraftian #[['initial_const, #[["bh", 1], ["bhl", 1], ["br", 3], ["c", 54], ["ch", 20], ["chth", 1], ["cl", 3], ["cr", 4], ["cth", 3], ["d", 70], ["dh", 3], ["djh", 2], ["dl", 1], ["dr", 3], ["dw", 2], ["dz", 1], ["f", 15], ["fr", 2], ["g", 50], ["gh", 11], ["ghl", 1], ["gl", 1], ["gn", 4], ["gr", 2], ["h", 44], ["hl", 1], ["hs", 1], ["j", 8], ["k", 34], ["kh", 2], ["kl", 2], ["kr", 1], ["kth", 1], ["l", 147], ["ll", 1], ["m", 111], ["mh", 1], ["ml", 1], ["mm", 1], ["mn", 1], ["mth", 1], ["n", 107], ["ngr", 1], ["nh", 1], ["nl", 2], ["p", 34], ["ph", 19], ["phl", 1], ["phr", 1], ["pn", 4], ["pr", 2], ["ps", 1], ["pt", 1], ["qu", 16], ["r", 113], ["rh", 3], ["rl", 2], ["rr", 1], ["s", 65], ["sf", 1], ["sh", 16], ["sk", 1], ["sn", 2], ["sng", 1], ["st", 1], ["str", 2], ["t", 71], ["th", 56], ["thr", 3], ["tl", 1], ["tn", 1], ["tr", 3], ["ts", 4], ["tsch", 1], ["v", 42], ["vhl", 1], ["vl", 1], ["vr", 1], ["w", 9], ["x", 9], ["z", 43], ["zh", 5], ["zk", 1]]], ['vowel, #[["aa", 18], ["ae", 2], ["ah", 11], ["ai", 32], ["au", 14], ["aw", 1], ["ay", 2], ["e", 187], ["ea", 1], ["ee", 9], ["eh", 3], ["ei", 12], ["eu", 2], ["i", 236], ["ie", 3], ["ih", 1], ["ii", 1], ["o", 308], ["oh", 1], ["oi", 8], ["oo", 15], ["ou", 26], ["ow", 2], ["oy", 1], ["u", 114], ["uh", 1], ["uu", 3], ["y", 44], ["ya", 13], ["ye", 1], ["yeh", 1], ["yi", 4], ["yo", 10], ["yoh", 1], ["yu", 6]]], ['final_const, #[["b", 20], ["bn", 1], ["c", 21], ["ch", 6], ["d", 26], ["f", 5], ["g", 28], ["gh", 3], ["gn", 1], ["j", 1], ["k", 21], ["l", 81], ["lf", 1], ["ll", 1], ["lp", 1], ["lt", 2], ["lth", 1], ["m", 58], ["mb", 1], ["mh", 1], ["mr", 1], ["ms", 2], ["n", 151], ["nd", 3], ["ng", 12], ["ngh", 2], ["nn", 1], ["ns", 1], ["nt", 4], ["nth", 1], ["p", 6], ["ph", 5], ["ps", 2], ["q", 2], ["qh", 1], ["r", 134], ["rc", 1], ["rd", 2], ["rg", 2], ["rgh", 1], ["rh", 2], ["rn", 3], ["rp", 1], ["rph", 1], ["rrh", 1], ["rt", 1], ["rth", 5], ["s", 102], ["sh", 4], ["sht", 1], ["sk", 4], ["st", 3], ["t", 25], ["th", 53], ["tl", 1], ["v", 2], ["x", 7], ["z", 12]]], ['syllable_pattern, #[['V, 1], ['VC, 1], ['CV, 4], ['CVC, 4]]], ['syllables, #[[1, 3], [2, 5], [3, 5], [4, 3], [5, 1]]]]
var $name_generator vowel #[]
var $name_generator initial_const #[]
var $name_generator totals #[]
var $name_generator final_const #[]
var $name_generator generator 0
var $root info ["The basic algorythm for this generator is taken from Ross Smith's <alien@acheron.amigans.gen.nz> random name generator in C (it is public domain).  It was converted to ColdC by Brandon Gillespie.", "", "This system generates random names, by putting together sounds according to rules specified by the generator type.  Ross Smith was inspired to write it from some of the name generators described in a few of GDW's Traveller products.", "", "Generator types are dictionaries broken into several sub dictionaries, where each sub dictionary is one of:", "", "  'syllables", "  'syllable_pattern", "  'initial_const", "  'verb", "  'final_const", "", "  'syllables:", "", "      This is a simple integer dictionary to randomize the number of", "      syllables in a word.", "", "  'syllable_pattern", "", "      This dictionary can only have 4 elements, where each element is", "      one of the symbols: 'V, 'VC, 'CV, 'CVC, each of which represents", "      the frequency of that combination.", "", "  'initial_const", "  'verb", "  'final_const", "", "      Each of these dictionaries represent the various character", "      combinations available for each posistion in the syllable", "      pattern.  The correlating value to the key is the frequency.", "", "Frequencies are relative, they do not have to add up to any particular value.", "", "A short example:", "", "#[['syllables, #[[1, 3], [2, 1]]],", "  ['syllable_pattern, #[['V, 1], ['VC, 1], ['CV, 1], ['CVC, 1]]],", "  ['initial_const, #[[\"t\", 4], [\"th\", 1], [\"y\", 1]]],", "  ['vowel, #[[\"a\", 1], [\"e\", 1], [\"i\", 1], [\"ie\", 1]]],", "  ['final_const, #[[\"b\", 2], [\"d\", 2], [\"rgh\", 1]]],", " ]", "", "Here are some names generated from the above generator type:", "", "\"Rgh Dyatiyie Eyie Eta Btie Dyitetha Ttithati Ethie Yye\"", "", "Notes on the ColdC design of $word_generator:", "", "    For simplicity all I do is enter each character value (consonant/vowel)", "    in a large list the amount of times it's frequency is specified, then", "    to find a character the generator does characters[random(length)].", "    There are probably better ways, but in the long run this is fast", "    as it only has to generate that cache once (although it takes some", "    time to generate this cache, and the cache can take up a bit of space).", "", "    This is why when switching generators the generator takes some time, as", "    it recompiles a new generator into the cache.", "", "    Generate a word with:   $word_generator.generate()", "", "    This will default to the last generator used (using the existing", "    cache), and will break word generation with a max of 12 (although", "    there may still be longer words).  To specify another generator", "    simply send that generator as a symbol for the first argument.  To", "    change the max cutoff point send an integer for the second ", "    argument."]

method get_generator
    arg generator;
    
    return get_var(generator);
.

method generate
    arg [args];
    var l, out, s, p, rand, r, v, vc, cv, cvc, x, g, tmp, which, max;
    
    which = [@args, 'lovecraftian][1];
    max = [@args, 12, 12][2];
    max = (max > 2) ? max | 3;
    .initialize_word_generator(which);
    g = get_var(which);
    s = random(totals['syllables]);
    p = g['syllable_pattern];
    v = p['V];
    vc = v + (p['VC]);
    cv = vc + (p['CV]);
    cvc = cvc + (p['CVC]);
    tmp = ['initial_const, 'vowel, 'final_const][random(3)];
    out = get_var(tmp)[random(totals[tmp])];
    l = #[['fc, ""], ['v, ""], ['sc, ""]];
    while (strlen(out) < 2) {
        for x in [1 .. s] {
            rand = random(cvc);
    
            // first consonant
            if (rand >= cvc) {
                tmp = initial_const[random(totals['initial_const])];
                while ((l['fc]) == tmp)
                    tmp = initial_const[random(totals['initial_const])];
                out = out + tmp;
                l = dict_add(l, 'fc, tmp);
                pause();
            }
    
            // vowel
            tmp = vowel[random(totals['vowel])];
            while ((l['v]) == tmp)
                tmp = vowel[random(totals['vowel])];
            out = out + tmp;
            l = dict_add(l, 'v, tmp);
            pause();
    
            // second consonant
            if (((rand > v) && (rand <= vc)) || (rand > cv)) {
                tmp = final_const[random(totals['final_const])];
                while ((l['sc]) == tmp)
                    tmp = final_const[random(totals['final_const])];
                out = out + tmp;
                l = dict_add(l, 'sc, tmp);
                pause();
            }
            if (strlen(out) > max)
                break;
        }
    }
    return out.capitalize();
.

method set_generator
    arg dict_name, dict;
    
    (> .perms(sender()) <);
    set_var(dict_name, dict);
.

method initialize_word_generator
    arg which;
    var x, y, z, total, tmp, dict, syllables;
    
    if (generator == which)
        return;
    .reset_word_generator();
    generator = which;
    tmp = [];
    total = 0;
    dict = get_var(which);
    syllables = dict['syllables];
    syllables = listlen(dict_keys(syllables));
    totals = dict_add(totals, 'syllables, syllables);
    for z in (['initial_const, 'vowel, 'final_const]) {
        for x in (dict_keys(dict[z])) {
            for y in [1 .. (dict[z])[x]] {
                tmp = [@tmp, x];
                total = total + 1;
                pause();
            }
        }
        set_var(z, tmp);
        totals = dict_add(totals, z, total);
        tmp = [];
        total = 0;
    }
.

method reset_word_generator
    generator = 0;
    initial_const = #[];
    vowel = #[];
    totals = #[];
    final_const = #[];
.