… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* |
25 | /* |
… | |
… | |
28 | #include <global.h> |
29 | #include <global.h> |
29 | #include <loader.h> |
30 | #include <loader.h> |
30 | #include <skills.h> |
31 | #include <skills.h> |
31 | #include <sproto.h> |
32 | #include <sproto.h> |
32 | #include <living.h> |
33 | #include <living.h> |
33 | #include <math.h> |
|
|
34 | |
34 | |
35 | /* |
35 | /* |
36 | * Object id parsing functions |
36 | * Object id parsing functions |
37 | */ |
37 | */ |
38 | |
38 | |
… | |
… | |
361 | count = tmp->nrof; |
361 | count = tmp->nrof; |
362 | |
362 | |
363 | /* container is open, so use it */ |
363 | /* container is open, so use it */ |
364 | if (tmp->flag [FLAG_STARTEQUIP]) |
364 | if (tmp->flag [FLAG_STARTEQUIP]) |
365 | alt = op; |
365 | alt = op; |
366 | else if (op->container) |
366 | else if ((alt = op->container_ ())) |
367 | { |
367 | { |
368 | alt = op->container; |
|
|
369 | if (alt != tmp->env && !sack_can_hold (op, alt, tmp, count)) |
368 | if (alt != tmp->env && !sack_can_hold (op, alt, tmp, count)) |
370 | goto leave; |
369 | goto leave; |
371 | } |
370 | } |
372 | else |
371 | else |
373 | { /* non container pickup */ |
372 | { /* non container pickup */ |
… | |
… | |
427 | int |
426 | int |
428 | command_take (object *op, char *params) |
427 | command_take (object *op, char *params) |
429 | { |
428 | { |
430 | object *tmp, *next; |
429 | object *tmp, *next; |
431 | |
430 | |
432 | if (op->container) |
431 | if (op->container_ ()) |
433 | tmp = op->container->inv; |
432 | tmp = op->container_ ()->inv; |
434 | else |
433 | else |
435 | { |
434 | { |
436 | tmp = op->above; |
435 | tmp = op->above; |
437 | if (tmp) |
436 | if (tmp) |
438 | while (tmp->above) |
437 | while (tmp->above) |
… | |
… | |
520 | char buf[MAX_BUF]; |
519 | char buf[MAX_BUF]; |
521 | |
520 | |
522 | if (sack == tmp) |
521 | if (sack == tmp) |
523 | return; /* Can't put an object in itself */ |
522 | return; /* Can't put an object in itself */ |
524 | |
523 | |
525 | if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) |
524 | if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP)) |
526 | { |
525 | { |
527 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cannot put the %s in the %s.", query_name (tmp), query_name (sack)); |
526 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cannot put the %s in the %s.", query_name (tmp), query_name (sack)); |
528 | return; |
527 | return; |
529 | } |
528 | } |
530 | |
529 | |
… | |
… | |
539 | |
538 | |
540 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) |
539 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) |
541 | { |
540 | { |
542 | tmp = tmp2->below; |
541 | tmp = tmp2->below; |
543 | |
542 | |
544 | if ((sack->type == CONTAINER && sack_can_hold (op, op->container, tmp2, tmp2->nrof))) |
543 | if ((sack->type == CONTAINER && sack_can_hold (op, op->container_ (), tmp2, tmp2->nrof))) |
545 | put_object_in_sack (op, sack, tmp2, 0); |
544 | put_object_in_sack (op, sack, tmp2, 0); |
546 | else |
545 | else |
547 | { |
546 | { |
548 | sprintf (buf, "Your %s fills up.", query_name (sack)); |
547 | sprintf (buf, "Your %s fills up.", query_name (sack)); |
549 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
548 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
… | |
… | |
585 | return; |
584 | return; |
586 | |
585 | |
587 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
586 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
588 | if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) |
587 | if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) |
589 | return; /* can't unapply it */ |
588 | return; /* can't unapply it */ |
590 | |
|
|
591 | //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D |
|
|
592 | |
589 | |
593 | /* We are only dropping some of the items. We split the current object |
590 | /* We are only dropping some of the items. We split the current object |
594 | * off |
591 | * off |
595 | */ |
592 | */ |
596 | if (!can_split (op, tmp, nrof)) |
593 | if (!can_split (op, tmp, nrof)) |
… | |
… | |
613 | * object that was dropped. |
610 | * object that was dropped. |
614 | * |
611 | * |
615 | * Make sure to check what happened with <obj> after this function returns! |
612 | * Make sure to check what happened with <obj> after this function returns! |
616 | * Otherwise you may leak this object. |
613 | * Otherwise you may leak this object. |
617 | */ |
614 | */ |
618 | |
|
|
619 | void |
615 | void |
620 | drop_object (object *dropper, object *obj) |
616 | drop_object (object *dropper, object *obj) |
621 | { |
617 | { |
622 | if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper))) |
618 | if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper))) |
623 | return; |
619 | return; |
… | |
… | |
706 | } |
702 | } |
707 | |
703 | |
708 | if (op->type == PLAYER && op->contr->last_used == tmp) |
704 | if (op->type == PLAYER && op->contr->last_used == tmp) |
709 | op->contr->last_used = tmp->below ? tmp->below |
705 | op->contr->last_used = tmp->below ? tmp->below |
710 | : tmp->above ? tmp->above |
706 | : tmp->above ? tmp->above |
711 | : 0; |
707 | : (object *)0; |
712 | |
708 | |
713 | if (op->container) |
709 | if (op->container_ ()) |
714 | { |
710 | { |
715 | if (op->type == PLAYER) |
711 | if (op->type == PLAYER) |
716 | put_object_in_sack (op, op->container, tmp, op->contr->count); |
712 | put_object_in_sack (op, op->container_ (), tmp, op->contr->count); |
717 | else |
713 | else |
718 | put_object_in_sack (op, op->container, tmp, 0); |
714 | put_object_in_sack (op, op->container_ (), tmp, 0); |
719 | } |
715 | } |
720 | else |
716 | else |
721 | { |
717 | { |
722 | if (op->type == PLAYER) |
718 | if (op->type == PLAYER) |
723 | drop_object (op, tmp, op->contr->count); |
719 | drop_object (op, tmp, op->contr->count); |
… | |
… | |
765 | nextinv = nextinv->below; |
761 | nextinv = nextinv->below; |
766 | |
762 | |
767 | if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY && |
763 | if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY && |
768 | curinv->type != FOOD && curinv->type != KEY && |
764 | curinv->type != FOOD && curinv->type != KEY && |
769 | curinv->type != SPECIAL_KEY && curinv->type != GEM && |
765 | curinv->type != SPECIAL_KEY && curinv->type != GEM && |
770 | !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv)) |
766 | !curinv->invisible && (curinv->type != CONTAINER || op->container_ () != curinv)) |
771 | { |
767 | { |
772 | drop (op, curinv); |
768 | drop (op, curinv); |
773 | if (--cnt <= 0) break; |
769 | if (--cnt <= 0) break; |
774 | } |
770 | } |
775 | |
771 | |
… | |
… | |
869 | * <cnt> can be a 0 pointer or a pointer to the maximum number of |
865 | * <cnt> can be a 0 pointer or a pointer to the maximum number of |
870 | * drop operations to perform. |
866 | * drop operations to perform. |
871 | * |
867 | * |
872 | * Returns true if at least one item was dropped. |
868 | * Returns true if at least one item was dropped. |
873 | */ |
869 | */ |
874 | bool |
870 | static bool |
875 | drop_vector (object *dropper, vector<object *> &objs, int *cnt) |
871 | drop_vector (object *dropper, vector<object *> &objs, int *cnt) |
876 | { |
872 | { |
877 | vector<object *>::iterator i; |
873 | vector<object *>::iterator i; |
878 | |
874 | |
879 | bool did_one = false; |
875 | bool did_one = false; |
… | |
… | |
1103 | examine_monster (object *op, object *tmp) |
1099 | examine_monster (object *op, object *tmp) |
1104 | { |
1100 | { |
1105 | new_draw_info (NDI_UNIQUE, 0, op, tmp->describe_monster (op).c_str ()); |
1101 | new_draw_info (NDI_UNIQUE, 0, op, tmp->describe_monster (op).c_str ()); |
1106 | } |
1102 | } |
1107 | |
1103 | |
|
|
1104 | static void |
|
|
1105 | describe_dump_object (dynbuf &buf, object *ob) |
|
|
1106 | { |
|
|
1107 | char *txt = dump_object (ob); |
|
|
1108 | for (char *p = txt; *p; ++p) if (*p == '\n') *p = '\r'; |
|
|
1109 | buf << "\n" << txt << "\n"; |
|
|
1110 | |
|
|
1111 | if (!ob->is_arch ()) |
|
|
1112 | describe_dump_object (buf, ob->arch); |
|
|
1113 | } |
|
|
1114 | |
1108 | std::string |
1115 | std::string |
1109 | object::describe (object *who) |
1116 | object::describe (object *who) |
1110 | { |
1117 | { |
1111 | dynbuf_text buf (1024, 1024); |
1118 | dynbuf_text buf (1024, 1024); |
1112 | |
1119 | |
… | |
… | |
1145 | buf.printf ("It has %d charges left.\r", stats.food); |
1152 | buf.printf ("It has %d charges left.\r", stats.food); |
1146 | break; |
1153 | break; |
1147 | } |
1154 | } |
1148 | |
1155 | |
1149 | if (materialname && !msg) |
1156 | if (materialname && !msg) |
1150 | buf.printf ("It is made of: %s.\r", &materialname); |
1157 | buf << (nrof > 1 ? "They are made of " : "It is made of ") |
|
|
1158 | << materialname |
|
|
1159 | << '\r'; |
1151 | |
1160 | |
1152 | if (who) |
1161 | if (who) |
1153 | /* Where to wear this item */ |
1162 | /* Where to wear this item */ |
1154 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1163 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1155 | if (slot[i].info) |
1164 | if (slot[i].info) |
… | |
… | |
1186 | buf << "This is a buildable item.\r"; |
1195 | buf << "This is a buildable item.\r"; |
1187 | |
1196 | |
1188 | /* Does the object have a message? Don't show message for all object |
1197 | /* Does the object have a message? Don't show message for all object |
1189 | * types - especially if the first entry is a match |
1198 | * types - especially if the first entry is a match |
1190 | */ |
1199 | */ |
|
|
1200 | if (msg) |
|
|
1201 | { |
1191 | if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) |
1202 | if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) |
1192 | { |
1203 | { |
|
|
1204 | buf << '\r'; |
|
|
1205 | |
1193 | /* This is just a hack so when identifying the items, we print |
1206 | /* This is just a hack so when identifying the items, we print |
1194 | * out the extra message |
1207 | * out the extra message |
1195 | */ |
1208 | */ |
1196 | if (need_identify (this) && flag [FLAG_IDENTIFIED]) |
1209 | if (need_identify (this) && flag [FLAG_IDENTIFIED]) |
1197 | buf << "The object has a story:\r"; |
1210 | buf << "The object has a story:\r"; |
1198 | |
1211 | |
1199 | buf << msg << '\n'; |
1212 | buf << msg << '\n'; |
|
|
1213 | } |
|
|
1214 | } |
|
|
1215 | else if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED] |
|
|
1216 | && (type == SPELLBOOK || type == ROD || type == WAND |
|
|
1217 | || type == ROD || type == POTION || type == SCROLL)) |
|
|
1218 | // for spellbooks and other stuff that contains spells, print the spell message, |
|
|
1219 | // unless the object has a custom message handled above. |
|
|
1220 | buf << '\r' << inv->msg << '\n'; |
|
|
1221 | |
|
|
1222 | // try to display the duration for some potions and scrolls |
|
|
1223 | // this includes change ability potions and group spells, |
|
|
1224 | // but does not handle protection potions |
|
|
1225 | if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED] |
|
|
1226 | && (type == POTION || type == SCROLL)) |
|
|
1227 | { |
|
|
1228 | object *spell = inv; |
|
|
1229 | |
|
|
1230 | if (spell->subtype == SP_PARTY_SPELL) |
|
|
1231 | spell = spell->other_arch; |
|
|
1232 | |
|
|
1233 | if (spell->subtype == SP_CHANGE_ABILITY) |
|
|
1234 | buf.printf ("\nH<The effect will last about %.10g seconds.>", |
|
|
1235 | TICK2TIME (change_ability_duration (spell, this))); |
|
|
1236 | } |
|
|
1237 | |
|
|
1238 | // Display a hint about inscribable items [empty books] |
|
|
1239 | // This includes the amount of text they can hold. |
|
|
1240 | if (type == INSCRIBABLE) |
|
|
1241 | { |
|
|
1242 | if (other_arch && other_arch->type == SCROLL) |
|
|
1243 | buf.printf ("\nH<You can use the inscription skill to inscribe a spell into it.>"); |
|
|
1244 | else |
|
|
1245 | buf.printf ("\nH<You can use the inscription skill to inscribe text into it. It has room for up to %d characters.>", |
|
|
1246 | weight_limit); |
1200 | } |
1247 | } |
1201 | |
1248 | |
1202 | buf << '\n'; |
1249 | buf << '\n'; |
|
|
1250 | |
|
|
1251 | // the dungeon master additionally gets a complete dump |
|
|
1252 | if (who && who->flag [FLAG_WIZLOOK]) |
|
|
1253 | { |
|
|
1254 | buf << "\nT<Object>\n"; |
|
|
1255 | describe_dump_object (buf, this); |
|
|
1256 | |
|
|
1257 | if (inv) |
|
|
1258 | { |
|
|
1259 | buf << "\nT<Top Inventory>\n"; |
|
|
1260 | describe_dump_object (buf, inv); |
|
|
1261 | } |
|
|
1262 | } |
1203 | |
1263 | |
1204 | return std::string (buf.linearise (), buf.size ()); |
1264 | return std::string (buf.linearise (), buf.size ()); |
1205 | } |
1265 | } |
1206 | |
1266 | |
1207 | static void |
1267 | static void |