00001
00002
00003
00004
00005
00006
00007 #ifndef STASH_H
00008 #define STASH_H
00009
00010 #include "shopping.h"
00011 #include <string>
00012
00013 #include <iostream>
00014 #include <map>
00015 #include <vector>
00016
00017 #include "externs.h"
00018 #include "player.h"
00019
00020 class input_history;
00021 class reader;
00022 class writer;
00023 class StashMenu;
00024
00025
00026 void stash_init_new_level();
00027
00028 enum STASH_TRACK_MODES
00029 {
00030 STM_NONE,
00031 STM_EXPLICIT,
00032 STM_DROPPED,
00033
00034 STM_ALL,
00035 };
00036
00037 struct stash_search_result;
00038 class Stash
00039 {
00040 public:
00041 Stash(int xp = -1, int yp = -1);
00042
00043 static bool is_boring_feature(dungeon_feature_type feat);
00044 static void filter(object_class_type base_type, uint8_t sub_type);
00045 static void filter(const std::string &filt);
00046
00047 static std::string stash_item_name(const item_def &item);
00048 void update();
00049 void save(writer&) const;
00050 void load(reader&);
00051
00052 std::string description() const;
00053 std::string feature_description() const;
00054 std::vector<item_def> get_items() const;
00055
00056 bool show_menu(const level_pos &place, bool can_travel) const;
00057
00058
00059
00060 bool pickup_eligible() const;
00061
00062
00063
00064 bool unverified() const;
00065
00066 bool matches_search(const std::string &prefix,
00067 const base_pattern &search,
00068 stash_search_result &res)
00069 const;
00070
00071 void write(std::ostream &os, int refx = 0, int refy = 0,
00072 std::string place = "",
00073 bool identify = false) const;
00074
00075 bool empty() const
00076 {
00077 return enabled && items.empty() && feat == DNGN_FLOOR;
00078 }
00079
00080 bool isAt(const coord_def& c) const { return c.x == x && c.y == y; }
00081 int abs_pos() const { return abspos; }
00082 int getX() const { return x; }
00083 int getY() const { return y; }
00084
00085 bool is_verified() const { return verified; }
00086
00087 bool enabled;
00088
00089
00090
00091
00092 public:
00093 static bool is_filtered(const item_def &item);
00094
00095 private:
00096 void _update_corpses(int rot_time);
00097 void add_item(const item_def &item, bool add_to_front = false);
00098
00099 private:
00100 bool verified;
00101 uint8_t x, y;
00102 int abspos;
00103 dungeon_feature_type feat;
00104 trap_type trap;
00105
00106 std::vector<item_def> items;
00107
00108
00109
00110
00111
00112
00113
00114 static bool aggressive_verify;
00115 static std::vector<item_def> filters;
00116
00117 static bool are_items_same(const item_def &, const item_def &);
00118
00119 friend class LevelStashes;
00120 friend class ST_ItemIterator;
00121 };
00122
00123 class ShopInfo
00124 {
00125 public:
00126 ShopInfo(int xp, int yp);
00127
00128 bool matches_search(const std::string &prefix,
00129 const base_pattern &search,
00130 stash_search_result &res)
00131 const;
00132
00133 std::string description() const;
00134
00135 void save(writer&) const;
00136 void load(reader&);
00137
00138 bool show_menu(const level_pos &place, bool can_travel) const;
00139 bool is_visited() const { return items.size() || visited; }
00140
00141 void write(std::ostream &os, bool identify = false) const;
00142
00143 void reset() { items.clear(); visited = true; }
00144 void set_name(const std::string& s) { name = s; }
00145
00146 void add_item(const item_def &item, unsigned price);
00147
00148 bool isAt(const coord_def& c) const { return x == c.x && y == c.y; }
00149
00150
00151 struct shop_item
00152 {
00153 item_def item;
00154 unsigned price;
00155 };
00156
00157 private:
00158 int x, y;
00159 std::string name;
00160
00161 int shoptype;
00162
00163
00164 bool visited;
00165
00166 std::vector<shop_item> items;
00167
00168 std::string shop_item_name(const shop_item &si) const;
00169 std::string shop_item_desc(const shop_item &si) const;
00170 void describe_shop_item(const shop_item &si) const;
00171 void fill_out_menu(StashMenu &menu, const level_pos &place) const;
00172
00173 friend class ST_ItemIterator;
00174 };
00175
00176 struct stash_search_result
00177 {
00178
00179 level_pos pos;
00180
00181
00182
00183 int player_distance;
00184
00185
00186 int matches;
00187
00188
00189
00190 int count;
00191
00192
00193
00194 std::string match;
00195
00196
00197 const Stash *stash;
00198 const ShopInfo *shop;
00199
00200 stash_search_result() : pos(), player_distance(0), matches(0),
00201 count(0), match(), stash(NULL), shop(NULL)
00202 {
00203 }
00204
00205 bool operator < (const stash_search_result &ssr) const
00206 {
00207 return (player_distance < ssr.player_distance
00208 || (player_distance == ssr.player_distance
00209 && matches > ssr.matches));
00210 }
00211 };
00212
00213 extern std::ostream &operator << (std::ostream &, const Stash &);
00214
00215 class LevelStashes
00216 {
00217 public:
00218 LevelStashes();
00219
00220 const Stash *find_stash(coord_def c) const;
00221 Stash *find_stash(coord_def c);
00222 const ShopInfo *find_shop(const coord_def& c) const;
00223 ShopInfo &get_shop(const coord_def& c);
00224
00225 level_id where() const;
00226
00227 void get_matching_stashes(const base_pattern &search,
00228 std::vector<stash_search_result> &results) const;
00229
00230
00231
00232 bool update_stash(const coord_def& c);
00233
00234
00235
00236 bool needs_visit(const coord_def& c) const;
00237 bool shop_needs_visit(const coord_def& c) const;
00238
00239
00240
00241 bool unverified_stash(const coord_def &c) const;
00242
00243
00244
00245 void add_stash(int x = -1, int y = -1);
00246
00247
00248
00249 void no_stash(int x = -1, int y = -1);
00250
00251 void kill_stash(const Stash &s);
00252
00253 void save(writer&) const;
00254 void load(reader&);
00255
00256 void write(std::ostream &os, bool identify = false) const;
00257 std::string level_name() const;
00258 std::string short_level_name() const;
00259
00260 int stash_count() const { return m_stashes.size() + m_shops.size(); }
00261 int visible_stash_count() const { return _num_enabled_stashes() + m_shops.size(); }
00262
00263 bool is_current() const;
00264
00265 void remove_shop(const coord_def& c);
00266 private:
00267 int _num_enabled_stashes() const;
00268 void _update_corpses(int rot_time);
00269
00270 private:
00271 typedef std::map<int, Stash> stashes_t;
00272 typedef std::vector<ShopInfo> shops_t;
00273
00274
00275 level_id m_place;
00276 stashes_t m_stashes;
00277 shops_t m_shops;
00278
00279 friend class StashTracker;
00280 friend class ST_ItemIterator;
00281 };
00282
00283 extern std::ostream &operator << (std::ostream &, const LevelStashes &);
00284
00285 class StashTracker
00286 {
00287 public:
00288 static bool is_level_untrackable()
00289 {
00290 return you.level_type == LEVEL_LABYRINTH
00291 || you.level_type == LEVEL_ABYSS;
00292 }
00293
00294 StashTracker() : levels(), last_corpse_update(0)
00295 {
00296 }
00297
00298 void search_stashes();
00299
00300 LevelStashes &get_current_level();
00301 LevelStashes *find_current_level();
00302 LevelStashes *find_level(const level_id &pos);
00303
00304 ShopInfo &get_shop(const coord_def& c)
00305 {
00306 return get_current_level().get_shop(c);
00307 }
00308
00309 void remove_level(const level_id &which = level_id::current());
00310
00311 enum stash_update_mode
00312 {
00313 ST_PASSIVE,
00314 ST_AGGRESSIVE,
00315
00316
00317 };
00318
00319 void update_corpses();
00320
00321 void update_visible_stashes(StashTracker::stash_update_mode = ST_PASSIVE);
00322
00323
00324
00325
00326 bool update_stash(const coord_def& c);
00327
00328
00329
00330 void add_stash(int x = -1, int y = -1, bool verbose = false);
00331
00332
00333
00334 void no_stash(int x = -1, int y = -1);
00335
00336 void save(writer&) const;
00337 void load(reader&);
00338
00339 void write(std::ostream &os, bool identify = false) const;
00340
00341 void dump(const char *filename, bool identify = false) const;
00342
00343 void remove_shop(const coord_def& c);
00344 private:
00345 void get_matching_stashes(const base_pattern &search,
00346 std::vector<stash_search_result> &results) const;
00347 bool display_search_results(std::vector<stash_search_result> &results,
00348 const char* sort_style);
00349 std::string stash_search_prompt();
00350
00351 private:
00352 typedef std::map<level_id, LevelStashes> stash_levels_t;
00353 stash_levels_t levels;
00354
00355 int last_corpse_update;
00356
00357 friend class ST_ItemIterator;
00358 };
00359
00360 class ST_ItemIterator
00361 {
00362 public:
00363 ST_ItemIterator();
00364
00365 const ST_ItemIterator& operator ++ ();
00366 ST_ItemIterator operator ++ (int);
00367
00368 operator bool() const;
00369 const item_def& operator *() const;
00370 const item_def* operator->() const;
00371
00372 const level_id &place();
00373 const ShopInfo* shop();
00374 unsigned price();
00375
00376 private:
00377 level_id m_place;
00378 const item_def* m_item;
00379 unsigned m_price;
00380 const ShopInfo* m_shop;
00381
00382 StashTracker::stash_levels_t::const_iterator m_stash_level_it;
00383 LevelStashes::stashes_t::const_iterator m_stash_it;
00384 LevelStashes::shops_t::const_iterator m_shop_it;
00385 std::vector<item_def>::const_iterator m_stash_item_it;
00386
00387 std::vector<ShopInfo::shop_item>::const_iterator m_shop_item_it;
00388
00389 private:
00390 void new_level();
00391 };
00392
00393 extern StashTracker StashTrack;
00394
00395 void maybe_update_stashes();
00396 bool is_stash(const coord_def& c);
00397 std::string get_stash_desc(const coord_def& c);
00398 void describe_stash(const coord_def& c);
00399
00400 std::vector<item_def> item_list_in_stash(const coord_def& pos);
00401
00402 std::string userdef_annotate_item(const char *s, const item_def *item,
00403 bool exclusive = false);
00404
00405 #define STASH_LUA_SEARCH_ANNOTATE "ch_stash_search_annotate_item"
00406 #define STASH_LUA_DUMP_ANNOTATE "ch_stash_dump_annotate_item"
00407 #define STASH_LUA_VIEW_ANNOTATE "ch_stash_view_annotate_item"
00408
00409 #endif