create_magazine_title.js

import { intersection, unique } from "./set_utils.js";
import { test, random } from "./random_utils.js";
import { titleCase } from "./string_utils.js";
import { logger } from "./utils.js"

// Some books are just for fun, some would be useful for gaining experience given a known
// list of skills, and it would be nice to point that out (e.g. '+Bargain'). Seems okay to
// me to have canned titles as well that don't follow the rules, just to mix things up.
// 'Observational Signatures of Self-Destructive Civilisations'
// http://arxiv.org/pdf/1507.08530v1.pdf

const ADJ = [
  "all",
  "amazing",
  "astonishing",
  "atomic",
  "bolshevik",
  "boy’s",
  "communist",
  "dark",
  "dynamic",
  "exciting",
  "favorite",
  "gentleman’s",
  "girl’s",
  "incredible",
  "lady’s",
  "northwest",
  "popular",
  "railroad man’s",
  "ranch",
  "saucy",
  "spicy",
  "startling",
  "thrilling",
  "women’s",
  "wonderful",
];
const GENRES = [
  "adventure",
  "air",
  "cowboy",
  "detective",
  "fantasy",
  "far west",
  "FBI",
  "flying",
  "frontier",
  "ghost",
  "high seas",
  "horror",
  "indian",
  "jungle",
  "new love",
  "northwest",
  "outdoor",
  "pirate",
  "prison",
  "psychic",
  "ranch",
  "romance",
  "sci-fi",
  "science",
  "supernatural",
  "sweetheart",
  "western",
];
const BASE = ["almanac", "weekly", "magazine", "quarterly", "stories", "tales", "thrills"];
const CANNED_TITLES = [
  "all-story",
  "argosy",
  "black mask",
  "cavalier",
  "keepsake",
  "ladies home almanac",
  "ocean",
  "scrap book",
];
const GENRE_BASES = ["mysteries", "westerns", "thrillers", "{love|ghost|true} stories"];
const REDUNDANT_WITH_GENRES = ["ghost", "mystery", "new love", "western", "high seas"];

// These are just some interesting adjectives and nouns

var storyAdj = [
  "three",
  "white",
  "deep",
  "away",
  "back",
  "beyond",
  "great",
  "lost",
  "big",
  "like",
  "little",
  "living",
  "new",
  "long",
  "two",
  "small",
  "dead",
  "never",
  "last",
  "best",
  "dark",
  "old",
  "second",
  "first",
  "one",
  "cold",
  "red",
  "bad",
  "final",
  "broken",
  "just",
  "perfect",
  "green",
  "blue",
];

var storyNouns = [
  "man",
  "summer",
  "witch",
  "time",
  "earth",
  "house",
  "heaven",
  "mind",
  "devil",
  "flight",
  "book",
  "mother",
  "star{|s}",
  "king",
  "thing{|s}",
  "stairs",
  "universe",
  "glass",
  "eye",
  "darkness",
  "lady",
  "end",
  "sun",
  "call",
  "woman",
  "water",
  "dance",
  "mars",
  "light",
  "moon",
  "black",
  "winter",
  "wind",
  "queen",
  "river",
  "dragon",
  "skin",
  "ghost{|s}",
  "alien",
  "",
  "garden",
  "war",
  "death",
  "monster{|s}",
  "dead",
  "never",
  "story",
  "bones",
  "soul",
  "blood",
  "mirror",
  "children",
  "beast",
  "men",
  "fire",
  "hell",
  "know",
  "demon",
  "planet",
  "snow",
  "dark",
  "ice",
  "god{|s}",
  "way",
  "heart",
  "stone",
  "door",
  "world{|s}",
  "human",
  "dream{|s}",
  "second",
  "family",
  "fall",
  "boy",
  "song",
  "city",
  "road",
  "place",
  "gift",
  "sky",
  "life",
  "shadow{|s}",
  "people",
  "flesh",
  "final",
  "memory",
  "tale",
  "",
  "wings",
  "day{|s}",
  "home",
  "game",
  "space",
  "tree",
  "eyes",
  "dust",
  "room",
  "name",
  "rain",
  "box",
  "thing",
  "sea",
  "night",
  "love",
  "girl",
  "machine",
  "child",
  "daughter",
  "future",
  "angel",
  "magic",
  "dream",
  "hand",
];

function addIf(percent, array, options) {
  if (test(percent)) {
    array.push(random(options));
  }
}

function pulpMagTitle() {
  if (test(5)) {
    return "The " + titleCase(random(CANNED_TITLES));
  }
  let array = [];
  addIf(35, array, ADJ);
  addIf(100, array, GENRES);
  addIf(15, array, GENRES);
  addIf(10, array, ["fiction"]);

  if (test(80) || intersection(array, REDUNDANT_WITH_GENRES).length) {
    array.push(random(BASE));
  } else {
    array.push(random(GENRE_BASES));
  }
  return titleCase(unique(array).join(" "));
}

// ODD: 'High Seas Jungle Tales', 'High Seas Indian Tales'

/**
 * Magazines will be produced as generic items in bags, loot, etc. This method returns a
 * magazine with an auto-generated title, usually pretty silly. The titles are random so
 * these magazines are not considered collectible.
 *
 * @return {String} magazine with a title
 */
export function createMagazineTitle() {
  logger.start("createMagazineTitle");
  let title = pulpMagTitle();
  return logger.end(title);
}