… | |
… | |
520 | |
520 | |
521 | return 0; |
521 | return 0; |
522 | } |
522 | } |
523 | |
523 | |
524 | /* |
524 | /* |
525 | * This function was part of drop, now is own function. |
525 | * This function was part of drop, now is own function. |
526 | * Player 'op' tries to put object 'tmp' into sack 'sack', |
526 | * Player 'op' tries to put object 'tmp' into sack 'sack', |
527 | * if nrof is non zero, then nrof objects is tried to put into sack. |
527 | * if nrof is non zero, then nrof objects is tried to put into sack. |
|
|
528 | * |
528 | * Note that the 'sack' in question can now be a transport, |
529 | * Note that the 'sack' in question can now be a transport, |
529 | * so this function isn't named very good anymore. |
530 | * so this function isn't named very good anymore. |
530 | */ |
531 | */ |
531 | void |
532 | void |
532 | put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof) |
533 | put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof) |
… | |
… | |
607 | |
608 | |
608 | /* We are only dropping some of the items. We split the current object |
609 | /* We are only dropping some of the items. We split the current object |
609 | * off |
610 | * off |
610 | */ |
611 | */ |
611 | if (!can_split (op, tmp, nrof)) |
612 | if (!can_split (op, tmp, nrof)) |
612 | |
|
|
613 | if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op))) |
|
|
614 | return; |
613 | return; |
615 | |
614 | |
|
|
615 | drop_object (op, tmp); |
|
|
616 | |
|
|
617 | if (!tmp->destroyed () && !tmp->is_inserted ()) |
|
|
618 | { |
|
|
619 | // if nothing happened with the object we give it back |
|
|
620 | op->insert (tmp); |
|
|
621 | } |
|
|
622 | } |
|
|
623 | |
|
|
624 | /* In contrast to drop_object (op, tmp, nrof) above this function takes the |
|
|
625 | * already split off object, and feeds it to the event handlers and does |
|
|
626 | * other magic with it. |
|
|
627 | * |
|
|
628 | * <droppper> is the object that dropped this object and <obj> is the |
|
|
629 | * object that was dropped. |
|
|
630 | * |
|
|
631 | * Make sure to check what happened with <obj> after this function returns! |
|
|
632 | * Otherwise you may leak this object. |
|
|
633 | */ |
|
|
634 | |
|
|
635 | void |
|
|
636 | drop_object (object *dropper, object *obj) |
|
|
637 | { |
|
|
638 | if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper))) |
|
|
639 | return; |
|
|
640 | |
|
|
641 | if (obj->destroyed () || obj->is_inserted ()) |
|
|
642 | return; |
|
|
643 | |
616 | if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) |
644 | if (QUERY_FLAG (obj, FLAG_STARTEQUIP)) |
617 | { |
645 | { |
618 | op->statusmsg (format ("You drop the %s.", query_name (tmp))); |
646 | dropper->statusmsg (format ("You drop the %s.", query_name (obj))); |
619 | op->statusmsg ("The gods who lent it to you retrieves it."); |
647 | dropper->statusmsg ("The god who lent it to you retrieves it."); |
620 | |
648 | |
621 | tmp->destroy (); |
649 | obj->destroy (); |
622 | op->update_stats (); |
650 | dropper->update_stats (); |
623 | return; |
651 | return; |
624 | } |
652 | } |
625 | |
653 | |
626 | /* Call this before we update the various windows/players. At least |
654 | for (object *floor = GET_MAP_OB (dropper->map, dropper->x, dropper->y); |
627 | * that we, we know the weight is correct. |
655 | floor; |
|
|
656 | floor = floor->above) |
|
|
657 | if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (obj), ARG_OBJECT (dropper))) |
|
|
658 | return; |
|
|
659 | |
|
|
660 | if (obj->destroyed () || obj->is_inserted ()) |
|
|
661 | return; |
|
|
662 | |
|
|
663 | if (is_in_shop (dropper) && !QUERY_FLAG (obj, FLAG_UNPAID) && obj->type != MONEY) |
|
|
664 | if (!sell_item (obj, dropper)) |
|
|
665 | return; |
|
|
666 | |
|
|
667 | /* If nothing special happened with this object, the default action is to |
|
|
668 | * insert it below the dropper: |
628 | */ |
669 | */ |
629 | // 2007-11-26: moved op->update_stats away and calling it later after |
|
|
630 | // all items of a drop command have been processed. |
|
|
631 | |
670 | |
632 | for (object *floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above) |
671 | obj->x = dropper->x; |
633 | if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) |
672 | obj->y = dropper->y; |
634 | return; |
|
|
635 | |
673 | |
636 | if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY) |
|
|
637 | { |
|
|
638 | if (!sell_item (tmp, op)) |
|
|
639 | return; // if we can't sell it we don't drop it |
|
|
640 | } |
|
|
641 | |
|
|
642 | tmp->x = op->x; |
|
|
643 | tmp->y = op->y; |
|
|
644 | |
|
|
645 | insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); |
674 | insert_ob_in_map (obj, dropper->map, dropper, INS_BELOW_ORIGINATOR); |
646 | } |
675 | } |
647 | |
676 | |
648 | void |
677 | void |
649 | drop (object *op, object *tmp) |
678 | drop (object *op, object *tmp) |
650 | { |
679 | { |
… | |
… | |
659 | if (tmp->env && tmp->env->type != PLAYER) |
688 | if (tmp->env && tmp->env->type != PLAYER) |
660 | { |
689 | { |
661 | /* Just toss the object - probably shouldn't be hanging |
690 | /* Just toss the object - probably shouldn't be hanging |
662 | * around anyways |
691 | * around anyways |
663 | */ |
692 | */ |
664 | tmp->remove (); |
|
|
665 | tmp->destroy (); |
693 | tmp->destroy (); |
666 | return; |
694 | return; |
667 | } |
695 | } |
668 | else |
696 | else |
669 | { |
697 | { |
… | |
… | |
849 | |
877 | |
850 | /* draw_look(op);*/ |
878 | /* draw_look(op);*/ |
851 | return 0; |
879 | return 0; |
852 | } |
880 | } |
853 | |
881 | |
|
|
882 | |
|
|
883 | /* This function tries to drop all objects in the <objs> vector. |
|
|
884 | * <dropper> is the object that wants to drop them. |
|
|
885 | * <cnt> can be a 0 pointer or a pointer to the maximum number of |
|
|
886 | * drop operations to perform. |
|
|
887 | * |
|
|
888 | * Returns true if at least one item was dropped. |
|
|
889 | */ |
|
|
890 | bool |
|
|
891 | drop_vector (object *dropper, vector<object *> &objs, int *cnt) |
|
|
892 | { |
|
|
893 | vector<object *>::iterator i; |
|
|
894 | |
|
|
895 | bool did_one = false; |
|
|
896 | |
|
|
897 | for (i = objs.begin (); i != objs.end (); i++) |
|
|
898 | { |
|
|
899 | drop (dropper, *i); |
|
|
900 | if (cnt && --*cnt <= 0) break; |
|
|
901 | did_one = true; |
|
|
902 | } |
|
|
903 | |
|
|
904 | return did_one; |
|
|
905 | } |
|
|
906 | |
854 | /* Object op wants to drop object(s) params. params can be a |
907 | /* Object op wants to drop object(s) params. params can be a |
855 | * comma seperated list. |
908 | * comma seperated list. |
856 | */ |
909 | */ |
857 | int |
910 | int |
858 | command_drop (object *op, char *params) |
911 | command_drop (object *op, char *params) |
… | |
… | |
865 | new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); |
918 | new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); |
866 | return 0; |
919 | return 0; |
867 | } |
920 | } |
868 | else |
921 | else |
869 | { |
922 | { |
870 | int cnt = MAX_ITEM_PER_DROP; |
923 | vector<object *> matched_objs; |
871 | |
924 | |
872 | for (tmp = op->inv; tmp; tmp = next) |
925 | for (tmp = op->inv; tmp; tmp = next) |
873 | { |
926 | { |
874 | next = tmp->below; |
927 | next = tmp->below; |
875 | if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) |
928 | if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) |
876 | continue; |
929 | continue; |
877 | |
930 | |
878 | if (item_matched_string (op, tmp, params)) |
931 | if (item_matched_string (op, tmp, params)) |
879 | { |
932 | matched_objs.push_back (tmp); |
880 | drop (op, tmp); |
|
|
881 | if (--cnt <= 0) break; |
|
|
882 | did_one = 1; |
|
|
883 | } |
933 | } |
884 | } |
|
|
885 | |
934 | |
886 | if (!did_one) |
935 | int cnt = MAX_ITEM_PER_DROP; |
|
|
936 | |
|
|
937 | if (!drop_vector (op, matched_objs, &cnt)) |
887 | new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); |
938 | new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); |
888 | |
939 | |
889 | if (cnt <= 0) |
940 | if (cnt <= 0) |
890 | op->failmsg ("Only dropped some items, can't drop that many items at once."); |
941 | op->failmsg ("Only dropped some items, can't drop that many items at once."); |
891 | } |
942 | } |
… | |
… | |
970 | dynbuf_text buf (512, 512); |
1021 | dynbuf_text buf (512, 512); |
971 | |
1022 | |
972 | object *mon = head ? head : this; |
1023 | object *mon = head ? head : this; |
973 | |
1024 | |
974 | if (QUERY_FLAG (mon, FLAG_UNDEAD)) |
1025 | if (QUERY_FLAG (mon, FLAG_UNDEAD)) |
975 | buf << " - It is an undead force.\n"; |
1026 | buf << "It is an undead force.\r"; |
976 | |
1027 | |
977 | if (mon->level > who->level) |
1028 | if (mon->level > who->level) |
978 | buf << " - It is likely more powerful than you.\n"; |
1029 | buf << "It is likely more powerful than you.\r"; |
979 | else if (mon->level < who->level) |
1030 | else if (mon->level < who->level) |
980 | buf << " - It is likely less powerful than you.\n"; |
1031 | buf << "It is likely less powerful than you.\r"; |
981 | else |
1032 | else |
982 | buf << " - It is probably as powerful as you.\n"; |
1033 | buf << "It is probably as powerful as you.\r"; |
983 | |
1034 | |
984 | if (mon->attacktype & AT_ACID) |
1035 | if (mon->attacktype & AT_ACID) |
985 | buf << " - You seem to smell an acrid odor.\n"; |
1036 | buf << "You seem to smell an acrid odor.\r"; |
986 | |
1037 | |
987 | /* Anyone know why this used to use the clone value instead of the |
1038 | /* Anyone know why this used to use the clone value instead of the |
988 | * maxhp field? This seems that it should give more accurate results. |
1039 | * maxhp field? This seems that it should give more accurate results. |
989 | */ |
1040 | */ |
990 | switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) |
1041 | switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) |
991 | { /* From 1-4 */ |
1042 | { /* From 1-4 */ |
992 | case 1: |
1043 | case 1: |
993 | buf << " - It is in a bad shape.\n"; |
1044 | buf << "It is in a bad shape.\r"; |
994 | break; |
1045 | break; |
995 | case 2: |
1046 | case 2: |
996 | buf << " - It is hurt.\n"; |
1047 | buf << "It is hurt.\r"; |
997 | break; |
1048 | break; |
998 | case 3: |
1049 | case 3: |
999 | buf << " - It is somewhat hurt.\n"; |
1050 | buf << "It is somewhat hurt.\r"; |
1000 | break; |
1051 | break; |
1001 | case 4: |
1052 | case 4: |
1002 | buf << " - It is in excellent shape.\n"; |
1053 | buf << "It is in excellent shape.\r"; |
1003 | break; |
1054 | break; |
1004 | } |
1055 | } |
1005 | |
1056 | |
1006 | if (present_in_ob (POISONING, mon)) |
1057 | if (present_in_ob (POISONING, mon)) |
1007 | buf << " - It looks very ill.\n"; |
1058 | buf << "It looks very ill.\r"; |
|
|
1059 | |
|
|
1060 | buf << '\n'; |
1008 | |
1061 | |
1009 | return buf; |
1062 | return buf; |
1010 | } |
1063 | } |
1011 | |
1064 | |
1012 | /* tmp is the object being described, pl is who is examing it. */ |
1065 | /* tmp is the object being described, pl is who is examing it. */ |
… | |
… | |
1070 | std::string |
1123 | std::string |
1071 | object::describe (object *who) |
1124 | object::describe (object *who) |
1072 | { |
1125 | { |
1073 | dynbuf_text buf (1024, 1024); |
1126 | dynbuf_text buf (1024, 1024); |
1074 | |
1127 | |
1075 | buf.printf ("That is: %s.\n\n", long_desc (who).c_str ()); |
1128 | buf.printf ("That is: %s.\r", long_desc (who).c_str ()); |
1076 | |
1129 | |
1077 | if (custom_name) |
1130 | if (custom_name) |
1078 | buf.printf ("You call it %s.\n\n", &custom_name); |
1131 | buf.printf ("You call it %s.\r", &custom_name); |
1079 | |
1132 | |
1080 | switch (type) |
1133 | switch (type) |
1081 | { |
1134 | { |
1082 | case SPELLBOOK: |
1135 | case SPELLBOOK: |
1083 | if (flag [FLAG_IDENTIFIED] && inv) |
1136 | if (flag [FLAG_IDENTIFIED] && inv) |
1084 | buf.printf ("%s is a %s %s spell.\n", &inv->name, get_levelnumber (inv->level), &inv->skill); |
1137 | buf.printf ("%s is a %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill); |
1085 | break; |
1138 | break; |
1086 | |
1139 | |
1087 | case BOOK: |
1140 | case BOOK: |
1088 | if (msg) |
1141 | if (msg) |
1089 | buf << "Something is written in it.\n"; |
1142 | buf << "Something is written in it.\r"; |
1090 | break; |
1143 | break; |
1091 | |
1144 | |
1092 | case CONTAINER: |
1145 | case CONTAINER: |
1093 | if (race != NULL) |
1146 | if (race) |
1094 | { |
1147 | { |
1095 | if (weight_limit && stats.Str < 100) |
1148 | if (weight_limit && stats.Str < 100) |
1096 | buf.printf ("It can hold only %s and its weight limit is %.1f kg.\n", |
1149 | buf.printf ("It can hold only %s and its weight limit is %.1f kg.\r", |
1097 | &race, weight_limit / (10.0 * (100 - stats.Str))); |
1150 | &race, weight_limit / (10.0 * (100 - stats.Str))); |
1098 | else |
1151 | else |
1099 | buf.printf ("It can hold only %s.\n", &race); |
1152 | buf.printf ("It can hold only %s.\r", &race); |
1100 | } |
1153 | } |
1101 | else if (weight_limit && stats.Str < 100) |
1154 | else if (weight_limit && stats.Str < 100) |
1102 | buf.printf ("Its weight limit is %.1f kg.\n", weight_limit / (10.0 * (100 - stats.Str))); |
1155 | buf.printf ("Its weight limit is %.1f kg.\r", weight_limit / (10.0 * (100 - stats.Str))); |
1103 | break; |
1156 | break; |
1104 | |
1157 | |
1105 | case WAND: |
1158 | case WAND: |
1106 | if (flag [FLAG_IDENTIFIED]) |
1159 | if (flag [FLAG_IDENTIFIED]) |
1107 | buf.printf ("It has %d charges left.\n", stats.food); |
1160 | buf.printf ("It has %d charges left.\r", stats.food); |
1108 | break; |
1161 | break; |
1109 | } |
1162 | } |
1110 | |
1163 | |
1111 | if (materialname && !msg) |
1164 | if (materialname && !msg) |
1112 | buf.printf ("It is made of: %s.\n", &materialname); |
1165 | buf.printf ("It is made of: %s.\r", &materialname); |
1113 | |
1166 | |
1114 | if (who) |
1167 | if (who) |
1115 | /* Where to wear this item */ |
1168 | /* Where to wear this item */ |
1116 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1169 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1117 | if (slot[i].info) |
1170 | if (slot[i].info) |
… | |
… | |
1119 | buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name); |
1172 | buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name); |
1120 | |
1173 | |
1121 | if (slot[i].info < -1 && who->slot[i].info) |
1174 | if (slot[i].info < -1 && who->slot[i].info) |
1122 | buf.printf ("(%d)", -slot[i].info); |
1175 | buf.printf ("(%d)", -slot[i].info); |
1123 | |
1176 | |
1124 | buf << ".\n"; |
1177 | buf << ".\r"; |
1125 | } |
1178 | } |
1126 | |
1179 | |
1127 | if (weight) |
1180 | if (weight) |
1128 | buf.printf (nrof > 1 ? "They weigh %3.3f kg.\n" : "It weighs %3.3f kg.\n", weight * (nrof ? nrof : 1) / 1000.0); |
1181 | buf.printf ("%s %3.3f kg.\r", nrof > 1 ? "They weigh" : "It weighs", weight * (nrof ? nrof : 1) / 1000.0); |
1129 | |
1182 | |
1130 | if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who) |
1183 | if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who) |
1131 | { |
1184 | { |
1132 | buf.printf ("You reckon %s worth %s.\n", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX)); |
1185 | buf.printf ("You reckon %s worth %s.\r", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX)); |
1133 | |
1186 | |
1134 | if (is_in_shop (who)) |
1187 | if (is_in_shop (who)) |
1135 | { |
1188 | { |
1136 | if (flag [FLAG_UNPAID]) |
1189 | if (flag [FLAG_UNPAID]) |
1137 | buf.printf ("%s would cost you %s.\n", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP)); |
1190 | buf.printf ("%s would cost you %s.\r", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP)); |
1138 | else |
1191 | else |
1139 | buf.printf ("You are offered %s for %s.\n", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it"); |
1192 | buf.printf ("You are offered %s for %s.\r", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it"); |
1140 | } |
1193 | } |
1141 | } |
1194 | } |
1142 | |
1195 | |
1143 | if (flag [FLAG_MONSTER]) |
1196 | if (flag [FLAG_MONSTER]) |
1144 | buf << describe_monster (who); |
1197 | buf << describe_monster (who); |
1145 | |
1198 | |
1146 | /* Is this item buildable? */ |
1199 | /* Is this item buildable? */ |
1147 | if (flag [FLAG_IS_BUILDABLE]) |
1200 | if (flag [FLAG_IS_BUILDABLE]) |
1148 | buf << "This is a buildable item.\n"; |
1201 | buf << "This is a buildable item.\r"; |
1149 | |
1202 | |
1150 | /* Does the object have a message? Don't show message for all object |
1203 | /* Does the object have a message? Don't show message for all object |
1151 | * types - especially if the first entry is a match |
1204 | * types - especially if the first entry is a match |
1152 | */ |
1205 | */ |
1153 | if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) |
1206 | if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) |
1154 | { |
1207 | { |
1155 | /* This is just a hack so when identifying the items, we print |
1208 | /* This is just a hack so when identifying the items, we print |
1156 | * out the extra message |
1209 | * out the extra message |
1157 | */ |
1210 | */ |
1158 | if (need_identify (this) && flag [FLAG_IDENTIFIED]) |
1211 | if (need_identify (this) && flag [FLAG_IDENTIFIED]) |
1159 | buf << "The object has a story:\n\n"; |
1212 | buf << "The object has a story:\r"; |
1160 | |
1213 | |
1161 | buf << msg << '\n'; |
1214 | buf << msg << '\n'; |
1162 | } |
1215 | } |
1163 | |
1216 | |
1164 | buf << '\n'; |
1217 | buf << '\n'; |