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

Comparing deliantra/server/server/c_object.C (file contents):
Revision 1.80 by elmex, Sun Oct 5 12:40:21 2008 UTC vs.
Revision 1.84 by root, Mon Dec 22 21:11:27 2008 UTC

520 520
521 return 0; 521 return 0;
522} 522}
523 523
524/* 524/*
525 * This function was part of drop, now is own function. 525 * This function was part of drop, now is own function.
526 * Player 'op' tries to put object 'tmp' into sack 'sack', 526 * Player 'op' tries to put object 'tmp' into sack 'sack',
527 * if nrof is non zero, then nrof objects is tried to put into sack. 527 * if nrof is non zero, then nrof objects is tried to put into sack.
528 *
528 * Note that the 'sack' in question can now be a transport, 529 * Note that the 'sack' in question can now be a transport,
529 * so this function isn't named very good anymore. 530 * so this function isn't named very good anymore.
530 */ 531 */
531void 532void
532put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof) 533put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof)
609 * off 610 * off
610 */ 611 */
611 if (!can_split (op, tmp, nrof)) 612 if (!can_split (op, tmp, nrof))
612 return; 613 return;
613 614
615 drop_object (op, tmp);
616
617 if (!tmp->destroyed () && !tmp->is_inserted ())
618 {
619 // if nothing happened with the object we give it back
620 op->insert (tmp);
621 }
622}
623
624/* In contrast to drop_object (op, tmp, nrof) above this function takes the
625 * already split off object, and feeds it to the event handlers and does
626 * other magic with it.
627 *
628 * <droppper> is the object that dropped this object and <obj> is the
629 * object that was dropped.
630 *
631 * Make sure to check what happened with <obj> after this function returns!
632 * Otherwise you may leak this object.
633 */
634
635void
636drop_object (object *dropper, object *obj)
637{
614 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op))) 638 if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper)))
615 return; 639 return;
640
641 if (obj->destroyed () || obj->is_inserted ())
642 return;
616 643
617 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 644 if (QUERY_FLAG (obj, FLAG_STARTEQUIP))
618 { 645 {
619 op->statusmsg (format ("You drop the %s.", query_name (tmp))); 646 dropper->statusmsg (format ("You drop the %s.", query_name (obj)));
620 op->statusmsg ("The god who lent it to you retrieves it."); 647 dropper->statusmsg ("The god who lent it to you retrieves it.");
621 648
622 tmp->destroy (); 649 obj->destroy ();
623 op->update_stats (); 650 dropper->update_stats ();
624 return; 651 return;
625 } 652 }
626 653
627 /* Call this before we update the various windows/players. At least 654 for (object *floor = GET_MAP_OB (dropper->map, dropper->x, dropper->y);
628 * that we, we know the weight is correct. 655 floor;
656 floor = floor->above)
657 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (obj), ARG_OBJECT (dropper)))
658 return;
659
660 if (obj->destroyed () || obj->is_inserted ())
661 return;
662
663 if (is_in_shop (dropper) && !QUERY_FLAG (obj, FLAG_UNPAID) && obj->type != MONEY)
664 if (!sell_item (obj, dropper))
665 return;
666
667 /* If nothing special happened with this object, the default action is to
668 * insert it below the dropper:
629 */ 669 */
630 // 2007-11-26: moved op->update_stats away and calling it later after
631 // all items of a drop command have been processed.
632 670
633 for (object *floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above) 671 obj->x = dropper->x;
634 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) 672 obj->y = dropper->y;
635 return;
636 673
637 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
638 {
639 if (!sell_item (tmp, op))
640 {
641 // if we can't sell it we don't drop it, so give it back to the seller
642 op->insert (tmp);
643 return;
644 }
645 }
646
647 tmp->x = op->x;
648 tmp->y = op->y;
649
650 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); 674 insert_ob_in_map (obj, dropper->map, dropper, INS_BELOW_ORIGINATOR);
651} 675}
652 676
653void 677void
654drop (object *op, object *tmp) 678drop (object *op, object *tmp)
655{ 679{
853 877
854/* draw_look(op);*/ 878/* draw_look(op);*/
855 return 0; 879 return 0;
856} 880}
857 881
882
883/* This function tries to drop all objects in the <objs> vector.
884 * <dropper> is the object that wants to drop them.
885 * <cnt> can be a 0 pointer or a pointer to the maximum number of
886 * drop operations to perform.
887 *
888 * Returns true if at least one item was dropped.
889 */
890bool
891drop_vector (object *dropper, vector<object *> &objs, int *cnt)
892{
893 vector<object *>::iterator i;
894
895 bool did_one = false;
896
897 for (i = objs.begin (); i != objs.end (); i++)
898 {
899 drop (dropper, *i);
900 if (cnt && --*cnt <= 0) break;
901 did_one = true;
902 }
903
904 return did_one;
905}
906
858/* Object op wants to drop object(s) params. params can be a 907/* Object op wants to drop object(s) params. params can be a
859 * comma seperated list. 908 * comma seperated list.
860 */ 909 */
861int 910int
862command_drop (object *op, char *params) 911command_drop (object *op, char *params)
869 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); 918 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?");
870 return 0; 919 return 0;
871 } 920 }
872 else 921 else
873 { 922 {
874 int cnt = MAX_ITEM_PER_DROP; 923 vector<object *> matched_objs;
875 924
876 for (tmp = op->inv; tmp; tmp = next) 925 for (tmp = op->inv; tmp; tmp = next)
877 { 926 {
878 next = tmp->below; 927 next = tmp->below;
879 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) 928 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible)
880 continue; 929 continue;
881 930
882 if (item_matched_string (op, tmp, params)) 931 if (item_matched_string (op, tmp, params))
883 { 932 matched_objs.push_back (tmp);
884 drop (op, tmp);
885 if (--cnt <= 0) break;
886 did_one = 1;
887 } 933 }
888 }
889 934
890 if (!did_one) 935 int cnt = MAX_ITEM_PER_DROP;
936
937 if (!drop_vector (op, matched_objs, &cnt))
891 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 938 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
892 939
893 if (cnt <= 0) 940 if (cnt <= 0)
894 op->failmsg ("Only dropped some items, can't drop that many items at once."); 941 op->failmsg ("Only dropped some items, can't drop that many items at once.");
895 } 942 }
1085 1132
1086 switch (type) 1133 switch (type)
1087 { 1134 {
1088 case SPELLBOOK: 1135 case SPELLBOOK:
1089 if (flag [FLAG_IDENTIFIED] && inv) 1136 if (flag [FLAG_IDENTIFIED] && inv)
1090 buf.printf ("%s is a %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill); 1137 buf.printf ("%s is a level %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill);
1091 break; 1138 break;
1092 1139
1093 case BOOK: 1140 case BOOK:
1094 if (msg) 1141 if (msg)
1095 buf << "Something is written in it.\r"; 1142 buf << "Something is written in it.\r";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines