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 "mon-predicate.h"
#include "monster.h"
#include "obj-desc.h"
#include "obj-pile.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-calcs.h"
#include "player-timed.h"
#include "project.h"
#include "target.h"
#include "trap.h"
#include "ui-display.h"
#include "ui-input.h"
#include "ui-keymap.h"
#include "ui-map.h"
#include "ui-mon-lore.h"
#include "ui-object.h"
#include "ui-output.h"
#include "ui-target.h"
#include "ui-term.h"


int target_dir (struct keypress ch)
 Extract a direction (or zero) from a character. More...
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. More...
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. More...
static ui_event target_recall_loop_object (struct object *obj, 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. More...
static ui_event target_set_interactive_aux (int y, int x, int mode)
 Examine a grid, return a keypress. More...
void textui_target (void)
 Target command. More...
void textui_target_closest (void)
 Target closest monster. More...
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). More...
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". More...
bool target_set_interactive (int mode, int x, int y)
 Handle "target" and "look". More...

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

◆ adjust_panel_help()

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.

Optionally accounts for the targeting help window.

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

Referenced by target_set_interactive().

◆ draw_path()

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).

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, player::cave, COLOUR_BLUE, COLOUR_L_DARK, COLOUR_L_RED, COLOUR_WHITE, COLOUR_YELLOW, term_win::cx, term_win::cy, i, monster_is_camouflaged(), monster_is_visible(), move_cursor_relative(), panel_contains(), term::scr, square_isknown(), square_isprojectable(), square_isseen(), square_monster(), square_object(), Term, Term_addch(), Term_what(), void(), loc::x, and loc::y.

Referenced by target_set_interactive().

◆ load_path()

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".

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().

◆ target_dir()

int target_dir ( struct keypress  ch)

◆ target_dir_allow()

int target_dir_allow ( struct keypress  ch,
bool  allow_5 

◆ target_display_help()

void target_display_help ( bool  monster,
bool  free 

◆ target_recall_loop_object()

static ui_event target_recall_loop_object ( struct object obj,
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.

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).

objis 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, display_object_recall_interactive(), EVT_KBRD, EVT_MOUSE, heatmap::grids, inkey_m(), ui_event::key, KEY_GRID_X, KEY_GRID_Y, ui_event::mouse, move_cursor_relative(), chunk::noise, object_desc(), chunk::objects, ODESC_FULL, ODESC_PREFIX, object::oidx, prt(), chunk::scent, strnfmt(), ui_event::type, and player::wizard.

Referenced by target_set_interactive_aux().

◆ target_set_interactive()

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(), allow_animations(), bell(), mouseclick::button, cave, change_panel(), CMD_PATHFIND, cmd_set_arg_point(), cmdq_peek(), cmdq_push(), keypress::code, COL_MAP, ddx, ddy, disallow_animations(), distance(), draw_path(), ESCAPE, EVT_MOUSE, flag, player::grid, 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(), loc(), 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_INFO, project_path(), PROJECT_THRU, prt(), point_set::pts, monster::race, player_upkeep::redraw, square_in_bounds(), square_in_bounds_fully(), 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(), 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().

◆ target_set_interactive_aux()

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

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(), trap_kind::desc, EVT_KBRD, EVT_MOUSE, monster_race::flags, floor_list, angband_constants::floor_size, get_lore(), player::grid, heatmap::grids, 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, loc(), loc_eq(), look_mon_desc(), lore_show_interactive(), MDESC_IND_VIS, mem_free(), mem_zalloc(), keypress::mods, monster_desc(), monster_is_obvious(), monster_race_track(), ui_event::mouse, move_cursor_relative(), trap_kind::name, name, object::next, chunk::noise, object::number, object_desc(), ODESC_FULL, ODESC_PREFIX, OLIST_GOLD, OLIST_WEIGHT, prt(), monster::race, rf_has, s1, s2, scan_distant_floor(), chunk::scent, screen_load(), screen_save(), show_floor(), square(), square_apparent_name(), square_in_bounds(), square_isdoor(), square_isinteresting(), square_isshop(), square_isvisibletrap(), square_monster(), strnfmt(), TARGET_LOOK, TARGET_OUT_VAL_SIZE, target_recall_loop_object(), player::timed, track_object(), square::trap, ui_event::type, player::upkeep, VERB_AGREEMENT, player::wizard, mouseclick::y, and z_info.

Referenced by target_set_interactive().

◆ textui_target()

void textui_target ( void  )

Target command.

References msg, TARGET_KILL, and target_set_interactive().

◆ textui_target_closest()

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, void(), loc::x, and loc::y.