Angband
Functions
ui-target.c File Reference

UI for targetting code. More...

#include "angband.h"
#include "cave.h"
#include "game-input.h"
#include "init.h"
#include "mon-desc.h"
#include "mon-lore.h"
#include "monster.h"
#include "obj-desc.h"
#include "obj-pile.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-timed.h"
#include "project.h"
#include "target.h"
#include "trap.h"
#include "ui-input.h"
#include "ui-keymap.h"
#include "ui-map.h"
#include "ui-mon-lore.h"
#include "ui-obj.h"
#include "ui-output.h"
#include "ui-target.h"
#include "ui-term.h"

Functions

int target_dir (struct keypress ch)
 Extract a direction (or zero) from a character.
int target_dir_allow (struct keypress ch, bool allow_5)
void target_display_help (bool monster, bool free)
 Display targeting help at the bottom of the screen.
static bool adjust_panel_help (int y, int x, bool help)
 Perform the minimum "whole panel" adjustment to ensure that the given location is contained inside the current panel, and return TRUE if any such adjustment was performed.
static ui_event target_recall_loop_object (object_type *o_ptr, int y, int x, char out_val[TARGET_OUT_VAL_SIZE], const char *s1, const char *s2, const char *s3, char *coords)
 Display the object name of the selected object and allow for full object recall.
static ui_event target_set_interactive_aux (int y, int x, int mode)
 Examine a grid, return a keypress.
void textui_target (void)
 Target command.
void textui_target_closest (void)
 Target closest monster.
static int draw_path (u16b path_n, struct loc *path_g, wchar_t *c, int *a, int y1, int x1)
 Draw a visible path over the squares between (x1,y1) and (x2,y2).
static void load_path (u16b path_n, struct loc *path_g, wchar_t *c, int *a)
 Load the attr/char at each point along "path" which is on screen from "a" and "c".
bool target_set_interactive (int mode, int x, int y)
 Handle "target" and "look".

Detailed Description

UI for targetting code.

Copyright (c) 1997-2014 Angband contributors

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Function Documentation

static bool adjust_panel_help ( int  y,
int  x,
bool  help 
)
static

Perform the minimum "whole panel" adjustment to ensure that the given location is contained inside the current panel, and return TRUE if any such adjustment was performed.

Optionally accounts for the targeting help window.

References angband_term, ANGBAND_TERM_MAX, COL_MAP, FALSE, term::hgt, modify_panel(), term::offset_x, term::offset_y, PW_MAP, ROW_MAP, Term, tile_height, tile_width, TRUE, term::wid, and window_flag.

Referenced by target_set_interactive().

static int draw_path ( u16b  path_n,
struct loc path_g,
wchar_t *  c,
int a,
int  y1,
int  x1 
)
static

Draw a visible path over the squares between (x1,y1) and (x2,y2).

The path consists of "*", which are white except where there is a monster, object or feature in the grid.

This routine has (at least) three weaknesses:

  • remembered objects/walls which are no longer present are not shown,
  • squares which (e.g.) the player has walked through in the dark are treated as unknown space.
  • walls which appear strange due to hallucination aren't treated correctly.

The first two result from information being lost from the dungeon arrays, which requires changes elsewhere

References cave, COLOUR_BLUE, COLOUR_L_DARK, COLOUR_L_RED, COLOUR_WHITE, COLOUR_YELLOW, term_win::cx, term_win::cy, monster_race::flags, i, object::marked, monster::mflag, mflag_has, move_cursor_relative(), panel_contains(), player_can_see_bold(), monster::race, rf_has, term::scr, square_ismark(), square_isprojectable(), square_monster(), square_object(), Term, Term_addch(), Term_what(), TRUE, void(), loc::x, and loc::y.

Referenced by target_set_interactive().

static void load_path ( u16b  path_n,
struct loc path_g,
wchar_t *  c,
int a 
)
static

Load the attr/char at each point along "path" which is on screen from "a" and "c".

This was saved in draw_path().

References i, move_cursor_relative(), panel_contains(), Term_addch(), Term_fresh(), loc::x, and loc::y.

Referenced by target_set_interactive().

int target_dir ( struct keypress  ch)
int target_dir_allow ( struct keypress  ch,
bool  allow_5 
)
void target_display_help ( bool  monster,
bool  free 
)
static ui_event target_recall_loop_object ( object_type o_ptr,
int  y,
int  x,
char  out_val[TARGET_OUT_VAL_SIZE],
const char *  s1,
const char *  s2,
const char *  s3,
char *  coords 
)
static

Display the object name of the selected object and allow for full object recall.

Returns an event that occurred display.

This will only work for a single object on the ground and not a pile. This loop is similar to the monster recall loop in target_set_interactive_aux(). The out_val array size needs to match the size that is passed in (since this code was extracted from there).

Parameters
o_ptris the object to describe.
yis the cave row of the object.
xis the cave column of the object.
out_valis the string that holds the name of the object and is returned to the caller.
s1is part of the output string.
s2is part of the output string.
s3is part of the output string.
coordsis part of the output string

References mouseclick::button, cave, keypress::code, square::cost, display_object_recall_interactive(), EVT_KBRD, EVT_MOUSE, FALSE, inkey_m(), ui_event::key, KEY_GRID_X, KEY_GRID_Y, ui_event::mouse, move_cursor_relative(), object_desc(), ODESC_FULL, ODESC_PREFIX, prt(), chunk::squares, strnfmt(), ui_event::type, square::when, and player::wizard.

Referenced by target_set_interactive_aux().

bool target_set_interactive ( int  mode,
int  x,
int  y 
)

Handle "target" and "look".

Note that this code can be called from "get_aim_dir()".

Currently, when "flag" is true, that is, when "interesting" grids are being used, and a directional key is used, we only scroll by a single panel, in the direction requested, and check for any interesting grids on that panel. The "correct" solution would actually involve scanning a larger set of grids, including ones in panels which are adjacent to the one currently scanned, but this is overkill for this function. XXX XXX

Hack – targetting/observing an "outer border grid" may induce problems, so this is not currently allowed.

The player can use the direction keys to move among "interesting" grids in a heuristic manner, or the "space", "+", and "-" keys to move through the "interesting" grids in a sequential manner, or can enter "location" mode, and use the direction keys to move one grid at a time in any direction. The "t" (set target) command will only target a monster (as opposed to a location) if the monster is target_able and the "interesting" mode is being used.

The current grid is described using the "look" method above, and a new command may be entered at any time, but note that if the "TARGET_LOOK" bit flag is set (or if we are in "location" mode, where "space" has no obvious meaning) then "space" will scan through the description of the current grid until done, instead of immediately jumping to the next "interesting" grid. This allows the "target" command to retain its old semantics.

The "*", "+", and "-" keys may always be used to jump immediately to the next (or previous) interesting grid, in the proper mode.

The "return" key may always be used to scan through a complete grid description (forever).

This command will cancel any old target, even if used from inside the "look" command.

'mode' is one of TARGET_LOOK or TARGET_KILL. 'x' and 'y' are the initial position of the target to be highlighted, or -1 if no location is specified. Returns TRUE if a target has been successfully set, FALSE otherwise.

References adjust_panel_help(), bell(), mouseclick::button, cave, change_panel(), CMD_PATHFIND, cmd_set_arg_point(), cmdq_peek(), cmdq_push(), keypress::code, COL_MAP, ddx, ddy, distance(), draw_path(), ESCAPE, EVT_MOUSE, FALSE, flag, handle_stuff(), health_track(), chunk::height, term::hgt, i, KC_MOD_ALT, KC_MOD_CONTROL, ui_event::key, KEY_GRID_X, KEY_GRID_Y, load_path(), angband_constants::max_range, mem_free(), mem_zalloc(), modify_panel(), mouseclick::mods, monster_race_track(), ui_event::mouse, term::offset_x, term::offset_y, point_set_dispose(), point_set_size(), PR_BASIC, PR_DEPTH, PR_EQUIP, PR_EXTRA, PR_MAP, PR_STATUS, project_path(), PROJECT_THRU, prt(), point_set::pts, player::px, player::py, monster::race, player_upkeep::redraw, square_monster(), square_object(), target_able(), target_dir(), target_display_help(), target_get_monsters(), target_is_set(), TARGET_KILL, TARGET_LOOK, target_pick(), target_set_interactive_aux(), target_set_location(), target_set_monster(), Term, Term_clear(), Term_get_size(), TRUE, ui_event::type, player::upkeep, verify_panel(), term::wid, chunk::width, loc::x, mouseclick::x, loc::y, mouseclick::y, and z_info.

Referenced by context_menu_cave(), context_menu_player(), do_cmd_look(), do_cmd_wiz_bamf(), textui_get_aim_dir(), textui_process_click(), and textui_target().

static ui_event target_set_interactive_aux ( int  y,
int  x,
int  mode 
)
static

Examine a grid, return a keypress.

The "mode" argument contains the "TARGET_LOOK" bit flag, which indicates that the "space" key should scan through the contents of the grid, instead of simply returning immediately. This lets the "look" command get complete information, without making the "target" command annoying.

The "info" argument contains the "commands" which should be shown inside the "[xxx]" text. This string must never be empty, or grids containing monsters will be displayed with an extra comma.

Note that if a monster is in the grid, we update both the monster recall info and the health bar info to track that monster.

This function correctly handles multiple objects per grid, and objects and terrain features in the same grid, though the latter never happens.

This function must handle blindness/hallucination.

References buf, mouseclick::button, cave, keypress::code, coords_desc(), square::cost, EVT_KBRD, EVT_MOUSE, FALSE, monster_race::flags, angband_constants::floor_size, get_lore(), handle_stuff(), health_track(), monster::held_obj, inkey(), inkey_m(), is_a_vowel(), KC_ENTER, ui_event::key, KEY_GRID_X, KEY_GRID_Y, trap::kind, look_mon_desc(), lore_show_interactive(), MDESC_IND_VIS, mem_free(), mem_zalloc(), monster::mflag, mflag_has, keypress::mods, square::mon, monster_desc(), monster_race_track(), ui_event::mouse, move_cursor_relative(), trap_kind::name, name, object::next, object::number, object_desc(), ODESC_FULL, ODESC_PREFIX, OLIST_GOLD, OLIST_WEIGHT, prt(), player::px, player::py, monster::race, rf_has, s1, s2, scan_floor(), screen_load(), screen_save(), show_floor(), square_apparent_name(), square_isdoor(), square_isinteresting(), square_isshop(), square_isvisibletrap(), square_monster(), chunk::squares, strnfmt(), TARGET_LOOK, TARGET_OUT_VAL_SIZE, target_recall_loop_object(), player::timed, track_object(), square::trap, TRUE, ui_event::type, player::upkeep, VERB_AGREEMENT, square::when, player::wizard, mouseclick::y, and z_info.

Referenced by target_set_interactive().

void textui_target ( void  )

Target command.

References msg, TARGET_KILL, and target_set_interactive().

void textui_target_closest ( void  )

Target closest monster.

XXX: Move to using CMD_TARGET_CLOSEST at some point instead of invoking target_set_closest() directly.

References move_cursor_relative(), target_get(), TARGET_KILL, target_set_closest(), Term_fresh(), Term_get_cursor(), Term_redraw_section(), Term_set_cursor(), Term_xtra(), TERM_XTRA_DELAY, TRUE, and void().