From 0d9b633b8c5b5395e80c38fa5916fd0f81d1041a Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 21 Dec 2019 18:15:27 -0500 Subject: [PATCH] Add pickStringChance; make chance of generic description depend on possible descriptions, not all of them Previously, if there were 10 possible descriptions for an action, the chance of getting the normal text was only 1 in 12. Now, only descriptions whose criteria are met count towards this chance --- recursive-desc.js | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/recursive-desc.js b/recursive-desc.js index 3ab5a9c..9155837 100644 --- a/recursive-desc.js +++ b/recursive-desc.js @@ -5,6 +5,15 @@ var rules = {}; var defaults = {}; +const synonyms = { + heavy: ["heavy", "weighty"], + huge: ["huge", "massive", "gigantic", "large"], + cosmic: ["cosmic", "utterly colossal", "star-spanning"], + gulp: ["gulp", "gluk", "glrk", "glp"], + swallow: ["swallow", "gulp"], + looming: ["looming", "imposing", "awe-inspiring", "menacing"] +} + function plural(quantity, singular, plural) { return quantity > 1 ? plural : singular; } @@ -134,7 +143,7 @@ function describe(action, container, macro, verbose=true, flat=false, extra1=0) container = flatten(container); } - if (options.length > 0 && Math.random() > (1 / (2 + rules[action].length))) { + if (options.length > 0 && Math.random() > (1 / (2 + options.length))) { let choice = Math.floor(Math.random() * options.length); return options[choice](container, macro, verbose, flat, extra1); } @@ -152,6 +161,15 @@ function pickString(...array){ var pick = strings[~~(Math.random() * strings.length)]; return pick; } + +function pickStringChance(chance, ...array) { + if (Math.random() < chance) { + return pickString(...array); + } else { + return "" + } +} + // DEFAULTS function defaultEat(container, macro, verbose, flat) { @@ -215,6 +233,7 @@ function defaultStomp(container, macro, verbose, flat) { container.describe(verbose), pickString("under", "beneath", "with"), "your", + pickStringChance(0.4, ...synonyms.looming), macro.footDesc(false,false,true) + "." ], [ capitalize(container.describe(verbose)), @@ -229,21 +248,20 @@ function defaultStomp(container, macro, verbose, flat) { macro.footDesc(false,false,true), pickString("crushes", "smashes", "flattens"), container.describe(verbose) - ]).join(" "); + ]).filter(Boolean).join(" "); else return "You step on " + container.describe(verbose) + "."; } function defaultStompWedge(container, macro, verbose, flat) { - if (container.count == 1) { - let line = container.describe(verbose); - line = line.charAt(0).toUpperCase() + line.slice(1); - return line + " is wedged in your " + macro.toeDesc(true); - } else { - let line = container.describe(verbose); - line = line.charAt(0).toUpperCase() + line.slice(1); - return line + " are wedged in your " + macro.toeDesc(true); - } + return [ + capitalize(container.describe(verbose)), + (container.count > 1 ? "are" : "is"), + pickString("wedged", "trapped", "left stuck", "jammed"), + pickString("in", "between", "within"), + "your", + macro.toeDesc(true) + ].join(" ") } function defaultFlexToes(container, macro, verbose, flat) {