summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libutil.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-03 17:59:49 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-03 17:59:49 +0000
commit718202ee6b6445890db808f4420073e2cce506c2 (patch)
tree2640787ddfef39aca363946a32a05df0ae62c62e /crawl-ref/source/libutil.cc
parent589e206de3965240ac0475dcc98b339914ace70b (diff)
downloadcrawl-ref-718202ee6b6445890db808f4420073e2cce506c2.tar.gz
crawl-ref-718202ee6b6445890db808f4420073e2cce506c2.zip
Manual update (David).
Added javelins and sling bullets. Only Urug gets javelins at the moment. No monster gets sling bullets, but they can be randomly generated. Added deep elf blademasters and master archers to provide Silence-users some entertainment on Elf:7. I've adjusted the non-rogue-layout Elf:7s to use blademasters. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1732 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r--crawl-ref/source/libutil.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc
index 042615ee64..14fe074a33 100644
--- a/crawl-ref/source/libutil.cc
+++ b/crawl-ref/source/libutil.cc
@@ -183,6 +183,72 @@ std::string pluralise(const std::string &name,
return name + "s";
}
+static std::string pow_in_words(int pow)
+{
+ switch (pow)
+ {
+ case 0:
+ return "";
+ case 3:
+ return " thousand";
+ case 6:
+ return " million";
+ case 9:
+ return " billion";
+ case 12:
+ default:
+ return " trillion";
+ }
+}
+
+static std::string tens_in_words(unsigned num)
+{
+ static const char *numbers[] = {
+ "", "one", "two", "three", "four", "five", "six", "seven",
+ "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
+ "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
+ };
+ static const char *tens[] = {
+ "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
+ "eighty", "ninety"
+ };
+
+ if (num < 20)
+ return numbers[num];
+
+ int ten = num / 10, digit = num % 10;
+ return std::string(tens[ten])
+ + (digit? std::string("-") + numbers[digit] : "");
+}
+
+static std::string join_strings(const std::string &a, const std::string &b)
+{
+ return !a.empty() && !b.empty()? a + " " + b :
+ a.empty()? b : a;
+}
+
+static std::string hundreds_in_words(unsigned num)
+{
+ unsigned dreds = num / 100, tens = num % 100;
+ std::string sdreds = dreds? tens_in_words(dreds) + " hundred" : "";
+ std::string stens = tens? tens_in_words(tens) : "";
+ return join_strings(sdreds, stens);
+}
+
+std::string number_in_words(unsigned num, int pow)
+{
+ if (pow == 12)
+ return number_in_words(num, 0) + pow_in_words(pow);
+
+ unsigned thousands = num % 1000, rest = num / 1000;
+ if (!rest and !thousands)
+ return ("zero");
+
+ return join_strings((rest? number_in_words(rest, pow + 3) : ""),
+ (thousands? hundreds_in_words(thousands) + pow_in_words(pow)
+ : ""));
+}
+
std::string replace_all(std::string s,
const std::string &find,
const std::string &repl)