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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines