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.218 by root, Wed Apr 23 07:25:54 2008 UTC vs.
Revision 1.224 by root, Fri May 2 20:16:24 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}
605} 606}
606 607
607object & 608object &
608object::operator =(const object &src) 609object::operator =(const object &src)
609{ 610{
610 bool is_freed = flag [FLAG_FREED]; 611 remove ();
611 bool is_removed = flag [FLAG_REMOVED];
612 612
613 *(object_copy *)this = src; 613 *(object_copy *)this = src;
614 614
615 flag [FLAG_FREED] = is_freed;
616 flag [FLAG_REMOVED] = is_removed; 615 flag [FLAG_REMOVED] = true;
617 616
618 /* Copy over key_values, if any. */ 617 /* Copy over key_values, if any. */
619 if (src.key_values) 618 if (src.key_values)
620 { 619 {
621 key_value *tail = 0; 620 key_value *tail = 0;
745 * UP_OBJ_FACE: only the objects face has changed. 744 * UP_OBJ_FACE: only the objects face has changed.
746 */ 745 */
747void 746void
748update_object (object *op, int action) 747update_object (object *op, int action)
749{ 748{
750 if (op == NULL) 749 if (!op)
751 { 750 {
752 /* this should never happen */ 751 /* this should never happen */
753 LOG (llevDebug, "update_object() called for NULL object.\n"); 752 LOG (llevError | logBacktrace, "update_object() called for NULL object.\n");
754 return; 753 return;
755 } 754 }
756 755
757 if (op->env) 756 if (!op->is_on_map ())
758 { 757 {
759 /* Animation is currently handled by client, so nothing 758 /* Animation is currently handled by client, so nothing
760 * to do in this case. 759 * to do in this case.
761 */ 760 */
762 return; 761 return;
763 } 762 }
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 763
771 /* make sure the object is within map boundaries */ 764 /* 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) 765 if (op->x < 0 || op->x >= op->map->width || op->y < 0 || op->y >= op->map->height)
773 { 766 {
774 LOG (llevError, "update_object() called for object out of map!\n"); 767 LOG (llevError, "update_object() called for object out of map!\n");
964 object *op = new object; 957 object *op = new object;
965 op->link (); 958 op->link ();
966 return op; 959 return op;
967} 960}
968 961
962static struct freed_map : maptile
963{
964 freed_map ()
965 {
966 path = "<freed objects map>";
967 name = "/internal/freed_objects_map";
968 width = 3;
969 height = 3;
970 nodrop = 1;
971
972 alloc ();
973 in_memory = MAP_ACTIVE;
974 }
975} freed_map; // freed objects are moved here to avoid crashes
976
969void 977void
970object::do_destroy () 978object::do_destroy ()
971{ 979{
972 if (flag [FLAG_IS_LINKED]) 980 if (flag [FLAG_IS_LINKED])
973 remove_button_link (this); 981 remove_button_link (this);
983 unlink (); 991 unlink ();
984 992
985 flag [FLAG_FREED] = 1; 993 flag [FLAG_FREED] = 1;
986 994
987 // hack to ensure that freed objects still have a valid map 995 // hack to ensure that freed objects still have a valid map
988 {
989 static maptile *freed_map; // freed objects are moved here to avoid crashes
990
991 if (!freed_map)
992 {
993 freed_map = new maptile;
994
995 freed_map->path = "<freed objects map>";
996 freed_map->name = "/internal/freed_objects_map";
997 freed_map->width = 3;
998 freed_map->height = 3;
999 freed_map->nodrop = 1;
1000
1001 freed_map->alloc ();
1002 freed_map->in_memory = MAP_ACTIVE;
1003 }
1004
1005 map = freed_map; 996 map = &freed_map;
1006 x = 1; 997 x = 1;
1007 y = 1; 998 y = 1;
1008 }
1009 999
1010 if (more) 1000 if (more)
1011 { 1001 {
1012 more->destroy (); 1002 more->destroy ();
1013 more = 0; 1003 more = 0;
1025void 1015void
1026object::destroy (bool destroy_inventory) 1016object::destroy (bool destroy_inventory)
1027{ 1017{
1028 if (destroyed ()) 1018 if (destroyed ())
1029 return; 1019 return;
1020
1021 if (!is_head () && !head->destroyed ())
1022 {
1023 LOG (llevError | logBacktrace, "tried to destroy the tail of an object");
1024 head->destroy (destroy_inventory);
1025 return;
1026 }
1030 1027
1031 destroy_inv (!destroy_inventory); 1028 destroy_inv (!destroy_inventory);
1032 1029
1033 if (is_head ()) 1030 if (is_head ())
1034 if (sound_destroy) 1031 if (sound_destroy)
1055 if (flag [FLAG_REMOVED]) 1052 if (flag [FLAG_REMOVED])
1056 return; 1053 return;
1057 1054
1058 INVOKE_OBJECT (REMOVE, this); 1055 INVOKE_OBJECT (REMOVE, this);
1059 1056
1060 if (object *pl = visible_to ())
1061 esrv_del_item (pl->contr, count);
1062
1063 flag [FLAG_REMOVED] = true; 1057 flag [FLAG_REMOVED] = true;
1064 1058
1065 if (more) 1059 if (more)
1066 more->remove (); 1060 more->remove ();
1067 1061
1069 * In this case, the object to be removed is in someones 1063 * In this case, the object to be removed is in someones
1070 * inventory. 1064 * inventory.
1071 */ 1065 */
1072 if (env) 1066 if (env)
1073 { 1067 {
1068 flag [FLAG_REMOVED] = false; // hack around the issue of visible_to checking flag_removed
1069 if (object *pl = visible_to ())
1070 esrv_del_item (pl->contr, count);
1071 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1072
1074 adjust_weight (env, -total_weight ()); 1073 adjust_weight (env, -total_weight ());
1075 1074
1076 *(above ? &above->below : &env->inv) = below; 1075 *(above ? &above->below : &env->inv) = below;
1077 1076
1078 if (below) 1077 if (below)
1096 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) 1095 if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER))
1097 otmp->update_stats (); 1096 otmp->update_stats ();
1098 } 1097 }
1099 else if (map) 1098 else if (map)
1100 { 1099 {
1101 if (type == PLAYER)
1102 {
1103 // leaving a spot always closes any open container on the ground
1104 if (container && !container->env)
1105 // this causes spurious floorbox updates, but it ensures
1106 // that the CLOSE event is being sent.
1107 close_container ();
1108
1109 --map->players;
1110 map->touch ();
1111 }
1112
1113 map->dirty = true; 1100 map->dirty = true;
1114 mapspace &ms = this->ms (); 1101 mapspace &ms = this->ms ();
1102
1103 if (object *pl = ms.player ())
1104 {
1105 if (type == PLAYER) // this == pl(!)
1106 {
1107 // leaving a spot always closes any open container on the ground
1108 if (container && !container->env)
1109 // this causes spurious floorbox updates, but it ensures
1110 // that the CLOSE event is being sent.
1111 close_container ();
1112
1113 --map->players;
1114 map->touch ();
1115 }
1116 else if (pl->container == this)
1117 {
1118 // removing a container should close it
1119 close_container ();
1120 }
1121
1122 esrv_del_item (pl->contr, count);
1123 }
1115 1124
1116 /* link the object above us */ 1125 /* link the object above us */
1117 if (above) 1126 if (above)
1118 above->below = below; 1127 above->below = below;
1119 else 1128 else
2315 * create clone from object to another 2324 * create clone from object to another
2316 */ 2325 */
2317object * 2326object *
2318object_create_clone (object *asrc) 2327object_create_clone (object *asrc)
2319{ 2328{
2320 object *dst = 0, *tmp, *src, *prev, *item; 2329 object *dst = 0;
2321 2330
2322 if (!asrc) 2331 if (!asrc)
2323 return 0; 2332 return 0;
2324 2333
2325 src = asrc->head_ (); 2334 object *src = asrc->head_ ();
2326 2335
2327 prev = 0; 2336 object *prev = 0;
2328 for (object *part = src; part; part = part->more) 2337 for (object *part = src; part; part = part->more)
2329 { 2338 {
2330 tmp = part->clone (); 2339 object *tmp = part->clone ();
2340
2331 tmp->x -= src->x; 2341 tmp->x -= src->x;
2332 tmp->y -= src->y; 2342 tmp->y -= src->y;
2333 2343
2334 if (!part->head) 2344 if (!part->head)
2335 { 2345 {
2345 prev->more = tmp; 2355 prev->more = tmp;
2346 2356
2347 prev = tmp; 2357 prev = tmp;
2348 } 2358 }
2349 2359
2350 for (item = src->inv; item; item = item->below) 2360 for (object *item = src->inv; item; item = item->below)
2351 insert_ob_in_ob (object_create_clone (item), dst); 2361 insert_ob_in_ob (object_create_clone (item), dst);
2352 2362
2353 return dst; 2363 return dst;
2354} 2364}
2355 2365
2609object::open_container (object *new_container) 2619object::open_container (object *new_container)
2610{ 2620{
2611 if (container == new_container) 2621 if (container == new_container)
2612 return; 2622 return;
2613 2623
2614 if (object *old_container = container) 2624 object *old_container = container;
2625
2626 if (old_container)
2615 { 2627 {
2616 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) 2628 if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this)))
2617 return; 2629 return;
2618 2630
2619#if 0 2631#if 0
2621 if (object *closer = old_container->inv) 2633 if (object *closer = old_container->inv)
2622 if (closer->type == CLOSE_CON) 2634 if (closer->type == CLOSE_CON)
2623 closer->destroy (); 2635 closer->destroy ();
2624#endif 2636#endif
2625 2637
2638 // make sure the container is available
2639 esrv_send_item (this, old_container);
2640
2626 old_container->flag [FLAG_APPLIED] = false; 2641 old_container->flag [FLAG_APPLIED] = false;
2627 container = 0; 2642 container = 0;
2628 2643
2644 // client needs item update to make it work, client bug requires this to be separate
2629 esrv_update_item (UPD_FLAGS, this, old_container); 2645 esrv_update_item (UPD_FLAGS, this, old_container);
2646
2630 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2647 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container));
2631 play_sound (sound_find ("chest_close")); 2648 play_sound (sound_find ("chest_close"));
2632 } 2649 }
2633 2650
2634 if (new_container) 2651 if (new_container)
2647 } 2664 }
2648#endif 2665#endif
2649 2666
2650 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2667 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container));
2651 2668
2669 // make sure the container is available, client bug requires this to be separate
2670 esrv_send_item (this, new_container);
2671
2652 new_container->flag [FLAG_APPLIED] = true; 2672 new_container->flag [FLAG_APPLIED] = true;
2653 container = new_container; 2673 container = new_container;
2654 2674
2675 // client needs flag change
2655 esrv_update_item (UPD_FLAGS, this, new_container); 2676 esrv_update_item (UPD_FLAGS, this, new_container);
2656 esrv_send_inventory (this, new_container); 2677 esrv_send_inventory (this, new_container);
2657 play_sound (sound_find ("chest_open")); 2678 play_sound (sound_find ("chest_open"));
2658 } 2679 }
2680// else if (!old_container->env && contr && contr->ns)
2681// contr->ns->floorbox_reset ();
2659} 2682}
2660 2683
2661object * 2684object *
2662object::force_find (const shstr name) 2685object::force_find (const shstr name)
2663{ 2686{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines