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.67 by root, Mon Apr 21 23:35:24 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 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 if (op->type == PLAYER)
667 esrv_del_item (op->contr, tmp->count);
668
669 tmp->destroy (); 633 obj->destroy ();
670 op->update_stats (); 634 dropper->update_stats ();
671 return; 635 return;
672 } 636 }
673 637
674 if (op->type == PLAYER) 638 for (object *floor = GET_MAP_OB (dropper->map, dropper->x, dropper->y);
675 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;
676 643
677 /* Call this before we update the various windows/players. At least 644 if (obj->destroyed () || obj->is_inserted ())
678 * 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:
679 */ 653 */
680 // 2007-11-26: moved op->update_stats away and calling it later after
681 // all items of a drop command have been processed.
682 654
683 for (floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above) 655 obj->x = dropper->x;
684 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) 656 obj->y = dropper->y;
685 return;
686 657
687 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
688 sell_item (tmp, op);
689
690 tmp->x = op->x;
691 tmp->y = op->y;
692
693 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); 658 insert_ob_in_map (obj, dropper->map, dropper, INS_BELOW_ORIGINATOR);
694}
695
696void update_after_inventory_change (object *op)
697{
698 /* Call this before we update the various windows/players. At least
699 * that we, we know the weight is correct.
700 */
701 op->update_stats ();
702
703 // elmex: kept this for now, i have no idea what happens when i remove it:
704 if (op->type == PLAYER)
705 {
706 /* Need to update the weight for the player */
707 esrv_send_item (op, op);
708 op->contr->ns->floorbox_update ();
709 }
710} 659}
711 660
712void 661void
713drop (object *op, object *tmp) 662drop (object *op, object *tmp)
714{ 663{
723 if (tmp->env && tmp->env->type != PLAYER) 672 if (tmp->env && tmp->env->type != PLAYER)
724 { 673 {
725 /* Just toss the object - probably shouldn't be hanging 674 /* Just toss the object - probably shouldn't be hanging
726 * around anyways 675 * around anyways
727 */ 676 */
728 tmp->remove ();
729 tmp->destroy (); 677 tmp->destroy ();
730 return; 678 return;
731 } 679 }
732 else 680 else
733 { 681 {
734 while (tmp != NULL && tmp->invisible) 682 while (tmp && tmp->invisible)
735 tmp = tmp->below; 683 tmp = tmp->below;
736 } 684 }
737 } 685 }
738 686
739 if (tmp == NULL) 687 if (tmp == NULL)
740 { 688 {
741 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.");
742 return; 690 return;
743 } 691 }
692
744 if (QUERY_FLAG (tmp, FLAG_INV_LOCKED)) 693 if (QUERY_FLAG (tmp, FLAG_INV_LOCKED))
745 { 694 {
746 new_draw_info (NDI_UNIQUE, 0, op, "This item is locked"); 695 new_draw_info (NDI_UNIQUE, 0, op, "This item is locked");
747 return; 696 return;
748 } 697 }
698
749 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 699 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
750 { 700 {
751#if 0 701#if 0
752 /* 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. */
753 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.");
777 727
778 if (op->type == PLAYER) 728 if (op->type == PLAYER)
779 op->contr->count = 0; 729 op->contr->count = 0;
780} 730}
781 731
782
783
784/* Command will drop all items that have not been locked */ 732/* Command will drop all items that have not been locked */
785int 733int
786command_dropall (object *op, char *params) 734command_dropall (object *op, char *params)
787{ 735{
788 736
789 object *curinv, *nextinv;
790
791 if (op->inv == NULL) 737 if (op->inv == NULL)
792 { 738 {
793 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop!"); 739 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop!");
794 return 0; 740 return 0;
795 } 741 }
796 742
797 curinv = op->inv; 743 object *curinv = op->inv;
744 object *nextinv;
798 745
799 /* 746 /*
800 This is the default. Drops everything not locked or considered 747 This is the default. Drops everything not locked or considered
801 not something that should be dropped. 748 not something that should be dropped.
802 */ 749 */
806 in a shop. --Tero.Pelander@utu.fi 753 in a shop. --Tero.Pelander@utu.fi
807 */ 754 */
808 755
809 int cnt = MAX_ITEM_PER_DROP; 756 int cnt = MAX_ITEM_PER_DROP;
810 757
811 if (params == NULL) 758 if (!params)
812 { 759 {
813 while (curinv != NULL) 760 while (curinv)
814 { 761 {
815 nextinv = curinv->below; 762 nextinv = curinv->below;
763
816 while (nextinv && nextinv->type == MONEY) 764 while (nextinv && nextinv->type == MONEY)
817 nextinv = nextinv->below; 765 nextinv = nextinv->below;
766
818 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY && 767 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY &&
819 curinv->type != FOOD && curinv->type != KEY && 768 curinv->type != FOOD && curinv->type != KEY &&
820 curinv->type != SPECIAL_KEY && curinv->type != GEM && 769 curinv->type != SPECIAL_KEY && curinv->type != GEM &&
821 !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv)) 770 !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv))
822 { 771 {
823 drop (op, curinv); 772 drop (op, curinv);
824 if (--cnt <= 0) break; 773 if (--cnt <= 0) break;
825 } 774 }
775
826 curinv = nextinv; 776 curinv = nextinv;
827 } 777 }
828 } 778 }
829
830 else if (strcmp (params, "weapons") == 0) 779 else if (strcmp (params, "weapons") == 0)
831 { 780 {
832 while (curinv != NULL) 781 while (curinv)
833 { 782 {
834 nextinv = curinv->below; 783 nextinv = curinv->below;
784
835 while (nextinv && nextinv->type == MONEY) 785 while (nextinv && nextinv->type == MONEY)
836 nextinv = nextinv->below; 786 nextinv = nextinv->below;
787
837 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)))
838 { 789 {
839 drop (op, curinv); 790 drop (op, curinv);
840 if (--cnt <= 0) break; 791 if (--cnt <= 0) break;
841 } 792 }
793
842 curinv = nextinv; 794 curinv = nextinv;
843 } 795 }
844 } 796 }
845
846 else if (strcmp (params, "armor") == 0 || strcmp (params, "armour") == 0) 797 else if (strcmp (params, "armor") == 0 || strcmp (params, "armour") == 0)
847 { 798 {
848 while (curinv != NULL) 799 while (curinv)
849 { 800 {
850 nextinv = curinv->below; 801 nextinv = curinv->below;
802
851 while (nextinv && nextinv->type == MONEY) 803 while (nextinv && nextinv->type == MONEY)
852 nextinv = nextinv->below; 804 nextinv = nextinv->below;
805
853 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))
854 { 807 {
855 drop (op, curinv); 808 drop (op, curinv);
856 if (--cnt <= 0) break; 809 if (--cnt <= 0) break;
857 } 810 }
811
858 curinv = nextinv; 812 curinv = nextinv;
859 } 813 }
860 } 814 }
861
862 else if (strcmp (params, "misc") == 0) 815 else if (strcmp (params, "misc") == 0)
863 { 816 {
864 while (curinv != NULL) 817 while (curinv)
865 { 818 {
866 nextinv = curinv->below; 819 nextinv = curinv->below;
820
867 while (nextinv && nextinv->type == MONEY) 821 while (nextinv && nextinv->type == MONEY)
868 nextinv = nextinv->below; 822 nextinv = nextinv->below;
823
869 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))
870 { 825 {
871 switch (curinv->type) 826 switch (curinv->type)
872 { 827 {
873 case HORN: 828 case HORN:
891 break; 846 break;
892 default: 847 default:
893 curinv = nextinv; 848 curinv = nextinv;
894 break; 849 break;
895 } 850 }
851
896 if (--cnt <= 0) break; 852 if (--cnt <= 0) break;
897 } 853 }
854
898 curinv = nextinv; 855 curinv = nextinv;
899 } 856 }
900 } 857 }
901 858
902 if (cnt <= 0) 859 if (cnt <= 0)
903 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.");
904 861
905 update_after_inventory_change (op);
906
907/* draw_look(op);*/ 862/* draw_look(op);*/
908 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;
909} 889}
910 890
911/* 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
912 * comma seperated list. 892 * comma seperated list.
913 */ 893 */
914
915int 894int
916command_drop (object *op, char *params) 895command_drop (object *op, char *params)
917{ 896{
918 object *tmp, *next; 897 object *tmp, *next;
919 int did_one = 0; 898 int did_one = 0;
923 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); 902 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?");
924 return 0; 903 return 0;
925 } 904 }
926 else 905 else
927 { 906 {
928 int cnt = MAX_ITEM_PER_DROP; 907 vector<object *> matched_objs;
929 908
930 for (tmp = op->inv; tmp; tmp = next) 909 for (tmp = op->inv; tmp; tmp = next)
931 { 910 {
932 next = tmp->below; 911 next = tmp->below;
933 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) 912 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible)
934 continue; 913 continue;
935 914
936 if (item_matched_string (op, tmp, params)) 915 if (item_matched_string (op, tmp, params))
937 { 916 matched_objs.push_back (tmp);
938 drop (op, tmp);
939 if (--cnt <= 0) break;
940 did_one = 1;
941 } 917 }
942 }
943 918
944 if (!did_one) 919 int cnt = MAX_ITEM_PER_DROP;
920
921 if (!drop_vector (op, matched_objs, &cnt))
945 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 922 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
946 923
947 if (cnt <= 0) 924 if (cnt <= 0)
948 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.");
949
950 update_after_inventory_change (op);
951 } 926 }
952 927
953 return 0; 928 return 0;
954} 929}
955 930
1030 dynbuf_text buf (512, 512); 1005 dynbuf_text buf (512, 512);
1031 1006
1032 object *mon = head ? head : this; 1007 object *mon = head ? head : this;
1033 1008
1034 if (QUERY_FLAG (mon, FLAG_UNDEAD)) 1009 if (QUERY_FLAG (mon, FLAG_UNDEAD))
1035 buf << "It is an undead force.\n"; 1010 buf << "It is an undead force.\r";
1036 1011
1037 if (mon->level > who->level) 1012 if (mon->level > who->level)
1038 buf << "It is likely more powerful than you.\n"; 1013 buf << "It is likely more powerful than you.\r";
1039 else if (mon->level < who->level) 1014 else if (mon->level < who->level)
1040 buf << "It is likely less powerful than you.\n"; 1015 buf << "It is likely less powerful than you.\r";
1041 else 1016 else
1042 buf << "It is probably as powerful as you.\n"; 1017 buf << "It is probably as powerful as you.\r";
1043 1018
1044 if (mon->attacktype & AT_ACID) 1019 if (mon->attacktype & AT_ACID)
1045 buf << "You seem to smell an acrid odor.\n"; 1020 buf << "You seem to smell an acrid odor.\r";
1046 1021
1047 /* 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
1048 * maxhp field? This seems that it should give more accurate results. 1023 * maxhp field? This seems that it should give more accurate results.
1049 */ 1024 */
1050 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) 1025 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1))
1051 { /* From 1-4 */ 1026 { /* From 1-4 */
1052 case 1: 1027 case 1:
1053 buf << "It is in a bad shape.\n"; 1028 buf << "It is in a bad shape.\r";
1054 break; 1029 break;
1055 case 2: 1030 case 2:
1056 buf << "It is hurt.\n"; 1031 buf << "It is hurt.\r";
1057 break; 1032 break;
1058 case 3: 1033 case 3:
1059 buf << "It is somewhat hurt.\n"; 1034 buf << "It is somewhat hurt.\r";
1060 break; 1035 break;
1061 case 4: 1036 case 4:
1062 buf << "It is in excellent shape.\n"; 1037 buf << "It is in excellent shape.\r";
1063 break; 1038 break;
1064 } 1039 }
1065 1040
1066 if (present_in_ob (POISONING, mon)) 1041 if (present_in_ob (POISONING, mon))
1067 buf << "It looks very ill.\n"; 1042 buf << "It looks very ill.\r";
1043
1044 buf << '\n';
1068 1045
1069 return buf; 1046 return buf;
1070} 1047}
1071 1048
1072/* 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. */
1079} 1056}
1080 1057
1081std::string 1058std::string
1082object::long_desc (object *who) 1059object::long_desc (object *who)
1083{ 1060{
1084 std::string buf (query_name (this)); 1061 std::string buf (query_name ());
1085 1062
1086 switch (type) 1063 switch (type)
1087 { 1064 {
1088 case RING: 1065 case RING:
1089 case SKILL: 1066 case SKILL:
1101 case CLOAK: 1078 case CLOAK:
1102 case FOOD: 1079 case FOOD:
1103 case DRINK: 1080 case DRINK:
1104 case FLESH: 1081 case FLESH:
1105 case SKILL_TOOL: 1082 case SKILL_TOOL:
1083 case LAMP:
1106 case POWER_CRYSTAL: 1084 case POWER_CRYSTAL:
1107 { 1085 {
1108 const char *cp = ::describe_item (this, who); 1086 const char *cp = ::describe_item (this, who);
1109 1087
1110 if (*cp) 1088 if (*cp)
1130std::string 1108std::string
1131object::describe (object *who) 1109object::describe (object *who)
1132{ 1110{
1133 dynbuf_text buf (1024, 1024); 1111 dynbuf_text buf (1024, 1024);
1134 1112
1135 buf.printf ("That is: %s.\n", long_desc (who).c_str ()); 1113 buf.printf ("That is: %s.\r", long_desc (who).c_str ());
1136 1114
1137 if (custom_name) 1115 if (custom_name)
1138 buf.printf ("You call it %s\n", &custom_name); 1116 buf.printf ("You call it %s.\r", &custom_name);
1139 1117
1140 switch (type) 1118 switch (type)
1141 { 1119 {
1142 case SPELLBOOK: 1120 case SPELLBOOK:
1143 if (flag [FLAG_IDENTIFIED] && inv) 1121 if (flag [FLAG_IDENTIFIED] && inv)
1144 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);
1145 break; 1123 break;
1146 1124
1147 case BOOK: 1125 case BOOK:
1148 if (msg) 1126 if (msg)
1149 buf << "Something is written in it.\n"; 1127 buf << "Something is written in it.\r";
1150 break; 1128 break;
1151 1129
1152 case CONTAINER: 1130 case CONTAINER:
1153 if (race != NULL) 1131 if (race)
1154 { 1132 {
1155 if (weight_limit && stats.Str < 100) 1133 if (weight_limit && stats.Str < 100)
1156 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",
1157 &race, weight_limit / (10.0 * (100 - stats.Str))); 1135 &race, weight_limit / (10.0 * (100 - stats.Str)));
1158 else 1136 else
1159 buf.printf ("It can hold only %s.\n", &race); 1137 buf.printf ("It can hold only %s.\r", &race);
1160 } 1138 }
1161 else if (weight_limit && stats.Str < 100) 1139 else if (weight_limit && stats.Str < 100)
1162 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)));
1163 break; 1141 break;
1164 1142
1165 case WAND: 1143 case WAND:
1166 if (flag [FLAG_IDENTIFIED]) 1144 if (flag [FLAG_IDENTIFIED])
1167 buf.printf ("It has %d charges left.\n", stats.food); 1145 buf.printf ("It has %d charges left.\r", stats.food);
1168 break; 1146 break;
1169 } 1147 }
1170 1148
1171 if (materialname && !msg) 1149 if (materialname && !msg)
1172 buf.printf ("It is made of: %s.\n", &materialname); 1150 buf.printf ("It is made of: %s.\r", &materialname);
1173 1151
1174 if (who) 1152 if (who)
1175 /* Where to wear this item */ 1153 /* Where to wear this item */
1176 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 1154 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
1177 if (slot[i].info) 1155 if (slot[i].info)
1179 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);
1180 1158
1181 if (slot[i].info < -1 && who->slot[i].info) 1159 if (slot[i].info < -1 && who->slot[i].info)
1182 buf.printf ("(%d)", -slot[i].info); 1160 buf.printf ("(%d)", -slot[i].info);
1183 1161
1184 buf << ".\n"; 1162 buf << ".\r";
1185 } 1163 }
1186 1164
1187 if (weight) 1165 if (weight)
1188 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);
1189 1167
1190 if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who) 1168 if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who)
1191 { 1169 {
1192 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));
1193 1171
1194 if (is_in_shop (who)) 1172 if (is_in_shop (who))
1195 { 1173 {
1196 if (flag [FLAG_UNPAID]) 1174 if (flag [FLAG_UNPAID])
1197 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));
1198 else 1176 else
1199 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");
1200 } 1178 }
1201 } 1179 }
1202 1180
1203 if (flag [FLAG_MONSTER]) 1181 if (flag [FLAG_MONSTER])
1204 buf << describe_monster (who); 1182 buf << describe_monster (who);
1205 1183
1206 /* Is this item buildable? */ 1184 /* Is this item buildable? */
1207 if (flag [FLAG_IS_BUILDABLE]) 1185 if (flag [FLAG_IS_BUILDABLE])
1208 buf << "This is a buildable item.\n"; 1186 buf << "This is a buildable item.\r";
1209 1187
1210 /* 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
1211 * types - especially if the first entry is a match 1189 * types - especially if the first entry is a match
1212 */ 1190 */
1213 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && *msg != '@') 1191 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ())
1214 { 1192 {
1215 /* 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
1216 * out the extra message 1194 * out the extra message
1217 */ 1195 */
1218 if (need_identify (this) && flag [FLAG_IDENTIFIED]) 1196 if (need_identify (this) && flag [FLAG_IDENTIFIED])
1219 buf << "The object has a story:\n"; 1197 buf << "The object has a story:\r";
1220 1198
1221 buf << msg << '\n'; 1199 buf << msg << '\n';
1222 } 1200 }
1223 1201
1224 buf << '\n'; 1202 buf << '\n';
1229static void 1207static void
1230display_new_pickup (object *op) 1208display_new_pickup (object *op)
1231{ 1209{
1232 int i = op->contr->mode; 1210 int i = op->contr->mode;
1233 1211
1234 if (!(i & PU_NEWMODE))
1235 return;
1236
1237 new_draw_info_format (NDI_UNIQUE, 0, op, "%d NEWMODE", i & PU_NEWMODE ? 1 : 0);
1238 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);
1239 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);
1240 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);
1241 1215
1242 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);
1293 }; 1267 };
1294 1268
1295 if (!params) 1269 if (!params)
1296 { 1270 {
1297 /* if the new mode is used, just print the settings */ 1271 /* if the new mode is used, just print the settings */
1298 if (op->contr->mode & PU_NEWMODE)
1299 {
1300 display_new_pickup (op); 1272 display_new_pickup (op);
1301 return 1;
1302 }
1303 if (1)
1304 LOG (llevDebug, "command_pickup: !params\n");
1305 set_pickup_mode (op, (op->contr->mode > 6) ? 0 : op->contr->mode + 1);
1306 return 0; 1273 return 0;
1307 } 1274 }
1308 1275
1309 while (*params == ' ' && *params) 1276 while (*params == ' ' && *params)
1310 params++; 1277 params++;
1316 for (mode = 0; names[mode]; mode++) 1283 for (mode = 0; names[mode]; mode++)
1317 { 1284 {
1318 if (!strcmp (names[mode], params + 1)) 1285 if (!strcmp (names[mode], params + 1))
1319 { 1286 {
1320 i = op->contr->mode; 1287 i = op->contr->mode;
1321 if (!(i & PU_NEWMODE)) 1288
1322 i = PU_NEWMODE;
1323 if (*params == '+') 1289 if (*params == '+')
1324 i = i | modes[mode]; 1290 i = i | modes[mode];
1325 else 1291 else
1326 i = i & ~modes[mode]; 1292 i = i & ~modes[mode];
1293
1327 op->contr->mode = i; 1294 op->contr->mode = i;
1328 display_new_pickup (op); 1295 display_new_pickup (op);
1329 return 1; 1296 return 1;
1330 } 1297 }
1331 } 1298 }
1333 return 1; 1300 return 1;
1334 } 1301 }
1335 1302
1336 if (sscanf (params, "%u", &i) != 1) 1303 if (sscanf (params, "%u", &i) != 1)
1337 { 1304 {
1338 if (1)
1339 LOG (llevDebug, "command_pickup: params==NULL\n");
1340 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.");
1341 return 1; 1306 return 1;
1342 } 1307 }
1343 set_pickup_mode (op, i); 1308
1309 if (i <= PU_RATIO)
1310 i |= op->contr->mode & ~PU_RATIO;
1311
1312 op->contr->mode = i;
1344 1313
1345 return 1; 1314 return 1;
1346}
1347
1348void
1349set_pickup_mode (object *op, int i)
1350{
1351 switch (op->contr->mode = i)
1352 {
1353 case 0:
1354 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Don't pick up.");
1355 break;
1356 case 1:
1357 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item.");
1358 break;
1359 case 2:
1360 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item and stop.");
1361 break;
1362 case 3:
1363 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Stop before picking up.");
1364 break;
1365 case 4:
1366 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items.");
1367 break;
1368 case 5:
1369 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items and stop.");
1370 break;
1371 case 6:
1372 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all magic items.");
1373 break;
1374 case 7:
1375 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all coins and gems");
1376 break;
1377 }
1378} 1315}
1379 1316
1380int 1317int
1381command_search_items (object *op, char *params) 1318command_search_items (object *op, char *params)
1382{ 1319{
1383 char buf[MAX_BUF]; 1320 char buf[MAX_BUF];
1384 1321
1385 if (settings.search_items == FALSE)
1386 return 1;
1387
1388 if (params == NULL) 1322 if (params == NULL)
1389 { 1323 {
1390 if (op->contr->search_str[0] == '\0') 1324 if (op->contr->search_str[0] == '\0')
1391 { 1325 {
1392 new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1"); 1326 new_draw_info (NDI_UNIQUE, 0, op, "Example: search-items magic+1");
1393 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");
1394 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'.");
1395 return 1; 1329 return 1;
1396 } 1330 }
1397 1331
1399 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); 1333 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off.");
1400 op->update_stats (); 1334 op->update_stats ();
1401 return 1; 1335 return 1;
1402 } 1336 }
1403 1337
1404 if ((int) strlen (params) >= MAX_BUF) 1338 if (strlen (params) >= MAX_BUF)
1405 { 1339 {
1406 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); 1340 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long.");
1407 return 1; 1341 return 1;
1408 } 1342 }
1409 1343
1410 strcpy (op->contr->search_str, params); 1344 strcpy (op->contr->search_str, params);
1411 sprintf (buf, "Searching for '%s'.", op->contr->search_str); 1345 sprintf (buf, "Now searching for '%s'.", op->contr->search_str);
1412 new_draw_info (NDI_UNIQUE, 0, op, buf); 1346 new_draw_info (NDI_UNIQUE, 0, op, buf);
1413 op->update_stats (); 1347 op->update_stats ();
1348
1414 return 1; 1349 return 1;
1415} 1350}
1416 1351

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines