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.52 by root, Sat May 12 20:21:54 2007 UTC vs.
Revision 1.76 by root, Sun Sep 7 21:31:23 2008 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 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 */
90 * Shortcut to find_best_apply_object_match(pl, params, AF_NULL); 88 * Shortcut to find_best_apply_object_match(pl, params, AF_NULL);
91 **/ 89 **/
92object * 90object *
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_NULL); 93 return find_best_apply_object_match (pl, params, AP_TOGGLE);
94}
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 }
96} 113}
97 114
98int 115int
99command_uskill (object *pl, char *params) 116command_uskill (object *pl, char *params)
100{ 117{
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 return change_skill (pl, skill, 0); 146 pl->change_skill (0);
147 apply_special (pl, skill, AP_APPLY);
148 return 1;
130} 149}
131 150
132/* These functions (command_search, command_disarm) are really just wrappers for 151/* These functions (command_search, command_disarm) are really just wrappers for
133 * things like 'use_skill ...'). In fact, they should really be obsoleted 152 * things like 'use_skill ...'). In fact, they should really be obsoleted
134 * and replaced with those. 153 * and replaced with those.
208 * not need to use split_ob and stuff. 227 * not need to use split_ob and stuff.
209 */ 228 */
210int 229int
211sack_can_hold (object *pl, object *sack, object *op, uint32 nrof) 230sack_can_hold (object *pl, object *sack, object *op, uint32 nrof)
212{ 231{
213
214 if (!QUERY_FLAG (sack, FLAG_APPLIED)) 232 if (!QUERY_FLAG (sack, FLAG_APPLIED))
215 { 233 {
216 new_draw_info_format (NDI_UNIQUE, 0, pl, "The %s is not active.", query_name (sack)); 234 new_draw_info_format (NDI_UNIQUE, 0, pl, "The %s is not active.", query_name (sack));
217 return 0; 235 return 0;
218 } 236 }
237
219 if (sack == op) 238 if (sack == op)
220 { 239 {
221 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the %s into itself.", query_name (sack)); 240 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the %s into itself.", query_name (sack));
222 return 0; 241 return 0;
223 } 242 }
243
224 if (sack->race && (sack->race != op->race || op->type == CONTAINER || (sack->stats.food && sack->stats.food != op->type))) 244 if (sack->race && (sack->race != op->race || op->type == CONTAINER || (sack->stats.food && sack->stats.food != op->type)))
225 { 245 {
226 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can put only %s into the %s.", &sack->race, query_name (sack)); 246 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can put only %s into the %s.", &sack->race, query_name (sack));
227 return 0; 247 return 0;
228 } 248 }
249
229 if (op->type == SPECIAL_KEY && sack->slaying && op->slaying) 250 if (op->type == SPECIAL_KEY && sack->slaying && op->slaying)
230 { 251 {
231 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the key into %s.", query_name (sack)); 252 new_draw_info_format (NDI_UNIQUE, 0, pl, "You can't put the key into %s.", query_name (sack));
232 return 0; 253 return 0;
233 } 254 }
255
234 if (sack->weight_limit && (sint32) (sack->carrying + (nrof ? nrof : 1) * 256 if (sack->weight_limit && (sint32) (sack->carrying + (nrof ? nrof : 1) *
235 (op->weight + (op->type == CONTAINER ? (op->carrying * op->stats.Str) : 0)) 257 (op->weight + (op->type == CONTAINER ? (op->carrying * op->stats.Str) : 0))
236 * (100 - sack->stats.Str) / 100) > sack->weight_limit) 258 * (100 - sack->stats.Str) / 100) > sack->weight_limit)
237 { 259 {
238 new_draw_info_format (NDI_UNIQUE, 0, pl, "That won't fit in the %s!", query_name (sack)); 260 new_draw_info_format (NDI_UNIQUE, 0, pl, "That won't fit in the %s!", query_name (sack));
239 return 0; 261 return 0;
240 } 262 }
263
241 /* All other checks pass, must be OK */ 264 /* All other checks pass, must be OK */
242 return 1; 265 return 1;
243} 266}
244 267
245/* Pick up commands follow */ 268/* Pick up commands follow */
250 * pick up (0 means all of them) 273 * pick up (0 means all of them)
251 */ 274 */
252static void 275static void
253pick_up_object (object *pl, object *op, object *tmp, int nrof) 276pick_up_object (object *pl, object *op, object *tmp, int nrof)
254{ 277{
255 /* buf needs to be big (more than 256 chars) because you can get
256 * very long item names.
257 */
258 char buf[HUGE_BUF];
259 object *env = tmp->env; 278 object *env = tmp->env;
260 uint32 weight, effective_weight_limit; 279 uint32 weight, effective_weight_limit;
261 int tmp_nrof = tmp->nrof ? tmp->nrof : 1; 280 int tmp_nrof = tmp->number_of ();
262 281
263 /* IF the player is flying & trying to take the item out of a container 282 /* IF the player is flying & trying to take the item out of a container
264 * that is in his inventory, let him. tmp->env points to the container 283 * that is in his inventory, let him. tmp->env points to the container
265 * (sack, luggage, etc), tmp->env->env then points to the player (nested 284 * (sack, luggage, etc), tmp->env->env then points to the player (nested
266 * containers not allowed as of now) 285 * containers not allowed as of now)
267 */ 286 */
268 if ((pl->move_type & MOVE_FLYING) && !QUERY_FLAG (pl, FLAG_WIZ) && tmp->in_player () != pl) 287 if ((pl->move_type & MOVE_FLYING) && !QUERY_FLAG (pl, FLAG_WIZ) && tmp->in_player () != pl)
269 { 288 {
270 new_draw_info (NDI_UNIQUE, 0, pl, "You are levitating, you can't reach the ground!"); 289 pl->failmsg ("You are levitating, you can't reach the ground! "
290 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
291 "or waiting till the levitation effect wears off.>");
271 return; 292 return;
272 } 293 }
273 294
274 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 295 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
275 return; 296 return;
276 297
277 if (QUERY_FLAG (tmp, FLAG_WAS_WIZ) && !QUERY_FLAG (pl, FLAG_WAS_WIZ))
278 {
279 new_draw_info (NDI_UNIQUE, 0, pl, "The object disappears in a puff of smoke!");
280 new_draw_info (NDI_UNIQUE, 0, pl, "It must have been an illusion.");
281
282 if (pl->contr)
283 esrv_del_item (pl->contr, tmp->count);
284
285 tmp->destroy ();
286 return;
287 }
288
289 if (nrof > tmp_nrof || nrof == 0) 298 if (nrof > tmp_nrof || nrof <= 0)
290 nrof = tmp_nrof; 299 nrof = tmp_nrof;
291 300
292 /* Figure out how much weight this object will add to the player */ 301 /* Figure out how much weight this object will add to the player */
293 weight = tmp->weight * nrof; 302 weight = tmp->weight * nrof;
294 if (tmp->inv) 303 if (tmp->inv)
295 weight += tmp->carrying * (100 - tmp->stats.Str) / 100; 304 weight += tmp->carrying * (100 - tmp->stats.Str) / 100;
296 305
297 if (pl->stats.Str <= MAX_STAT)
298 effective_weight_limit = weight_limit[pl->stats.Str]; 306 effective_weight_limit = weight_limit [min (MAX_STAT, pl->stats.Str)];
299 else
300 effective_weight_limit = weight_limit[MAX_STAT];
301 307
302 if ((pl->weight + pl->carrying + weight) > effective_weight_limit) 308 if ((pl->weight + pl->carrying + weight) > effective_weight_limit)
303 { 309 {
304 new_draw_info (0, 0, pl, "That item is too heavy for you to pick up."); 310 new_draw_info (0, 0, pl, "That item is too heavy for you to pick up.");
305 return; 311 return;
306 } 312 }
307 313
308 if (nrof != tmp_nrof) 314 if (!can_split (pl, tmp, nrof))
309 {
310 object *tmp2 = tmp;
311
312 tmp = get_split_ob (tmp, nrof);
313 if (!tmp)
314 {
315 new_draw_info (NDI_UNIQUE, 0, pl, errmsg);
316 return; 315 return;
317 }
318 316
319 /* Tell the client what happened to the rest of objects */ 317 if (QUERY_FLAG (tmp, FLAG_UNPAID))
320 if (pl->contr) 318 {
321 if (tmp2->destroyed ()) 319 tmp->flag.reset (FLAG_UNPAID);
322 esrv_del_item (pl->contr, tmp2->count); 320 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));
323 else 321 tmp->flag.set (FLAG_UNPAID);
324 esrv_update_item (UPD_NROF, pl, tmp2);
325 } 322 }
326 else 323 else
327 { 324 new_draw_info_format (NDI_UNIQUE, 0, pl, "You pick up the %s.", query_name (tmp));
328 /* If the object is in a container, send a delete to the client.
329 * - we are moving all the items from the container to elsewhere,
330 * so it needs to be deleted.
331 */
332 if (!QUERY_FLAG (tmp, FLAG_REMOVED))
333 {
334 if (tmp->env && pl->type == PLAYER)
335 esrv_del_item (pl->contr, tmp->count);
336 325
337 tmp->remove (); /* Unlink it */ 326 op->insert (tmp);
338 }
339 }
340
341 if (QUERY_FLAG (tmp, FLAG_UNPAID))
342 sprintf (buf, "%s will cost you %s.", query_name (tmp), query_cost_string (tmp, pl, F_BUY | F_SHOP));
343 else
344 sprintf (buf, "You pick up the %s.", query_name (tmp));
345
346 new_draw_info (NDI_UNIQUE, 0, pl, buf);
347
348 tmp = insert_ob_in_ob (tmp, op);
349
350 /* All the stuff below deals with client/server code, and is only
351 * usable by players
352 */
353 if (pl->contr)
354 {
355 esrv_send_item (pl, tmp);
356
357 /* These are needed to update the weight for the container we
358 * are putting the object in.
359 */
360 if (op != pl)
361 {
362 esrv_update_item (UPD_WEIGHT, pl, op);
363 esrv_send_item (pl, pl);
364 }
365
366 /* Update the container the object was in */
367 if (env && env != pl && env != op)
368 esrv_update_item (UPD_WEIGHT, pl, env);
369 }
370} 327}
371 328
372/* modified slightly to allow monsters use this -b.t. 5-31-95 */ 329/* modified slightly to allow monsters use this -b.t. 5-31-95 */
373void 330void
374pick_up (object *op, object *alt) 331pick_up (object *op, object *alt)
384 if (!can_pick (op, alt)) 341 if (!can_pick (op, alt))
385 { 342 {
386 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up the %s.", &alt->name); 343 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up the %s.", &alt->name);
387 goto leave; 344 goto leave;
388 } 345 }
346
389 tmp = alt; 347 tmp = alt;
390 } 348 }
391 else 349 else
392 { 350 {
393 if (op->below == NULL || !can_pick (op, op->below)) 351 if (op->below == NULL || !can_pick (op, op->below))
402 /* Try to catch it. */ 360 /* Try to catch it. */
403 tmp_map = tmp->map; 361 tmp_map = tmp->map;
404 tmp = stop_item (tmp); 362 tmp = stop_item (tmp);
405 if (tmp == NULL) 363 if (tmp == NULL)
406 goto leave; 364 goto leave;
365
407 need_fix_tmp = 1; 366 need_fix_tmp = 1;
408 if (!can_pick (op, tmp)) 367 if (!can_pick (op, tmp))
409 goto leave; 368 goto leave;
410 369
411 if (op->type == PLAYER) 370 if (op->type == PLAYER)
416 } 375 }
417 else 376 else
418 count = tmp->nrof; 377 count = tmp->nrof;
419 378
420 /* container is open, so use it */ 379 /* container is open, so use it */
380 if (tmp->flag [FLAG_STARTEQUIP])
381 alt = op;
421 if (op->container) 382 else if (op->container)
422 { 383 {
423 alt = op->container; 384 alt = op->container;
424 if (alt != tmp->env && !sack_can_hold (op, alt, tmp, count)) 385 if (alt != tmp->env && !sack_can_hold (op, alt, tmp, count))
425 goto leave; 386 goto leave;
426 } 387 }
445 /* here it could be possible to check rent, 406 /* here it could be possible to check rent,
446 * if someone wants to implement it 407 * if someone wants to implement it
447 */ 408 */
448 alt = op; 409 alt = op;
449 } 410 }
411
450#ifdef PICKUP_DEBUG 412#ifdef PICKUP_DEBUG
451 LOG (llevDebug, "Pick_up(): %s picks %s (%d) and inserts it %s.\n", op->name, tmp->name, op->contr->count, alt->name); 413 LOG (llevDebug, "Pick_up(): %s picks %s (%d) and inserts it %s.\n", op->name, tmp->name, op->contr->count, alt->name);
452#endif 414#endif
453 415
454 /* startequip items are not allowed to be put into containers: */ 416 /* startequip items are not allowed to be put into containers: */
504 466
505 /* Makes processing easier */ 467 /* Makes processing easier */
506 if (params && *params == '\0') 468 if (params && *params == '\0')
507 params = 0; 469 params = 0;
508 470
471 int cnt = MAX_ITEM_PER_DROP;
472
509 while (tmp) 473 while (tmp)
510 { 474 {
511 next = tmp->below; 475 next = tmp->below;
512 476
513 if (tmp->invisible) 477 if (tmp->invisible)
519 /* This following two if and else if could be merged into line 483 /* This following two if and else if could be merged into line
520 * but that probably will make it more difficult to read, and 484 * but that probably will make it more difficult to read, and
521 * not make it any more efficient 485 * not make it any more efficient
522 */ 486 */
523 if (params && item_matched_string (op, tmp, params)) 487 if (params && item_matched_string (op, tmp, params))
488 {
489 if (--cnt < 0) break;
524 pick_up (op, tmp); 490 pick_up (op, tmp);
491 }
525 else if (can_pick (op, tmp) && !params) 492 else if (can_pick (op, tmp) && !params)
526 { 493 {
494 if (--cnt < 0) break;
527 pick_up (op, tmp); 495 pick_up (op, tmp);
528 break; 496 break;
529 } 497 }
530 498
531 tmp = next; 499 tmp = next;
500 }
501
502 if (cnt < 0)
503 {
504 op->failmsg ("Couldn't pick up so many items at once.");
505 return 0;
532 } 506 }
533 507
534 if (!params && !tmp) 508 if (!params && !tmp)
535 { 509 {
536 for (tmp = op->below; tmp; tmp = tmp->below) 510 for (tmp = op->below; tmp; tmp = tmp->below)
537 if (!tmp->invisible) 511 if (!tmp->invisible)
538 { 512 {
539 char buf[MAX_BUF];
540
541 sprintf (buf, "You can't pick up a %s.", &tmp->name); 513 new_draw_info_format (NDI_UNIQUE, 0, op, "You can't pick up a %s.", &tmp->name);
542 new_draw_info (NDI_UNIQUE, 0, op, buf);
543 break; 514 break;
544 } 515 }
545 516
546 if (!tmp) 517 if (!tmp)
547 new_draw_info (NDI_UNIQUE, 0, op, "There is nothing to pick up."); 518 new_draw_info (NDI_UNIQUE, 0, op, "There is nothing to pick up.");
548 } 519 }
549 520
550 return 0; 521 return 0;
551} 522}
552
553 523
554/* 524/*
555 * This function was part of drop, now is own function. 525 * This function was part of drop, now is own function.
556 * Player 'op' tries to put object 'tmp' into sack 'sack', 526 * Player 'op' tries to put object 'tmp' into sack 'sack',
557 * 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.
573 return; 543 return;
574 } 544 }
575 545
576 if (tmp->type == CONTAINER && tmp->inv) 546 if (tmp->type == CONTAINER && tmp->inv)
577 { 547 {
578
579 /* Eneq(@csd.uu.se): If the object to be dropped is a container 548 /* Eneq(@csd.uu.se): If the object to be dropped is a container
580 * we instead move the contents of that container into the active 549 * we instead move the contents of that container into the active
581 * container, this is only done if the object has something in it. 550 * container, this is only done if the object has something in it.
582 */ 551 */
583 sack2 = tmp; 552 sack2 = tmp;
586 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp) 555 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp)
587 { 556 {
588 tmp = tmp2->below; 557 tmp = tmp2->below;
589 558
590 if ((sack->type == CONTAINER && sack_can_hold (op, op->container, tmp2, tmp2->nrof))) 559 if ((sack->type == CONTAINER && sack_can_hold (op, op->container, tmp2, tmp2->nrof)))
591 {
592 put_object_in_sack (op, sack, tmp2, 0); 560 put_object_in_sack (op, sack, tmp2, 0);
593 }
594 else 561 else
595 { 562 {
596 sprintf (buf, "Your %s fills up.", query_name (sack)); 563 sprintf (buf, "Your %s fills up.", query_name (sack));
597 new_draw_info (NDI_UNIQUE, 0, op, buf); 564 new_draw_info (NDI_UNIQUE, 0, op, buf);
598 break; 565 break;
599 } 566 }
600 } 567 }
601 568
602 esrv_update_item (UPD_WEIGHT, op, sack2);
603 return; 569 return;
604 } 570 }
605 571
606 /* Don't worry about this for containers - our caller should have 572 /* Don't worry about this for containers - our caller should have
607 * already checked this. 573 * already checked this.
612 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 578 if (QUERY_FLAG (tmp, FLAG_APPLIED))
613 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 579 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
614 return; 580 return;
615 581
616 /* we want to put some portion of the item into the container */ 582 /* we want to put some portion of the item into the container */
617 if (nrof && tmp->nrof != nrof) 583 if (!can_split (op, tmp, nrof))
618 {
619 object *tmp2 = tmp;
620
621 tmp = get_split_ob (tmp, nrof);
622
623 if (!tmp)
624 {
625 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
626 return; 584 return;
627 }
628 /* Tell a client what happened other objects */
629 if (tmp2->destroyed ())
630 esrv_del_item (op->contr, tmp2->count);
631 else /* this can proably be replaced with an update */
632 esrv_send_item (op, tmp2);
633 }
634 else
635 tmp->remove ();
636 585
637 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack)); 586 new_draw_info_format (NDI_UNIQUE, 0, op, "You put the %s in %s.", query_name (tmp), query_name (sack));
638 tmp2 = insert_ob_in_ob (tmp, sack); 587 sack->insert (tmp);
639 op->update_stats (); /* This is overkill, fix_player() is called somewhere */
640 /* in object.c */
641
642 /* If an object merged (and thus, different object), we need to
643 * delete the original.
644 */
645 if (tmp2 != tmp)
646 esrv_del_item (op->contr, tmp->count);
647
648 esrv_send_item (op, tmp2);
649
650 /* update the sacks weight */
651 esrv_update_item (UPD_WEIGHT, op, sack);
652} 588}
653 589
654/* 590/*
655 * This function was part of drop, now is own function. 591 * This function was part of drop, now is own function.
656 * Player 'op' tries to drop object 'tmp', if tmp is non zero, then 592 * Player 'op' tries to drop object 'tmp', if tmp is non zero, then
658 * This is used when dropping objects onto the floor. 594 * This is used when dropping objects onto the floor.
659 */ 595 */
660void 596void
661drop_object (object *op, object *tmp, uint32 nrof) 597drop_object (object *op, object *tmp, uint32 nrof)
662{ 598{
663 char buf[MAX_BUF];
664 object *floor;
665
666 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 599 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
667 return; 600 return;
668 601
669 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 602 if (QUERY_FLAG (tmp, FLAG_APPLIED))
670 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE)) 603 if (apply_special (op, tmp, AP_UNAPPLY | AP_NO_MERGE))
673 //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D 606 //fprintf (stderr, "ui, on space is %ld\n", op->ms ().volume ());//D
674 607
675 /* We are only dropping some of the items. We split the current object 608 /* We are only dropping some of the items. We split the current object
676 * off 609 * off
677 */ 610 */
678 if (nrof && tmp->nrof != nrof) 611 if (!can_split (op, tmp, nrof))
679 {
680 object *tmp2 = tmp;
681
682 tmp = get_split_ob (tmp, nrof);
683 if (!tmp)
684 {
685 new_draw_info (NDI_UNIQUE, 0, op, errmsg);
686 return;
687 }
688 /* Tell a client what happened rest of objects. tmp2 is now the
689 * original object
690 */
691 if (op->type == PLAYER)
692 {
693 if (tmp2->destroyed ())
694 esrv_del_item (op->contr, tmp2->count);
695 else
696 esrv_send_item (op, tmp2);
697 }
698 }
699 else
700 tmp->remove ();
701 612
702 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op))) 613 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op)))
703 return; 614 return;
704 615
705 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 616 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP))
706 { 617 {
707 sprintf (buf, "You drop the %s.", query_name (tmp)); 618 op->statusmsg (format ("You drop the %s.", query_name (tmp)));
708 new_draw_info (NDI_UNIQUE, 0, op, buf); 619 op->statusmsg ("The gods who lent it to you retrieves it.");
709 new_draw_info (NDI_UNIQUE, 0, op, "The gods who lent it to you retrieves it.");
710
711 if (op->type == PLAYER)
712 esrv_del_item (op->contr, tmp->count);
713 620
714 tmp->destroy (); 621 tmp->destroy ();
715 op->update_stats (); 622 op->update_stats ();
716 return; 623 return;
717 } 624 }
718 625
719 if (op->type == PLAYER)
720 esrv_del_item (op->contr, tmp->count);
721
722 /* Call this before we update the various windows/players. At least 626 /* Call this before we update the various windows/players. At least
723 * that we, we know the weight is correct. 627 * that we, we know the weight is correct.
724 */ 628 */
725 op->update_stats (); /* This is overkill, fix_player() is called somewhere */ 629 // 2007-11-26: moved op->update_stats away and calling it later after
726 /* in object.c */ 630 // all items of a drop command have been processed.
727 631
728 if (op->type == PLAYER)
729 {
730 /* Need to update the weight for the player */
731 esrv_send_item (op, op);
732 op->contr->ns->floorbox_update ();
733 }
734
735 for (floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above) 632 for (object *floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above)
736 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) 633 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op)))
737 return; 634 return;
738 635
739 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY) 636 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
637 {
740 sell_item (tmp, op); 638 if (!sell_item (tmp, op))
639 return; // if we can't sell it we don't drop it
640 }
741 641
742 tmp->x = op->x; 642 tmp->x = op->x;
743 tmp->y = op->y; 643 tmp->y = op->y;
744 644
745 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); 645 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR);
765 tmp->destroy (); 665 tmp->destroy ();
766 return; 666 return;
767 } 667 }
768 else 668 else
769 { 669 {
770 while (tmp != NULL && tmp->invisible) 670 while (tmp && tmp->invisible)
771 tmp = tmp->below; 671 tmp = tmp->below;
772 } 672 }
773 } 673 }
774 674
775 if (tmp == NULL) 675 if (tmp == NULL)
776 { 676 {
777 new_draw_info (NDI_UNIQUE, 0, op, "You don't have anything to drop."); 677 new_draw_info (NDI_UNIQUE, 0, op, "You don't have anything to drop.");
778 return; 678 return;
779 } 679 }
680
780 if (QUERY_FLAG (tmp, FLAG_INV_LOCKED)) 681 if (QUERY_FLAG (tmp, FLAG_INV_LOCKED))
781 { 682 {
782 new_draw_info (NDI_UNIQUE, 0, op, "This item is locked"); 683 new_draw_info (NDI_UNIQUE, 0, op, "This item is locked");
783 return; 684 return;
784 } 685 }
686
785 if (QUERY_FLAG (tmp, FLAG_NO_DROP)) 687 if (QUERY_FLAG (tmp, FLAG_NO_DROP))
786 { 688 {
787#if 0 689#if 0
788 /* Eneq(@csd.uu.se): Objects with NO_DROP defined can't be dropped. */ 690 /* Eneq(@csd.uu.se): Objects with NO_DROP defined can't be dropped. */
789 new_draw_info (NDI_UNIQUE, 0, op, "This item can't be dropped."); 691 new_draw_info (NDI_UNIQUE, 0, op, "This item can't be dropped.");
813 715
814 if (op->type == PLAYER) 716 if (op->type == PLAYER)
815 op->contr->count = 0; 717 op->contr->count = 0;
816} 718}
817 719
818
819
820/* Command will drop all items that have not been locked */ 720/* Command will drop all items that have not been locked */
821int 721int
822command_dropall (object *op, char *params) 722command_dropall (object *op, char *params)
823{ 723{
824 724
825 object *curinv, *nextinv;
826
827 if (op->inv == NULL) 725 if (op->inv == NULL)
828 { 726 {
829 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop!"); 727 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop!");
830 return 0; 728 return 0;
831 } 729 }
832 730
833 curinv = op->inv; 731 object *curinv = op->inv;
732 object *nextinv;
834 733
835 /* 734 /*
836 This is the default. Drops everything not locked or considered 735 This is the default. Drops everything not locked or considered
837 not something that should be dropped. 736 not something that should be dropped.
838 */ 737 */
840 Care must be taken that the next item pointer is not to money as 739 Care must be taken that the next item pointer is not to money as
841 the drop() routine will do unknown things to it when dropping 740 the drop() routine will do unknown things to it when dropping
842 in a shop. --Tero.Pelander@utu.fi 741 in a shop. --Tero.Pelander@utu.fi
843 */ 742 */
844 743
845 if (params == NULL) 744 int cnt = MAX_ITEM_PER_DROP;
745
746 if (!params)
846 { 747 {
847 while (curinv != NULL) 748 while (curinv)
848 { 749 {
849 nextinv = curinv->below; 750 nextinv = curinv->below;
751
850 while (nextinv && nextinv->type == MONEY) 752 while (nextinv && nextinv->type == MONEY)
851 nextinv = nextinv->below; 753 nextinv = nextinv->below;
754
852 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY && 755 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && curinv->type != MONEY &&
853 curinv->type != FOOD && curinv->type != KEY && 756 curinv->type != FOOD && curinv->type != KEY &&
854 curinv->type != SPECIAL_KEY && curinv->type != GEM && 757 curinv->type != SPECIAL_KEY && curinv->type != GEM &&
855 !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv)) 758 !curinv->invisible && (curinv->type != CONTAINER || op->container != curinv))
856 { 759 {
857 drop (op, curinv); 760 drop (op, curinv);
761 if (--cnt <= 0) break;
858 } 762 }
763
859 curinv = nextinv; 764 curinv = nextinv;
860 } 765 }
861 } 766 }
862
863 else if (strcmp (params, "weapons") == 0) 767 else if (strcmp (params, "weapons") == 0)
864 { 768 {
865 while (curinv != NULL) 769 while (curinv)
866 { 770 {
867 nextinv = curinv->below; 771 nextinv = curinv->below;
772
868 while (nextinv && nextinv->type == MONEY) 773 while (nextinv && nextinv->type == MONEY)
869 nextinv = nextinv->below; 774 nextinv = nextinv->below;
775
870 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == WEAPON) || (curinv->type == BOW) || (curinv->type == ARROW))) 776 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == WEAPON) || (curinv->type == BOW) || (curinv->type == ARROW)))
871 { 777 {
872 drop (op, curinv); 778 drop (op, curinv);
779 if (--cnt <= 0) break;
873 } 780 }
781
874 curinv = nextinv; 782 curinv = nextinv;
875 } 783 }
876 } 784 }
877
878 else if (strcmp (params, "armor") == 0 || strcmp (params, "armour") == 0) 785 else if (strcmp (params, "armor") == 0 || strcmp (params, "armour") == 0)
879 { 786 {
880 while (curinv != NULL) 787 while (curinv)
881 { 788 {
882 nextinv = curinv->below; 789 nextinv = curinv->below;
790
883 while (nextinv && nextinv->type == MONEY) 791 while (nextinv && nextinv->type == MONEY)
884 nextinv = nextinv->below; 792 nextinv = nextinv->below;
793
885 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == ARMOUR) || curinv->type == SHIELD || curinv->type == HELMET)) 794 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && ((curinv->type == ARMOUR) || curinv->type == SHIELD || curinv->type == HELMET))
886 { 795 {
887 drop (op, curinv); 796 drop (op, curinv);
797 if (--cnt <= 0) break;
888 } 798 }
799
889 curinv = nextinv; 800 curinv = nextinv;
890 } 801 }
891 } 802 }
892
893 else if (strcmp (params, "misc") == 0) 803 else if (strcmp (params, "misc") == 0)
894 { 804 {
895 while (curinv != NULL) 805 while (curinv)
896 { 806 {
897 nextinv = curinv->below; 807 nextinv = curinv->below;
808
898 while (nextinv && nextinv->type == MONEY) 809 while (nextinv && nextinv->type == MONEY)
899 nextinv = nextinv->below; 810 nextinv = nextinv->below;
811
900 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && !QUERY_FLAG (curinv, FLAG_APPLIED)) 812 if (!QUERY_FLAG (curinv, FLAG_INV_LOCKED) && !QUERY_FLAG (curinv, FLAG_APPLIED))
901 { 813 {
902 switch (curinv->type) 814 switch (curinv->type)
903 { 815 {
904 case HORN: 816 case HORN:
922 break; 834 break;
923 default: 835 default:
924 curinv = nextinv; 836 curinv = nextinv;
925 break; 837 break;
926 } 838 }
839
840 if (--cnt <= 0) break;
927 } 841 }
842
928 curinv = nextinv; 843 curinv = nextinv;
929 } 844 }
930 } 845 }
931 846
932 op->contr->ns->floorbox_update (); 847 if (cnt <= 0)
848 op->failmsg ("Only dropped some items, can't drop that many items at once.");
933 849
934/* draw_look(op);*/ 850/* draw_look(op);*/
935 return 0; 851 return 0;
936} 852}
937 853
938/* Object op wants to drop object(s) params. params can be a 854/* Object op wants to drop object(s) params. params can be a
939 * comma seperated list. 855 * comma seperated list.
940 */ 856 */
941
942int 857int
943command_drop (object *op, char *params) 858command_drop (object *op, char *params)
944{ 859{
945 object *tmp, *next; 860 object *tmp, *next;
946 int did_one = 0; 861 int did_one = 0;
950 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); 865 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?");
951 return 0; 866 return 0;
952 } 867 }
953 else 868 else
954 { 869 {
870 int cnt = MAX_ITEM_PER_DROP;
871
955 for (tmp = op->inv; tmp; tmp = next) 872 for (tmp = op->inv; tmp; tmp = next)
956 { 873 {
957 next = tmp->below; 874 next = tmp->below;
958 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) 875 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible)
959 continue; 876 continue;
877
960 if (item_matched_string (op, tmp, params)) 878 if (item_matched_string (op, tmp, params))
961 { 879 {
962 drop (op, tmp); 880 drop (op, tmp);
881 if (--cnt <= 0) break;
963 did_one = 1; 882 did_one = 1;
964 } 883 }
965 } 884 }
885
966 if (!did_one) 886 if (!did_one)
967 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 887 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
968 } 888
969 if (op->type == PLAYER) 889 if (cnt <= 0)
970 { 890 op->failmsg ("Only dropped some items, can't drop that many items at once.");
971 op->contr->count = 0;
972 op->contr->ns->floorbox_update ();
973 }; 891 }
974 892
975/* draw_look(op);*/
976 return 0; 893 return 0;
977} 894}
978 895
979int 896int
980command_examine (object *op, char *params) 897command_examine (object *op, char *params)
983 { 900 {
984 object *tmp = op->below; 901 object *tmp = op->below;
985 902
986 while (tmp && !tmp->client_visible ()) 903 while (tmp && !tmp->client_visible ())
987 tmp = tmp->below; 904 tmp = tmp->below;
905
988 if (tmp) 906 if (tmp)
989 examine (op, tmp); 907 examine (op, tmp);
990 } 908 }
991 else 909 else
992 { 910 {
993 object *tmp = find_best_object_match (op, params); 911 object *tmp = find_best_object_match (op, params);
994 912
995 if (tmp) 913 if (tmp)
996 examine (op, tmp); 914 examine (op, tmp);
997 else 915 else
998 new_draw_info_format (NDI_UNIQUE, 0, op, "Could not find an object that matches %s", params); 916 op->contr->infobox (MSG_CHANNEL ("examine"), format ("Could not find an object that matches %s", params));
999 } 917 }
918
1000 return 0; 919 return 0;
1001} 920}
1002 921
1003/* op should be a player. 922/* op should be a player.
1004 * we return the object the player has marked with the 'mark' command 923 * we return the object the player has marked with the 'mark' command
1051 dynbuf_text buf (512, 512); 970 dynbuf_text buf (512, 512);
1052 971
1053 object *mon = head ? head : this; 972 object *mon = head ? head : this;
1054 973
1055 if (QUERY_FLAG (mon, FLAG_UNDEAD)) 974 if (QUERY_FLAG (mon, FLAG_UNDEAD))
1056 buf << "It is an undead force.\n"; 975 buf << " - It is an undead force.\n";
1057 976
1058 if (mon->level > who->level) 977 if (mon->level > who->level)
1059 buf << "It is likely more powerful than you.\n"; 978 buf << " - It is likely more powerful than you.\n";
1060 else if (mon->level < who->level) 979 else if (mon->level < who->level)
1061 buf << "It is likely less powerful than you.\n"; 980 buf << " - It is likely less powerful than you.\n";
1062 else 981 else
1063 buf << "It is probably as powerful as you.\n"; 982 buf << " - It is probably as powerful as you.\n";
1064 983
1065 if (mon->attacktype & AT_ACID) 984 if (mon->attacktype & AT_ACID)
1066 buf << "You seem to smell an acrid odor.\n"; 985 buf << " - You seem to smell an acrid odor.\n";
1067 986
1068 /* Anyone know why this used to use the clone value instead of the 987 /* Anyone know why this used to use the clone value instead of the
1069 * maxhp field? This seems that it should give more accurate results. 988 * maxhp field? This seems that it should give more accurate results.
1070 */ 989 */
1071 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1)) 990 switch ((mon->stats.hp + 1) * 4 / (mon->stats.maxhp + 1))
1072 { /* From 1-4 */ 991 { /* From 1-4 */
1073 case 1: 992 case 1:
1074 buf << "It is in a bad shape.\n"; 993 buf << " - It is in a bad shape.\n";
1075 break; 994 break;
1076 case 2: 995 case 2:
1077 buf << "It is hurt.\n"; 996 buf << " - It is hurt.\n";
1078 break; 997 break;
1079 case 3: 998 case 3:
1080 buf << "It is somewhat hurt.\n"; 999 buf << " - It is somewhat hurt.\n";
1081 break; 1000 break;
1082 case 4: 1001 case 4:
1083 buf << "It is in excellent shape.\n"; 1002 buf << " - It is in excellent shape.\n";
1084 break; 1003 break;
1085 } 1004 }
1086 1005
1087 if (present_in_ob (POISONING, mon)) 1006 if (present_in_ob (POISONING, mon))
1088 buf << "It looks very ill.\n"; 1007 buf << " - It looks very ill.\n";
1089 1008
1090 return buf; 1009 return buf;
1091} 1010}
1092 1011
1093/* tmp is the object being described, pl is who is examing it. */ 1012/* tmp is the object being described, pl is who is examing it. */
1151std::string 1070std::string
1152object::describe (object *who) 1071object::describe (object *who)
1153{ 1072{
1154 dynbuf_text buf (1024, 1024); 1073 dynbuf_text buf (1024, 1024);
1155 1074
1156 buf.printf ("That is: %s.\n", long_desc (who).c_str ()); 1075 buf.printf ("That is: %s.\n\n", long_desc (who).c_str ());
1157 1076
1158 if (custom_name) 1077 if (custom_name)
1159 buf,printf ("You call it %s\n", &custom_name); 1078 buf.printf ("You call it %s.\n\n", &custom_name);
1160 1079
1161 switch (type) 1080 switch (type)
1162 { 1081 {
1163 case SPELLBOOK: 1082 case SPELLBOOK:
1164 if (flag [FLAG_IDENTIFIED] && inv) 1083 if (flag [FLAG_IDENTIFIED] && inv)
1165 buf.printf ("%s is a %s %s spell\n", &inv->name, get_levelnumber (inv->level), &inv->skill); 1084 buf.printf ("%s is a %s %s spell.\n", &inv->name, get_levelnumber (inv->level), &inv->skill);
1166 break; 1085 break;
1167 1086
1168 case BOOK: 1087 case BOOK:
1169 if (msg) 1088 if (msg)
1170 buf << "Something is written in it.\n"; 1089 buf << "Something is written in it.\n";
1229 buf << "This is a buildable item.\n"; 1148 buf << "This is a buildable item.\n";
1230 1149
1231 /* Does the object have a message? Don't show message for all object 1150 /* Does the object have a message? Don't show message for all object
1232 * types - especially if the first entry is a match 1151 * types - especially if the first entry is a match
1233 */ 1152 */
1234 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && strncasecmp (msg, "@match", 7)) 1153 if (msg && type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ())
1235 { 1154 {
1236 /* This is just a hack so when identifying the items, we print 1155 /* This is just a hack so when identifying the items, we print
1237 * out the extra message 1156 * out the extra message
1238 */ 1157 */
1239 if (need_identify (this) && flag [FLAG_IDENTIFIED]) 1158 if (need_identify (this) && flag [FLAG_IDENTIFIED])
1240 buf << "The object has a story:\n"; 1159 buf << "The object has a story:\n\n";
1241 1160
1242 buf << msg << '\n'; 1161 buf << msg << '\n';
1243 } 1162 }
1244 1163
1245 buf << '\n'; 1164 buf << '\n';
1246 1165
1247 return std::string (buf.linearise (), buf.size ()); 1166 return std::string (buf.linearise (), buf.size ());
1248}
1249
1250void
1251examine (object *op, object *tmp)
1252{
1253 std::string s = tmp->describe (op);
1254
1255 new_draw_info (NDI_UNIQUE, 0, op, s.c_str ());
1256}
1257
1258/*
1259 * inventory prints object's inventory. If inv==NULL then print player's
1260 * inventory.
1261 * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ]
1262 */
1263void
1264inventory (object *op, object *inv)
1265{
1266 object *tmp;
1267 const char *in;
1268 int items = 0, length;
1269
1270 if (inv == NULL && op == NULL)
1271 {
1272 new_draw_info (NDI_UNIQUE, 0, op, "Inventory of what object?");
1273 return;
1274 }
1275
1276 tmp = inv ? inv->inv : op->inv;
1277
1278 while (tmp)
1279 {
1280 if ((!tmp->invisible &&
1281 (inv == NULL || inv->type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) || (!op || QUERY_FLAG (op, FLAG_WIZ)))
1282 items++;
1283 tmp = tmp->below;
1284 }
1285
1286 if (inv == NULL)
1287 { /* player's inventory */
1288 if (items == 0)
1289 {
1290 new_draw_info (NDI_UNIQUE, 0, op, "You carry nothing.");
1291 return;
1292 }
1293 else
1294 {
1295 length = 28;
1296 in = "";
1297 if (op)
1298 clear_win_info (op);
1299 new_draw_info (NDI_UNIQUE, 0, op, "Inventory:");
1300 }
1301 }
1302 else
1303 {
1304 if (items == 0)
1305 return;
1306 else
1307 {
1308 length = 28;
1309 in = " ";
1310 }
1311 }
1312
1313 for (tmp = inv ? inv->inv : op->inv; tmp; tmp = tmp->below)
1314 {
1315 if ((!op || !QUERY_FLAG (op, FLAG_WIZ)) && (tmp->invisible || (inv && inv->type != CONTAINER && !QUERY_FLAG (tmp, FLAG_APPLIED))))
1316 continue;
1317 if ((!op || QUERY_FLAG (op, FLAG_WIZ)))
1318 new_draw_info_format (NDI_UNIQUE, 0, op, "%s- %-*.*s (%5d) %-8s", in, length, length,
1319 query_name (tmp), tmp->count, query_weight (tmp));
1320 else
1321 new_draw_info_format (NDI_UNIQUE, 0, op, "%s- %-*.*s %-8s", in, length + 8, length + 8, query_name (tmp), query_weight (tmp));
1322 }
1323
1324 if (!inv && op)
1325 new_draw_info_format (NDI_UNIQUE, 0, op, "%-*s %-8s", 41, "Total weight :", query_weight (op));
1326} 1167}
1327 1168
1328static void 1169static void
1329display_new_pickup (object *op) 1170display_new_pickup (object *op)
1330{ 1171{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines