From 432fd3111694130fc627da8ee6c27ddbcb79905f Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 31 Oct 2009 18:19:04 -0500 Subject: Simplify (very) ugly thing color-related functions. --- crawl-ref/source/mon-util.cc | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index 8d37d99192..14ec525994 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -1735,42 +1735,31 @@ void define_monster(monsters &mons) mons.ench_countdown = 0; } -unsigned char ugly_thing_random_colour() -{ - const unsigned char colours[] = - { - RED, BROWN, GREEN, CYAN, MAGENTA, LIGHTGREY - }; - - return (RANDOM_ELEMENT(colours)); -} +static const unsigned char ugly_colour_values[] = { + RED, BROWN, GREEN, CYAN, MAGENTA, LIGHTGREY +}; static const char *ugly_colour_names[] = { "red", "brown", "green", "cyan", "purple", "white" }; +unsigned char ugly_thing_random_colour() +{ + return (RANDOM_ELEMENT(ugly_colour_values)); +} + int ugly_thing_colour_offset(const monsters *mon) { if (mon->type != MONS_UGLY_THING && mon->type != MONS_VERY_UGLY_THING) return (-1); - switch (make_low_colour(mon->colour)) + for (unsigned i = 0; i < ARRAYSZ(ugly_colour_values); ++i) { - case RED: - return (0); - case BROWN: - return (1); - case GREEN: - return (2); - case CYAN: - return (3); - case MAGENTA: - return (4); - case LIGHTGREY: - return (5); - default: - return (-1); + if (make_low_colour(mon->colour) == ugly_colour_values[i]) + return (i); } + + return (-1); } static std::string _ugly_thing_colour_name(const monsters *mon) -- cgit v1.2.3-54-g00ecf