Atrinik Server  4.0
Functions
shop.c File Reference
#include <global.h>
#include <toolkit/string.h>
#include <arch.h>

Go to the source code of this file.

Functions

int64_t shop_get_cost (object *op, int mode)
 
static archetype_tshop_get_next_coin (int64_t cost, int *cointype)
 
const char * shop_get_cost_string (int64_t cost)
 
const char * shop_get_cost_string_item (object *op, int mode)
 
int64_t shop_get_money (object *op)
 
static int64_t shop_pay_inventory (object *obj, int64_t to_pay)
 
static int64_t shop_pay_amount (object *op, int64_t to_pay)
 
bool shop_pay (object *op, int64_t to_pay)
 
bool shop_pay_item (object *op, object *item)
 
static bool shop_pay_items_rec (object *op, object *where)
 
bool shop_pay_items (object *op)
 
void shop_sell_item (object *op, object *item)
 
void shop_insert_coins (object *op, int64_t value)
 

Detailed Description

Functions dealing with shop handling, bargaining, etc.

Definition in file shop.c.

Function Documentation

int64_t shop_get_cost ( object op,
int  mode 
)

Calculate the price of an item.

Parameters
tmpObject we're querying the price of.
modeOne of Cost modes.
Returns
The price of the item.

Definition at line 43 of file shop.c.

const char* shop_get_cost_string ( int64_t  cost)

Converts a price to number of coins.

Parameters
costValue to transform to currency.
Returns
Static buffer containing the price. Will be overwritten with the next call to this function.

Definition at line 178 of file shop.c.

const char* shop_get_cost_string_item ( object op,
int  mode 
)

Query the cost of an item.

This is really a wrapper for shop_get_cost_string() and shop_get_cost().

Parameters
opObject we're querying the price of.
modeOne of Cost modes.
Returns
The cost string.

Definition at line 238 of file shop.c.

int64_t shop_get_money ( object op)

Finds out how much money the player is carrying, including what is in containers and in bank.

Parameters
opItem to get money for. Must be a player or a container.
Returns
Total money the player is carrying.

Definition at line 251 of file shop.c.

static archetype_t* shop_get_next_coin ( int64_t  cost,
int *  cointype 
)
static

Find the coin type that is worth more than 'cost'. Starts at the 'cointype' placement.

Parameters
costValue we're searching.
[in,out]cointypeFirst coin type to search. Will contain the next coin ID.
Returns
Coin archetype, NULL if none found.

Definition at line 150 of file shop.c.

void shop_insert_coins ( object op,
int64_t  value 
)

Insert coins into an object.

Parameters
opObject to receive the coins.
valueValue of coins to insert (for example, 120 for 1 silver and 20 copper).

Definition at line 587 of file shop.c.

bool shop_pay ( object op,
int64_t  to_pay 
)

Pays the specified amount of money.

Parameters
opObject paying.
to_payAmount to pay.
Returns
False if not enough money, in which case nothing is removed, true if money was removed.

Definition at line 428 of file shop.c.

static int64_t shop_pay_amount ( object op,
int64_t  to_pay 
)
static

Recursively attempts to pay the specified amount of money.

Parameters
opWho is paying.
to_payAmount to pay.
Returns
Amount left to pay.

Definition at line 397 of file shop.c.

static int64_t shop_pay_inventory ( object obj,
int64_t  to_pay 
)
static

Pays the specified amount, taking the proper amount of money from the object's inventory.

Parameters
objObject to remove the money for.
to_payRequired amount.
Returns
Amount still left to pay.

Definition at line 284 of file shop.c.

bool shop_pay_item ( object op,
object item 
)

Attempts to pay for the specified item.

Parameters
opObject buying.
itemItem to buy.
Returns
Whether the object was purchased successfully (and money removed).

Definition at line 465 of file shop.c.

bool shop_pay_items ( object op)

Descends inventories looking for unpaid items, and pays for them.

Parameters
opObject buying the stuff.
Returns
True if everything has been paid for, false otherwise.

Definition at line 542 of file shop.c.

static bool shop_pay_items_rec ( object op,
object where 
)
static

Recursively pay for items in inventories. Used by shop_pay_items().

Parameters
opObject buying the stuff.
whereWhere to look.
Returns
True if everything has been paid for, false otherwise.

Definition at line 479 of file shop.c.

void shop_sell_item ( object op,
object item 
)

Sell an item.

Parameters
opWho is selling the item.
itemThe item to sell.

Definition at line 554 of file shop.c.