version 1.34 | | version 1.35 |
---|
| | |
/* | | /* |
* static char *rcsid_shop_c = | | * static char *rcsid_shop_c = |
* "$Id: shop.c,v 1.34 2005/03/06 20:38:54 akirschbaum Exp $"; | | * "$Id: shop.c,v 1.35 2005/04/14 06:12:57 mwedel Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
#endif | | #endif |
| | |
| | |
static uint64 pay_from_container(object *pouch, uint64 to_pay); | | static uint64 pay_from_container(object *pl, object *pouch, uint64 to_pay); |
| | |
| | |
#define NUM_COINS 3 /* number of coin types */ | | #define NUM_COINS 3 /* number of coin types */ |
| | |
if (to_pay==0) return 1; | | if (to_pay==0) return 1; |
if (to_pay > query_money(pl)) return 0; | | if (to_pay > query_money(pl)) return 0; |
| | |
to_pay = pay_from_container(pl, to_pay); | | to_pay = pay_from_container(pl, pl, to_pay); |
| | |
for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) { | | for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) { |
if (pouch->type == CONTAINER | | if (pouch->type == CONTAINER |
&& QUERY_FLAG(pouch, FLAG_APPLIED) | | && QUERY_FLAG(pouch, FLAG_APPLIED) |
&& (pouch->race == NULL || strstr(pouch->race, "gold"))) { | | && (pouch->race == NULL || strstr(pouch->race, "gold"))) { |
to_pay = pay_from_container(pouch, to_pay); | | to_pay = pay_from_container(pl, pouch, to_pay); |
} | | } |
} | | } |
fix_player(pl); | | fix_player(pl); |
| | |
if (saved_money > 0) | | if (saved_money > 0) |
change_exp(pl,saved_money,"bargaining",SK_EXP_NONE); | | change_exp(pl,saved_money,"bargaining",SK_EXP_NONE); |
| | |
to_pay = pay_from_container(pl, to_pay); | | to_pay = pay_from_container(pl, pl, to_pay); |
| | |
for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) { | | for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) { |
if (pouch->type == CONTAINER | | if (pouch->type == CONTAINER |
&& QUERY_FLAG(pouch, FLAG_APPLIED) | | && QUERY_FLAG(pouch, FLAG_APPLIED) |
&& (pouch->race == NULL || strstr(pouch->race, "gold"))) { | | && (pouch->race == NULL || strstr(pouch->race, "gold"))) { |
to_pay = pay_from_container(pouch, to_pay); | | to_pay = pay_from_container(pl, pouch, to_pay); |
} | | } |
} | | } |
if (settings.real_wiz == FALSE && QUERY_FLAG(pl, FLAG_WAS_WIZ)) | | if (settings.real_wiz == FALSE && QUERY_FLAG(pl, FLAG_WAS_WIZ)) |
| | |
* to_pay is the required amount. | | * to_pay is the required amount. |
* returns the amount still missing after using "pouch". | | * returns the amount still missing after using "pouch". |
*/ | | */ |
static uint64 pay_from_container(object *pouch, uint64 to_pay) { | | static uint64 pay_from_container(object *pl, object *pouch, uint64 to_pay) { |
int count, i; | | int count, i; |
sint64 remain; | | sint64 remain; |
object *tmp, *coin_objs[NUM_COINS], *next; | | object *tmp, *coin_objs[NUM_COINS], *next; |
archetype *at; | | archetype *at; |
object *who; | | |
| | |
if (pouch->type != PLAYER && pouch->type != CONTAINER) return to_pay; | | if (pouch->type != PLAYER && pouch->type != CONTAINER) return to_pay; |
| | |
| | |
pouch->name, coins[NUM_COINS-1-i]); | | pouch->name, coins[NUM_COINS-1-i]); |
remove_ob(tmp); | | remove_ob(tmp); |
coin_objs[i]->nrof += tmp->nrof; | | coin_objs[i]->nrof += tmp->nrof; |
esrv_del_item(pouch->contr, tmp->count); | | esrv_del_item(pl->contr, tmp->count); |
free_object(tmp); | | free_object(tmp); |
} | | } |
else { | | else { |
remove_ob(tmp); | | remove_ob(tmp); |
if(pouch->type==PLAYER) esrv_del_item(pouch->contr, tmp->count); | | if(pouch->type==PLAYER) esrv_del_item(pl->contr, tmp->count); |
coin_objs[i] = tmp; | | coin_objs[i] = tmp; |
} | | } |
break; | | break; |
| | |
for (i=0; i<NUM_COINS; i++) { | | for (i=0; i<NUM_COINS; i++) { |
if (coin_objs[i]->nrof) { | | if (coin_objs[i]->nrof) { |
object *tmp = insert_ob_in_ob(coin_objs[i], pouch); | | object *tmp = insert_ob_in_ob(coin_objs[i], pouch); |
for (who = pouch; who && who->type!=PLAYER && who->env!=NULL; who=who->env) ; | | |
esrv_send_item(who, tmp); | | esrv_send_item(pl, tmp); |
esrv_send_item (who, pouch); | | esrv_send_item (pl, pouch); |
if(who != pouch) esrv_update_item (UPD_WEIGHT, who, pouch); | | if (pl != pouch) esrv_update_item (UPD_WEIGHT, pl, pouch); |
if (pouch->type != PLAYER) { | | if (pl->type != PLAYER) { |
esrv_send_item (who, who); | | esrv_send_item (pl, pl); |
} | | } |
} else { | | } else { |
free_object(coin_objs[i]); | | free_object(coin_objs[i]); |