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.68 by root, Tue Apr 22 02:46:18 2008 UTC vs.
Revision 1.89 by elmex, Mon Jan 12 00:17:23 2009 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,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 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
94} 94}
95 95
96static bool 96static bool
97can_split (object *pl, object *&op, sint32 nrof) 97can_split (object *pl, object *&op, sint32 nrof)
98{ 98{
99 if (object *tmp = op->split (nrof)) 99 if (object *tmp = op->split (nrof ? nrof : op->number_of ()))
100 { 100 {
101 op = tmp; 101 op = tmp;
102 return true; 102 return true;
103 } 103 }
104 else 104 else
133 { 133 {
134 new_draw_info (NDI_UNIQUE, 0, pl, "Usage: ready_skill <skill name>"); 134 new_draw_info (NDI_UNIQUE, 0, pl, "Usage: ready_skill <skill name>");
135 return 0; 135 return 0;
136 } 136 }
137 137
138 skill = find_skill_by_name (pl, params); 138 skill = find_skill_by_name_fuzzy (pl, params);
139 139
140 if (!skill) 140 if (!skill)
141 { 141 {
142 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no knowledge of the skill %s", params); 142 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no knowledge of the skill %s", params);
143 return 0; 143 return 0;
144 } 144 }
145 145
146 pl->change_skill (0); 146 pl->change_skill (0);
147 apply_special (pl, skill, AP_APPLY); 147 apply_special (pl, skill, AP_APPLY);
148 return 1; 148 return 1;
149}
150
151/* These functions (command_search, command_disarm) are really just wrappers for
152 * things like 'use_skill ...'). In fact, they should really be obsoleted
153 * and replaced with those.
154 */
155int
156command_search (object *op, char *params)
157{
158 return use_skill (op, skill_names[SK_FIND_TRAPS]);
159}
160
161int
162command_disarm (object *op, char *params)
163{
164 return use_skill (op, skill_names[SK_DISARM_TRAPS]);
165} 149}
166 150
167/* A little special because we do want to pass the full params along 151/* A little special because we do want to pass the full params along
168 * as it includes the object to throw. 152 * as it includes the object to throw.
169 */ 153 */
284 * (sack, luggage, etc), tmp->env->env then points to the player (nested 268 * (sack, luggage, etc), tmp->env->env then points to the player (nested
285 * containers not allowed as of now) 269 * containers not allowed as of now)
286 */ 270 */
287 if ((pl->move_type & MOVE_FLYING) && !QUERY_FLAG (pl, FLAG_WIZ) && tmp->in_player () != pl) 271 if ((pl->move_type & MOVE_FLYING) && !QUERY_FLAG (pl, FLAG_WIZ) && tmp->in_player () != pl)
288 { 272 {
289 new_draw_info (NDI_UNIQUE, 0, pl, "You are levitating, you can't reach the ground!"); 273 pl->failmsg ("You are levitating, you can't reach the ground! "
274 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
275 "or waiting till the levitation effect wears off.>");
290 return; 276 return;
291 } 277 }
292 278
293 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 279 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
294 return; 280 return;
311 297
312 if (!can_split (pl, tmp, nrof)) 298 if (!can_split (pl, tmp, nrof))
313 return; 299 return;
314 300
315 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 301 if (QUERY_FLAG (tmp, FLAG_UNPAID))
302 {
303 tmp->flag.reset (FLAG_UNPAID);
316 new_draw_info_format (NDI_UNIQUE, 0, pl, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP)); 304 new_draw_info_format (NDI_UNIQUE, 0, pl, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP));
305 tmp->flag.set (FLAG_UNPAID);
306 }
317 else 307 else
318 new_draw_info_format (NDI_UNIQUE, 0, pl, "You pick up the %s.", query_name (tmp)); 308 new_draw_info_format (NDI_UNIQUE, 0, pl, "You pick up the %s.", query_name (tmp));
319 309
320 tmp = insert_ob_in_ob (tmp, op); 310 op->insert (tmp);
321
322 /* All the stuff below deals with client/server code, and is only
323 * usable by players
324 */
325 if (pl->contr)
326 {
327 esrv_send_item (pl, tmp);
328
329 /* These are needed to update the weight for the container we
330 * are putting the object in.
331 */
332 if (op != pl)
333 {
334 esrv_update_item (UPD_WEIGHT, pl, op);
335 esrv_send_item (pl, pl);
336 }
337
338 /* Update the container the object was in */
339 if (env && env != pl && env != op)
340 esrv_update_item (UPD_WEIGHT, pl, env);
341 }
342} 311}
343 312
344/* modified slightly to allow monsters use this -b.t. 5-31-95 */ 313/* modified slightly to allow monsters use this -b.t. 5-31-95 */
345void 314void
346pick_up (object *op, object *alt) 315pick_up (object *op, object *alt)
499 * but that probably will make it more difficult to read, and 468 * but that probably will make it more difficult to read, and
500 * not make it any more efficient 469 * not make it any more efficient
501 */ 470 */
502 if (params && item_matched_string (op, tmp, params)) 471 if (params && item_matched_string (op, tmp, params))
503 { 472 {
473 if (--cnt < 0) break;
504 pick_up (op, tmp); 474 pick_up (op, tmp);
505 if (--cnt <= 0) break;
506 } 475 }
507 else if (can_pick (op, tmp) && !params) 476 else if (can_pick (op, tmp) && !params)
508 { 477 {
478 if (--cnt < 0) break;
509 pick_up (op, tmp); 479 pick_up (op, tmp);
510 break; 480 break;
511 } 481 }
512 482
513 tmp = next; 483 tmp = next;
514 } 484 }
515 485
516 if (cnt <= 0) 486 if (cnt < 0)
517 { 487 {
518 op->failmsg ("Couldn't pick up so many items at once."); 488 op->failmsg ("Couldn't pick up so many items at once.");
519 return 0; 489 return 0;
520 } 490 }
521 491
534 504
535 return 0; 505 return 0;
536} 506}
537 507
538/* 508/*
539 * This function was part of drop, now is own function. 509 * This function was part of drop, now is own function.
540 * Player 'op' tries to put object 'tmp' into sack 'sack', 510 * Player 'op' tries to put object 'tmp' into sack 'sack',
541 * if nrof is non zero, then nrof objects is tried to put into sack. 511 * if nrof is non zero, then nrof objects is tried to put into sack.
512 *
542 * Note that the 'sack' in question can now be a transport, 513 * Note that the 'sack' in question can now be a transport,
543 * so this function isn't named very good anymore. 514 * so this function isn't named very good anymore.
544 */ 515 */
545void 516void
546put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof) 517put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof)
569 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) 540 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp)
570 { 541 {
571 tmp = tmp2->below; 542 tmp = tmp2->below;
572 543
573 if ((sack->type == CONTAINER && sack_can_hold (op, op->container, tmp2, tmp2->nrof))) 544 if ((sack->type == CONTAINER && sack_can_hold (op, op->container, tmp2, tmp2->nrof)))
574 {
575 put_object_in_sack (op, sack, tmp2, 0); 545 put_object_in_sack (op, sack, tmp2, 0);
576 }
577 else 546 else
578 { 547 {
579 sprintf (buf, "Your %s fills up.", query_name (sack)); 548 sprintf (buf, "Your %s fills up.", query_name (sack));
580 new_draw_info (NDI_UNIQUE, 0, op, buf); 549 new_draw_info (NDI_UNIQUE, 0, op, buf);
581 break; 550 break;
582 } 551 }
583 } 552 }
584 553
585 esrv_update_item (UPD_WEIGHT, op, sack2);
586 return; 554 return;
587 } 555 }
588 556
589 /* Don't worry about this for containers - our caller should have 557 /* Don't worry about this for containers - our caller should have
590 * already checked this. 558 * already checked this.
595 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 563 if (QUERY_FLAG (tmp, FLAG_APPLIED))
596 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 564 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
597 return; 565 return;
598 566
599 /* we want to put some portion of the item into the container */ 567 /* we want to put some portion of the item into the container */
600 if (nrof && tmp->nrof != nrof)
601 {
602 if (!can_split (op, tmp, nrof)) 568 if (!can_split (op, tmp, nrof))
603 return; 569 return;
604 }
605 else
606 tmp->remove ();
607 570
608 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack)); 571 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack));
609 tmp2 = insert_ob_in_ob (tmp, sack); 572 sack->insert (tmp);
610
611 // elmex: 2007-11-26: removed update_stats and replaced
612 // it by update_after_inventory_change () in the caller
613 // of this function
614
615 /* If an object merged (and thus, different object), we need to
616 * delete the original.
617 */
618 if (tmp2 != tmp)
619 esrv_del_item (op->contr, tmp->count);
620
621 esrv_send_item (op, tmp2);
622
623 /* update the sacks weight */
624 esrv_update_item (UPD_WEIGHT, op, sack);
625} 573}
626 574
627/* 575/*
628 * This function was part of drop, now is own function. 576 * This function was part of drop, now is own function.
629 * Player 'op' tries to drop object 'tmp', if tmp is non zero, then 577 * Player 'op' tries to drop object 'tmp', if tmp is non zero, then
631 * This is used when dropping objects onto the floor. 579 * This is used when dropping objects onto the floor.
632 */ 580 */
633void 581void
634drop_object (object *op, object *tmp, uint32 nrof) 582drop_object (object *op, object *tmp, uint32 nrof)
635{ 583{
636 object *floor;
637
638 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 584 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
639 return; 585 return;
640 586
641 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 587 if (QUERY_FLAG (tmp, FLAG_APPLIED))
642 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 588 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
645 //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D 591 //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D
646 592
647 /* We are only dropping some of the items. We split the current object 593 /* We are only dropping some of the items. We split the current object
648 * off 594 * off
649 */ 595 */
650 if (nrof && tmp->nrof != nrof)
651 {
652 if (!can_split (op, tmp, nrof)) 596 if (!can_split (op, tmp, nrof))
653 return;
654 }
655 else
656 tmp->remove ();
657
658 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op)))
659 return; 597 return;
660 598
599 drop_object (op, tmp);
600
601 if (!tmp->destroyed () && !tmp->is_inserted ())
602 {
603 // if nothing happened with the object we give it back
604 op->insert (tmp);
605 }
606}
607
608/* In contrast to drop_object (op, tmp, nrof) above this function takes the
609 * already split off object, and feeds it to the event handlers and does
610 * other magic with it.
611 *
612 * <droppper> is the object that dropped this object and <obj> is the
613 * object that was dropped.
614 *
615 * Make sure to check what happened with <obj> after this function returns!
616 * Otherwise you may leak this object.
617 */
618
619void
620drop_object (object *dropper, object *obj)
621{
622 if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper)))
623 return;
624
625 if (obj->destroyed () || obj->is_inserted ())
626 return;
627
661 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 628 if (QUERY_FLAG (obj, FLAG_STARTEQUIP))
662 { 629 {
663 op->statusmsg (format ("You drop the %s.", query_name (tmp))); 630 dropper->statusmsg (format ("You drop the %s.", query_name (obj)));
664 op->statusmsg ("The gods who lent it to you retrieves it."); 631 dropper->statusmsg ("The god who lent it to you retrieves it.");
665 632
666 tmp->destroy (); 633 obj->destroy ();
667 op->update_stats (); 634 dropper->update_stats ();
668 return; 635 return;
669 } 636 }
670 637
671 if (op->type == PLAYER) 638 for (object *floor = GET_MAP_OB (dropper->map, dropper->x, dropper->y);
672 esrv_del_item (op->contr, tmp->count); 639 floor;
640 floor = floor->above)
641 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (obj), ARG_OBJECT (dropper)))
642 return;
673 643
674 /* Call this before we update the various windows/players. At least 644 if (obj->destroyed () || obj->is_inserted ())
675 * that we, we know the weight is correct. 645 return;
646
647 if (is_in_shop (dropper) && !QUERY_FLAG (obj, FLAG_UNPAID) && obj->type != MONEY)
648 if (!sell_item (obj, dropper))
649 return;
650
651 /* If nothing special happened with this object, the default action is to
652 * insert it below the dropper:
676 */ 653 */
677 // 2007-11-26: moved op->update_stats away and calling it later after
678 // all items of a drop command have been processed.
679 654
680 for (floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above) 655 obj->x = dropper->x;
681 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) 656 obj->y = dropper->y;
682 return;
683 657
684 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
685 sell_item (tmp, op);
686
687 tmp->x = op->x;
688 tmp->y = op->y;
689
690 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); 658 insert_ob_in_map (obj, dropper->map, dropper, INS_BELOW_ORIGINATOR);
691}
692
693void update_after_inventory_change (object *op)
694{
695 /* Call this before we update the various windows/players. At least
696 * that we, we know the weight is correct.
697 */
698 op->update_stats ();
699
700 // elmex: kept this for now, i have no idea what happens when i remove it:
701 if (op->type == PLAYER)
702 {
703 /* Need to update the weight for the player */
704 esrv_send_item (op, op);
705 op->contr->ns->floorbox_update ();
706 }
707} 659}
708 660
709void 661void
710drop (object *op, object *tmp) 662drop (object *op, object *tmp)
711{ 663{
720 if (tmp->env && tmp->env->type != PLAYER) 672 if (tmp->env && tmp->env->type != PLAYER)
721 { 673 {
722 /* Just toss the object - probably shouldn't be hanging 674 /* Just toss the object - probably shouldn't be hanging
723 * around anyways 675 * around anyways
724 */ 676 */
725 tmp->remove ();
726 tmp->destroy (); 677 tmp->destroy ();
727 return; 678 return;
728 } 679 }
729 else 680 else
730 { 681 {
731 while (tmp != NULL && tmp->invisible) 682 while (tmp && tmp->invisible)
732 tmp = tmp->below; 683 tmp = tmp->below;
733 } 684 }
734 } 685 }
735 686
736 if (tmp == NULL) 687 if (tmp == NULL)
737 { 688 {
738 new_draw_info (NDI_UNIQUE, 0, op, "You don't have anything to drop."); 689 new_draw_info (NDI_UNIQUE, 0, op, "You don't have anything to drop.");
739 return; 690 return;
740 } 691 }
692
741 if (QUERY_FLAG (tmp, FLAG_INV_LOCKED)) 693 if (QUERY_FLAG (tmp, FLAG_INV_LOCKED))
742 { 694 {
743 new_draw_info (NDI_UNIQUE, 0, op, "This item is locked"); 695 new_draw_info (NDI_UNIQUE, 0, op, "This item is locked");
744 return; 696 return;
745 } 697 }
698
746 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 699 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
747 { 700 {
748#if 0 701#if 0
749 /* Eneq(@csd.uu.se): Objects with NO_DROP defined can't be dropped. */ 702 /* Eneq(@csd.uu.se): Objects with NO_DROP defined can't be dropped. */
750 new_draw_info (NDI_UNIQUE, 0, op, "This item can't be dropped."); 703 new_draw_info (NDI_UNIQUE, 0, op, "This item can't be dropped.");
774 727
775 if (op->type == PLAYER) 728 if (op->type == PLAYER)
776 op->contr->count = 0; 729 op->contr->count = 0;
777} 730}
778 731
779
780
781/* Command will drop all items that have not been locked */ 732/* Command will drop all items that have not been locked */
782int 733int
783command_dropall (object *op, char *params) 734command_dropall (object *op, char *params)
784{ 735{
785 736
786 object *curinv, *nextinv;
787
788 if (op->inv == NULL) 737 if (op->inv == NULL)
789 { 738 {
790 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop!"); 739 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop!");
791 return 0; 740 return 0;
792 } 741 }
793 742
794 curinv = op->inv; 743 object *curinv = op->inv;
744 object *nextinv;
795 745
796 /* 746 /*
797 This is the default. Drops everything not locked or considered 747 This is the default. Drops everything not locked or considered
798 not something that should be dropped. 748 not something that should be dropped.
799 */ 749 */
803 in a shop. --Tero.Pelander@utu.fi 753 in a shop. --Tero.Pelander@utu.fi
804 */ 754 */
805 755
806 int cnt = MAX_ITEM_PER_DROP; 756 int cnt = MAX_ITEM_PER_DROP;
807 757
808 if (params == NULL) 758 if (!params)
809 { 759 {
810 while (curinv != NULL) 760 while (curinv)
811 { 761 {
812 nextinv = curinv->below; 762 nextinv = curinv->below;
763
813 while (nextinv && nextinv->type == MONEY) 764 while (nextinv && nextinv->type == MONEY)
814 nextinv = nextinv->below; 765 nextinv = nextinv->below;
766
815 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY && 767 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY &&
816 curinv->type != FOOD && curinv->type != KEY && 768 curinv->type != FOOD && curinv->type != KEY &&
817 curinv->type != SPECIAL_KEY && curinv->type != GEM && 769 curinv->type != SPECIAL_KEY && curinv->type != GEM &&
818 !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv)) 770 !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv))
819 { 771 {
820 drop (op, curinv); 772 drop (op, curinv);
821 if (--cnt <= 0) break; 773 if (--cnt <= 0) break;
822 } 774 }
775
823 curinv = nextinv; 776 curinv = nextinv;
824 } 777 }
825 } 778 }
826
827 else if (strcmp (params, "weapons") == 0) 779 else if (strcmp (params, "weapons") == 0)
828 { 780 {
829 while (curinv != NULL) 781 while (curinv)
830 { 782 {
831 nextinv = curinv->below; 783 nextinv = curinv->below;
784
832 while (nextinv && nextinv->type == MONEY) 785 while (nextinv && nextinv->type == MONEY)
833 nextinv = nextinv->below; 786 nextinv = nextinv->below;
787
834 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == WEAPON) || (curinv->type == BOW) || (curinv->type == ARROW))) 788 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == WEAPON) || (curinv->type == BOW) || (curinv->type == ARROW)))
835 { 789 {
836 drop (op, curinv); 790 drop (op, curinv);
837 if (--cnt <= 0) break; 791 if (--cnt <= 0) break;
838 } 792 }
793
839 curinv = nextinv; 794 curinv = nextinv;
840 } 795 }
841 } 796 }
842
843 else if (strcmp (params, "armor") == 0 || strcmp (params, "armour") == 0) 797 else if (strcmp (params, "armor") == 0 || strcmp (params, "armour") == 0)
844 { 798 {
845 while (curinv != NULL) 799 while (curinv)
846 { 800 {
847 nextinv = curinv->below; 801 nextinv = curinv->below;
802
848 while (nextinv && nextinv->type == MONEY) 803 while (nextinv && nextinv->type == MONEY)
849 nextinv = nextinv->below; 804 nextinv = nextinv->below;
805
850 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == ARMOUR) || curinv->type == SHIELD || curinv->type == HELMET)) 806 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == ARMOUR) || curinv->type == SHIELD || curinv->type == HELMET))
851 { 807 {
852 drop (op, curinv); 808 drop (op, curinv);
853 if (--cnt <= 0) break; 809 if (--cnt <= 0) break;
854 } 810 }
811
855 curinv = nextinv; 812 curinv = nextinv;
856 } 813 }
857 } 814 }
858
859 else if (strcmp (params, "misc") == 0) 815 else if (strcmp (params, "misc") == 0)
860 { 816 {
861 while (curinv != NULL) 817 while (curinv)
862 { 818 {
863 nextinv = curinv->below; 819 nextinv = curinv->below;
820
864 while (nextinv && nextinv->type == MONEY) 821 while (nextinv && nextinv->type == MONEY)
865 nextinv = nextinv->below; 822 nextinv = nextinv->below;
823
866 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && !QUERY_FLAG (curinv, FLAG_APPLIED)) 824 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && !QUERY_FLAG (curinv, FLAG_APPLIED))
867 { 825 {
868 switch (curinv->type) 826 switch (curinv->type)
869 { 827 {
870 case HORN: 828 case HORN:
888 break; 846 break;
889 default: 847 default:
890 curinv = nextinv; 848 curinv = nextinv;
891 break; 849 break;
892 } 850 }
851
893 if (--cnt <= 0) break; 852 if (--cnt <= 0) break;
894 } 853 }
854
895 curinv = nextinv; 855 curinv = nextinv;
896 } 856 }
897 } 857 }
898 858
899 if (cnt <= 0) 859 if (cnt <= 0)
900 op->failmsg ("Only dropped some items, can't drop that many items at once."); 860 op->failmsg ("Only dropped some items, can't drop that many items at once.");
901 861
902 update_after_inventory_change (op);
903
904/* draw_look(op);*/ 862/* draw_look(op);*/
905 return 0; 863 return 0;
864}
865
866
867/* This function tries to drop all objects in the <objs> vector.
868 * <dropper> is the object that wants to drop them.
869 * <cnt> can be a 0 pointer or a pointer to the maximum number of
870 * drop operations to perform.
871 *
872 * Returns true if at least one item was dropped.
873 */
874bool
875drop_vector (object *dropper, vector<object *> &objs, int *cnt)
876{
877 vector<object *>::iterator i;
878
879 bool did_one = false;
880
881 for (i = objs.begin (); i != objs.end (); i++)
882 {
883 drop (dropper, *i);
884 if (cnt && --*cnt <= 0) break;
885 did_one = true;
886 }
887
888 return did_one;
906} 889}
907 890
908/* Object op wants to drop object(s) params. params can be a 891/* Object op wants to drop object(s) params. params can be a
909 * comma seperated list. 892 * comma seperated list.
910 */ 893 */
911
912int 894int
913command_drop (object *op, char *params) 895command_drop (object *op, char *params)
914{ 896{
915 object *tmp, *next; 897 object *tmp, *next;
916 int did_one = 0; 898 int did_one = 0;
920 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); 902 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?");
921 return 0; 903 return 0;
922 } 904 }
923 else 905 else
924 { 906 {
925 int cnt = MAX_ITEM_PER_DROP; 907 vector<object *> matched_objs;
926 908
927 for (tmp = op->inv; tmp; tmp = next) 909 for (tmp = op->inv; tmp; tmp = next)
928 { 910 {
929 next = tmp->below; 911 next = tmp->below;
930 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) 912 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible)
931 continue; 913 continue;
932 914
933 if (item_matched_string (op, tmp, params)) 915 if (item_matched_string (op, tmp, params))
934 { 916 matched_objs.push_back (tmp);
935 drop (op, tmp);
936 if (--cnt <= 0) break;
937 did_one = 1;
938 } 917 }
939 }
940 918
941 if (!did_one) 919 int cnt = MAX_ITEM_PER_DROP;
920
921 if (!drop_vector (op, matched_objs, &cnt))
942 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 922 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
943 923
944 if (cnt <= 0) 924 if (cnt <= 0)
945 op->failmsg ("Only dropped some items, can't drop that many items at once."); 925 op->failmsg ("Only dropped some items, can't drop that many items at once.");
946
947 update_after_inventory_change (op);
948 } 926 }
949 927
950 return 0; 928 return 0;
951} 929}
952 930
1027 dynbuf_text buf (512, 512); 1005 dynbuf_text buf (512, 512);
1028 1006
1029 object *mon = head ? head : this; 1007 object *mon = head ? head : this;
1030 1008
1031 if (QUERY_FLAG (mon, FLAG_UNDEAD)) 1009 if (QUERY_FLAG (mon, FLAG_UNDEAD))
1032 buf << "It is an undead force.\n"; 1010 buf << "It is an undead force.\r";
1033 1011
1034 if (mon->level > who->level) 1012 if (mon->level > who->level)
1035 buf << "It is likely more powerful than you.\n"; 1013 buf << "It is likely more powerful than you.\r";
1036 else if (mon->level < who->level) 1014 else if (mon->level < who->level)
1037 buf << "It is likely less powerful than you.\n"; 1015 buf << "It is likely less powerful than you.\r";
1038 else 1016 else
1039 buf << "It is probably as powerful as you.\n"; 1017 buf << "It is probably as powerful as you.\r";
1040 1018
1041 if (mon->attacktype & AT_ACID) 1019 if (mon->attacktype & AT_ACID)
1042 buf << "You seem to smell an acrid odor.\n"; 1020 buf << "You seem to smell an acrid odor.\r";
1043 1021
1044 /* Anyone know why this used to use the clone value instead of the 1022 /* Anyone know why this used to use the clone value instead of the
1045 * maxhp field? This seems that it should give more accurate results. 1023 * maxhp field? This seems that it should give more accurate results.
1046 */ 1024 */
1047 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) 1025 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1))
1048 { /* From 1-4 */ 1026 { /* From 1-4 */
1049 case 1: 1027 case 1:
1050 buf << "It is in a bad shape.\n"; 1028 buf << "It is in a bad shape.\r";
1051 break; 1029 break;
1052 case 2: 1030 case 2:
1053 buf << "It is hurt.\n"; 1031 buf << "It is hurt.\r";
1054 break; 1032 break;
1055 case 3: 1033 case 3:
1056 buf << "It is somewhat hurt.\n"; 1034 buf << "It is somewhat hurt.\r";
1057 break; 1035 break;
1058 case 4: 1036 case 4:
1059 buf << "It is in excellent shape.\n"; 1037 buf << "It is in excellent shape.\r";
1060 break; 1038 break;
1061 } 1039 }
1062 1040
1063 if (present_in_ob (POISONING, mon)) 1041 if (present_in_ob (POISONING, mon))
1064 buf << "It looks very ill.\n"; 1042 buf << "It looks very ill.\r";
1043
1044 buf << '\n';
1065 1045
1066 return buf; 1046 return buf;
1067} 1047}
1068 1048
1069/* tmp is the object being described, pl is who is examing it. */ 1049/* tmp is the object being described, pl is who is examing it. */
1076} 1056}
1077 1057
1078std::string 1058std::string
1079object::long_desc (object *who) 1059object::long_desc (object *who)
1080{ 1060{
1081 std::string buf (query_name (this)); 1061 std::string buf (query_name ());
1082 1062
1083 switch (type) 1063 switch (type)
1084 { 1064 {
1085 case RING: 1065 case RING:
1086 case SKILL: 1066 case SKILL:
1098 case CLOAK: 1078 case CLOAK:
1099 case FOOD: 1079 case FOOD:
1100 case DRINK: 1080 case DRINK:
1101 case FLESH: 1081 case FLESH:
1102 case SKILL_TOOL: 1082 case SKILL_TOOL:
1083 case LAMP:
1103 case POWER_CRYSTAL: 1084 case POWER_CRYSTAL:
1104 { 1085 {
1105 const char *cp = ::describe_item (this, who); 1086 const char *cp = ::describe_item (this, who);
1106 1087
1107 if (*cp) 1088 if (*cp)
1127std::string 1108std::string
1128object::describe (object *who) 1109object::describe (object *who)
1129{ 1110{
1130 dynbuf_text buf (1024, 1024); 1111 dynbuf_text buf (1024, 1024);
1131 1112
1132 buf.printf ("That is: %s.\n", long_desc (who).c_str ()); 1113 buf.printf ("That is: %s.\r", long_desc (who).c_str ());
1133 1114
1134 if (custom_name) 1115 if (custom_name)
1135 buf.printf ("You call it %s\n", &custom_name); 1116 buf.printf ("You call it %s.\r", &custom_name);
1136 1117
1137 switch (type) 1118 switch (type)
1138 { 1119 {
1139 case SPELLBOOK: 1120 case SPELLBOOK:
1140 if (flag [FLAG_IDENTIFIED] && inv) 1121 if (flag [FLAG_IDENTIFIED] && inv)
1141 buf.printf ("%s is a %s %s spell\n", &inv->name, get_levelnumber (inv->level), &inv->skill); 1122 buf.printf ("%s is a level %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill);
1142 break; 1123 break;
1143 1124
1144 case BOOK: 1125 case BOOK:
1145 if (msg) 1126 if (msg)
1146 buf << "Something is written in it.\n"; 1127 buf << "Something is written in it.\r";
1147 break; 1128 break;
1148 1129
1149 case CONTAINER: 1130 case CONTAINER:
1150 if (race != NULL) 1131 if (race)
1151 { 1132 {
1152 if (weight_limit && stats.Str < 100) 1133 if (weight_limit && stats.Str < 100)
1153 buf.printf ("It can hold only %s and its weight limit is %.1f kg.\n", 1134 buf.printf ("It can hold only %s and its weight limit is %.1f kg.\r",
1154 &race, weight_limit / (10.0 * (100 - stats.Str))); 1135 &race, weight_limit / (10.0 * (100 - stats.Str)));
1155 else 1136 else
1156 buf.printf ("It can hold only %s.\n", &race); 1137 buf.printf ("It can hold only %s.\r", &race);
1157 } 1138 }
1158 else if (weight_limit && stats.Str < 100) 1139 else if (weight_limit && stats.Str < 100)
1159 buf.printf ("Its weight limit is %.1f kg.\n", weight_limit / (10.0 * (100 - stats.Str))); 1140 buf.printf ("Its weight limit is %.1f kg.\r", weight_limit / (10.0 * (100 - stats.Str)));
1160 break; 1141 break;
1161 1142
1162 case WAND: 1143 case WAND:
1163 if (flag [FLAG_IDENTIFIED]) 1144 if (flag [FLAG_IDENTIFIED])
1164 buf.printf ("It has %d charges left.\n", stats.food); 1145 buf.printf ("It has %d charges left.\r", stats.food);
1165 break; 1146 break;
1166 } 1147 }
1167 1148
1168 if (materialname && !msg) 1149 if (materialname && !msg)
1169 buf.printf ("It is made of: %s.\n", &materialname); 1150 buf.printf ("It is made of: %s.\r", &materialname);
1170 1151
1171 if (who) 1152 if (who)
1172 /* Where to wear this item */ 1153 /* Where to wear this item */
1173 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 1154 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
1174 if (slot[i].info) 1155 if (slot[i].info)
1176 buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name); 1157 buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name);
1177 1158
1178 if (slot[i].info < -1 && who->slot[i].info) 1159 if (slot[i].info < -1 && who->slot[i].info)
1179 buf.printf ("(%d)", -slot[i].info); 1160 buf.printf ("(%d)", -slot[i].info);
1180 1161
1181 buf << ".\n"; 1162 buf << ".\r";
1182 } 1163 }
1183 1164
1184 if (weight) 1165 if (weight)
1185 buf.printf (nrof > 1 ? "They weigh %3.3f kg.\n" : "It weighs %3.3f kg.\n", weight * (nrof ? nrof : 1) / 1000.0); 1166 buf.printf ("%s %3.3f kg.\r", nrof > 1 ? "They weigh" : "It weighs", weight * (nrof ? nrof : 1) / 1000.0);
1186 1167
1187 if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who) 1168 if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who)
1188 { 1169 {
1189 buf.printf ("You reckon %s worth %s.\n", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX)); 1170 buf.printf ("You reckon %s worth %s.\r", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX));
1190 1171
1191 if (is_in_shop (who)) 1172 if (is_in_shop (who))
1192 { 1173 {
1193 if (flag [FLAG_UNPAID]) 1174 if (flag [FLAG_UNPAID])
1194 buf.printf ("%s would cost you %s.\n", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP)); 1175 buf.printf ("%s would cost you %s.\r", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP));
1195 else 1176 else
1196 buf.printf ("You are offered %s for %s.\n", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it"); 1177 buf.printf ("You are offered %s for %s.\r", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it");
1197 } 1178 }
1198 } 1179 }
1199 1180
1200 if (flag [FLAG_MONSTER]) 1181 if (flag [FLAG_MONSTER])
1201 buf << describe_monster (who); 1182 buf << describe_monster (who);
1202 1183
1203 /* Is this item buildable? */ 1184 /* Is this item buildable? */
1204 if (flag [FLAG_IS_BUILDABLE]) 1185 if (flag [FLAG_IS_BUILDABLE])
1205 buf << "This is a buildable item.\n"; 1186 buf << "This is a buildable item.\r";
1206 1187
1207 /* Does the object have a message? Don't show message for all object 1188 /* Does the object have a message? Don't show message for all object
1208 * types - especially if the first entry is a match 1189 * types - especially if the first entry is a match
1209 */ 1190 */
1210 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && *msg != '@') 1191 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ())
1211 { 1192 {
1212 /* This is just a hack so when identifying the items, we print 1193 /* This is just a hack so when identifying the items, we print
1213 * out the extra message 1194 * out the extra message
1214 */ 1195 */
1215 if (need_identify (this) && flag [FLAG_IDENTIFIED]) 1196 if (need_identify (this) && flag [FLAG_IDENTIFIED])
1216 buf << "The object has a story:\n"; 1197 buf << "The object has a story:\r";
1217 1198
1218 buf << msg << '\n'; 1199 buf << msg << '\n';
1219 } 1200 }
1220 1201
1221 buf << '\n'; 1202 buf << '\n';
1226static void 1207static void
1227display_new_pickup (object *op) 1208display_new_pickup (object *op)
1228{ 1209{
1229 int i = op->contr->mode; 1210 int i = op->contr->mode;
1230 1211
1231 if (!(i & PU_NEWMODE))
1232 return;
1233
1234 new_draw_info_format (NDI_UNIQUE, 0, op, "%d NEWMODE", i & PU_NEWMODE ? 1 : 0);
1235 new_draw_info_format (NDI_UNIQUE, 0, op, "%d DEBUG", i & PU_DEBUG ? 1 : 0); 1212 new_draw_info_format (NDI_UNIQUE, 0, op, "%d DEBUG", i & PU_DEBUG ? 1 : 0);
1236 new_draw_info_format (NDI_UNIQUE, 0, op, "%d INHIBIT", i & PU_INHIBIT ? 1 : 0); 1213 new_draw_info_format (NDI_UNIQUE, 0, op, "%d INHIBIT", i & PU_INHIBIT ? 1 : 0);
1237 new_draw_info_format (NDI_UNIQUE, 0, op, "%d STOP", i & PU_STOP ? 1 : 0); 1214 new_draw_info_format (NDI_UNIQUE, 0, op, "%d STOP", i & PU_STOP ? 1 : 0);
1238 1215
1239 new_draw_info_format (NDI_UNIQUE, 0, op, "%d <= x pickup weight/value RATIO (0==off)", (i & PU_RATIO) * 5); 1216 new_draw_info_format (NDI_UNIQUE, 0, op, "%d <= x pickup weight/value RATIO (0==off)", (i & PU_RATIO) * 5);
1290 }; 1267 };
1291 1268
1292 if (!params) 1269 if (!params)
1293 { 1270 {
1294 /* if the new mode is used, just print the settings */ 1271 /* if the new mode is used, just print the settings */
1295 if (op->contr->mode & PU_NEWMODE)
1296 {
1297 display_new_pickup (op); 1272 display_new_pickup (op);
1298 return 1;
1299 }
1300 if (1)
1301 LOG (llevDebug, "command_pickup: !params\n");
1302 set_pickup_mode (op, (op->contr->mode > 6) ? 0 : op->contr->mode + 1);
1303 return 0; 1273 return 0;
1304 } 1274 }
1305 1275
1306 while (*params == ' ' && *params) 1276 while (*params == ' ' && *params)
1307 params++; 1277 params++;
1313 for (mode = 0; names[mode]; mode++) 1283 for (mode = 0; names[mode]; mode++)
1314 { 1284 {
1315 if (!strcmp (names[mode], params + 1)) 1285 if (!strcmp (names[mode], params + 1))
1316 { 1286 {
1317 i = op->contr->mode; 1287 i = op->contr->mode;
1318 if (!(i & PU_NEWMODE)) 1288
1319 i = PU_NEWMODE;
1320 if (*params == '+') 1289 if (*params == '+')
1321 i = i | modes[mode]; 1290 i = i | modes[mode];
1322 else 1291 else
1323 i = i & ~modes[mode]; 1292 i = i & ~modes[mode];
1293
1324 op->contr->mode = i; 1294 op->contr->mode = i;
1325 display_new_pickup (op); 1295 display_new_pickup (op);
1326 return 1; 1296 return 1;
1327 } 1297 }
1328 } 1298 }
1330 return 1; 1300 return 1;
1331 } 1301 }
1332 1302
1333 if (sscanf (params, "%u", &i) != 1) 1303 if (sscanf (params, "%u", &i) != 1)
1334 { 1304 {
1335 if (1)
1336 LOG (llevDebug, "command_pickup: params==NULL\n");
1337 new_draw_info (NDI_UNIQUE, 0, op, "Usage: pickup <0-7> or <value_density> ."); 1305 new_draw_info (NDI_UNIQUE, 0, op, "Usage: pickup <value_density> or [+-]type.");
1338 return 1; 1306 return 1;
1339 } 1307 }
1340 set_pickup_mode (op, i); 1308
1309 if (i <= PU_RATIO)
1310 i |= op->contr->mode & ~PU_RATIO;
1311
1312 op->contr->mode = i;
1341 1313
1342 return 1; 1314 return 1;
1343}
1344
1345void
1346set_pickup_mode (object *op, int i)
1347{
1348 switch (op->contr->mode = i)
1349 {
1350 case 0:
1351 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Don't pick up.");
1352 break;
1353 case 1:
1354 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item.");
1355 break;
1356 case 2:
1357 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item and stop.");
1358 break;
1359 case 3:
1360 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Stop before picking up.");
1361 break;
1362 case 4:
1363 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items.");
1364 break;
1365 case 5:
1366 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items and stop.");
1367 break;
1368 case 6:
1369 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all magic items.");
1370 break;
1371 case 7:
1372 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all coins and gems");
1373 break;
1374 }
1375} 1315}
1376 1316
1377int 1317int
1378command_search_items (object *op, char *params) 1318command_search_items (object *op, char *params)
1379{ 1319{
1380 char buf[MAX_BUF]; 1320 char buf[MAX_BUF];
1381 1321
1382 if (settings.search_items == FALSE)
1383 return 1;
1384
1385 if (params == NULL) 1322 if (params == NULL)
1386 { 1323 {
1387 if (op->contr->search_str[0] == '\0') 1324 if (op->contr->search_str[0] == '\0')
1388 { 1325 {
1389 new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1"); 1326 new_draw_info (NDI_UNIQUE, 0, op, "Example: search-items magic+1");
1390 new_draw_info (NDI_UNIQUE, 0, op, "Would automatically pick up all"); 1327 new_draw_info (NDI_UNIQUE, 0, op, "Would automatically pick up all");
1391 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'."); 1328 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'.");
1392 return 1; 1329 return 1;
1393 } 1330 }
1394 1331
1396 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); 1333 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off.");
1397 op->update_stats (); 1334 op->update_stats ();
1398 return 1; 1335 return 1;
1399 } 1336 }
1400 1337
1401 if ((int) strlen (params) >= MAX_BUF) 1338 if (strlen (params) >= MAX_BUF)
1402 { 1339 {
1403 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); 1340 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long.");
1404 return 1; 1341 return 1;
1405 } 1342 }
1406 1343
1407 strcpy (op->contr->search_str, params); 1344 strcpy (op->contr->search_str, params);
1408 sprintf (buf, "Searching for '%s'.", op->contr->search_str); 1345 sprintf (buf, "Now searching for '%s'.", op->contr->search_str);
1409 new_draw_info (NDI_UNIQUE, 0, op, buf); 1346 new_draw_info (NDI_UNIQUE, 0, op, buf);
1410 op->update_stats (); 1347 op->update_stats ();
1348
1411 return 1; 1349 return 1;
1412} 1350}
1413 1351

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines