Angband
Data Structures | Macros | Enumerations | Functions | Variables
ui-store.c File Reference

Store UI. More...

#include "angband.h"
#include "cave.h"
#include "cmds.h"
#include "game-event.h"
#include "game-input.h"
#include "hint.h"
#include "init.h"
#include "monster.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-ignore.h"
#include "obj-info.h"
#include "obj-knowledge.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-history.h"
#include "store.h"
#include "target.h"
#include "ui-display.h"
#include "ui-input.h"
#include "ui-menu.h"
#include "ui-object.h"
#include "ui-options.h"
#include "ui-knowledge.h"
#include "ui-player.h"
#include "ui-spell.h"
#include "ui-command.h"
#include "ui-store.h"
#include "z-debug.h"

Data Structures

struct  store_context
 

Macros

#define STORE_GOLD_CHANGE   0x01
 
#define STORE_FRAME_CHANGE   0x02
 
#define STORE_SHOW_HELP   0x04
 
#define STORE_INIT_CHANGE   (STORE_FRAME_CHANGE | STORE_GOLD_CHANGE)
 

Enumerations

enum  {
  LOC_PRICE = 0, LOC_OWNER, LOC_HEADER, LOC_MORE,
  LOC_HELP_CLEAR, LOC_HELP_PROMPT, LOC_AU, LOC_WEIGHT,
  LOC_MAX
}
 Easy names for the elements of the 'scr_places' arrays. More...
 
enum  {
  ACT_INSPECT_INVEN, ACT_SELL, ACT_EXAMINE, ACT_BUY,
  ACT_BUY_ONE, ACT_EXIT
}
 Enum for context menu entries. More...
 

Functions

static const char * random_hint (void)
 
static void prt_welcome (const struct owner *proprietor)
 The greeting a shopkeeper gives the character says a lot about his general attitude. More...
 
static void store_display_recalc (struct store_context *ctx)
 This function sets up screen locations based on the current term size. More...
 
static void store_display_entry (struct menu *menu, int oid, bool cursor, int row, int col, int width)
 Redisplay a single store entry. More...
 
static void store_display_frame (struct store_context *ctx)
 Display store (after clearing screen) More...
 
static void store_display_help (struct store_context *ctx)
 Display help. More...
 
static void store_redraw (struct store_context *ctx)
 Decides what parts of the store display to redraw. More...
 
static bool store_get_check (const char *prompt)
 
static bool store_sell (struct store_context *ctx)
 
static bool store_purchase (struct store_context *ctx, int item, bool single)
 Buy an object from a store. More...
 
static void store_examine (struct store_context *ctx, int item)
 Examine an item in a store. More...
 
static void store_menu_set_selections (struct menu *menu, bool knowledge_menu)
 
static void store_menu_recalc (struct menu *m)
 
static bool store_process_command_key (struct keypress kp)
 Process a command in a store. More...
 
static int store_get_stock (struct menu *m, int oid)
 Select an item from the store's stock, and return the stock index. More...
 
static int context_menu_store (struct store_context *ctx, const int oid, int mx, int my)
 
static void context_menu_store_item (struct store_context *ctx, const int oid, int mx, int my)
 
static bool store_menu_handle (struct menu *m, const ui_event *event, int oid)
 Handle store menu input. More...
 
static void store_menu_init (struct store_context *ctx, struct store *store, bool inspect_only)
 Init the store menu. More...
 
void textui_store_knowledge (int n)
 Display contents of a store from knowledge menu. More...
 
static void refresh_stock (game_event_type type, game_event_data *unused, void *user)
 Handle stock change. More...
 
void enter_store (game_event_type type, game_event_data *data, void *user)
 Enter a store. More...
 
void use_store (game_event_type type, game_event_data *data, void *user)
 Interact with a store. More...
 
void leave_store (game_event_type type, game_event_data *data, void *user)
 

Variables

static const char * comment_welcome []
 Shopkeeper welcome messages. More...
 
static const char * comment_hint []
 
static region store_menu_region = { 1, 4, -1, -2 }
 
static const menu_iter store_menu
 

Detailed Description

Store UI.

Copyright (c) 1997 Robert A. Koeneke, James E. Wilson, Ben Harrison Copyright (c) 1998-2014 Angband developers

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.

Macro Definition Documentation

◆ STORE_FRAME_CHANGE

#define STORE_FRAME_CHANGE   0x02

Referenced by store_menu_handle(), and store_redraw().

◆ STORE_GOLD_CHANGE

#define STORE_GOLD_CHANGE   0x01

◆ STORE_INIT_CHANGE

#define STORE_INIT_CHANGE   (STORE_FRAME_CHANGE | STORE_GOLD_CHANGE)

◆ STORE_SHOW_HELP

#define STORE_SHOW_HELP   0x04

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Easy names for the elements of the 'scr_places' arrays.

Enumerator
LOC_PRICE 
LOC_OWNER 
LOC_HEADER 
LOC_MORE 
LOC_HELP_CLEAR 
LOC_HELP_PROMPT 
LOC_AU 
LOC_WEIGHT 
LOC_MAX 

◆ anonymous enum

anonymous enum

Enum for context menu entries.

Enumerator
ACT_INSPECT_INVEN 
ACT_SELL 
ACT_EXAMINE 
ACT_BUY 
ACT_BUY_ONE 
ACT_EXIT 

Function Documentation

◆ context_menu_store()

static int context_menu_store ( struct store_context ctx,
const int  oid,
int  mx,
int  my 
)
static

◆ context_menu_store_item()

static void context_menu_store_item ( struct store_context ctx,
const int  oid,
int  mx,
int  my 
)
static

◆ enter_store()

void enter_store ( game_event_type  type,
game_event_data data,
void user 
)

Enter a store.

References cave, EVENT_LEAVE_WORLD, event_signal(), msg, player::px, player::py, and square_isshop().

Referenced by ui_enter_world().

◆ leave_store()

void leave_store ( game_event_type  type,
game_event_data data,
void user 
)

◆ prt_welcome()

static void prt_welcome ( const struct owner proprietor)
static

The greeting a shopkeeper gives the character says a lot about his general attitude.

Taken and modified from Sangband 1.0.

Note that each comment_hint should have exactly one s

References player::class, comment_hint, comment_welcome, format(), player::full_name, i, player::lev, MIN, msg, N_ELEMENTS, owner::name, one_in_, prt(), randint0, random_hint(), and player_class::title.

Referenced by use_store().

◆ random_hint()

static const char* random_hint ( void  )
static

References hint::hint, hints, hint::next, NULL, and one_in_.

Referenced by prt_welcome().

◆ refresh_stock()

static void refresh_stock ( game_event_type  type,
game_event_data unused,
void user 
)
static

◆ store_display_entry()

static void store_display_entry ( struct menu menu,
int  oid,
bool  cursor,
int  row,
int  col,
int  width 
)
static

◆ store_display_frame()

static void store_display_frame ( struct store_context ctx)
static

◆ store_display_help()

static void store_display_help ( struct store_context ctx)
static

◆ store_display_recalc()

static void store_display_recalc ( struct store_context ctx)
static

This function sets up screen locations based on the current term size.

Current screen layout: line 0: reserved for messages line 1: shopkeeper and their purse / item buying price line 2: empty line 3: table headers

line 4: Start of items

If help is turned off, then the rest of the display goes as:

line (height - 4): end of items line (height - 3): "more" prompt line (height - 2): empty line (height - 1): Help prompt and remaining gold

If help is turned on, then the rest of the display goes as:

line (height - 7): end of items line (height - 6): "more" prompt line (height - 4): gold remaining line (height - 3): command help

References menu::boundary, store_context::flags, loc(), LOC_AU, LOC_HEADER, LOC_HELP_CLEAR, LOC_HELP_PROMPT, LOC_MORE, LOC_OWNER, LOC_PRICE, LOC_WEIGHT, store_context::menu, menu_layout(), region::page_rows, store_context::scr_places_x, store_context::scr_places_y, store::sidx, store_context::store, STORE_HOME, STORE_SHOW_HELP, Term_get_size(), and text_out_wrap.

Referenced by refresh_stock(), store_menu_handle(), and store_menu_init().

◆ store_examine()

static void store_examine ( struct store_context ctx,
int  item 
)
static

◆ store_get_check()

static bool store_get_check ( const char *  prompt)
static

References keypress::code, ESCAPE, inkey(), and prt().

Referenced by store_purchase(), and store_sell().

◆ store_get_stock()

static int store_get_stock ( struct menu m,
int  oid 
)
static

Select an item from the store's stock, and return the stock index.

References menu::cursor, EVT_ESCAPE, EVT_SELECT, menu::flags, menu_select(), MN_NO_ACTION, and ui_event::type.

Referenced by store_menu_handle().

◆ store_menu_handle()

static bool store_menu_handle ( struct menu m,
const ui_event event,
int  oid 
)
static

◆ store_menu_init()

static void store_menu_init ( struct store_context ctx,
struct store store,
bool  inspect_only 
)
static

◆ store_menu_recalc()

static void store_menu_recalc ( struct menu m)
static

◆ store_menu_set_selections()

static void store_menu_set_selections ( struct menu menu,
bool  knowledge_menu 
)
static

◆ store_process_command_key()

static bool store_process_command_key ( struct keypress  kp)
static

Process a command in a store.

Note that we must allow the use of a few "special" commands in the stores which are not allowed in the dungeon, and we must disable some commands which are allowed in the dungeon but not in the stores, to prevent chaos.

References CMD_INSCRIBE, CMD_TAKEOFF, CMD_UNINSCRIBE, CMD_WIELD, cmdq_push_repeat(), keypress::code, do_cmd_change_name(), do_cmd_equip(), do_cmd_inven(), do_cmd_messages(), do_cmd_quiver(), do_cmd_save_screen(), KTRL, msg_flag, prt(), textui_browse_knowledge(), textui_cmd_ignore(), textui_obj_examine(), textui_spell_browse(), and toggle_inven_equip().

Referenced by store_menu_handle().

◆ store_purchase()

static bool store_purchase ( struct store_context ctx,
int  item,
bool  single 
)
static

◆ store_redraw()

static void store_redraw ( struct store_context ctx)
static

◆ store_sell()

static bool store_sell ( struct store_context ctx)
static

◆ textui_store_knowledge()

void textui_store_knowledge ( int  n)

Display contents of a store from knowledge menu.

The only allowed actions are 'I' to inspect an item

References clear_from(), EVENT_MESSAGE_FLUSH, event_signal(), store_context::list, mem_free(), store_context::menu, menu_select(), screen_load(), screen_save(), store_menu_init(), and stores.

Referenced by do_cmd_knowledge_store().

◆ use_store()

void use_store ( game_event_type  type,
game_event_data data,
void user 
)

Variable Documentation

◆ comment_hint

const char* comment_hint[]
static
Initial value:
=
{
"\"%s\""
}

Referenced by prt_welcome().

◆ comment_welcome

const char* comment_welcome[]
static
Initial value:
=
{
"",
"%s nods to you.",
"%s says hello.",
"%s: \"See anything you like, adventurer?\"",
"%s: \"How may I help you, %s?\"",
"%s: \"Welcome back, %s.\"",
"%s: \"A pleasure to see you again, %s.\"",
"%s: \"How may I be of assistance, good %s?\"",
"%s: \"You do honour to my humble store, noble %s.\"",
"%s: \"I and my family are entirely at your service, %s.\""
}

Shopkeeper welcome messages.

The shopkeeper's name must come first, then the character's name.

Referenced by prt_welcome().

◆ store_menu

const menu_iter store_menu
static
Initial value:
=
{
NULL
}
static void store_display_entry(struct menu *menu, int oid, bool cursor, int row, int col, int width)
Redisplay a single store entry.
Definition: ui-store.c:265
static bool store_menu_handle(struct menu *m, const ui_event *event, int oid)
Handle store menu input.
Definition: ui-store.c:969
NULL
Definition: list-summon-types.h:18

◆ store_menu_region

region store_menu_region = { 1, 4, -1, -2 }
static