ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_object.C
(Generate patch)

Comparing deliantra/server/server/c_object.C (file contents):
Revision 1.54 by root, Thu May 17 20:27:01 2007 UTC vs.
Revision 1.89 by elmex, Mon Jan 12 00:17:23 2009 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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 GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The author can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 *
24 */ 22 */
25 23
26/* 24/*
27 * Object (handling) commands 25 * Object (handling) commands
28 */ 26 */
93find_best_object_match (object *pl, const char *params) 91find_best_object_match (object *pl, const char *params)
94{ 92{
95 return find_best_apply_object_match (pl, params, AP_TOGGLE); 93 return find_best_apply_object_match (pl, params, AP_TOGGLE);
96} 94}
97 95
96static bool
97can_split (object *pl, object *&op, sint32 nrof)
98{
99 if (object *tmp = op->split (nrof ? nrof : op->number_of ()))
100 {
101 op = tmp;
102 return true;
103 }
104 else
105 {
106 if (op->nrof > 1)
107 new_draw_info_format (NDI_UNIQUE, 0, pl, "There are only %d %s.", op->nrof, &op->name_pl);
108 else
109 new_draw_info_format (NDI_UNIQUE, 0, pl, "There is only one %s.", &op->name);
110
111 return false;
112 }
113}
114
98int 115int
99command_uskill (object *pl, char *params) 116command_uskill (object *pl, char *params)
100{ 117{
101 if (!params) 118 if (!params)
102 { 119 {
116 { 133 {
117 new_draw_info (NDI_UNIQUE, 0, pl, "Usage: ready_skill <skill name>"); 134 new_draw_info (NDI_UNIQUE, 0, pl, "Usage: ready_skill <skill name>");
118 return 0; 135 return 0;
119 } 136 }
120 137
121 skill = find_skill_by_name (pl, params); 138 skill = find_skill_by_name_fuzzy (pl, params);
122 139
123 if (!skill) 140 if (!skill)
124 { 141 {
125 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no knowledge of the skill %s", params); 142 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no knowledge of the skill %s", params);
126 return 0; 143 return 0;
127 } 144 }
128 145
129 pl->change_skill (0); 146 pl->change_skill (0);
130 apply_special (pl, skill, AP_APPLY); 147 apply_special (pl, skill, AP_APPLY);
131 return 1; 148 return 1;
132}
133
134/* These functions (command_search, command_disarm) are really just wrappers for
135 * things like 'use_skill ...'). In fact, they should really be obsoleted
136 * and replaced with those.
137 */
138int
139command_search (object *op, char *params)
140{
141 return use_skill (op, skill_names[SK_FIND_TRAPS]);
142}
143
144int
145command_disarm (object *op, char *params)
146{
147 return use_skill (op, skill_names[SK_DISARM_TRAPS]);
148} 149}
149 150
150/* A little special because we do want to pass the full params along 151/* A little special because we do want to pass the full params along
151 * as it includes the object to throw. 152 * as it includes the object to throw.
152 */ 153 */
210 * not need to use split_ob and stuff. 211 * not need to use split_ob and stuff.
211 */ 212 */
212int 213int
213sack_can_hold (object *pl, object *sack, object *op, uint32 nrof) 214sack_can_hold (object *pl, object *sack, object *op, uint32 nrof)
214{ 215{
215
216 if (!QUERY_FLAG (sack, FLAG_APPLIED)) 216 if (!QUERY_FLAG (sack, FLAG_APPLIED))
217 { 217 {
218 new_draw_info_format (NDI_UNIQUE, 0, pl, "The %s is not active.", query_name (sack)); 218 new_draw_info_format (NDI_UNIQUE, 0, pl, "The %s is not active.", query_name (sack));
219 return 0; 219 return 0;
220 } 220 }
221
221 if (sack == op) 222 if (sack == op)
222 { 223 {
223 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the %s into itself.", query_name (sack)); 224 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the %s into itself.", query_name (sack));
224 return 0; 225 return 0;
225 } 226 }
227
226 if (sack->race && (sack->race != op->race || op->type == CONTAINER || (sack->stats.food && sack->stats.food != op->type))) 228 if (sack->race && (sack->race != op->race || op->type == CONTAINER || (sack->stats.food && sack->stats.food != op->type)))
227 { 229 {
228 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can put only %s into the %s.", &sack->race, query_name (sack)); 230 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can put only %s into the %s.", &sack->race, query_name (sack));
229 return 0; 231 return 0;
230 } 232 }
233
231 if (op->type == SPECIAL_KEY && sack->slaying && op->slaying) 234 if (op->type == SPECIAL_KEY && sack->slaying && op->slaying)
232 { 235 {
233 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the key into %s.", query_name (sack)); 236 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the key into %s.", query_name (sack));
234 return 0; 237 return 0;
235 } 238 }
239
236 if (sack->weight_limit && (sint32) (sack->carrying + (nrof ? nrof : 1) * 240 if (sack->weight_limit && (sint32) (sack->carrying + (nrof ? nrof : 1) *
237 (op->weight + (op->type == CONTAINER ? (op->carrying * op->stats.Str) : 0)) 241 (op->weight + (op->type == CONTAINER ? (op->carrying * op->stats.Str) : 0))
238 * (100 - sack->stats.Str) / 100) > sack->weight_limit) 242 * (100 - sack->stats.Str) / 100) > sack->weight_limit)
239 { 243 {
240 new_draw_info_format (NDI_UNIQUE, 0, pl, "That won't fit in the %s!", query_name (sack)); 244 new_draw_info_format (NDI_UNIQUE, 0, pl, "That won't fit in the %s!", query_name (sack));
241 return 0; 245 return 0;
242 } 246 }
247
243 /* All other checks pass, must be OK */ 248 /* All other checks pass, must be OK */
244 return 1; 249 return 1;
245} 250}
246 251
247/* Pick up commands follow */ 252/* Pick up commands follow */
252 * pick up (0 means all of them) 257 * pick up (0 means all of them)
253 */ 258 */
254static void 259static void
255pick_up_object (object *pl, object *op, object *tmp, int nrof) 260pick_up_object (object *pl, object *op, object *tmp, int nrof)
256{ 261{
257 /* buf needs to be big (more than 256 chars) because you can get
258 * very long item names.
259 */
260 char buf[HUGE_BUF];
261 object *env = tmp->env; 262 object *env = tmp->env;
262 uint32 weight, effective_weight_limit; 263 uint32 weight, effective_weight_limit;
263 int tmp_nrof = tmp->nrof ? tmp->nrof : 1; 264 int tmp_nrof = tmp->number_of ();
264 265
265 /* IF the player is flying & trying to take the item out of a container 266 /* IF the player is flying & trying to take the item out of a container
266 * that is in his inventory, let him. tmp->env points to the container 267 * that is in his inventory, let him. tmp->env points to the container
267 * (sack, luggage, etc), tmp->env->env then points to the player (nested 268 * (sack, luggage, etc), tmp->env->env then points to the player (nested
268 * containers not allowed as of now) 269 * containers not allowed as of now)
269 */ 270 */
270 if ((pl->move_type & MOVE_FLYING) && !QUERY_FLAG (pl, FLAG_WIZ) && tmp->in_player () != pl) 271 if ((pl->move_type & MOVE_FLYING) && !QUERY_FLAG (pl, FLAG_WIZ) && tmp->in_player () != pl)
271 { 272 {
272 new_draw_info (NDI_UNIQUE, 0, pl, "You are levitating, you can't reach the ground!"); 273 pl->failmsg ("You are levitating, you can't reach the ground! "
274 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
275 "or waiting till the levitation effect wears off.>");
273 return; 276 return;
274 } 277 }
275 278
276 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 279 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
277 return; 280 return;
278 281
279 if (nrof > tmp_nrof || nrof == 0) 282 if (nrof > tmp_nrof || nrof <= 0)
280 nrof = tmp_nrof; 283 nrof = tmp_nrof;
281 284
282 /* Figure out how much weight this object will add to the player */ 285 /* Figure out how much weight this object will add to the player */
283 weight = tmp->weight * nrof; 286 weight = tmp->weight * nrof;
284 if (tmp->inv) 287 if (tmp->inv)
285 weight += tmp->carrying * (100 - tmp->stats.Str) / 100; 288 weight += tmp->carrying * (100 - tmp->stats.Str) / 100;
286 289
287 if (pl->stats.Str <= MAX_STAT)
288 effective_weight_limit = weight_limit[pl->stats.Str]; 290 effective_weight_limit = weight_limit [min (MAX_STAT, pl->stats.Str)];
289 else
290 effective_weight_limit = weight_limit[MAX_STAT];
291 291
292 if ((pl->weight + pl->carrying + weight) > effective_weight_limit) 292 if ((pl->weight + pl->carrying + weight) > effective_weight_limit)
293 { 293 {
294 new_draw_info (0, 0, pl, "That item is too heavy for you to pick up."); 294 new_draw_info (0, 0, pl, "That item is too heavy for you to pick up.");
295 return; 295 return;
296 } 296 }
297 297
298 if (nrof != tmp_nrof) 298 if (!can_split (pl, tmp, nrof))
299 {
300 object *tmp2 = tmp;
301
302 tmp = get_split_ob (tmp, nrof);
303 if (!tmp)
304 {
305 new_draw_info (NDI_UNIQUE, 0, pl, errmsg);
306 return; 299 return;
307 }
308 300
309 /* Tell the client what happened to the rest of objects */ 301 if (QUERY_FLAG (tmp, FLAG_UNPAID))
310 if (pl->contr) 302 {
311 if (tmp2->destroyed ()) 303 tmp->flag.reset (FLAG_UNPAID);
312 esrv_del_item (pl->contr, tmp2->count); 304 new_draw_info_format (NDI_UNIQUE, 0, pl, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP));
313 else 305 tmp->flag.set (FLAG_UNPAID);
314 esrv_update_item (UPD_NROF, pl, tmp2);
315 } 306 }
316 else 307 else
317 { 308 new_draw_info_format (NDI_UNIQUE, 0, pl, "You pick up the %s.", query_name (tmp));
318 /* If the object is in a container, send a delete to the client.
319 * - we are moving all the items from the container to elsewhere,
320 * so it needs to be deleted.
321 */
322 if (!QUERY_FLAG (tmp, FLAG_REMOVED))
323 {
324 if (tmp->env && pl->type == PLAYER)
325 esrv_del_item (pl->contr, tmp->count);
326 309
327 tmp->remove (); /* Unlink it */ 310 op->insert (tmp);
328 }
329 }
330
331 if (QUERY_FLAG (tmp, FLAG_UNPAID))
332 sprintf (buf, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP));
333 else
334 sprintf (buf, "You pick up the %s.", query_name (tmp));
335
336 new_draw_info (NDI_UNIQUE, 0, pl, buf);
337
338 tmp = insert_ob_in_ob (tmp, op);
339
340 /* All the stuff below deals with client/server code, and is only
341 * usable by players
342 */
343 if (pl->contr)
344 {
345 esrv_send_item (pl, tmp);
346
347 /* These are needed to update the weight for the container we
348 * are putting the object in.
349 */
350 if (op != pl)
351 {
352 esrv_update_item (UPD_WEIGHT, pl, op);
353 esrv_send_item (pl, pl);
354 }
355
356 /* Update the container the object was in */
357 if (env && env != pl && env != op)
358 esrv_update_item (UPD_WEIGHT, pl, env);
359 }
360} 311}
361 312
362/* modified slightly to allow monsters use this -b.t. 5-31-95 */ 313/* modified slightly to allow monsters use this -b.t. 5-31-95 */
363void 314void
364pick_up (object *op, object *alt) 315pick_up (object *op, object *alt)
374 if (!can_pick (op, alt)) 325 if (!can_pick (op, alt))
375 { 326 {
376 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up the %s.", &alt->name); 327 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up the %s.", &alt->name);
377 goto leave; 328 goto leave;
378 } 329 }
330
379 tmp = alt; 331 tmp = alt;
380 } 332 }
381 else 333 else
382 { 334 {
383 if (op->below == NULL || !can_pick (op, op->below)) 335 if (op->below == NULL || !can_pick (op, op->below))
392 /* Try to catch it. */ 344 /* Try to catch it. */
393 tmp_map = tmp->map; 345 tmp_map = tmp->map;
394 tmp = stop_item (tmp); 346 tmp = stop_item (tmp);
395 if (tmp == NULL) 347 if (tmp == NULL)
396 goto leave; 348 goto leave;
349
397 need_fix_tmp = 1; 350 need_fix_tmp = 1;
398 if (!can_pick (op, tmp)) 351 if (!can_pick (op, tmp))
399 goto leave; 352 goto leave;
400 353
401 if (op->type == PLAYER) 354 if (op->type == PLAYER)
406 } 359 }
407 else 360 else
408 count = tmp->nrof; 361 count = tmp->nrof;
409 362
410 /* container is open, so use it */ 363 /* container is open, so use it */
364 if (tmp->flag [FLAG_STARTEQUIP])
365 alt = op;
411 if (op->container) 366 else if (op->container)
412 { 367 {
413 alt = op->container; 368 alt = op->container;
414 if (alt != tmp->env && !sack_can_hold (op, alt, tmp, count)) 369 if (alt != tmp->env && !sack_can_hold (op, alt, tmp, count))
415 goto leave; 370 goto leave;
416 } 371 }
435 /* here it could be possible to check rent, 390 /* here it could be possible to check rent,
436 * if someone wants to implement it 391 * if someone wants to implement it
437 */ 392 */
438 alt = op; 393 alt = op;
439 } 394 }
395
440#ifdef PICKUP_DEBUG 396#ifdef PICKUP_DEBUG
441 LOG (llevDebug, "Pick_up(): %s picks %s (%d) and inserts it %s.\n", op->name, tmp->name, op->contr->count, alt->name); 397 LOG (llevDebug, "Pick_up(): %s picks %s (%d) and inserts it %s.\n", op->name, tmp->name, op->contr->count, alt->name);
442#endif 398#endif
443 399
444 /* startequip items are not allowed to be put into containers: */ 400 /* startequip items are not allowed to be put into containers: */
494 450
495 /* Makes processing easier */ 451 /* Makes processing easier */
496 if (params && *params == '\0') 452 if (params && *params == '\0')
497 params = 0; 453 params = 0;
498 454
455 int cnt = MAX_ITEM_PER_DROP;
456
499 while (tmp) 457 while (tmp)
500 { 458 {
501 next = tmp->below; 459 next = tmp->below;
502 460
503 if (tmp->invisible) 461 if (tmp->invisible)
509 /* This following two if and else if could be merged into line 467 /* This following two if and else if could be merged into line
510 * but that probably will make it more difficult to read, and 468 * but that probably will make it more difficult to read, and
511 * not make it any more efficient 469 * not make it any more efficient
512 */ 470 */
513 if (params && item_matched_string (op, tmp, params)) 471 if (params && item_matched_string (op, tmp, params))
472 {
473 if (--cnt < 0) break;
514 pick_up (op, tmp); 474 pick_up (op, tmp);
475 }
515 else if (can_pick (op, tmp) && !params) 476 else if (can_pick (op, tmp) && !params)
516 { 477 {
478 if (--cnt < 0) break;
517 pick_up (op, tmp); 479 pick_up (op, tmp);
518 break; 480 break;
519 } 481 }
520 482
521 tmp = next; 483 tmp = next;
484 }
485
486 if (cnt < 0)
487 {
488 op->failmsg ("Couldn't pick up so many items at once.");
489 return 0;
522 } 490 }
523 491
524 if (!params && !tmp) 492 if (!params && !tmp)
525 { 493 {
526 for (tmp = op->below; tmp; tmp = tmp->below) 494 for (tmp = op->below; tmp; tmp = tmp->below)
527 if (!tmp->invisible) 495 if (!tmp->invisible)
528 { 496 {
529 char buf[MAX_BUF];
530
531 sprintf (buf, "You can't pick up a %s.", &tmp->name); 497 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up a %s.", &tmp->name);
532 new_draw_info (NDI_UNIQUE, 0, op, buf);
533 break; 498 break;
534 } 499 }
535 500
536 if (!tmp) 501 if (!tmp)
537 new_draw_info (NDI_UNIQUE, 0, op, "There is nothing to pick up."); 502 new_draw_info (NDI_UNIQUE, 0, op, "There is nothing to pick up.");
538 } 503 }
539 504
540 return 0; 505 return 0;
541} 506}
542 507
543
544/* 508/*
545 * This function was part of drop, now is own function. 509 * This function was part of drop, now is own function.
546 * Player 'op' tries to put object 'tmp' into sack 'sack', 510 * Player 'op' tries to put object 'tmp' into sack 'sack',
547 * if nrof is non zero, then nrof objects is tried to put into sack. 511 * if nrof is non zero, then nrof objects is tried to put into sack.
512 *
548 * Note that the 'sack' in question can now be a transport, 513 * Note that the 'sack' in question can now be a transport,
549 * so this function isn't named very good anymore. 514 * so this function isn't named very good anymore.
550 */ 515 */
551void 516void
552put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof) 517put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof)
563 return; 528 return;
564 } 529 }
565 530
566 if (tmp->type == CONTAINER && tmp->inv) 531 if (tmp->type == CONTAINER && tmp->inv)
567 { 532 {
568
569 /* Eneq(@csd.uu.se): If the object to be dropped is a container 533 /* Eneq(@csd.uu.se): If the object to be dropped is a container
570 * we instead move the contents of that container into the active 534 * we instead move the contents of that container into the active
571 * container, this is only done if the object has something in it. 535 * container, this is only done if the object has something in it.
572 */ 536 */
573 sack2 = tmp; 537 sack2 = tmp;
576 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) 540 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp)
577 { 541 {
578 tmp = tmp2->below; 542 tmp = tmp2->below;
579 543
580 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)))
581 {
582 put_object_in_sack (op, sack, tmp2, 0); 545 put_object_in_sack (op, sack, tmp2, 0);
583 }
584 else 546 else
585 { 547 {
586 sprintf (buf, "Your %s fills up.", query_name (sack)); 548 sprintf (buf, "Your %s fills up.", query_name (sack));
587 new_draw_info (NDI_UNIQUE, 0, op, buf); 549 new_draw_info (NDI_UNIQUE, 0, op, buf);
588 break; 550 break;
589 } 551 }
590 } 552 }
591 553
592 esrv_update_item (UPD_WEIGHT, op, sack2);
593 return; 554 return;
594 } 555 }
595 556
596 /* Don't worry about this for containers - our caller should have 557 /* Don't worry about this for containers - our caller should have
597 * already checked this. 558 * already checked this.
602 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 563 if (QUERY_FLAG (tmp, FLAG_APPLIED))
603 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 564 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
604 return; 565 return;
605 566
606 /* we want to put some portion of the item into the container */ 567 /* we want to put some portion of the item into the container */
607 if (nrof && tmp->nrof != nrof) 568 if (!can_split (op, tmp, nrof))
608 {
609 object *tmp2 = tmp;
610
611 tmp = get_split_ob (tmp, nrof);
612
613 if (!tmp)
614 {
615 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
616 return; 569 return;
617 }
618 /* Tell a client what happened other objects */
619 if (tmp2->destroyed ())
620 esrv_del_item (op->contr, tmp2->count);
621 else /* this can proably be replaced with an update */
622 esrv_send_item (op, tmp2);
623 }
624 else
625 tmp->remove ();
626 570
627 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack)); 571 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack));
628 tmp2 = insert_ob_in_ob (tmp, sack); 572 sack->insert (tmp);
629 op->update_stats (); /* This is overkill, fix_player() is called somewhere */
630 /* in object.c */
631
632 /* If an object merged (and thus, different object), we need to
633 * delete the original.
634 */
635 if (tmp2 != tmp)
636 esrv_del_item (op->contr, tmp->count);
637
638 esrv_send_item (op, tmp2);
639
640 /* update the sacks weight */
641 esrv_update_item (UPD_WEIGHT, op, sack);
642} 573}
643 574
644/* 575/*
645 * This function was part of drop, now is own function. 576 * This function was part of drop, now is own function.
646 * Player 'op' tries to drop object 'tmp', if tmp is non zero, then 577 * Player 'op' tries to drop object 'tmp', if tmp is non zero, then
648 * This is used when dropping objects onto the floor. 579 * This is used when dropping objects onto the floor.
649 */ 580 */
650void 581void
651drop_object (object *op, object *tmp, uint32 nrof) 582drop_object (object *op, object *tmp, uint32 nrof)
652{ 583{
653 char buf[MAX_BUF];
654 object *floor;
655
656 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 584 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
657 return; 585 return;
658 586
659 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 587 if (QUERY_FLAG (tmp, FLAG_APPLIED))
660 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 588 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
663 //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D 591 //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D
664 592
665 /* We are only dropping some of the items. We split the current object 593 /* We are only dropping some of the items. We split the current object
666 * off 594 * off
667 */ 595 */
668 if (nrof && tmp->nrof != nrof) 596 if (!can_split (op, tmp, nrof))
669 {
670 object *tmp2 = tmp;
671
672 tmp = get_split_ob (tmp, nrof);
673 if (!tmp)
674 {
675 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
676 return;
677 }
678 /* Tell a client what happened rest of objects. tmp2 is now the
679 * original object
680 */
681 if (op->type == PLAYER)
682 {
683 if (tmp2->destroyed ())
684 esrv_del_item (op->contr, tmp2->count);
685 else
686 esrv_send_item (op, tmp2);
687 }
688 }
689 else
690 tmp->remove ();
691
692 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op)))
693 return; 597 return;
694 598
599 drop_object (op, tmp);
600
601 if (!tmp->destroyed () && !tmp->is_inserted ())
602 {
603 // if nothing happened with the object we give it back
604 op->insert (tmp);
605 }
606}
607
608/* In contrast to drop_object (op, tmp, nrof) above this function takes the
609 * already split off object, and feeds it to the event handlers and does
610 * other magic with it.
611 *
612 * <droppper> is the object that dropped this object and <obj> is the
613 * object that was dropped.
614 *
615 * Make sure to check what happened with <obj> after this function returns!
616 * Otherwise you may leak this object.
617 */
618
619void
620drop_object (object *dropper, object *obj)
621{
622 if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper)))
623 return;
624
625 if (obj->destroyed () || obj->is_inserted ())
626 return;
627
695 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 628 if (QUERY_FLAG (obj, FLAG_STARTEQUIP))
696 { 629 {
697 sprintf (buf, "You drop the %s.", query_name (tmp)); 630 dropper->statusmsg (format ("You drop the %s.", query_name (obj)));
698 new_draw_info (NDI_UNIQUE, 0, op, buf); 631 dropper->statusmsg ("The god who lent it to you retrieves it.");
699 new_draw_info (NDI_UNIQUE, 0, op, "The gods who lent it to you retrieves it.");
700 632
701 if (op->type == PLAYER)
702 esrv_del_item (op->contr, tmp->count);
703
704 tmp->destroy (); 633 obj->destroy ();
705 op->update_stats (); 634 dropper->update_stats ();
706 return; 635 return;
707 } 636 }
708 637
709 if (op->type == PLAYER) 638 for (object *floor = GET_MAP_OB (dropper->map, dropper->x, dropper->y);
710 esrv_del_item (op->contr, tmp->count); 639 floor;
640 floor = floor->above)
641 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (obj), ARG_OBJECT (dropper)))
642 return;
711 643
712 /* Call this before we update the various windows/players. At least 644 if (obj->destroyed () || obj->is_inserted ())
713 * that we, we know the weight is correct. 645 return;
646
647 if (is_in_shop (dropper) && !QUERY_FLAG (obj, FLAG_UNPAID) && obj->type != MONEY)
648 if (!sell_item (obj, dropper))
649 return;
650
651 /* If nothing special happened with this object, the default action is to
652 * insert it below the dropper:
714 */ 653 */
715 op->update_stats (); /* This is overkill, fix_player() is called somewhere */
716 /* in object.c */
717 654
718 if (op->type == PLAYER) 655 obj->x = dropper->x;
719 { 656 obj->y = dropper->y;
720 /* Need to update the weight for the player */
721 esrv_send_item (op, op);
722 op->contr->ns->floorbox_update ();
723 }
724 657
725 for (floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above)
726 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op)))
727 return;
728
729 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
730 sell_item (tmp, op);
731
732 tmp->x = op->x;
733 tmp->y = op->y;
734
735 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); 658 insert_ob_in_map (obj, dropper->map, dropper, INS_BELOW_ORIGINATOR);
736} 659}
737 660
738void 661void
739drop (object *op, object *tmp) 662drop (object *op, object *tmp)
740{ 663{
749 if (tmp->env && tmp->env->type != PLAYER) 672 if (tmp->env && tmp->env->type != PLAYER)
750 { 673 {
751 /* Just toss the object - probably shouldn't be hanging 674 /* Just toss the object - probably shouldn't be hanging
752 * around anyways 675 * around anyways
753 */ 676 */
754 tmp->remove ();
755 tmp->destroy (); 677 tmp->destroy ();
756 return; 678 return;
757 } 679 }
758 else 680 else
759 { 681 {
760 while (tmp != NULL && tmp->invisible) 682 while (tmp && tmp->invisible)
761 tmp = tmp->below; 683 tmp = tmp->below;
762 } 684 }
763 } 685 }
764 686
765 if (tmp == NULL) 687 if (tmp == NULL)
766 { 688 {
767 new_draw_info (NDI_UNIQUE, 0, op, "You don't have anything to drop."); 689 new_draw_info (NDI_UNIQUE, 0, op, "You don't have anything to drop.");
768 return; 690 return;
769 } 691 }
692
770 if (QUERY_FLAG (tmp, FLAG_INV_LOCKED)) 693 if (QUERY_FLAG (tmp, FLAG_INV_LOCKED))
771 { 694 {
772 new_draw_info (NDI_UNIQUE, 0, op, "This item is locked"); 695 new_draw_info (NDI_UNIQUE, 0, op, "This item is locked");
773 return; 696 return;
774 } 697 }
698
775 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 699 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
776 { 700 {
777#if 0 701#if 0
778 /* Eneq(@csd.uu.se): Objects with NO_DROP defined can't be dropped. */ 702 /* Eneq(@csd.uu.se): Objects with NO_DROP defined can't be dropped. */
779 new_draw_info (NDI_UNIQUE, 0, op, "This item can't be dropped."); 703 new_draw_info (NDI_UNIQUE, 0, op, "This item can't be dropped.");
803 727
804 if (op->type == PLAYER) 728 if (op->type == PLAYER)
805 op->contr->count = 0; 729 op->contr->count = 0;
806} 730}
807 731
808
809
810/* Command will drop all items that have not been locked */ 732/* Command will drop all items that have not been locked */
811int 733int
812command_dropall (object *op, char *params) 734command_dropall (object *op, char *params)
813{ 735{
814 736
815 object *curinv, *nextinv;
816
817 if (op->inv == NULL) 737 if (op->inv == NULL)
818 { 738 {
819 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop!"); 739 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop!");
820 return 0; 740 return 0;
821 } 741 }
822 742
823 curinv = op->inv; 743 object *curinv = op->inv;
744 object *nextinv;
824 745
825 /* 746 /*
826 This is the default. Drops everything not locked or considered 747 This is the default. Drops everything not locked or considered
827 not something that should be dropped. 748 not something that should be dropped.
828 */ 749 */
830 Care must be taken that the next item pointer is not to money as 751 Care must be taken that the next item pointer is not to money as
831 the drop() routine will do unknown things to it when dropping 752 the drop() routine will do unknown things to it when dropping
832 in a shop. --Tero.Pelander@utu.fi 753 in a shop. --Tero.Pelander@utu.fi
833 */ 754 */
834 755
835 if (params == NULL) 756 int cnt = MAX_ITEM_PER_DROP;
757
758 if (!params)
836 { 759 {
837 while (curinv != NULL) 760 while (curinv)
838 { 761 {
839 nextinv = curinv->below; 762 nextinv = curinv->below;
763
840 while (nextinv && nextinv->type == MONEY) 764 while (nextinv && nextinv->type == MONEY)
841 nextinv = nextinv->below; 765 nextinv = nextinv->below;
766
842 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY && 767 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY &&
843 curinv->type != FOOD && curinv->type != KEY && 768 curinv->type != FOOD && curinv->type != KEY &&
844 curinv->type != SPECIAL_KEY && curinv->type != GEM && 769 curinv->type != SPECIAL_KEY && curinv->type != GEM &&
845 !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv)) 770 !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv))
846 { 771 {
847 drop (op, curinv); 772 drop (op, curinv);
773 if (--cnt <= 0) break;
848 } 774 }
775
849 curinv = nextinv; 776 curinv = nextinv;
850 } 777 }
851 } 778 }
852
853 else if (strcmp (params, "weapons") == 0) 779 else if (strcmp (params, "weapons") == 0)
854 { 780 {
855 while (curinv != NULL) 781 while (curinv)
856 { 782 {
857 nextinv = curinv->below; 783 nextinv = curinv->below;
784
858 while (nextinv && nextinv->type == MONEY) 785 while (nextinv && nextinv->type == MONEY)
859 nextinv = nextinv->below; 786 nextinv = nextinv->below;
787
860 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == WEAPON) || (curinv->type == BOW) || (curinv->type == ARROW))) 788 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == WEAPON) || (curinv->type == BOW) || (curinv->type == ARROW)))
861 { 789 {
862 drop (op, curinv); 790 drop (op, curinv);
791 if (--cnt <= 0) break;
863 } 792 }
793
864 curinv = nextinv; 794 curinv = nextinv;
865 } 795 }
866 } 796 }
867
868 else if (strcmp (params, "armor") == 0 || strcmp (params, "armour") == 0) 797 else if (strcmp (params, "armor") == 0 || strcmp (params, "armour") == 0)
869 { 798 {
870 while (curinv != NULL) 799 while (curinv)
871 { 800 {
872 nextinv = curinv->below; 801 nextinv = curinv->below;
802
873 while (nextinv && nextinv->type == MONEY) 803 while (nextinv && nextinv->type == MONEY)
874 nextinv = nextinv->below; 804 nextinv = nextinv->below;
805
875 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == ARMOUR) || curinv->type == SHIELD || curinv->type == HELMET)) 806 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == ARMOUR) || curinv->type == SHIELD || curinv->type == HELMET))
876 { 807 {
877 drop (op, curinv); 808 drop (op, curinv);
809 if (--cnt <= 0) break;
878 } 810 }
811
879 curinv = nextinv; 812 curinv = nextinv;
880 } 813 }
881 } 814 }
882
883 else if (strcmp (params, "misc") == 0) 815 else if (strcmp (params, "misc") == 0)
884 { 816 {
885 while (curinv != NULL) 817 while (curinv)
886 { 818 {
887 nextinv = curinv->below; 819 nextinv = curinv->below;
820
888 while (nextinv && nextinv->type == MONEY) 821 while (nextinv && nextinv->type == MONEY)
889 nextinv = nextinv->below; 822 nextinv = nextinv->below;
823
890 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && !QUERY_FLAG (curinv, FLAG_APPLIED)) 824 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && !QUERY_FLAG (curinv, FLAG_APPLIED))
891 { 825 {
892 switch (curinv->type) 826 switch (curinv->type)
893 { 827 {
894 case HORN: 828 case HORN:
912 break; 846 break;
913 default: 847 default:
914 curinv = nextinv; 848 curinv = nextinv;
915 break; 849 break;
916 } 850 }
851
852 if (--cnt <= 0) break;
917 } 853 }
854
918 curinv = nextinv; 855 curinv = nextinv;
919 } 856 }
920 } 857 }
921 858
922 op->contr->ns->floorbox_update (); 859 if (cnt <= 0)
860 op->failmsg ("Only dropped some items, can't drop that many items at once.");
923 861
924/* draw_look(op);*/ 862/* draw_look(op);*/
925 return 0; 863 return 0;
864}
865
866
867/* This function tries to drop all objects in the <objs> vector.
868 * <dropper> is the object that wants to drop them.
869 * <cnt> can be a 0 pointer or a pointer to the maximum number of
870 * drop operations to perform.
871 *
872 * Returns true if at least one item was dropped.
873 */
874bool
875drop_vector (object *dropper, vector<object *> &objs, int *cnt)
876{
877 vector<object *>::iterator i;
878
879 bool did_one = false;
880
881 for (i = objs.begin (); i != objs.end (); i++)
882 {
883 drop (dropper, *i);
884 if (cnt && --*cnt <= 0) break;
885 did_one = true;
886 }
887
888 return did_one;
926} 889}
927 890
928/* Object op wants to drop object(s) params. params can be a 891/* Object op wants to drop object(s) params. params can be a
929 * comma seperated list. 892 * comma seperated list.
930 */ 893 */
931
932int 894int
933command_drop (object *op, char *params) 895command_drop (object *op, char *params)
934{ 896{
935 object *tmp, *next; 897 object *tmp, *next;
936 int did_one = 0; 898 int did_one = 0;
940 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); 902 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?");
941 return 0; 903 return 0;
942 } 904 }
943 else 905 else
944 { 906 {
907 vector<object *> matched_objs;
908
945 for (tmp = op->inv; tmp; tmp = next) 909 for (tmp = op->inv; tmp; tmp = next)
946 { 910 {
947 next = tmp->below; 911 next = tmp->below;
948 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) 912 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible)
949 continue; 913 continue;
914
950 if (item_matched_string (op, tmp, params)) 915 if (item_matched_string (op, tmp, params))
951 { 916 matched_objs.push_back (tmp);
952 drop (op, tmp);
953 did_one = 1;
954 } 917 }
955 } 918
956 if (!did_one) 919 int cnt = MAX_ITEM_PER_DROP;
920
921 if (!drop_vector (op, matched_objs, &cnt))
957 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 922 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
958 } 923
959 if (op->type == PLAYER) 924 if (cnt <= 0)
960 { 925 op->failmsg ("Only dropped some items, can't drop that many items at once.");
961 op->contr->count = 0;
962 op->contr->ns->floorbox_update ();
963 }; 926 }
964 927
965/* draw_look(op);*/
966 return 0; 928 return 0;
967} 929}
968 930
969int 931int
970command_examine (object *op, char *params) 932command_examine (object *op, char *params)
973 { 935 {
974 object *tmp = op->below; 936 object *tmp = op->below;
975 937
976 while (tmp && !tmp->client_visible ()) 938 while (tmp && !tmp->client_visible ())
977 tmp = tmp->below; 939 tmp = tmp->below;
940
978 if (tmp) 941 if (tmp)
979 examine (op, tmp); 942 examine (op, tmp);
980 } 943 }
981 else 944 else
982 { 945 {
983 object *tmp = find_best_object_match (op, params); 946 object *tmp = find_best_object_match (op, params);
984 947
985 if (tmp) 948 if (tmp)
986 examine (op, tmp); 949 examine (op, tmp);
987 else 950 else
988 new_draw_info_format (NDI_UNIQUE, 0, op, "Could not find an object that matches %s", params); 951 op->contr->infobox (MSG_CHANNEL ("examine"), format ("Could not find an object that matches %s", params));
989 } 952 }
953
990 return 0; 954 return 0;
991} 955}
992 956
993/* op should be a player. 957/* op should be a player.
994 * we return the object the player has marked with the 'mark' command 958 * we return the object the player has marked with the 'mark' command
1041 dynbuf_text buf (512, 512); 1005 dynbuf_text buf (512, 512);
1042 1006
1043 object *mon = head ? head : this; 1007 object *mon = head ? head : this;
1044 1008
1045 if (QUERY_FLAG (mon, FLAG_UNDEAD)) 1009 if (QUERY_FLAG (mon, FLAG_UNDEAD))
1046 buf << "It is an undead force.\n"; 1010 buf << "It is an undead force.\r";
1047 1011
1048 if (mon->level > who->level) 1012 if (mon->level > who->level)
1049 buf << "It is likely more powerful than you.\n"; 1013 buf << "It is likely more powerful than you.\r";
1050 else if (mon->level < who->level) 1014 else if (mon->level < who->level)
1051 buf << "It is likely less powerful than you.\n"; 1015 buf << "It is likely less powerful than you.\r";
1052 else 1016 else
1053 buf << "It is probably as powerful as you.\n"; 1017 buf << "It is probably as powerful as you.\r";
1054 1018
1055 if (mon->attacktype & AT_ACID) 1019 if (mon->attacktype & AT_ACID)
1056 buf << "You seem to smell an acrid odor.\n"; 1020 buf << "You seem to smell an acrid odor.\r";
1057 1021
1058 /* Anyone know why this used to use the clone value instead of the 1022 /* Anyone know why this used to use the clone value instead of the
1059 * maxhp field? This seems that it should give more accurate results. 1023 * maxhp field? This seems that it should give more accurate results.
1060 */ 1024 */
1061 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) 1025 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1))
1062 { /* From 1-4 */ 1026 { /* From 1-4 */
1063 case 1: 1027 case 1:
1064 buf << "It is in a bad shape.\n"; 1028 buf << "It is in a bad shape.\r";
1065 break; 1029 break;
1066 case 2: 1030 case 2:
1067 buf << "It is hurt.\n"; 1031 buf << "It is hurt.\r";
1068 break; 1032 break;
1069 case 3: 1033 case 3:
1070 buf << "It is somewhat hurt.\n"; 1034 buf << "It is somewhat hurt.\r";
1071 break; 1035 break;
1072 case 4: 1036 case 4:
1073 buf << "It is in excellent shape.\n"; 1037 buf << "It is in excellent shape.\r";
1074 break; 1038 break;
1075 } 1039 }
1076 1040
1077 if (present_in_ob (POISONING, mon)) 1041 if (present_in_ob (POISONING, mon))
1078 buf << "It looks very ill.\n"; 1042 buf << "It looks very ill.\r";
1043
1044 buf << '\n';
1079 1045
1080 return buf; 1046 return buf;
1081} 1047}
1082 1048
1083/* tmp is the object being described, pl is who is examing it. */ 1049/* tmp is the object being described, pl is who is examing it. */
1090} 1056}
1091 1057
1092std::string 1058std::string
1093object::long_desc (object *who) 1059object::long_desc (object *who)
1094{ 1060{
1095 std::string buf (query_name (this)); 1061 std::string buf (query_name ());
1096 1062
1097 switch (type) 1063 switch (type)
1098 { 1064 {
1099 case RING: 1065 case RING:
1100 case SKILL: 1066 case SKILL:
1112 case CLOAK: 1078 case CLOAK:
1113 case FOOD: 1079 case FOOD:
1114 case DRINK: 1080 case DRINK:
1115 case FLESH: 1081 case FLESH:
1116 case SKILL_TOOL: 1082 case SKILL_TOOL:
1083 case LAMP:
1117 case POWER_CRYSTAL: 1084 case POWER_CRYSTAL:
1118 { 1085 {
1119 const char *cp = ::describe_item (this, who); 1086 const char *cp = ::describe_item (this, who);
1120 1087
1121 if (*cp) 1088 if (*cp)
1141std::string 1108std::string
1142object::describe (object *who) 1109object::describe (object *who)
1143{ 1110{
1144 dynbuf_text buf (1024, 1024); 1111 dynbuf_text buf (1024, 1024);
1145 1112
1146 buf.printf ("That is: %s.\n", long_desc (who).c_str ()); 1113 buf.printf ("That is: %s.\r", long_desc (who).c_str ());
1147 1114
1148 if (custom_name) 1115 if (custom_name)
1149 buf,printf ("You call it %s\n", &custom_name); 1116 buf.printf ("You call it %s.\r", &custom_name);
1150 1117
1151 switch (type) 1118 switch (type)
1152 { 1119 {
1153 case SPELLBOOK: 1120 case SPELLBOOK:
1154 if (flag [FLAG_IDENTIFIED] && inv) 1121 if (flag [FLAG_IDENTIFIED] && inv)
1155 buf.printf ("%s is a %s %s spell\n", &inv->name, get_levelnumber (inv->level), &inv->skill); 1122 buf.printf ("%s is a level %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill);
1156 break; 1123 break;
1157 1124
1158 case BOOK: 1125 case BOOK:
1159 if (msg) 1126 if (msg)
1160 buf << "Something is written in it.\n"; 1127 buf << "Something is written in it.\r";
1161 break; 1128 break;
1162 1129
1163 case CONTAINER: 1130 case CONTAINER:
1164 if (race != NULL) 1131 if (race)
1165 { 1132 {
1166 if (weight_limit && stats.Str < 100) 1133 if (weight_limit && stats.Str < 100)
1167 buf.printf ("It can hold only %s and its weight limit is %.1f kg.\n", 1134 buf.printf ("It can hold only %s and its weight limit is %.1f kg.\r",
1168 &race, weight_limit / (10.0 * (100 - stats.Str))); 1135 &race, weight_limit / (10.0 * (100 - stats.Str)));
1169 else 1136 else
1170 buf.printf ("It can hold only %s.\n", &race); 1137 buf.printf ("It can hold only %s.\r", &race);
1171 } 1138 }
1172 else if (weight_limit && stats.Str < 100) 1139 else if (weight_limit && stats.Str < 100)
1173 buf.printf ("Its weight limit is %.1f kg.\n", weight_limit / (10.0 * (100 - stats.Str))); 1140 buf.printf ("Its weight limit is %.1f kg.\r", weight_limit / (10.0 * (100 - stats.Str)));
1174 break; 1141 break;
1175 1142
1176 case WAND: 1143 case WAND:
1177 if (flag [FLAG_IDENTIFIED]) 1144 if (flag [FLAG_IDENTIFIED])
1178 buf.printf ("It has %d charges left.\n", stats.food); 1145 buf.printf ("It has %d charges left.\r", stats.food);
1179 break; 1146 break;
1180 } 1147 }
1181 1148
1182 if (materialname && !msg) 1149 if (materialname && !msg)
1183 buf.printf ("It is made of: %s.\n", &materialname); 1150 buf.printf ("It is made of: %s.\r", &materialname);
1184 1151
1185 if (who) 1152 if (who)
1186 /* Where to wear this item */ 1153 /* Where to wear this item */
1187 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 1154 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
1188 if (slot[i].info) 1155 if (slot[i].info)
1190 buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name); 1157 buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name);
1191 1158
1192 if (slot[i].info < -1 && who->slot[i].info) 1159 if (slot[i].info < -1 && who->slot[i].info)
1193 buf.printf ("(%d)", -slot[i].info); 1160 buf.printf ("(%d)", -slot[i].info);
1194 1161
1195 buf << ".\n"; 1162 buf << ".\r";
1196 } 1163 }
1197 1164
1198 if (weight) 1165 if (weight)
1199 buf.printf (nrof > 1 ? "They weigh %3.3f kg.\n" : "It weighs %3.3f kg.\n", weight * (nrof ? nrof : 1) / 1000.0); 1166 buf.printf ("%s %3.3f kg.\r", nrof > 1 ? "They weigh" : "It weighs", weight * (nrof ? nrof : 1) / 1000.0);
1200 1167
1201 if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who) 1168 if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who)
1202 { 1169 {
1203 buf.printf ("You reckon %s worth %s.\n", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX)); 1170 buf.printf ("You reckon %s worth %s.\r", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX));
1204 1171
1205 if (is_in_shop (who)) 1172 if (is_in_shop (who))
1206 { 1173 {
1207 if (flag [FLAG_UNPAID]) 1174 if (flag [FLAG_UNPAID])
1208 buf.printf ("%s would cost you %s.\n", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP)); 1175 buf.printf ("%s would cost you %s.\r", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP));
1209 else 1176 else
1210 buf.printf ("You are offered %s for %s.\n", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it"); 1177 buf.printf ("You are offered %s for %s.\r", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it");
1211 } 1178 }
1212 } 1179 }
1213 1180
1214 if (flag [FLAG_MONSTER]) 1181 if (flag [FLAG_MONSTER])
1215 buf << describe_monster (who); 1182 buf << describe_monster (who);
1216 1183
1217 /* Is this item buildable? */ 1184 /* Is this item buildable? */
1218 if (flag [FLAG_IS_BUILDABLE]) 1185 if (flag [FLAG_IS_BUILDABLE])
1219 buf << "This is a buildable item.\n"; 1186 buf << "This is a buildable item.\r";
1220 1187
1221 /* Does the object have a message? Don't show message for all object 1188 /* Does the object have a message? Don't show message for all object
1222 * types - especially if the first entry is a match 1189 * types - especially if the first entry is a match
1223 */ 1190 */
1224 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && strncasecmp (msg, "@match", 7)) 1191 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ())
1225 { 1192 {
1226 /* This is just a hack so when identifying the items, we print 1193 /* This is just a hack so when identifying the items, we print
1227 * out the extra message 1194 * out the extra message
1228 */ 1195 */
1229 if (need_identify (this) && flag [FLAG_IDENTIFIED]) 1196 if (need_identify (this) && flag [FLAG_IDENTIFIED])
1230 buf << "The object has a story:\n"; 1197 buf << "The object has a story:\r";
1231 1198
1232 buf << msg << '\n'; 1199 buf << msg << '\n';
1233 } 1200 }
1234 1201
1235 buf << '\n'; 1202 buf << '\n';
1236 1203
1237 return std::string (buf.linearise (), buf.size ()); 1204 return std::string (buf.linearise (), buf.size ());
1238}
1239
1240void
1241examine (object *op, object *tmp)
1242{
1243 std::string s = tmp->describe (op);
1244
1245 new_draw_info (NDI_UNIQUE, 0, op, s.c_str ());
1246}
1247
1248/*
1249 * inventory prints object's inventory. If inv==NULL then print player's
1250 * inventory.
1251 * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ]
1252 */
1253void
1254inventory (object *op, object *inv)
1255{
1256 object *tmp;
1257 const char *in;
1258 int items = 0, length;
1259
1260 if (inv == NULL && op == NULL)
1261 {
1262 new_draw_info (NDI_UNIQUE, 0, op, "Inventory of what object?");
1263 return;
1264 }
1265
1266 tmp = inv ? inv->inv : op->inv;
1267
1268 while (tmp)
1269 {
1270 if ((!tmp->invisible &&
1271 (inv == NULL || inv->type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) || (!op || QUERY_FLAG (op, FLAG_WIZ)))
1272 items++;
1273 tmp = tmp->below;
1274 }
1275
1276 if (inv == NULL)
1277 { /* player's inventory */
1278 if (items == 0)
1279 {
1280 new_draw_info (NDI_UNIQUE, 0, op, "You carry nothing.");
1281 return;
1282 }
1283 else
1284 {
1285 length = 28;
1286 in = "";
1287 if (op)
1288 clear_win_info (op);
1289 new_draw_info (NDI_UNIQUE, 0, op, "Inventory:");
1290 }
1291 }
1292 else
1293 {
1294 if (items == 0)
1295 return;
1296 else
1297 {
1298 length = 28;
1299 in = " ";
1300 }
1301 }
1302
1303 for (tmp = inv ? inv->inv : op->inv; tmp; tmp = tmp->below)
1304 {
1305 if ((!op || !QUERY_FLAG (op, FLAG_WIZ)) && (tmp->invisible || (inv && inv->type != CONTAINER && !QUERY_FLAG (tmp, FLAG_APPLIED))))
1306 continue;
1307 if ((!op || QUERY_FLAG (op, FLAG_WIZ)))
1308 new_draw_info_format (NDI_UNIQUE, 0, op, "%s- %-*.*s (%5d) %-8s", in, length, length,
1309 query_name (tmp), tmp->count, query_weight (tmp));
1310 else
1311 new_draw_info_format (NDI_UNIQUE, 0, op, "%s- %-*.*s %-8s", in, length + 8, length + 8, query_name (tmp), query_weight (tmp));
1312 }
1313
1314 if (!inv && op)
1315 new_draw_info_format (NDI_UNIQUE, 0, op, "%-*s %-8s", 41, "Total weight :", query_weight (op));
1316} 1205}
1317 1206
1318static void 1207static void
1319display_new_pickup (object *op) 1208display_new_pickup (object *op)
1320{ 1209{
1321 int i = op->contr->mode; 1210 int i = op->contr->mode;
1322 1211
1323 if (!(i & PU_NEWMODE))
1324 return;
1325
1326 new_draw_info_format (NDI_UNIQUE, 0, op, "%d NEWMODE", i & PU_NEWMODE ? 1 : 0);
1327 new_draw_info_format (NDI_UNIQUE, 0, op, "%d DEBUG", i & PU_DEBUG ? 1 : 0); 1212 new_draw_info_format (NDI_UNIQUE, 0, op, "%d DEBUG", i & PU_DEBUG ? 1 : 0);
1328 new_draw_info_format (NDI_UNIQUE, 0, op, "%d INHIBIT", i & PU_INHIBIT ? 1 : 0); 1213 new_draw_info_format (NDI_UNIQUE, 0, op, "%d INHIBIT", i & PU_INHIBIT ? 1 : 0);
1329 new_draw_info_format (NDI_UNIQUE, 0, op, "%d STOP", i & PU_STOP ? 1 : 0); 1214 new_draw_info_format (NDI_UNIQUE, 0, op, "%d STOP", i & PU_STOP ? 1 : 0);
1330 1215
1331 new_draw_info_format (NDI_UNIQUE, 0, op, "%d <= x pickup weight/value RATIO (0==off)", (i & PU_RATIO) * 5); 1216 new_draw_info_format (NDI_UNIQUE, 0, op, "%d <= x pickup weight/value RATIO (0==off)", (i & PU_RATIO) * 5);
1382 }; 1267 };
1383 1268
1384 if (!params) 1269 if (!params)
1385 { 1270 {
1386 /* if the new mode is used, just print the settings */ 1271 /* if the new mode is used, just print the settings */
1387 if (op->contr->mode & PU_NEWMODE)
1388 {
1389 display_new_pickup (op); 1272 display_new_pickup (op);
1390 return 1;
1391 }
1392 if (1)
1393 LOG (llevDebug, "command_pickup: !params\n");
1394 set_pickup_mode (op, (op->contr->mode > 6) ? 0 : op->contr->mode + 1);
1395 return 0; 1273 return 0;
1396 } 1274 }
1397 1275
1398 while (*params == ' ' && *params) 1276 while (*params == ' ' && *params)
1399 params++; 1277 params++;
1405 for (mode = 0; names[mode]; mode++) 1283 for (mode = 0; names[mode]; mode++)
1406 { 1284 {
1407 if (!strcmp (names[mode], params + 1)) 1285 if (!strcmp (names[mode], params + 1))
1408 { 1286 {
1409 i = op->contr->mode; 1287 i = op->contr->mode;
1410 if (!(i & PU_NEWMODE)) 1288
1411 i = PU_NEWMODE;
1412 if (*params == '+') 1289 if (*params == '+')
1413 i = i | modes[mode]; 1290 i = i | modes[mode];
1414 else 1291 else
1415 i = i & ~modes[mode]; 1292 i = i & ~modes[mode];
1293
1416 op->contr->mode = i; 1294 op->contr->mode = i;
1417 display_new_pickup (op); 1295 display_new_pickup (op);
1418 return 1; 1296 return 1;
1419 } 1297 }
1420 } 1298 }
1422 return 1; 1300 return 1;
1423 } 1301 }
1424 1302
1425 if (sscanf (params, "%u", &i) != 1) 1303 if (sscanf (params, "%u", &i) != 1)
1426 { 1304 {
1427 if (1)
1428 LOG (llevDebug, "command_pickup: params==NULL\n");
1429 new_draw_info (NDI_UNIQUE, 0, op, "Usage: pickup <0-7> or <value_density> ."); 1305 new_draw_info (NDI_UNIQUE, 0, op, "Usage: pickup <value_density> or [+-]type.");
1430 return 1; 1306 return 1;
1431 } 1307 }
1432 set_pickup_mode (op, i); 1308
1309 if (i <= PU_RATIO)
1310 i |= op->contr->mode & ~PU_RATIO;
1311
1312 op->contr->mode = i;
1433 1313
1434 return 1; 1314 return 1;
1435}
1436
1437void
1438set_pickup_mode (object *op, int i)
1439{
1440 switch (op->contr->mode = i)
1441 {
1442 case 0:
1443 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Don't pick up.");
1444 break;
1445 case 1:
1446 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item.");
1447 break;
1448 case 2:
1449 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item and stop.");
1450 break;
1451 case 3:
1452 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Stop before picking up.");
1453 break;
1454 case 4:
1455 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items.");
1456 break;
1457 case 5:
1458 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items and stop.");
1459 break;
1460 case 6:
1461 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all magic items.");
1462 break;
1463 case 7:
1464 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all coins and gems");
1465 break;
1466 }
1467} 1315}
1468 1316
1469int 1317int
1470command_search_items (object *op, char *params) 1318command_search_items (object *op, char *params)
1471{ 1319{
1472 char buf[MAX_BUF]; 1320 char buf[MAX_BUF];
1473 1321
1474 if (settings.search_items == FALSE)
1475 return 1;
1476
1477 if (params == NULL) 1322 if (params == NULL)
1478 { 1323 {
1479 if (op->contr->search_str[0] == '\0') 1324 if (op->contr->search_str[0] == '\0')
1480 { 1325 {
1481 new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1"); 1326 new_draw_info (NDI_UNIQUE, 0, op, "Example: search-items magic+1");
1482 new_draw_info (NDI_UNIQUE, 0, op, "Would automatically pick up all"); 1327 new_draw_info (NDI_UNIQUE, 0, op, "Would automatically pick up all");
1483 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'."); 1328 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'.");
1484 return 1; 1329 return 1;
1485 } 1330 }
1486 1331
1488 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); 1333 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off.");
1489 op->update_stats (); 1334 op->update_stats ();
1490 return 1; 1335 return 1;
1491 } 1336 }
1492 1337
1493 if ((int) strlen (params) >= MAX_BUF) 1338 if (strlen (params) >= MAX_BUF)
1494 { 1339 {
1495 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); 1340 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long.");
1496 return 1; 1341 return 1;
1497 } 1342 }
1498 1343
1499 strcpy (op->contr->search_str, params); 1344 strcpy (op->contr->search_str, params);
1500 sprintf (buf, "Searching for '%s'.", op->contr->search_str); 1345 sprintf (buf, "Now searching for '%s'.", op->contr->search_str);
1501 new_draw_info (NDI_UNIQUE, 0, op, buf); 1346 new_draw_info (NDI_UNIQUE, 0, op, buf);
1502 op->update_stats (); 1347 op->update_stats ();
1348
1503 return 1; 1349 return 1;
1504} 1350}
1505 1351

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines