3 * Summary: Classes tracking player stashes
4 * Written by: Darshan Shaligram
26 void stash_init_new_level();
28 enum STASH_TRACK_MODES
30 STM_NONE
, // Stashes are not tracked
31 STM_EXPLICIT
, // Only explicitly marked stashes are tracked
32 STM_DROPPED
, // Dropped items and explicitly marked stashes are
34 STM_ALL
, // All seen items are tracked
37 struct stash_search_result
;
41 Stash(int xp
= -1, int yp
= -1);
43 static bool is_boring_feature(dungeon_feature_type feat
);
44 static void filter(object_class_type base_type
, uint8_t sub_type
);
45 static void filter(const std::string
&filt
);
47 static std::string
stash_item_name(const item_def
&item
);
49 void save(writer
&) const;
52 std::string
description() const;
53 std::string
feature_description() const;
54 std::vector
<item_def
> get_items() const;
56 bool show_menu(const level_pos
&place
, bool can_travel
) const;
58 // Returns true if this Stash contains items that are eligible for
60 bool pickup_eligible() const;
62 // Returns true if this Stash is unverified (a visit by the character will
64 bool unverified() const;
66 bool matches_search(const std::string
&prefix
,
67 const base_pattern
&search
,
68 stash_search_result
&res
)
71 void write(std::ostream
&os
, int refx
= 0, int refy
= 0,
72 std::string place
= "",
73 bool identify
= false) const;
77 return enabled
&& items
.empty() && feat
== DNGN_FLOOR
;
80 bool isAt(const coord_def
& c
) const { return c
.x
== x
&& c
.y
== y
; }
81 int abs_pos() const { return abspos
; }
82 int getX() const { return x
; }
83 int getY() const { return y
; }
85 bool is_verified() const { return verified
; }
87 bool enabled
; // If false, this Stash will neither track
88 // items nor dump itself. Disabled stashes are
89 // also never removed from the level's map of
93 static bool is_filtered(const item_def
&item
);
96 void _update_corpses(int rot_time
);
97 void add_item(const item_def
&item
, bool add_to_front
= false);
100 bool verified
; // Is this correct to the best of our knowledge?
103 dungeon_feature_type feat
;
106 std::vector
<item_def
> items
;
109 * If true (the default), the stash-tracker is a lot more likely to consider
110 * squares that the player is not standing on as correctly-verified. This
111 * will lead to cleaner dumps, but the chance of stashes not accurately
112 * reflecting what's in the dungeon also increases.
114 static bool aggressive_verify
;
115 static std::vector
<item_def
> filters
;
117 static bool are_items_same(const item_def
&, const item_def
&);
119 friend class LevelStashes
;
120 friend class ST_ItemIterator
;
126 ShopInfo(int xp
, int yp
);
128 bool matches_search(const std::string
&prefix
,
129 const base_pattern
&search
,
130 stash_search_result
&res
)
133 std::string
description() const;
135 void save(writer
&) const;
138 bool show_menu(const level_pos
&place
, bool can_travel
) const;
139 bool is_visited() const { return items
.size() || visited
; }
141 void write(std::ostream
&os
, bool identify
= false) const;
143 void reset() { items
.clear(); visited
= true; }
144 void set_name(const std::string
& s
) { name
= s
; }
146 void add_item(const item_def
&item
, unsigned price
);
148 bool isAt(const coord_def
& c
) const { return x
== c
.x
&& y
== c
.y
; }
163 // Set true if the player has visited this shop
166 std::vector
<shop_item
> items
;
168 std::string
shop_item_name(const shop_item
&si
) const;
169 std::string
shop_item_desc(const shop_item
&si
) const;
170 void describe_shop_item(const shop_item
&si
) const;
171 void fill_out_menu(StashMenu
&menu
, const level_pos
&place
) const;
173 friend class ST_ItemIterator
;
176 struct stash_search_result
178 // Where's this thingummy of interest.
181 // Number of levels the player must cross to reach the level the stash/shop
185 // Number of items in the stash that match the search.
188 // Count of items stacks in the stash that matched. This will be the same as
189 // matches if each matching stack's quantity is 1.
192 // Text that describes this search result - usually the name of
193 // the first matching item in the stash or the name of the shop.
196 // The stash or shop in question. Both can be null if this is a feature.
198 const ShopInfo
*shop
;
200 stash_search_result() : pos(), player_distance(0), matches(0),
201 count(0), match(), stash(NULL
), shop(NULL
)
205 bool operator < (const stash_search_result
&ssr
) const
207 return (player_distance
< ssr
.player_distance
208 || (player_distance
== ssr
.player_distance
209 && matches
> ssr
.matches
));
213 extern std::ostream
&operator << (std::ostream
&, const Stash
&);
220 const Stash
*find_stash(coord_def c
) const;
221 Stash
*find_stash(coord_def c
);
222 const ShopInfo
*find_shop(const coord_def
& c
) const;
223 ShopInfo
&get_shop(const coord_def
& c
);
225 level_id
where() const;
227 void get_matching_stashes(const base_pattern
&search
,
228 std::vector
<stash_search_result
> &results
) const;
230 // Update stash at (x,y) on current level, defaulting to player's current
231 // location if no parameters are supplied.
232 bool update_stash(const coord_def
& c
);
234 // Returns true if the square at c contains potentially interesting
235 // swag that merits a personal visit (for EXPLORE_GREEDY).
236 bool needs_visit(const coord_def
& c
) const;
237 bool shop_needs_visit(const coord_def
& c
) const;
239 // Returns true if the items at c are not fully known to the stash-tracker
240 // and can be updated if the character steps on the square.
241 bool unverified_stash(const coord_def
&c
) const;
243 // Add stash at (x,y), or player's current location if no parameters are
245 void add_stash(int x
= -1, int y
= -1);
247 // Mark square (x,y) as not stashworthy. The player's current location is
248 // used if no parameters are supplied.
249 void no_stash(int x
= -1, int y
= -1);
251 void kill_stash(const Stash
&s
);
253 void save(writer
&) const;
256 void write(std::ostream
&os
, bool identify
= false) const;
257 std::string
level_name() const;
258 std::string
short_level_name() const;
260 int stash_count() const { return m_stashes
.size() + m_shops
.size(); }
261 int visible_stash_count() const { return _num_enabled_stashes() + m_shops
.size(); }
263 bool is_current() const;
265 void remove_shop(const coord_def
& c
);
267 int _num_enabled_stashes() const;
268 void _update_corpses(int rot_time
);
271 typedef std::map
<int, Stash
> stashes_t
;
272 typedef std::vector
<ShopInfo
> shops_t
;
279 friend class StashTracker
;
280 friend class ST_ItemIterator
;
283 extern std::ostream
&operator << (std::ostream
&, const LevelStashes
&);
288 static bool is_level_untrackable()
290 return you
.level_type
== LEVEL_LABYRINTH
291 || you
.level_type
== LEVEL_ABYSS
;
294 StashTracker() : levels(), last_corpse_update(0)
298 void search_stashes();
300 LevelStashes
&get_current_level();
301 LevelStashes
*find_current_level();
302 LevelStashes
*find_level(const level_id
&pos
);
304 ShopInfo
&get_shop(const coord_def
& c
)
306 return get_current_level().get_shop(c
);
309 void remove_level(const level_id
&which
= level_id::current());
311 enum stash_update_mode
313 ST_PASSIVE
, // Maintain existing stashes only.
314 ST_AGGRESSIVE
, // Create stashes for each square containing
315 // objects, even if those squares were not
316 // previously marked as stashes.
319 void update_corpses();
321 void update_visible_stashes(StashTracker::stash_update_mode
= ST_PASSIVE
);
323 // Update stash at (x,y) on current level, defaulting to player's current
324 // location if no parameters are supplied, return true if a stash was
326 bool update_stash(const coord_def
& c
);
328 // Add stash at (x,y), or player's current location if no parameters are
330 void add_stash(int x
= -1, int y
= -1, bool verbose
= false);
332 // Mark square (x,y) as not stashworthy. The player's current location is
333 // used if no parameters are supplied.
334 void no_stash(int x
= -1, int y
= -1);
336 void save(writer
&) const;
339 void write(std::ostream
&os
, bool identify
= false) const;
341 void dump(const char *filename
, bool identify
= false) const;
343 void remove_shop(const coord_def
& c
);
345 void get_matching_stashes(const base_pattern
&search
,
346 std::vector
<stash_search_result
> &results
) const;
347 bool display_search_results(std::vector
<stash_search_result
> &results
,
348 const char* sort_style
);
349 std::string
stash_search_prompt();
352 typedef std::map
<level_id
, LevelStashes
> stash_levels_t
;
353 stash_levels_t levels
;
355 int last_corpse_update
;
357 friend class ST_ItemIterator
;
360 class ST_ItemIterator
365 const ST_ItemIterator
& operator ++ ();
366 ST_ItemIterator
operator ++ (int);
368 operator bool() const;
369 const item_def
& operator *() const;
370 const item_def
* operator->() const;
372 const level_id
&place();
373 const ShopInfo
* shop();
378 const item_def
* m_item
;
380 const ShopInfo
* m_shop
;
382 StashTracker::stash_levels_t::const_iterator m_stash_level_it
;
383 LevelStashes::stashes_t::const_iterator m_stash_it
;
384 LevelStashes::shops_t::const_iterator m_shop_it
;
385 std::vector
<item_def
>::const_iterator m_stash_item_it
;
387 std::vector
<ShopInfo::shop_item
>::const_iterator m_shop_item_it
;
393 extern StashTracker StashTrack
;
395 void maybe_update_stashes();
396 bool is_stash(const coord_def
& c
);
397 std::string
get_stash_desc(const coord_def
& c
);
398 void describe_stash(const coord_def
& c
);
400 std::vector
<item_def
> item_list_in_stash(const coord_def
& pos
);
402 std::string
userdef_annotate_item(const char *s
, const item_def
*item
,
403 bool exclusive
= false);
405 #define STASH_LUA_SEARCH_ANNOTATE "ch_stash_search_annotate_item"
406 #define STASH_LUA_DUMP_ANNOTATE "ch_stash_dump_annotate_item"
407 #define STASH_LUA_VIEW_ANNOTATE "ch_stash_view_annotate_item"