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.50 by elmex, Thu Apr 24 11:26:41 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 }
206 * AND Cha = 30 will get optimal price. 206 * AND Cha = 30 will get optimal price.
207 * Thus charisma will never get useless. 207 * Thus charisma will never get useless.
208 * -b.e. edler@heydernet.de 208 * -b.e. edler@heydernet.de
209 */ 209 */
210 210
211 if (who != NULL && who->type == PLAYER) 211 if (who && who->type == PLAYER)
212 { 212 {
213 int lev_bargain = 0; 213 int lev_bargain = 0;
214 int lev_identify = 0; 214 int lev_identify = 0;
215 int idskill1 = 0;
216 int idskill2 = 0;
217 const typedata *tmptype;
218
219 tmptype = get_typedata (tmp->type);
220 215
221 if (find_skill_by_number (who, SK_BARGAINING)) 216 if (find_skill_by_number (who, SK_BARGAINING))
222 lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level; 217 lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level;
223 218
224 if (tmptype) 219 if (const typedata *tmptype = get_typedata (tmp->type))
225 { 220 {
226 idskill1 = tmptype->identifyskill; 221 if (int idskill1 = tmptype->identifyskill)
227
228 if (idskill1)
229 { 222 {
230 idskill2 = tmptype->identifyskill2; 223 int idskill2 = tmptype->identifyskill2;
231 224
232 if (find_skill_by_number (who, idskill1)) 225 if (find_skill_by_number (who, idskill1))
233 lev_identify = find_skill_by_number (who, idskill1)->level; 226 lev_identify = find_skill_by_number (who, idskill1)->level;
234 227
235 if (idskill2 && find_skill_by_number (who, idskill2)) 228 if (idskill2 && find_skill_by_number (who, idskill2))
236 lev_identify += find_skill_by_number (who, idskill2)->level; 229 lev_identify += find_skill_by_number (who, idskill2)->level;
237 } 230 }
238 } 231 }
239 else
240 LOG (llevError, "Query_cost: item %s hasn't got a valid type\n", tmp->debug_desc ());
241 232
242 /* ratio determines how much of the price modification 233 /* ratio determines how much of the price modification
243 * will come from the basic stat charisma 234 * will come from the basic stat charisma
244 * the rest will come from the level in bargaining skill 235 * the rest will come from the level in bargaining skill
245 */ 236 */
418 409
419 if (coin == NULL) 410 if (coin == NULL)
420 return "nothing"; 411 return "nothing";
421 412
422 num = real_value / coin->value; 413 num = real_value / coin->value;
414
423 if (num == 1) 415 if (num == 1)
424 sprintf (buf, "about one %s", &coin->object::name); 416 sprintf (buf, "about one %s", &coin->object::name);
425 else if (num < 5) 417 else if (num < 5)
426 sprintf (buf, "a few %s", &coin->object::name_pl); 418 sprintf (buf, "a few %s", &coin->object::name_pl);
427 else if (num < 10) 419 else if (num < 10)
432 sprintf (buf, "lots of %s", &coin->object::name_pl); 424 sprintf (buf, "lots of %s", &coin->object::name_pl);
433 else if (num < 1000) 425 else if (num < 1000)
434 sprintf (buf, "a great many %s", &coin->object::name_pl); 426 sprintf (buf, "a great many %s", &coin->object::name_pl);
435 else 427 else
436 sprintf (buf, "a vast quantity of %s", &coin->object::name_pl); 428 sprintf (buf, "a vast quantity of %s", &coin->object::name_pl);
429
437 return buf; 430 return buf;
438 } 431 }
439 } 432 }
440 } 433 }
441 434
638 count--; 631 count--;
639 } 632 }
640 } 633 }
641 634
642 for (i = 0; i < NUM_COINS; i++) 635 for (i = 0; i < NUM_COINS; i++)
643 {
644 if (coin_objs[i]->nrof) 636 if (coin_objs[i]->nrof)
645 insert_ob_in_ob (coin_objs [i], pouch); 637 insert_ob_in_ob (coin_objs [i], pouch);
646 else 638 else
647 coin_objs[i]->destroy (); 639 coin_objs[i]->destroy ();
648 }
649} 640}
650 641
651/* 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
652 * 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.
653 * 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
673 unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); 664 unpaid_price += query_cost (item, pl, F_BUY | F_SHOP);
674 } 665 }
675 666
676 if (unpaid_price > player_wealth) 667 if (unpaid_price > player_wealth)
677 { 668 {
678 char buf[MAX_BUF]; 669 dynbuf_text buf;
679 char cost[MAX_BUF];
680 char missing[MAX_BUF];
681 670
682 snprintf (cost, MAX_BUF, "%s", cost_string_from_value (unpaid_price, 0)); 671 buf << "You have " << unpaid_count
683 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.>";
684 676
685 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);
686 unpaid_count, cost, missing);
687 new_draw_info (NDI_UNIQUE, 0, pl, buf);
688 678
689 return 0; 679 return 0;
690 } 680 }
691 else 681 else
692 return 1; 682 return 1;
804 794
805/* elmex: this is for the bank plugin :( */ 795/* elmex: this is for the bank plugin :( */
806sint64 796sint64
807pay_player_arch (object *pl, const char *arch, sint64 amount) 797pay_player_arch (object *pl, const char *arch, sint64 amount)
808{ 798{
809 archetype *at = archetype::find (arch);
810
811 if (!at)
812 return 0;
813
814 if (amount > 0) 799 if (amount)
815 { 800 {
816 object *tmp = arch_to_object (at); 801 object *ob = archetype::get (arch);
802
803 if (!ob)
804 return 0;
805
817 tmp->nrof = amount; 806 ob->nrof = amount;
818 insert_ob_in_ob (tmp, pl); 807 pl->insert (ob);
819 } 808 }
820 809
821 return 1; 810 return 1;
822} 811}
823 812
1075{ 1064{
1076 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; 1065 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2;
1077 1066
1078 if (s1->type < s2->type) 1067 if (s1->type < s2->type)
1079 return -1; 1068 return -1;
1069
1080 if (s1->type > s2->type) 1070 if (s1->type > s2->type)
1081 return 1; 1071 return 1;
1082 1072
1083 /* 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
1084 * via alphabetical order 1074 * via alphabetical order
1134 1124
1135void 1125void
1136shop_listing (object *sign, object *op) 1126shop_listing (object *sign, object *op)
1137{ 1127{
1138 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; 1128 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2;
1139 const char *shop_coords = get_ob_key_value (sign, "shop_coords"); 1129 const char *shop_coords = sign->kv (shstr_shop_coords);
1140 object *stack; 1130 object *stack;
1141 shopinv *items; 1131 shopinv *items;
1142 1132
1143 /* 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 */
1144 if (op->type != PLAYER) 1134 if (op->type != PLAYER)
1217 1207
1218/* elmex: this function checks whether the object is in a shop */ 1208/* elmex: this function checks whether the object is in a shop */
1219bool 1209bool
1220is_in_shop (object *o) 1210is_in_shop (object *o)
1221{ 1211{
1222 if (!o->map) 1212 if (!o->is_on_map ())
1223 return false; 1213 return false;
1224 1214
1225 return is_in_shop (o->map, o->x, o->y); 1215 return is_in_shop (o->map, o->x, o->y);
1226} 1216}
1227 1217
1235is_in_shop (maptile *map, int x, int y) 1225is_in_shop (maptile *map, int x, int y)
1236{ 1226{
1237 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)
1238 if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) 1228 if (QUERY_FLAG (floor, FLAG_IS_FLOOR))
1239 return floor->type == SHOP_FLOOR; 1229 return floor->type == SHOP_FLOOR;
1230
1240 return false; 1231 return false;
1241} 1232}
1242 1233

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines