From 7f72c37783571cc8a398b0c9d56a2727191c08c4 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Tue, 29 Sep 2009 10:17:05 -0500 Subject: Simplify several random array selections by using RANDOM_ELEMENT(). --- crawl-ref/source/fight.cc | 7 ++----- crawl-ref/source/ghost.cc | 4 ++-- crawl-ref/source/mstuff2.cc | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index 12ab335741..6497ac8fe5 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -4282,12 +4282,9 @@ static const char *klown_attack[] = std::string melee_attack::mons_attack_verb(const mon_attack_def &attk) { if (attacker->id() == MONS_KILLER_KLOWN && attk.type == AT_HIT) - { - const int num_attacks = sizeof(klown_attack) / sizeof(*klown_attack); - return (klown_attack[random2(num_attacks)]); - } + return (RANDOM_ELEMENT(klown_attack)); - if (attacker->id() == MONS_KRAKEN_TENTACLE) + if (attacker->id() == MONS_KRAKEN_TENTACLE && attk.type == AT_TENTACLE_SLAP) return ("slap"); static const char *attack_types[] = diff --git a/crawl-ref/source/ghost.cc b/crawl-ref/source/ghost.cc index 411d9a8dc1..bbd464e0a4 100644 --- a/crawl-ref/source/ghost.cc +++ b/crawl-ref/source/ghost.cc @@ -410,7 +410,7 @@ static unsigned char _ugly_thing_random_colour(unsigned char not_colour) unsigned char colour; do - colour = (colours[random2(sizeof(colours) / sizeof(*colours))]); + colour = RANDOM_ELEMENT(colours); while (colour == not_colour); return (colour); @@ -518,7 +518,7 @@ void ghost_demon::init_ugly_thing(bool very_ugly, bool only_mutate) AT_TENTACLE_SLAP, AT_TAIL_SLAP, AT_GORE }; - att_type = att_types[random2(sizeof(att_types) / sizeof(*att_types))]; + att_type = RANDOM_ELEMENT(att_types); // An ugly thing always gets a low-intensity colour. If we're // mutating it, it always gets a different colour from what it had diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc index 408a3e79e8..609aa86a6c 100644 --- a/crawl-ref/source/mstuff2.cc +++ b/crawl-ref/source/mstuff2.cc @@ -72,7 +72,7 @@ static monster_type _pick_random_wraith() MONS_SPECTRAL_WARRIOR }; - return wraiths[random2(sizeof(wraiths) / sizeof(*wraiths))]; + return (RANDOM_ELEMENT(wraiths)); } static monster_type _pick_horrible_thing() @@ -93,7 +93,7 @@ static monster_type _pick_undead_summon() MONS_SIMULACRUM_LARGE, MONS_SHADOW }; - return undead[random2(sizeof(undead) / sizeof(*undead))]; + return (RANDOM_ELEMENT(undead)); } static void _do_high_level_summon(monsters *monster, bool monsterNearby, -- cgit v1.2.3-54-g00ecf