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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.219 by root, Wed Apr 23 21:09:10 2008 UTC vs.
Revision 1.222 by root, Wed Apr 30 05:06:36 2008 UTC

334 334
335// find player who can see this object 335// find player who can see this object
336object * 336object *
337object::visible_to () const 337object::visible_to () const
338{ 338{
339 if (!flag [FLAG_REMOVED]) 339 if (client_visible () && !flag [FLAG_REMOVED])
340 { 340 {
341 // see if we are in a container of sorts 341 // see if we are in a container of sorts
342 if (env) 342 if (env)
343 { 343 {
344 // the player inventory itself is always visible 344 // the player inventory itself is always visible
358 else 358 else
359 { 359 {
360 // maybe there is a player standing on the same mapspace 360 // maybe there is a player standing on the same mapspace
361 // this will catch the case where "this" is a player 361 // this will catch the case where "this" is a player
362 if (object *pl = ms ().player ()) 362 if (object *pl = ms ().player ())
363 if (!pl->container || this == pl->container)
363 return pl; 364 return pl;
364 } 365 }
365 } 366 }
366 367
367 return 0; 368 return 0;
368} 369}
745 * UP_OBJ_FACE: only the objects face has changed. 746 * UP_OBJ_FACE: only the objects face has changed.
746 */ 747 */
747void 748void
748update_object (object *op, int action) 749update_object (object *op, int action)
749{ 750{
750 if (op == NULL) 751 if (!op)
751 { 752 {
752 /* this should never happen */ 753 /* this should never happen */
753 LOG (llevDebug, "update_object() called for NULL object.\n"); 754 LOG (llevError | logBacktrace, "update_object() called for NULL object.\n");
754 return; 755 return;
755 } 756 }
756 757
757 if (op->env) 758 if (!op->is_on_map ())
758 { 759 {
759 /* Animation is currently handled by client, so nothing 760 /* Animation is currently handled by client, so nothing
760 * to do in this case. 761 * to do in this case.
761 */ 762 */
762 return; 763 return;
763 } 764 }
764
765 /* If the map is saving, don't do anything as everything is
766 * going to get freed anyways.
767 */
768 if (!op->map || op->map->in_memory == MAP_SAVING)
769 return;
770 765
771 /* make sure the object is within map boundaries */ 766 /* make sure the object is within map boundaries */
772 if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height) 767 if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height)
773 { 768 {
774 LOG (llevError, "update_object() called for object out of map!\n"); 769 LOG (llevError, "update_object() called for object out of map!\n");
1061 if (flag [FLAG_REMOVED]) 1056 if (flag [FLAG_REMOVED])
1062 return; 1057 return;
1063 1058
1064 INVOKE_OBJECT (REMOVE, this); 1059 INVOKE_OBJECT (REMOVE, this);
1065 1060
1066 if (object *pl = visible_to ())
1067 esrv_del_item (pl->contr, count);
1068
1069 flag [FLAG_REMOVED] = true; 1061 flag [FLAG_REMOVED] = true;
1070 1062
1071 if (more) 1063 if (more)
1072 more->remove (); 1064 more->remove ();
1073 1065
1075 * In this case, the object to be removed is in someones 1067 * In this case, the object to be removed is in someones
1076 * inventory. 1068 * inventory.
1077 */ 1069 */
1078 if (env) 1070 if (env)
1079 { 1071 {
1072 flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed
1073 if (object *pl = visible_to ())
1074 esrv_del_item (pl->contr, count);
1075 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1076
1080 adjust_weight (env, -total_weight ()); 1077 adjust_weight (env, -total_weight ());
1081 1078
1082 *(above ? &above->below : &env->inv) = below; 1079 *(above ? &above->below : &env->inv) = below;
1083 1080
1084 if (below) 1081 if (below)
1102 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1099 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER))
1103 otmp->update_stats (); 1100 otmp->update_stats ();
1104 } 1101 }
1105 else if (map) 1102 else if (map)
1106 { 1103 {
1107 if (type == PLAYER)
1108 {
1109 // leaving a spot always closes any open container on the ground
1110 if (container && !container->env)
1111 // this causes spurious floorbox updates, but it ensures
1112 // that the CLOSE event is being sent.
1113 close_container ();
1114
1115 --map->players;
1116 map->touch ();
1117 }
1118
1119 map->dirty = true; 1104 map->dirty = true;
1120 mapspace &ms = this->ms (); 1105 mapspace &ms = this->ms ();
1106
1107 if (object *pl = ms.player ())
1108 {
1109 if (type == PLAYER) // this == pl(!)
1110 {
1111 // leaving a spot always closes any open container on the ground
1112 if (container && !container->env)
1113 // this causes spurious floorbox updates, but it ensures
1114 // that the CLOSE event is being sent.
1115 close_container ();
1116
1117 --map->players;
1118 map->touch ();
1119 }
1120 else if (pl->container == this)
1121 {
1122 // removing a container should close it
1123 close_container ();
1124 }
1125
1126 esrv_del_item (pl->contr, count);
1127 }
1121 1128
1122 /* link the object above us */ 1129 /* link the object above us */
1123 if (above) 1130 if (above)
1124 above->below = below; 1131 above->below = below;
1125 else 1132 else
2615object::open_container (object *new_container) 2622object::open_container (object *new_container)
2616{ 2623{
2617 if (container == new_container) 2624 if (container == new_container)
2618 return; 2625 return;
2619 2626
2620 if (object *old_container = container) 2627 object *old_container = container;
2628
2629 if (old_container)
2621 { 2630 {
2622 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) 2631 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this)))
2623 return; 2632 return;
2624 2633
2625#if 0 2634#if 0
2627 if (object *closer = old_container->inv) 2636 if (object *closer = old_container->inv)
2628 if (closer->type == CLOSE_CON) 2637 if (closer->type == CLOSE_CON)
2629 closer->destroy (); 2638 closer->destroy ();
2630#endif 2639#endif
2631 2640
2641 // make sure the container is available
2642 esrv_send_item (this, old_container);
2643
2632 old_container->flag [FLAG_APPLIED] = false; 2644 old_container->flag [FLAG_APPLIED] = false;
2633 container = 0; 2645 container = 0;
2634 2646
2647 // client needs item update to make it work, client bug requires this to be separate
2635 esrv_update_item (UPD_FLAGS, this, old_container); 2648 esrv_update_item (UPD_FLAGS, this, old_container);
2649
2636 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2650 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container));
2637 play_sound (sound_find ("chest_close")); 2651 play_sound (sound_find ("chest_close"));
2638 } 2652 }
2639 2653
2640 if (new_container) 2654 if (new_container)
2653 } 2667 }
2654#endif 2668#endif
2655 2669
2656 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2670 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container));
2657 2671
2672 // make sure the container is available, client bug requires this to be separate
2673 esrv_send_item (this, new_container);
2674
2658 new_container->flag [FLAG_APPLIED] = true; 2675 new_container->flag [FLAG_APPLIED] = true;
2659 container = new_container; 2676 container = new_container;
2660 2677
2678 // client needs flag change
2661 esrv_update_item (UPD_FLAGS, this, new_container); 2679 esrv_update_item (UPD_FLAGS, this, new_container);
2662 esrv_send_inventory (this, new_container); 2680 esrv_send_inventory (this, new_container);
2663 play_sound (sound_find ("chest_open")); 2681 play_sound (sound_find ("chest_open"));
2664 } 2682 }
2683// else if (!old_container->env && contr && contr->ns)
2684// contr->ns->floorbox_reset ();
2665} 2685}
2666 2686
2667object * 2687object *
2668object::force_find (const shstr name) 2688object::force_find (const shstr name)
2669{ 2689{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines