Angband
Macros | Functions | Variables
store.c File Reference

Store stocking. More...

#include "angband.h"
#include "cave.h"
#include "cmds.h"
#include "game-event.h"
#include "game-world.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-power.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-history.h"
#include "store.h"
#include "target.h"
#include "debug.h"
#include "list-object-flags.h"

Macros

#define OF(a)   #a,
 
#define ONE_OF(x)   x[randint0(N_ELEMENTS(x))]
 

Utilities

More...
 

Functions

static void store_maint (struct store *s)
 Maintain the inventory at the stores. More...
 
struct storestore_at (struct chunk *c, int y, int x)
 Return the store instance at the given location. More...
 
static struct storestore_new (int idx)
 Create a new store. More...
 
void cleanup_stores (void)
 Get rid of stores at cleanup. More...
 
static enum parser_error parse_store (struct parser *p)
 

Edit file parsing

More...
 
static enum parser_error parse_slots (struct parser *p)
 
static enum parser_error parse_turnover (struct parser *p)
 
static enum parser_error parse_normal (struct parser *p)
 
static enum parser_error parse_always (struct parser *p)
 
static enum parser_error parse_owner (struct parser *p)
 
static enum parser_error parse_buy (struct parser *p)
 
static enum parser_error parse_buy_flag (struct parser *p)
 
struct parserinit_parse_stores (void)
 
static errr run_parse_stores (struct parser *p)
 
static errr finish_parse_stores (struct parser *p)
 
static struct storeflatten_stores (struct store *store_list)
 

Other init stuff

More...
 
void store_init (void)
 
void store_reset (void)
 
static bool store_is_staple (struct store *s, struct object_kind *k)
 Check if a given item kind is an always-stocked item. More...
 
static bool store_can_carry (struct store *store, struct object_kind *kind)
 Check if a given item kind is an always-stocked or sometimes-stocked item. More...
 
static void purchase_analyze (int price, int value, int guess)
 Let a shop-keeper React to a purchase. More...
 
static bool store_will_buy (struct store *store, const struct object *obj)
 

Check if a store will buy an object

More...
 
int price_item (struct store *store, const struct object *obj, bool store_buying, int qty)
 

Basics: pricing, generation, etc. More...

 
static int mass_roll (int times, int max)
 Special "mass production" computation. More...
 
static void mass_produce (struct object *obj)
 Some cheap objects should be created in piles. More...
 
void store_stock_list (struct store *store, struct object **list, int n)
 Sort the store inventory into an ordered array. More...
 
static void store_object_absorb (struct object *old, struct object *new)
 Allow a store object to absorb another object. More...
 
bool store_check_num (struct store *store, const struct object *obj)
 Check to see if the shop will be carrying too many objects. More...
 
void home_carry (struct object *obj)
 Add an object to the inventory of the Home. More...
 
struct objectstore_carry (struct store *store, struct object *obj)
 Add an object to a real stores inventory. More...
 
void store_delete (struct store *s, struct object *obj, int amt)
 
static struct objectstore_find_kind (struct store *s, struct object_kind *k)
 Find a given object kind in the store. More...
 
static void store_delete_random (struct store *store)
 Delete an object from store 'store', or, if it is a stack, perhaps only partially delete it. More...
 
static bool black_market_ok (const struct object *obj)
 This makes sure that the black market doesn't stock any object that other stores have, unless it is an ego-item or has various bonuses. More...
 
static struct object_kindstore_get_choice (struct store *store)
 Get a choice from the store allocation table, in tables.c. More...
 
static bool store_create_random (struct store *store)
 Creates a random object and gives it to store 'store'. More...
 
static struct objectstore_create_item (struct store *store, struct object_kind *kind)
 Helper function: create an item with the given tval,sval pair, add it to the store st. More...
 
void store_update (void)
 Update the stores on the return to town. More...
 
struct ownerstore_ownerbyidx (struct store *s, unsigned int idx)
 Owner stuff. More...
 
static struct ownerstore_choose_owner (struct store *s)
 
void store_shuffle (struct store *store)
 Shuffle one of the stores. More...
 
int find_inven (const struct object *obj)
 

Higher-level code

More...
 
void do_cmd_buy (struct command *cmd)
 Buy the item with the given index from the current store's inventory. More...
 
void do_cmd_retrieve (struct command *cmd)
 Retrieve the item with the given index from the home's inventory. More...
 
bool store_will_buy_tester (const struct object *obj)
 Determine if the current store will purchase the given object. More...
 
void do_cmd_sell (struct command *cmd)
 Sell an item to the current store. More...
 
void do_cmd_stash (struct command *cmd)
 Stash an item in the home. More...
 

Variables

struct storestores
 

Constants and definitions

More...
 
struct hinthints
 The hints array. More...
 
static const char * obj_flags []
 
static struct file_parser store_parser
 
struct init_module store_module
 
static const char * comment_worthless []
 

Flavour text stuff

More...
 
static const char * comment_bad []
 
static const char * comment_accept []
 
static const char * comment_good []
 
static const char * comment_great []
 

Detailed Description

Store stocking.

Copyright (c) 1997 Robert A. Koeneke, James E. Wilson, Ben Harrison Copyright (c) 2007 Andi Sidwell

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

#define OF (   a)    #a,
#define ONE_OF (   x)    x[randint0(N_ELEMENTS(x))]


Utilities

Referenced by do_cmd_buy(), and purchase_analyze().

Function Documentation

static bool black_market_ok ( const struct object obj)
static

This makes sure that the black market doesn't stock any object that other stores have, unless it is an ego-item or has various bonuses.

Based on a suggestion by Lee Vogt lvogt.nosp@m.@cig.nosp@m..mcel.nosp@m..mot.nosp@m..com.

References object::ego, i, object::kind, MAX_STORES, object::next, object_value(), STORE_B_MARKET, STORE_HOME, object::to_a, object::to_d, and object::to_h.

Referenced by store_create_random(), and store_maint().

void cleanup_stores ( void  )
void do_cmd_buy ( struct command cmd)
void do_cmd_retrieve ( struct command cmd)
void do_cmd_sell ( struct command cmd)
void do_cmd_stash ( struct command cmd)
int find_inven ( const struct object obj)
static errr finish_parse_stores ( struct parser p)
static

References parser_destroy(), and parser_priv().

static struct store* flatten_stores ( struct store store_list)
static


Other init stuff

References MAX_STORES, mem_free(), mem_zalloc(), store::next, and store::sidx.

Referenced by store_init().

void home_carry ( struct object obj)

Add an object to the inventory of the Home.

Also note that it may not correctly "adapt" to "knowledge" becoming known: the player may have to pick stuff up and drop it again.

References object::known, object::next, object_absorb(), object_similar(), OSTACK_PACK, pile_insert(), store::stock, store::stock_k, store::stock_num, store::stock_size, and STORE_HOME.

Referenced by do_cmd_stash(), and rd_stores_aux().

struct parser* init_parse_stores ( void  )
static void mass_produce ( struct object obj)
static

Some cheap objects should be created in piles.

References object_kind::base, object::ego, object::kind, mass_roll(), object_base::max_stack, MIN, object::number, object_value(), randint1, size, and object::tval.

Referenced by store_create_random().

static int mass_roll ( int  times,
int  max 
)
static

Special "mass production" computation.

References i, and randint0.

Referenced by mass_produce().

static enum parser_error parse_always ( struct parser p)
static
static enum parser_error parse_buy ( struct parser p)
static
static enum parser_error parse_buy_flag ( struct parser p)
static
static enum parser_error parse_normal ( struct parser p)
static
static enum parser_error parse_owner ( struct parser p)
static
static enum parser_error parse_slots ( struct parser p)
static
static enum parser_error parse_store ( struct parser p)
static
static enum parser_error parse_turnover ( struct parser p)
static
int price_item ( struct store store,
const struct object obj,
bool  store_buying,
int  qty 
)


Basics: pricing, generation, etc.


Determine the price of an object (qty one) in a store.

store_buying == true means the shop is buying, player selling == false means the shop is selling, player buying

This function never lets a shop-keeper lose money in a transaction.

The "greed" value should exceed 100 when the player is "buying" the object, and should be less than 100 when the player is "selling" it.

Hack – the black market always charges twice as much as it should.

References owner::max_cost, object_value_real(), OPT, store::owner, store::sidx, STORE_B_MARKET, and tval_can_have_charges().

Referenced by do_cmd_buy(), do_cmd_sell(), show_obj(), store_display_entry(), store_purchase(), and store_sell().

static void purchase_analyze ( int  price,
int  value,
int  guess 
)
static

Let a shop-keeper React to a purchase.

We paid "price", it was worth "value", and we thought it was worth "guess"

References comment_bad, comment_good, comment_great, comment_worthless, msgt(), and ONE_OF.

Referenced by do_cmd_sell().

static errr run_parse_stores ( struct parser p)
static
struct store* store_at ( struct chunk c,
int  y,
int  x 
)

Return the store instance at the given location.

References cave, NULL, square_isshop(), and square_shopnum().

Referenced by do_cmd_buy(), do_cmd_retrieve(), do_cmd_sell(), do_cmd_stash(), show_obj(), store_will_buy_tester(), and use_store().

static bool store_can_carry ( struct store store,
struct object_kind kind 
)
static

Check if a given item kind is an always-stocked or sometimes-stocked item.

References i, store::normal_num, store::normal_table, and store_is_staple().

Referenced by store_carry(), and store_will_buy_tester().

struct object* store_carry ( struct store store,
struct object obj 
)

Add an object to a real stores inventory.

If the object is "worthless", it is thrown away (except in the home).

If the object cannot be combined with an object already in the inventory, make a new slot for it, and calculate its "per item" price. Note that this price will be negative, since the price will not be "fixed" yet. Adding an object to a "fixed" price stack will not change the fixed price.

Returns the object inserted (for ease of use) or NULL if it disappears

References object_kind::charge, angband_constants::default_lamp, object::flags, angband_constants::fuel_torch, i, object::kind, object::known, object::next, object::note, object::notice, NULL, object::number, OBJ_NOTICE_ASSESSED, object_is_carried(), object_similar(), object_value(), object_value_real(), of_has, OSTACK_STORE, pile_insert(), object::pval, randcalc(), RANDOMISE, store::stock, store::stock_k, store::stock_num, store::stock_size, store_can_carry(), store_object_absorb(), object::timeout, tval_can_have_charges(), tval_can_have_timeout(), tval_is_launcher(), tval_is_light(), value, and z_info.

Referenced by do_cmd_sell(), rd_stores_aux(), store_create_item(), and store_create_random().

bool store_check_num ( struct store store,
const struct object obj 
)

Check to see if the shop will be carrying too many objects.

Note that the shop, just like a player, will not accept things it cannot hold. Before, one could "nuke" objects this way, by adding them to a pile which was already full.

References object::next, object_similar(), OSTACK_PACK, OSTACK_STORE, store::sidx, store::stock, store::stock_num, store::stock_size, and STORE_HOME.

Referenced by do_cmd_sell(), do_cmd_stash(), and store_sell().

static struct owner* store_choose_owner ( struct store s)
static
static struct object* store_create_item ( struct store store,
struct object_kind kind 
)
static

Helper function: create an item with the given tval,sval pair, add it to the store st.

Return the item in the inventory.

References object::known, object_new(), object_prep(), object_set_base_known(), object::origin, player_know_object(), RANDOMISE, and store_carry().

Referenced by store_maint().

static bool store_create_random ( struct store store)
static
void store_delete ( struct store s,
struct object obj,
int  amt 
)
static void store_delete_random ( struct store store)
static

Delete an object from store 'store', or, if it is a stack, perhaps only partially delete it.

This function is used when store maintainance occurs, and is designed to imitate non-PC purchasers making purchases from the store.

The reason this doesn't check for "staple" items and refuse to delete them is that a store could conceviably have two stacks of a single staple item, in which case, you could have a store which had more stacks than staple items, but all stacks are staple items.

References object::artifact, history_lose_artifact(), object::next, num, object::number, object::pval, randint0, randint1, store::stock, store::stock_num, store_delete(), tval_can_have_charges(), and tval_is_ammo().

Referenced by store_maint().

static struct object* store_find_kind ( struct store s,
struct object_kind k 
)
static

Find a given object kind in the store.

References object::ego, object::kind, object::next, NULL, and store::stock.

Referenced by store_maint().

static struct object_kind* store_get_choice ( struct store store)
static

Get a choice from the store allocation table, in tables.c.

References store::normal_num, store::normal_table, and randint0.

Referenced by store_create_random().

void store_init ( void  )
static bool store_is_staple ( struct store s,
struct object_kind k 
)
static

Check if a given item kind is an always-stocked item.

References store::always_num, store::always_table, and i.

Referenced by do_cmd_buy(), and store_can_carry().

static void store_maint ( struct store s)
static
static struct store* store_new ( int  idx)
static

Create a new store.

References mem_zalloc(), store::sidx, store::stock_size, angband_constants::store_inven_max, and z_info.

Referenced by parse_store().

static void store_object_absorb ( struct object old,
struct object new 
)
static
struct owner* store_ownerbyidx ( struct store s,
unsigned int  idx 
)

Owner stuff.

References owner::next, owner::oidx, store::owners, and quit_fmt().

Referenced by rd_stores_aux(), and store_choose_owner().

void store_reset ( void  )
void store_shuffle ( struct store store)

Shuffle one of the stores.

References store::owner, and store_choose_owner().

Referenced by do_cmd_buy(), store_reset(), and store_update().

void store_stock_list ( struct store store,
struct object **  list,
int  n 
)

Sort the store inventory into an ordered array.

References earlier_object(), i, object::next, NULL, num, store::sidx, store::stock, and STORE_HOME.

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

void store_update ( void  )

Update the stores on the return to town.

References daycount, MAX_STORES, msg, one_in_, OPT, randint0, STORE_HOME, store_maint(), angband_constants::store_shuffle, store_shuffle(), and z_info.

Referenced by dungeon_change_level().

static bool store_will_buy ( struct store store,
const struct object obj 
)
static


Check if a store will buy an object

Determine if the current store will purchase the given object

Note that a shop-keeper must refuse to buy "worthless" objects

References store::buy, object_buy::flag, object::flags, object_buy::next, object_flag_is_known(), object_value(), of_has, store::sidx, STORE_HOME, object_buy::tval, and object::tval.

Referenced by do_cmd_sell(), and store_will_buy_tester().

bool store_will_buy_tester ( const struct object obj)

Determine if the current store will purchase the given object.

References cave, object::kind, object_flavor_is_aware(), OPT, player::px, player::py, store_at(), store_can_carry(), store_will_buy(), and tval_can_have_charges().

Referenced by context_menu_object(), and store_sell().

Variable Documentation

const char* comment_accept[]
static
Initial value:
=
{
"Okay.",
"Fine.",
"Accepted!",
"Agreed!",
"Done!",
"Taken!"
}

Referenced by do_cmd_buy().

const char* comment_bad[]
static
Initial value:
=
{
"Damn!",
"You fiend!",
"The shopkeeper curses at you.",
"The shopkeeper glares at you."
}

Referenced by purchase_analyze().

const char* comment_good[]
static
Initial value:
=
{
"Cool!",
"You've made my day!",
"The shopkeeper sniggers.",
"The shopkeeper giggles.",
"The shopkeeper laughs loudly."
}

Referenced by purchase_analyze().

const char* comment_great[]
static
Initial value:
=
{
"Yipee!",
"I think I'll retire!",
"The shopkeeper jumps for joy.",
"The shopkeeper smiles gleefully.",
"Wow. I'm going to name my new villa in your honour."
}

Referenced by purchase_analyze().

const char* comment_worthless[]
static
Initial value:
=
{
"Arrgghh!",
"You bastard!",
"You hear someone sobbing...",
"The shopkeeper howls in agony!",
"The shopkeeper wails in anguish!",
"The shopkeeper beats his head against the counter."
}


Flavour text stuff

Messages for reacting to purchase prices.

Referenced by purchase_analyze().

struct hint* hints

The hints array.

Referenced by cleanup_hints(), finish_parse_hints(), and random_hint().

const char* obj_flags[]
static

Referenced by parse_buy_flag().

struct init_module store_module
Initial value:
= {
.name = "store",
.init = store_init,
.cleanup = cleanup_stores
}
void cleanup_stores(void)
Get rid of stores at cleanup.
Definition: store.c:98
void store_init(void)
Definition: store.c:331
struct file_parser store_parser
static
Initial value:
= {
"store",
}
struct parser * init_parse_stores(void)
Definition: store.c:272
static errr finish_parse_stores(struct parser *p)
Definition: store.c:290
static errr run_parse_stores(struct parser *p)
Definition: store.c:286
NULL
Definition: list-summon-types.h:18
struct store* stores