summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-03 11:48:10 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-03 11:48:10 +0000
commit64c579b2ffaaff8ff6aa49fac6520218d09ac559 (patch)
tree9d950cebf330b3d58173b954343da56d5f678a5e /crawl-ref
parentc64f7db0025aeb9d0c0392271fb011053ff5d6cf (diff)
downloadcrawl-ref-64c579b2ffaaff8ff6aa49fac6520218d09ac559.tar.gz
crawl-ref-64c579b2ffaaff8ff6aa49fac6520218d09ac559.zip
Reintroduce parts of the old get_species_by_index to code to fix
misbehaviuor with wizmode-defined ghosts (doesn't really work anyway) and (hopefully) the highscores. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3507 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/debug.cc24
-rw-r--r--crawl-ref/source/hiscores.cc2
-rw-r--r--crawl-ref/source/newgame.cc78
-rw-r--r--crawl-ref/source/newgame.h8
4 files changed, 99 insertions, 13 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 8fdbb4b56e..441b4105bc 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -425,7 +425,7 @@ void create_spec_monster_name(int x, int y)
return;
}
- const bool force_place = x != -1 && y != -1;
+ const bool force_place = (x != -1 && y != -1);
if (x == -1)
x = you.x_pos;
if (y == -1)
@@ -473,14 +473,28 @@ void create_spec_monster_name(int x, int y)
ghost.name = "John Doe";
- char class_str[80];
+ char input_str[80];
+ mpr( "Make player ghost which species? ", MSGCH_PROMPT );
+ get_input_line( input_str, sizeof( input_str ) );
+
+ int sp_id = get_species_by_abbrev(input_str);
+ if (sp_id == -1)
+ sp_id = str_to_species(input_str);
+
+ if (sp_id == -1)
+ {
+ mpr("No such species, making it Human.");
+ sp_id = SP_HUMAN;
+ }
+ ghost.species = static_cast<species_type>(sp_id);
+
mpr( "Make player ghost which class? ", MSGCH_PROMPT );
- get_input_line( class_str, sizeof( class_str ) );
+ get_input_line( input_str, sizeof( input_str ) );
- int class_id = get_class_index_by_abbrev(class_str);
+ int class_id = get_class_by_abbrev(input_str);
if (class_id == -1)
- class_id = get_class_index_by_name(class_str);
+ class_id = get_class_by_name(input_str);
if (class_id == -1)
{
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index db21884def..fee4dd2417 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -612,7 +612,7 @@ void scorefile_entry::init_with_fields()
uid = fields->int_field("uid");
race = str_to_species(fields->str_field("race"));
- cls = get_class_index_by_name(fields->str_field("cls").c_str());
+ cls = get_class_by_name(fields->str_field("cls").c_str());
lvl = fields->int_field("xl");
diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc
index 0f09f78da9..4ce2d0ad6c 100644
--- a/crawl-ref/source/newgame.cc
+++ b/crawl-ref/source/newgame.cc
@@ -319,6 +319,23 @@ const char *get_species_abbrev( int which_species )
return (Species_Abbrev_List[ which_species ]);
}
+// needed for debug.cc and hiscores.cc
+int get_species_by_abbrev( const char *abbrev )
+{
+ int i;
+ COMPILE_CHECK(ARRAYSIZE(Species_Abbrev_List) == NUM_SPECIES, c1);
+ for (i = SP_HUMAN; i < NUM_SPECIES; i++)
+ {
+ if (tolower( abbrev[0] ) == tolower( Species_Abbrev_List[i][0] )
+ && tolower( abbrev[1] ) == tolower( Species_Abbrev_List[i][1] ))
+ {
+ break;
+ }
+ }
+
+ return ((i < NUM_SPECIES) ? i : -1);
+}
+
static const char * Class_Abbrev_List[ NUM_JOBS ] =
{ "Fi", "Wz", "Pr", "Th", "Gl", "Ne", "Pa", "As", "Be", "Hu",
"Cj", "En", "FE", "IE", "Su", "AE", "EE", "Cr", "DK", "VM",
@@ -335,13 +352,12 @@ static const char * Class_Name_List[ NUM_JOBS ] =
int get_class_index_by_abbrev( const char *abbrev )
{
COMPILE_CHECK(ARRAYSIZE(Class_Abbrev_List) == NUM_JOBS, c1);
- COMPILE_CHECK(ARRAYSIZE(Class_Name_List) == NUM_JOBS, c2);
+ unsigned int job;
for (unsigned int i = 0; i < ARRAYSIZE(old_jobs_order); i++)
{
- const job_type job
- = (Options.use_old_selection_order ? old_jobs_order[i]
- : new_jobs_order[i]);
+ job = (Options.use_old_selection_order ? old_jobs_order[i]
+ : new_jobs_order[i]);
if (tolower( abbrev[0] ) == tolower( Class_Abbrev_List[job][0] )
&& tolower( abbrev[1] ) == tolower( Class_Abbrev_List[job][1] ))
@@ -360,8 +376,26 @@ const char *get_class_abbrev( int which_job )
return (Class_Abbrev_List[ which_job ]);
}
+int get_class_by_abbrev( const char *abbrev )
+{
+ int i;
+
+ for (i = 0; i < NUM_JOBS; i++)
+ {
+ if (tolower( abbrev[0] ) == tolower( Class_Abbrev_List[i][0] )
+ && tolower( abbrev[1] ) == tolower( Class_Abbrev_List[i][1] ))
+ {
+ break;
+ }
+ }
+
+ return ((i < NUM_JOBS) ? i : -1);
+}
+
int get_class_index_by_name( const char *name )
{
+ COMPILE_CHECK(ARRAYSIZE(Class_Name_List) == NUM_JOBS, c1);
+
char *ptr;
char lowered_buff[80];
char lowered_class[80];
@@ -370,11 +404,12 @@ int get_class_index_by_name( const char *name )
strlwr( lowered_buff );
int cl = -1;
+ unsigned int job;
for (unsigned int i = 0; i < ARRAYSIZE(old_jobs_order); i++)
{
- const int job = (Options.use_old_selection_order ? old_jobs_order[i]
- : new_jobs_order[i]);
-
+ job = (Options.use_old_selection_order ? old_jobs_order[i]
+ : new_jobs_order[i]);
+
strncpy( lowered_class, Class_Name_List[job], sizeof( lowered_class ) );
strlwr( lowered_class );
@@ -397,6 +432,35 @@ const char *get_class_name( int which_job )
return (Class_Name_List[ which_job ]);
}
+int get_class_by_name( const char *name )
+{
+ int i;
+ int cl = -1;
+
+ char *ptr;
+ char lowered_buff[80];
+ char lowered_class[80];
+
+ strncpy( lowered_buff, name, sizeof( lowered_buff ) );
+ strlwr( lowered_buff );
+
+ for (i = 0; i < NUM_JOBS; i++)
+ {
+ strncpy( lowered_class, Class_Name_List[i], sizeof( lowered_class ) );
+ strlwr( lowered_class );
+
+ ptr = strstr( lowered_class, lowered_buff );
+ if (ptr != NULL)
+ {
+ cl = i;
+ if (ptr == lowered_class) // prefix takes preference
+ break;
+ }
+ }
+
+ return (cl);
+}
+
static void reset_newgame_options(void)
{
ng_race = ng_cls = 0;
diff --git a/crawl-ref/source/newgame.h b/crawl-ref/source/newgame.h
index c3bf9f6fce..6fa34e55a1 100644
--- a/crawl-ref/source/newgame.h
+++ b/crawl-ref/source/newgame.h
@@ -26,6 +26,14 @@ const char *get_class_abbrev( int which_job );
const char *get_class_name( int which_job );
/* ***********************************************************************
+ * called from: debug and hiscores
+ * *********************************************************************** */
+int get_species_by_abbrev( const char *abbrev );
+int get_species_by_name( const char *name );
+int get_class_by_abbrev( const char *abbrev );
+int get_class_by_name( const char *name );
+
+/* ***********************************************************************
* called from: acr
* *********************************************************************** */
bool new_game();