ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/shop.C
(Generate patch)

Comparing deliantra/server/server/shop.C (file contents):
Revision 1.51 by root, Fri Apr 25 11:40:34 2008 UTC vs.
Revision 1.58 by root, Tue Dec 16 23:25:25 2008 UTC

126 { 126 {
127 if (tmp->arch != NULL) 127 if (tmp->arch != NULL)
128 { 128 {
129 if (flag == F_BUY) 129 if (flag == F_BUY)
130 { 130 {
131 LOG (llevError, "Asking for buy-value of unidentified object.\n"); 131 LOG (llevError | logBacktrace, "Asking for buy-value of unidentified object.\n");
132 val = tmp->arch->value * 50 * number; 132 val = tmp->arch->value * 50 * number;
133 } 133 }
134 else 134 else
135 { /* Trying to sell something, or get true value */ 135 { /* Trying to sell something, or get true value */
136 if (tmp->type == POTION) 136 if (tmp->type == POTION)
150 else 150 else
151 { /* No archetype with this object */ 151 { /* No archetype with this object */
152 LOG (llevDebug, "In sell item: Have object with no archetype: %s\n", &tmp->name); 152 LOG (llevDebug, "In sell item: Have object with no archetype: %s\n", &tmp->name);
153 if (flag == F_BUY) 153 if (flag == F_BUY)
154 { 154 {
155 LOG (llevError, "Asking for buy-value of unidentified object without arch.\n"); 155 LOG (llevError | logBacktrace, "Asking for buy-value of unidentified object without arch.\n");
156 val = number * tmp->value * 10; 156 val = number * tmp->value * 10;
157 } 157 }
158 else 158 else
159 val = number * tmp->value / 5; 159 val = number * tmp->value / 5;
160 } 160 }
631 count--; 631 count--;
632 } 632 }
633 } 633 }
634 634
635 for (i = 0; i < NUM_COINS; i++) 635 for (i = 0; i < NUM_COINS; i++)
636 {
637 if (coin_objs[i]->nrof) 636 if (coin_objs[i]->nrof)
638 insert_ob_in_ob (coin_objs [i], pouch); 637 insert_ob_in_ob (coin_objs [i], pouch);
639 else 638 else
640 coin_objs[i]->destroy (); 639 coin_objs[i]->destroy ();
641 }
642} 640}
643 641
644/* Checks all unpaid items in op's inventory, adds up all the money they 642/* Checks all unpaid items in op's inventory, adds up all the money they
645 * have, and checks that they can actually afford what they want to buy. 643 * have, and checks that they can actually afford what they want to buy.
646 * Returns 1 if they can, and 0 if they can't. also prints an appropriate message 644 * Returns 1 if they can, and 0 if they can't. also prints an appropriate message
666 unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); 664 unpaid_price += query_cost (item, pl, F_BUY | F_SHOP);
667 } 665 }
668 666
669 if (unpaid_price > player_wealth) 667 if (unpaid_price > player_wealth)
670 { 668 {
671 char buf[MAX_BUF]; 669 dynbuf_text buf;
672 char cost[MAX_BUF];
673 char missing[MAX_BUF];
674 670
675 snprintf (cost, MAX_BUF, "%s", cost_string_from_value (unpaid_price, 0)); 671 buf << "You have " << unpaid_count
676 snprintf (missing, MAX_BUF, "%s", cost_string_from_value (unpaid_price - player_wealth, 0)); 672 << " unpaid item(s) that would cost you " << cost_string_from_value (unpaid_price, 0)
673 << ". You need another " << cost_string_from_value (unpaid_price - player_wealth, 0)
674 << " to be able to afford that. "
675 "H<You cannot leave a shop with items you cannot pay - drop those unpaid items first.>";
677 676
678 snprintf (buf, MAX_BUF, "You have %d unpaid items that would cost you %s. You need another %s to be able to afford that.", 677 pl->failmsg (buf);
679 unpaid_count, cost, missing);
680 new_draw_info (NDI_UNIQUE, 0, pl, buf);
681 678
682 return 0; 679 return 0;
683 } 680 }
684 else 681 else
685 return 1; 682 return 1;
797 794
798/* elmex: this is for the bank plugin :( */ 795/* elmex: this is for the bank plugin :( */
799sint64 796sint64
800pay_player_arch (object *pl, const char *arch, sint64 amount) 797pay_player_arch (object *pl, const char *arch, sint64 amount)
801{ 798{
802 archetype *at = archetype::find (arch);
803
804 if (!at)
805 return 0;
806
807 if (amount > 0) 799 if (amount)
808 { 800 {
809 object *tmp = arch_to_object (at); 801 object *ob = archetype::get (arch);
802
803 if (!ob)
804 return 0;
805
810 tmp->nrof = amount; 806 ob->nrof = amount;
811 insert_ob_in_ob (tmp, pl); 807 pl->insert (ob);
812 } 808 }
813 809
814 return 1; 810 return 1;
815} 811}
816 812
1068{ 1064{
1069 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; 1065 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2;
1070 1066
1071 if (s1->type < s2->type) 1067 if (s1->type < s2->type)
1072 return -1; 1068 return -1;
1069
1073 if (s1->type > s2->type) 1070 if (s1->type > s2->type)
1074 return 1; 1071 return 1;
1075 1072
1076 /* the type is the same (what atoi gets), so do a strcasecmp to sort 1073 /* the type is the same (what atoi gets), so do a strcasecmp to sort
1077 * via alphabetical order 1074 * via alphabetical order
1127 1124
1128void 1125void
1129shop_listing (object *sign, object *op) 1126shop_listing (object *sign, object *op)
1130{ 1127{
1131 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; 1128 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2;
1132 const char *shop_coords = get_ob_key_value (sign, "shop_coords"); 1129 const char *shop_coords = sign->kv (shstr_shop_coords);
1133 object *stack; 1130 object *stack;
1134 shopinv *items; 1131 shopinv *items;
1135 1132
1136 /* Should never happen, but just in case a monster does apply a sign */ 1133 /* Should never happen, but just in case a monster does apply a sign */
1137 if (op->type != PLAYER) 1134 if (op->type != PLAYER)
1210 1207
1211/* elmex: this function checks whether the object is in a shop */ 1208/* elmex: this function checks whether the object is in a shop */
1212bool 1209bool
1213is_in_shop (object *o) 1210is_in_shop (object *o)
1214{ 1211{
1215 if (!o->map) 1212 if (!o->is_on_map ())
1216 return false; 1213 return false;
1217 1214
1218 return is_in_shop (o->map, o->x, o->y); 1215 return is_in_shop (o->map, o->x, o->y);
1219} 1216}
1220 1217
1228is_in_shop (maptile *map, int x, int y) 1225is_in_shop (maptile *map, int x, int y)
1229{ 1226{
1230 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) 1227 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above)
1231 if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) 1228 if (QUERY_FLAG (floor, FLAG_IS_FLOOR))
1232 return floor->type == SHOP_FLOOR; 1229 return floor->type == SHOP_FLOOR;
1230
1233 return false; 1231 return false;
1234} 1232}
1235 1233

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines