summaryrefslogtreecommitdiff
path: root/src/cave.cc
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:57 +0100
committerBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:57 +0100
commit7e0812e98805b1ca7a9480090a71d8a6ec830931 (patch)
tree7dc653b98ac1dabbbeaff5481a1cf37f01020fcb /src/cave.cc
parent4b6f8d810f5ad513bea8fada09be01dde0fd643c (diff)
Fix hallucinatory monsters/items
Diffstat (limited to 'src/cave.cc')
-rw-r--r--src/cave.cc131
1 files changed, 46 insertions, 85 deletions
diff --git a/src/cave.cc b/src/cave.cc
index 19bbe2e7..679af3ba 100644
--- a/src/cave.cc
+++ b/src/cave.cc
@@ -381,108 +381,69 @@ bool_ cave_valid_bold(int y, int x)
-
-/*
- * Hack -- Legal monster codes FIXME: Remove?
- */
-// static cptr image_monster_hack = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
-/*
- * Hack -- Legal monster codes for IBM pseudo-graphics
- *
- * Dropped. Although this option has long left unmaintained, hardcoding
- * code points makes it impossible to update the font and prf files
- * flexibly. And the normal graphics code still works with it -- pelpel
- */
-
/*
- * Mega-Hack -- Hallucinatory monster
+ * Generate visual for hallucinatory monster
*/
static void image_monster(byte *ap, char *cp)
{
- int n;
-
- // switch (graphics_mode)
- // {
- /* Text mode */
- // case GRAPHICS_NONE:
- // {
- // n = strlen(image_monster_hack);
-
- // /* Random symbol from set above */
- // *cp = (image_monster_hack[rand_int(n)]);
+ // Cached state which keeps a list of all the "live" monster race entries.
+ static std::vector<size_t> *instance = nullptr;
- // /* Random color */
- // *ap = randint(15);
-
- // break;
- // }
-
- // /* Normal graphics */
- // default:
- // {
- // FIXME: Why wouldn't this work for text mode too? And 2) this assumes that all indexes in r_info are valid... is that assumption OK?
- /* Avoid player ghost */
- n = randint(max_r_idx);
-
- *cp = r_info[n].x_char;
+ // First-time initialization
+ if (!instance)
+ {
+ // Create the list of "live" indexes
+ instance = new std::vector<size_t>();
+ // Start at 1 to avoid 'player'
+ for (size_t i = 1; i < max_r_idx; i++)
+ {
+ if (r_info[i].name)
+ {
+ instance->push_back(i);
+ }
+ }
+ }
- *ap = r_info[n].x_attr;
+ // Sanity check
+ assert(instance != nullptr);
- // break;
- // }
- // }
+ // Select a race at random
+ int n = rand_int(instance->size());
+ *cp = r_info[(*instance)[n]].x_char;
+ *ap = r_info[(*instance)[n]].x_attr;
}
-
-
-/*
- * Hack -- Legal object codes FIXME: Remove?
- */
-// static cptr image_object_hack = "?/|\\\"!$()_-=[]{},~";
-
/*
- * Hardcoded IBM pseudo-graphics code points have been removed
- * for the same reason as stated above -- pelpel
- */
-
-/*
- * Mega-Hack -- Hallucinatory object
+ * Generate visual for hallucinatory object
*/
static void image_object(byte *ap, char *cp)
{
- int n;
-
- // switch (graphics_mode)
- // {
- // /* Text mode */
- // case GRAPHICS_NONE:
- // {
- // n = strlen(image_object_hack);
+ // Cached state which keeps a list of the "live" object_kind entries.
+ static std::vector<size_t> *instance = nullptr;
- // /* Random symbol from set above */
- // *cp = (image_object_hack[rand_int(n)]);
-
- // /* Random color */
- // *ap = randint(15);
-
- // /* Done */
- // break;
- // }
-
- // /* Normal graphics */
- // default:
- // {
- // FIXME: Why wouldn't this work for text mode too? And 2) this assumes that all k_info indexes are valid... is that assumption correct?!?
- n = randint(max_k_idx - 1);
+ // First-time initialization
+ if (!instance)
+ {
+ // Create the list of "live" indexes
+ instance = new std::vector<size_t>();
+ // Filter all the "live" entries
+ for (size_t i = 0; i < max_k_idx; i++)
+ {
+ if (k_info[i].name)
+ {
+ instance->push_back(i);
+ }
+ }
+ }
- *cp = k_info[n].x_char;
- *ap = k_info[n].x_attr;
+ // Sanity check
+ assert(instance != nullptr);
- // break;
- // }
- // }
+ // Select an object kind at random
+ int n = rand_int(instance->size());
+ *cp = k_info[(*instance)[n]].x_char;
+ *ap = k_info[(*instance)[n]].x_attr;
}