| version 1.30 | | version 1.31 |
|---|
| | |
| /* | | /* |
| * static char *rcsid_shop_c = | | * static char *rcsid_shop_c = |
| * "$Id: shop.c,v 1.30 2004/05/06 07:04:23 mwedel Exp $"; | | * "$Id: shop.c,v 1.31 2004/06/13 17:30:38 akirschbaum Exp $"; |
| */ | | */ |
| | | |
| /* | | /* |
| | |
| #endif | | #endif |
| | | |
| | | |
| | | static uint64 pay_from_container(object *pouch, uint64 to_pay); |
| | | |
| | | |
| #define NUM_COINS 3 /* number of coin types */ | | #define NUM_COINS 3 /* number of coin types */ |
| static char *coins[] = {"platinacoin", "goldcoin", "silvercoin", NULL}; | | static char *coins[] = {"platinacoin", "goldcoin", "silvercoin", NULL}; |
| | | |
| | |
| 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(NULL, pl, to_pay); | | to_pay = pay_from_container(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(NULL, pouch, to_pay); | | to_pay = pay_from_container(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(op, pl, to_pay); | | to_pay = pay_from_container(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(op, pouch, to_pay); | | to_pay = pay_from_container(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)) |
| | |
| * appropriately | | * appropriately |
| * | | * |
| * DAMN: This function is used for the player, then for any active | | * DAMN: This function is used for the player, then for any active |
| * containers that can hold money, until the op is paid for. | | * containers that can hold money. |
| | | * |
| | | * pouch is the container (pouch or player) to remove the coins from. |
| | | * to_pay is the required amount. |
| | | * returns the amount still missing after using "pouch". |
| */ | | */ |
| uint64 pay_from_container(object *op, object *pouch, int to_pay) { | | static uint64 pay_from_container(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; |
| | |
| for (who = pouch; who && who->type!=PLAYER && who->env!=NULL; who=who->env) ; | | for (who = pouch; who && who->type!=PLAYER && who->env!=NULL; who=who->env) ; |
| esrv_send_item(who, tmp); | | esrv_send_item(who, tmp); |
| esrv_send_item (who, pouch); | | esrv_send_item (who, pouch); |
| esrv_update_item (UPD_WEIGHT, who, pouch); | | if(who != pouch) esrv_update_item (UPD_WEIGHT, who, pouch); |
| if (pouch->type != PLAYER) { | | if (pouch->type != PLAYER) { |
| esrv_send_item (who, who); | | esrv_send_item (who, who); |
| esrv_update_item (UPD_WEIGHT, who, who); | | |
| } | | } |
| } else { | | } else { |
| free_object(coin_objs[i]); | | free_object(coin_objs[i]); |
| | |
| esrv_send_item (pl, pouch); | | esrv_send_item (pl, pouch); |
| esrv_update_item (UPD_WEIGHT, pl, pouch); | | esrv_update_item (UPD_WEIGHT, pl, pouch); |
| esrv_send_item (pl, pl); | | esrv_send_item (pl, pl); |
| esrv_update_item (UPD_WEIGHT, pl, pl); | | |
| } | | } |
| } | | } |
| } | | } |
| | |
| tmp = insert_ob_in_ob(tmp, pl); | | tmp = insert_ob_in_ob(tmp, pl); |
| esrv_send_item (pl, tmp); | | esrv_send_item (pl, tmp); |
| esrv_send_item (pl, pl); | | esrv_send_item (pl, pl); |
| esrv_update_item (UPD_WEIGHT, pl, pl); | | |
| } | | } |
| } | | } |
| } | | } |