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.48 by root, Tue Apr 22 02:46:18 2008 UTC vs.
Revision 1.54 by root, Sat Aug 30 02:26:46 2008 UTC

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
640 } 633 }
641 634
642 for (i = 0; i < NUM_COINS; i++) 635 for (i = 0; i < NUM_COINS; i++)
643 { 636 {
644 if (coin_objs[i]->nrof) 637 if (coin_objs[i]->nrof)
645 {
646 object *tmp = insert_ob_in_ob (coin_objs[i], pouch); 638 insert_ob_in_ob (coin_objs [i], pouch);
647
648 esrv_send_item (pl, tmp);
649 esrv_send_item (pl, pouch);
650
651 if (pl != pouch)
652 esrv_update_item (UPD_WEIGHT, pl, pouch);
653
654 if (pl->type != PLAYER)
655 esrv_send_item (pl, pl);
656 }
657 else 639 else
658 coin_objs[i]->destroy (); 640 coin_objs[i]->destroy ();
659 } 641 }
660} 642}
661 643
684 unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); 666 unpaid_price += query_cost (item, pl, F_BUY | F_SHOP);
685 } 667 }
686 668
687 if (unpaid_price > player_wealth) 669 if (unpaid_price > player_wealth)
688 { 670 {
689 char buf[MAX_BUF]; 671 dynbuf_text buf;
690 char cost[MAX_BUF];
691 char missing[MAX_BUF];
692 672
693 snprintf (cost, MAX_BUF, "%s", cost_string_from_value (unpaid_price, 0)); 673 buf << "You have " << unpaid_count
694 snprintf (missing, MAX_BUF, "%s", cost_string_from_value (unpaid_price - player_wealth, 0)); 674 << " unpaid item(s) that would cost you " << cost_string_from_value (unpaid_price, 0)
675 << ". You need another " << cost_string_from_value (unpaid_price - player_wealth, 0)
676 << " to be able to afford that.";
695 677
696 snprintf (buf, MAX_BUF, "You have %d unpaid items that would cost you %s. You need another %s to be able to afford that.", 678 pl->failmsg (buf);
697 unpaid_count, cost, missing);
698 new_draw_info (NDI_UNIQUE, 0, pl, buf);
699 679
700 return 0; 680 return 0;
701 } 681 }
702 else 682 else
703 return 1; 683 return 1;
732 SET_FLAG (op, FLAG_UNPAID); 712 SET_FLAG (op, FLAG_UNPAID);
733 return 0; 713 return 0;
734 } 714 }
735 else 715 else
736 { 716 {
737 object *tmp;
738
739 CLEAR_FLAG (op, FLAG_UNPAID); 717 CLEAR_FLAG (op, FLAG_UNPAID);
740 CLEAR_FLAG (op, FLAG_PLAYER_SOLD); 718 CLEAR_FLAG (op, FLAG_PLAYER_SOLD);
741 new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); 719 new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op));
742 tmp = merge_ob (op, NULL);
743 720
744 if (pl->type == PLAYER) 721 if (!merge_ob (op, op->env->inv))
745 {
746 if (tmp)
747 { /* it was merged */
748 esrv_del_item (pl->contr, op->count);
749 op = tmp;
750 }
751
752 esrv_send_item (pl, op); 722 esrv_update_item (UPD_FLAGS, pl, op);
753 }
754 723
755 goto next_item; 724 goto next_item;
756 } 725 }
757 } 726 }
758 } 727 }
800 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) 769 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit))
801 { 770 {
802 if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) 771 if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n)
803 n = (pouch->weight_limit - pouch->carrying) / w; 772 n = (pouch->weight_limit - pouch->carrying) / w;
804 773
805 tmp = arch_to_object (at); 774 object *tmp = arch_to_object (at);
806 tmp->nrof = n; 775 tmp->nrof = n;
807 amount -= tmp->nrof * tmp->value; 776 amount -= tmp->nrof * tmp->value;
808 tmp = insert_ob_in_ob (tmp, pouch); 777 pouch->insert (tmp);
809 esrv_send_item (pl, tmp);
810 esrv_send_item (pl, pouch);
811 esrv_update_item (UPD_WEIGHT, pl, pouch);
812 esrv_send_item (pl, pl);
813 } 778 }
814 } 779 }
815 } 780 }
816 781
817 if (amount / at->value > 0) 782 if (amount / at->value > 0)
818 { 783 {
819 tmp = arch_to_object (at); 784 object *tmp = arch_to_object (at);
820 tmp->nrof = amount / tmp->value; 785 tmp->nrof = amount / tmp->value;
821 amount -= tmp->nrof * tmp->value; 786 amount -= tmp->nrof * tmp->value;
822 tmp = insert_ob_in_ob (tmp, pl); 787 pl->insert (tmp);
823 esrv_send_item (pl, tmp);
824 esrv_send_item (pl, pl);
825 } 788 }
826 } 789 }
827 } 790 }
828 791
829 if (amount != 0) 792 if (amount != 0)
832 795
833/* elmex: this is for the bank plugin :( */ 796/* elmex: this is for the bank plugin :( */
834sint64 797sint64
835pay_player_arch (object *pl, const char *arch, sint64 amount) 798pay_player_arch (object *pl, const char *arch, sint64 amount)
836{ 799{
837 archetype *at = archetype::find (arch);
838
839 if (!at)
840 return 0;
841
842 if (amount > 0) 800 if (amount)
843 { 801 {
844 object *tmp = arch_to_object (at); 802 object *ob = archetype::get (arch);
803
804 if (!ob)
805 return 0;
806
845 tmp->nrof = amount; 807 ob->nrof = amount;
846 tmp = insert_ob_in_ob (tmp, pl); 808 pl->insert (ob);
847 esrv_send_item (pl, tmp);
848 esrv_send_item (pl, pl);
849 } 809 }
850 810
851 return 1; 811 return 1;
852} 812}
853 813
856 * buy item. 816 * buy item.
857 * 817 *
858 * Modified to fill available race: gold containers before dumping 818 * Modified to fill available race: gold containers before dumping
859 * remaining coins in character's inventory. 819 * remaining coins in character's inventory.
860 */ 820 */
861void 821bool
862sell_item (object *op, object *pl) 822sell_item (object *op, object *pl)
863{ 823{
864 sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; 824 sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain;
865 825
866 if (pl == NULL || pl->type != PLAYER) 826 if (pl == NULL || pl->type != PLAYER)
867 { 827 {
868 LOG (llevDebug, "Object other than player tried to sell something.\n"); 828 LOG (llevDebug, "Object other than player tried to sell something.\n");
869 return; 829 return false;
870 } 830 }
871 831
872 op->custom_name = 0; 832 op->custom_name = 0;
873 833
874 if (!amount) 834 if (!amount)
875 { 835 {
876 new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", query_name (op)); 836 new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.",
877 837 query_name (op));
878 /* Even if the character doesn't get anything for it, it may still be 838 // elmex: change: the player now gets the item back if the shop is not
879 * worth something. If so, make it unpaid 839 // interested in it.
880 */
881 if (op->value)
882 {
883 SET_FLAG (op, FLAG_UNPAID);
884 SET_FLAG (op, FLAG_PLAYER_SOLD);
885 }
886
887 identify (op);
888 return; 840 return false;
889 } 841 }
890 842
891 /* We compare the price with the one for a player 843 /* We compare the price with the one for a player
892 * without bargaining skill. 844 * without bargaining skill.
893 * This determins the amount of exp (if any) gained for bargaining. 845 * This determins the amount of exp (if any) gained for bargaining.
898 if (extra_gain > 0) 850 if (extra_gain > 0)
899 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); 851 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE);
900 852
901 pay_player (pl, amount); 853 pay_player (pl, amount);
902 854
903 new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); 855 new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.",
856 query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op));
904 pl->play_sound (sound_find ("shop_sell")); 857 pl->play_sound (sound_find ("shop_sell"));
905 858
906 SET_FLAG (op, FLAG_UNPAID); 859 SET_FLAG (op, FLAG_UNPAID);
907 identify (op); 860 identify (op);
861
862 return true;
908} 863}
909 864
910/* returns a double that is the ratio of the price that a shop will offer for 865/* returns a double that is the ratio of the price that a shop will offer for
911 * item based on the shops specialisation. Does not take account of greed, 866 * item based on the shops specialisation. Does not take account of greed,
912 * returned value is between SPECIALISATION_EFFECT and 1. 867 * returned value is between SPECIALISATION_EFFECT and 1.
1110{ 1065{
1111 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; 1066 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2;
1112 1067
1113 if (s1->type < s2->type) 1068 if (s1->type < s2->type)
1114 return -1; 1069 return -1;
1070
1115 if (s1->type > s2->type) 1071 if (s1->type > s2->type)
1116 return 1; 1072 return 1;
1117 1073
1118 /* the type is the same (what atoi gets), so do a strcasecmp to sort 1074 /* the type is the same (what atoi gets), so do a strcasecmp to sort
1119 * via alphabetical order 1075 * via alphabetical order
1169 1125
1170void 1126void
1171shop_listing (object *sign, object *op) 1127shop_listing (object *sign, object *op)
1172{ 1128{
1173 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; 1129 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2;
1174 const char *shop_coords = get_ob_key_value (sign, "shop_coords"); 1130 const char *shop_coords = sign->kv (shstr_shop_coords);
1175 object *stack; 1131 object *stack;
1176 shopinv *items; 1132 shopinv *items;
1177 1133
1178 /* Should never happen, but just in case a monster does apply a sign */ 1134 /* Should never happen, but just in case a monster does apply a sign */
1179 if (op->type != PLAYER) 1135 if (op->type != PLAYER)
1252 1208
1253/* elmex: this function checks whether the object is in a shop */ 1209/* elmex: this function checks whether the object is in a shop */
1254bool 1210bool
1255is_in_shop (object *o) 1211is_in_shop (object *o)
1256{ 1212{
1257 if (!o->map) 1213 if (!o->is_on_map ())
1258 return false; 1214 return false;
1259 1215
1260 return is_in_shop (o->map, o->x, o->y); 1216 return is_in_shop (o->map, o->x, o->y);
1261} 1217}
1262 1218
1270is_in_shop (maptile *map, int x, int y) 1226is_in_shop (maptile *map, int x, int y)
1271{ 1227{
1272 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) 1228 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above)
1273 if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) 1229 if (QUERY_FLAG (floor, FLAG_IS_FLOOR))
1274 return floor->type == SHOP_FLOOR; 1230 return floor->type == SHOP_FLOOR;
1231
1275 return false; 1232 return false;
1276} 1233}
1277 1234

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines