… | |
… | |
574 | } |
574 | } |
575 | |
575 | |
576 | this->owner = owner; |
576 | this->owner = owner; |
577 | } |
577 | } |
578 | |
578 | |
579 | int |
|
|
580 | object::slottype () const |
|
|
581 | { |
|
|
582 | if (type == SKILL) |
|
|
583 | { |
|
|
584 | if (IS_COMBAT_SKILL (subtype)) return slot_combat; |
|
|
585 | if (IS_RANGED_SKILL (subtype)) return slot_ranged; |
|
|
586 | } |
|
|
587 | else |
|
|
588 | { |
|
|
589 | if (slot [body_combat].info) return slot_combat; |
|
|
590 | if (slot [body_range ].info) return slot_ranged; |
|
|
591 | } |
|
|
592 | |
|
|
593 | return slot_none; |
|
|
594 | } |
|
|
595 | |
|
|
596 | bool |
|
|
597 | object::change_weapon (object *ob) |
|
|
598 | { |
|
|
599 | if (current_weapon == ob) |
|
|
600 | return true; |
|
|
601 | |
|
|
602 | if (current_weapon && current_weapon->flag [FLAG_APPLIED]) |
|
|
603 | { |
|
|
604 | manual_apply (this, current_weapon, AP_UNAPPLY); |
|
|
605 | |
|
|
606 | if (current_weapon && !current_weapon->flag [FLAG_APPLIED])//D |
|
|
607 | LOG (llevError, "FATAL: did not clear current_weapon (%s)\n", current_weapon->debug_desc ()); |
|
|
608 | |
|
|
609 | if (current_weapon && current_weapon->flag [FLAG_APPLIED]) |
|
|
610 | return false; |
|
|
611 | } |
|
|
612 | |
|
|
613 | current_weapon = 0; |
|
|
614 | |
|
|
615 | if (ob && !ob->flag [FLAG_APPLIED]) |
|
|
616 | { |
|
|
617 | manual_apply (this, ob, AP_APPLY); |
|
|
618 | |
|
|
619 | if (ob->flag [FLAG_APPLIED]) |
|
|
620 | current_weapon = ob; |
|
|
621 | else |
|
|
622 | return false; |
|
|
623 | } |
|
|
624 | |
|
|
625 | return true; |
|
|
626 | } |
|
|
627 | |
|
|
628 | /* Zero the key_values on op, decrementing the shared-string |
579 | /* Zero the key_values on op, decrementing the shared-string |
629 | * refcounts and freeing the links. |
580 | * refcounts and freeing the links. |
630 | */ |
581 | */ |
631 | static void |
582 | static void |
632 | free_key_values (object *op) |
583 | free_key_values (object *op) |
… | |
… | |
988 | map->insert (op, x, y); |
939 | map->insert (op, x, y); |
989 | } |
940 | } |
990 | } |
941 | } |
991 | } |
942 | } |
992 | |
943 | |
|
|
944 | /* |
|
|
945 | * Remove and free all objects in the inventory of the given object. |
|
|
946 | * Unlike destroy_inv, this assumes the *this is destroyed as well |
|
|
947 | * well, so we can (and have to!) take shortcuts. |
|
|
948 | */ |
|
|
949 | void |
|
|
950 | object::destroy_inv_fast () |
|
|
951 | { |
|
|
952 | while (object *op = inv) |
|
|
953 | { |
|
|
954 | // remove from object the fast way |
|
|
955 | op->flag [FLAG_REMOVED] = true; |
|
|
956 | op->env = 0; |
|
|
957 | if ((inv = inv->below)) |
|
|
958 | inv->above = 0; |
|
|
959 | |
|
|
960 | // then destroy |
|
|
961 | op->destroy (); |
|
|
962 | } |
|
|
963 | } |
|
|
964 | |
993 | object *object::create () |
965 | object *object::create () |
994 | { |
966 | { |
995 | object *op = new object; |
967 | object *op = new object; |
996 | op->link (); |
968 | op->link (); |
997 | return op; |
969 | return op; |
… | |
… | |
1067 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
1039 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
1068 | head->destroy (); |
1040 | head->destroy (); |
1069 | return; |
1041 | return; |
1070 | } |
1042 | } |
1071 | |
1043 | |
1072 | destroy_inv (false); |
1044 | destroy_inv_fast (); |
1073 | |
1045 | |
1074 | if (is_head ()) |
1046 | if (is_head ()) |
1075 | if (sound_destroy) |
1047 | if (sound_destroy) |
1076 | play_sound (sound_destroy); |
1048 | play_sound (sound_destroy); |
1077 | else if (flag [FLAG_MONSTER]) |
1049 | else if (flag [FLAG_MONSTER]) |