summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-26 16:15:58 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-26 16:15:58 +0000
commitbf21ef9d3d94cd696c1661e6610296c367a6a34f (patch)
tree2eff7cb3055f54554cfdd1db13e83d683b588c86
parent2bccfd8a3ce5d589f5ba82697dbee17fe05e670c (diff)
downloadcrawl-ref-bf21ef9d3d94cd696c1661e6610296c367a6a34f.tar.gz
crawl-ref-bf21ef9d3d94cd696c1661e6610296c367a6a34f.zip
Trunk->0.3 merge (2569, 2571): Code cleanup.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.3@2599 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/debug.cc7
-rw-r--r--crawl-ref/source/describe.cc11
-rw-r--r--crawl-ref/source/hiscores.cc9
-rw-r--r--crawl-ref/source/monstuff.cc19
-rw-r--r--crawl-ref/source/newgame.cc13
-rw-r--r--crawl-ref/source/player.cc262
-rw-r--r--crawl-ref/source/player.h8
-rw-r--r--crawl-ref/source/skills2.cc2
8 files changed, 106 insertions, 225 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 9b70a50930..cd922de58c 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -247,8 +247,9 @@ void debug_change_species( void )
for (i = SP_HUMAN; i < NUM_SPECIES; i++)
{
+ const species_type si = static_cast<species_type>(i);
const std::string sp_name =
- lowercase_string(species_name(i, you.experience_level));
+ lowercase_string(species_name(si, you.experience_level));
std::string::size_type pos = sp_name.find(specs);
if (pos != std::string::npos)
@@ -256,11 +257,11 @@ void debug_change_species( void )
if (pos == 0 && *specs)
{
// we prefer prefixes over partial matches
- sp = static_cast<species_type>(i);
+ sp = si;
break;
}
else
- sp = static_cast<species_type>(i);
+ sp = si;
}
}
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index cc7e49ef3f..60d631ffbd 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -3800,13 +3800,16 @@ std::string ghost_description(const monsters &mons, bool concise)
const ghost_demon &ghost = *(mons.ghost);
+ const species_type gspecies =
+ static_cast<species_type>(ghost.values[GVAL_SPECIES]);
+
// We're fudging stats so that unarmed combat gets based off
// of the ghost's species, not the player's stats... exact
// stats aren't required anyways, all that matters is whether
// dex >= str. -- bwr
const int dex = 10;
int str;
- switch (ghost.values[GVAL_SPECIES])
+ switch (gspecies)
{
case SP_MOUNTAIN_DWARF:
case SP_TROLL:
@@ -3835,7 +3838,7 @@ std::string ghost_description(const monsters &mons, bool concise)
gstr << ghost.name << " the "
<< skill_title( ghost.values[GVAL_BEST_SKILL],
ghost.values[GVAL_SKILL_LEVEL],
- ghost.values[GVAL_SPECIES],
+ gspecies,
str, dex, GOD_NO_GOD )
<< ", a"
<< ((ghost.values[GVAL_EXP_LEVEL] < 4) ? " weakling" :
@@ -3848,10 +3851,10 @@ std::string ghost_description(const monsters &mons, bool concise)
: " legendary")
<< " ";
if ( concise )
- gstr << get_species_abbrev(ghost.values[GVAL_SPECIES])
+ gstr << get_species_abbrev(gspecies)
<< get_class_abbrev(ghost.values[GVAL_CLASS]);
else
- gstr << species_name(ghost.values[GVAL_SPECIES],
+ gstr << species_name(gspecies,
ghost.values[GVAL_EXP_LEVEL])
<< " "
<< get_class_name(ghost.values[GVAL_CLASS]);
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index 4fdcc79e78..e77e56ec88 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -659,7 +659,9 @@ void scorefile_entry::set_base_xlog_fields() const
fields->add_field("lv", SCORE_VERSION);
fields->add_field("name", "%s", name.c_str());
fields->add_field("uid", "%d", uid);
- fields->add_field("race", "%s", species_name(race, lvl).c_str());
+ fields->add_field("race", "%s",
+ species_name(static_cast<species_type>(race),
+ lvl).c_str());
fields->add_field("cls", "%s", get_class_name(cls));
fields->add_field("char", "%s%s",
get_species_abbrev(race),
@@ -1204,7 +1206,8 @@ scorefile_entry::character_description(death_desc_verbosity verbosity) const
else
{
snprintf( buf, HIGHSCORE_SIZE, "%8ld %s the %s %s (level %d",
- points, name.c_str(), species_name(race, lvl).c_str(),
+ points, name.c_str(),
+ species_name(static_cast<species_type>(race), lvl).c_str(),
get_class_name(cls), lvl );
desc = buf;
}
@@ -1228,7 +1231,7 @@ scorefile_entry::character_description(death_desc_verbosity verbosity) const
if (verbose)
{
- std::string srace = species_name( race, lvl );
+ std::string srace = species_name(static_cast<species_type>(race), lvl);
snprintf( scratch, INFO_SIZE, "Began as a%s %s %s",
is_vowel(srace[0]) ? "n" : "",
srace.c_str(),
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index 901b27894f..5ae7f18f0c 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <math.h>
#ifdef DOS
#include <conio.h>
@@ -1186,8 +1185,7 @@ bool monster_polymorph( monsters *monster, monster_type targetc,
str_polymon += "!";
}
- bool player_messaged =
- simple_monster_message(monster, str_polymon.c_str() );
+ bool player_messaged = simple_monster_message(monster, str_polymon.c_str());
// the actual polymorphing:
const int old_hp = monster->hit_points;
@@ -1258,16 +1256,23 @@ bool monster_polymorph( monsters *monster, monster_type targetc,
}
}
else if (mons_is_insubstantial(monster->type)
- || monster->type == MONS_OOZE || monster->type == MONS_PULSATING_LUMP)
+ || monster->type == MONS_OOZE
+ || monster->type == MONS_PULSATING_LUMP)
{
- int net = get_trapping_net(monster->x, monster->y);
+ const int net = get_trapping_net(monster->x, monster->y);
if (net != NON_ITEM)
remove_item_stationary(mitm[net]);
if (mons_is_insubstantial(monster->type))
- simple_monster_message(monster, " drifts right through the net!");
+ {
+ simple_monster_message(monster,
+ " drifts right through the net!");
+ }
else
- simple_monster_message(monster, " oozes right through the net!");
+ {
+ simple_monster_message(monster,
+ " oozes right through the net!");
+ }
}
else
monster->add_ench(ENCH_HELD);
diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc
index 221187b679..23072e2db1 100644
--- a/crawl-ref/source/newgame.cc
+++ b/crawl-ref/source/newgame.cc
@@ -191,8 +191,8 @@ static bool prev_startup_options_set(void)
static std::string get_opt_race_name(char race)
{
- int prace = letter_to_species(race);
- return prace && prace != SP_UNKNOWN? species_name(prace, 1) : "Random";
+ species_type prace = letter_to_species(race);
+ return prace != SP_UNKNOWN? species_name(prace, 1) : "Random";
}
static std::string get_opt_class_name(char oclass)
@@ -3041,18 +3041,19 @@ spec_query:
*linebuf = 0;
for (int i = SP_HUMAN; i < NUM_SPECIES; ++i)
{
- if (!is_species_valid_choice(static_cast<species_type>(i)))
+ const species_type si = static_cast<species_type>(i);
+ if (!is_species_valid_choice(si))
continue;
if (you.char_class != JOB_UNKNOWN &&
- !class_allowed(static_cast<species_type>(i), you.char_class))
+ !class_allowed(si, you.char_class))
continue;
char buf[100];
- char sletter = species_to_letter(i);
+ char sletter = species_to_letter(si);
snprintf(buf, sizeof buf, "%c - %-26s",
sletter,
- species_name(i, 1).c_str());
+ species_name(si, 1).c_str());
if (sletter == Options.prev_race)
prevraceok = true;
strncat(linebuf, buf, sizeof linebuf);
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index ae2b6f621e..7ee7221904 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -27,7 +27,6 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include <math.h>
#include <ctype.h>
#include <sstream>
@@ -89,63 +88,10 @@ std::string pronoun_you(description_level_type desc)
}
}
-//////////////////////////////////////////////////////////////////////////
-/*
- you.duration []: //jmf: obsolete, see enum.h instead
- //[ds] Well, can we lose it yet?
- 0 - liquid flames
- 1 - icy armour
- 2 - repel missiles
- 3 - prayer
- 4 - regeneration
- 5 - vorpal blade
- 6 - fire brand
- 7 - ice brand
- 8 - lethal infusion
- 9 - swiftness
- 10 - insulation
- 11 - stonemail
- 12 - controlled flight
- 13 - teleport
- 14 - control teleport
- 15 - poison weapon
- 16 - resist poison
- 17 - breathe something
- 18 - transformation (duration)
- 19 - death channel
- 20 - deflect missiles
- */
-
-/* attributes
- 0 - resist lightning
- 1 - spec_air
- 2 - spec_earth
- 3 - control teleport
- 4 - walk slowly (eg naga)
- 5 - transformation (form)
- 6 - Nemelex card gift countdown
- 7 - Nemelex has given you a card table
- 8 - How many demonic powers a dspawn has
- */
-
-/* armour list
- 0 - wielded
- 1 - cloak
- 2 - helmet
- 3 - gloves
- 4 - boots
- 5 - shield
- 6 - body armour
- 7 - ring 0
- 8 - ring 1
- 9 - amulet
- */
-
/* Contains functions which return various player state vars,
and other stuff related to the player. */
-int species_exp_mod(char species);
-void ability_increase(void);
+static void ability_increase();
// Use this function whenever the player enters (or lands and thus re-enters)
// a grid.
@@ -416,7 +362,7 @@ bool player_under_penance(void)
return (false);
}
-bool player_genus(unsigned char which_genus, unsigned char species)
+bool player_genus(genus_type which_genus, species_type species)
{
if (species == SP_UNKNOWN)
species = you.species;
@@ -3199,7 +3145,7 @@ int check_stealth(void)
return (stealth);
} // end check_stealth()
-void ability_increase(void)
+static void ability_increase()
{
mpr("Your experience leads to an increase in your attributes!",
MSGCH_INTRINSIC_GAIN);
@@ -3546,72 +3492,51 @@ int str_to_species(const std::string &species)
for (int i = SP_HUMAN; i < NUM_SPECIES; ++i)
{
- if (species == species_name(i, 10))
+ if (species == species_name(static_cast<species_type>(i), 10))
return (i);
}
for (int i = SP_HUMAN; i < NUM_SPECIES; ++i)
{
- if (species == species_name(i, 1))
+ if (species == species_name(static_cast<species_type>(i), 1))
return (i);
}
return (SP_HUMAN);
}
-// Note that this function only has the one static buffer, so if you
-// want to use the results, you'll want to make a copy.
-std::string species_name( int speci, int level, bool genus,
- bool adj, bool cap )
-// defaults: false false true
+std::string species_name(species_type speci, int level, bool genus, bool adj)
+// defaults: false false
{
- static char species_buff[80];
+ std::string res;
if (player_genus( GENPC_DRACONIAN, speci ))
{
if (adj || genus) // adj doesn't care about exact species
- strcpy( species_buff, "Draconian" );
+ res = "Draconian";
else
{
- // No longer have problems with ghosts here -- Sharp Aug2002
if (level < 7)
- strcpy( species_buff, "Draconian" );
+ res = "Draconian";
else
{
switch (speci)
{
- case SP_RED_DRACONIAN:
- strcpy( species_buff, "Red Draconian" );
- break;
- case SP_WHITE_DRACONIAN:
- strcpy( species_buff, "White Draconian" );
- break;
- case SP_GREEN_DRACONIAN:
- strcpy( species_buff, "Green Draconian" );
- break;
- case SP_GOLDEN_DRACONIAN:
- strcpy( species_buff, "Yellow Draconian" );
- break;
- case SP_GREY_DRACONIAN:
- strcpy( species_buff, "Grey Draconian" );
- break;
- case SP_BLACK_DRACONIAN:
- strcpy( species_buff, "Black Draconian" );
- break;
- case SP_PURPLE_DRACONIAN:
- strcpy( species_buff, "Purple Draconian" );
- break;
- case SP_MOTTLED_DRACONIAN:
- strcpy( species_buff, "Mottled Draconian" );
- break;
- case SP_PALE_DRACONIAN:
- strcpy( species_buff, "Pale Draconian" );
- break;
+ case SP_RED_DRACONIAN: res = "Red Draconian"; break;
+ case SP_WHITE_DRACONIAN: res = "White Draconian"; break;
+ case SP_GREEN_DRACONIAN: res = "Green Draconian"; break;
+ case SP_GOLDEN_DRACONIAN: res = "Yellow Draconian"; break;
+ case SP_GREY_DRACONIAN: res = "Grey Draconian"; break;
+ case SP_BLACK_DRACONIAN: res = "Black Draconian"; break;
+ case SP_PURPLE_DRACONIAN: res = "Purple Draconian"; break;
+ case SP_MOTTLED_DRACONIAN: res = "Mottled Draconian"; break;
+ case SP_PALE_DRACONIAN: res = "Pale Draconian"; break;
+
case SP_UNK0_DRACONIAN:
case SP_UNK1_DRACONIAN:
case SP_BASE_DRACONIAN:
default:
- strcpy( species_buff, "Draconian" );
+ res = "Draconian";
break;
}
}
@@ -3620,47 +3545,33 @@ std::string species_name( int speci, int level, bool genus,
else if (player_genus( GENPC_ELVEN, speci ))
{
if (adj) // doesn't care about species/genus
- strcpy( species_buff, "Elven" );
+ res = "Elven";
else if (genus)
- strcpy( species_buff, "Elf" );
+ res = "Elf";
else
{
switch (speci)
{
- default:
- strcpy( species_buff, "Elf" );
- break;
- case SP_HIGH_ELF:
- strcpy( species_buff, "High Elf" );
- break;
- case SP_GREY_ELF:
- strcpy( species_buff, "Grey Elf" );
- break;
- case SP_DEEP_ELF:
- strcpy( species_buff, "Deep Elf" );
- break;
- case SP_SLUDGE_ELF:
- strcpy( species_buff, "Sludge Elf" );
- break;
+ case SP_HIGH_ELF: res = "High Elf"; break;
+ case SP_GREY_ELF: res = "Grey Elf"; break;
+ case SP_DEEP_ELF: res = "Deep Elf"; break;
+ case SP_SLUDGE_ELF: res = "Sludge Elf"; break;
+ default: res = "Elf"; break;
}
}
}
else if (player_genus( GENPC_DWARVEN, speci ))
{
if (adj) // doesn't care about species/genus
- strcpy( species_buff, "Dwarven" );
+ res = "Dwarven";
else if (genus)
- strcpy( species_buff, "Dwarf" );
+ res = "Dwarf";
else
{
switch (speci)
{
- case SP_MOUNTAIN_DWARF:
- strcpy( species_buff, "Mountain Dwarf" );
- break;
- default:
- strcpy( species_buff, "Dwarf" );
- break;
+ case SP_MOUNTAIN_DWARF: res = "Mountain Dwarf"; break;
+ default: res = "Dwarf"; break;
}
}
}
@@ -3668,78 +3579,37 @@ std::string species_name( int speci, int level, bool genus,
{
switch (speci)
{
- case SP_HUMAN:
- strcpy( species_buff, "Human" );
- break;
- case SP_HALFLING:
- strcpy( species_buff, "Halfling" );
- break;
+ case SP_HUMAN: res = "Human"; break;
+ case SP_HALFLING: res = "Halfling"; break;
+ case SP_KOBOLD: res = "Kobold"; break;
+ case SP_MUMMY: res = "Mummy"; break;
+ case SP_NAGA: res = "Naga"; break;
+ // We've previously declared that these are radically
+ // different from Ogres... so we're not going to
+ // refer to them as Ogres. -- bwr
+ case SP_OGRE_MAGE: res = "Ogre-Mage"; break;
+ case SP_CENTAUR: res = "Centaur"; break;
+ case SP_SPRIGGAN: res = "Spriggan"; break;
+ case SP_MINOTAUR: res = "Minotaur"; break;
+ case SP_KENKU: res = "Kenku"; break;
+ case SP_VAMPIRE: res = "Vampire"; break;
+
case SP_HILL_ORC:
- strcpy( species_buff, (adj) ? "Orcish" : (genus) ? "Orc"
- : "Hill Orc" );
- break;
- case SP_KOBOLD:
- strcpy( species_buff, "Kobold" );
- break;
- case SP_MUMMY:
- strcpy( species_buff, "Mummy" );
- break;
- case SP_NAGA:
- strcpy( species_buff, "Naga" );
- break;
- case SP_GNOME:
- strcpy( species_buff, (adj) ? "Gnomish" : "Gnome" );
- break;
- case SP_OGRE:
- strcpy( species_buff, (adj) ? "Ogreish" : "Ogre" );
- break;
- case SP_TROLL:
- strcpy( species_buff, (adj) ? "Trollish" : "Troll" );
- break;
- case SP_OGRE_MAGE:
- // We've previously declared that these are radically
- // different from Ogres... so we're not going to
- // refer to them as Ogres. -- bwr
- strcpy( species_buff, "Ogre-Mage" );
- break;
- case SP_CENTAUR:
- strcpy( species_buff, "Centaur" );
- break;
- case SP_DEMIGOD:
- strcpy( species_buff, (adj) ? "Divine" : "Demigod" );
- break;
- case SP_SPRIGGAN:
- strcpy( species_buff, "Spriggan" );
- break;
- case SP_MINOTAUR:
- strcpy( species_buff, "Minotaur" );
- break;
- case SP_DEMONSPAWN:
- strcpy( species_buff, (adj) ? "Demonic" : "Demonspawn" );
- break;
- case SP_GHOUL:
- strcpy( species_buff, (adj) ? "Ghoulish" : "Ghoul" );
- break;
- case SP_KENKU:
- strcpy( species_buff, "Kenku" );
- break;
- case SP_MERFOLK:
- strcpy( species_buff, (adj) ? "Merfolkian" : "Merfolk" );
- break;
- case SP_VAMPIRE:
- strcpy( species_buff, "Vampire" );
- break;
- default:
- strcpy( species_buff, (adj) ? "Yakish" : "Yak" );
+ res = (adj ? "Orcish" : genus ? "Orc" : "Hill Orc");
break;
+
+ case SP_GNOME: res = (adj ? "Gnomish" : "Gnome"); break;
+ case SP_OGRE: res = (adj ? "Ogreish" : "Ogre"); break;
+ case SP_TROLL: res = (adj ? "Trollish" : "Troll"); break;
+ case SP_DEMIGOD: res = (adj ? "Divine" : "Demigod"); break;
+ case SP_DEMONSPAWN: res = (adj ? "Demonic" : "Demonspawn" ); break;
+ case SP_GHOUL: res = (adj ? "Ghoulish" : "Ghoul"); break;
+ case SP_MERFOLK: res = (adj ? "Merfolkian" : "Merfolk"); break;
+ default: res = (adj ? "Yakish" : "Yak"); break;
}
}
-
- if (!cap)
- strlwr( species_buff );
-
- return (species_buff);
-} // end species_name()
+ return res;
+}
bool player_res_corrosion(bool calc_unid)
{
@@ -3803,12 +3673,11 @@ bool player_has_spell( int spell )
return you.has_spell(spell);
}
-int species_exp_mod(char species)
+static int species_exp_mod(species_type species)
{
-
- if (player_genus(GENPC_DRACONIAN))
+ if (player_genus(GENPC_DRACONIAN, species))
return 14;
- else if (player_genus(GENPC_DWARVEN))
+ else if (player_genus(GENPC_DWARVEN, species))
return 13;
{
switch (species)
@@ -3944,8 +3813,7 @@ unsigned long exp_needed(int lev)
if (lev < 13)
{
lev -= 4;
- level = 10 + 10 * lev
- + 30 * (static_cast<int>(pow( 2.0, lev + 1 )));
+ level = 10 + 10 * lev + 30 * (2 << lev);
}
else
{
@@ -4404,8 +4272,8 @@ int get_species_index_by_name( const char *name )
for (i = SP_HUMAN; i < NUM_SPECIES; i++)
{
- std::string lowered_species =
- lowercase_string( species_name( i, 0, false, false, false ) );
+ const std::string lowered_species =
+ lowercase_string(species_name(static_cast<species_type>(i),0));
pos = lowered_species.find( lowered_buff );
if (pos != std::string::npos)
{
diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h
index c822f6bfdc..98a3217740 100644
--- a/crawl-ref/source/player.h
+++ b/crawl-ref/source/player.h
@@ -76,8 +76,8 @@ bool wearing_amulet(char which_am, bool calc_unid = true);
/* ***********************************************************************
* called from: acr - chardump - describe - newgame - view
* *********************************************************************** */
-std::string species_name( int speci, int level, bool genus = false,
- bool adj = false, bool cap = true );
+std::string species_name( species_type speci, int level,
+ bool genus = false, bool adj = false);
int str_to_species(const std::string &species);
/* ***********************************************************************
@@ -311,8 +311,8 @@ void redraw_skill(const std::string &your_name, const std::string &class_name);
* called from: ability - fight - item_use - mutation - newgame - spells0 -
* transfor
* *********************************************************************** */
-bool player_genus( unsigned char which_genus,
- unsigned char species = SP_UNKNOWN );
+bool player_genus( genus_type which_genus,
+ species_type species = SP_UNKNOWN );
bool you_can_wear( int eq, bool special_armour = false );
bool you_tran_can_wear( int eq, bool check_mutation = false );
diff --git a/crawl-ref/source/skills2.cc b/crawl-ref/source/skills2.cc
index 0778120d11..d0e17e2840 100644
--- a/crawl-ref/source/skills2.cc
+++ b/crawl-ref/source/skills2.cc
@@ -2067,7 +2067,7 @@ std::string skill_title( unsigned char best_skill, unsigned char skill_lev,
{
// need species name
snprintf( title_buff, sizeof(title_buff), tempstr,
- species_name(species, 0, true,
+ species_name(static_cast<species_type>(species), 0, true,
(ptr == tempstr
&& best_skill != SK_NECROMANCY)).c_str() );
// The above code only capitalises start-of-string racenames