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.49 by root, Tue Apr 22 07:01:47 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
826 * buy item. 815 * buy item.
827 * 816 *
828 * Modified to fill available race: gold containers before dumping 817 * Modified to fill available race: gold containers before dumping
829 * remaining coins in character's inventory. 818 * remaining coins in character's inventory.
830 */ 819 */
831void 820bool
832sell_item (object *op, object *pl) 821sell_item (object *op, object *pl)
833{ 822{
834 sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; 823 sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain;
835 824
836 if (pl == NULL || pl->type != PLAYER) 825 if (pl == NULL || pl->type != PLAYER)
837 { 826 {
838 LOG (llevDebug, "Object other than player tried to sell something.\n"); 827 LOG (llevDebug, "Object other than player tried to sell something.\n");
839 return; 828 return false;
840 } 829 }
841 830
842 op->custom_name = 0; 831 op->custom_name = 0;
843 832
844 if (!amount) 833 if (!amount)
845 { 834 {
846 new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", query_name (op)); 835 new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.",
847 836 query_name (op));
848 /* Even if the character doesn't get anything for it, it may still be 837 // elmex: change: the player now gets the item back if the shop is not
849 * worth something. If so, make it unpaid 838 // interested in it.
850 */
851 if (op->value)
852 {
853 SET_FLAG (op, FLAG_UNPAID);
854 SET_FLAG (op, FLAG_PLAYER_SOLD);
855 }
856
857 identify (op);
858 return; 839 return false;
859 } 840 }
860 841
861 /* We compare the price with the one for a player 842 /* We compare the price with the one for a player
862 * without bargaining skill. 843 * without bargaining skill.
863 * This determins the amount of exp (if any) gained for bargaining. 844 * This determins the amount of exp (if any) gained for bargaining.
868 if (extra_gain > 0) 849 if (extra_gain > 0)
869 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); 850 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE);
870 851
871 pay_player (pl, amount); 852 pay_player (pl, amount);
872 853
873 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)); 854 new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.",
855 query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op));
874 pl->play_sound (sound_find ("shop_sell")); 856 pl->play_sound (sound_find ("shop_sell"));
875 857
876 SET_FLAG (op, FLAG_UNPAID); 858 SET_FLAG (op, FLAG_UNPAID);
877 identify (op); 859 identify (op);
860
861 return true;
878} 862}
879 863
880/* returns a double that is the ratio of the price that a shop will offer for 864/* returns a double that is the ratio of the price that a shop will offer for
881 * item based on the shops specialisation. Does not take account of greed, 865 * item based on the shops specialisation. Does not take account of greed,
882 * returned value is between SPECIALISATION_EFFECT and 1. 866 * returned value is between SPECIALISATION_EFFECT and 1.
1080{ 1064{
1081 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; 1065 shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2;
1082 1066
1083 if (s1->type < s2->type) 1067 if (s1->type < s2->type)
1084 return -1; 1068 return -1;
1069
1085 if (s1->type > s2->type) 1070 if (s1->type > s2->type)
1086 return 1; 1071 return 1;
1087 1072
1088 /* 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
1089 * via alphabetical order 1074 * via alphabetical order
1139 1124
1140void 1125void
1141shop_listing (object *sign, object *op) 1126shop_listing (object *sign, object *op)
1142{ 1127{
1143 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; 1128 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2;
1144 const char *shop_coords = get_ob_key_value (sign, "shop_coords"); 1129 const char *shop_coords = sign->kv (shstr_shop_coords);
1145 object *stack; 1130 object *stack;
1146 shopinv *items; 1131 shopinv *items;
1147 1132
1148 /* 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 */
1149 if (op->type != PLAYER) 1134 if (op->type != PLAYER)
1222 1207
1223/* elmex: this function checks whether the object is in a shop */ 1208/* elmex: this function checks whether the object is in a shop */
1224bool 1209bool
1225is_in_shop (object *o) 1210is_in_shop (object *o)
1226{ 1211{
1227 if (!o->map) 1212 if (!o->is_on_map ())
1228 return false; 1213 return false;
1229 1214
1230 return is_in_shop (o->map, o->x, o->y); 1215 return is_in_shop (o->map, o->x, o->y);
1231} 1216}
1232 1217
1240is_in_shop (maptile *map, int x, int y) 1225is_in_shop (maptile *map, int x, int y)
1241{ 1226{
1242 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)
1243 if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) 1228 if (QUERY_FLAG (floor, FLAG_IS_FLOOR))
1244 return floor->type == SHOP_FLOOR; 1229 return floor->type == SHOP_FLOOR;
1230
1245 return false; 1231 return false;
1246} 1232}
1247 1233

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines