… | |
… | |
141 | * objects with lists are rare, and lists stay short. If not, use a |
141 | * objects with lists are rare, and lists stay short. If not, use a |
142 | * different structure or at least keep the lists sorted... |
142 | * different structure or at least keep the lists sorted... |
143 | */ |
143 | */ |
144 | |
144 | |
145 | /* For each field in wants, */ |
145 | /* For each field in wants, */ |
146 | for (wants_field = wants->key_values; wants_field != NULL; wants_field = wants_field->next) |
146 | for (wants_field = wants->key_values; wants_field; wants_field = wants_field->next) |
147 | { |
147 | { |
148 | key_value *has_field; |
148 | key_value *has_field; |
149 | |
149 | |
150 | /* Look for a field in has with the same key. */ |
150 | /* Look for a field in has with the same key. */ |
151 | has_field = get_ob_key_link (has, wants_field->key); |
151 | has_field = get_ob_key_link (has, wants_field->key); |
… | |
… | |
364 | { |
364 | { |
365 | if (!op) |
365 | if (!op) |
366 | return strdup ("[NULLOBJ]"); |
366 | return strdup ("[NULLOBJ]"); |
367 | |
367 | |
368 | object_freezer freezer; |
368 | object_freezer freezer; |
369 | save_object (freezer, op, 3); |
369 | save_object (freezer, op, 1); |
370 | return freezer.as_string (); |
370 | return freezer.as_string (); |
371 | } |
371 | } |
372 | |
372 | |
373 | /* |
373 | /* |
374 | * get_nearest_part(multi-object, object 2) returns the part of the |
374 | * get_nearest_part(multi-object, object 2) returns the part of the |
… | |
… | |
522 | tail = new_link; |
522 | tail = new_link; |
523 | } |
523 | } |
524 | } |
524 | } |
525 | } |
525 | } |
526 | |
526 | |
527 | update_ob_speed (dst); |
527 | dst->set_speed (dst->speed); |
528 | } |
528 | } |
529 | |
529 | |
530 | object * |
530 | object * |
531 | object::clone () |
531 | object::clone () |
532 | { |
532 | { |
… | |
… | |
554 | * Updates the speed of an object. If the speed changes from 0 to another |
554 | * Updates the speed of an object. If the speed changes from 0 to another |
555 | * value, or vice versa, then add/remove the object from the active list. |
555 | * value, or vice versa, then add/remove the object from the active list. |
556 | * This function needs to be called whenever the speed of an object changes. |
556 | * This function needs to be called whenever the speed of an object changes. |
557 | */ |
557 | */ |
558 | void |
558 | void |
559 | update_ob_speed (object *op) |
559 | object::set_speed (float speed) |
560 | { |
560 | { |
561 | extern int arch_init; |
561 | extern int arch_init; |
562 | |
562 | |
563 | /* No reason putting the archetypes objects on the speed list, |
563 | /* No reason putting the archetypes objects on the speed list, |
564 | * since they never really need to be updated. |
564 | * since they never really need to be updated. |
565 | */ |
565 | */ |
566 | |
566 | if (flag [FLAG_FREED] && speed) |
567 | if (QUERY_FLAG (op, FLAG_FREED) && op->speed) |
|
|
568 | { |
567 | { |
569 | LOG (llevError, "Object %s is freed but has speed.\n", &op->name); |
568 | LOG (llevError, "Object %s is freed but has speed.\n", &name); |
570 | #ifdef MANY_CORES |
|
|
571 | abort (); |
|
|
572 | #else |
|
|
573 | op->speed = 0; |
569 | speed = 0; |
574 | #endif |
|
|
575 | } |
570 | } |
|
|
571 | |
|
|
572 | this->speed = speed; |
576 | |
573 | |
577 | if (arch_init) |
574 | if (arch_init) |
578 | return; |
575 | return; |
579 | |
576 | |
580 | if (FABS (op->speed) > MIN_ACTIVE_SPEED) |
577 | if (FABS (speed) > MIN_ACTIVE_SPEED) |
581 | { |
578 | { |
582 | /* If already on active list, don't do anything */ |
579 | /* If already on active list, don't do anything */ |
583 | if (op->active_next || op->active_prev || op == active_objects) |
580 | if (active_next || active_prev || this == active_objects) |
584 | return; |
581 | return; |
585 | |
582 | |
586 | /* process_events() expects us to insert the object at the beginning |
583 | /* process_events() expects us to insert the object at the beginning |
587 | * of the list. */ |
584 | * of the list. */ |
588 | op->active_next = active_objects; |
585 | active_next = active_objects; |
589 | |
586 | |
590 | if (op->active_next != NULL) |
587 | if (active_next) |
591 | op->active_next->active_prev = op; |
588 | active_next->active_prev = this; |
592 | |
589 | |
593 | active_objects = op; |
590 | active_objects = this; |
594 | } |
591 | } |
595 | else |
592 | else |
596 | { |
593 | { |
597 | /* If not on the active list, nothing needs to be done */ |
594 | /* If not on the active list, nothing needs to be done */ |
598 | if (!op->active_next && !op->active_prev && op != active_objects) |
595 | if (!active_next && !active_prev && this != active_objects) |
599 | return; |
596 | return; |
600 | |
597 | |
601 | if (op->active_prev == NULL) |
598 | if (!active_prev) |
602 | { |
599 | { |
603 | active_objects = op->active_next; |
600 | active_objects = active_next; |
604 | |
601 | |
605 | if (op->active_next != NULL) |
602 | if (active_next) |
606 | op->active_next->active_prev = NULL; |
603 | active_next->active_prev = 0; |
607 | } |
604 | } |
608 | else |
605 | else |
609 | { |
606 | { |
610 | op->active_prev->active_next = op->active_next; |
607 | active_prev->active_next = active_next; |
611 | |
608 | |
612 | if (op->active_next) |
609 | if (active_next) |
613 | op->active_next->active_prev = op->active_prev; |
610 | active_next->active_prev = active_prev; |
614 | } |
611 | } |
615 | |
612 | |
616 | op->active_next = NULL; |
613 | active_next = 0; |
617 | op->active_prev = NULL; |
614 | active_prev = 0; |
618 | } |
615 | } |
619 | } |
616 | } |
620 | |
617 | |
621 | /* This function removes object 'op' from the list of active |
618 | /* This function removes object 'op' from the list of active |
622 | * objects. |
619 | * objects. |
… | |
… | |
788 | object *op = new object; |
785 | object *op = new object; |
789 | op->link (); |
786 | op->link (); |
790 | return op; |
787 | return op; |
791 | } |
788 | } |
792 | |
789 | |
793 | /* |
|
|
794 | * free_object() frees everything allocated by an object, removes |
|
|
795 | * it from the list of used objects, and puts it on the list of |
|
|
796 | * free objects. The IS_FREED() flag is set in the object. |
|
|
797 | * The object must have been removed by remove_ob() first for |
|
|
798 | * this function to succeed. |
|
|
799 | * |
|
|
800 | * If destroy_inventory is set, free inventory as well. Else drop items in |
|
|
801 | * inventory to the ground. |
|
|
802 | */ |
|
|
803 | void |
790 | void |
804 | object::do_destroy () |
791 | object::do_destroy () |
805 | { |
792 | { |
806 | attachable::do_destroy (); |
793 | attachable::do_destroy (); |
807 | |
794 | |
… | |
… | |
850 | |
837 | |
851 | // only relevant for players(?), but make sure of it anyways |
838 | // only relevant for players(?), but make sure of it anyways |
852 | contr = 0; |
839 | contr = 0; |
853 | |
840 | |
854 | /* Remove object from the active list */ |
841 | /* Remove object from the active list */ |
855 | speed = 0; |
842 | set_speed (0); |
856 | update_ob_speed (this); |
|
|
857 | |
843 | |
858 | unlink (); |
844 | unlink (); |
859 | } |
845 | } |
860 | |
846 | |
861 | /* |
847 | /* |