… | |
… | |
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); |
… | |
… | |
684 | object * |
676 | object * |
685 | object::clone () |
677 | object::clone () |
686 | { |
678 | { |
687 | object *neu = create (); |
679 | object *neu = create (); |
688 | copy_to (neu); |
680 | copy_to (neu); |
|
|
681 | neu->map = map; // not copied by copy_to |
689 | return neu; |
682 | return neu; |
690 | } |
683 | } |
691 | |
684 | |
692 | /* |
685 | /* |
693 | * 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 |
… | |
… | |
1159 | * appropriately. |
1152 | * appropriately. |
1160 | */ |
1153 | */ |
1161 | pl->close_container (); |
1154 | pl->close_container (); |
1162 | |
1155 | |
1163 | //TODO: the floorbox prev/next might need updating |
1156 | //TODO: the floorbox prev/next might need updating |
1164 | 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 (); |
1165 | } |
1161 | } |
1166 | |
1162 | |
1167 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1163 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
1168 | { |
1164 | { |
1169 | /* 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 |
… | |
… | |
1467 | |
1463 | |
1468 | op->map->dirty = true; |
1464 | op->map->dirty = true; |
1469 | |
1465 | |
1470 | if (object *pl = ms.player ()) |
1466 | if (object *pl = ms.player ()) |
1471 | //TODO: the floorbox prev/next might need updating |
1467 | //TODO: the floorbox prev/next might need updating |
1472 | 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 (); |
1473 | |
1472 | |
1474 | /* If this object glows, it may affect lighting conditions that are |
1473 | /* If this object glows, it may affect lighting conditions that are |
1475 | * 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 |
1476 | * 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 |
1477 | * on the map will get recalculated. The players could very well |
1476 | * on the map will get recalculated. The players could very well |