How Crawl makes names


If it doesn't fit anywhere else, it belongs here. Also, come here if you just need to get hammered.

Spider Stomper

Posts: 242

Joined: Friday, 17th April 2015, 16:22

Post Sunday, 5th March 2017, 06:07

How Crawl makes names

"This function is insane, but that might be useful." -crawl's source code

The names of scrolls, shopkeepers, panlords, some artifacts, Jiyva, and the player character if they decline to provide a name, are all determined from the same function: make_name.

make_name takes two arguments: a seed for the special RNG it uses (for testing purposes I assume), and the type of name to make. There are three types of names: Jiyva names, scroll names, and everything else.

The first thing the function does is determine the desired length of the name (named len). This is a random number from 3 to 7 (evenly distributed). There is a 20% chance to add a number from 0-5 to it; if that fails, we add 1 to it. In essence:
20%: 3 + 0...4 + 0...5 (1 + 1d5 + 1d6, 3-12)
80%: 3 + 0...4 + 1 (3 + 1d5, 4-8)
If we are making a name for a scroll, add 6 to len because "scrolls have longer names".
If we are making a name for Jiyva, and len is greater than 8, set len to 8.
len is not always the length of the name that will ensue, as we will see later, but it is a close-ish approximation.

The function asserts at this point that len is between 1 and 201. If it somehow is not, the game crashes.

We enter a massive string-building loop which runs 150 times, or until the length of the name reaches or exceeds len.

Every iteration of the loop, we do exactly one of the following five tasks:

1.) If this is the first character, and we are making a name for Jiyva, add a J.



2.) If this is the first character, or the previous character was a space, add a letter from A-Z completely at random.



3.) If all of the following are true:
-the name does not contain any spaces yet
-the name is not for Jiyva
-the name is at least 6 characters long so far
-the name is less than len - 4 (meaning we have 5 or more spots for future characters)
-a 4/5 RNG poll passes
then add a space to the name.



4.) If all of the following are true:
-the name contains at least one character so far (this check seems completely redundant)
-Either of the next two are true:
----- the previous letter is a consonant, OR
----- the previous character is NOT a consonant AND the character before the previous character is a consonant AND a 2/5 RNG poll passes AND a redundant check that the word is more than one letter long (it must be 2 or more letters long)
then attempt to add a "vowel" to the name:
Pick a vowel at random from the string "aeiouaeiouaeiouy ", which contains three of each traditional vowel, one Y, and two spaces which apparently count as vowels???

If the vowel is a space, veto it and don't add any characters if any of the following are true:
-len is less than 7.
-We have placed 2 or fewer letters so far.
-The length of the name is at least len - 3 (meaning we have only 3 or fewer spaces to add characters).
-The previous character was a space.
-The character before the previous character was a space.
-We are making a name for Jiyva.
-The previous two characters are both consonants.

If the vowel is not a space, veto it and don't add any characters if all of the following are true:
-The name is more than one letter long (redundant check)
-The vowel is the same as the previous character
-The vowel is an 'i', the vowel is a 'y', or a 2/5 RNG poll passes.

If we didn't veto the vowel, add it to the end of the name.




5.) If we don't do any of the above, try to add at least one consonant:
If the name is empty (impossible) or if the previous character is a space, we consider ourselves to be at the start of the name and set beg to true.
If the length of the name so far is at least len - 2, we consider ourselves to be at the end of the name and set end to true.

If all of the following are true:
-len is greater than 3, or the name isn't empty (a tautology; this line will always be true)
-A 2/7 RNG poll passes.
-At least one of beg and end is false.
Then we add multiple consonants:
If beg is true, select one of the following sets: kl gr cl cr fr pr tr tw br pl bl str shr thr sm sh ch th ph pn kh gh mn ps st sk sch
If end is true, select one of the following sets: ts cs xt nt ll rr ss wk wn ng cw mp ck nk dd tt bb pp nn mm kk gg ff pt tz dgh rgh rph rch
If neither is true, select any of the above sets, or one of the following sets: cz xk zx xz cv vv nl rh dw nw khl

Check if the length of the set we chose is greater than 1. If it somehow is not, crash the game.

Increase len by the length of the consonant set - 2. In other words, if we pulled a set that is 3 characters long, increase len by one.

Add the set to the end of the name.


If we don't add a consonant set, add a single consonant at random. Unlike vowels, consonants all have equal weight and do not include spaces or Y.




At this point we hopefully have a nice name. Chances are, the name is len characters long, but it could be shorter. Due to the wonders of RNG, it is possible for us to have a single letter at this point.

Try to give a sensible final letter. If all of the following are true:
-The name is not empty (redundant)
-The last character is not a space.
-The last character is not the letter Y.
-The last character is not a consonant.
-Either the name's length is less than len, or len is less than 8 and a 2/3 RNG poll passes.
Then we add a random consonant.

If we are making a name for Jiyva, chop off anything on the right side of the name to make the name 8 characters or less, if needed. This can be needed because len can be increased by consonant sets.

If the name is less than 4 characters and we are making a name for Jiyva, throw it out and start over from the top.
If the name is less than 4 characters and we are not making a name for Jiyva, throw it out and replace it with "plog".

Apply proper capitalization: if making a scroll the name should be in all-caps, otherwise capitalize the first letter.

If we are making a name for Jiyva and the name has any spaces in it at this point, crash the game.

Return the finished name.
Last edited by Doesnt on Tuesday, 7th March 2017, 19:28, edited 1 time in total.

For this message the author Doesnt has received thanks: 4
amalloy, dracos369, Lasty, n1000

Temple Termagant

Posts: 12

Joined: Monday, 5th December 2016, 15:47

Post Monday, 6th March 2017, 22:19

Re: How Crawl makes names

If I'm reading this right, any name that generated with less than four characters should actually be named "plog." Which means this mace should have been called "plog," but it wasn't.
  Code:
the +6 mace "Z" {pain, MP+9 Dex+3 Stlth-}
User avatar

Dungeon Master

Posts: 502

Joined: Wednesday, 7th March 2012, 13:25

Location: Lexington, KY, US

Post Monday, 6th March 2017, 23:10

Re: How Crawl makes names

TheSilverBeluga wrote:If I'm reading this right, any name that generated with less than four characters should actually be named "plog." Which means this mace should have been called "plog," but it wasn't.
  Code:
the +6 mace "Z" {pain, MP+9 Dex+3 Stlth-}


Z, Q, and X are specifically present as "fixed" randart names in _joke_weapon_name_. Also "Ox".

Ziggurat Zagger

Posts: 8786

Joined: Sunday, 5th May 2013, 08:25

Post Tuesday, 7th March 2017, 07:29

Re: How Crawl makes names

Meanwhile, in Wesnoth:
Image

For this message the author duvessa has received thanks:
n1000

Return to Crazy Yiuf's Corner

Who is online

Users browsing this forum: No registered users and 18 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.