summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2006-10-06 12:08:14 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2006-10-06 12:08:14 +0000
commit6cc7c661ff9c255e2a5fe0a76cacb2e5f8e8c750 (patch)
tree4cc197e9c11996e2e9a3cfd91ec76f124cfb2676
parent98fffcc251ff707b93575955d65f466ae6d37248 (diff)
downloadcrawl-ref-6cc7c661ff9c255e2a5fe0a76cacb2e5f8e8c750.tar.gz
crawl-ref-6cc7c661ff9c255e2a5fe0a76cacb2e5f8e8c750.zip
Started consolidating branch-name stuff into a single function.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup@211 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/Kills.cc73
-rw-r--r--crawl-ref/source/files.cc1
-rw-r--r--crawl-ref/source/hiscores.cc140
-rw-r--r--crawl-ref/source/misc.cc100
-rw-r--r--crawl-ref/source/misc.h6
-rw-r--r--crawl-ref/source/notes.cc14
6 files changed, 129 insertions, 205 deletions
diff --git a/crawl-ref/source/Kills.cc b/crawl-ref/source/Kills.cc
index 0dfe4376c1..39b5c138c3 100644
--- a/crawl-ref/source/Kills.cc
+++ b/crawl-ref/source/Kills.cc
@@ -6,16 +6,19 @@
* Modified for Crawl Reference by $Author$ on $Date$
*/
#include "AppHdr.h"
+
+#include <algorithm>
+
#include "chardump.h"
#include "describe.h"
#include "mon-util.h"
#include "files.h"
#include "itemname.h"
+#include "misc.h"
#include "travel.h"
#include "tags.h"
#include "Kills.h"
#include "clua.h"
-#include <algorithm>
#define KILLS_MAJOR_VERSION 4
#define KILLS_MINOR_VERSION 1
@@ -26,7 +29,7 @@ static void kill_lua_filltable(std::vector<kill_exp> &v);
unsigned short get_packed_place( unsigned char branch, int subdepth,
- char level_type )
+ char level_type )
{
unsigned short place = (unsigned short)
( (branch << 8) | subdepth );
@@ -297,71 +300,7 @@ long Kills::get_kills(std::vector<kill_exp> &all_kills) const
// describe places would be nice.
std::string short_place_name(unsigned short place)
{
- unsigned char branch = (unsigned char) ((place >> 8) & 0xFF);
- int lev = place & 0xFF;
-
- const char *s;
- bool level_num = false;
- if (lev == 0xFF)
- {
- switch (branch)
- {
- case LEVEL_ABYSS:
- s = "Abyss";
- break;
- case LEVEL_PANDEMONIUM:
- s = "Pan";
- break;
- case LEVEL_LABYRINTH:
- s = "Lab";
- break;
- default:
- s = "Buggy Badlands";
- break;
- }
- }
- else
- {
- switch (branch)
- {
- case BRANCH_VESTIBULE_OF_HELL:
- s = "Hell";
- break;
- case BRANCH_HALL_OF_BLADES:
- s = "Blade";
- break;
- case BRANCH_ECUMENICAL_TEMPLE:
- s = "Temple";
- break;
- default:
- level_num = true;
- s = (branch == BRANCH_DIS) ? "Dis:" :
- (branch == BRANCH_GEHENNA) ? "Geh:" :
- (branch == BRANCH_COCYTUS) ? "Coc:" :
- (branch == BRANCH_TARTARUS) ? "Tar:" :
- (branch == BRANCH_ORCISH_MINES) ? "Orc:" :
- (branch == BRANCH_HIVE) ? "Hive:" :
- (branch == BRANCH_LAIR) ? "Lair:" :
- (branch == BRANCH_SLIME_PITS) ? "Slime:" :
- (branch == BRANCH_VAULTS) ? "Vault:" :
- (branch == BRANCH_CRYPT) ? "Crypt:" :
- (branch == BRANCH_HALL_OF_ZOT) ? "Zot:" :
- (branch == BRANCH_SNAKE_PIT) ? "Snake:" :
- (branch == BRANCH_ELVEN_HALLS) ? "Elf:" :
- (branch == BRANCH_TOMB) ? "Tomb:" :
- (branch == BRANCH_SWAMP) ? "Swamp:" : "D:";
- break;
- }
- }
-
- std::string pl = s;
- if (level_num)
- {
- char buf[20];
- snprintf(buf, sizeof buf, "%d", lev);
- pl += buf;
- }
- return pl;
+ return place_name( place, false, true );
}
void Kills::save(FILE *file) const
diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc
index 2194be911c..0dc7ce62e1 100644
--- a/crawl-ref/source/files.cc
+++ b/crawl-ref/source/files.cc
@@ -26,7 +26,6 @@
#include "files.h"
#include "version.h"
-#include <algorithm>
#include <string.h>
#include <string>
#include <stdlib.h>
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index bc51a058d9..787888c832 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -37,6 +37,7 @@
#include "hiscores.h"
#include "itemname.h"
+#include "misc.h"
#include "mon-util.h"
#include "player.h"
#include "religion.h"
@@ -468,54 +469,9 @@ void hiscores_format_single(char *buf, struct scorefile_entry &se)
if (se.death_type != KILLED_BY_LEAVING && se.death_type != KILLED_BY_WINNING)
{
- if (se.level_type == LEVEL_ABYSS)
- {
- strcat(buf, " (Abyss)");
- return;
- }
- else if (se.level_type == LEVEL_PANDEMONIUM)
- {
- strcat(buf, " (Pan)");
- return;
- }
- else if (se.level_type == LEVEL_LABYRINTH)
- {
- strcat(buf, " (Lab)");
- return;
- }
- else if (se.branch == BRANCH_VESTIBULE_OF_HELL)
- {
- strcat(buf, " (Hell)"); // Gate? Vest?
- return;
- }
- else if (se.branch == BRANCH_HALL_OF_BLADES)
- {
- strcat(buf, " (Blade)");
- return;
- }
- else if (se.branch == BRANCH_ECUMENICAL_TEMPLE)
- {
- strcat(buf, " (Temple)");
- return;
- }
-
- snprintf( scratch, sizeof(scratch), " (%s%d)",
- (se.branch == BRANCH_DIS) ? "Dis " :
- (se.branch == BRANCH_GEHENNA) ? "Geh " :
- (se.branch == BRANCH_COCYTUS) ? "Coc " :
- (se.branch == BRANCH_TARTARUS) ? "Tar " :
- (se.branch == BRANCH_ORCISH_MINES) ? "Orc " :
- (se.branch == BRANCH_HIVE) ? "Hive " :
- (se.branch == BRANCH_LAIR) ? "Lair " :
- (se.branch == BRANCH_SLIME_PITS) ? "Slime " :
- (se.branch == BRANCH_VAULTS) ? "Vault " :
- (se.branch == BRANCH_CRYPT) ? "Crypt " :
- (se.branch == BRANCH_HALL_OF_ZOT) ? "Zot " :
- (se.branch == BRANCH_SNAKE_PIT) ? "Snake " :
- (se.branch == BRANCH_ELVEN_HALLS) ? "Elf " :
- (se.branch == BRANCH_TOMB) ? "Tomb " :
- (se.branch == BRANCH_SWAMP) ? "Swamp " : "DLv ",
- se.dlvl );
+ snprintf( scratch, sizeof scratch, " (%s)",
+ place_name(get_packed_place(se.branch,se.dlvl,se.level_type),
+ false, true).c_str());
strcat( buf, scratch );
} // endif - killed by winning
@@ -967,84 +923,18 @@ int hiscores_format_single_long( char *buf, struct scorefile_entry &se,
if (verbose && se.death_type != KILLED_BY_QUITTING)
strcat( buf, "..." );
- if (se.level_type == LEVEL_ABYSS)
- strcat( buf, " in the Abyss" );
- else if (se.level_type == LEVEL_PANDEMONIUM)
- strcat( buf, " in Pandemonium" );
- else if (se.level_type == LEVEL_LABYRINTH)
- strcat( buf, " in a labyrinth" );
- else
- {
- switch (se.branch)
- {
- case BRANCH_ECUMENICAL_TEMPLE:
- strcat( buf, " in the Ecumenical Temple" );
- break;
- case BRANCH_HALL_OF_BLADES:
- strcat( buf, " in the Hall of Blades" );
- break;
- case BRANCH_VESTIBULE_OF_HELL:
- strcat( buf, " in the Vestibule" );
- break;
-
- case BRANCH_DIS:
- strcat( buf, " on Dis" );
- break;
- case BRANCH_GEHENNA:
- strcat( buf, " on Gehenna" );
- break;
- case BRANCH_COCYTUS:
- strcat( buf, " on Cocytus" );
- break;
- case BRANCH_TARTARUS:
- strcat( buf, " on Tartarus" );
- break;
- case BRANCH_ORCISH_MINES:
- strcat( buf, " on Orcish Mines" );
- break;
- case BRANCH_HIVE:
- strcat( buf, " on Hive" );
- break;
- case BRANCH_LAIR:
- strcat( buf, " on Lair" );
- break;
- case BRANCH_SLIME_PITS:
- strcat( buf, " on Slime Pits" );
- break;
- case BRANCH_VAULTS:
- strcat( buf, " on Vault" );
- break;
- case BRANCH_CRYPT:
- strcat( buf, " on Crypt" );
- break;
- case BRANCH_HALL_OF_ZOT:
- strcat( buf, " on Hall of Zot" );
- break;
- case BRANCH_SNAKE_PIT:
- strcat( buf, " on Snake Pit" );
- break;
- case BRANCH_ELVEN_HALLS:
- strcat( buf, " on Elven Halls" );
- break;
- case BRANCH_TOMB:
- strcat( buf, " on Tomb" );
- break;
- case BRANCH_SWAMP:
- strcat( buf, " on Swamp" );
- break;
- case BRANCH_MAIN_DUNGEON:
- strcat( buf, " on Dungeon" );
- break;
- }
+ // where did we die?
+ std::string placename =
+ place_name(get_packed_place(se.branch, se.dlvl, se.level_type),
+ true, true);
- if (se.branch != BRANCH_VESTIBULE_OF_HELL
- && se.branch != BRANCH_ECUMENICAL_TEMPLE
- && se.branch != BRANCH_HALL_OF_BLADES)
- {
- snprintf( scratch, sizeof(scratch), " Level %d", se.dlvl );
- strcat( buf, scratch );
- }
- }
+ // add appropriate prefix
+ if (placename.find("Level") == 0)
+ strcat( buf, " on ");
+ else
+ strcat( buf, " in ");
+
+ strcat(buf, placename.c_str() );
if (verbose && se.death_time
&& !hiscore_same_day( se.birth_time, se.death_time ))
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 833311f09e..e973d26e9d 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -2042,3 +2042,103 @@ bool i_feel_safe()
}
return true;
}
+
+std::string place_name( unsigned short place, bool long_name,
+ bool include_number ) {
+
+ unsigned char branch = (unsigned char) ((place >> 8) & 0xFF);
+ int lev = place & 0xFF;
+
+ std::string result;
+ if (lev == 0xFF)
+ {
+ switch (branch)
+ {
+ case LEVEL_ABYSS:
+ return ( long_name ? "The Abyss" : "Abyss" );
+ case LEVEL_PANDEMONIUM:
+ return ( long_name ? "Pandemonium" : "Pan" );
+ case LEVEL_LABYRINTH:
+ return ( long_name ? "a Labyrinth" : "Lab" );
+ default:
+ return ( long_name ? "Buggy Badlands" : "Bug" );
+ }
+ }
+ else
+ {
+ switch (branch)
+ {
+ case BRANCH_VESTIBULE_OF_HELL:
+ return ( long_name ? "The Vestibule of Hell" : "Hell" );
+ case BRANCH_HALL_OF_BLADES:
+ return ( long_name ? "The Hall of Blades" : "Blade" );
+ case BRANCH_ECUMENICAL_TEMPLE:
+ return ( long_name ? "The Ecumenical Temple" : "Temple" );
+ case BRANCH_DIS:
+ result = ( long_name ? "The Iron City of Dis" : "Dis");
+ break;
+ case BRANCH_GEHENNA:
+ result = ( long_name ? "Gehenna" : "Geh" );
+ break;
+ case BRANCH_COCYTUS:
+ result = ( long_name ? "Cocytus" : "Coc" );
+ break;
+ case BRANCH_TARTARUS:
+ result = ( long_name ? "Tartarus" : "Tar" );
+ break;
+ case BRANCH_ORCISH_MINES:
+ result = ( long_name ? "The Orcish Mines" : "Orc" );
+ break;
+ case BRANCH_HIVE:
+ result = ( long_name ? "The Hive" : "Hive" );
+ break;
+ case BRANCH_LAIR:
+ result = ( long_name ? "The Lair" : "Lair" );
+ break;
+ case BRANCH_SLIME_PITS:
+ result = ( long_name ? "The Slime Pits" : "Slime" );
+ break;
+ case BRANCH_VAULTS:
+ result = ( long_name ? "The Vaults" : "Vault" );
+ break;
+ case BRANCH_CRYPT:
+ result = ( long_name ? "The Crypt" : "Crypt" );
+ break;
+ case BRANCH_HALL_OF_ZOT:
+ result = ( long_name ? "The Hall of Zot" : "Zot" );
+ break;
+ case BRANCH_SNAKE_PIT:
+ result = ( long_name ? "The Snake Pit" : "Snake" );
+ break;
+ case BRANCH_ELVEN_HALLS:
+ result = ( long_name ? "The Elven Halls" : "Elf" );
+ break;
+ case BRANCH_TOMB:
+ result = ( long_name ? "The Tomb" : "Tomb" );
+ break;
+ case BRANCH_SWAMP:
+ result = ( long_name ? "The Swamp" : "Swamp" );
+ break;
+ default:
+ result = ( long_name ? "The Dungeon" : "D" );
+ break;
+ }
+ }
+
+ if ( include_number ) {
+ char buf[200];
+ if ( long_name ) {
+ // decapitalize 'the'
+ if ( result.find("The") == 0 )
+ result[0] = 't';
+ snprintf( buf, sizeof buf, "Level %d of %s",
+ lev, result.c_str() );
+ }
+ else {
+ snprintf( buf, sizeof buf, "%s:%d",
+ result.c_str(), lev );
+ }
+ result = buf;
+ }
+ return result;
+}
diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h
index 7bab0e7ac9..7b294b6bcb 100644
--- a/crawl-ref/source/misc.h
+++ b/crawl-ref/source/misc.h
@@ -147,10 +147,8 @@ const char *grid_item_destruction_message( unsigned char grid );
void curare_hits_player(int agent, int degree);
-// last updated 24aug2006 {hp}
-/* ***********************************************************************
- * called from: items
- * *********************************************************************** */
bool i_feel_safe();
+std::string place_name( unsigned short place, bool long_name,
+ bool include_number );
#endif
diff --git a/crawl-ref/source/notes.cc b/crawl-ref/source/notes.cc
index d3c3970e20..03175480b5 100644
--- a/crawl-ref/source/notes.cc
+++ b/crawl-ref/source/notes.cc
@@ -176,9 +176,7 @@ static bool is_noteworthy( const Note& note ) {
if ( note.type == NOTE_LEARN_SPELL && Options.note_all_spells )
return true;
-
- unsigned i;
- for ( i = 0; i < note_list.size(); ++i ) {
+ for ( unsigned i = 0; i < note_list.size(); ++i ) {
if ( note_list[i].type != note.type )
continue;
const Note& rnote( note_list[i] );
@@ -209,12 +207,12 @@ static bool is_noteworthy( const Note& note ) {
return false;
break;
default:
- mpr("Buggy note passed: unknown note type");
- // Return now, rather than give a "Buggy note passed" message
- // for each note of the matching type in the note list.
- return true;
+ mpr("Buggy note passed: unknown note type");
+ // Return now, rather than give a "Buggy note passed" message
+ // for each note of the matching type in the note list.
+ return true;
+ }
}
- } // for ( i = 0; i < note_list.size(); ++i )
return true;
}