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.47 by root, Sun Apr 13 01:34:09 2008 UTC vs.
Revision 1.53 by root, Sat May 3 11:14:50 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
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
583 { 576 {
584 // This should not happen, but if it does, just merge the two. 577 // This should not happen, but if it does, just merge the two.
585 if (coin_objs [i]) 578 if (coin_objs [i])
586 { 579 {
587 LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); 580 LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]);
588 tmp->remove ();
589 coin_objs[i]->nrof += tmp->nrof; 581 coin_objs[i]->nrof += tmp->nrof;
590 esrv_del_item (pl->contr, tmp->count);
591 tmp->destroy (); 582 tmp->destroy ();
592 } 583 }
593 else 584 else
594 { 585 {
595 tmp->remove (); 586 tmp->remove ();
596
597 if (pouch->type == PLAYER)
598 esrv_del_item (pl->contr, tmp->count);
599
600 coin_objs[i] = tmp; 587 coin_objs[i] = tmp;
601 } 588 }
602 589
603 break; 590 break;
604 } 591 }
646 } 633 }
647 634
648 for (i = 0; i < NUM_COINS; i++) 635 for (i = 0; i < NUM_COINS; i++)
649 { 636 {
650 if (coin_objs[i]->nrof) 637 if (coin_objs[i]->nrof)
651 {
652 object *tmp = insert_ob_in_ob (coin_objs[i], pouch); 638 insert_ob_in_ob (coin_objs [i], pouch);
653
654 esrv_send_item (pl, tmp);
655 esrv_send_item (pl, pouch);
656
657 if (pl != pouch)
658 esrv_update_item (UPD_WEIGHT, pl, pouch);
659
660 if (pl->type != PLAYER)
661 esrv_send_item (pl, pl);
662 }
663 else 639 else
664 coin_objs[i]->destroy (); 640 coin_objs[i]->destroy ();
665 } 641 }
666} 642}
667 643
738 SET_FLAG (op, FLAG_UNPAID); 714 SET_FLAG (op, FLAG_UNPAID);
739 return 0; 715 return 0;
740 } 716 }
741 else 717 else
742 { 718 {
743 object *tmp;
744
745 CLEAR_FLAG (op, FLAG_UNPAID); 719 CLEAR_FLAG (op, FLAG_UNPAID);
746 CLEAR_FLAG (op, FLAG_PLAYER_SOLD); 720 CLEAR_FLAG (op, FLAG_PLAYER_SOLD);
747 new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); 721 new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op));
748 tmp = merge_ob (op, NULL);
749 722
750 if (pl->type == PLAYER) 723 if (!merge_ob (op, op->env->inv))
751 {
752 if (tmp)
753 { /* it was merged */
754 esrv_del_item (pl->contr, op->count);
755 op = tmp;
756 }
757
758 esrv_send_item (pl, op); 724 esrv_update_item (UPD_FLAGS, pl, op);
759 }
760 725
761 goto next_item; 726 goto next_item;
762 } 727 }
763 } 728 }
764 } 729 }
806 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) 771 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit))
807 { 772 {
808 if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) 773 if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n)
809 n = (pouch->weight_limit - pouch->carrying) / w; 774 n = (pouch->weight_limit - pouch->carrying) / w;
810 775
811 tmp = arch_to_object (at); 776 object *tmp = arch_to_object (at);
812 tmp->nrof = n; 777 tmp->nrof = n;
813 amount -= tmp->nrof * tmp->value; 778 amount -= tmp->nrof * tmp->value;
814 tmp = insert_ob_in_ob (tmp, pouch); 779 pouch->insert (tmp);
815 esrv_send_item (pl, tmp);
816 esrv_send_item (pl, pouch);
817 esrv_update_item (UPD_WEIGHT, pl, pouch);
818 esrv_send_item (pl, pl);
819 } 780 }
820 } 781 }
821 } 782 }
822 783
823 if (amount / at->value > 0) 784 if (amount / at->value > 0)
824 { 785 {
825 tmp = arch_to_object (at); 786 object *tmp = arch_to_object (at);
826 tmp->nrof = amount / tmp->value; 787 tmp->nrof = amount / tmp->value;
827 amount -= tmp->nrof * tmp->value; 788 amount -= tmp->nrof * tmp->value;
828 tmp = insert_ob_in_ob (tmp, pl); 789 pl->insert (tmp);
829 esrv_send_item (pl, tmp);
830 esrv_send_item (pl, pl);
831 } 790 }
832 } 791 }
833 } 792 }
834 793
835 if (amount != 0) 794 if (amount != 0)
847 806
848 if (amount > 0) 807 if (amount > 0)
849 { 808 {
850 object *tmp = arch_to_object (at); 809 object *tmp = arch_to_object (at);
851 tmp->nrof = amount; 810 tmp->nrof = amount;
852 tmp = insert_ob_in_ob (tmp, pl); 811 insert_ob_in_ob (tmp, pl);
853 esrv_send_item (pl, tmp);
854 esrv_send_item (pl, pl);
855 } 812 }
856 813
857 return 1; 814 return 1;
858} 815}
859 816
862 * buy item. 819 * buy item.
863 * 820 *
864 * Modified to fill available race: gold containers before dumping 821 * Modified to fill available race: gold containers before dumping
865 * remaining coins in character's inventory. 822 * remaining coins in character's inventory.
866 */ 823 */
867void 824bool
868sell_item (object *op, object *pl) 825sell_item (object *op, object *pl)
869{ 826{
870 sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; 827 sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain;
871 828
872 if (pl == NULL || pl->type != PLAYER) 829 if (pl == NULL || pl->type != PLAYER)
873 { 830 {
874 LOG (llevDebug, "Object other than player tried to sell something.\n"); 831 LOG (llevDebug, "Object other than player tried to sell something.\n");
875 return; 832 return false;
876 } 833 }
877 834
878 op->custom_name = 0; 835 op->custom_name = 0;
879 836
880 if (!amount) 837 if (!amount)
881 { 838 {
882 new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", query_name (op)); 839 new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.",
883 840 query_name (op));
884 /* Even if the character doesn't get anything for it, it may still be 841 // elmex: change: the player now gets the item back if the shop is not
885 * worth something. If so, make it unpaid 842 // interested in it.
886 */
887 if (op->value)
888 {
889 SET_FLAG (op, FLAG_UNPAID);
890 SET_FLAG (op, FLAG_PLAYER_SOLD);
891 }
892
893 identify (op);
894 return; 843 return false;
895 } 844 }
896 845
897 /* We compare the price with the one for a player 846 /* We compare the price with the one for a player
898 * without bargaining skill. 847 * without bargaining skill.
899 * This determins the amount of exp (if any) gained for bargaining. 848 * This determins the amount of exp (if any) gained for bargaining.
904 if (extra_gain > 0) 853 if (extra_gain > 0)
905 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); 854 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE);
906 855
907 pay_player (pl, amount); 856 pay_player (pl, amount);
908 857
909 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)); 858 new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.",
859 query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op));
910 pl->play_sound (sound_find ("shop_sell")); 860 pl->play_sound (sound_find ("shop_sell"));
911 861
912 SET_FLAG (op, FLAG_UNPAID); 862 SET_FLAG (op, FLAG_UNPAID);
913 identify (op); 863 identify (op);
864
865 return true;
914} 866}
915 867
916/* returns a double that is the ratio of the price that a shop will offer for 868/* returns a double that is the ratio of the price that a shop will offer for
917 * item based on the shops specialisation. Does not take account of greed, 869 * item based on the shops specialisation. Does not take account of greed,
918 * returned value is between SPECIALISATION_EFFECT and 1. 870 * returned value is between SPECIALISATION_EFFECT and 1.
1116{ 1068{
1117 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; 1069 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2;
1118 1070
1119 if (s1->type < s2->type) 1071 if (s1->type < s2->type)
1120 return -1; 1072 return -1;
1073
1121 if (s1->type > s2->type) 1074 if (s1->type > s2->type)
1122 return 1; 1075 return 1;
1123 1076
1124 /* the type is the same (what atoi gets), so do a strcasecmp to sort 1077 /* the type is the same (what atoi gets), so do a strcasecmp to sort
1125 * via alphabetical order 1078 * via alphabetical order
1175 1128
1176void 1129void
1177shop_listing (object *sign, object *op) 1130shop_listing (object *sign, object *op)
1178{ 1131{
1179 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; 1132 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2;
1180 const char *shop_coords = get_ob_key_value (sign, "shop_coords"); 1133 const char *shop_coords = sign->kv (shstr_shop_coords);
1181 object *stack; 1134 object *stack;
1182 shopinv *items; 1135 shopinv *items;
1183 1136
1184 /* Should never happen, but just in case a monster does apply a sign */ 1137 /* Should never happen, but just in case a monster does apply a sign */
1185 if (op->type != PLAYER) 1138 if (op->type != PLAYER)
1258 1211
1259/* elmex: this function checks whether the object is in a shop */ 1212/* elmex: this function checks whether the object is in a shop */
1260bool 1213bool
1261is_in_shop (object *o) 1214is_in_shop (object *o)
1262{ 1215{
1263 if (!o->map) 1216 if (!o->is_on_map ())
1264 return false; 1217 return false;
1265 1218
1266 return is_in_shop (o->map, o->x, o->y); 1219 return is_in_shop (o->map, o->x, o->y);
1267} 1220}
1268 1221
1276is_in_shop (maptile *map, int x, int y) 1229is_in_shop (maptile *map, int x, int y)
1277{ 1230{
1278 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) 1231 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above)
1279 if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) 1232 if (QUERY_FLAG (floor, FLAG_IS_FLOOR))
1280 return floor->type == SHOP_FLOOR; 1233 return floor->type == SHOP_FLOOR;
1234
1281 return false; 1235 return false;
1282} 1236}
1283 1237

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines