summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/debug.cc9
-rw-r--r--crawl-ref/source/enum.h5
-rw-r--r--crawl-ref/source/food.cc2
-rw-r--r--crawl-ref/source/it_use2.cc4
-rw-r--r--crawl-ref/source/items.cc2
-rw-r--r--crawl-ref/source/mutation.cc118
-rw-r--r--crawl-ref/source/mutation.h8
-rw-r--r--crawl-ref/source/notes.cc6
-rw-r--r--crawl-ref/source/player.cc2
-rw-r--r--crawl-ref/source/spl-cast.cc4
-rw-r--r--crawl-ref/source/xom.cc4
11 files changed, 87 insertions, 77 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 7158778e84..6cd43af64f 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -1318,23 +1318,24 @@ bool debug_add_mutation(void)
if (specs[0] == '\0')
return (false);
- int mutation = -1;
+ mutation_type mutation = NUM_MUTATIONS;
for (int i = 0; i < NUM_MUTATIONS; i++)
{
char mut_name[80];
- strncpy( mut_name, mutation_name( i, 1 ), sizeof( mut_name ) );
+ const mutation_type m = static_cast<mutation_type>(i);
+ strncpy( mut_name, mutation_name( m, 1 ), sizeof( mut_name ) );
char *ptr = strstr( strlwr(mut_name), strlwr(specs) );
if (ptr != NULL)
{
// we take the first mutation that matches
- mutation = i;
+ mutation = m;
break;
}
}
- if (mutation == -1)
+ if (mutation == NUM_MUTATIONS)
mpr("I can't warp you that way!");
else
{
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h
index 99ffc763e6..47d22008da 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -2704,7 +2704,10 @@ enum mutation_type
MUT_RED2_SCALES,
MUT_IRIDESCENT_SCALES,
MUT_PATTERNED_SCALES, // 85
- NUM_MUTATIONS
+ NUM_MUTATIONS,
+
+ RANDOM_MUTATION = 100,
+ RANDOM_XOM_MUTATION = 101
};
enum object_class_type // (unsigned char) mitm[].base_type
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index 9c0ad6d5d2..776b47d945 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -769,7 +769,7 @@ static void eat_chunk( int chunk_effect )
{
case CE_MUTAGEN_RANDOM:
mpr("This meat tastes really weird.");
- mutate(100);
+ mutate(RANDOM_MUTATION);
xom_is_stimulated(100);
break;
diff --git a/crawl-ref/source/it_use2.cc b/crawl-ref/source/it_use2.cc
index b247568409..9738564c53 100644
--- a/crawl-ref/source/it_use2.cc
+++ b/crawl-ref/source/it_use2.cc
@@ -265,7 +265,7 @@ bool potion_effect( potion_type pot_eff, int pow )
for (i = 0; i < 7; i++)
{
if (random2(10) > i)
- delete_mutation(100);
+ delete_mutation(RANDOM_MUTATION);
}
break;
@@ -273,7 +273,7 @@ bool potion_effect( potion_type pot_eff, int pow )
mpr("You feel extremely strange.");
for (i = 0; i < 3; i++)
{
- mutate(100, false);
+ mutate(RANDOM_MUTATION, false);
}
did_god_conduct(DID_STIMULANTS, 4 + random2(4));
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index b055822f5d..edabb39e9d 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -2366,7 +2366,7 @@ void handle_time( long time_delta )
// we want to warp the player, not do good stuff!
if (one_chance_in(5))
- mutate(100);
+ mutate(RANDOM_MUTATION);
else
give_bad_mutation(coinflip());
diff --git a/crawl-ref/source/mutation.cc b/crawl-ref/source/mutation.cc
index f3f001e686..ce1c580ea3 100644
--- a/crawl-ref/source/mutation.cc
+++ b/crawl-ref/source/mutation.cc
@@ -1132,7 +1132,7 @@ formatted_string describe_mutations()
result += colourname;
result += '>';
}
- result += mutation_name(i);
+ result += mutation_name(static_cast<mutation_type>(i));
if ( you.demon_pow[i] )
{
result += "</";
@@ -1159,7 +1159,7 @@ void display_mutations()
getch();
}
-static int calc_mutation_amusement_value(int which_mutation)
+static int calc_mutation_amusement_value(mutation_type which_mutation)
{
int amusement = 16 * (11 - mutation_rarity[which_mutation]);
@@ -1214,10 +1214,26 @@ static int calc_mutation_amusement_value(int which_mutation)
return (amusement);
}
-bool mutate(int which_mutation, bool failMsg, bool force_mutation,
+static bool accept_mutation( mutation_type mutat )
+{
+ int limit = 3;
+ if ( mutat == MUT_STRONG || mutat == MUT_CLEVER ||
+ mutat == MUT_AGILE || mutat == MUT_WEAK ||
+ mutat == MUT_DOPEY || mutat == MUT_CLUMSY )
+ limit = 14;
+
+ if ( you.mutation[mutat] >= limit )
+ return false;
+
+ const int rarity = mutation_rarity[mutat] + you.demon_pow[mutat];
+ // low rarity means unlikely to choose it
+ return (rarity > random2(10));
+}
+
+bool mutate(mutation_type which_mutation, bool failMsg, bool force_mutation,
bool demonspawn)
{
- int mutat = which_mutation;
+ mutation_type mutat = which_mutation;
if (demonspawn)
force_mutation = true;
@@ -1267,36 +1283,30 @@ bool mutate(int which_mutation, bool failMsg, bool force_mutation,
return (false);
}
- if (which_mutation == 100 && random2(15) < how_mutated())
+ if (which_mutation == RANDOM_MUTATION)
{
- if (!force_mutation && !one_chance_in(3))
- return (false);
+ if ( random2(15) < how_mutated() )
+ {
+ if (!force_mutation && !one_chance_in(3))
+ return (false);
+ else
+ return (delete_mutation(RANDOM_MUTATION));
+ }
else
- return (delete_mutation(100));
- }
-
- if (which_mutation == 100)
- {
- do
{
- mutat = random2(NUM_MUTATIONS);
-
- if (one_chance_in(1000))
- return false;
+ do
+ {
+ mutat = static_cast<mutation_type>(random2(NUM_MUTATIONS));
+ if (one_chance_in(1000))
+ return false;
+ } while ( !accept_mutation(mutat) );
}
- while ((you.mutation[mutat] >= 3
- && (mutat != MUT_STRONG && mutat != MUT_CLEVER
- && mutat != MUT_AGILE) && (mutat != MUT_WEAK
- && mutat != MUT_DOPEY
- && mutat != MUT_CLUMSY))
- || you.mutation[mutat] > 13
- || random2(10) >= mutation_rarity[mutat] + you.demon_pow[mutat]);
}
- else if (which_mutation == 101)
+ else if (which_mutation == RANDOM_XOM_MUTATION)
{
do
{
- mutat = random2(NUM_MUTATIONS);
+ mutat = static_cast<mutation_type>(random2(NUM_MUTATIONS));
if (one_chance_in(1000))
return false;
@@ -1315,19 +1325,12 @@ bool mutate(int which_mutation, bool failMsg, bool force_mutation,
}
}
}
- while ((you.mutation[mutat] >= 3
- && (mutat != MUT_STRONG && mutat != MUT_CLEVER
- && mutat != MUT_AGILE) && (mutat != MUT_WEAK
- && mutat != MUT_DOPEY
- && mutat != MUT_CLUMSY))
- || you.mutation[mutat] > 13
- || random2(10) >= mutation_rarity[mutat] + you.demon_pow[mutat]);
+ while ( !accept_mutation(mutat) );
}
- else if (you.mutation[mutat] >= 3
- && (mutat != MUT_STRONG && mutat != MUT_CLEVER
- && mutat != MUT_AGILE)
- && (mutat != MUT_WEAK && mutat != MUT_DOPEY
- && mutat != MUT_CLUMSY))
+ else if (you.mutation[mutat] >= 3 &&
+ mutat != MUT_STRONG && mutat != MUT_CLEVER &&
+ mutat != MUT_AGILE && mutat != MUT_WEAK &&
+ mutat != MUT_DOPEY && mutat != MUT_CLUMSY)
{
return false;
}
@@ -1721,9 +1724,9 @@ int how_mutated(void)
return (j);
} // end how_mutated()
-bool delete_mutation(int which_mutation)
+bool delete_mutation(mutation_type which_mutation)
{
- int mutat = which_mutation;
+ mutation_type mutat = which_mutation;
int i;
if (you.mutation[MUT_MUTATION_RESISTANCE] > 1
@@ -1733,11 +1736,11 @@ bool delete_mutation(int which_mutation)
return false;
}
- if (which_mutation == 100)
+ if (which_mutation == RANDOM_MUTATION)
{
do
{
- mutat = random2(NUM_MUTATIONS);
+ mutat = static_cast<mutation_type>(random2(NUM_MUTATIONS));
if (one_chance_in(1000))
return false;
}
@@ -1930,7 +1933,7 @@ char body_covered(void)
return covered;
}
-const char *mutation_name(int which_mutat, int level )
+const char *mutation_name(mutation_type which_mutat, int level)
{
static char mut_string[INFO_SIZE];
@@ -1959,7 +1962,7 @@ const char *mutation_name(int which_mutat, int level )
/* Use an attribute counter for how many demonic mutations a dspawn has */
void demonspawn(void)
{
- int whichm = -1;
+ mutation_type whichm = NUM_MUTATIONS;
char howm = 1;
int counter = 0;
@@ -2083,10 +2086,11 @@ void demonspawn(void)
}
// check here so we can see if we need to extend our options:
- if (whichm != -1 && you.mutation[whichm] != 0)
- whichm = -1;
+ if (whichm != NUM_MUTATIONS && you.mutation[whichm] != 0)
+ whichm = NUM_MUTATIONS;
- if (you.experience_level < 10 || (counter > 0 && whichm == -1))
+ if (you.experience_level < 10 ||
+ (counter > 0 && whichm == NUM_MUTATIONS))
{
if ((!you.mutation[MUT_THROW_FROST] // only one of these
&& !you.mutation[MUT_THROW_FLAMES]
@@ -2204,7 +2208,8 @@ void demonspawn(void)
if (one_chance_in(12))
{
- whichm = MUT_RED_SCALES + random2(16);
+ whichm = static_cast<mutation_type>(MUT_RED_SCALES +
+ random2(16));
switch (whichm)
{
@@ -2252,14 +2257,14 @@ void demonspawn(void)
}
}
- if (whichm != -1 && you.mutation[whichm] != 0)
- whichm = -1;
+ if (whichm != NUM_MUTATIONS && you.mutation[whichm] != 0)
+ whichm = NUM_MUTATIONS;
counter++;
}
- while (whichm == -1 && counter < 5000);
+ while (whichm == NUM_MUTATIONS && counter < 5000);
- if (whichm == -1 || !perma_mutate( whichm, howm ))
+ if (whichm == NUM_MUTATIONS || !perma_mutate( whichm, howm ))
{
/* unlikely but remotely possible */
/* I know this is a cop-out */
@@ -2270,7 +2275,7 @@ void demonspawn(void)
}
} // end demonspawn()
-bool perma_mutate(int which_mut, char how_much)
+bool perma_mutate(mutation_type which_mut, int how_much)
{
char levels = 0;
@@ -2290,10 +2295,9 @@ bool perma_mutate(int which_mut, char how_much)
bool give_bad_mutation(bool forceMutation, bool failMsg)
{
- int temp_rand = 0; // probability determination {dlb}
- int which_bad_one = 0;
+ mutation_type which_bad_one;
- temp_rand = random2(12);
+ const int temp_rand = random2(12);
which_bad_one = ((temp_rand >= 11) ? MUT_CARNIVOROUS :
(temp_rand == 10) ? MUT_HERBIVOROUS :
@@ -2314,7 +2318,7 @@ bool give_bad_mutation(bool forceMutation, bool failMsg)
//jmf: might be useful somewhere (eg Xom or transmigration effect)
bool give_cosmetic_mutation()
{
- int mutation = -1;
+ mutation_type mutation = NUM_MUTATIONS;
int how_much = 0;
int counter = 0;
diff --git a/crawl-ref/source/mutation.h b/crawl-ref/source/mutation.h
index f7f2b27d93..a50c1c50e8 100644
--- a/crawl-ref/source/mutation.h
+++ b/crawl-ref/source/mutation.h
@@ -22,7 +22,7 @@
* called from: acr - decks - effects - fight - food - it_use2 - items -
* mutation - religion - spell - spells
* *********************************************************************** */
-bool mutate(int which_mutation, bool failMsg = true,
+bool mutate(mutation_type which_mutation, bool failMsg = true,
bool force_mutation = false, bool demonspawn = false);
@@ -39,7 +39,7 @@ formatted_string describe_mutations();
/* ***********************************************************************
* called from: decks - it_use2 - mutation - spells
* *********************************************************************** */
-bool delete_mutation(int which_mutation);
+bool delete_mutation(mutation_type which_mutation);
// last updated 12may2000 {dlb}
@@ -47,7 +47,7 @@ bool delete_mutation(int which_mutation);
* called from: chardump
* *********************************************************************** */
// default of level == -1, means to use the player's current level
-const char *mutation_name( int which_mutat, int level = -1 );
+const char *mutation_name( mutation_type which_mutat, int level = -1 );
// last updated 12may2000 {dlb}
@@ -68,6 +68,6 @@ bool give_bad_mutation( bool forceMutation = false, bool failMsg = true );
* *********************************************************************** */
void demonspawn(void);
-bool perma_mutate(int which_mut, char how_much);
+bool perma_mutate(mutation_type which_mut, int how_much);
#endif
diff --git a/crawl-ref/source/notes.cc b/crawl-ref/source/notes.cc
index 8658c33ab3..3f3e1124ed 100644
--- a/crawl-ref/source/notes.cc
+++ b/crawl-ref/source/notes.cc
@@ -302,11 +302,13 @@ std::string Note::describe( bool when, bool where, bool what ) const
break;
case NOTE_GET_MUTATION:
result << "Gained mutation: "
- << mutation_name(first, second == 0 ? 1 : second);
+ << mutation_name(static_cast<mutation_type>(first),
+ second == 0 ? 1 : second);
break;
case NOTE_LOSE_MUTATION:
result << "Lost mutation: "
- << mutation_name(first, second == 3 ? 3 : second+1);
+ << mutation_name(static_cast<mutation_type>(first),
+ second == 3 ? 3 : second+1);
break;
case NOTE_USER_NOTE:
result << name;
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 9713d5c8a3..d3b2075eff 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -5230,7 +5230,7 @@ bool player::backlit() const
void player::mutate()
{
if (one_chance_in(5))
- ::mutate(100);
+ ::mutate(RANDOM_MUTATION);
else
give_bad_mutation();
}
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index b45e069e1e..61a9e1aaa1 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -1548,7 +1548,7 @@ spret_type your_spells( spell_type spell, int powc, bool allow_fail )
set_hp( 1 + random2(you.hp), false );
- if (!mutate(100, false))
+ if (!mutate(RANDOM_MUTATION, false))
mpr("Odd... you don't feel any different.");
break;
@@ -2857,7 +2857,7 @@ bool miscast_effect( unsigned int sp_type, int mag_pow, int mag_fail,
case 1:
mpr("You feel very strange.");
- delete_mutation(100);
+ delete_mutation(RANDOM_MUTATION);
ouch(5 + random2avg(23, 2), 0, KILLED_BY_WILD_MAGIC, cause);
break;
diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc
index be3754a4c8..deb949009b 100644
--- a/crawl-ref/source/xom.cc
+++ b/crawl-ref/source/xom.cc
@@ -525,7 +525,7 @@ static bool xom_is_good(int sever)
int j = random2(4);
while (i < j)
{
- if (mutate(100, failMsg, true))
+ if (mutate(RANDOM_MUTATION, failMsg, true))
done = true;
else
failMsg = false;
@@ -665,7 +665,7 @@ static bool xom_is_bad(int sever)
bool failMsg = true;
for (int i = 0; i < random2(4)+1; i++)
{
- if (mutate(101, failMsg, true))
+ if (mutate(RANDOM_XOM_MUTATION, failMsg, true))
done = true;
else
failMsg = false;