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.223 by root, Wed Apr 30 08:29:31 2008 UTC vs.
Revision 1.227 by root, Sat May 3 09:04:17 2008 UTC

603 } 603 }
604 604
605 op->key_values = 0; 605 op->key_values = 0;
606} 606}
607 607
608object & 608/*
609object::operator =(const object &src) 609 * copy_to first frees everything allocated by the dst object,
610 * and then copies the contents of itself into the second
611 * object, allocating what needs to be allocated. Basically, any
612 * data that is malloc'd needs to be re-malloc/copied. Otherwise,
613 * if the first object is freed, the pointers in the new object
614 * will point at garbage.
615 */
616void
617object::copy_to (object *dst)
610{ 618{
611 bool is_freed = flag [FLAG_FREED]; 619 dst->remove ();
612 bool is_removed = flag [FLAG_REMOVED];
613
614 *(object_copy *)this = src; 620 *(object_copy *)dst = *this;
615
616 flag [FLAG_FREED] = is_freed;
617 flag [FLAG_REMOVED] = is_removed; 621 dst->flag [FLAG_REMOVED] = true;
618 622
619 /* Copy over key_values, if any. */ 623 /* Copy over key_values, if any. */
620 if (src.key_values) 624 if (key_values)
621 { 625 {
622 key_value *tail = 0; 626 key_value *tail = 0;
623 key_values = 0; 627 dst->key_values = 0;
624 628
625 for (key_value *i = src.key_values; i; i = i->next) 629 for (key_value *i = key_values; i; i = i->next)
626 { 630 {
627 key_value *new_link = new key_value; 631 key_value *new_link = new key_value;
628 632
629 new_link->next = 0; 633 new_link->next = 0;
630 new_link->key = i->key; 634 new_link->key = i->key;
631 new_link->value = i->value; 635 new_link->value = i->value;
632 636
633 /* Try and be clever here, too. */ 637 /* Try and be clever here, too. */
634 if (!key_values) 638 if (!dst->key_values)
635 { 639 {
636 key_values = new_link; 640 dst->key_values = new_link;
637 tail = new_link; 641 tail = new_link;
638 } 642 }
639 else 643 else
640 { 644 {
641 tail->next = new_link; 645 tail->next = new_link;
642 tail = new_link; 646 tail = new_link;
643 } 647 }
644 } 648 }
645 } 649 }
646}
647
648/*
649 * copy_to first frees everything allocated by the dst object,
650 * and then copies the contents of itself into the second
651 * object, allocating what needs to be allocated. Basically, any
652 * data that is malloc'd needs to be re-malloc/copied. Otherwise,
653 * if the first object is freed, the pointers in the new object
654 * will point at garbage.
655 */
656void
657object::copy_to (object *dst)
658{
659 *dst = *this;
660 650
661 if (speed < 0) 651 if (speed < 0)
662 dst->speed_left -= rndm (); 652 dst->speed_left -= rndm ();
663 653
664 dst->set_speed (dst->speed); 654 dst->set_speed (dst->speed);
686object * 676object *
687object::clone () 677object::clone ()
688{ 678{
689 object *neu = create (); 679 object *neu = create ();
690 copy_to (neu); 680 copy_to (neu);
681 neu->map = map; // not copied by copy_to
691 return neu; 682 return neu;
692} 683}
693 684
694/* 685/*
695 * If an object with the IS_TURNABLE() flag needs to be turned due 686 * If an object with the IS_TURNABLE() flag needs to be turned due
1161 * appropriately. 1152 * appropriately.
1162 */ 1153 */
1163 pl->close_container (); 1154 pl->close_container ();
1164 1155
1165 //TODO: the floorbox prev/next might need updating 1156 //TODO: the floorbox prev/next might need updating
1166 esrv_del_item (pl->contr, count); 1157 //esrv_del_item (pl->contr, count);
1158 //TODO: update floorbox to preserve ordering
1159 if (pl->contr->ns)
1160 pl->contr->ns->floorbox_update ();
1167 } 1161 }
1168 1162
1169 for (tmp = ms.bot; tmp; tmp = tmp->above) 1163 for (tmp = ms.bot; tmp; tmp = tmp->above)
1170 { 1164 {
1171 /* No point updating the players look faces if he is the object 1165 /* No point updating the players look faces if he is the object
1469 1463
1470 op->map->dirty = true; 1464 op->map->dirty = true;
1471 1465
1472 if (object *pl = ms.player ()) 1466 if (object *pl = ms.player ())
1473 //TODO: the floorbox prev/next might need updating 1467 //TODO: the floorbox prev/next might need updating
1474 esrv_send_item (pl, op); 1468 //esrv_send_item (pl, op);
1469 //TODO: update floorbox to preserve ordering
1470 if (pl->contr->ns)
1471 pl->contr->ns->floorbox_update ();
1475 1472
1476 /* If this object glows, it may affect lighting conditions that are 1473 /* If this object glows, it may affect lighting conditions that are
1477 * visible to others on this map. But update_all_los is really 1474 * visible to others on this map. But update_all_los is really
1478 * an inefficient way to do this, as it means los for all players 1475 * an inefficient way to do this, as it means los for all players
1479 * on the map will get recalculated. The players could very well 1476 * on the map will get recalculated. The players could very well
2326 * create clone from object to another 2323 * create clone from object to another
2327 */ 2324 */
2328object * 2325object *
2329object_create_clone (object *asrc) 2326object_create_clone (object *asrc)
2330{ 2327{
2331 object *dst = 0, *tmp, *src, *prev, *item; 2328 object *dst = 0;
2332 2329
2333 if (!asrc) 2330 if (!asrc)
2334 return 0; 2331 return 0;
2335 2332
2336 src = asrc->head_ (); 2333 object *src = asrc->head_ ();
2337 2334
2338 prev = 0; 2335 object *prev = 0;
2339 for (object *part = src; part; part = part->more) 2336 for (object *part = src; part; part = part->more)
2340 { 2337 {
2341 tmp = part->clone (); 2338 object *tmp = part->clone ();
2339
2342 tmp->x -= src->x; 2340 tmp->x -= src->x;
2343 tmp->y -= src->y; 2341 tmp->y -= src->y;
2344 2342
2345 if (!part->head) 2343 if (!part->head)
2346 { 2344 {
2356 prev->more = tmp; 2354 prev->more = tmp;
2357 2355
2358 prev = tmp; 2356 prev = tmp;
2359 } 2357 }
2360 2358
2361 for (item = src->inv; item; item = item->below) 2359 for (object *item = src->inv; item; item = item->below)
2362 insert_ob_in_ob (object_create_clone (item), dst); 2360 insert_ob_in_ob (object_create_clone (item), dst);
2363 2361
2364 return dst; 2362 return dst;
2365} 2363}
2366 2364

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines