summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-11-25 20:36:42 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-11-25 20:36:42 +0000
commiteca2b4e128181432115b49cb6371c51fa3221cec (patch)
tree6d0ae350754ba522d2848d4164696c1d476c4231 /crawl-ref/source
parent2184f5a98edb10e49ec9b7611601552fe686d737 (diff)
downloadcrawl-ref-eca2b4e128181432115b49cb6371c51fa3221cec.tar.gz
crawl-ref-eca2b4e128181432115b49cb6371c51fa3221cec.zip
Added you.level_type_name_abbrev, which on portal levels is stored in
notes (adding an overhead of 4 bytes per note) to be used as the place name when displaying notes, like this: 34 | Zig:2 | Shot with a bolt by a yaktaur captain (26 damage) Breaks savefile compatibility. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7621 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/dat/clua/ziggurat.lua2
-rw-r--r--crawl-ref/source/dat/icecave.des1
-rw-r--r--crawl-ref/source/externs.h6
-rw-r--r--crawl-ref/source/luadgn.cc22
-rw-r--r--crawl-ref/source/misc.cc70
-rw-r--r--crawl-ref/source/notes.cc25
-rw-r--r--crawl-ref/source/notes.h3
-rw-r--r--crawl-ref/source/tags.cc6
8 files changed, 105 insertions, 30 deletions
diff --git a/crawl-ref/source/dat/clua/ziggurat.lua b/crawl-ref/source/dat/clua/ziggurat.lua
index ae727fecf2..db25f7cb55 100644
--- a/crawl-ref/source/dat/clua/ziggurat.lua
+++ b/crawl-ref/source/dat/clua/ziggurat.lua
@@ -83,6 +83,7 @@ function ziggurat_portal(e)
desc = "gateway to a ziggurat",
dst = "ziggurat",
dstname = "Ziggurat:1",
+ dstname_abbrev = "Zig:1",
dstorigin = "on level 1 of a ziggurat",
floor = "stone_arch",
onclimb = ziggurat_initialiser
@@ -129,6 +130,7 @@ local function zig_go_deeper()
return one_way_stair {
onclimb = zig_depth_increment,
dstname = "Ziggurat:" .. newdepth,
+ dstname_abbrev = "Zig:" .. newdepth,
dstorigin = "on level " .. newdepth .. " of a ziggurat"
}
end
diff --git a/crawl-ref/source/dat/icecave.des b/crawl-ref/source/dat/icecave.des
index f2f1016643..e258591c83 100644
--- a/crawl-ref/source/dat/icecave.des
+++ b/crawl-ref/source/dat/icecave.des
@@ -28,6 +28,7 @@ function ice_cave_portal(e)
e.marker([[O = lua:one_way_stair { desc = "A frozen archway",
dst = "ice_cave",
dstname = "Ice Cave",
+ dstname_abbrev = "IceCv",
dstovermap = "frozen archway",
dstorigin = "in an ice cave",
floor = "stone_arch" }]])
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index ef22c4eb6d..c5d620147d 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -842,6 +842,12 @@ public:
// if not explicitly set by the entry portal.
std::string level_type_name;
+ // Abbreviation of portal vault name, for use in notes. If not
+ // explicitly set by the portal vault, will be set from level_type_name
+ // or level_type_tag if either is short enough, or the shorter of the
+ // two will be truncated if neither is short enough.
+ std::string level_type_name_abbrev;
+
// Item origin string for items from portal vaults, so that dumps
// can have origins like "You found it in on level 2 of a ziggurat".
// Will be set relative to level_type_name if not explicitly set.
diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc
index 1a688561a3..02a74f96be 100644
--- a/crawl-ref/source/luadgn.cc
+++ b/crawl-ref/source/luadgn.cc
@@ -2251,6 +2251,27 @@ LUAFN(dgn_set_level_type_name)
return(0);
}
+LUAFN(dgn_set_level_type_name_abbrev)
+{
+ if (you.level_type != LEVEL_PORTAL_VAULT)
+ {
+ luaL_error(ls, "Can only set level type name abbreviation on "
+ "portal vaults");
+ return(0);
+ }
+
+ if (!lua_isstring(ls, 1))
+ {
+ luaL_argerror(ls, 1, "Expected string for level type name "
+ "abberviation");
+ return(0);
+ }
+
+ you.level_type_name_abbrev = luaL_checkstring(ls, 1);
+
+ return(0);
+}
+
LUAFN(dgn_set_level_type_origin)
{
if (you.level_type != LEVEL_PORTAL_VAULT)
@@ -2512,6 +2533,7 @@ static const struct luaL_reg dgn_lib[] =
{ "level_id", dgn_level_id },
{ "level_name", dgn_level_name },
{ "set_level_type_name", dgn_set_level_type_name },
+ { "set_level_type_name_abbrev", dgn_set_level_type_name_abbrev },
{ "set_level_type_origin", dgn_set_level_type_origin },
{ "map_by_tag", dgn_map_by_tag },
{ "map_in_depth", dgn_map_in_depth },
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 86e91cc8bb..43b9951ba1 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -1363,15 +1363,29 @@ static void leaving_level_now()
std::string neworigin =
env.markers.property_at(you.pos(), MAT_ANY, "dstorigin");
- you.level_type_origin = "";
+ const std::string oldname_abbrev = you.level_type_name_abbrev;
+ std::string newname_abbrev =
+ env.markers.property_at(you.pos(), MAT_ANY, "dstname_abbrev");
dungeon_events.fire_position_event(DET_PLAYER_CLIMBS, you.pos());
dungeon_events.fire_event(DET_LEAVING_LEVEL);
- // Lua scripts explicitly set level_type_na,e so use that.
+ // Lua scripts explicitly set level_type_name, so use that.
if (you.level_type_name != oldname)
newname = you.level_type_name;
+ // Lua scripts explicitly set level_type_name_abbrev, so use that.
+ if (you.level_type_name_abbrev != oldname_abbrev)
+ newname_abbrev = you.level_type_name_abbrev;
+
+ if (newname_abbrev.length() > MAX_NOTE_PLACE_LEN)
+ {
+ mprf(MSGCH_ERROR, "'%s' is too long for a portal vault name "
+ "abbreviation, truncating");
+ newname_abbrev = newname_abbrev.substr(0, MAX_NOTE_PLACE_LEN);
+ }
+
+ you.level_type_origin = "";
// Lua scripts explicitly set level_type_origin, so use that.
if (!you.level_type_origin.empty())
neworigin = you.level_type_origin;
@@ -1383,14 +1397,38 @@ static void leaving_level_now()
you.level_type_name = newname;
}
+ // Don't clobber level_type_name_abbrev for stairs in portal vaults.
+ if (you.level_type_name_abbrev.empty() || !newname_abbrev.empty()
+ || you.level_type != LEVEL_PORTAL_VAULT)
+ {
+ you.level_type_name_abbrev = newname_abbrev;
+ }
+
if (you.level_type_tag.empty() || !newtype.empty()
|| you.level_type != LEVEL_PORTAL_VAULT)
{
- you.level_type_tag = newtype;
+ you.level_type_tag = newtype;
}
+ const std::string spaced_tag = replace_all(you.level_type_tag, "_", " ");
if (!you.level_type_tag.empty() && you.level_type_name.empty())
- you.level_type_name = you.level_type_tag;
+ you.level_type_name = spaced_tag;
+
+ if (!you.level_type_name.empty() && you.level_type_name_abbrev.empty())
+ {
+ if (you.level_type_name.length() <= MAX_NOTE_PLACE_LEN)
+ you.level_type_name_abbrev = you.level_type_name;
+ else if (you.level_type_tag.length() <= MAX_NOTE_PLACE_LEN)
+ you.level_type_name_abbrev = spaced_tag;
+ else
+ {
+ const std::string shorter =
+ you.level_type_name.length() < you.level_type_tag.length() ?
+ you.level_type_name : spaced_tag;
+
+ you.level_type_name_abbrev = shorter.substr(0, MAX_NOTE_PLACE_LEN);
+ }
+ }
if (!neworigin.empty())
you.level_type_origin = neworigin;
@@ -1399,13 +1437,17 @@ static void leaving_level_now()
std::string lname = lowercase_string(you.level_type_name);
std::string article, prep;
- if (starts_with(lname, "level "))
+ if (starts_with(lname, "level ")
+ || lname.find(":") != std::string::npos)
+ {
prep = "on ";
+ }
else
prep = "in ";
if (starts_with(lname, "a ") || starts_with(lname, "an ")
- || starts_with(lname, "the ") || starts_with(lname, "level "))
+ || starts_with(lname, "the ") || starts_with(lname, "level ")
+ || lname.find(":") != std::string::npos)
{
; // Doesn't need an article
}
@@ -2420,18 +2462,6 @@ void new_level(void)
{
if (you.level_type == LEVEL_PORTAL_VAULT)
{
- std::string name = "Portal";
- if (you.level_type_name.length() <= 7
- && you.level_type_name.find(":") == std::string::npos)
- {
- name = uppercase_first(you.level_type_name);
- }
- else if (you.level_type_tag.length() <= 7)
- {
- name = uppercase_first(you.level_type_tag);
- name = replace_all(name, "_", " ");
- }
-
// If there's more than one word in level_type_origin then skip
// the first, since it's most likely a preposition.
std::string desc = "Entered ";
@@ -2442,12 +2472,12 @@ void new_level(void)
desc += you.level_type_origin.substr(space + 1);
desc += ".";
- take_note(Note(NOTE_DUNGEON_LEVEL_CHANGE, 0, 0, name.c_str(),
+ take_note(Note(NOTE_DUNGEON_LEVEL_CHANGE, 0, 0, NULL,
desc.c_str()));
}
else
take_note(Note(NOTE_DUNGEON_LEVEL_CHANGE));
-
+
print_stats_level();
#ifdef DGL_WHEREIS
whereis_record();
diff --git a/crawl-ref/source/notes.cc b/crawl-ref/source/notes.cc
index e3018971e3..4a103f31c1 100644
--- a/crawl-ref/source/notes.cc
+++ b/crawl-ref/source/notes.cc
@@ -28,7 +28,7 @@
#include "spl-util.h"
#include "tags.h"
-#define NOTES_VERSION_NUMBER 1001
+#define NOTES_VERSION_NUMBER 1002
std::vector<Note> note_list;
@@ -249,11 +249,11 @@ std::string Note::describe( bool when, bool where, bool what ) const
if (where)
{
- if (type == NOTE_DUNGEON_LEVEL_CHANGE && !name.empty())
- result << "| " << std::setw(7) << std::left
- << name << " | ";
+ if (!place_abbrev.empty())
+ result << "| " << std::setw(MAX_NOTE_PLACE_LEN) << std::left
+ << place_abbrev << " | ";
else
- result << "| " << std::setw(7) << std::left
+ result << "| " << std::setw(MAX_NOTE_PLACE_LEN) << std::left
<< short_place_name(packed_place) << " | ";
}
@@ -378,19 +378,26 @@ std::string Note::describe( bool when, bool where, bool what ) const
Note::Note()
{
- turn = you.num_turns;
+ turn = you.num_turns;
packed_place = get_packed_place();
+
+ if (you.level_type == LEVEL_PORTAL_VAULT)
+ place_abbrev = you.level_type_name_abbrev;
}
Note::Note( NOTE_TYPES t, int f, int s, const char* n, const char* d ) :
- type(t), first(f), second(s)
+ type(t), first(f), second(s), place_abbrev("")
{
if (n)
name = std::string(n);
if (d)
desc = std::string(d);
- turn = you.num_turns;
+
+ turn = you.num_turns;
packed_place = get_packed_place();
+
+ if (you.level_type == LEVEL_PORTAL_VAULT)
+ place_abbrev = you.level_type_name_abbrev;
}
void Note::check_milestone() const
@@ -432,6 +439,7 @@ void Note::save(writer& outf) const
marshallLong( outf, first );
marshallLong( outf, second );
marshallString4( outf, name );
+ marshallString4( outf, place_abbrev );
marshallString4( outf, desc );
}
@@ -443,6 +451,7 @@ void Note::load(reader& inf)
first = unmarshallLong( inf );
second = unmarshallLong( inf );
unmarshallString4( inf, name );
+ unmarshallString4( inf, place_abbrev );
unmarshallString4( inf, desc );
}
diff --git a/crawl-ref/source/notes.h b/crawl-ref/source/notes.h
index 417be71af5..86879d0081 100644
--- a/crawl-ref/source/notes.h
+++ b/crawl-ref/source/notes.h
@@ -13,6 +13,8 @@
#include <vector>
#include <stdio.h>
+#define MAX_NOTE_PLACE_LEN 7
+
class reader;
class writer;
@@ -62,6 +64,7 @@ struct Note
int first, second;
long turn;
unsigned short packed_place;
+ std::string place_abbrev;
std::string name;
std::string desc;
};
diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc
index 409b35f06a..ae13c5c077 100644
--- a/crawl-ref/source/tags.cc
+++ b/crawl-ref/source/tags.cc
@@ -875,6 +875,7 @@ static void tag_construct_you(writer &th)
marshallLong(th, you.sage_bonus_degree);
marshallByte(th, you.level_type);
marshallString(th, you.level_type_name);
+ marshallString(th, you.level_type_name_abbrev);
marshallString(th, you.level_type_origin);
marshallString(th, you.level_type_tag);
marshallByte(th, you.entry_cause);
@@ -1273,8 +1274,9 @@ static void tag_read_you(reader &th, char minorVersion)
if (minorVersion >= TAG_MINOR_LUADGN)
{
- you.level_type_origin = unmarshallString(th);
- you.level_type_tag = unmarshallString(th);
+ you.level_type_name_abbrev = unmarshallString(th);
+ you.level_type_origin = unmarshallString(th);
+ you.level_type_tag = unmarshallString(th);
}
you.entry_cause = static_cast<entry_cause_type>( unmarshallByte(th) );