diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-12-12 19:53:45 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2006-12-12 19:53:45 +0000 |
commit | 4c1860113f640efeb503505542393f3dccdd5060 (patch) | |
tree | e28485e52508608a7823fa389f2354b44d717a06 | |
parent | 170c1de4d2bc1b996f11cffdec0fc49cfe71c388 (diff) | |
download | crawl-ref-4c1860113f640efeb503505542393f3dccdd5060.tar.gz crawl-ref-4c1860113f640efeb503505542393f3dccdd5060.zip |
Tweaked stash-tracker so that greedy explore works in Pandemonium.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@621 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/AppHdr.h | 11 | ||||
-rw-r--r-- | crawl-ref/source/acr.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/debug.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/files.cc | 29 | ||||
-rw-r--r-- | crawl-ref/source/initfile.cc | 10 | ||||
-rw-r--r-- | crawl-ref/source/misc.cc | 18 | ||||
-rw-r--r-- | crawl-ref/source/misc.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/overmap.cc | 10 | ||||
-rw-r--r-- | crawl-ref/source/stash.cc | 132 | ||||
-rw-r--r-- | crawl-ref/source/stash.h | 32 | ||||
-rw-r--r-- | crawl-ref/source/travel.cc | 88 | ||||
-rw-r--r-- | crawl-ref/source/travel.h | 56 |
12 files changed, 202 insertions, 190 deletions
diff --git a/crawl-ref/source/AppHdr.h b/crawl-ref/source/AppHdr.h index 56ea84e0cd..5ce561d512 100644 --- a/crawl-ref/source/AppHdr.h +++ b/crawl-ref/source/AppHdr.h @@ -56,6 +56,17 @@ // // #define CLUA_BINDINGS +// Uncomment to prevent Crawl from looking for a list of saves when +// asking the player to enter a name. This can speed up startup +// considerably if you have a lot of saves lying around (even more so +// if the saves are zipped). +// +// #define DISABLE_SAVEGAME_LISTS + +// Uncomment to prevent Crawl from remembering startup preferences. +// +// #define DISABLE_STICKY_STARTUP_OPTIONS + // OS X's Terminal.app has color handling problems; dark grey is // especially bad, so we'll want to remap that. OS X is otherwise // Unix-ish, so we shouldn't need other special handling. diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index a382847a27..9e73009b6a 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -2769,7 +2769,7 @@ static bool initialise(void) draw_border(); new_level(); - travel_init_new_level(); + init_new_level(); // Mark items in inventory as of unknown origin. origin_set_inventory(origin_set_unknown); diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index c92d416d12..ba6a815086 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -2151,9 +2151,6 @@ void debug_make_trap() mprf("Created a %s trap, marked it undiscovered", trap_name(trap)); - - // Also tell travel that its world-view must change. - travel_init_new_level(); } static const char *shop_types[] = { diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index 1eba6f40c5..fe39797abf 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -238,20 +238,20 @@ static bool is_uid_file(const std::string &name, const std::string &ext) } -static bool is_save_file_name(const std::string &name) +bool is_save_file_name(const std::string &name) { return is_uid_file(name, ".sav"); } #ifdef LOAD_UNPACKAGE_CMD -static bool is_packed_save(const std::string &name) +bool is_packed_save(const std::string &name) { return is_uid_file(name, PACKAGE_SUFFIX); } #endif // Returns a full player struct read from the save. -static player read_character_info(const std::string &savefile) +player read_character_info(const std::string &savefile) { player fromfile; player backup = you; @@ -263,24 +263,21 @@ static player read_character_info(const std::string &savefile) char majorVersion = 0; char minorVersion = 0; - if (!determine_version(charf, majorVersion, minorVersion)) - goto done_reading_character; - - if (majorVersion != SAVE_MAJOR_VERSION) - goto done_reading_character; - - restore_tagged_file(charf, TAGTYPE_PLAYER_NAME, minorVersion); - fromfile = you; - you = backup; + if (determine_version(charf, majorVersion, minorVersion) + && majorVersion == SAVE_MAJOR_VERSION) + { + restore_tagged_file(charf, TAGTYPE_PLAYER_NAME, minorVersion); + fromfile = you; + you = backup; + } -done_reading_character: fclose(charf); return fromfile; } // Returns the names of all files in the given directory. Note that the // filenames returned are relative to the directory. -static std::vector<std::string> get_dir_files(const std::string &dirname) +std::vector<std::string> get_dir_files(const std::string &dirname) { std::vector<std::string> files; @@ -446,13 +443,14 @@ std::string get_savedir_path(const std::string &shortpath) */ std::vector<player> find_saved_characters() { + std::vector<player> chars; +#ifndef DISABLE_SAVEGAME_LISTS std::string searchpath = Options.save_dir; if (searchpath.empty()) searchpath = "."; std::vector<std::string> allfiles = get_dir_files(searchpath); - std::vector<player> chars; for (int i = 0, size = allfiles.size(); i < size; ++i) { std::string filename = allfiles[i]; @@ -495,6 +493,7 @@ std::vector<player> find_saved_characters() } std::sort(chars.begin(), chars.end()); +#endif // !DISABLE_SAVEGAME_LISTS return (chars); } diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 86225d4ffc..56e86060ab 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -204,7 +204,7 @@ static int str_to_weapon( const std::string &str ) return (WPN_UNKNOWN); } -static std::string weapon_to_str( int weapon ) +std::string weapon_to_str( int weapon ) { switch (weapon) { @@ -889,6 +889,7 @@ std::string read_init_file(bool runscript) static void read_startup_prefs() { +#ifndef DISABLE_STICKY_STARTUP_OPTIONS std::string fn = get_prefs_filename(); FILE *f = fopen(fn.c_str(), "r"); if (!f) @@ -908,8 +909,10 @@ static void read_startup_prefs() Options.prev_race = temp.race; Options.prev_book = temp.book; Options.prev_name = temp.player_name; +#endif // !DISABLE_STICKY_STARTUP_OPTIONS } +#ifndef DISABLE_STICKY_STARTUP_OPTIONS static void write_newgame_options(FILE *f) { // Write current player name @@ -958,19 +961,23 @@ static void write_newgame_options(FILE *f) "random"); } } +#endif // !DISABLE_STICKY_STARTUP_OPTIONS void write_newgame_options_file() { +#ifndef DISABLE_STICKY_STARTUP_OPTIONS std::string fn = get_prefs_filename(); FILE *f = fopen(fn.c_str(), "w"); if (!f) return; write_newgame_options(f); fclose(f); +#endif // !DISABLE_STICKY_STARTUP_OPTIONS } void save_player_name() { +#ifndef DISABLE_STICKY_STARTUP_OPTIONS if (!Options.remember_name) return ; @@ -979,6 +986,7 @@ void save_player_name() // And save write_newgame_options_file(); +#endif // !DISABLE_STICKY_STARTUP_OPTIONS } void read_options(FILE *f, bool runscript) diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index 6235ebd1b6..56155c14e3 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -558,7 +558,7 @@ void up_stairs(void) && you.level_type != LEVEL_ABYSS && you.level_type != LEVEL_PANDEMONIUM; - level_id old_level_id = level_id::get_current_level_id(); + level_id old_level_id = level_id::current(); LevelInfo &old_level_info = travel_cache.get_level_info(old_level_id); int stair_x = you.x_pos, stair_y = you.y_pos; if (collect_travel_data) @@ -669,12 +669,12 @@ void up_stairs(void) mpr( "You sense a powerful magical force warping space.", MSGCH_WARN ); // Tell the travel code that we're now on a new level - travel_init_new_level(); + init_new_level(); if (collect_travel_data) { // Update stair information for the stairs we just ascended, and the // down stairs we're currently on. - level_id new_level_id = level_id::get_current_level_id(); + level_id new_level_id = level_id::current(); if (you.level_type != LEVEL_PANDEMONIUM && you.level_type != LEVEL_ABYSS && @@ -821,7 +821,7 @@ void down_stairs( bool remove_stairs, int old_level, bool force ) && you.level_type != LEVEL_ABYSS && you.level_type != LEVEL_PANDEMONIUM; - level_id old_level_id = level_id::get_current_level_id(); + level_id old_level_id = level_id::current(); LevelInfo &old_level_info = travel_cache.get_level_info(old_level_id); int stair_x = you.x_pos, stair_y = you.y_pos; if (collect_travel_data) @@ -1109,12 +1109,12 @@ void down_stairs( bool remove_stairs, int old_level, bool force ) if (you.skills[SK_TRANSLOCATIONS] > 0 && !allow_control_teleport( true )) mpr( "You sense a powerful magical force warping space.", MSGCH_WARN ); - travel_init_new_level(); + init_new_level(); if (collect_travel_data) { // Update stair information for the stairs we just descended, and the // upstairs we're currently on. - level_id new_level_id = level_id::get_current_level_id(); + level_id new_level_id = level_id::current(); if (you.level_type != LEVEL_PANDEMONIUM && you.level_type != LEVEL_ABYSS && @@ -1143,6 +1143,12 @@ void down_stairs( bool remove_stairs, int old_level, bool force ) } } // end down_stairs() +void init_new_level() +{ + travel_init_new_level(); + stash_init_new_level(); +} + void new_level(void) { int curr_subdungeon_level = you.your_level + 1; diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h index efc5016a4b..18eefdafa6 100644 --- a/crawl-ref/source/misc.h +++ b/crawl-ref/source/misc.h @@ -86,6 +86,7 @@ void itrap(struct bolt &pbolt, int trapped); * *********************************************************************** */ void new_level(void); +void init_new_level(); // last updated 12may2000 {dlb} /* *********************************************************************** diff --git a/crawl-ref/source/overmap.cc b/crawl-ref/source/overmap.cc index 9a55761e60..ab61669d1c 100644 --- a/crawl-ref/source/overmap.cc +++ b/crawl-ref/source/overmap.cc @@ -385,7 +385,7 @@ std::string overview_description_string() void unnotice_labyrinth_portal() { - level_pos curpos(level_id::get_current_level_id()); + level_pos curpos(level_id::current()); // XXX Is there really no better way to do this? curpos.pos.x = you.x_pos; curpos.pos.y = you.y_pos; @@ -473,7 +473,7 @@ void seen_staircase( unsigned char which_staircase, const coord_def& pos ) ASSERT(which_branch != BRANCH_MAIN_DUNGEON); - stair_level[which_branch] = level_id::get_current_level_id(); + stair_level[which_branch] = level_id::current(); } // if player has seen an altar; record it @@ -483,14 +483,14 @@ void seen_altar( god_type god, const coord_def& pos ) if ( you.level_type != LEVEL_DUNGEON ) return; - level_pos where(level_id::get_current_level_id(), pos); + level_pos where(level_id::current(), pos); altars_present[where] = god; } void unnotice_altar() { const coord_def pos(you.x_pos, you.y_pos); - const level_pos curpos(level_id::get_current_level_id(), pos); + const level_pos curpos(level_id::current(), pos); // Hmm, what happens when erasing a nonexistent key directly? if (altars_present.find(curpos) != altars_present.end()) altars_present.erase(curpos); @@ -519,7 +519,7 @@ void seen_other_thing( unsigned char which_thing, const coord_def& pos ) if ( you.level_type != LEVEL_DUNGEON ) // can't record in abyss or pan. return; - level_pos where(level_id::get_current_level_id(), pos); + level_pos where(level_id::current(), pos); switch ( which_thing ) { diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index 4c295b27cb..d9f59c6de6 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -33,12 +33,18 @@ #include <algorithm> #define ST_MAJOR_VER ((unsigned char) 4) -#define ST_MINOR_VER ((unsigned char) 4) +#define ST_MINOR_VER ((unsigned char) 5) #define LUA_SEARCH_ANNOTATE "ch_stash_search_annotate_item" #define LUA_DUMP_ANNOTATE "ch_stash_dump_annotate_item" #define LUA_VIEW_ANNOTATE "ch_stash_view_annotate_item" +void stash_init_new_level() +{ + // If there's an existing stash level for Pan, blow it away. + stashes.remove_level( level_id(LEVEL_PANDEMONIUM) ); +} + std::string userdef_annotate_item(const char *s, const item_def *item, bool exclusive) { @@ -850,21 +856,13 @@ std::ostream &operator << (std::ostream &os, const ShopInfo &s) return os; } -LevelStashes::LevelStashes() -{ - branch = you.where_are_you; - depth = you.your_level; -} - -bool LevelStashes::operator < (const LevelStashes &lev) const +LevelStashes::LevelStashes() : place(), stashes(), shops() { - return branch < lev.branch || (branch == lev.branch && depth < lev.depth); } -bool LevelStashes::isBelowPlayer() const +level_id LevelStashes::where() const { - return branch > you.where_are_you - || (branch == you.where_are_you && depth > you.your_level); + return (place); } Stash *LevelStashes::find_stash(int x, int y) @@ -881,7 +879,7 @@ const Stash *LevelStashes::find_stash(int x, int y) const y = you.y_pos; } const int abspos = (GXM * y) + x; - c_stashes::const_iterator st = stashes.find(abspos); + stashes_t::const_iterator st = stashes.find(abspos); return (st == stashes.end()? NULL : &st->second); } @@ -984,38 +982,32 @@ void LevelStashes::add_stash(int x, int y) } } -bool LevelStashes::isCurrent() const +bool LevelStashes::is_current() const { - return branch == you.where_are_you && depth == you.your_level; + return (place == level_id::current()); } bool LevelStashes::in_hell() const { - return branch >= BRANCH_DIS - && branch <= BRANCH_THE_PIT - && branch != BRANCH_VESTIBULE_OF_HELL; + return place.branch >= BRANCH_DIS + && place.branch <= BRANCH_THE_PIT + && place.branch != BRANCH_VESTIBULE_OF_HELL; } bool LevelStashes::in_branch(int branchid) const { - return branch == branchid; + return place.branch == branchid; } std::string LevelStashes::level_name() const { - int curr_subdungeon_level = subdungeon_depth( branch, depth ); - return (place_name( - get_packed_place(branch, curr_subdungeon_level, LEVEL_DUNGEON), - true, true)); + return place.describe(true, true); } std::string LevelStashes::short_level_name() const { - return (short_place_name( - get_packed_place( branch, - subdungeon_depth( branch, depth ), - LEVEL_DUNGEON ) )); + return place.describe(); } int LevelStashes::count_stashes() const @@ -1024,7 +1016,7 @@ int LevelStashes::count_stashes() const if (!rawcount) return (0); - for (c_stashes::const_iterator iter = stashes.begin(); + for (stashes_t::const_iterator iter = stashes.begin(); iter != stashes.end(); iter++) { if (!iter->second.enabled) @@ -1038,9 +1030,8 @@ void LevelStashes::get_matching_stashes( std::vector<stash_search_result> &results) const { - level_id clid(branch, subdungeon_depth(branch, depth)); - std::string lplace = "{" + short_place_name(clid) + "}"; - for (c_stashes::const_iterator iter = stashes.begin(); + std::string lplace = "{" + place.describe() + "}"; + for (stashes_t::const_iterator iter = stashes.begin(); iter != stashes.end(); iter++) { if (iter->second.enabled) @@ -1048,7 +1039,7 @@ void LevelStashes::get_matching_stashes( stash_search_result res; if (iter->second.matches_search(lplace, search, res)) { - res.pos.id = clid; + res.pos.id = place; results.push_back(res); } } @@ -1059,7 +1050,7 @@ void LevelStashes::get_matching_stashes( stash_search_result res; if (shops[i].matches_search(lplace, search, res)) { - res.pos.id = clid; + res.pos.id = place; results.push_back(res); } } @@ -1080,7 +1071,7 @@ void LevelStashes::write(std::ostream &os, bool identify) const const Stash &s = stashes.begin()->second; int refx = s.getX(), refy = s.getY(); std::string levname = short_level_name(); - for (c_stashes::const_iterator iter = stashes.begin(); + for (stashes_t::const_iterator iter = stashes.begin(); iter != stashes.end(); iter++) { iter->second.write(os, refx, refy, levname, identify); @@ -1094,11 +1085,10 @@ void LevelStashes::save(FILE *file) const // How many stashes on this level? writeShort(file, (short) stashes.size()); - writeByte(file, branch); - writeShort(file, (short) depth); + place.save(file); // And write the individual stashes - for (c_stashes::const_iterator iter = stashes.begin(); + for (stashes_t::const_iterator iter = stashes.begin(); iter != stashes.end(); iter++) iter->second.save(file); @@ -1111,8 +1101,7 @@ void LevelStashes::load(FILE *file) { int size = readShort(file); - branch = readByte(file); - depth = readShort(file); + place.load(file); stashes.clear(); for (int i = 0; i < size; ++i) @@ -1141,29 +1130,21 @@ std::ostream &operator << (std::ostream &os, const LevelStashes &ls) LevelStashes &StashTracker::get_current_level() { - std::vector<LevelStashes>::iterator iter = levels.begin(); - for ( ; iter != levels.end() && !iter->isBelowPlayer(); iter++) - { - if (iter->isCurrent()) return *iter; - } - if (iter == levels.end()) - levels.push_back(LevelStashes()); - else - levels.insert(iter, LevelStashes()); - return get_current_level(); + return (levels[level_id::current()]); +} + +LevelStashes *StashTracker::find_level(const level_id &id) +{ + stash_levels_t::iterator i = levels.find(id); + return (i != levels.end()? &i->second : NULL); } LevelStashes *StashTracker::find_current_level() { if (is_level_untrackable()) return (NULL); - - std::vector<LevelStashes>::iterator iter = levels.begin(); - for ( ; iter != levels.end() && !iter->isBelowPlayer(); iter++) - { - if (iter->isCurrent()) return &*iter; - } - return (NULL); + + return find_level(level_id::current()); } @@ -1174,23 +1155,15 @@ bool StashTracker::update_stash(int x, int y) { bool res = lev->update_stash(x, y); if (!lev->stash_count()) - remove_level(*lev); + remove_level(); return res; } return false; } -void StashTracker::remove_level(const LevelStashes &ls) +void StashTracker::remove_level(const level_id &place) { - std::vector<LevelStashes>::iterator iter = levels.begin(); - for ( ; iter != levels.end(); ++iter) - { - if (&ls == &*iter) - { - levels.erase(iter); - break ; - } - } + levels.erase(place); } void StashTracker::no_stash(int x, int y) @@ -1200,7 +1173,7 @@ void StashTracker::no_stash(int x, int y) LevelStashes ¤t = get_current_level(); current.no_stash(x, y); if (!current.stash_count()) - remove_level(current); + remove_level(); } void StashTracker::add_stash(int x, int y, bool verbose) @@ -1218,7 +1191,7 @@ void StashTracker::add_stash(int x, int y, bool verbose) } if (!current.stash_count()) - remove_level(current); + remove_level(); } void StashTracker::dump(const char *filename, bool identify) const @@ -1238,10 +1211,10 @@ void StashTracker::write(std::ostream &os, bool identify) const os << " You have no stashes." << std::endl; else { - std::vector<LevelStashes>::const_iterator iter = levels.begin(); - for ( ; iter != levels.end(); iter++) + for (stash_levels_t::const_iterator iter = levels.begin(); + iter != levels.end(); iter++) { - iter->write(os, identify); + iter->second.write(os, identify); } } } @@ -1256,9 +1229,9 @@ void StashTracker::save(FILE *file) const writeShort(file, (short) levels.size()); // And ask each level to write itself to the tag - std::vector<LevelStashes>::const_iterator iter = levels.begin(); + stash_levels_t::const_iterator iter = levels.begin(); for ( ; iter != levels.end(); iter++) - iter->save(file); + iter->second.save(file); } void StashTracker::load(FILE *file) @@ -1276,7 +1249,8 @@ void StashTracker::load(FILE *file) { LevelStashes st; st.load(file); - if (st.stash_count()) levels.push_back(st); + if (st.stash_count()) + levels[st.where()] = st; } } @@ -1313,7 +1287,7 @@ void StashTracker::update_visible_stashes( } if (lev && !lev->stash_count()) - remove_level(*lev); + remove_level(); } #define SEARCH_SPAM_THRESHOLD 400 @@ -1388,17 +1362,17 @@ void StashTracker::get_matching_stashes( std::vector<stash_search_result> &results) const { - std::vector<LevelStashes>::const_iterator iter = levels.begin(); + stash_levels_t::const_iterator iter = levels.begin(); for ( ; iter != levels.end(); iter++) { - iter->get_matching_stashes(search, results); + iter->second.get_matching_stashes(search, results); if (results.size() > SEARCH_SPAM_THRESHOLD) return; } get_matching_features(search, results); - level_id curr = level_id::get_current_level_id(); + level_id curr = level_id::current(); for (unsigned i = 0; i < results.size(); ++i) results[i].player_distance = level_distance(curr, results[i].pos.id); diff --git a/crawl-ref/source/stash.h b/crawl-ref/source/stash.h index e6bfd8ea5a..489a51d973 100644 --- a/crawl-ref/source/stash.h +++ b/crawl-ref/source/stash.h @@ -15,9 +15,11 @@ #include <vector> #include "externs.h" +#include "misc.h" #include "travel.h" // Stash definitions +void stash_init_new_level(); enum STASH_TRACK_MODES { @@ -205,6 +207,8 @@ public: ShopInfo &get_shop(int x, int y); const ShopInfo *find_shop(int x, int y) const; + level_id where() const; + void get_matching_stashes(const base_pattern &search, std::vector<stash_search_result> &results) const; @@ -239,19 +243,16 @@ public: int stash_count() const { return stashes.size() + shops.size(); } int visible_stash_count() const { return count_stashes() + shops.size(); } - bool isCurrent() const; - bool isBelowPlayer() const; - bool operator < (const LevelStashes &lev) const; + bool is_current() const; private: // which level - unsigned char branch; - int depth; + level_id place; - typedef std::map<int, Stash> c_stashes; - typedef std::vector<ShopInfo> c_shops; + typedef std::map<int, Stash> stashes_t; + typedef std::vector<ShopInfo> shops_t; - c_stashes stashes; - c_shops shops; + stashes_t stashes; + shops_t shops; int count_stashes() const; }; @@ -264,8 +265,7 @@ public: static bool is_level_untrackable() { return you.level_type == LEVEL_LABYRINTH - || you.level_type == LEVEL_ABYSS - || you.level_type == LEVEL_PANDEMONIUM; + || you.level_type == LEVEL_ABYSS; } StashTracker() : levels() @@ -276,13 +276,14 @@ public: LevelStashes &get_current_level(); LevelStashes *find_current_level(); + LevelStashes *find_level(const level_id &pos); ShopInfo &get_shop(int x, int y) { return get_current_level().get_shop(x, y); } - void remove_level(const LevelStashes &ls); + void remove_level(const level_id &which = level_id::current()); enum stash_update_mode { @@ -313,12 +314,15 @@ public: void write(std::ostream &os, bool identify = false) const; void dump(const char *filename, bool identify = false) const; -private: - std::vector<LevelStashes> levels; +private: void get_matching_stashes(const base_pattern &search, std::vector<stash_search_result> &results) const; void display_search_results(std::vector<stash_search_result> &results); + +private: + typedef std::map<level_id, LevelStashes> stash_levels_t; + stash_levels_t levels; }; extern StashTracker stashes; diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index a895044d7b..26a442ccac 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -36,7 +36,7 @@ #endif #define TC_MAJOR_VERSION ((unsigned char) 4) -#define TC_MINOR_VERSION ((unsigned char) 4) +#define TC_MINOR_VERSION ((unsigned char) 5) enum IntertravelDestination { @@ -308,8 +308,7 @@ void clear_excludes() if (can_travel_interlevel()) { - LevelInfo &li = travel_cache.get_level_info( - level_id::get_current_level_id()); + LevelInfo &li = travel_cache.get_level_info(level_id::current()); li.update(); } } @@ -343,8 +342,7 @@ void toggle_exclude(int x, int y) if (can_travel_interlevel()) { - LevelInfo &li = travel_cache.get_level_info( - level_id::get_current_level_id()); + LevelInfo &li = travel_cache.get_level_info(level_id::current()); li.update(); } } @@ -648,7 +646,7 @@ bool is_branch_stair(int gridx, int gridy) { const coord_def pos(gridx, gridy); - const level_id curr = level_id::get_current_level_id(); + const level_id curr = level_id::current(); const level_id next = level_id::get_next_level_id(pos); return (next.branch != curr.branch); @@ -956,10 +954,10 @@ command_type travel() && (travel_target.pos.x != you.x_pos || travel_target.pos.y != you.y_pos || travel_target.id != - level_id::get_current_level_id())) + level_id::current())) { if (last_stair.depth != -1 - && last_stair == level_id::get_current_level_id()) + && last_stair == level_id::current()) { // We're trying to take the same stairs again. Baaad. @@ -977,7 +975,7 @@ command_type travel() // need to make sure we don't go into an infinite loop // trying to take it again and again. We'll check // last_stair before attempting to take stairs again. - last_stair = level_id::get_current_level_id(); + last_stair = level_id::current(); // This is important, else we'll probably stop traveling // the moment we clear the stairs. That's because the @@ -1401,22 +1399,22 @@ static int branch_backout[][2] = * Given a branch id, returns the parent branch. If the branch id is not found, * returns BRANCH_MAIN_DUNGEON. */ -unsigned char find_parent_branch(unsigned char br) +int find_parent_branch(int br) { for (unsigned i = 0; i < sizeof(branch_backout) / sizeof(branch_backout[0]); i++) { if (branch_backout[i][0] == br) - return (unsigned char) branch_backout[i][1]; + return branch_backout[i][1]; } return 0; } extern std::map<branch_type, level_id> stair_level; -void find_parent_branch(unsigned char br, int depth, - unsigned char *pb, int *pd) +void find_parent_branch(int br, int depth, + int *pb, int *pd) { const branch_type bran = static_cast<branch_type>(br); if ( stair_level.find(bran) == stair_level.end() ) @@ -1444,7 +1442,7 @@ void find_parent_branch(unsigned char br, int depth, // (Assuming, of course, that the vector started out empty.) // void trackback(std::vector<level_id> &vec, - unsigned char branch, int subdepth) + int branch, int subdepth) { if (subdepth < 1 || subdepth > MAX_LEVELS) return; @@ -1453,7 +1451,7 @@ void trackback(std::vector<level_id> &vec, if (branch != BRANCH_MAIN_DUNGEON) { - unsigned char pb; + int pb; int pd; find_parent_branch(branch, subdepth, &pb, &pd); if (pd) @@ -1646,7 +1644,7 @@ static int get_nearest_level_depth(unsigned char branch) player_in_branch( BRANCH_GEHENNA ))) return you.hell_exit + 1; - level_id id = level_id::get_current_level_id(); + level_id id = level_id::current(); do { find_parent_branch(id.branch, id.depth, @@ -1848,7 +1846,7 @@ static bool is_hell_branch(int branch) static level_pos find_up_level() { - level_id curr = level_id::get_current_level_id(); + level_id curr = level_id::current(); curr.depth--; if (is_hell_branch(curr.branch)) @@ -1882,7 +1880,7 @@ static level_pos find_up_level() static level_pos find_down_level() { - level_id curr = level_id::get_current_level_id(); + level_id curr = level_id::current(); curr.depth++; return (curr); } @@ -1942,7 +1940,7 @@ void start_translevel_travel(const level_pos &pos) { travel_target = pos; - if (pos.id != level_id::get_current_level_id()) + if (pos.id != level_id::current()) { if (!loadlev_populate_stair_distances(pos)) { @@ -1962,7 +1960,7 @@ void start_translevel_travel(bool prompt_for_destination) { // Update information for this level. We need it even for the prompts, so // we can't wait to confirm that the user chose to initiate travel. - travel_cache.get_level_info(level_id::get_current_level_id()).update(); + travel_cache.get_level_info(level_id::current()).update(); if (prompt_for_destination) { @@ -1976,7 +1974,7 @@ void start_translevel_travel(bool prompt_for_destination) travel_target = target; } - if (level_id::get_current_level_id() == travel_target.id && + if (level_id::current() == travel_target.id && (travel_target.pos.x == -1 || (travel_target.pos.x == you.x_pos && travel_target.pos.y == you.y_pos))) @@ -2041,7 +2039,7 @@ static int find_transtravel_stair( const level_id &cur, const bool target_has_excludes ) { int local_distance = -1; - level_id player_level = level_id::get_current_level_id(); + level_id player_level = level_id::current(); LevelInfo &li = travel_cache.get_level_info(cur); @@ -2261,7 +2259,7 @@ static void populate_stair_distances(const level_pos &target) static int find_transtravel_square(const level_pos &target, bool verbose) { - level_id current = level_id::get_current_level_id(); + level_id current = level_id::current(); coord_def best_stair(-1, -1); coord_def cur_stair(you.x_pos, you.y_pos); @@ -2322,7 +2320,7 @@ void start_travel(int x, int y) is_travel_ok(x, y, false)) { // We'll need interlevel travel to get here. - travel_target.id = level_id::get_current_level_id(); + travel_target.id = level_id::current(); travel_target.pos.x = x; travel_target.pos.y = y; @@ -2403,19 +2401,18 @@ static void readCoord(FILE *file, coord_def &pos) pos.y = readShort(file); } -level_id level_id::get_current_level_id() +level_id level_id::current() { - level_id id; - id.branch = you.where_are_you; - id.depth = subdungeon_depth(you.where_are_you, you.your_level); - + const level_id id(you.where_are_you, + subdungeon_depth(you.where_are_you, you.your_level), + you.level_type); return id; } level_id level_id::get_next_level_id(const coord_def &pos) { short gridc = grd[pos.x][pos.y]; - level_id id = get_current_level_id(); + level_id id = current(); switch (gridc) { @@ -2519,7 +2516,7 @@ level_id level_id::get_next_level_id(const coord_def &pos) unsigned short level_id::packed_place() const { - return get_packed_place(branch, depth, LEVEL_DUNGEON); + return get_packed_place(branch, depth, level_type); } std::string level_id::describe( bool long_name, bool with_number ) const @@ -2529,14 +2526,16 @@ std::string level_id::describe( bool long_name, bool with_number ) const void level_id::save(FILE *file) const { - writeByte(file, branch); + writeShort(file, branch); writeShort(file, depth); + writeShort(file, level_type); } void level_id::load(FILE *file) { - branch = readByte(file); - depth = readShort(file); + branch = readShort(file); + depth = readShort(file); + level_type = readShort(file); } void level_pos::save(FILE *file) const @@ -2999,7 +2998,7 @@ unsigned char TravelCache::is_waypoint(const level_pos &lp) const void TravelCache::update_waypoints() const { level_pos lp; - lp.id = level_id::get_current_level_id(); + lp.id = level_id::current(); memset(curr_waypoints, 0, sizeof curr_waypoints); for (lp.pos.x = 1; lp.pos.x < GXM; ++lp.pos.x) @@ -3062,7 +3061,7 @@ void TravelCache::add_waypoint(int x, int y) y = you.y_pos; } const coord_def pos(x, y); - const level_id &lid = level_id::get_current_level_id(); + const level_id &lid = level_id::current(); LevelInfo &li = get_level_info(lid); li.add_waypoint(pos); @@ -3084,15 +3083,14 @@ int TravelCache::get_waypoint_count() const void TravelCache::reset_distances() { - std::map<level_id, LevelInfo, level_id::less_than>::iterator i = - levels.begin(); + std::map<level_id, LevelInfo>::iterator i = levels.begin(); for ( ; i != levels.end(); ++i) i->second.reset_distances(); } bool TravelCache::is_known_branch(unsigned char branch) const { - std::map<level_id, LevelInfo, level_id::less_than>::const_iterator i = + std::map<level_id, LevelInfo>::const_iterator i = levels.begin(); for ( ; i != levels.end(); ++i) if (i->second.is_known_branch(branch)) @@ -3110,10 +3108,13 @@ void TravelCache::save(FILE *file) const writeShort(file, levels.size()); // Save all the levels we have - std::map<level_id, LevelInfo, level_id::less_than>::const_iterator i = + std::map<level_id, LevelInfo>::const_iterator i = levels.begin(); for ( ; i != levels.end(); ++i) { + if (i->first.level_type != LEVEL_DUNGEON) + continue; + i->first.save(file); i->second.save(file); } @@ -3153,19 +3154,18 @@ void TravelCache::load(FILE *file) void TravelCache::set_level_excludes() { if (can_travel_interlevel()) - get_level_info(level_id::get_current_level_id()).set_level_excludes(); + get_level_info(level_id::current()).set_level_excludes(); } void TravelCache::update() { if (can_travel_interlevel()) - get_level_info(level_id::get_current_level_id()).update(); + get_level_info(level_id::current()).update(); } void TravelCache::fixup_levels() { - std::map<level_id, LevelInfo, level_id::less_than>::iterator i = - levels.begin(); + std::map<level_id, LevelInfo>::iterator i = levels.begin(); for ( ; i != levels.end(); ++i) i->second.fixup(); } diff --git a/crawl-ref/source/travel.h b/crawl-ref/source/travel.h index b84d2d0584..c92dcbfb1a 100644 --- a/crawl-ref/source/travel.h +++ b/crawl-ref/source/travel.h @@ -109,24 +109,34 @@ enum explore_stop_type //////////////////////////////////////////////////////////////////////////// // Structs for interlevel travel. -// Identifies a level. This has no meaning in the Abyss, labyrinths or -// Pandemonium. +// Identifies a level. struct level_id { - unsigned char branch; // The branch in which the level is. - int depth; // What depth (in this branch - starting from 1) - // this level is. - - level_id() : branch(0), depth(-1) { } +public: + int branch; // The branch in which the level is. + int depth; // What depth (in this branch - starting from 1) + int level_type; - level_id(unsigned char br, int dep) : branch(br), depth(dep) { } +public: + level_id() : branch(0), depth(-1), level_type(LEVEL_DUNGEON) { } + level_id(int br, int dep, int ltype = LEVEL_DUNGEON) + : branch(br), depth(dep), level_type(ltype) + { + if (level_type != LEVEL_DUNGEON) + branch = depth = -1; + } + level_id(int ltype) : branch(-1), depth(-1), level_type(ltype) { } unsigned short packed_place() const; + std::string describe(bool long_name = false, bool with_number = true) const; - std::string describe( bool long_name, bool with_number ) const; + bool is_valid() const + { + return (branch != -1 && depth != -1) || level_type != LEVEL_DUNGEON; + } // Returns the level_id of the current level. - static level_id get_current_level_id(); + static level_id current(); // Returns the level_id of the level that the stair/portal/whatever at // 'pos' on the current level leads to. @@ -134,28 +144,24 @@ struct level_id bool operator == ( const level_id &id ) const { - return branch == id.branch && depth == id.depth; + return branch == id.branch && depth == id.depth + && level_type == id.level_type; } bool operator != ( const level_id &id ) const { - return branch != id.branch || depth != id.depth; + return branch != id.branch || depth != id.depth + || level_type != id.level_type; } bool operator <( const level_id &id ) const { + if (level_type != id.level_type) + return (level_type < id.level_type); + return (branch < id.branch) || (branch==id.branch && depth < id.depth); } - struct less_than - { - bool operator () (const level_id &first, const level_id &second) const - { - return first.branch < second.branch || - (first.branch == second.branch && first.depth < second.depth); - } - }; - void save(FILE *) const; void load(FILE *); }; @@ -359,6 +365,12 @@ public: return li; } + LevelInfo *find_level_info(const level_id &lev) + { + std::map<level_id, LevelInfo>::iterator i = levels.find(lev); + return (i != levels.end()? &i->second : NULL); + } + bool know_level(const level_id &lev) const { return levels.find(lev) != levels.end(); @@ -391,7 +403,7 @@ private: void fixup_levels(); private: - std::map<level_id, LevelInfo, level_id::less_than> levels; + std::map<level_id, LevelInfo> levels; level_pos waypoints[TRAVEL_WAYPOINT_COUNT]; }; |