… | |
… | |
603 | } |
603 | } |
604 | |
604 | |
605 | op->key_values = 0; |
605 | op->key_values = 0; |
606 | } |
606 | } |
607 | |
607 | |
608 | object & |
608 | /* |
609 | object::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 | */ |
|
|
616 | void |
|
|
617 | object::copy_to (object *dst) |
610 | { |
618 | { |
611 | remove (); |
619 | dst->remove (); |
612 | |
|
|
613 | *(object_copy *)this = src; |
620 | *(object_copy *)dst = *this; |
614 | |
|
|
615 | flag [FLAG_REMOVED] = true; |
621 | dst->flag [FLAG_REMOVED] = true; |
616 | |
622 | |
617 | /* Copy over key_values, if any. */ |
623 | /* Copy over key_values, if any. */ |
618 | if (src.key_values) |
624 | if (key_values) |
619 | { |
625 | { |
620 | key_value *tail = 0; |
626 | key_value *tail = 0; |
621 | key_values = 0; |
627 | dst->key_values = 0; |
622 | |
628 | |
623 | for (key_value *i = src.key_values; i; i = i->next) |
629 | for (key_value *i = key_values; i; i = i->next) |
624 | { |
630 | { |
625 | key_value *new_link = new key_value; |
631 | key_value *new_link = new key_value; |
626 | |
632 | |
627 | new_link->next = 0; |
633 | new_link->next = 0; |
628 | new_link->key = i->key; |
634 | new_link->key = i->key; |
629 | new_link->value = i->value; |
635 | new_link->value = i->value; |
630 | |
636 | |
631 | /* Try and be clever here, too. */ |
637 | /* Try and be clever here, too. */ |
632 | if (!key_values) |
638 | if (!dst->key_values) |
633 | { |
639 | { |
634 | key_values = new_link; |
640 | dst->key_values = new_link; |
635 | tail = new_link; |
641 | tail = new_link; |
636 | } |
642 | } |
637 | else |
643 | else |
638 | { |
644 | { |
639 | tail->next = new_link; |
645 | tail->next = new_link; |
640 | tail = new_link; |
646 | tail = new_link; |
641 | } |
647 | } |
642 | } |
648 | } |
643 | } |
649 | } |
644 | } |
|
|
645 | |
|
|
646 | /* |
|
|
647 | * copy_to first frees everything allocated by the dst object, |
|
|
648 | * and then copies the contents of itself into the second |
|
|
649 | * object, allocating what needs to be allocated. Basically, any |
|
|
650 | * data that is malloc'd needs to be re-malloc/copied. Otherwise, |
|
|
651 | * if the first object is freed, the pointers in the new object |
|
|
652 | * will point at garbage. |
|
|
653 | */ |
|
|
654 | void |
|
|
655 | object::copy_to (object *dst) |
|
|
656 | { |
|
|
657 | *dst = *this; |
|
|
658 | |
650 | |
659 | if (speed < 0) |
651 | if (speed < 0) |
660 | dst->speed_left -= rndm (); |
652 | dst->speed_left -= rndm (); |
661 | |
653 | |
662 | dst->set_speed (dst->speed); |
654 | dst->set_speed (dst->speed); |