summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-09 09:35:50 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-11-09 09:35:50 +0000
commit785c184350a4f45e76499b78fbc16d6eaee014cd (patch)
treee2e6051448b60f1e4f8baf0bbbaf64cac5af8c96
parent434bf1751235285cf23ed92c3109af48dc8caf8f (diff)
downloadcrawl-ref-785c184350a4f45e76499b78fbc16d6eaee014cd.tar.gz
crawl-ref-785c184350a4f45e76499b78fbc16d6eaee014cd.zip
Removed another unnecessary duplicate place name function.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup@373 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/Kills.cc27
-rw-r--r--crawl-ref/source/Kills.h7
-rw-r--r--crawl-ref/source/chardump.cc67
-rw-r--r--crawl-ref/source/items.cc2
-rw-r--r--crawl-ref/source/misc.cc51
-rw-r--r--crawl-ref/source/misc.h21
-rw-r--r--crawl-ref/source/notes.cc4
-rw-r--r--crawl-ref/source/stash.cc134
-rw-r--r--crawl-ref/source/stash.h12
-rw-r--r--crawl-ref/source/travel.h2
10 files changed, 86 insertions, 241 deletions
diff --git a/crawl-ref/source/Kills.cc b/crawl-ref/source/Kills.cc
index 5635cab660..bd1936db50 100644
--- a/crawl-ref/source/Kills.cc
+++ b/crawl-ref/source/Kills.cc
@@ -27,25 +27,6 @@
static void kill_lua_filltable(std::vector<kill_exp> &v);
#endif
-
-unsigned short get_packed_place( unsigned char branch, int subdepth,
- char level_type )
-{
- unsigned short place = (unsigned short)
- ( (branch << 8) | (subdepth & 0xFF) );
- if (level_type == LEVEL_ABYSS || level_type == LEVEL_PANDEMONIUM
- || level_type == LEVEL_LABYRINTH)
- place = (unsigned short) ( (level_type << 8) | 0xFF );
- return place;
-}
-
-unsigned short get_packed_place()
-{
- return get_packed_place( you.where_are_you,
- subdungeon_depth(you.where_are_you, you.your_level),
- you.level_type );
-}
-
///////////////////////////////////////////////////////////////////////////
// KillMaster
//
@@ -293,14 +274,6 @@ long Kills::get_kills(std::vector<kill_exp> &all_kills) const
return (count);
}
-// Takes a packed 'place' and returns a compact stringified place name.
-// XXX: This is done in several other places; a unified function to
-// describe places would be nice.
-std::string short_place_name(unsigned short place)
-{
- return place_name( place, false, true );
-}
-
void Kills::save(FILE *file) const
{
// How many kill records do we have?
diff --git a/crawl-ref/source/Kills.h b/crawl-ref/source/Kills.h
index 074ea79a6d..f3ada4fe40 100644
--- a/crawl-ref/source/Kills.h
+++ b/crawl-ref/source/Kills.h
@@ -169,13 +169,6 @@ private:
const;
};
-unsigned short get_packed_place();
-
-unsigned short get_packed_place( unsigned char branch, int subdepth,
- char level_type );
-
-std::string short_place_name(unsigned short place);
-
enum KILL_DUMP_OPTIONS
{
KDO_NO_PLACES, // Don't dump places at all
diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc
index fa3c04aea2..4bb87f04e5 100644
--- a/crawl-ref/source/chardump.cc
+++ b/crawl-ref/source/chardump.cc
@@ -41,6 +41,7 @@
#include "itemprop.h"
#include "items.h"
#include "macro.h"
+#include "misc.h"
#include "mutation.h"
#include "notes.h"
#include "output.h"
@@ -544,68 +545,12 @@ static void sdump_notes(const std::string &, std::string& text)
//---------------------------------------------------------------
static void sdump_location(const std::string &, std::string & text)
{
- if (you.level_type != LEVEL_DUNGEON || you.your_level != -1)
- text += "You are ";
-
- if (you.level_type == LEVEL_PANDEMONIUM)
- text += "in Pandemonium";
- else if (you.level_type == LEVEL_ABYSS)
- text += "in the Abyss";
- else if (you.level_type == LEVEL_LABYRINTH)
- text += "in a labyrinth";
- else if (you.where_are_you == BRANCH_DIS)
- text += "in Dis";
- else if (you.where_are_you == BRANCH_GEHENNA)
- text += "in Gehenna";
- else if (you.where_are_you == BRANCH_VESTIBULE_OF_HELL)
- text += "in the Vestibule of Hell";
- else if (you.where_are_you == BRANCH_COCYTUS)
- text += "in Cocytus";
- else if (you.where_are_you == BRANCH_TARTARUS)
- text += "in Tartarus";
- else if (you.where_are_you == BRANCH_INFERNO)
- text += "in the Inferno";
- else if (you.where_are_you == BRANCH_THE_PIT)
- text += "in the Pit";
- else if (you.where_are_you == BRANCH_ORCISH_MINES)
- text += "in the Mines";
- else if (you.where_are_you == BRANCH_HIVE)
- text += "in the Hive";
- else if (you.where_are_you == BRANCH_LAIR)
- text += "in the Lair";
- else if (you.where_are_you == BRANCH_SLIME_PITS)
- text += "in the Slime Pits";
- else if (you.where_are_you == BRANCH_VAULTS)
- text += "in the Vaults";
- else if (you.where_are_you == BRANCH_CRYPT)
- text += "in the Crypt";
- else if (you.where_are_you == BRANCH_HALL_OF_BLADES)
- text += "in the Hall of Blades";
- else if (you.where_are_you == BRANCH_HALL_OF_ZOT)
- text += "in the Hall of Zot";
- else if (you.where_are_you == BRANCH_ECUMENICAL_TEMPLE)
- text += "in the Ecumenical Temple";
- else if (you.where_are_you == BRANCH_SNAKE_PIT)
- text += "in the Snake Pit";
- else if (you.where_are_you == BRANCH_ELVEN_HALLS)
- text += "in the Elven Halls";
- else if (you.where_are_you == BRANCH_TOMB)
- text += "in the Tomb";
- else if (you.where_are_you == BRANCH_SWAMP)
- text += "in the Swamp";
+ if (you.your_level == -1
+ && you.where_are_you == BRANCH_MAIN_DUNGEON
+ && you.level_type == LEVEL_DUNGEON)
+ text += "You escaped";
else
- {
- if (you.your_level == -1)
- text += "You escaped";
- else
- {
- text += "on level ";
-
- char st_prn[20];
- itoa(you.your_level + 1, st_prn, 10);
- text += st_prn;
- }
- }
+ text += "You are " + prep_branch_level_name();
text += ".";
text += "\n";
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index 16c1ab824c..320de6c818 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -990,7 +990,7 @@ static std::string origin_monster_desc(const item_def &item)
static std::string origin_place_desc(const item_def &item)
{
- return prep_branch_level_name(item.orig_place);
+ return prep_branch_level_name(item.orig_place);
}
bool is_rune(const item_def &item)
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 14ee373ddb..48aed3057a 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -2020,6 +2020,31 @@ bool i_feel_safe()
return true;
}
+// Do not attempt to use level_id if level_type != LEVEL_DUNGEON
+std::string short_place_name(level_id id)
+{
+ return short_place_name(
+ get_packed_place(id.branch, id.depth, LEVEL_DUNGEON));
+}
+
+unsigned short get_packed_place( unsigned char branch, int subdepth,
+ char level_type )
+{
+ unsigned short place = (unsigned short)
+ ( (branch << 8) | (subdepth & 0xFF) );
+ if (level_type == LEVEL_ABYSS || level_type == LEVEL_PANDEMONIUM
+ || level_type == LEVEL_LABYRINTH)
+ place = (unsigned short) ( (level_type << 8) | 0xFF );
+ return place;
+}
+
+unsigned short get_packed_place()
+{
+ return get_packed_place( you.where_are_you,
+ subdungeon_depth(you.where_are_you, you.your_level),
+ you.level_type );
+}
+
std::string place_name( unsigned short place, bool long_name,
bool include_number ) {
@@ -2124,6 +2149,32 @@ std::string place_name( unsigned short place, bool long_name,
return result;
}
+// Takes a packed 'place' and returns a compact stringified place name.
+// XXX: This is done in several other places; a unified function to
+// describe places would be nice.
+std::string short_place_name(unsigned short place)
+{
+ return place_name( place, false, true );
+}
+
+// Prepositional form of branch level name. For example, "in the
+// Abyss" or "on level 3 of the Main Dungeon".
+std::string prep_branch_level_name(unsigned short packed_place)
+{
+ std::string place = place_name( packed_place, true, true );
+ if (place.length() && place != "Pandemonium")
+ place[0] = tolower(place[0]);
+ return (place.find("level") == 0?
+ "on " + place
+ : "in " + place);
+}
+
+// Use current branch and depth
+std::string prep_branch_level_name()
+{
+ return prep_branch_level_name( get_packed_place() );
+}
+
int absdungeon_depth(unsigned char branch, int subdepth)
{
int realdepth = subdepth - 1;
diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h
index a1973791a4..a11d043940 100644
--- a/crawl-ref/source/misc.h
+++ b/crawl-ref/source/misc.h
@@ -16,6 +16,7 @@
#include "externs.h"
+#include "travel.h"
// last updated 08jan2001 {gdl}
/* ***********************************************************************
@@ -149,10 +150,30 @@ void curare_hits_player(int agent, int degree);
bool i_feel_safe();
+//////////////////////////////////////////////////////////////////////
+// Places and names
+//
+unsigned short get_packed_place();
+
+unsigned short get_packed_place( unsigned char branch, int subdepth,
+ char level_type );
+
+std::string short_place_name(unsigned short place);
+std::string short_place_name(level_id id);
std::string place_name( unsigned short place, bool long_name = false,
bool include_number = true );
+// Prepositional form of branch level name. For example, "in the
+// Abyss" or "on level 3 of the Main Dungeon".
+std::string prep_branch_level_name(unsigned short packed_place);
+std::string prep_branch_level_name();
+
+// Get displayable depth in the current branch, given the absolute
+// depth.
int subdungeon_depth(unsigned char branch, int depth);
+
+// Get absolute depth given the displayable depth in the branch.
int absdungeon_depth(unsigned char branch, int subdepth);
+//////////////////////////////////////////////////////////////////////
#endif
diff --git a/crawl-ref/source/notes.cc b/crawl-ref/source/notes.cc
index 0efe9686bc..0af29ec998 100644
--- a/crawl-ref/source/notes.cc
+++ b/crawl-ref/source/notes.cc
@@ -10,12 +10,12 @@
#include "files.h"
#include "Kills.h"
#include "message.h"
+#include "misc.h"
#include "mon-pick.h"
#include "mutation.h"
#include "religion.h"
#include "skills2.h"
#include "spl-util.h"
-#include "stash.h"
#define NOTES_VERSION_NUMBER 1001
@@ -251,7 +251,7 @@ std::string describe_note( const Note& note ) {
break;
case NOTE_DUNGEON_LEVEL_CHANGE:
snprintf(buf, sizeof buf, "Entered %s",
- branch_level_name(note.packed_place).c_str());
+ place_name(note.packed_place, true, true).c_str());
break;
case NOTE_LEARN_SPELL:
snprintf(buf, sizeof buf, "Learned a level %d spell: %s",
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc
index 0f3001452f..86c5b96e40 100644
--- a/crawl-ref/source/stash.cc
+++ b/crawl-ref/source/stash.cc
@@ -40,12 +40,6 @@
#define LUA_DUMP_ANNOTATE "ch_stash_dump_annotate_item"
#define LUA_VIEW_ANNOTATE "ch_stash_view_annotate_item"
-std::string short_place_name(level_id id)
-{
- return short_place_name(
- get_packed_place(id.branch, id.depth, LEVEL_DUNGEON));
-}
-
std::string userdef_annotate_item(const char *s, const item_def *item,
bool exclusive)
{
@@ -960,7 +954,9 @@ bool LevelStashes::in_branch(int branchid) const
std::string LevelStashes::level_name() const
{
int curr_subdungeon_level = subdungeon_depth( branch, depth );
- return (branch_level_name(branch, curr_subdungeon_level));
+ return (place_name(
+ get_packed_place(branch, curr_subdungeon_level, LEVEL_DUNGEON),
+ true, true));
}
std::string LevelStashes::short_level_name() const
@@ -1503,127 +1499,3 @@ void StashTracker::display_search_results(
StashTracker stashes;
#endif
-
-std::string branch_level_name(unsigned char branch, int sub_depth)
-{
- int ltype = sub_depth == 0xFF? branch : 0;
- if (ltype == LEVEL_PANDEMONIUM)
- return ("Pandemonium");
- else if (ltype == LEVEL_ABYSS)
- return ("The Abyss");
- else if (ltype == LEVEL_LABYRINTH)
- return ("A Labyrinth");
- else
- {
- char buf[200];
- const char *s = NULL;
- *buf = 0;
- // level_type == LEVEL_DUNGEON
- if (branch != BRANCH_VESTIBULE_OF_HELL
- && branch != BRANCH_ECUMENICAL_TEMPLE
- && branch != BRANCH_HALL_OF_BLADES)
- snprintf(buf, sizeof buf, "Level %d", sub_depth);
-
- switch (branch)
- {
- case BRANCH_MAIN_DUNGEON:
- s = " of the Dungeon";
- break;
- case BRANCH_DIS:
- s = " of Dis";
- break;
- case BRANCH_GEHENNA:
- s = " of Gehenna";
- break;
- case BRANCH_VESTIBULE_OF_HELL:
- s = "The Vestibule of Hell";
- break;
- case BRANCH_COCYTUS:
- s = " of Cocytus";
- break;
- case BRANCH_TARTARUS:
- s = " of Tartarus";
- break;
- case BRANCH_INFERNO:
- s = " of the Inferno";
- break;
- case BRANCH_THE_PIT:
- s = " of the Pit";
- break;
- case BRANCH_ORCISH_MINES:
- s = " of the Orcish Mines";
- break;
- case BRANCH_HIVE:
- s = " of the Hive";
- break;
- case BRANCH_LAIR:
- s = " of the Lair";
- break;
- case BRANCH_SLIME_PITS:
- s = " of the Slime Pits";
- break;
- case BRANCH_VAULTS:
- s = " of the Vaults";
- break;
- case BRANCH_CRYPT:
- s = " of the Crypt";
- break;
- case BRANCH_HALL_OF_BLADES:
- s = "The Hall of Blades";
- break;
- case BRANCH_HALL_OF_ZOT:
- s = " of the Realm of Zot";
- break;
- case BRANCH_ECUMENICAL_TEMPLE:
- s = "The Ecumenical Temple";
- break;
- case BRANCH_SNAKE_PIT:
- s = " of the Snake Pit";
- break;
- case BRANCH_ELVEN_HALLS:
- s = " of the Elven Halls";
- break;
- case BRANCH_TOMB:
- s = " of the Tomb";
- break;
- case BRANCH_SWAMP:
- s = " of the Swamp";
- break;
- }
- if (s)
- strncat(buf, s, sizeof(buf) - 1);
- return (buf);
- }
-}
-
-std::string branch_level_name(unsigned short packed_place)
-{
- return branch_level_name(packed_place >> 8, packed_place & 0xFF);
-}
-
-// Prepositional form of branch level name. For example, "in the
-// Abyss" or "on level 3 of the Main Dungeon".
-std::string prep_branch_level_name(unsigned char branch, int sub_depth)
-{
- std::string place = branch_level_name(branch, sub_depth);
- if (place.length() && place != "Pandemonium")
- place[0] = tolower(place[0]);
- return (place.find("level") == 0?
- "on " + place
- : "in " + place);
-}
-
-std::string prep_branch_level_name(unsigned short packed_place)
-{
- return prep_branch_level_name(packed_place >> 8, packed_place & 0xFF);
-}
-
-// Use current branch and depth
-std::string prep_branch_level_name()
-{
- int branch = you.where_are_you;
- int sub_depth = subdungeon_depth( branch, you.your_level );
-
- return prep_branch_level_name(branch, sub_depth);
-}
-
diff --git a/crawl-ref/source/stash.h b/crawl-ref/source/stash.h
index dafe707c82..727fb656e4 100644
--- a/crawl-ref/source/stash.h
+++ b/crawl-ref/source/stash.h
@@ -317,18 +317,6 @@ void describe_stash(int x, int y);
#endif // STASH_TRACKING
-std::string branch_level_name(unsigned char branch, int sub_depth);
-
-std::string branch_level_name(unsigned short packed_place);
-
-// Prepositional form of branch level name. For example, "in the
-// Abyss" or "on level 3 of the Main Dungeon".
-std::string prep_branch_level_name(unsigned char branch, int sub_depth);
-
-std::string prep_branch_level_name(unsigned short packed_place);
-
-std::string prep_branch_level_name();
-
std::string userdef_annotate_item(const char *s, const item_def *item,
bool exclusive = false);
diff --git a/crawl-ref/source/travel.h b/crawl-ref/source/travel.h
index d50b83a69c..8c733b9af2 100644
--- a/crawl-ref/source/travel.h
+++ b/crawl-ref/source/travel.h
@@ -104,6 +104,8 @@ enum EXPLORE_STOP
////////////////////////////////////////////////////////////////////////////
// Structs for interlevel travel.
+// Identifies a level. This has no meaning in the Abyss, labyrinths or
+// Pandemonium.
struct level_id
{
unsigned char branch; // The branch in which the level is.