1 | /* |
1 | /* |
2 | * static char *rcsid_object_c = |
2 | * static char *rcsid_object_c = |
3 | * "$Id: object.C,v 1.21 2006/09/09 21:48:28 root Exp $"; |
3 | * "$Id: object.C,v 1.23 2006/09/10 14:54:02 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
529 | SET_FLAG (this, FLAG_REMOVED); |
529 | SET_FLAG (this, FLAG_REMOVED); |
530 | } |
530 | } |
531 | |
531 | |
532 | void object::clone (object *destination) |
532 | void object::clone (object *destination) |
533 | { |
533 | { |
534 | *(object_copy *)destination = *(object_copy *)this; |
534 | *(object_copy *)destination = *this; |
535 | *(object_pod *)destination = *(object_pod *)this; |
535 | *(object_pod *)destination = *this; |
536 | |
536 | |
537 | if (self || cb) |
537 | if (self || cb) |
538 | INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination)); |
538 | INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination)); |
539 | } |
539 | } |
540 | |
540 | |
… | |
… | |
590 | |
590 | |
591 | if (op2->speed < 0) |
591 | if (op2->speed < 0) |
592 | op->speed_left = op2->speed_left - RANDOM() % 200 / 100.0; |
592 | op->speed_left = op2->speed_left - RANDOM() % 200 / 100.0; |
593 | |
593 | |
594 | /* Copy over key_values, if any. */ |
594 | /* Copy over key_values, if any. */ |
595 | if (op2->key_values != NULL) |
595 | if (op2->key_values) |
596 | { |
596 | { |
597 | key_value *tail = NULL; |
597 | key_value *tail = 0; |
598 | key_value *i; |
598 | key_value *i; |
599 | |
599 | |
600 | op->key_values = NULL; |
600 | op->key_values = 0; |
601 | |
601 | |
602 | for (i = op2->key_values; i != NULL; i = i->next) |
602 | for (i = op2->key_values; i; i = i->next) |
603 | { |
603 | { |
604 | key_value *new_link = new key_value; |
604 | key_value *new_link = new key_value; |
605 | |
605 | |
606 | new_link->next = NULL; |
606 | new_link->next = 0; |
607 | new_link->key = i->key; |
607 | new_link->key = i->key; |
608 | new_link->value = i->value; |
608 | new_link->value = i->value; |
609 | |
609 | |
610 | /* Try and be clever here, too. */ |
610 | /* Try and be clever here, too. */ |
611 | if (op->key_values == NULL) |
611 | if (!op->key_values) |
612 | { |
612 | { |
613 | op->key_values = new_link; |
613 | op->key_values = new_link; |
614 | tail = new_link; |
614 | tail = new_link; |
615 | } |
615 | } |
616 | else |
616 | else |
… | |
… | |
843 | mortals.clear (); |
843 | mortals.clear (); |
844 | } |
844 | } |
845 | |
845 | |
846 | object::object () |
846 | object::object () |
847 | { |
847 | { |
848 | count = ++ob_count; |
|
|
849 | |
|
|
850 | prev = 0; |
|
|
851 | next = objects; |
|
|
852 | |
|
|
853 | if (objects) |
|
|
854 | objects->prev = this; |
|
|
855 | |
|
|
856 | objects = this; |
|
|
857 | |
|
|
858 | SET_FLAG (this, FLAG_REMOVED); |
848 | SET_FLAG (this, FLAG_REMOVED); |
859 | |
849 | |
860 | expmul = 1.0; |
850 | expmul = 1.0; |
861 | face = blank_face; |
851 | face = blank_face; |
862 | attacked_by_count = -1; |
852 | attacked_by_count = -1; |
863 | } |
853 | } |
864 | |
854 | |
865 | object::~object () |
855 | object::~object () |
866 | { |
856 | { |
|
|
857 | free_key_values (this); |
867 | } |
858 | } |
|
|
859 | |
|
|
860 | void |
|
|
861 | object::link () |
|
|
862 | { |
|
|
863 | count = ++ob_count; |
|
|
864 | |
|
|
865 | prev = 0; |
|
|
866 | next = objects; |
|
|
867 | |
|
|
868 | if (objects) |
|
|
869 | objects->prev = this; |
|
|
870 | |
|
|
871 | objects = this; |
|
|
872 | } |
|
|
873 | |
|
|
874 | void |
|
|
875 | object::unlink () |
|
|
876 | { |
|
|
877 | count = 0; |
|
|
878 | |
|
|
879 | /* Remove this object from the list of used objects */ |
|
|
880 | if (prev) prev->next = next; |
|
|
881 | if (next) next->prev = prev; |
|
|
882 | if (this == objects) objects = next; |
|
|
883 | } |
868 | |
884 | |
869 | object *object::create () |
885 | object *object::create () |
870 | { |
886 | { |
871 | return new object; |
887 | object *op = new object; |
|
|
888 | op->link (); |
|
|
889 | return op; |
872 | } |
890 | } |
873 | |
891 | |
874 | /* |
892 | /* |
875 | * free_object() frees everything allocated by an object, removes |
893 | * free_object() frees everything allocated by an object, removes |
876 | * it from the list of used objects, and puts it on the list of |
894 | * it from the list of used objects, and puts it on the list of |
… | |
… | |
959 | |
977 | |
960 | /* Remove object from the active list */ |
978 | /* Remove object from the active list */ |
961 | speed = 0; |
979 | speed = 0; |
962 | update_ob_speed (this); |
980 | update_ob_speed (this); |
963 | |
981 | |
|
|
982 | unlink (); |
|
|
983 | |
964 | SET_FLAG (this, FLAG_FREED); |
984 | SET_FLAG (this, FLAG_FREED); |
965 | |
|
|
966 | mortalise (); |
|
|
967 | } |
|
|
968 | |
|
|
969 | void |
|
|
970 | object::mortalise () |
|
|
971 | { |
|
|
972 | count = 0; |
|
|
973 | |
|
|
974 | /* Remove this object from the list of used objects */ |
|
|
975 | if (prev) prev->next = next; |
|
|
976 | if (next) next->prev = prev; |
|
|
977 | if (this == objects) objects = next; |
|
|
978 | |
|
|
979 | free_key_values (this); |
|
|
980 | |
985 | |
981 | mortals.push_back (this); |
986 | mortals.push_back (this); |
982 | } |
987 | } |
983 | |
988 | |
984 | /* |
989 | /* |