… | |
… | |
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 | /* |
… | |
… | |
361 | count = tmp->nrof; |
362 | count = tmp->nrof; |
362 | |
363 | |
363 | /* container is open, so use it */ |
364 | /* container is open, so use it */ |
364 | if (tmp->flag [FLAG_STARTEQUIP]) |
365 | if (tmp->flag [FLAG_STARTEQUIP]) |
365 | alt = op; |
366 | alt = op; |
366 | else if (op->container) |
367 | else if ((alt = op->container_ ())) |
367 | { |
368 | { |
368 | alt = op->container; |
|
|
369 | if (alt != tmp->env && !sack_can_hold (op, alt, tmp, count)) |
369 | if (alt != tmp->env && !sack_can_hold (op, alt, tmp, count)) |
370 | goto leave; |
370 | goto leave; |
371 | } |
371 | } |
372 | else |
372 | else |
373 | { /* non container pickup */ |
373 | { /* non container pickup */ |
… | |
… | |
427 | int |
427 | int |
428 | command_take (object *op, char *params) |
428 | command_take (object *op, char *params) |
429 | { |
429 | { |
430 | object *tmp, *next; |
430 | object *tmp, *next; |
431 | |
431 | |
432 | if (op->container) |
432 | if (op->container_ ()) |
433 | tmp = op->container->inv; |
433 | tmp = op->container_ ()->inv; |
434 | else |
434 | else |
435 | { |
435 | { |
436 | tmp = op->above; |
436 | tmp = op->above; |
437 | if (tmp) |
437 | if (tmp) |
438 | while (tmp->above) |
438 | while (tmp->above) |
… | |
… | |
520 | char buf[MAX_BUF]; |
520 | char buf[MAX_BUF]; |
521 | |
521 | |
522 | if (sack == tmp) |
522 | if (sack == tmp) |
523 | return; /* Can't put an object in itself */ |
523 | return; /* Can't put an object in itself */ |
524 | |
524 | |
525 | if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) |
525 | if (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP)) |
526 | { |
526 | { |
527 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cannot put the %s in the %s.", query_name (tmp), query_name (sack)); |
527 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cannot put the %s in the %s.", query_name (tmp), query_name (sack)); |
528 | return; |
528 | return; |
529 | } |
529 | } |
530 | |
530 | |
… | |
… | |
539 | |
539 | |
540 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) |
540 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) |
541 | { |
541 | { |
542 | tmp = tmp2->below; |
542 | tmp = tmp2->below; |
543 | |
543 | |
544 | if ((sack->type == CONTAINER && sack_can_hold (op, op->container, tmp2, tmp2->nrof))) |
544 | if ((sack->type == CONTAINER && sack_can_hold (op, op->container_ (), tmp2, tmp2->nrof))) |
545 | put_object_in_sack (op, sack, tmp2, 0); |
545 | put_object_in_sack (op, sack, tmp2, 0); |
546 | else |
546 | else |
547 | { |
547 | { |
548 | sprintf (buf, "Your %s fills up.", query_name (sack)); |
548 | sprintf (buf, "Your %s fills up.", query_name (sack)); |
549 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
549 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
… | |
… | |
585 | return; |
585 | return; |
586 | |
586 | |
587 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
587 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
588 | if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) |
588 | if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) |
589 | return; /* can't unapply it */ |
589 | return; /* can't unapply it */ |
590 | |
|
|
591 | //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D |
|
|
592 | |
590 | |
593 | /* We are only dropping some of the items. We split the current object |
591 | /* We are only dropping some of the items. We split the current object |
594 | * off |
592 | * off |
595 | */ |
593 | */ |
596 | if (!can_split (op, tmp, nrof)) |
594 | if (!can_split (op, tmp, nrof)) |
… | |
… | |
613 | * object that was dropped. |
611 | * object that was dropped. |
614 | * |
612 | * |
615 | * Make sure to check what happened with <obj> after this function returns! |
613 | * Make sure to check what happened with <obj> after this function returns! |
616 | * Otherwise you may leak this object. |
614 | * Otherwise you may leak this object. |
617 | */ |
615 | */ |
618 | |
|
|
619 | void |
616 | void |
620 | drop_object (object *dropper, object *obj) |
617 | drop_object (object *dropper, object *obj) |
621 | { |
618 | { |
622 | if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper))) |
619 | if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper))) |
623 | return; |
620 | return; |
… | |
… | |
706 | } |
703 | } |
707 | |
704 | |
708 | if (op->type == PLAYER && op->contr->last_used == tmp) |
705 | if (op->type == PLAYER && op->contr->last_used == tmp) |
709 | op->contr->last_used = tmp->below ? tmp->below |
706 | op->contr->last_used = tmp->below ? tmp->below |
710 | : tmp->above ? tmp->above |
707 | : tmp->above ? tmp->above |
711 | : 0; |
708 | : (object *)0; |
712 | |
709 | |
713 | if (op->container) |
710 | if (op->container_ ()) |
714 | { |
711 | { |
715 | if (op->type == PLAYER) |
712 | if (op->type == PLAYER) |
716 | put_object_in_sack (op, op->container, tmp, op->contr->count); |
713 | put_object_in_sack (op, op->container_ (), tmp, op->contr->count); |
717 | else |
714 | else |
718 | put_object_in_sack (op, op->container, tmp, 0); |
715 | put_object_in_sack (op, op->container_ (), tmp, 0); |
719 | } |
716 | } |
720 | else |
717 | else |
721 | { |
718 | { |
722 | if (op->type == PLAYER) |
719 | if (op->type == PLAYER) |
723 | drop_object (op, tmp, op->contr->count); |
720 | drop_object (op, tmp, op->contr->count); |
… | |
… | |
765 | nextinv = nextinv->below; |
762 | nextinv = nextinv->below; |
766 | |
763 | |
767 | if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY && |
764 | if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY && |
768 | curinv->type != FOOD && curinv->type != KEY && |
765 | curinv->type != FOOD && curinv->type != KEY && |
769 | curinv->type != SPECIAL_KEY && curinv->type != GEM && |
766 | curinv->type != SPECIAL_KEY && curinv->type != GEM && |
770 | !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv)) |
767 | !curinv->invisible && (curinv->type != CONTAINER || op->container_ () != curinv)) |
771 | { |
768 | { |
772 | drop (op, curinv); |
769 | drop (op, curinv); |
773 | if (--cnt <= 0) break; |
770 | if (--cnt <= 0) break; |
774 | } |
771 | } |
775 | |
772 | |
… | |
… | |
1103 | examine_monster (object *op, object *tmp) |
1100 | examine_monster (object *op, object *tmp) |
1104 | { |
1101 | { |
1105 | new_draw_info (NDI_UNIQUE, 0, op, tmp->describe_monster (op).c_str ()); |
1102 | new_draw_info (NDI_UNIQUE, 0, op, tmp->describe_monster (op).c_str ()); |
1106 | } |
1103 | } |
1107 | |
1104 | |
|
|
1105 | static void |
|
|
1106 | describe_dump_object (dynbuf &buf, object *ob) |
|
|
1107 | { |
|
|
1108 | char *txt = dump_object (ob); |
|
|
1109 | for (char *p = txt; *p; ++p) if (*p == '\n') *p = '\r'; |
|
|
1110 | buf << "\n" << txt << "\n"; |
|
|
1111 | |
|
|
1112 | if (!ob->is_arch ()) |
|
|
1113 | describe_dump_object (buf, ob->arch); |
|
|
1114 | } |
|
|
1115 | |
1108 | std::string |
1116 | std::string |
1109 | object::describe (object *who) |
1117 | object::describe (object *who) |
1110 | { |
1118 | { |
1111 | dynbuf_text buf (1024, 1024); |
1119 | dynbuf_text buf (1024, 1024); |
1112 | |
1120 | |
… | |
… | |
1145 | buf.printf ("It has %d charges left.\r", stats.food); |
1153 | buf.printf ("It has %d charges left.\r", stats.food); |
1146 | break; |
1154 | break; |
1147 | } |
1155 | } |
1148 | |
1156 | |
1149 | if (materialname && !msg) |
1157 | if (materialname && !msg) |
1150 | buf.printf ("It is made of: %s.\r", &materialname); |
1158 | buf << (nrof > 1 ? "They are made of " : "It is made of ") |
|
|
1159 | << materialname |
|
|
1160 | << '\r'; |
1151 | |
1161 | |
1152 | if (who) |
1162 | if (who) |
1153 | /* Where to wear this item */ |
1163 | /* Where to wear this item */ |
1154 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1164 | for (int i = 0; i < NUM_BODY_LOCATIONS; i++) |
1155 | if (slot[i].info) |
1165 | if (slot[i].info) |
… | |
… | |
1186 | buf << "This is a buildable item.\r"; |
1196 | buf << "This is a buildable item.\r"; |
1187 | |
1197 | |
1188 | /* Does the object have a message? Don't show message for all object |
1198 | /* Does the object have a message? Don't show message for all object |
1189 | * types - especially if the first entry is a match |
1199 | * types - especially if the first entry is a match |
1190 | */ |
1200 | */ |
|
|
1201 | if (msg) |
|
|
1202 | { |
1191 | if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) |
1203 | if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) |
1192 | { |
1204 | { |
|
|
1205 | buf << '\r'; |
|
|
1206 | |
1193 | /* This is just a hack so when identifying the items, we print |
1207 | /* This is just a hack so when identifying the items, we print |
1194 | * out the extra message |
1208 | * out the extra message |
1195 | */ |
1209 | */ |
1196 | if (need_identify (this) && flag [FLAG_IDENTIFIED]) |
1210 | if (need_identify (this) && flag [FLAG_IDENTIFIED]) |
1197 | buf << "The object has a story:\r"; |
1211 | buf << "The object has a story:\r"; |
1198 | |
1212 | |
1199 | buf << msg << '\n'; |
1213 | buf << msg << '\n'; |
|
|
1214 | } |
|
|
1215 | } |
|
|
1216 | else if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED] |
|
|
1217 | && (type == SPELLBOOK || type == ROD || type == WAND |
|
|
1218 | || type == ROD || type == POTION || type == SCROLL)) |
|
|
1219 | // for spellbooks and other stuff that contains spells, print the spell message, |
|
|
1220 | // unless the object has a custom message handled above. |
|
|
1221 | buf << '\r' << inv->msg << '\n'; |
|
|
1222 | |
|
|
1223 | // try to display the duration for some potions and scrolls |
|
|
1224 | // this includes change ability potions and group spells, |
|
|
1225 | // but does not handle protection potions |
|
|
1226 | if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED] |
|
|
1227 | && (type == POTION || type == SCROLL)) |
|
|
1228 | { |
|
|
1229 | object *spell = inv; |
|
|
1230 | |
|
|
1231 | if (spell->subtype == SP_PARTY_SPELL) |
|
|
1232 | spell = spell->other_arch; |
|
|
1233 | |
|
|
1234 | if (spell->subtype == SP_CHANGE_ABILITY) |
|
|
1235 | buf.printf ("\nH<The effect will last about %.10g seconds.>", |
|
|
1236 | TICK2TIME (change_ability_duration (spell, this))); |
|
|
1237 | } |
|
|
1238 | |
|
|
1239 | // Display a hint about inscribable items [empty books] |
|
|
1240 | // This includes the amount of text they can hold. |
|
|
1241 | if (type == INSCRIBABLE) |
|
|
1242 | { |
|
|
1243 | if (other_arch && other_arch->type == SCROLL) |
|
|
1244 | buf.printf ("\nH<You can use the inscription skill to inscribe a spell into it.>"); |
|
|
1245 | else |
|
|
1246 | buf.printf ("\nH<You can use the inscription skill to inscribe text into it. It has room for up to %d characters.>", |
|
|
1247 | weight_limit); |
1200 | } |
1248 | } |
1201 | |
1249 | |
1202 | buf << '\n'; |
1250 | buf << '\n'; |
|
|
1251 | |
|
|
1252 | // the dungeon master additionally gets a complete dump |
|
|
1253 | if (who && who->flag [FLAG_WIZLOOK]) |
|
|
1254 | { |
|
|
1255 | buf << "\nT<Object>\n"; |
|
|
1256 | describe_dump_object (buf, this); |
|
|
1257 | |
|
|
1258 | if (inv) |
|
|
1259 | { |
|
|
1260 | buf << "\nT<Top Inventory>\n"; |
|
|
1261 | describe_dump_object (buf, inv); |
|
|
1262 | } |
|
|
1263 | } |
1203 | |
1264 | |
1204 | return std::string (buf.linearise (), buf.size ()); |
1265 | return std::string (buf.linearise (), buf.size ()); |
1205 | } |
1266 | } |
1206 | |
1267 | |
1207 | static void |
1268 | static void |