Debian Codegraph @

server/c_object.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13 /**
14 * @file
15 * Object commands, including picking/dropping, locking, etc.
16 * @todo clean multiple variations of same stuff (pickup and such), or rename for less confusion.
17 */
18
19 #include "global.h"
20
21 #include <ctype.h>
22 #include <math.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "living.h"
27 #include "loader.h"
28 #include "shop.h"
29 #include "skills.h"
30 #include "sproto.h"
31
32 static void set_pickup_mode(const object *op, int i);
33
34 /*
35 * Object id parsing functions
36 */
37
38 /**
39 * Search from start and through below for what matches best with params.
40 * we use object_matches_string above - this gives us consistent behaviour
41 * between many commands. Return the best match, or NULL if no match.
42 *
43 * @param start
44 * first object to start searching at.
45 * @param pl
46 * what object we're searching for.
47 * @param params
48 * what to search for.
49 * @param aflag
50 * Either 0 or AP_APPLY or AP_UNAPPLY. Used with apply -u, and apply -a to
51 * only unapply applied, or apply unapplied objects.
52 * @return
53 * matching object, or NULL if no suitable.
54 **/
55 static object *find_best_apply_object_match(object *start, object *pl, const char *params, int aflag) {
56 object *tmp, *best = NULL;
57 int match_val = 0, tmpmatch;
58
59 tmp = start;
60 FOR_OB_AND_BELOW_PREPARE(tmp) {
61 if (tmp->invisible)
62 continue;
63 if (aflag == AP_APPLY && QUERY_FLAG(tmp, FLAG_APPLIED))
64 continue;
65 if (aflag == AP_UNAPPLY && !QUERY_FLAG(tmp, FLAG_APPLIED))
66 continue;
67 tmpmatch = object_matches_string(pl, tmp, params);
68 if (tmpmatch > match_val) {
69 match_val = tmpmatch;
70 best = tmp;
71 }
72 } FOR_OB_AND_BELOW_FINISH();
73 return best;
74 }
75
76 /**
77 * Shortcut to find_best_apply_object_match(pl->inv, pl, params, AF_NULL);
78 *
79 * @param pl
80 * who to search an item for.
81 * @param params
82 * what to search for.
83 * @return
84 * matching object, or NULL if no suitable.
85 **/
86 static object *find_best_object_match(object *pl, const char *params) {
87 return find_best_apply_object_match(pl->inv, pl, params, AP_NULL);
88 }
89
90 /**
91 * 'use_skill' command.
92 *
93 * @param pl
94 * player.
95 * @param params
96 * skill to use, and optional parameters.
97 */
98 void command_uskill(object *pl, const char *params) {
99 if (*params == '\0') {
100 draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
101 "Usage: use_skill <skill name>");
102 return;
103 }
104 use_skill(pl, params);
105 }
106
107 /**
108 * 'ready_skill' command.
109 *
110 * @param pl
111 * player.
112 * @param params
113 * skill name.
114 */
115 void command_rskill(object *pl, const char *params) {
116 object *skill;
117
118 if (*params == '\0') {
119 draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
120 "Usage: ready_skill <skill name>");
121 return;
122 }
123 skill = find_skill_by_name(pl, params);
124
125 if (!skill) {
126 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_MISSING,
127 "You have no knowledge of the skill %s",
128 params);
129 return;
130 }
131 change_skill(pl, skill, 0);
132 }
133
134 /**
135 * Attempt to use a skill from its subtype. If multiple skills share the same,
136 * the first found is used.
137 * @param op who is applying a skill.
138 * @param skill_subtype skill subtype.
139 * @param params additional parameters to the skill.
140 * @param missing_message message to display if op doesn't know the skill.
141 */
142 static void do_skill_by_number(object *op, int skill_subtype, const char *params,
143 const char *missing_message) {
144 object *skop = find_skill_by_number(op, skill_subtype);
145 if (skop) {
146 do_skill(op, op, skop, op->facing, *params == '\0' ? NULL : params);
147 return;
148 }
149
150 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_MISSING,
151 missing_message);
152 }
153
154 /* These functions (command_search, command_disarm) are really juse wrappers for
155 * things like 'use_skill ...'). In fact, they should really be obsoleted
156 * and replaced with those.
157 */
158 /**
159 * 'search' command.
160 *
161 * @param op
162 * player.
163 * @param params
164 * unused.
165 */
166 void command_search(object *op, const char *params) {
167 do_skill_by_number(op, SK_FIND_TRAPS, params, "You don't know how to search for unusual things.");
168 }
169
170 /**
171 * 'disarm' command.
172 *
173 * @param op
174 * player.
175 * @param params
176 * unused.
177 */
178 void command_disarm(object *op, const char *params) {
179 do_skill_by_number(op, SK_DISARM_TRAPS, params, "You don't know how to disarm traps.");
180 }
181
182 /**
183 * 'throw' command.
184 *
185 * A little special because we do want to pass the full params along
186 * as it includes the object to throw.
187 *
188 * @param op
189 * player.
190 * @param params
191 * what to throw.
192 */
193 void command_throw(object *op, const char *params) {
194 do_skill_by_number(op, SK_THROWING, params, "You have no knowledge of the skill throwing.");
195 }
196
197 /**
198 * 'apply' command.
199 *
200 * @param op
201 * player.
202 * @param params
203 * what to apply.
204 */
205 void command_apply(object *op, const char *params) {
206 int aflag = 0;
207 object *inv = op->inv;
208 object *item;
209
210 if (*params == '\0') {
211 apply_by_living_below(op);
212 return;
213 }
214
215 while (*params == ' ')
216 params++;
217 if (!strncmp(params, "-a ", 3)) {
218 aflag = AP_APPLY;
219 params += 3;
220 }
221 if (!strncmp(params, "-u ", 3)) {
222 aflag = AP_UNAPPLY;
223 params += 3;
224 }
225 if (!strncmp(params, "-o ", 3)) {
226 aflag = AP_OPEN;
227 params += 3;
228 }
229 if (!strncmp(params, "-b ", 3)) {
230 params += 3;
231 if (op->container)
232 inv = op->container->inv;
233 else {
234 inv = op;
235 while (inv->above)
236 inv = inv->above;
237 }
238 }
239 while (*params == ' ')
240 params++;
241
242 item = find_best_apply_object_match(inv, op, params, aflag);
243 if (item == NULL)
244 item = find_best_apply_object_match(inv, op, params, AP_NULL);
245 if (item) {
246 apply_by_living(op, item, aflag, 0);
247 } else
248 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
249 "Could not find any match to the %s.",
250 params);
251 }
252
253 /**
254 * Check if an item op can be put into a sack. If pl exists then tell
255 * a player the reason of failure.
256 *
257 * @param pl
258 * player.
259 * @param sack
260 * container to try to put into.
261 * @param op
262 * what to put in the sack.
263 * @param nrof
264 * number of objects (op) we want to put in. We specify it separately instead of
265 * using op->nrof because often times, a player may have specified a
266 * certain number of objects to drop, so we can pass that number, and
267 * not need to use split_ob() and stuff.
268 * @return
269 * 1 if it will fit, 0 if it will not.
270 */
271 int sack_can_hold(const object *pl, const object *sack, const object *op, uint32_t nrof) {
272 char name[MAX_BUF];
273 query_name(sack, name, MAX_BUF);
274
275 if (!QUERY_FLAG(sack, FLAG_APPLIED)) {
276 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
277 "The %s is not active.",
278 name);
279 return 0;
280 }
281 if (sack == op) {
282 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
283 "You can't put the %s into itself.",
284 name);
285 return 0;
286 }
287 if (sack->race
288 && (sack->race != op->race || op->type == CONTAINER || (sack->stats.food && sack->stats.food != op->type))) {
289 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
290 "You can put only %s into the %s.",
291 sack->race, name);
292 return 0;
293 }
294 if (op->type == SPECIAL_KEY && sack->slaying && op->slaying) {
295 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
296 "You can't put the key into %s.",
297 name);
298 return 0;
299 }
300 if (sack->weight_limit) {
301 int32_t new_weight;
302
303 new_weight = sack->carrying+(nrof ? nrof : 1)
304 *(op->weight+(op->type == CONTAINER ? op->carrying*op->stats.Str : 0))
305 *(100-sack->stats.Str)/100;
306 if (new_weight > sack->weight_limit) {
307 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
308 "That won't fit in the %s!",
309 name);
310 return 0;
311 }
312 }
313 /* All other checks pass, must be OK */
314 return 1;
315 }
316
317 /**
318 * Try to pick up some item.
319 *
320 * @param pl
321 * object (player or monster) picking up.
322 * @param op
323 * object to put tmp into.
324 * @param tmp
325 * object to pick up.
326 * @param nrof
327 * number of tmp to pick up (0 means all of them).
328 */
329 static void pick_up_object(object *pl, object *op, object *tmp, int nrof) {
330 /* buf needs to be big (more than 256 chars) because you can get
331 * very long item names.
332 */
333 char buf[HUGE_BUF], name[MAX_BUF];
334 object *env = tmp->env;
335 uint32_t weight, effective_weight_limit;
336 const int tmp_nrof = NROF(tmp);
337 tag_t tag;
338 mapstruct* map = tmp->map;
339 int16_t x = tmp->x, y = tmp->y;
340
341 /* IF the player is flying & trying to take the item out of a container
342 * that is in his inventory, let him. tmp->env points to the container
343 * (sack, luggage, etc), tmp->env->env then points to the player (nested
344 * containers not allowed as of now)
345 */
346 if ((pl->move_type&MOVE_FLYING)
347 && !QUERY_FLAG(pl, FLAG_WIZ)
348 && object_get_player_container(tmp) != pl) {
349 draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
350 "You are levitating, you can't reach the ground!");
351 return;
352 }
353 if (QUERY_FLAG(tmp, FLAG_NO_DROP))
354 return;
355
356 if (QUERY_FLAG(tmp, FLAG_WAS_WIZ) && !QUERY_FLAG(pl, FLAG_WAS_WIZ)) {
357 draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE,
358 "The object disappears in a puff of smoke! It must have been an illusion.");
359 if (!QUERY_FLAG(tmp, FLAG_REMOVED))
360 object_remove(tmp);
361 object_free_drop_inventory(tmp);
362 return;
363 }
364
365 if (nrof > tmp_nrof || nrof == 0)
366 nrof = tmp_nrof;
367
368 /* Figure out how much weight this object will add to the player */
369 weight = tmp->weight*nrof;
370 if (tmp->inv)
371 weight += tmp->carrying*(100-tmp->stats.Str)/100;
372
373 effective_weight_limit = get_weight_limit(MIN(pl->stats.Str, settings.max_stat));
374
375 if (pl->weight+pl->carrying+weight > effective_weight_limit) {
376 draw_ext_info(0, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE,
377 "That item is too heavy for you to pick up.");
378 return;
379 }
380
381 if (settings.real_wiz == FALSE && QUERY_FLAG(pl, FLAG_WAS_WIZ))
382 SET_FLAG(tmp, FLAG_WAS_WIZ);
383
384 if (nrof != tmp_nrof) {
385 char failure[MAX_BUF];
386
387 tmp = object_split(tmp, nrof, failure, sizeof(failure));
388 if (!tmp) {
389 draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
390 failure);
391 return;
392 }
393 } else {
394 /* If the object is in a container, send a delete to the client.
395 * - we are moving all the items from the container to elsewhere,
396 * so it needs to be deleted.
397 */
398 if (!QUERY_FLAG(tmp, FLAG_REMOVED)) {
399 object_remove(tmp); /* Unlink it */
400 }
401 }
402 query_name(tmp, name, MAX_BUF);
403
404 if (QUERY_FLAG(tmp, FLAG_UNPAID)) {
405 char *value = cost_str(shop_price_buy(tmp, pl));
406 snprintf(buf, sizeof(buf), "%s will cost you %s.", name, value);
407 free(value);
408 } else
409 snprintf(buf, sizeof(buf), "You pick up the %s.", name);
410
411 /* Now item is about to be picked. */
412 tag = tmp->count;
413 if (execute_event(tmp, EVENT_PICKUP, pl, op, NULL, SCRIPT_FIX_ALL) != 0) {
414 /* put item back, if it still exists */
415 if (tmp->count == tag && !QUERY_FLAG(tmp, FLAG_FREED)) {
416 if (env != NULL) {
417 object_insert_in_ob(tmp, env);
418 } else {
419 object_insert_in_map_at(tmp, map, NULL, 0, x, y);
420 }
421 }
422 return;
423 }
424
425 draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
426 buf);
427
428 tmp = object_insert_in_ob(tmp, op);
429
430 /* All the stuff below deals with client/server code, and is only
431 * usable by players
432 */
433 if (pl->type != PLAYER)
434 return;
435
436 /* Additional weight changes speed, etc */
437 fix_object(pl);
438
439 /* These are needed to update the weight for the container we
440 * are putting the object in.
441 */
442 if (op != pl) {
443 esrv_update_item(UPD_WEIGHT, pl, op);
444 esrv_update_item(UPD_WEIGHT, pl, pl);
445 }
446
447 /* Update the container the object was in */
448 if (env && env != pl && env != op)
449 esrv_update_item(UPD_WEIGHT, pl, env);
450 }
451
452 /**
453 * Try to pick up an item.
454 *
455 * @param op
456 * object trying to pick up.
457 * @param alt
458 * optional object op is trying to pick. If NULL, try to pick first item under op.
459 */
460 void pick_up(object *op, object *alt) {
461 /* modified slightly to allow monsters use this -b.t. 5-31-95 */
462 object *tmp = NULL, *tmp1;
463 mapstruct *tmp_map = NULL;
464 int count;
465
466 /* Decide which object to pick. */
467 if (alt) {
468 if (!object_can_pick(op, alt)) {
469 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
470 "You can't pick up the %s.",
471 alt->name);
472 return;
473 }
474 tmp = alt;
475 } else {
476 if (op->below == NULL || !object_can_pick(op, op->below)) {
477 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
478 "There is nothing to pick up here.");
479 return;
480 }
481 tmp = op->below;
482 }
483
484 /* it is possible that the object is a thrown object and is flying about.
485 * in that case, what we want to pick up is the payload. Objects
486 * that are thrown are encapsulated into a thrown object.
487 * stop_item() returns the payload (unlinked from map) and gets rid of the
488 * container object. If this object isn't picked up, we need to insert
489 * it back on the map.
490 * A bug here is that even attempting to pick up one of these objects will
491 * result in this logic being called even if player is unable to pick it
492 * up.
493 */
494
495 tmp_map = tmp->map;
496 tmp1 = stop_item(tmp);
497 if (tmp1 == NULL)
498 return;
499
500 /* If it is a thrown object, insert it back into the map here.
501 * makes life easier further along. Do no merge so pick up code
502 * behaves more sanely.
503 */
504 if (tmp1 != tmp) {
505 tmp = object_insert_in_map(tmp1, tmp_map, op, INS_NO_MERGE);
506 }
507
508 if (tmp == NULL)
509 return;
510
511 if (!object_can_pick(op, tmp))
512 return;
513
514 /* Establish how many of the object we are picking up */
515 if (op->type == PLAYER) {
516 count = op->contr->count;
517 if (count == 0)
518 count = tmp->nrof;
519 } else
520 count = tmp->nrof;
521
522 /* container is open, so use it */
523 if (op->container) {
524 alt = op->container;
525 if (alt != tmp->env && !sack_can_hold(op, alt, tmp, count))
526 return;
527 } else {
528 /* non container pickup. See if player has any
529 * active containers.
530 */
531 object *container = NULL;
532
533 /* Look for any active containers that can hold this item.
534 * we cover two cases here - the perfect match case, where we
535 * break out of the loop, and the general case (have a container),
536 * Moved this into a single loop - reduces redundant code, is
537 * more efficient and easier to follow. MSW 2009-04-06
538 */
539 alt = op->inv;
540 FOR_OB_AND_BELOW_PREPARE(alt) {
541 if (alt->type == CONTAINER
542 && QUERY_FLAG(alt, FLAG_APPLIED)
543 && sack_can_hold(NULL, alt, tmp, count)) {
544 if (alt->race && alt->race == tmp->race) {
545 break; /* perfect match */
546 } else if (!container) {
547 container = alt;
548 }
549 }
550 } FOR_OB_AND_BELOW_FINISH();
551 /* Note container could be null, but no reason to check for it */
552 if (!alt)
553 alt = container;
554
555 if (!alt)
556 alt = op; /* No free containers */
557 }
558 /* see if this object is already in this container. If so,
559 * move it to player inventory from this container.
560 */
561 if (tmp->env == alt) {
562 alt = op;
563 }
564
565 /* Don't allow players to be put into containers. Instead,
566 * just put them in the players inventory.
567 */
568 if (tmp->type == CONTAINER && alt->type==CONTAINER) {
569 alt = op;
570 }
571 #ifdef PICKUP_DEBUG
572 LOG(llevDebug, "Pick_up(): %s picks %s (%d) and inserts it %s.\n", op->name, tmp->name, op->contr->count, alt->name);
573 #endif
574
575 /* startequip items are not allowed to be put into containers
576 * Not sure why we have this limitation
577 */
578 if (op->type == PLAYER
579 && alt->type == CONTAINER
580 && QUERY_FLAG(tmp, FLAG_STARTEQUIP)) {
581 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
582 "This object cannot be put into containers!");
583 return;
584 }
585
586 pick_up_object(op, alt, tmp, count);
587 if (op->type == PLAYER)
588 op->contr->count = 0;
589 }
590
591 /**
592 * This takes (picks up) and item.
593 *
594 * @param op
595 * player who issued the command.
596 * @param params
597 * string to match against the item name.
598 */
599 void command_take(object *op, const char *params) {
600 object *tmp;
601 int ival;
602 int missed = 0;
603
604 if (op->container)
605 tmp = op->container->inv;
606 else {
607 tmp = op->above;
608 if (tmp)
609 while (tmp->above) {
610 tmp = tmp->above;
611 }
612 if (!tmp)
613 tmp = op->below;
614 }
615
616 if (tmp == NULL) {
617 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
618 "Nothing to take!");
619 return;
620 }
621
622 /* Makes processing easier */
623 if (*params == '\0')
624 params = NULL;
625
626 FOR_OB_AND_BELOW_PREPARE(tmp) {
627 if (tmp->invisible) {
628 continue;
629 }
630 /* This following two if and else if could be merged into line
631 * but that probably will make it more difficult to read, and
632 * not make it any more efficient
633 */
634 if (params) {
635 ival = object_matches_string(op, tmp, params);
636 if (ival > 0) {
637 if (ival <= 2 && !object_can_pick(op, tmp)) {
638 if (!QUERY_FLAG(tmp, FLAG_IS_FLOOR))/* don't count floor tiles */
639 missed++;
640 } else
641 pick_up(op, tmp);
642 }
643 } else {
644 if (object_can_pick(op, tmp)) {
645 pick_up(op, tmp);
646 break;
647 }
648 }
649 } FOR_OB_AND_BELOW_FINISH();
650 if (!params && !tmp) {
651 int found = 0;
652 FOR_BELOW_PREPARE(op, tmp)
653 if (!tmp->invisible) {
654 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
655 "You can't pick up a %s.",
656 tmp->name ? tmp->name : "null");
657 found = 1;
658 break;
659 }
660 FOR_BELOW_FINISH();
661 if (!found)
662 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
663 "There is nothing to pick up.");
664 }
665 if (missed == 1)
666 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
667 "You were unable to take one of the items.");
668 else if (missed > 1)
669 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE,
670 "You were unable to take %d of the items.",
671 missed);
672 }
673
674 /**
675 * Something tries to put an object into another.
676 *
677 * This function was part of drop(), now is own function.
678 *
679 * @note
680 * the 'sack' in question can now be a transport,
681 * so this function isn't named very good anymore.
682 *
683 * @param op
684 * who is moving the item.
685 * @param sack
686 * where to put the object.
687 * @param tmp
688 * what to put into sack.
689 * @param nrof
690 * if non zero, then nrof objects is tried to put into sack, else everything is put.
691 */
692 void put_object_in_sack(object *op, object *sack, object *tmp, uint32_t nrof) {
693 object *sack2, *orig = sack;
694 char name_sack[MAX_BUF], name_tmp[MAX_BUF];
695
696 if (sack == tmp)
697 return; /* Can't put an object in itself */
698 query_name(sack, name_sack, MAX_BUF);
699 if (sack->type != CONTAINER && sack->type != TRANSPORT) {
700 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
701 "The %s is not a container.",
702 name_sack);
703 return;
704 }
705 if (QUERY_FLAG(tmp, FLAG_STARTEQUIP)) {
706 query_name(tmp, name_tmp, MAX_BUF);
707 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
708 "You cannot put the %s in the %s.",
709 name_tmp, name_sack);
710 return;
711 }
712 if (tmp->type == CONTAINER) {
713 if (tmp->inv) {
714 if (tmp->slaying)
715 return;
716 /* Eneq(@csd.uu.se): If the object to be dropped is a container
717 * and does not require a key to be opened,
718 * we instead move the contents of that container into the active
719 * container, this is only done if the object has something in it.
720 * If object is container but need a key, just don't do anything
721 */
722 sack2 = tmp;
723 query_name(tmp, name_tmp, MAX_BUF);
724 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
725 "You move the items from %s into %s.",
726 name_tmp, name_sack);
727
728 FOR_INV_PREPARE(tmp, tmp2) {
729 if ((sack->type == CONTAINER && sack_can_hold(op, op->container, tmp2, tmp2->nrof))
730 || (sack->type == TRANSPORT && transport_can_hold(sack, tmp2, tmp2->nrof))) {
731 put_object_in_sack(op, sack, tmp2, 0);
732 } else {
733 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
734 MSG_TYPE_COMMAND_FAILURE,
735 "Your %s fills up.",
736 name_sack);
737 break;
738 }
739 } FOR_INV_FINISH();
740 esrv_update_item(UPD_WEIGHT, op, sack2);
741 return;
742 } else {
743 query_name(tmp, name_tmp, MAX_BUF);
744 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
745 "You can not put a %s into a %s",
746 name_tmp,
747 name_sack);
748 return;
749 }
750 }
751
752 /* Don't worry about this for containers - our caller should have
753 * already checked this.
754 */
755 if (sack->type == CONTAINER && !sack_can_hold(op, sack, tmp, nrof ? nrof : tmp->nrof))
756 return;
757
758 if (QUERY_FLAG(tmp, FLAG_APPLIED)) {
759 if (apply_special(op, tmp, AP_UNAPPLY|AP_NO_MERGE))
760 return;
761 }
762
763 /* we want to put some portion of the item into the container */
764 if (nrof && tmp->nrof != nrof) {
765 char failure[MAX_BUF];
766
767 tmp = object_split(tmp, nrof, failure, sizeof(failure));
768
769 if (!tmp) {
770 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
771 failure);
772 return;
773 }
774 } else
775 object_remove(tmp);
776
777 if (sack->nrof > 1) {
778 orig = object_split(sack, sack->nrof-1, NULL, 0);
779 set_object_face_main(orig);
780 CLEAR_FLAG(orig, FLAG_APPLIED);
781 if (sack->env) {
782 object_insert_in_ob(orig, sack->env);
783 } else {
784 object_insert_in_map_at(orig, sack->map, NULL, 0, sack->x, sack->y);
785 orig->move_off = 0;
786 }
787 }
788
789 query_name(tmp, name_tmp, MAX_BUF);
790 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
791 "You put the %s in %s.",
792 name_tmp, name_sack);
793
794 object_insert_in_ob(tmp, sack);
795 if (!QUERY_FLAG(op, FLAG_NO_FIX_PLAYER))
796 fix_object(op); /* This is overkill, fix_player() is called somewhere */
797 /* in object.c */
798
799 /* If a transport, need to update all the players in the transport
800 * the view of what is in it.
801 */
802 if (sack->type == TRANSPORT) {
803 FOR_INV_PREPARE(sack, tmp)
804 if (tmp->type == PLAYER)
805 tmp->contr->socket.update_look = 1;
806 FOR_INV_FINISH();
807 } else {
808 /* update the sacks weight */
809 esrv_update_item(UPD_WEIGHT, op, sack);
810 }
811 }
812
813 /**
814 * Try to drop an object on the floor.
815 *
816 * This function was part of drop, now is own function.
817 *
818 * @param op
819 * who is dropping the item.
820 * @param tmp
821 * item to drop.
822 * @param nrof
823 * if is non zero, then nrof objects is tried to be dropped.
824 * @return
825 * object dropped, NULL if it was destroyed.
826 * @todo shouldn't tmp be NULL if object_was_destroyed returns true?
827 */
828 object *drop_object(object *op, object *tmp, uint32_t nrof) {
829 tag_t tmp_tag;
830
831 if (QUERY_FLAG(tmp, FLAG_NO_DROP)) {
832 return NULL;
833 }
834
835 if (QUERY_FLAG(tmp, FLAG_APPLIED)) {
836 if (apply_special(op, tmp, AP_UNAPPLY|AP_NO_MERGE))
837 return NULL; /* can't unapply it */
838 }
839
840 /* Lauwenmark: Handle for plugin drop event */
841 if (execute_event(tmp, EVENT_DROP, op, NULL, NULL, SCRIPT_FIX_ALL) != 0)
842 return NULL;
843
844 /* ensure the plugin didn't destroy the object */
845 if (QUERY_FLAG(tmp, FLAG_REMOVED))
846 return NULL;
847
848 /* We are only dropping some of the items. We split the current objec
849 * off
850 */
851 if (nrof && tmp->nrof != nrof) {
852 char failure[MAX_BUF];
853
854 tmp = object_split(tmp, nrof, failure, sizeof(failure));
855 if (!tmp) {
856 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
857 failure);
858 return NULL;
859 }
860 } else
861 object_remove(tmp);
862
863 if (QUERY_FLAG(tmp, FLAG_STARTEQUIP)) {
864 char name[MAX_BUF];
865
866 query_name(tmp, name, MAX_BUF);
867 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
868 "You drop the %s. The gods who lent it to you retrieve it.",
869 name);
870 object_free_drop_inventory(tmp);
871
872 if (!QUERY_FLAG(op, FLAG_NO_FIX_PLAYER))
873 fix_object(op);
874
875 return NULL;
876 }
877
878 /* If SAVE_INTERVAL is commented out, we never want to save
879 * the player here.
880 */
881 #ifdef SAVE_INTERVAL
882 /* I'm not sure why there is a value check - since the save
883 * is done every SAVE_INTERVAL seconds, why care the value
884 * of what he is dropping?
885 */
886 if (op->type == PLAYER
887 && !QUERY_FLAG(tmp, FLAG_UNPAID)
888 && (tmp->nrof ? tmp->value*tmp->nrof : tmp->value > 2000)
889 && op->contr->last_save_time+SAVE_INTERVAL <= time(NULL)) {
890 save_player(op, 1);
891 op->contr->last_save_time = time(NULL);
892 }
893 #endif /* SAVE_INTERVAL */
894
895
896 tmp_tag = tmp->count;
897 object_insert_in_map_at(tmp, op->map, op, INS_BELOW_ORIGINATOR, op->x, op->y);
898 if (!object_was_destroyed(tmp, tmp_tag) && !QUERY_FLAG(tmp, FLAG_UNPAID) && tmp->type != MONEY && shop_contains(op)) {
899 sell_item(tmp, op);
900 }
901
902 /* Call this before we update the various windows/players. At least
903 * that we, we know the weight is correct.
904 */
905 if (!QUERY_FLAG(op, FLAG_NO_FIX_PLAYER)) {
906 fix_object(op); /* This is overkill, fix_player() is called somewhere */
907 /* in object.c */
908
909 /* Need to update weight of player */
910 if (op->type == PLAYER)
911 esrv_update_item(UPD_WEIGHT, op, op);
912 }
913 return tmp;
914 }
915
916 /**
917 * Drop an item, either on the floor or in a container.
918 *
919 * @param op
920 * who is dropping an item.
921 * @param tmp
922 * what object to drop.
923 */
924 void drop(object *op, object *tmp) {
925 /* Hopeful fix for disappearing objects when dropping from a container -
926 * somehow, players get an invisible object in the container, and the
927 * old logic would skip over invisible objects - works fine for the
928 * playes inventory, but drop inventory wants to use the next value.
929 */
930 if (tmp->invisible) {
931 /* if the following is the case, it must be in an container. */
932 if (tmp->env && tmp->env->type != PLAYER) {
933 /* Just toss the object - probably shouldn't be hanging
934 * around anyways
935 */
936 object_remove(tmp);
937 object_free_drop_inventory(tmp);
938 return;
939 } else {
940 FOR_OB_AND_BELOW_PREPARE(tmp)
941 if (!tmp->invisible)
942 break;
943 FOR_OB_AND_BELOW_FINISH();
944 }
945 }
946
947 if (tmp == NULL) {
948 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
949 "You don't have anything to drop.");
950 return;
951 }
952 if (QUERY_FLAG(tmp, FLAG_INV_LOCKED)) {
953 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
954 "This item is locked");
955 return;
956 }
957 if (QUERY_FLAG(tmp, FLAG_NO_DROP)) {
958 return;
959 }
960
961 if (op->container) {
962 if (op->type == PLAYER) {
963 put_object_in_sack(op, op->container, tmp, op->contr->count);
964 } else {
965 put_object_in_sack(op, op->container, tmp, 0);
966 };
967 } else {
968 if (op->type == PLAYER) {
969 drop_object(op, tmp, op->contr->count);
970 } else {
971 drop_object(op, tmp, 0);
972 };
973 }
974 if (op->type == PLAYER)
975 op->contr->count = 0;
976 }
977
978 /**
979 * Command to drop all items that have not been locked.
980 *
981 * @param op
982 * player.
983 * @param params
984 * optional specifier, like 'armour', 'weapon' and such.
985 */
986 void command_dropall(object *op, const char *params) {
987 int count = 0;
988
989 if (op->inv == NULL) {
990 draw_ext_info(NDI_UNIQUE, 0, op,
991 MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
992 "Nothing to drop!");
993 return;
994 }
995
996 if (op->contr)
997 count = op->contr->count;
998
999 /* Set this so we don't call it for _every_ object that
1000 * is dropped.
1001 */
1002 SET_FLAG(op, FLAG_NO_FIX_PLAYER);
1003
1004 /*
1005 * This is the default. Drops everything not locked or considered
1006 * not something that should be dropped.
1007 * Care must be taken that the next item pointer is not to money as
1008 * the drop() routine will do unknown things to it when dropping
1009 * in a shop. [email protected]
1010 */
1011 if (*params == '\0') {
1012 FOR_INV_PREPARE(op, curinv) {
1013 if (!QUERY_FLAG(curinv, FLAG_INV_LOCKED)
1014 && curinv->type != MONEY
1015 && curinv->type != FOOD
1016 && curinv->type != KEY
1017 && curinv->type != SPECIAL_KEY
1018 && curinv->type != GEM
1019 && !curinv->invisible
1020 && (curinv->type != CONTAINER || op->container != curinv)) {
1021 drop(op, curinv);
1022 if (op->contr)
1023 op->contr->count = count;
1024 }
1025 } FOR_INV_FINISH();
1026 } else if (strcmp(params, "weapons") == 0) {
1027 FOR_INV_PREPARE(op, curinv) {
1028 if (!QUERY_FLAG(curinv, FLAG_INV_LOCKED)
1029 && (curinv->type == WEAPON || curinv->type == BOW || curinv->type == ARROW)) {
1030 drop(op, curinv);
1031 if (op->contr)
1032 op->contr->count = count;
1033 }
1034 } FOR_INV_FINISH();
1035 } else if (strcmp(params, "armor") == 0 || strcmp(params, "armour") == 0) {
1036 FOR_INV_PREPARE(op, curinv) {
1037 if (!QUERY_FLAG(curinv, FLAG_INV_LOCKED)
1038 && (curinv->type == ARMOUR || curinv->type == SHIELD || curinv->type == HELMET)) {
1039 drop(op, curinv);
1040 if (op->contr)
1041 op->contr->count = count;
1042 }
1043 } FOR_INV_FINISH();
1044 } else if (strcmp(params, "food") == 0) {
1045 FOR_INV_PREPARE(op, curinv) {
1046 if (!QUERY_FLAG(curinv, FLAG_INV_LOCKED)
1047 && (curinv->type == FOOD || curinv->type == DRINK)) {
1048 drop(op, curinv);
1049 if (op->contr)
1050 op->contr->count = count;
1051 }
1052 } FOR_INV_FINISH();
1053 } else if (strcmp(params, "flesh") == 0) {
1054 FOR_INV_PREPARE(op, curinv) {
1055 if (!QUERY_FLAG(curinv, FLAG_INV_LOCKED)
1056 && (curinv->type == FLESH)) {
1057 drop(op, curinv);
1058 if (op->contr)
1059 op->contr->count = count;
1060 }
1061 } FOR_INV_FINISH();
1062 } else if (strcmp(params, "misc") == 0) {
1063 FOR_INV_PREPARE(op, curinv) {
1064 if (!QUERY_FLAG(curinv, FLAG_INV_LOCKED)
1065 && !QUERY_FLAG(curinv, FLAG_APPLIED)) {
1066 switch (curinv->type) {
1067 case BOOK:
1068 case SPELLBOOK:
1069 case GIRDLE:
1070 case AMULET:
1071 case RING:
1072 case CLOAK:
1073 case BOOTS:
1074 case GLOVES:
1075 case BRACERS:
1076 case SCROLL:
1077 case ARMOUR_IMPROVER:
1078 case WEAPON_IMPROVER:
1079 case WAND:
1080 case ROD:
1081 case POTION:
1082 drop(op, curinv);
1083 if (op->contr)
1084 op->contr->count = count;
1085 break;
1086
1087 default:
1088 break;
1089 }
1090 }
1091 } FOR_INV_FINISH();
1092 }
1093 op->contr->socket.update_look = 1;
1094 CLEAR_FLAG(op, FLAG_NO_FIX_PLAYER);
1095 /* call it now, once */
1096 fix_object(op);
1097 /* Need to update weight of player. Likewise, only do it once */
1098 if (op->type == PLAYER)
1099 esrv_update_item(UPD_WEIGHT, op, op);
1100 }
1101
1102 /**
1103 * 'drop' command.
1104 *
1105 * @param op
1106 * player.
1107 * @param params
1108 * what to drop.
1109 */
1110 void command_drop(object *op, const char *params) {
1111 int did_one = 0;
1112 int ival = 0;
1113 int missed = 0;
1114
1115 if (*params == '\0') {
1116 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1117 "Drop what?");
1118 return;
1119 } else {
1120 FOR_INV_PREPARE(op, tmp) {
1121 if (QUERY_FLAG(tmp, FLAG_NO_DROP) || tmp->invisible)
1122 continue;
1123 ival = object_matches_string(op, tmp, params);
1124 if (ival > 0) {
1125 if (QUERY_FLAG(tmp, FLAG_INV_LOCKED) && (ival == 1 || ival == 2))
1126 missed++;
1127 else
1128 drop(op, tmp);
1129 did_one = 1;
1130 }
1131 } FOR_INV_FINISH();
1132 if (!did_one)
1133 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1134 "Nothing to drop.");
1135 if (missed == 1)
1136 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1137 "One item couldn't be dropped because it was locked.");
1138 else if (missed > 1)
1139 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1140 "%d items couldn't be dropped because they were locked.",
1141 missed);
1142 }
1143 if (op->type == PLAYER) {
1144 op->contr->count = 0;
1145 /*
1146 * Don't force a whole look update, items were transferred during their move.
1147 * Also this would send a 'delinv 0' to the client, which would make it appear
1148 * an opened container was closed.
1149 */
1150 /*op->contr->socket.update_look = 1;*/
1151 }
1152 }
1153
1154 /**
1155 * Put all contents of the container on the ground below the player or in opened container, except locked items.
1156 *
1157 * @param container
1158 * what to empty.
1159 * @param pl
1160 * player to drop for.
1161 */
1162 static void empty_container(object *container, object *pl) {
1163 int left = 0;
1164 char name[MAX_BUF];
1165
1166 if (!container->inv)
1167 return;
1168
1169 FOR_INV_PREPARE(container, inv) {
1170 object *next;
1171
1172 if (QUERY_FLAG(inv, FLAG_INV_LOCKED)) {
1173 /* you can have locked items in container. */
1174 left++;
1175 continue;
1176 }
1177 next = inv->below;
1178 drop(pl, inv);
1179 if (inv->below == next)
1180 /* item couldn't be dropped for some reason. */
1181 left++;
1182 } FOR_INV_FINISH();
1183 esrv_update_item(UPD_WEIGHT, pl, container);
1184
1185 query_name(container, name, sizeof(name));
1186 if (left)
1187 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, "You empty the %s except %d items.", name, left);
1188 else
1189 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, "You empty the %s.", name);
1190 }
1191
1192 /**
1193 * 'empty' command.
1194 *
1195 * @param op
1196 * player.
1197 * @param params
1198 * item specifier.
1199 */
1200 void command_empty(object *op, const char *params) {
1201 object *container;
1202
1203 if (*params == '\0') {
1204 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1205 "Empty what?");
1206 return;
1207 }
1208
1209 if (strcmp(params, "all") == 0) {
1210 FOR_INV_PREPARE(op, inv)
1211 if (inv->type == CONTAINER)
1212 empty_container(inv, op);
1213 FOR_INV_FINISH();
1214 return;
1215 }
1216
1217 container = find_best_object_match(op, params);
1218 if (!container) {
1219 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1220 "No such item.");
1221 return;
1222 }
1223 if (container->type != CONTAINER) {
1224 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1225 "This is not a container!");
1226 return;
1227 }
1228 empty_container(container, op);
1229 }
1230
1231 /**
1232 * 'examine' command.
1233 *
1234 * @param op
1235 * player.
1236 * @param params
1237 * optional item specifier.
1238 */
1239 void command_examine(object *op, const char *params) {
1240 if (*params == '\0') {
1241 FOR_BELOW_PREPARE(op, tmp)
1242 if (LOOK_OBJ(tmp)) {
1243 examine(op, tmp);
1244 break;
1245 }
1246 FOR_BELOW_FINISH();
1247 } else {
1248 object *tmp = find_best_object_match(op, params);
1249
1250 if (tmp)
1251 examine(op, tmp);
1252 else
1253 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1254 "Could not find an object that matches %s",
1255 params);
1256 }
1257 }
1258
1259 /**
1260 * Return the object the player has marked with the 'mark' command
1261 * below. If no match is found (or object has changed), we return
1262 * NULL. We leave it up to the calling function to print messages if
1263 * nothing is found.
1264 *
1265 * @param op
1266 * object. Should be a player.
1267 * @return
1268 * marked object if still valid, NULL else.
1269 */
1270 object *find_marked_object(object *op) {
1271 if (!op || !op->contr || !op->contr->mark)
1272 return NULL;
1273
1274 /* This may seem like overkill, but we need to make sure that they
1275 * player hasn't dropped the item. We use count on the off chance that
1276 * an item got reincarnated at some point.
1277 */
1278 /*
1279 FOR_INV_PREPARE(op, tmp) {
1280 if (tmp->invisible)
1281 continue;
1282 if (tmp == op->contr->mark) {
1283 if (tmp->count == op->contr->mark_count)
1284 return tmp;
1285 else {
1286 op->contr->mark = NULL;
1287 op->contr->mark_count = 0;
1288 return NULL;
1289 }
1290 }
1291 } FOR_INV_FINISH();
1292 */
1293 /* Try a different way of doing this
1294 * We check the environment of the marked object
1295 * to make sure it is still in the player's inventory.
1296 * In addition, we ensure there is the correct tag for that item.
1297 *
1298 * Daniel Hawkins 2018-10-23
1299 */
1300 if (op->contr->mark->env == op && op->contr->mark->count == op->contr->mark_count)
1301 return op->contr->mark;
1302 // Otherwise reset the mark, since it is no longer valid.
1303 op->contr->mark = NULL;
1304 op->contr->mark_count = 0;
1305 return NULL;
1306 }
1307
1308 /**
1309 * 'mark' command, to mark an item for some effects (enchant armor, ...).
1310 *
1311 * @param op
1312 * player.
1313 * @param params
1314 * If empty, we print out the currently marked object.
1315 * Otherwise, try to find a matching object - try best match first.
1316 */
1317 void command_mark(object *op, const char *params) {
1318 char name[MAX_BUF];
1319
1320 if (!op->contr)
1321 return;
1322 if (*params == '\0') {
1323 object *mark = find_marked_object(op);
1324 if (!mark)
1325 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1326 "You have no marked object.");
1327 else {
1328 query_name(mark, name, MAX_BUF);
1329 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
1330 "%s is marked.",
1331 name);
1332 }
1333 } else {
1334 object *mark1 = find_best_object_match(op, params);
1335
1336 if (!mark1) {
1337 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1338 "Could not find an object that matches %s",
1339 params);
1340 return;
1341 } else {
1342 op->contr->mark = mark1;
1343 op->contr->mark_count = mark1->count;
1344 query_name(mark1, name, MAX_BUF);
1345 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
1346 "Marked item %s",
1347 name);
1348 return;
1349 }
1350 }
1351 /*shouldnt get here */
1352 }
1353
1354 /**
1355 * Player examine a monster.
1356 *
1357 * @param op
1358 * player.
1359 * @param tmp
1360 * monster being examined.
1361 * @param level
1362 * level of the probe, to have a persistant marker for some duration.
1363 */
1364 void examine_monster(object *op, object *tmp, int level) {
1365 object *mon = HEAD(tmp), *probe;
1366
1367 if (QUERY_FLAG(mon, FLAG_UNDEAD))
1368 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1369 "It is an undead force.");
1370 if (mon->level > op->level)
1371 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1372 "It is likely more powerful than you.");
1373 else if (mon->level < op->level)
1374 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1375 "It is likely less powerful than you.");
1376 else
1377 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1378 "It is probably as powerful as you.");
1379
1380 if (mon->attacktype&AT_ACID)
1381 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1382 "You smell an acrid odor.");
1383
1384 /* Anyone know why this used to use the clone value instead of the
1385 * maxhp field? This seems that it should give more accurate results.
1386 */
1387 switch ((mon->stats.hp+1)*4/(mon->stats.maxhp+1)) {
1388 /* From 0-4+, since hp can be higher than maxhp if defined in map. */
1389 case 0:
1390 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1391 "It is critically wounded.");
1392 break;
1393
1394 case 1:
1395 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1396 "It is in a bad shape.");
1397 break;
1398
1399 case 2:
1400 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1401 "It is hurt.");
1402 break;
1403
1404 case 3:
1405 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1406 "It is somewhat hurt.");
1407 break;
1408
1409 default:
1410 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1411 "It is in excellent shape.");
1412 break;
1413 }
1414 if (object_present_in_ob(POISONING, mon) != NULL)
1415 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1416 "It looks very ill.");
1417
1418 if (level < 10)
1419 return;
1420 knowledge_show_monster_detail(op, mon->arch->name);
1421
1422 if (level < 15)
1423 return;
1424
1425 probe = object_find_by_type_and_name(mon, FORCE, "probe_force");
1426 if (probe != NULL && probe->level > level)
1427 return;
1428
1429 if (probe == NULL) {
1430 probe = create_archetype(FORCE_NAME);
1431 free_string(probe->name);
1432 probe->name = add_string("probe_force");
1433 SET_FLAG(probe, FLAG_APPLIED);
1434 SET_FLAG(probe, FLAG_PROBE);
1435 object_insert_in_ob(probe, mon);
1436 fix_object(mon);
1437 }
1438 probe->level = level;
1439 if (level / 10 > probe->duration)
1440 probe->duration = level / 10;
1441 }
1442
1443 /**
1444 * Player examines some object. The item may be identified automatically
1445 * if the player has the correct skill for that.
1446 *
1447 * @param op
1448 * player.
1449 * @param tmp
1450 * object to examine.
1451 */
1452 void examine(object *op, object *tmp) {
1453 char buf[VERY_BIG_BUF];
1454 int in_shop;
1455 int i, exp = 0, conn;
1456
1457 /* we use this to track how far along we got with trying to identify an item,
1458 * so that we can give the appropriate message to the player */
1459 int id_attempted = 0;
1460 char prefix[MAX_BUF] = "That is";
1461 const typedata *tmptype;
1462 object *skill;
1463
1464 buf[0] = '\0';
1465
1466 if (tmp == NULL || tmp->type == CLOSE_CON)
1467 return;
1468 tmptype = get_typedata(tmp->type);
1469 if (!tmptype) {
1470 LOG(llevError, "Attempted to examine item %d with type %d, which is invalid", tmp->count, tmp->type);
1471 return;
1472 }
1473 /* first of all check whether this is an item we need to identify, and identify it as best we can.*/
1474 if (!QUERY_FLAG(tmp, FLAG_IDENTIFIED)) {
1475 /* We will look for magic status, cursed status and then try to do a full skill-based ID, in that order */
1476 skill = find_skill_by_number(op, SK_DET_MAGIC);
1477 if (skill && (object_can_pick(op, tmp))) {
1478 exp = detect_magic_on_item(op, tmp, skill);
1479 if (exp) {
1480 change_exp(op, exp, skill->skill, SK_SUBTRACT_SKILL_EXP);
1481 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1482 "You discover mystic forces on %s", tmp->nrof <= 1?"that item":"those items" );
1483 }
1484 }
1485 skill = find_skill_by_number(op, SK_DET_CURSE);
1486 /* Cauldrons are a special case of item where it should be possible to detect a curse */
1487 if (skill && (object_can_pick(op, tmp) || QUERY_FLAG(tmp, FLAG_IS_CAULDRON))) {
1488 exp = detect_curse_on_item(op, tmp, skill);
1489 if (exp) {
1490 change_exp(op, exp, skill->skill, SK_SUBTRACT_SKILL_EXP);
1491 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1492 "You have a bad feeling about %s", tmp->nrof <= 1?"that item":"those items" );
1493 }
1494 }
1495 if (!QUERY_FLAG(tmp, FLAG_NO_SKILL_IDENT)) {
1496
1497 id_attempted = 1;
1498 skill = find_skill_by_number(op, tmptype->identifyskill);
1499 if (skill) {
1500 id_attempted = 2;
1501
1502 /* identify_object_with_skill() may merge tmp with another
1503 * object, so once that happens, we really can not do
1504 * any further processing with tmp. It would be possible
1505 * to modify identify_object_with_skill() to return
1506 * the merged object, but it is currently set to return
1507 * exp, so it would have to do it via modifying the
1508 * passed in value, but many other consumers would
1509 * need to be modified for that.
1510 */
1511 exp = identify_object_with_skill(tmp, op, skill, 1);
1512 if (exp) {
1513 change_exp(op, exp, skill->skill, SK_SUBTRACT_SKILL_EXP);
1514 return;
1515 }
1516 }
1517 if(!exp) {
1518 /* The primary id skill didn't work, let's try the secondary one */
1519 skill = find_skill_by_number(op, tmptype->identifyskill2);
1520 if (skill) {
1521 /* if we've reached here, then the first skill will have been attempted
1522 * and failed; this will have set FLAG_NO_SKILL_IDENT we want to clear
1523 * that now, and try with the secondary ID skill, if it fails, then the
1524 * flag will be reset anyway, if it succeeds, it won't matter.*/
1525 CLEAR_FLAG(tmp, FLAG_NO_SKILL_IDENT);
1526 id_attempted = 2;
1527 exp = identify_object_with_skill(tmp, op, skill, 1);
1528 if (exp) {
1529 change_exp(op, exp, skill->skill, SK_SUBTRACT_SKILL_EXP);
1530 return;
1531 }
1532 }
1533 }
1534 }
1535 }
1536 if (!exp) {
1537 /* if we did get exp we'll already have propulated prefix */
1538 if (tmptype->identifyskill || tmptype->identifyskill2) {
1539 switch (id_attempted) {
1540 case 1:
1541 snprintf(prefix, MAX_BUF, "You lack the skill to understand %s:", tmp->nrof <= 1?"that fully; it is":"those fully, they are");
1542 break;
1543 case 2:
1544 snprintf(prefix, MAX_BUF, "You fail to understand %s:", tmp->nrof <= 1?"that fully; it is":"those fully, they are");
1545 break;
1546 default:
1547 snprintf(prefix, MAX_BUF, "%s:", tmp->nrof <= 1?"That is":"Those are");
1548 }
1549 } else snprintf(prefix, MAX_BUF, "%s:", tmp->nrof <= 1?"That is":"Those are");
1550 }
1551 /* now we need to get the rest of the object description */
1552 ob_describe(tmp, op, 1, buf, sizeof(buf));
1553
1554 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1555 "%s %s", prefix, buf);
1556 buf[0] = '\0';
1557 if (tmp->custom_name) {
1558 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1559 "You name it %s",
1560 tmp->custom_name);
1561 }
1562
1563 switch (tmp->type) {
1564 case SKILLSCROLL:
1565 case SKILL_TOOL:
1566 // Embedded skills are stored as an archetype name and don't get reified
1567 // until the player actually reads/equips the object, so we need to
1568 // handle it differently from spells, which are stored in the inv.
1569 if (!tmp->skill) break; // Blank skill scroll, somehow.
1570 archetype *skill = get_archetype_by_skill_name(tmp->skill, SKILL);
1571 if (!skill) {
1572 // Skill name doesn't correspond to any actual skill.
1573 draw_ext_info(NDI_UNIQUE|NDI_BLUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO,
1574 "Unfortunately the scroll is damaged and unreadable.");
1575 break;
1576 }
1577 // Only print the flavor text once we have identified.
1578 if (is_identified(tmp) && skill->clone.msg) {
1579 StringBuffer *sb = stringbuffer_new();
1580 stringbuffer_append_string(sb, skill->clone.msg);
1581 stringbuffer_trim_whitespace(sb);
1582 char *const fluff = stringbuffer_finish(sb);
1583 // SPELL_INFO is not a perfect match here, but it should display in the
1584 // same manner as the spell descriptions below and there's no SKILL_INFO
1585 // message type.
1586 draw_ext_info(NDI_UNIQUE|NDI_BLUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, fluff);
1587 free(fluff);
1588 }
1589 break;
1590
1591 case SPELLBOOK:
1592 case SCROLL:
1593 case WAND:
1594 case ROD:
1595 case POTION:
1596 // Only print the flavor text once we have identified.
1597 if (is_identified(tmp) && tmp->inv && tmp->inv->msg) {
1598 // If the embedded spell has a msg, display it here so that the
1599 // player knows what it does before they actually read/use the item.
1600 // Strip trailing newlines so that the output of examine() is
1601 // contiguous.
1602 // TODO: It might be better to strip the newlines in object_set_msg
1603 // and append them at print time, rather than ensuring that the msg
1604 // is newline-terminated and stripping off the newlines when we don't
1605 // want them; C string handling makes the latter a lot less convenient.
1606 StringBuffer *sb = stringbuffer_new();
1607 stringbuffer_append_string(sb, tmp->inv->msg);
1608 stringbuffer_trim_whitespace(sb);
1609 char *const fluff = stringbuffer_finish(sb);
1610 draw_ext_info(NDI_UNIQUE|NDI_BLUE, 0, op, MSG_TYPE_SPELL, MSG_TYPE_SPELL_INFO, fluff);
1611 free(fluff);
1612 }
1613 if (tmp->type == WAND && is_identified(tmp)) {
1614 snprintf(buf, sizeof(buf), "It has %d charges left.", tmp->stats.food);
1615 }
1616 break;
1617
1618 case BOOK:
1619 if (tmp->msg != NULL)
1620 snprintf(buf, sizeof(buf), "Something is written in it.");
1621 break;
1622
1623 case CONTAINER:
1624 if (tmp->race != NULL) {
1625 if (tmp->weight_limit && tmp->stats.Str < 100)
1626 snprintf(buf, sizeof(buf), "It can hold only %s and its weight limit is %.1f kg.", tmp->race, tmp->weight_limit/(10.0*(100-tmp->stats.Str)));
1627 else
1628 snprintf(buf, sizeof(buf), "It can hold only %s.", tmp->race);
1629 } else
1630 if (tmp->weight_limit && tmp->stats.Str < 100)
1631 snprintf(buf, sizeof(buf), "Its weight limit is %.1f kg.", tmp->weight_limit/(10.0*(100-tmp->stats.Str)));
1632 break;
1633 }
1634
1635 if (buf[0] != '\0')
1636 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1637 buf);
1638
1639 // TODO: combine with weight and properly pluralize, so you get:
1640 // It is made of stone and weighs 15.0 kg.
1641 // They are made of paper and weigh 3 kg.
1642 if (tmp->materialname != NULL && !tmp->msg) {
1643 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1644 "It is made of: %s.",
1645 tmp->materialname);
1646 }
1647 /* Where to wear this item */
1648 for (i = 0; i < NUM_BODY_LOCATIONS; i++) {
1649 if (tmp->body_info[i]) {
1650 if (op->body_info[i]) {
1651 if (tmp->body_info[i] < -1) {
1652 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1653 "%s %s (%d)", tmp->nrof > 1 ? "They go" : "It goes",
1654 body_locations[i].use_name, -tmp->body_info[i]);
1655 } else {
1656 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1657 "%s %s", tmp->nrof > 1 ? "They go" : "It goes",
1658 body_locations[i].use_name);
1659 }
1660 } else {
1661 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1662 "%s %s", tmp->nrof > 1 ? "They go" : "It goes",
1663 body_locations[i].nonuse_name);
1664 }
1665 }
1666 }
1667
1668 if (tmp->weight) {
1669 snprintf(buf, sizeof(buf), tmp->nrof > 1 ? "They weigh %3.3f kg." : "It weighs %3.3f kg.", tmp->weight*((float)(tmp->nrof ? tmp->nrof : 1)/1000.0));
1670 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1671 buf);
1672 }
1673
1674 in_shop = shop_contains(op);
1675
1676 if (tmp->value && !QUERY_FLAG(tmp, FLAG_STARTEQUIP) && !QUERY_FLAG(tmp, FLAG_NO_PICK)) {
1677 char *value = cost_approx_str(tmp, op);
1678 snprintf(buf, sizeof(buf), "You reckon %s worth %s.", tmp->nrof > 1 ? "they are" : "it is", value);
1679 free(value);
1680 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1681 buf);
1682 if (in_shop) {
1683 if (QUERY_FLAG(tmp, FLAG_UNPAID)) {
1684 value = cost_str(shop_price_buy(tmp, op));
1685 snprintf(buf, sizeof(buf), "%s would cost you %s.", tmp->nrof > 1 ? "They" : "It", value);
1686 free(value);
1687 } else {
1688 value = cost_str(shop_price_sell(tmp, op));
1689 snprintf(buf, sizeof(buf), "You are offered %s for %s.", value, tmp->nrof > 1 ? "them" : "it");
1690 free(value);
1691 }
1692 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1693 buf);
1694 }
1695 }
1696
1697 if (QUERY_FLAG(tmp, FLAG_MONSTER))
1698 examine_monster(op, tmp, 0);
1699
1700 /* Is this item buildable? */
1701 if (QUERY_FLAG(tmp, FLAG_IS_BUILDABLE)) {
1702 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1703 "This is a buildable item.");
1704 if (QUERY_FLAG(tmp, FLAG_IS_LINKED)){
1705 conn = get_button_value(tmp);
1706 if (conn) {
1707 FOR_INV_PREPARE(op, tmp_inv) {
1708 if (tmp_inv->type == FORCE && tmp_inv->slaying != NULL
1709 && strcmp(tmp_inv->slaying, op->map->path) == 0
1710 && tmp_inv->msg != NULL
1711 && tmp_inv->path_attuned == (uint32_t) conn) {
1712
1713 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND,
1714 MSG_TYPE_COMMAND_EXAMINE, "Connected with: %s",
1715 tmp_inv->msg);
1716
1717 break;
1718 }
1719 } FOR_INV_FINISH();
1720 }
1721 }
1722 }
1723
1724 /* Does the object have a message? Don't show message for all object
1725 * types - especially if the first entry is a match
1726 */
1727 if (tmp->msg
1728 && tmp->type != EXIT
1729 && tmp->type != BOOK
1730 && tmp->type != CORPSE
1731 && !tmp->move_on
1732 && strncasecmp(tmp->msg, "@match", 6)) {
1733 /* This is just a hack so when identifying the items, we print
1734 * out the extra message. Do this only for "identifiable types", e.g.
1735 * we don't want to print this message when the player looks at a
1736 * locked door (where msg is used to store the message they get when
1737 * trying to force it open).
1738 *
1739 * Also, don't print the message for the object unless it has been identified
1740 * -- SilverNexus 2015-05-20
1741 */
1742 if (is_identifiable_type(tmp) && is_identified(tmp)) {
1743 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1744 "The object has a story:");
1745
1746 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1747 tmp->msg);
1748 }
1749 }
1750 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE,
1751 " "); /* Blank line */
1752
1753 if (is_identified(tmp)) {
1754 knowledge_item_can_be_used_alchemy(op, tmp);
1755 }
1756 }
1757
1758 /**
1759 * Prints object's inventory.
1760 *
1761 * @param op
1762 * who to print for.
1763 * @param inv
1764 * if NULL then print op's inventory, else print the inventory of inv.
1765 */
1766 void inventory(object *op, object *inv) {
1767 const char *in;
1768 int items = 0, length;
1769 char weight[MAX_BUF], name[MAX_BUF];
1770
1771 if (inv == NULL && op == NULL) {
1772 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1773 "Inventory of what object?");
1774 return;
1775 }
1776 FOR_INV_PREPARE(inv ? inv : op, tmp)
1777 if ((!tmp->invisible && (inv == NULL || inv->type == CONTAINER || QUERY_FLAG(tmp, FLAG_APPLIED)))
1778 || !op || QUERY_FLAG(op, FLAG_WIZ))
1779 items++;
1780 FOR_INV_FINISH();
1781 if (inv == NULL) { /* player's inventory */
1782 if (items == 0) {
1783 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
1784 "You carry nothing.");
1785 return;
1786 } else {
1787 length = 28;
1788 in = "";
1789 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INVENTORY,
1790 "Inventory:");
1791 }
1792 } else {
1793 if (items == 0)
1794 return;
1795 else {
1796 length = 28;
1797 in = " ";
1798 }
1799 }
1800 FOR_INV_PREPARE(inv ? inv : op, tmp) {
1801 if ((!op || !QUERY_FLAG(op, FLAG_WIZ))
1802 && (tmp->invisible || (inv && inv->type != CONTAINER && !QUERY_FLAG(tmp, FLAG_APPLIED))))
1803 continue;
1804 query_weight(tmp, weight, MAX_BUF);
1805 query_name(tmp, name, MAX_BUF);
1806 if (!op || QUERY_FLAG(op, FLAG_WIZ))
1807 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INVENTORY,
1808 "[fixed]%s- %-*.*s (%5d) %-8s",
1809 in, length, length, name, tmp->count, weight);
1810 else
1811 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INVENTORY,
1812 "[fixed]%s- %-*.*s %-8s",
1813 in, length+8, length+8, name, weight);
1814 } FOR_INV_FINISH();
1815 if (!inv && op) {
1816 query_weight(op, weight, MAX_BUF);
1817 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INVENTORY,
1818 "[fixed]%-*s %-8s",
1819 41, "Total weight :", weight);
1820 }
1821 }
1822
1823 /**
1824 * Utility function to display the pickup mode for a player.
1825 *
1826 * @param op
1827 * must be a player.
1828 * @param old
1829 * previous pickup mode.
1830 */
1831 static void display_new_pickup(const object *op, int old) {
1832 int i = op->contr->mode;
1833
1834 esrv_send_pickup(op->contr);
1835
1836 if (!(i&PU_NEWMODE) || !(i&PU_DEBUG)) {
1837 if ((old & PU_INHIBIT) != (op->contr->mode & PU_INHIBIT)) {
1838 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1839 "Pickup is %s.", (old & PU_INHIBIT) ? "active" : "inhibited");
1840 }
1841 return;
1842 }
1843
1844 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1845 "%d NEWMODE",
1846 i&PU_NEWMODE ? 1 : 0);
1847 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1848 "%d DEBUG",
1849 i&PU_DEBUG ? 1 : 0);
1850 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1851 "%d INHIBIT",
1852 i&PU_INHIBIT ? 1 : 0);
1853 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1854 "%d STOP",
1855 i&PU_STOP ? 1 : 0);
1856
1857 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1858 "%d <= x pickup weight/value RATIO (0==off)",
1859 (i&PU_RATIO)*5);
1860
1861 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1862 "%d FOOD",
1863 i&PU_FOOD ? 1 : 0);
1864 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1865 "%d DRINK",
1866 i&PU_DRINK ? 1 : 0);
1867 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1868 "%d VALUABLES",
1869 i&PU_VALUABLES ? 1 : 0);
1870
1871 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1872 "%d BOW",
1873 i&PU_BOW ? 1 : 0);
1874 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1875 "%d ARROW",
1876 i&PU_ARROW ? 1 : 0);
1877
1878 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1879 "%d HELMET",
1880 i&PU_HELMET ? 1 : 0);
1881 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1882 "%d SHIELD",
1883 i&PU_SHIELD ? 1 : 0);
1884 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1885 "%d ARMOUR",
1886 i&PU_ARMOUR ? 1 : 0);
1887
1888 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1889 "%d BOOTS",
1890 i&PU_BOOTS ? 1 : 0);
1891 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1892 "%d GLOVES",
1893 i&PU_GLOVES ? 1 : 0);
1894 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1895 "%d CLOAK",
1896 i&PU_CLOAK ? 1 : 0);
1897 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1898 "%d KEY",
1899 i&PU_KEY ? 1 : 0);
1900
1901 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1902 "%d MISSILEWEAPON",
1903 i&PU_MISSILEWEAPON ? 1 : 0);
1904 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1905 "%d MELEEWEAPON",
1906 i&PU_MELEEWEAPON ? 1 : 0);
1907 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1908 "%d MAGICAL",
1909 i&PU_MAGICAL ? 1 : 0);
1910 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1911 "%d POTION",
1912 i&PU_POTION ? 1 : 0);
1913
1914 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1915 "%d SPELLBOOK",
1916 i&PU_SPELLBOOK ? 1 : 0);
1917 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1918 "%d SKILLSCROLL",
1919 i&PU_SKILLSCROLL ? 1 : 0);
1920 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1921 "%d READABLES",
1922 i&PU_READABLES ? 1 : 0);
1923 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1924 "%d MAGICDEVICE",
1925 i&PU_MAGIC_DEVICE ? 1 : 0);
1926
1927 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1928 "%d NOT CURSED",
1929 i&PU_NOT_CURSED ? 1 : 0);
1930
1931 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1932 "%d JEWELS",
1933 i&PU_JEWELS ? 1 : 0);
1934
1935 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1936 "%d FLESH",
1937 i&PU_FLESH ? 1 : 0);
1938
1939 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1940 "%d CONTAINER",
1941 i&PU_CONTAINER ? 1 : 0);
1942
1943 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO,
1944 "");
1945 }
1946
1947 /**
1948 * 'pickup' command.
1949 *
1950 * @param op
1951 * player.
1952 * @param params
1953 * pickup mode. Can be empty to display the current mode.
1954 * @todo trash old pickup mode, merge with new pickup.
1955 */
1956 void command_pickup(object *op, const char *params) {
1957 uint32_t i;
1958 static const char *names[] = {
1959 "debug", "inhibit", "stop", "food", "drink",
1960 "valuables", "bow", "arrow", "helmet", "shield",
1961 "armour", "boots", "gloves", "cloak", "key",
1962 "missile", "melee", "magical", "potion", "spellbook",
1963 "skillscroll", "readables", "magicdevice", "notcursed", "jewels",
1964 "flesh", "container", NULL
1965 };
1966 static const uint32_t modes[] = {
1967 PU_DEBUG, PU_INHIBIT, PU_STOP, PU_FOOD, PU_DRINK, PU_VALUABLES, PU_BOW, PU_ARROW, PU_HELMET,
1968 PU_SHIELD, PU_ARMOUR, PU_BOOTS, PU_GLOVES, PU_CLOAK, PU_KEY, PU_MISSILEWEAPON, PU_MELEEWEAPON,
1969 PU_MAGICAL, PU_POTION, PU_SPELLBOOK, PU_SKILLSCROLL, PU_READABLES, PU_MAGIC_DEVICE,
1970 PU_NOT_CURSED, PU_JEWELS, PU_FLESH, PU_CONTAINER, 0
1971 };
1972
1973 if (*params == '\0') {
1974 /* if the new mode is used, just print the settings */
1975 if (op->contr->mode&PU_NEWMODE) {
1976 display_new_pickup(op, op->contr->mode);
1977 return;
1978 }
1979 if (1)
1980 LOG(llevDebug, "command_pickup: !params\n");
1981 set_pickup_mode(op, op->contr->mode > 6 ? 0 : op->contr->mode+1);
1982 return;
1983 }
1984
1985 while (*params == ' ')
1986 params++;
1987
1988 if (*params == '+' || *params == '-' || *params == '!') {
1989 int mode;
1990
1991 for (mode = 0; names[mode]; mode++) {
1992 if (!strcmp(names[mode], params+1)) {
1993 int old = op->contr->mode;
1994 i = op->contr->mode;
1995 if (!(i&PU_NEWMODE))
1996 i = PU_NEWMODE;
1997 if (*params == '+')
1998 i = i|modes[mode];
1999 else if (*params == '-')
2000 i = i&~modes[mode];
2001 else {
2002 if (i&modes[mode])
2003 i = i&~modes[mode];
2004 else
2005 i = i|modes[mode];
2006 }
2007 op->contr->mode = i;
2008 display_new_pickup(op, old);
2009 return;
2010 }
2011 }
2012 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2013 "Pickup: invalid item %s\n",
2014 params);
2015 return;
2016 }
2017
2018 if (sscanf(params, "%u", &i) != 1) {
2019 if (1)
2020 LOG(llevDebug, "command_pickup: params==NULL\n");
2021 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2022 "Usage: pickup <0-7> or <value_density> .");
2023 return;
2024 }
2025 set_pickup_mode(op, i);
2026 display_new_pickup(op, op->contr->mode);
2027 }
2028
2029 /**
2030 * Sets the 'old' pickup mode.
2031 *
2032 * @param op
2033 * player.
2034 * @param i
2035 * new pickup mode.
2036 */
2037 static void set_pickup_mode(const object *op, int i) {
2038 op->contr->mode = i;
2039 switch (op->contr->mode) {
2040 case 0:
2041 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2042 "Mode: Don't pick up.");
2043 break;
2044
2045 case 1:
2046 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2047 "Mode: Pick up one item.");
2048 break;
2049
2050 case 2:
2051 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2052 "Mode: Pick up one item and stop.");
2053 break;
2054
2055 case 3:
2056 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2057 "Mode: Stop before picking up.");
2058 break;
2059
2060 case 4:
2061 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2062 "Mode: Pick up all items.");
2063 break;
2064
2065 case 5:
2066 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2067 "Mode: Pick up all items and stop.");
2068 break;
2069
2070 case 6:
2071 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2072 "Mode: Pick up all magic items.");
2073 break;
2074
2075 case 7:
2076 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2077 "Mode: Pick up all coins and gems");
2078 break;
2079 }
2080 }
2081
2082 /**
2083 * 'search-items' command.
2084 *
2085 * @param op
2086 * player.
2087 * @param params
2088 * options.
2089 */
2090 void command_search_items(object *op, const char *params) {
2091 if (settings.search_items == FALSE)
2092 return;
2093
2094 if (*params == '\0') {
2095 if (op->contr->search_str[0] == '\0') {
2096 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2097 "Example: search magic+1 "
2098 "Would automatically pick up all "
2099 "items containing the word 'magic+1'.");
2100 return;
2101 }
2102 op->contr->search_str[0] = '\0';
2103 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2104 "Search mode turned off.");
2105 fix_object(op);
2106 return;
2107 }
2108 if ((int)strlen(params) >= MAX_BUF) {
2109 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2110 "Search string too long.");
2111 return;
2112 }
2113 strcpy(op->contr->search_str, params);
2114 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2115 "Searching for '%s'.",
2116 op->contr->search_str);
2117 fix_object(op);
2118 }
2119
2120 /**
2121 * Changing the custom name of an item
2122 *
2123 * Syntax is: rename \<what object\> to \<new name\>
2124 * - if 'what object' is omitted, marked object is used
2125 * - if 'to new name' is omitted, custom name is cleared
2126 *
2127 * Names are considered for all purpose having a length <=127 (max length sent to client
2128 * by server).
2129 *
2130 * @param op
2131 * player.
2132 * @param params
2133 * how to rename.
2134 */
2135 void command_rename_item(object *op, const char *params) {
2136 char buf[VERY_BIG_BUF], name[MAX_BUF];
2137 tag_t itemnumber;
2138 object *item = NULL;
2139 object *tmp;
2140 char *closebrace;
2141 size_t counter;
2142
2143 if (*params != '\0') {
2144 /* Let's skip white spaces */
2145 while (' ' == *params)
2146 params++;
2147
2148 /* Checking the first part */
2149 itemnumber = atoi(params);
2150 if (itemnumber != 0) {
2151 int found = 0;
2152 FOR_INV_PREPARE(op, item)
2153 if (item->count == itemnumber && !item->invisible) {
2154 found = 1;
2155 break;
2156 }
2157 FOR_INV_FINISH();
2158 if (!found) {
2159 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2160 "Tried to rename an invalid item.");
2161 return;
2162 }
2163 while (isdigit(*params) || ' ' == *params)
2164 params++;
2165 } else if ('<' == *params) {
2166 /* Got old name, let's get it & find appropriate matching item */
2167 closebrace = strchr(params, '>');
2168 if (!closebrace) {
2169 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2170 "Syntax error!");
2171 return;
2172 }
2173 /* Sanity check for buffer overruns */
2174 if (closebrace-params > 127) {
2175 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2176 "Old name too long (up to 127 characters allowed)!");
2177 return;
2178 }
2179 /* Copy the old name */
2180 snprintf(buf, sizeof(buf), "%.*s", (int)(closebrace-(params+1)), params+1);
2181
2182 /* Find best matching item */
2183 item = find_best_object_match(op, buf);
2184 if (!item) {
2185 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2186 "Could not find a matching item to rename.");
2187 return;
2188 }
2189
2190 /* Now need to move pointer to just after > */
2191 params = closebrace+1;
2192 while (' ' == *params)
2193 params++;
2194 } else {
2195 /* Use marked item */
2196 item = find_marked_object(op);
2197 if (!item) {
2198 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2199 "No marked item to rename.");
2200 return;
2201 }
2202 }
2203
2204 /* Now let's find the new name */
2205 if (!strncmp(params, "to ", 3)) {
2206 params += 3;
2207 while (' ' == *params)
2208 params++;
2209 if ('<' != *params) {
2210 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2211 "Syntax error, expecting < at start of new name!");
2212 return;
2213 }
2214 closebrace = strchr(params+1, '>');
2215 if (!closebrace) {
2216 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2217 "Syntax error, expecting > at end of new name!");
2218 return;
2219 }
2220
2221 /* Sanity check for buffer overruns */
2222 if (closebrace-params > 127) {
2223 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2224 "New name too long (up to 127 characters allowed)!");
2225 return;
2226 }
2227
2228 /* Copy the new name */
2229 snprintf(buf, sizeof(buf), "%.*s", (int)(closebrace-(params+1)), params+1);
2230
2231 /* Let's check it for weird characters */
2232 for (counter = 0; counter < strlen(buf); counter++) {
2233 if (isalnum(buf[counter]))
2234 continue;
2235 if (' ' == buf[counter])
2236 continue;
2237 if ('\'' == buf[counter])
2238 continue;
2239 if ('+' == buf[counter])
2240 continue;
2241 if ('_' == buf[counter])
2242 continue;
2243 if ('-' == buf[counter])
2244 continue;
2245
2246 /* If we come here, then the name contains an invalid character...
2247 * tell the player & exit
2248 */
2249 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2250 "Invalid new name!");
2251 return;
2252 }
2253 } else {
2254 /* If param contains something, then syntax error... */
2255 if (strlen(params)) {
2256 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2257 "Syntax error, expected 'to <' after old name!");
2258 return;
2259 }
2260 /* New name is empty */
2261 buf[0] = '\0';
2262 }
2263 } else {
2264 /* Last case: *params=='\0' */
2265 item = find_marked_object(op);
2266 if (!item) {
2267 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2268 "No marked item to rename.");
2269 return;
2270 }
2271 buf[0] = '\0';
2272 }
2273
2274 /* Coming here, everything is fine... */
2275 if (!strlen(buf)) {
2276 /* Clear custom name */
2277 if (item->custom_name == NULL) {
2278 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR,
2279 "This item has no custom name.");
2280 return;
2281 }
2282
2283 FREE_AND_CLEAR_STR(item->custom_name);
2284 query_base_name(item, item->nrof > 1 ? 1 : 0, name, MAX_BUF);
2285 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2286 "You stop calling your %s with weird names.",
2287 name);
2288 } else {
2289 if (item->custom_name != NULL && strcmp(item->custom_name, buf) == 0) {
2290 query_base_name(item, item->nrof > 1 ? 1 : 0, name, MAX_BUF);
2291 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2292 "You keep calling your %s %s.",
2293 name, buf);
2294 return;
2295 }
2296
2297 /* Set custom name */
2298 FREE_AND_COPY(item->custom_name, buf);
2299
2300 query_base_name(item, item->nrof > 1 ? 1 : 0, name, MAX_BUF);
2301 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS,
2302 "Your %s will now be called %s.",
2303 name, buf);
2304 }
2305
2306 tmp = object_merge(item, NULL);
2307 if (tmp == NULL) {
2308 /* object was not merged - if it was, object_merge() handles updating for us. */
2309 esrv_update_item(UPD_NAME, op, item);
2310 }
2311 }
2312
2313 /**
2314 * Alternate way to lock/unlock items (command line).
2315 *
2316 * @param op
2317 * player
2318 * @param params
2319 * sent command line.
2320 */
2321 void command_lock_item(object *op, const char *params) {
2322 object *item;
2323 object *tmp;
2324 char name[HUGE_BUF];
2325
2326 if (*params == '\0' || strlen(params) == 0) {
2327 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE,
2328 "Lock what item?");
2329 return;
2330 }
2331
2332 item = find_best_object_match(op, params);
2333 if (!item) {
2334 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE,
2335 "Can't find any matching item.");
2336 return;
2337 }
2338
2339 query_short_name(item, name, HUGE_BUF);
2340 if (QUERY_FLAG(item, FLAG_INV_LOCKED)) {
2341 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE,
2342 "Unlocked %s.", name);
2343 CLEAR_FLAG(item, FLAG_INV_LOCKED);
2344 } else {
2345 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE,
2346 "Locked %s.", name);
2347 SET_FLAG(item, FLAG_INV_LOCKED);
2348 }
2349
2350 tmp = object_merge(item, NULL);
2351 if (tmp == NULL) {
2352 /* object was not merged, if it was object_merge() handles updates for us */
2353 esrv_update_item(UPD_FLAGS, op, item);
2354 }
2355 }
2356
2357 /**
2358 * Try to use an item on another. Items are checked for key/values matching.
2359 * @param op
2360 * player.
2361 * @param params
2362 * sent string, with all parameters.
2363 */
2364 void command_use(object *op, const char *params) {
2365 char *with, copy[MAX_BUF];
2366 object *first, *second/*, *add*/;
2367 /*archetype *arch;*/
2368 /*int count;*/
2369 /*sstring data;*/
2370 recipe *transformation;
2371
2372 if (!IS_PLAYER(op))
2373 return;
2374
2375 strlcpy(copy, params, sizeof(copy));
2376 with = strstr(copy, " with ");
2377 if (!with) {
2378 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, "Syntax is use <item> with <item>.");
2379 return;
2380 }
2381
2382 with[0] = '\0';
2383 with = with+strlen(" with ");
2384
2385 first = find_best_object_match(op, copy);
2386 if (!first) {
2387 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, "No match for %s.", copy);
2388 return;
2389 }
2390 second = find_best_object_match(op, with);
2391 if (!second) {
2392 draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, "No match for %s.", with);
2393 return;
2394 }
2395
2396 transformation = NULL;
2397 while ((transformation = find_recipe_for_tool(first->arch->name, transformation))) {
2398 /** @todo handle multiple ingredients */
2399 if (transformation->ingred_count != 1)
2400 continue;
2401
2402 /* LOG(llevDebug, "use: check %s\n", transformation->title);*/
2403 if (strcmp(second->name, transformation->ingred->name) == 0) {
2404 /** @todo handle ingredient count, handle batches, and such */
2405 object *generated = create_archetype(transformation->arch_name[0]);
2406 if (transformation->yield)
2407 generated->nrof = transformation->yield;
2408 object_insert_in_ob(generated, op);
2409 /*draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, "Found recipe %s", transformation->title);*/
2410 object_decrease_nrof_by_one(second);
2411 return;
2412 }
2413 }
2414 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, "Nothing happens.");
2415 return;
2416
2417 /*
2418 snprintf(copy, sizeof(copy), "on_use_with_%s", first->arch->name);
2419 data = object_get_value(second, copy);
2420 if (!data) {
2421 snprintf(copy, sizeof(copy), "on_use_with_%d_%d", first->type, first->subtype);
2422 data = object_get_value(second, copy);
2423 if (!data) {
2424 snprintf(copy, sizeof(copy), "on_use_with_%d", first->type);
2425 data = object_get_value(second, copy);
2426 if (!data) {
2427 draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_FAILURE, "Nothing happens.");
2428 return 1;
2429 }
2430 }
2431 }
2432
2433 while (data != NULL) {
2434 if (strncmp(data, "add ", 4) == 0) {
2435 data += 4;
2436 if (isdigit(*data)) {
2437 count = atol(data);
2438 data = strchr(data, ' ')+1;
2439 } else
2440 count = 1;
2441 with = strchr(data, ' ');
2442 if (!with) {
2443 strncpy(copy, data, sizeof(copy));
2444 data = NULL;
2445 } else {
2446 *with = '\0';
2447 strncpy(copy, data, sizeof(copy));
2448 data += strlen(copy)+1;
2449 }
2450 arch = find_archetype(copy);
2451 if (!arch) {
2452 LOG(llevError, "Use: invalid archetype %s in %s.\n", copy, second->name);
2453 return 1;
2454 }
2455 add = object_create_arch(arch);
2456 add->nrof = count;
2457 object_insert_in_ob(add, op);
2458 } else if (strncmp(data, "remove $", 8) == 0) {
2459 data += 8;
2460 if (*data == '1') {
2461 if (first)
2462 first = object_decrease_nrof_by_one(first);
2463 data += 2;
2464 } else if (*data == '2') {
2465 if (second)
2466 second = object_decrease_nrof_by_one(second);
2467 data += 2;
2468 } else {
2469 LOG(llevError, "Use: invalid use string %s in %s\n", data, second->name);
2470 return 1;
2471 }
2472 } else {
2473 LOG(llevError, "Use: invalid use string %s in %s\n", data, second->name);
2474 return 1;
2475 }
2476 }
2477
2478 return 1;
2479 */
2480 }