ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_wiz.C
Revision: 1.91
Committed: Wed Nov 21 12:12:03 2012 UTC (11 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.90: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.53 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.90 *
4 root 1.87 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.80 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992 Frank Tore Johansen
7 root 1.90 *
8 root 1.72 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 root 1.90 *
13 root 1.49 * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17 root 1.90 *
18 root 1.72 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.90 *
22 root 1.53 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.32 */
24 elmex 1.1
25     #include <global.h>
26 root 1.29 #include <sproto.h>
27 elmex 1.1 #include <spells.h>
28     #include <treasure.h>
29     #include <skills.h>
30    
31     /** Defines for DM item stack **/
32     #define STACK_SIZE 50 /* Stack size, static */
33 root 1.8
34 elmex 1.1 /* Values for 'from' field of get_dm_object */
35     #define STACK_FROM_NONE 0 /* Item was not found */
36     #define STACK_FROM_TOP 1 /* Item is stack top */
37     #define STACK_FROM_STACK 2 /* Item is somewhere in stack */
38     #define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */
39    
40     /**
41     * Enough of the DM functions seem to need this that I broke
42     * it out to a seperate function. name is the person
43     * being saught, rq is who is looking for them. This
44     * prints diagnostics messages, and returns the
45     * other player, or NULL otherwise.
46     */
47 root 1.8 static player *
48     get_other_player_from_name (object *op, char *name)
49     {
50     if (!name)
51     return NULL;
52 elmex 1.1
53 root 1.27 for_all_players (pl)
54 root 1.8 if (!strncmp (pl->ob->name, name, MAX_NAME))
55 root 1.27 {
56     if (pl->ob == op)
57     {
58     new_draw_info (NDI_UNIQUE, 0, op, "You can't do that to yourself.");
59     return NULL;
60     }
61 elmex 1.1
62 root 1.27 if (pl->ns->state != ST_PLAYING)
63     {
64     new_draw_info (NDI_UNIQUE, 0, op, "That player is in no state for that right now.");
65     return NULL;
66     }
67 elmex 1.1
68 root 1.27 return pl;
69     }
70 root 1.25
71 root 1.27 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
72     return 0;
73 elmex 1.1 }
74    
75 root 1.74 static void
76     dm_stack_pop (player *pl)
77     {
78     if (!pl->stack_items || !pl->stack_position)
79     {
80     new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
81     return;
82     }
83    
84     pl->stack_position--;
85     new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
86     }
87    
88     /**
89     * Get current stack top item for player.
90     * Returns NULL if no stacked item.
91     * If stacked item disappeared (freed), remove it.
92     *
93     * Ryo, august 2004
94     */
95     static object *
96     dm_stack_peek (player *pl)
97     {
98     object *ob;
99    
100     if (!pl->stack_position)
101     {
102     new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
103     return NULL;
104     }
105    
106     ob = find_object (pl->stack_items[pl->stack_position - 1]);
107     if (!ob)
108     {
109     new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
110     dm_stack_pop (pl);
111     return NULL;
112     }
113    
114     return ob;
115     }
116    
117     /**
118     * Push specified item on player stack.
119     * Inform player of position.
120     * Initializes variables if needed.
121     */
122     void
123     dm_stack_push (player *pl, tag_t item)
124     {
125     if (!pl->stack_items)
126     {
127     pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
128     memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
129     }
130    
131     if (pl->stack_position == STACK_SIZE)
132     {
133     new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
134     return;
135     }
136    
137     pl->stack_items[pl->stack_position] = item;
138     new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
139     pl->stack_position++;
140     }
141    
142     /**
143     * Checks 'params' for object code.
144     *
145     * Can be:
146     * * empty => get current object stack top for player
147     * * number => get item with that tag, stack it for future use
148     * * $number => get specified stack item
149     * * "me" => player himself
150     *
151     * At function exit, params points to first non-object char
152     *
153     * 'from', if not NULL, contains at exit:
154     * * STACK_FROM_NONE => object not found
155     * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
156     * * STACK_FROM_STACK => item from somewhere in the stack
157     * * STACK_FROM_NUMBER => item by number, pushed on stack
158     *
159     * Ryo, august 2004
160     */
161     static object *
162     get_dm_object (player *pl, char **params, int *from)
163     {
164     int item_tag, item_position;
165     object *ob;
166    
167     if (!pl)
168     return NULL;
169    
170     if (!params || !*params || **params == '\0')
171     {
172     if (from)
173     *from = STACK_FROM_TOP;
174     /* No parameter => get stack item */
175     return dm_stack_peek (pl);
176     }
177    
178     /* Let's clean white spaces */
179     while (**params == ' ')
180     (*params)++;
181    
182     /* Next case: number => item tag */
183     if (sscanf (*params, "%d", &item_tag))
184     {
185     /* Move parameter to next item */
186     while (isdigit (**params))
187     (*params)++;
188    
189     /* And skip blanks, too */
190     while (**params == ' ')
191     (*params)++;
192    
193     /* Get item */
194     ob = find_object (item_tag);
195     if (!ob)
196     {
197     if (from)
198     *from = STACK_FROM_NONE;
199     new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
200     return NULL;
201     }
202    
203     /* Got one, let's push it on stack */
204     dm_stack_push (pl, item_tag);
205     if (from)
206     *from = STACK_FROM_NUMBER;
207     return ob;
208     }
209    
210     /* Next case: $number => stack item */
211     if (sscanf (*params, "$%d", &item_position))
212     {
213     /* Move parameter to next item */
214     (*params)++;
215    
216     while (isdigit (**params))
217     (*params)++;
218     while (**params == ' ')
219     (*params)++;
220    
221     if (item_position >= pl->stack_position)
222     {
223     if (from)
224     *from = STACK_FROM_NONE;
225     new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
226     return NULL;
227     }
228    
229     ob = find_object (pl->stack_items[item_position]);
230     if (!ob)
231     {
232     if (from)
233     *from = STACK_FROM_NONE;
234     new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
235     return NULL;
236     }
237    
238     if (from)
239     *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
240     return ob;
241     }
242    
243     /* Next case: 'me' => return pl->ob */
244     if (!strncmp (*params, "me", 2))
245     {
246     if (from)
247     *from = STACK_FROM_NUMBER;
248     dm_stack_push (pl, pl->ob->count);
249    
250     /* Skip to next token */
251     (*params) += 2;
252     while (**params == ' ')
253     (*params)++;
254    
255     return pl->ob;
256     }
257    
258     /* Last case: get stack top */
259     if (from)
260     *from = STACK_FROM_TOP;
261     return dm_stack_peek (pl);
262     }
263    
264 elmex 1.1 /**
265     * Actually hides specified player (obviously a DM).
266     * If 'silent_dm' is non zero, other players are informed of DM entering/leaving,
267     * else they just think someone left/entered.
268     */
269 root 1.74 static void
270 root 1.8 do_wizard_hide (object *op, int silent_dm)
271     {
272     if (op->contr->hidden)
273     {
274     op->contr->hidden = 0;
275     op->invisible = 1;
276     new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
277     op->map->players++;
278     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
279 root 1.35
280 root 1.8 if (!silent_dm)
281 root 1.35 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
282 root 1.8 }
283     else
284     {
285     op->contr->hidden = 1;
286     new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you.");
287     op->map->players--;
288 root 1.35
289 root 1.8 if (!silent_dm)
290 root 1.35 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
291    
292 root 1.8 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name);
293     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name);
294 elmex 1.1 }
295     }
296    
297 root 1.8 int
298     command_hide (object *op, char *params)
299 elmex 1.1 {
300 root 1.8 do_wizard_hide (op, 0);
301     return 1;
302 elmex 1.1 }
303    
304     /**
305     * This finds and returns the object which matches the name or
306     * object nubmer (specified via num #whatever).
307     */
308 root 1.8 static object *
309     find_object_both (char *params)
310     {
311     if (!params)
312     return NULL;
313 root 1.9
314 root 1.8 if (params[0] == '#')
315     return find_object (atol (params + 1));
316     else
317     return find_object_name (params);
318 elmex 1.1 }
319    
320     /**
321     * Sets the god for some objects. params should contain two values -
322     * first the object to change, followed by the god to change it to.
323     */
324 root 1.8 int
325     command_setgod (object *op, char *params)
326     {
327     object *ob, *god;
328     char *str;
329 elmex 1.1
330 root 1.8 if (!params || !(str = strchr (params, ' ')))
331     {
332     new_draw_info (NDI_UNIQUE, 0, op, "Usage: setgod object god");
333     return 0;
334 elmex 1.1 }
335    
336 root 1.8 /* kill the space, and set string to the next param */
337     *str++ = '\0';
338     if (!(ob = find_object_both (params)))
339     {
340     new_draw_info_format (NDI_UNIQUE, 0, op, "Set whose god - can not find object %s?", params);
341     return 1;
342 elmex 1.1 }
343    
344 root 1.8 /*
345     * Perhaps this is overly restrictive? Should we perhaps be able
346     * to rebless altars and the like?
347     */
348     if (ob->type != PLAYER)
349     {
350     new_draw_info_format (NDI_UNIQUE, 0, op, "%s is not a player - can not change its god", &ob->name);
351     return 1;
352 elmex 1.1 }
353    
354 root 1.8 god = find_god (str);
355     if (god == NULL)
356     {
357     new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str);
358     return 1;
359 elmex 1.1 }
360    
361 root 1.83 ob->become_follower (god);
362 root 1.8 return 1;
363 elmex 1.1 }
364    
365     int
366 root 1.8 command_freeze (object *op, char *params)
367 elmex 1.1 {
368 root 1.8 int ticks;
369     player *pl;
370 elmex 1.1
371 root 1.8 if (!params)
372     {
373     new_draw_info (NDI_UNIQUE, 0, op, "Usage: freeze [ticks] <player>.");
374     return 1;
375     }
376 elmex 1.1
377 root 1.8 ticks = atoi (params);
378     if (ticks)
379     {
380     while ((isdigit (*params) || isspace (*params)) && *params != 0)
381     params++;
382     if (*params == 0)
383     {
384     new_draw_info (NDI_UNIQUE, 0, op, "Usage: freeze [ticks] <player>.");
385     return 1;
386 elmex 1.1 }
387     }
388 root 1.8 else
389     ticks = 100;
390 elmex 1.1
391 root 1.8 pl = get_other_player_from_name (op, params);
392     if (!pl)
393 elmex 1.1 return 1;
394 root 1.8
395     new_draw_info (NDI_UNIQUE | NDI_RED, 0, pl->ob, "You have been frozen by the DM!");
396     new_draw_info_format (NDI_UNIQUE, 0, op, "You freeze %s for %d ticks", &pl->ob->name, ticks);
397     pl->ob->speed_left = -(pl->ob->speed * ticks);
398     return 0;
399 elmex 1.1 }
400    
401 root 1.8 int
402     command_arrest (object *op, char *params)
403     {
404     object *dummy;
405     player *pl;
406    
407     if (!op)
408 elmex 1.1 return 0;
409 root 1.28
410 root 1.8 if (params == NULL)
411     {
412     new_draw_info (NDI_UNIQUE, 0, op, "Usage: arrest <player>.");
413     return 1;
414     }
415 root 1.28
416 root 1.8 pl = get_other_player_from_name (op, params);
417     if (!pl)
418     return 1;
419 root 1.28
420 root 1.8 dummy = get_jail_exit (pl->ob);
421     if (!dummy)
422     {
423     /* we have nowhere to send the prisoner.... */
424     new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them");
425     return 0;
426     }
427 root 1.28
428 root 1.57 pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO
429 root 1.60 dummy->destroy ();
430 root 1.59
431 root 1.8 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested.");
432     new_draw_info (NDI_UNIQUE, 0, op, "OK.");
433     LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name);
434     return 1;
435 elmex 1.1 }
436    
437 root 1.8 int
438     command_summon (object *op, char *params)
439     {
440     int i;
441     player *pl;
442    
443     if (!op)
444     return 0;
445    
446     if (params == NULL)
447     {
448     new_draw_info (NDI_UNIQUE, 0, op, "Usage: summon <player>.");
449     return 1;
450     }
451    
452     pl = get_other_player_from_name (op, params);
453     if (!pl)
454 elmex 1.1 return 1;
455    
456 root 1.85 maptile *m = op->map;
457     sint16 nx = op->x;
458     sint16 ny = op->y;
459    
460     i = find_free_spot (op, m, nx, ny, 1, SIZEOFFREE1+1);
461 root 1.8 if (i == -1)
462     {
463     new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
464     return 1;
465     }
466    
467 root 1.85 nx += freearr_x [i];
468     ny += freearr_y [i];
469    
470     if (!xy_normalise (m, nx, ny))
471     {
472     new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
473     return 1;
474     }
475    
476     pl->ob->player_goto (m->path, nx, ny);
477 root 1.8 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
478     new_draw_info (NDI_UNIQUE, 0, op, "OK.");
479 elmex 1.1
480 root 1.8 return 1;
481 elmex 1.1 }
482    
483     /**
484     * This function is a real mess, because we're stucking getting
485     * the entire item description in one block of text, so we just
486     * can't simply parse it - we need to look for double quotes
487     * for example. This could actually get much simpler with just a
488     * little help from the client - if we could get line breaks, it
489     * makes parsing much easier, eg, something like:
490     * arch dragon
491     * name big nasty creature
492     * hp 5
493     * sp 30
494     * Is much easier to parse than
495     * dragon name "big nasty creature" hp 5 sp 30
496     * for example.
497     */
498 root 1.8 int
499     command_create (object *op, char *params)
500     {
501     object *tmp = NULL;
502     int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace;
503 root 1.88 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline;
504 root 1.8 archetype *at, *at_spell = NULL;
505     artifact *art = NULL;
506    
507     if (!op)
508     return 0;
509    
510     if (params == NULL)
511     {
512     new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]");
513     return 1;
514     }
515 root 1.9
516 root 1.8 bp = params;
517    
518     /* We need to know where the line ends */
519     endline = bp + strlen (bp);
520    
521     if (sscanf (bp, "%d ", &nrof))
522     {
523     if ((bp = strchr (params, ' ')) == NULL)
524     {
525     new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]");
526     return 1;
527     }
528     bp++;
529     set_nrof = 1;
530     LOG (llevDebug, "%s creates: (%d) %s\n", &op->name, nrof, bp);
531     }
532 root 1.9
533 root 1.8 if (sscanf (bp, "%d ", &magic))
534     {
535     if ((bp = strchr (bp, ' ')) == NULL)
536     {
537     new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]");
538     return 1;
539     }
540 root 1.9
541 root 1.8 bp++;
542     set_magic = 1;
543     LOG (llevDebug, "%s creates: (%d) (%d) %s\n", &op->name, nrof, magic, bp);
544     }
545 root 1.9
546 root 1.8 if ((cp = strstr (bp, " of ")) != NULL)
547     {
548     *cp = '\0';
549     cp += 4;
550     }
551 root 1.9
552 root 1.8 for (bp2 = bp; *bp2; bp2++)
553     {
554     if (*bp2 == ' ')
555     {
556     *bp2 = '\0';
557     bp2++;
558     break;
559     }
560     }
561    
562 root 1.11 if ((at = archetype::find (bp)) == NULL)
563 root 1.8 {
564     new_draw_info (NDI_UNIQUE, 0, op, "No such archetype.");
565     return 1;
566     }
567    
568     if (cp)
569     {
570     char spell_name[MAX_BUF], *fsp = NULL;
571    
572     /*
573     * Try to find a spell object for this. Note that
574     * we also set up spell_name which is only
575     * the first word.
576     */
577    
578 root 1.11 at_spell = archetype::find (cp);
579 root 1.47 if (!at_spell || at_spell->type != SPELL)
580 root 1.8 at_spell = find_archetype_by_object_name (cp);
581 root 1.47 if (!at_spell || at_spell->type != SPELL)
582 root 1.8 {
583 root 1.34 assign (spell_name, cp);
584 root 1.8 fsp = strchr (spell_name, ' ');
585     if (fsp)
586     {
587     *fsp = 0;
588     fsp++;
589 root 1.11 at_spell = archetype::find (spell_name);
590 root 1.8
591     /* Got a spell, update the first string pointer */
592 root 1.47 if (at_spell && at_spell->type == SPELL)
593 root 1.8 bp2 = cp + strlen (spell_name) + 1;
594     else
595     at_spell = NULL;
596 elmex 1.1 }
597     }
598    
599 root 1.8 /* OK - we didn't find a spell - presume the 'of'
600     * in this case means its an artifact.
601     */
602     if (!at_spell)
603     {
604 root 1.47 if (find_artifactlist (at->type) == NULL)
605     new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->type);
606 root 1.8 else
607     {
608 root 1.47 art = find_artifactlist (at->type)->items;
609 root 1.8
610 root 1.42 while (art)
611 root 1.8 {
612 root 1.66 if (!strcmp (&art->item->name, cp))
613 root 1.8 break;
614 root 1.42
615 root 1.8 art = art->next;
616     }
617 root 1.9
618 root 1.8 if (!art)
619 root 1.47 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->type, cp);
620 elmex 1.1 }
621 root 1.9
622 root 1.8 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp);
623 elmex 1.1 }
624 root 1.8 } /* if cp */
625    
626 root 1.47 if ((at->type == ROD || at->type == WAND || at->type == SCROLL ||
627     at->type == HORN || at->type == SPELLBOOK) && !at_spell)
628 root 1.8 {
629     new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find spell %s for object that needs it, or it is of wrong type", cp);
630     return 1;
631     }
632 elmex 1.1
633 root 1.8 /*
634     * Rather than have two different blocks with a lot of similar code,
635     * just create one object, do all the processing, and then determine
636     * if that one object should be inserted or if we need to make copies.
637     */
638 root 1.79 tmp = at->instance ();
639 root 1.9
640 root 1.8 if (set_magic)
641     set_abs_magic (tmp, magic);
642 root 1.9
643 root 1.8 if (art)
644     give_artifact_abilities (tmp, art->item);
645 root 1.9
646 root 1.84 if (tmp->need_identify ())
647 root 1.8 {
648 root 1.82 tmp->set_flag (FLAG_IDENTIFIED);
649     tmp->clr_flag (FLAG_KNOWN_MAGICAL);
650 root 1.8 }
651    
652     /*
653     * This entire block here tries to find variable pairings,
654     * eg, 'hp 4' or the like. The mess here is that values
655     * can be quoted (eg "my cool sword"); So the basic logic
656     * is we want to find two spaces, but if we got a quote,
657     * any spaces there don't count.
658     */
659     while (*bp2 && bp2 <= endline)
660     {
661     gotspace = 0;
662     gotquote = 0;
663 root 1.9
664 root 1.8 /* find the first quote */
665     for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++)
666     {
667    
668     /* Found a quote - now lets find the second one */
669     if (*bp3 == '"')
670     {
671     *bp3 = ' ';
672     bp2 = bp3 + 1; /* Update start of string */
673     bp3++;
674     gotquote++;
675     while (*bp3)
676     {
677     if (*bp3 == '"')
678     {
679     *bp3 = '\0';
680     gotquote++;
681     }
682     else
683     bp3++;
684 elmex 1.1 }
685 root 1.8 }
686     else if (*bp3 == ' ')
687 root 1.9 gotspace++;
688 elmex 1.1 }
689    
690 root 1.8 /*
691     * If we got two spaces, send the second one to null.
692     * if we've reached the end of the line, increase gotspace -
693     * this is perfectly valid for the list entry listed.
694     */
695     if (gotspace == 2 || gotquote == 2)
696     {
697     bp3--; /* Undo the extra increment */
698     *bp3 = '\0';
699     }
700     else if (*bp3 == '\0')
701     gotspace++;
702    
703     if ((gotquote && gotquote != 2) || (gotspace != 2 && gotquote != 2))
704     {
705     /*
706     * Unfortunately, we've clobbered lots of values, so printing
707     * out what we have probably isn't useful. Break out, because
708     * trying to recover is probably won't get anything useful
709     * anyways, and we'd be confused about end of line pointers
710     * anyways.
711     */
712     new_draw_info_format (NDI_UNIQUE, 0, op, "Malformed create line: %s", bp2);
713     break;
714     }
715 root 1.9
716 root 1.8 /* bp2 should still point to the start of this line,
717     * with bp3 pointing to the end
718     */
719     if (set_variable (tmp, bp2) == -1)
720     new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", bp2);
721     else
722     new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2);
723 root 1.9
724 root 1.8 bp2 = bp3 + 1;
725     }
726    
727 root 1.47 if (at->nrof)
728 root 1.8 {
729     if (at_spell)
730 root 1.79 tmp->insert (at_spell->instance ());
731 root 1.8
732 root 1.54 tmp->x = op->x;
733     tmp->y = op->y;
734     tmp->map = op->map;
735 root 1.9
736 root 1.8 if (set_nrof)
737     tmp->nrof = nrof;
738 root 1.9
739 root 1.54 op->insert (tmp);
740 root 1.8
741     /* Let's put this created item on stack so dm can access it easily. */
742     dm_stack_push (op->contr, tmp->count);
743    
744     return 1;
745     }
746     else
747     {
748     for (i = 0; i < (set_nrof ? nrof : 1); i++)
749     {
750 root 1.10 object *prev = 0, *head = 0;
751 root 1.8
752 root 1.48 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
753 root 1.8 {
754 root 1.79 object *dup = atmp->instance ();
755 root 1.8
756     if (at_spell)
757 root 1.79 insert_ob_in_ob (at_spell->instance (), dup);
758 root 1.8
759     /*
760     * The head is what contains all the important bits,
761     * so just copying it over should be fine.
762     */
763 root 1.10 if (!head)
764 root 1.8 {
765     head = dup;
766 root 1.22 tmp->copy_to (dup);
767 elmex 1.1 }
768 root 1.9
769 root 1.47 dup->x = op->x + dup->arch->x;
770     dup->y = op->y + dup->arch->y;
771 root 1.8 dup->map = op->map;
772    
773     if (head != dup)
774     {
775     dup->head = head;
776     prev->more = dup;
777 elmex 1.1 }
778 root 1.9
779 root 1.8 prev = dup;
780 elmex 1.1 }
781    
782 root 1.82 if (head->flag [FLAG_ALIVE])
783 root 1.8 {
784     object *check = head;
785     int size_x = 0;
786     int size_y = 0;
787    
788     while (check)
789     {
790 root 1.77 size_x = max (size_x, check->arch->x);
791     size_y = max (size_y, check->arch->y);
792 root 1.8 check = check->more;
793 elmex 1.1 }
794    
795 root 1.8 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
796     {
797     if (head->x < size_x || head->y < size_y)
798     {
799     dm_stack_pop (op->contr);
800 root 1.60 head->destroy ();
801 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "Object too big to insert in map, or wrong position.");
802 root 1.60 tmp->destroy ();
803 root 1.8 return 1;
804 elmex 1.1 }
805    
806 root 1.8 check = head;
807 root 1.9
808 root 1.8 while (check)
809     {
810     check->x -= size_x;
811     check->y -= size_y;
812     check = check->more;
813 elmex 1.1 }
814     }
815    
816 root 1.8 insert_ob_in_map (head, op->map, op, 0);
817     }
818     else
819     head = insert_ob_in_ob (head, op);
820    
821     /* Let's put this created item on stack so dm can access it easily. */
822     /* Wonder if we really want to push all of these, but since
823     * things like rods have nrof 0, we want to cover those.
824     */
825     dm_stack_push (op->contr, head->count);
826    
827 root 1.54 if (at->randomitems && !at_spell)
828 root 1.47 create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0);
829 elmex 1.1 }
830    
831 root 1.8 /* free the one we used to copy */
832 root 1.60 tmp->destroy ();
833 elmex 1.1 }
834    
835 root 1.8 return 1;
836 elmex 1.1 }
837    
838     /*
839     * Now follows dm-commands which are also acceptable from sockets
840     */
841    
842 root 1.8 int
843     command_inventory (object *op, char *params)
844     {
845 root 1.52 int i;
846 root 1.8 object *tmp;
847 elmex 1.1
848 root 1.52 if (!params || !sscanf (params, "%d", &i) || !(tmp = find_object (i)))
849 root 1.8 {
850 root 1.52 op->contr->failmsg ("Inventory of what object (nr)?");
851     return 1;
852 elmex 1.1 }
853    
854 root 1.52 op->contr->infobox (MSG_CHANNEL ("examine"), tmp->query_inventory (op));
855 elmex 1.1
856 root 1.8 return 1;
857 elmex 1.1 }
858    
859     /* just show player's their skills for now. Dm's can
860     * already see skills w/ inventory command - b.t.
861     */
862    
863 root 1.8 int
864     command_skills (object *op, char *params)
865     {
866     show_skills (op, params);
867     return 0;
868 elmex 1.1 }
869    
870 root 1.8 int
871     command_dump (object *op, char *params)
872     {
873     object *tmp;
874 elmex 1.1
875 root 1.8 tmp = get_dm_object (op->contr, &params, NULL);
876     if (!tmp)
877 elmex 1.1 return 1;
878 root 1.8
879 root 1.16 char *dump = dump_object (tmp);
880     new_draw_info (NDI_UNIQUE, 0, op, dump);
881     free (dump);
882    
883 root 1.82 if (tmp->flag [FLAG_OBJ_ORIGINAL])
884 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
885 root 1.16
886 root 1.8 return 1;
887 elmex 1.1 }
888    
889 root 1.8 int
890     command_patch (object *op, char *params)
891     {
892     char *arg, *arg2;
893     object *tmp;
894    
895     tmp = get_dm_object (op->contr, &params, NULL);
896     if (!tmp)
897     /* Player already informed of failure */
898 elmex 1.1 return 1;
899    
900 root 1.8 /* params set to first value by get_dm_default */
901     arg = params;
902     if (arg == NULL)
903     {
904     new_draw_info (NDI_UNIQUE, 0, op, "Patch what values?");
905 elmex 1.1 return 1;
906     }
907    
908 root 1.8 if ((arg2 = strchr (arg, ' ')))
909     arg2++;
910 root 1.43
911 root 1.8 if (set_variable (tmp, arg) == -1)
912     new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", arg);
913     else
914 root 1.43 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s=%s", &tmp->name, tmp->count, arg, arg2);
915 elmex 1.1
916 root 1.8 return 1;
917     }
918 elmex 1.1
919 root 1.8 int
920     command_remove (object *op, char *params)
921     {
922     object *tmp;
923     int from;
924 elmex 1.1
925 root 1.8 tmp = get_dm_object (op->contr, &params, &from);
926     if (!tmp)
927     {
928     new_draw_info (NDI_UNIQUE, 0, op, "Remove what object (nr)?");
929     return 1;
930 elmex 1.1 }
931    
932 root 1.8 if (tmp->type == PLAYER)
933     {
934     new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!");
935     return 1;
936 elmex 1.1 }
937    
938 root 1.82 if (tmp->flag [FLAG_REMOVED])
939 root 1.8 {
940     new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp));
941     return 1;
942 elmex 1.1 }
943    
944 root 1.8 if (from != STACK_FROM_STACK)
945     /* Item is either stack top, or is a number thus is now stack top, let's remove it */
946     dm_stack_pop (op->contr);
947    
948     /* Always work on the head - otherwise object will get in odd state */
949     if (tmp->head)
950     tmp = tmp->head;
951 root 1.21 tmp->remove ();
952 root 1.8 return 1;
953 elmex 1.1 }
954    
955 root 1.8 int
956     command_free (object *op, char *params)
957     {
958     object *tmp;
959     int from;
960 elmex 1.1
961 root 1.8 tmp = get_dm_object (op->contr, &params, &from);
962 elmex 1.1
963 root 1.8 if (!tmp)
964     {
965     new_draw_info (NDI_UNIQUE, 0, op, "Free what object (nr)?");
966     return 1;
967 elmex 1.1 }
968    
969 root 1.8 if (from != STACK_FROM_STACK)
970     /* Item is either stack top, or is a number thus is now stack top, let's remove it */
971     dm_stack_pop (op->contr);
972 elmex 1.1
973 root 1.8 if (tmp->head)
974     tmp = tmp->head;
975 root 1.22
976 root 1.60 tmp->destroy ();
977 root 1.8 return 1;
978 elmex 1.1 }
979    
980     /**
981     * This adds exp to a player. We now allow adding to a specific skill.
982     */
983 root 1.8 int
984     command_addexp (object *op, char *params)
985     {
986     char buf[MAX_BUF], skill[MAX_BUF];
987 root 1.50 int q;
988     long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
989 root 1.8 object *skillob = NULL;
990 elmex 1.1
991 root 1.8 skill[0] = '\0';
992 root 1.73 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2))
993 root 1.8 {
994     new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
995     return 1;
996 elmex 1.1 }
997    
998 root 1.27 for_all_players (pl)
999 root 1.8 if (!strncmp (pl->ob->name, buf, MAX_NAME))
1000 root 1.27 {
1001     if (q >= 3)
1002     {
1003     skillob = find_skill_by_name (pl->ob, skill);
1004     if (!skillob)
1005     {
1006     new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s in %s", skill, buf);
1007     return 1;
1008     }
1009    
1010     i = check_exp_adjust (skillob, i);
1011     skillob->stats.exp += i;
1012     calc_perm_exp (skillob);
1013     player_lvl_adj (pl->ob, skillob);
1014     }
1015 elmex 1.1
1016 root 1.27 pl->ob->stats.exp += i;
1017     calc_perm_exp (pl->ob);
1018     player_lvl_adj (pl->ob, NULL);
1019 elmex 1.1
1020 root 1.27 return 1;
1021     }
1022 elmex 1.1
1023 root 1.27 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1024 root 1.8 return 1;
1025 elmex 1.1 }
1026    
1027     /**************************************************************************/
1028 root 1.8
1029 elmex 1.1 /* Mods made by Tyler Van Gorder, May 10-13, 1992. */
1030 root 1.8
1031 elmex 1.1 /* CSUChico : tvangod@cscihp.ecst.csuchico.edu */
1032 root 1.8
1033 elmex 1.1 /**************************************************************************/
1034    
1035 root 1.8 int
1036     command_stats (object *op, char *params)
1037     {
1038     char buf[MAX_BUF];
1039    
1040 sf-kernelpanic 1.89 if (params == NULL || params[0] == '\0')
1041 root 1.8 {
1042     new_draw_info (NDI_UNIQUE, 0, op, "Who?");
1043     return 1;
1044     }
1045    
1046 root 1.27 for_all_players (pl)
1047 sf-kernelpanic 1.89 if (!strcmp (&pl->ob->name, params))
1048 root 1.8 {
1049     sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp);
1050     new_draw_info (NDI_UNIQUE, 0, op, buf);
1051     sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp);
1052     new_draw_info (NDI_UNIQUE, 0, op, buf);
1053     sprintf (buf, "Con : %-2d AC : %-4d WC : %d", pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc);
1054     new_draw_info (NDI_UNIQUE, 0, op, buf);
1055     sprintf (buf, "Int : %-2d Damage : %d", pl->ob->stats.Int, pl->ob->stats.dam);
1056     new_draw_info (NDI_UNIQUE, 0, op, buf);
1057 root 1.20 sprintf (buf, "Wis : %-2d EXP : %" PRId64, pl->ob->stats.Wis, pl->ob->stats.exp);
1058 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, buf);
1059     sprintf (buf, "Pow : %-2d Grace : %d", pl->ob->stats.Pow, pl->ob->stats.grace);
1060     new_draw_info (NDI_UNIQUE, 0, op, buf);
1061     sprintf (buf, "Cha : %-2d Food : %d", pl->ob->stats.Cha, pl->ob->stats.food);
1062     new_draw_info (NDI_UNIQUE, 0, op, buf);
1063 root 1.27 return 1;
1064 root 1.8 }
1065 root 1.27
1066     new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1067 root 1.8 return 1;
1068     }
1069    
1070     int
1071     command_abil (object *op, char *params)
1072     {
1073     char thing[20], thing2[20];
1074     int iii;
1075     char buf[MAX_BUF];
1076    
1077     iii = 0;
1078     thing[0] = '\0';
1079     thing2[0] = '\0';
1080     if (params == NULL || !sscanf (params, "%s %s %d", thing, thing2, &iii) || thing == NULL)
1081     {
1082     new_draw_info (NDI_UNIQUE, 0, op, "Who?");
1083     return 1;
1084     }
1085    
1086     if (thing2 == NULL)
1087     {
1088     new_draw_info (NDI_UNIQUE, 0, op, "You can't change that.");
1089     return 1;
1090     }
1091    
1092     if (iii < MIN_STAT || iii > MAX_STAT)
1093     {
1094     new_draw_info (NDI_UNIQUE, 0, op, "Illegal range of stat.\n");
1095     return 1;
1096     }
1097    
1098 root 1.27 for_all_players (pl)
1099 root 1.8 {
1100 root 1.66 if (!strcmp (&pl->ob->name, thing))
1101 root 1.8 {
1102 root 1.43 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii;
1103     if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii;
1104     if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii;
1105     if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii;
1106     if (!strcmp ("cha", thing2)) pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii;
1107     if (!strcmp ("int", thing2)) pl->ob->stats.Int = iii, pl->orig_stats.Int = iii;
1108     if (!strcmp ("pow", thing2)) pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii;
1109    
1110 root 1.8 sprintf (buf, "%s has been altered.", &pl->ob->name);
1111     new_draw_info (NDI_UNIQUE, 0, op, buf);
1112 root 1.26 pl->ob->update_stats ();
1113 root 1.8 return 1;
1114 elmex 1.1 }
1115 root 1.8 }
1116    
1117     new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1118     return 1;
1119 elmex 1.1 }
1120    
1121 root 1.8 int
1122     command_nowiz (object *op, char *params)
1123 pippijn 1.39 { /* 'nodm' is alias */
1124 root 1.82 op->clr_flag (FLAG_WIZ);
1125     op->clr_flag (FLAG_WIZPASS);
1126     op->clr_flag (FLAG_WIZCAST);
1127     op->clr_flag (FLAG_WIZLOOK);
1128 root 1.64 op->contr->do_los = 1;
1129 root 1.8
1130     if (op->contr->hidden)
1131     {
1132     new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
1133     op->map->players++;
1134     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
1135     op->contr->hidden = 0;
1136     op->invisible = 1;
1137     }
1138     else
1139     new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
1140 root 1.64
1141 root 1.8 return 1;
1142 elmex 1.1 }
1143    
1144     /**
1145     * object *op is trying to become dm.
1146     * pl_name is name supplied by player. Restrictive DM will make it harder
1147     * for socket users to become DM - in that case, it will check for the players
1148     * character name.
1149     */
1150 root 1.8 static int
1151     checkdm (object *op, const char *pl_name, const char *pl_passwd, const char *pl_host)
1152 elmex 1.1 {
1153 root 1.8 FILE *dmfile;
1154     char buf[MAX_BUF];
1155     char line_buf[160], name[160], passwd[160], host[160];
1156 elmex 1.1
1157     #ifdef RESTRICTIVE_DM
1158 root 1.8 *pl_name = op->name ? op->name : "*";
1159 elmex 1.1 #endif
1160    
1161 root 1.8 sprintf (buf, "%s/%s", settings.confdir, DMFILE);
1162     if ((dmfile = fopen (buf, "r")) == NULL)
1163     {
1164     LOG (llevDebug, "Could not find DM file.\n");
1165     return 0;
1166     }
1167    
1168     while (fgets (line_buf, 160, dmfile) != NULL)
1169     {
1170     if (line_buf[0] == '#')
1171     continue;
1172     if (sscanf (line_buf, "%[^:]:%[^:]:%s\n", name, passwd, host) != 3)
1173     {
1174     LOG (llevError, "Warning - malformed dm file entry: %s\n", line_buf);
1175     }
1176     else if ((!strcmp (name, "*") || (pl_name && !strcmp (pl_name, name)))
1177     && (!strcmp (passwd, "*") || !strcmp (passwd, pl_passwd)) && (!strcmp (host, "*") || !strcmp (host, pl_host)))
1178     {
1179     fclose (dmfile);
1180     return (1);
1181     }
1182     }
1183     fclose (dmfile);
1184     return (0);
1185     }
1186    
1187 root 1.75 static int
1188 root 1.8 do_wizard_dm (object *op, char *params, int silent)
1189     {
1190     if (!op->contr)
1191     return 0;
1192    
1193 root 1.82 if (op->flag [FLAG_WIZ])
1194 root 1.8 {
1195     new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1196     return 0;
1197     }
1198    
1199 root 1.25 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1200 root 1.8 {
1201 root 1.82 op->set_flag (FLAG_WIZ);
1202     op->set_flag (FLAG_WIZPASS);
1203     op->set_flag (FLAG_WIZCAST);
1204     op->set_flag (FLAG_WIZLOOK);
1205 root 1.64 op->contr->do_los = 1;
1206 root 1.43
1207 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1208     op->contr->write_buf[0] = '\0';
1209    
1210     if (!silent)
1211     new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1212    
1213     return 1;
1214     }
1215     else
1216     {
1217     new_draw_info (NDI_UNIQUE, 0, op, "Sorry Pal, I don't think so.");
1218     op->contr->write_buf[0] = '\0';
1219     return 0;
1220 elmex 1.1 }
1221     }
1222    
1223     /*
1224     * Actual command to perhaps become dm. Changed aroun a bit in version 0.92.2
1225     * - allow people on sockets to become dm, and allow better dm file
1226     */
1227 root 1.8 int
1228     command_dm (object *op, char *params)
1229     {
1230     if (!op->contr)
1231     return 0;
1232 elmex 1.1
1233 root 1.8 do_wizard_dm (op, params, 0);
1234 elmex 1.1
1235 root 1.8 return 1;
1236 elmex 1.1 }
1237    
1238 root 1.8 int
1239     command_invisible (object *op, char *params)
1240     {
1241     if (op)
1242     {
1243     op->invisible += 100;
1244 root 1.41 update_object (op, UP_OBJ_CHANGE);
1245 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible.");
1246 elmex 1.1 }
1247    
1248 root 1.8 return 0;
1249 elmex 1.1 }
1250    
1251     /**
1252     * Returns spell object (from archetypes) by name.
1253     * Returns NULL if 0 or more than one spell matches.
1254     * Used for wizard's learn spell/prayer.
1255     *
1256     * op is the player issuing the command.
1257     */
1258 root 1.8 static object *
1259 root 1.66 get_spell_by_name (object *op, shstr_cmp spell_name)
1260 root 1.8 {
1261 root 1.69 /* First check for full name matches. */
1262     int conflict_found = 0;
1263 elmex 1.78 archetype *found = 0;
1264    
1265 root 1.47 for_all_archetypes (at)
1266 root 1.8 {
1267 root 1.47 if (at->type != SPELL)
1268 root 1.8 continue;
1269    
1270 root 1.66 if (at->object::name != spell_name)
1271 root 1.8 continue;
1272    
1273 root 1.65 if (found)
1274 root 1.8 {
1275     if (!conflict_found)
1276     {
1277     conflict_found = 1;
1278 root 1.67 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name);
1279 root 1.46 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1280 elmex 1.1 }
1281 root 1.46
1282     new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1283 root 1.69 return 0;
1284 elmex 1.1 }
1285    
1286 root 1.46 found = at;
1287 elmex 1.1 }
1288    
1289 root 1.8 /* Return if exactly one archetype matches. */
1290 root 1.68 if (found)
1291 root 1.79 return found->instance ();
1292 elmex 1.1
1293 root 1.8 /* No spell found: just print an error message. */
1294 root 1.70 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist.");
1295 root 1.68
1296 root 1.71 return 0;
1297 elmex 1.1 }
1298    
1299 root 1.8 static int
1300     command_learn_spell_or_prayer (object *op, char *params, int special_prayer)
1301     {
1302     object *tmp;
1303 elmex 1.1
1304 root 1.8 if (op->contr == NULL || params == NULL)
1305     {
1306     new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to learn?");
1307     return 0;
1308 elmex 1.1 }
1309    
1310 root 1.8 tmp = get_spell_by_name (op, params);
1311     if (tmp == NULL)
1312     {
1313     return 0;
1314 elmex 1.1 }
1315    
1316 root 1.8 if (check_spell_known (op, tmp->name))
1317     {
1318     new_draw_info_format (NDI_UNIQUE, 0, op, "You already know the spell %s.", &tmp->name);
1319     return 0;
1320 elmex 1.1 }
1321    
1322 root 1.8 do_learn_spell (op, tmp, special_prayer);
1323 root 1.60 tmp->destroy ();
1324 root 1.8 return 1;
1325 elmex 1.1 }
1326    
1327 root 1.8 int
1328     command_learn_spell (object *op, char *params)
1329     {
1330     return command_learn_spell_or_prayer (op, params, 0);
1331 elmex 1.1 }
1332    
1333 root 1.8 int
1334     command_learn_special_prayer (object *op, char *params)
1335 elmex 1.1 {
1336 root 1.8 return command_learn_spell_or_prayer (op, params, 1);
1337 elmex 1.1 }
1338    
1339 root 1.8 int
1340     command_forget_spell (object *op, char *params)
1341 elmex 1.1 {
1342 root 1.8 object *spell;
1343 elmex 1.1
1344 root 1.8 if (op->contr == NULL || params == NULL)
1345     {
1346     new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?");
1347     return 0;
1348 elmex 1.1 }
1349    
1350 root 1.91 spell = op->find_spell (params);
1351 root 1.8 if (spell == NULL)
1352     {
1353     new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params);
1354     return 0;
1355 elmex 1.1 }
1356    
1357 root 1.8 do_forget_spell (op, spell->name);
1358     return 1;
1359 elmex 1.1 }
1360    
1361     /**
1362     * A players wants to become DM and hide.
1363     * Let's see if that's authorized.
1364     * Make sure to not tell anything to anyone.
1365     */
1366 root 1.8 int
1367     command_dmhide (object *op, char *params)
1368     {
1369     if (!do_wizard_dm (op, params, 1))
1370     return 0;
1371 elmex 1.1
1372 root 1.8 do_wizard_hide (op, 1);
1373 elmex 1.1
1374 root 1.8 return 1;
1375 elmex 1.1 }
1376    
1377     /**
1378     * Pop the stack top.
1379     */
1380 root 1.8 int
1381     command_stack_pop (object *op, char *params)
1382     {
1383     dm_stack_pop (op->contr);
1384     return 0;
1385 elmex 1.1 }
1386    
1387     /**
1388     * Push specified item on stack.
1389     */
1390 root 1.8 int
1391     command_stack_push (object *op, char *params)
1392     {
1393     object *ob;
1394     int from;
1395    
1396     ob = get_dm_object (op->contr, &params, &from);
1397 elmex 1.1
1398 root 1.8 if (ob && from != STACK_FROM_NUMBER)
1399     /* Object was from stack, need to push it again */
1400     dm_stack_push (op->contr, ob->count);
1401    
1402     return 0;
1403 elmex 1.1 }
1404    
1405     /**
1406     * Displays stack contents.
1407     */
1408 root 1.8 int
1409     command_stack_list (object *op, char *params)
1410     {
1411     int item;
1412     object *display;
1413     player *pl = op->contr;
1414    
1415     new_draw_info (NDI_UNIQUE, 0, op, "Item stack contents:");
1416    
1417     for (item = 0; item < pl->stack_position; item++)
1418     {
1419     display = find_object (pl->stack_items[item]);
1420     if (display)
1421     new_draw_info_format (NDI_UNIQUE, 0, op, " %d : %s [%d]", item, &display->name, display->count);
1422     else
1423     /* Item was freed */
1424     new_draw_info_format (NDI_UNIQUE, 0, op, " %d : (lost item: %d)", item, pl->stack_items[item]);
1425 elmex 1.1 }
1426    
1427 root 1.8 return 0;
1428 elmex 1.1 }
1429    
1430     /**
1431     * Empty DM item stack.
1432     */
1433 root 1.8 int
1434     command_stack_clear (object *op, char *params)
1435     {
1436     op->contr->stack_position = 0;
1437     new_draw_info (NDI_UNIQUE, 0, op, "Item stack cleared.");
1438     return 0;
1439 elmex 1.1 }
1440    
1441 root 1.8 int
1442     command_insert_into (object *op, char *params)
1443 elmex 1.1 {
1444 root 1.77 object *left, *right;
1445 root 1.8 int left_from, right_from;
1446 elmex 1.1
1447 root 1.8 left = get_dm_object (op->contr, &params, &left_from);
1448     if (!left)
1449     {
1450     new_draw_info (NDI_UNIQUE, 0, op, "Insert into what object?");
1451     return 0;
1452 elmex 1.1 }
1453    
1454 root 1.8 if (left_from == STACK_FROM_NUMBER)
1455     /* Item was stacked, remove it else right will be the same... */
1456     dm_stack_pop (op->contr);
1457 elmex 1.1
1458 root 1.8 right = get_dm_object (op->contr, &params, &right_from);
1459 elmex 1.1
1460 root 1.8 if (!right)
1461     {
1462     new_draw_info (NDI_UNIQUE, 0, op, "Insert what item?");
1463     return 0;
1464 elmex 1.1 }
1465    
1466 root 1.8 if (left_from == STACK_FROM_TOP && right_from == STACK_FROM_TOP)
1467     {
1468     /*
1469     * Special case: both items were taken from stack top.
1470     * Override the behaviour, taking left as item just below top, if exists.
1471     * See function description for why.
1472     * Besides, can't insert an item into itself.
1473     */
1474     if (op->contr->stack_position > 1)
1475     {
1476     left = find_object (op->contr->stack_items[op->contr->stack_position - 2]);
1477     if (left)
1478     new_draw_info (NDI_UNIQUE, 0, op, "(Note: item to insert into taken from undertop)");
1479     else
1480     /* Stupid case: item under top was freed, fallback to stack top */
1481     left = right;
1482 elmex 1.1 }
1483     }
1484    
1485 root 1.8 if (left == right)
1486 elmex 1.1 {
1487 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert an object into itself!");
1488     return 0;
1489 elmex 1.1 }
1490    
1491 root 1.8 if (right->type == PLAYER)
1492 elmex 1.1 {
1493 root 1.8 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!");
1494     return 0;
1495 elmex 1.1 }
1496    
1497 root 1.82 if (!right->flag [FLAG_REMOVED])
1498 root 1.21 right->remove ();
1499 root 1.54
1500 root 1.77 object *inserted = insert_ob_in_ob (right, left);
1501 elmex 1.1
1502 root 1.8 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left));
1503 elmex 1.1
1504 root 1.8 return 0;
1505 elmex 1.1
1506     }