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

// Nonsense
// Bride’s Ranch America’s Best Classics

const ADJ = [
  "all true",
  "all",
  "amazing",
  "america’s best",
  "astonishing",
  "atomic",
  "baffling",
  "best",
  "bolshevik",
  "boy’s",
  "bride’s",
  "communist",
  "dark",
  "dynamic",
  "exciting",
  "exciting",
  "favorite",
  "fearful",
  "forbidden",
  "funny",
  "G-I",
  "gentleman’s",
  "girl’s",
  "happy",
  "haunted",
  "incredible",
  "intimate",
  "lady’s",
  "men’s",
  "northwest",
  "oklahoma",
  "pictorial",
  "popular",
  "railroad man’s",
  "ranch",
  "saucy",
  "secret",
  "spicy",
  "startling",
  "strange",
  "terrific",
  "thrilling",
  "today’s",
  "true life",
  "wartime",
  "women’s",
  "wonderful",
  "wonderful",
];
const GENRES = [
  "adventure",
  "air",
  "cowboy",
  "detective",
  "fantasy",
  "far west",
  "FBI",
  "flying",
  "frontier",
  "ghost",
  "high seas",
  "horror",
  "indian",
  "jungle",
  "love",
  "new love",
  "northwest",
  "outdoor",
  "pirate",
  "prison",
  "psychic",
  "ranch",
  "romance",
  "sci-fi",
  "science",
  "supernatural",
  "sweetheart",
  "UFO",
  "western",
  "wonder",
];
const BASE = [
  "almanac",
  "classics",
  "comics",
  "confessions",
  "diary",
  "fables",
  "magazine",
  "quarterly",
  "reports",
  "stories",
  "tales",
  "thrills",
  "weekly",
];

const CANNED_TITLES = [
  "adventure into the past",
  "adventures in electricity",
  "adventures in jet power",
  "the all-story",
  "apache trail",
  "bughouse",
  "captain flight comics",
  "commander battle and the atomic sub comics",
  "the argosy",
  "black cobra comics",
  "the black mask comics",
  "captain jet comics",
  "hi-ho comics",
  "the cavalier",
  "the flame comics",
  "the keepsake",
  "lone eagle comics",
  "the ladies home almanac",
  "madhouse",
  "the ocean",
  "the scrap book",
  "star ranger",
];
const GENRE_BASES = ["classics", "mysteries", "westerns", "thrillers", "{love|ghost|true} stories"];
const REDUNDANT = {
  "thrillers": "thrilling",
  "classicss": "classic",
  "ghost stories": "ghost",
  "love stories": "new love",
  "westerns": "western",
};

function addIf(percent, array, options) {
  if (test(percent)) {
    var word = random(options);
    while (array.includes(REDUNDANT[word])) {
      console.log("1");
      word = random(options);
    }
    array.push(word);
  }
}

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

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

/**
 * 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");
  const title = pulpMagTitle();
  return logger.end(title);
}