1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
520 | |
520 | |
521 | return 0; |
521 | return 0; |
522 | } |
522 | } |
523 | |
523 | |
524 | /* |
524 | /* |
|
|
525 | * Returns the object which has the uuid equal to the argument. |
|
|
526 | * MOAR VERRRY slow. |
|
|
527 | */ |
|
|
528 | |
|
|
529 | object * |
|
|
530 | find_object_uuid (UUID i) |
|
|
531 | { |
|
|
532 | for_all_objects (op) |
|
|
533 | if (op->uuid == i) |
|
|
534 | return op; |
|
|
535 | |
|
|
536 | return 0; |
|
|
537 | } |
|
|
538 | |
|
|
539 | /* |
525 | * Returns the first object which has a name equal to the argument. |
540 | * Returns the first object which has a name equal to the argument. |
526 | * Used only by the patch command, but not all that useful. |
541 | * Used only by the patch command, but not all that useful. |
527 | * Enables features like "patch <name-of-other-player> food 999" |
542 | * Enables features like "patch <name-of-other-player> food 999" |
528 | */ |
543 | */ |
529 | object * |
544 | object * |
… | |
… | |
557 | LOG (llevError | logBacktrace, "tried to set owner of %s to %s\n", debug_desc (), owner->debug_desc ()); |
572 | LOG (llevError | logBacktrace, "tried to set owner of %s to %s\n", debug_desc (), owner->debug_desc ()); |
558 | return; |
573 | return; |
559 | } |
574 | } |
560 | |
575 | |
561 | this->owner = owner; |
576 | this->owner = owner; |
562 | } |
|
|
563 | |
|
|
564 | int |
|
|
565 | object::slottype () const |
|
|
566 | { |
|
|
567 | if (type == SKILL) |
|
|
568 | { |
|
|
569 | if (IS_COMBAT_SKILL (subtype)) return slot_combat; |
|
|
570 | if (IS_RANGED_SKILL (subtype)) return slot_ranged; |
|
|
571 | } |
|
|
572 | else |
|
|
573 | { |
|
|
574 | if (slot [body_combat].info) return slot_combat; |
|
|
575 | if (slot [body_range ].info) return slot_ranged; |
|
|
576 | } |
|
|
577 | |
|
|
578 | return slot_none; |
|
|
579 | } |
|
|
580 | |
|
|
581 | bool |
|
|
582 | object::change_weapon (object *ob) |
|
|
583 | { |
|
|
584 | if (current_weapon == ob) |
|
|
585 | return true; |
|
|
586 | |
|
|
587 | if (chosen_skill) |
|
|
588 | chosen_skill->flag [FLAG_APPLIED] = false; |
|
|
589 | |
|
|
590 | current_weapon = ob; |
|
|
591 | chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill); |
|
|
592 | |
|
|
593 | if (chosen_skill) |
|
|
594 | chosen_skill->flag [FLAG_APPLIED] = true; |
|
|
595 | |
|
|
596 | update_stats (); |
|
|
597 | |
|
|
598 | if (ob) |
|
|
599 | { |
|
|
600 | // now check wether any body locations became invalid, in which case |
|
|
601 | // we cannot apply the weapon at the moment. |
|
|
602 | for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) |
|
|
603 | if (slot[i].used < 0) |
|
|
604 | { |
|
|
605 | current_weapon = chosen_skill = 0; |
|
|
606 | update_stats (); |
|
|
607 | |
|
|
608 | new_draw_info_format (NDI_UNIQUE, 0, this, |
|
|
609 | "You try to balance all your items at once, " |
|
|
610 | "but the %s is just too much for your body. " |
|
|
611 | "[You need to unapply some items first - use the 'body' command to see " |
|
|
612 | "how many items you cna wera on a specific body part.]", &ob->name); |
|
|
613 | return false; |
|
|
614 | } |
|
|
615 | |
|
|
616 | //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); |
|
|
617 | } |
|
|
618 | else |
|
|
619 | ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons."); |
|
|
620 | |
|
|
621 | if (ob && !ob->flag [FLAG_APPLIED] && ob->type != SPELL) |
|
|
622 | { |
|
|
623 | LOG (llevError | logBacktrace, "%s changed to unapplied weapon %s", |
|
|
624 | &name, ob->debug_desc ()); |
|
|
625 | return false; |
|
|
626 | } |
|
|
627 | |
|
|
628 | return true; |
|
|
629 | } |
577 | } |
630 | |
578 | |
631 | /* Zero the key_values on op, decrementing the shared-string |
579 | /* Zero the key_values on op, decrementing the shared-string |
632 | * refcounts and freeing the links. |
580 | * refcounts and freeing the links. |
633 | */ |
581 | */ |
… | |
… | |
991 | map->insert (op, x, y); |
939 | map->insert (op, x, y); |
992 | } |
940 | } |
993 | } |
941 | } |
994 | } |
942 | } |
995 | |
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 | |
996 | object *object::create () |
965 | object *object::create () |
997 | { |
966 | { |
998 | object *op = new object; |
967 | object *op = new object; |
999 | op->link (); |
968 | op->link (); |
1000 | return op; |
969 | return op; |
… | |
… | |
1070 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
1039 | LOG (llevError | logBacktrace, "tried to destroy the tail of an object"); |
1071 | head->destroy (); |
1040 | head->destroy (); |
1072 | return; |
1041 | return; |
1073 | } |
1042 | } |
1074 | |
1043 | |
1075 | destroy_inv (false); |
1044 | destroy_inv_fast (); |
1076 | |
1045 | |
1077 | if (is_head ()) |
1046 | if (is_head ()) |
1078 | if (sound_destroy) |
1047 | if (sound_destroy) |
1079 | play_sound (sound_destroy); |
1048 | play_sound (sound_destroy); |
1080 | else if (flag [FLAG_MONSTER]) |
1049 | else if (flag [FLAG_MONSTER]) |
… | |
… | |
1134 | below = 0; |
1103 | below = 0; |
1135 | env = 0; |
1104 | env = 0; |
1136 | |
1105 | |
1137 | if (pl && pl->is_player ()) |
1106 | if (pl && pl->is_player ()) |
1138 | { |
1107 | { |
|
|
1108 | if (expect_false (pl->contr->combat_ob == this)) |
|
|
1109 | { |
|
|
1110 | pl->apply (pl->contr->combat_ob, AP_UNAPPLY); |
|
|
1111 | pl->contr->combat_ob = 0; |
|
|
1112 | if (pl->contr->ranged_ob) pl->apply (pl->contr->ranged_ob); |
|
|
1113 | } |
|
|
1114 | |
|
|
1115 | if (expect_false (pl->contr->ranged_ob == this)) |
|
|
1116 | { |
|
|
1117 | pl->apply (pl->contr->ranged_ob, AP_UNAPPLY); |
|
|
1118 | pl->contr->ranged_ob = 0; |
|
|
1119 | if (pl->contr->combat_ob) pl->apply (pl->contr->combat_ob); |
|
|
1120 | } |
|
|
1121 | |
1139 | pl->contr->queue_stats_update (); |
1122 | pl->contr->queue_stats_update (); |
1140 | |
1123 | |
1141 | if (glow_radius && pl->is_on_map ()) |
1124 | if (expect_false (glow_radius) && pl->is_on_map ()) |
1142 | update_all_los (pl->map, pl->x, pl->y); |
1125 | update_all_los (pl->map, pl->x, pl->y); |
1143 | } |
1126 | } |
1144 | } |
1127 | } |
1145 | else if (map) |
1128 | else if (map) |
1146 | { |
1129 | { |
… | |
… | |
1316 | * Passing 0 for flag gives proper default values, so flag really only needs |
1299 | * Passing 0 for flag gives proper default values, so flag really only needs |
1317 | * to be set if special handling is needed. |
1300 | * to be set if special handling is needed. |
1318 | * |
1301 | * |
1319 | * Return value: |
1302 | * Return value: |
1320 | * new object if 'op' was merged with other object |
1303 | * new object if 'op' was merged with other object |
1321 | * NULL if 'op' was destroyed |
1304 | * NULL if there was an error (destroyed, blocked etc.) |
1322 | * just 'op' otherwise |
1305 | * just 'op' otherwise |
1323 | */ |
1306 | */ |
1324 | object * |
1307 | object * |
1325 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1308 | insert_ob_in_map (object *op, maptile *m, object *originator, int flag) |
1326 | { |
1309 | { |
… | |
… | |
2678 | |
2661 | |
2679 | insert (force); |
2662 | insert (force); |
2680 | } |
2663 | } |
2681 | } |
2664 | } |
2682 | |
2665 | |
|
|
2666 | void object::change_move_type (MoveType mt) |
|
|
2667 | { |
|
|
2668 | if (move_type == mt) |
|
|
2669 | return; |
|
|
2670 | |
|
|
2671 | if (is_on_map ()) |
|
|
2672 | { |
|
|
2673 | // we are on the map, so handle move_on/off effects |
|
|
2674 | remove (); |
|
|
2675 | move_type = mt; |
|
|
2676 | map->insert (this, x, y, this); |
|
|
2677 | } |
|
|
2678 | else |
|
|
2679 | move_type = mt; |
|
|
2680 | } |
|
|
2681 | |