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.69 by root, Tue Apr 22 07:01:47 2008 UTC

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
311 311
312 if (!can_split (pl, tmp, nrof)) 312 if (!can_split (pl, tmp, nrof))
313 return; 313 return;
314 314
315 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 315 if (QUERY_FLAG (tmp, FLAG_UNPAID))
316 {
317 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)); 318 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));
319 tmp->flag.set (FLAG_UNPAID);
320 }
317 else 321 else
318 new_draw_info_format (NDI_UNIQUE, 0, pl, "You pick up the %s.", query_name (tmp)); 322 new_draw_info_format (NDI_UNIQUE, 0, pl, "You pick up the %s.", query_name (tmp));
319 323
320 tmp = insert_ob_in_ob (tmp, op); 324 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} 325}
343 326
344/* modified slightly to allow monsters use this -b.t. 5-31-95 */ 327/* modified slightly to allow monsters use this -b.t. 5-31-95 */
345void 328void
346pick_up (object *op, object *alt) 329pick_up (object *op, object *alt)
569 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) 552 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp)
570 { 553 {
571 tmp = tmp2->below; 554 tmp = tmp2->below;
572 555
573 if ((sack->type == CONTAINER && sack_can_hold (op, op->container, tmp2, tmp2->nrof))) 556 if ((sack->type == CONTAINER && sack_can_hold (op, op->container, tmp2, tmp2->nrof)))
574 {
575 put_object_in_sack (op, sack, tmp2, 0); 557 put_object_in_sack (op, sack, tmp2, 0);
576 }
577 else 558 else
578 { 559 {
579 sprintf (buf, "Your %s fills up.", query_name (sack)); 560 sprintf (buf, "Your %s fills up.", query_name (sack));
580 new_draw_info (NDI_UNIQUE, 0, op, buf); 561 new_draw_info (NDI_UNIQUE, 0, op, buf);
581 break; 562 break;
582 } 563 }
583 } 564 }
584 565
585 esrv_update_item (UPD_WEIGHT, op, sack2);
586 return; 566 return;
587 } 567 }
588 568
589 /* Don't worry about this for containers - our caller should have 569 /* Don't worry about this for containers - our caller should have
590 * already checked this. 570 * already checked this.
595 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 575 if (QUERY_FLAG (tmp, FLAG_APPLIED))
596 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 576 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
597 return; 577 return;
598 578
599 /* we want to put some portion of the item into the container */ 579 /* 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)) 580 if (!can_split (op, tmp, nrof))
603 return; 581 return;
604 }
605 else
606 tmp->remove ();
607 582
608 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack)); 583 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); 584 sack->insert (tmp);
610 585
611 // elmex: 2007-11-26: removed update_stats and replaced 586 // elmex: 2007-11-26: removed update_stats and replaced
612 // it by update_after_inventory_change () in the caller 587 // it by update_after_inventory_change () in the caller
613 // of this function 588 // 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} 589}
626 590
627/* 591/*
628 * This function was part of drop, now is own function. 592 * This function was part of drop, now is own function.
629 * Player 'op' tries to drop object 'tmp', if tmp is non zero, then 593 * Player 'op' tries to drop object 'tmp', if tmp is non zero, then
631 * This is used when dropping objects onto the floor. 595 * This is used when dropping objects onto the floor.
632 */ 596 */
633void 597void
634drop_object (object *op, object *tmp, uint32 nrof) 598drop_object (object *op, object *tmp, uint32 nrof)
635{ 599{
636 object *floor;
637
638 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 600 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
639 return; 601 return;
640 602
641 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 603 if (QUERY_FLAG (tmp, FLAG_APPLIED))
642 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 604 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
645 //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D 607 //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D
646 608
647 /* We are only dropping some of the items. We split the current object 609 /* We are only dropping some of the items. We split the current object
648 * off 610 * off
649 */ 611 */
650 if (nrof && tmp->nrof != nrof)
651 {
652 if (!can_split (op, tmp, nrof)) 612 if (!can_split (op, tmp, nrof))
653 return;
654 }
655 else
656 tmp->remove ();
657 613
658 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op))) 614 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op)))
659 return; 615 return;
660 616
661 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 617 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP))
665 621
666 tmp->destroy (); 622 tmp->destroy ();
667 op->update_stats (); 623 op->update_stats ();
668 return; 624 return;
669 } 625 }
670
671 if (op->type == PLAYER)
672 esrv_del_item (op->contr, tmp->count);
673 626
674 /* Call this before we update the various windows/players. At least 627 /* Call this before we update the various windows/players. At least
675 * that we, we know the weight is correct. 628 * that we, we know the weight is correct.
676 */ 629 */
677 // 2007-11-26: moved op->update_stats away and calling it later after 630 // 2007-11-26: moved op->update_stats away and calling it later after
678 // all items of a drop command have been processed. 631 // all items of a drop command have been processed.
679 632
680 for (floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above) 633 for (object *floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above)
681 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) 634 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op)))
682 return; 635 return;
683 636
684 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY) 637 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
685 sell_item (tmp, op); 638 sell_item (tmp, op);
688 tmp->y = op->y; 641 tmp->y = op->y;
689 642
690 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); 643 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR);
691} 644}
692 645
646void
693void update_after_inventory_change (object *op) 647update_after_inventory_change (object *op)
694{ 648{
695 /* Call this before we update the various windows/players. At least 649 /* Call this before we update the various windows/players. At least
696 * that we, we know the weight is correct. 650 * that we, we know the weight is correct.
697 */ 651 */
698 op->update_stats (); 652 op->update_stats ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines