Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   function Dwarf() {
  2.     any([ DwarfLineage, DwarfLineage, DwarfAlone ])();
  3.   }
  4.  
  5.   function DwarfLineage() {
  6.     PrepareDwarfName();
  7.     DwarfHeritage();
  8.   }
  9.  
  10.   function DwarfHeritage() {
  11.     Dwarf();
  12.     tokens.push(",");
  13.     tokens.push(any([ "heir to the throne of", "son of", "daughter of" ]));
  14.     DwarfSelf();
  15.   }
  16.  
  17.   function DwarfAlone() {
  18.     PrepareDwarfName();
  19.     DwarfSelf();
  20.   }
  21.  
  22.   function DwarfSelf() {
  23.     DwarfName();
  24.     DwarfTitle();
  25.   }
  26.  
  27.   function DwarfTitle() {
  28.     any([ Nothing, SomeDwarfTitle ])();
  29.   }
  30.  
  31.   function SomeDwarfTitle() {
  32.     tokens.push(",");
  33.     tokens.push(any(DwarfTitles));
  34.     tokens.push("of");
  35.     tokens.push(any(of([ Territories, Nations, Peoples ])));
  36.   }
  37.  
  38.   function DwarfName() {
  39.     SomeDwarfName();
  40.     any([ Nothing, Nothing, WhichOfHisName ])();
  41.  
  42.     names.pop();
  43.   }
  44.  
  45.   function WhichOfHisName() {
  46.     SomeOrdinalNumber();
  47.   }
  48.  
  49.   function SomeOrdinalNumber() {
  50.     var number = names[names.length - 1].number;
  51.  
  52.     var ordinal = "";
  53.     switch(number) {
  54.       case 1: ordinal = "1st"; break;
  55.       case 2: ordinal = "2nd"; break;
  56.       case 3: ordinal = "3rd"; break;
  57.       default: ordinal = number + "th";
  58.     }
  59.  
  60.     tokens.push(ordinal);
  61.   }
  62.  
  63.   function SomeDwarfName() {
  64.     tokens.push(names[names.length - 1].name);
  65.   }
  66.  
  67.   function PrepareDwarfName() {
  68.     var name = any(DwarfNames);
  69.  
  70.     if(memory[name])
  71.       memory[name]++;
  72.     else
  73.       memory[name] = 1;
  74.  
  75.     names.push({ name: name, number: memory[name] });
  76.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement