Apply the new ground_level method.
[crawl.git] / crawl-ref / source / directn.h
blobfaea2c1fc14449f15dfef65500e563df697b9252
1 /*
2 * File: directn.h
3 * Summary: Functions used when picking squares.
4 * Written by: Linley Henzell
5 */
8 #ifndef DIRECT_H
9 #define DIRECT_H
11 #include "describe.h"
12 #include "externs.h"
13 #include "enum.h"
14 #include "ray.h"
15 #include "state.h"
17 class range_view_annotator
19 public:
20 range_view_annotator(int range);
21 virtual ~range_view_annotator();
24 // An object that modifies the behaviour of the direction prompt.
25 class targeting_behaviour
27 public:
28 targeting_behaviour(bool just_looking = false);
29 virtual ~targeting_behaviour();
31 // Returns a keystroke for the prompt.
32 virtual int get_key();
33 virtual command_type get_command(int key = -1);
35 // Should we force a redraw?
36 virtual bool should_redraw() const { return false; }
37 // Clear the bit set above.
38 virtual void clear_redraw() { return; }
40 // Update the prompt shown at top.
41 virtual void update_top_prompt(std::string* p_top_prompt) {}
43 private:
44 std::string prompt;
46 public:
47 bool just_looking;
48 bool compass;
51 // output from direction() function:
52 class dist
54 public:
55 dist();
57 bool isMe() const;
58 void confusion_fuzz(); // modify target as if the player is confused.
60 bool isValid; // valid target chosen?
61 bool isTarget; // target (true), or direction (false)?
62 bool isEndpoint; // Does the player want the attack to stop at target?
63 bool isCancel; // user cancelled (usually <ESC> key)
64 bool choseRay; // user wants a specific beam
65 coord_def target; // target x,y or logical extension of beam to map edge
66 coord_def delta; // delta x and y if direction - always -1,0,1
67 ray_def ray; // ray chosen if necessary
70 struct direction_chooser_args
72 targeting_type restricts;
73 targ_mode_type mode;
74 int range;
75 bool just_looking;
76 bool needs_path;
77 bool may_target_monster;
78 bool may_target_self;
79 const char *target_prefix;
80 std::string top_prompt;
81 targeting_behaviour *behaviour;
82 bool cancel_at_self;
83 bool show_floor_desc;
85 direction_chooser_args() :
86 restricts(DIR_NONE),
87 mode(TARG_ANY),
88 range(-1),
89 just_looking(false),
90 needs_path(true),
91 may_target_monster(true),
92 may_target_self(false),
93 target_prefix(NULL),
94 behaviour(NULL),
95 cancel_at_self(false),
96 show_floor_desc(false) {}
99 class direction_chooser
101 public:
102 direction_chooser(dist& moves, const direction_chooser_args& args);
103 bool choose_direction();
105 private:
106 bool choose_compass(); // Used when we only need to choose a direction
108 bool do_main_loop();
110 // Return the location where targeting should start.
111 coord_def find_default_target() const;
113 void handle_mlist_cycle_command(command_type key_command);
114 void handle_wizard_command(command_type key_command, bool* loop_done);
115 void handle_movement_key(command_type key_command, bool* loop_done);
117 bool in_range(const coord_def& p) const;
119 // Jump to the player.
120 void move_to_you();
122 // Cycle to the next (dir == 1) or previous (dir == -1) object.
123 void object_cycle(int dir);
125 // Cycle to the next (dir == 1) or previous (dir == -1) monster.
126 void monster_cycle(int dir);
128 // Cycle to the next feature of the given type.
129 void feature_cycle_forward(int feature);
131 // Set the remembered target to be the current target.
132 void update_previous_target() const;
134 // Finalise the current choice of target. Return true if
135 // successful, false if failed (e.g. out of range.)
136 bool select(bool allow_out_of_range, bool endpoint);
137 bool select_compass_direction(const coord_def& delta);
138 bool select_previous_target();
140 // Return true if we need to abort targeting due to a signal.
141 bool handle_signals();
143 void reinitialize_move_flags();
145 // Return or set the current target.
146 const coord_def& target() const;
147 void set_target(const coord_def& new_target);
149 std::string build_targeting_hint_string() const;
151 actor* targeted_actor() const;
152 monster* targeted_monster() const;
154 // Functions which print things to the user.
155 // Each one is commented with a sample output.
157 // Whatever the caller defines. Typically something like:
158 // Casting: Venom Bolt.
159 // Can be modified by the targeting_behaviour.
160 void print_top_prompt() const;
162 // Press: ? - help, Shift-Dir - straight line, t - megabat
163 void print_key_hints() const;
165 // Here: An orc wizard, wielding a glowing orcish dagger, and wearing
166 // an orcish robe (miasma, silenced, almost dead)
167 // OR:
168 // Apport: A short sword.
169 void print_target_description(bool &did_cloud) const;
171 // Helper functions for the above.
172 void print_target_monster_description(bool &did_cloud) const;
173 void print_target_object_description() const;
175 // You see 2 +3 dwarven bolts here.
176 // There is something else lying underneath.
177 void print_items_description() const;
179 // Lava.
181 // If boring_too is false, then don't print anything on boring
182 // terrain (i.e. floor.)
183 void print_floor_description(bool boring_too) const;
185 std::string target_interesting_terrain_description() const;
186 std::string target_cloud_description() const;
187 std::string target_sanctuary_description() const;
188 std::string target_silence_description() const;
189 std::vector<std::string> target_cell_description_suffixes() const;
190 std::vector<std::string> monster_description_suffixes(
191 const monster_info& mi) const;
193 void describe_cell() const;
195 // Move the target to where the mouse pointer is (on tiles.)
196 // Returns whether the move was valid, i.e., whether the mouse
197 // pointer is in bounds.
198 bool tiles_update_target();
200 // Display the prompt when beginning targeting.
201 void show_initial_prompt();
203 void toggle_beam();
205 void finalize_moves();
206 command_type massage_command(command_type key_command) const;
207 void draw_beam_if_needed();
208 void do_redraws();
210 // Whether the current target is you.
211 bool looking_at_you() const;
213 // Whether the current target is valid.
214 bool move_is_ok() const;
216 void cycle_targeting_mode();
218 void describe_target();
219 void show_help();
221 // Parameters.
222 dist& moves; // Output.
223 targeting_type restricts; // What kind of target do we want?
224 targ_mode_type mode; // Hostiles or friendlies?
225 int range; // Max range to consider
226 bool just_looking;
227 bool needs_path; // Determine a ray while we're at it?
228 bool may_target_monster;
229 bool may_target_self; // ?? XXX Used only for _init_mlist() currently
230 const char *target_prefix; // A string displayed before describing target
231 std::string top_prompt; // Shown at the top of the message window
232 targeting_behaviour *behaviour; // Can be NULL for default
233 bool cancel_at_self; // Disallow self-targeting?
234 bool show_floor_desc; // Describe the floor of the current target
236 // Internal data.
237 ray_def beam; // The (possibly invalid) beam.
238 bool show_beam; // Does the user want the beam displayed?
239 bool have_beam; // Is the currently stored beam valid?
240 coord_def objfind_pos, monsfind_pos; // Cycling memory
242 // What we need to redraw.
243 bool need_beam_redraw;
244 bool need_cursor_redraw;
245 bool need_text_redraw;
246 bool need_all_redraw; // All of the above.
248 bool show_items_once; // Should we show items this time?
249 bool target_unshifted; // Do unshifted direction keys fire?
251 // Default behaviour, saved across instances.
252 static targeting_behaviour stock_behaviour;
256 #ifndef USE_TILE
257 char mlist_index_to_letter(int index);
258 #endif
260 void direction(dist &moves, const direction_chooser_args& args);
262 std::string thing_do_grammar(description_level_type dtype,
263 bool add_stop,
264 bool force_article,
265 std::string desc);
267 std::string get_terse_square_desc(const coord_def &gc);
268 void terse_describe_square(const coord_def &c, bool in_range = true);
269 void full_describe_square(const coord_def &c);
270 void get_square_desc(const coord_def &c, describe_info &inf,
271 bool examine_mons = false, bool show_floor = false);
273 void describe_floor();
274 std::string get_monster_equipment_desc(const monster_info& mi,
275 bool full_desc = true,
276 description_level_type mondtype = DESC_CAP_A,
277 bool print_attitude = false);
279 int dos_direction_unmunge(int doskey);
281 std::string feature_description(const coord_def& where, bool covering = false,
282 description_level_type dtype = DESC_CAP_A,
283 bool add_stop = true, bool base_desc = false);
284 std::string raw_feature_description(dungeon_feature_type grid,
285 trap_type tr = NUM_TRAPS,
286 bool base_desc = false);
287 std::string feature_description(dungeon_feature_type grid,
288 trap_type trap = NUM_TRAPS,
289 const std::string & cover_desc = "",
290 description_level_type dtype = DESC_CAP_A,
291 bool add_stop = true, bool base_desc = false);
293 void set_feature_desc_short(dungeon_feature_type grid,
294 const std::string &desc);
295 void set_feature_desc_short(const std::string &base_name,
296 const std::string &desc);
298 void setup_feature_descs_short();
300 std::vector<dungeon_feature_type> features_by_desc(const base_pattern &pattern);
302 void full_describe_view(void);
304 extern const struct coord_def Compass[8];
306 #endif