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

Comparing deliantra/server/server/c_wiz.C (file contents):
Revision 1.44 by root, Mon May 28 21:28:36 2007 UTC vs.
Revision 1.96 by root, Wed Dec 5 19:18:31 2018 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * under the terms of the GNU General Public License as published by the Free 10 * the terms of the Affero GNU General Public License as published by the
10 * Software Foundation; either version 2 of the License, or (at your option) 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, but 14 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the GNU General Public License along 19 * You should have received a copy of the Affero GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 20 * and the GNU General Public License along with this program. If not, see
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <global.h> 26#include <global.h>
26#include <sproto.h> 27#include <sproto.h>
27#include <spells.h> 28#include <spells.h>
34/* Values for 'from' field of get_dm_object */ 35/* Values for 'from' field of get_dm_object */
35#define STACK_FROM_NONE 0 /* Item was not found */ 36#define STACK_FROM_NONE 0 /* Item was not found */
36#define STACK_FROM_TOP 1 /* Item is stack top */ 37#define STACK_FROM_TOP 1 /* Item is stack top */
37#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ 38#define STACK_FROM_STACK 2 /* Item is somewhere in stack */
38#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ 39#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */
39
40 40
41/** 41/**
42 * Enough of the DM functions seem to need this that I broke 42 * Enough of the DM functions seem to need this that I broke
43 * it out to a seperate function. name is the person 43 * it out to a seperate function. name is the person
44 * being saught, rq is who is looking for them. This 44 * being saught, rq is who is looking for them. This
71 71
72 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 72 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
73 return 0; 73 return 0;
74} 74}
75 75
76static void
77dm_stack_pop (player *pl)
78{
79 if (!pl->stack_items || !pl->stack_position)
80 {
81 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
82 return;
83 }
84
85 pl->stack_position--;
86 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
87}
88
76/** 89/**
77 * Actually hides specified player (obviously a DM). 90 * Get current stack top item for player.
78 * If 'silent_dm' is non zero, other players are informed of DM entering/leaving, 91 * Returns NULL if no stacked item.
79 * else they just think someone left/entered. 92 * If stacked item disappeared (freed), remove it.
93 *
94 * Ryo, august 2004
95 */
96static object *
97dm_stack_peek (player *pl)
98{
99 object *ob;
100
101 if (!pl->stack_position)
102 {
103 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
104 return NULL;
105 }
106
107 ob = find_object (pl->stack_items[pl->stack_position - 1]);
108 if (!ob)
109 {
110 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
111 dm_stack_pop (pl);
112 return NULL;
113 }
114
115 return ob;
116}
117
118/**
119 * Push specified item on player stack.
120 * Inform player of position.
121 * Initializes variables if needed.
80 */ 122 */
81void 123void
82do_wizard_hide (object *op, int silent_dm) 124dm_stack_push (player *pl, tag_t item)
83{ 125{
84 if (op->contr->hidden) 126 if (!pl->stack_items)
85 {
86 op->contr->hidden = 0;
87 op->invisible = 1;
88 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
89 op->map->players++;
90 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
91
92 if (!silent_dm)
93 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
94 } 127 {
95 else 128 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
129 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
96 { 130 }
97 op->contr->hidden = 1;
98 new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you.");
99 op->map->players--;
100 131
101 if (!silent_dm) 132 if (pl->stack_position == STACK_SIZE)
102 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
103
104 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name);
105 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name);
106 } 133 {
107} 134 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
108
109int
110command_hide (object *op, char *params)
111{
112 do_wizard_hide (op, 0);
113 return 1; 135 return;
136 }
137
138 pl->stack_items[pl->stack_position] = item;
139 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
140 pl->stack_position++;
141}
142
143/**
144 * Checks 'params' for object code.
145 *
146 * Can be:
147 * * empty => get current object stack top for player
148 * * number => get item with that tag, stack it for future use
149 * * $number => get specified stack item
150 * * "me" => player himself
151 *
152 * At function exit, params points to first non-object char
153 *
154 * 'from', if not NULL, contains at exit:
155 * * STACK_FROM_NONE => object not found
156 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
157 * * STACK_FROM_STACK => item from somewhere in the stack
158 * * STACK_FROM_NUMBER => item by number, pushed on stack
159 *
160 * Ryo, august 2004
161 */
162static object *
163get_dm_object (player *pl, char **params, int *from)
164{
165 int item_tag, item_position;
166 object *ob;
167
168 if (!pl)
169 return NULL;
170
171 if (!params || !*params || **params == '\0')
172 {
173 if (from)
174 *from = STACK_FROM_TOP;
175 /* No parameter => get stack item */
176 return dm_stack_peek (pl);
177 }
178
179 /* Let's clean white spaces */
180 while (**params == ' ')
181 (*params)++;
182
183 /* Next case: number => item tag */
184 if (sscanf (*params, "%d", &item_tag))
185 {
186 /* Move parameter to next item */
187 while (isdigit (**params))
188 (*params)++;
189
190 /* And skip blanks, too */
191 while (**params == ' ')
192 (*params)++;
193
194 /* Get item */
195 ob = find_object (item_tag);
196 if (!ob)
197 {
198 if (from)
199 *from = STACK_FROM_NONE;
200 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
201 return NULL;
202 }
203
204 /* Got one, let's push it on stack */
205 dm_stack_push (pl, item_tag);
206 if (from)
207 *from = STACK_FROM_NUMBER;
208 return ob;
209 }
210
211 /* Next case: $number => stack item */
212 if (sscanf (*params, "$%d", &item_position))
213 {
214 /* Move parameter to next item */
215 (*params)++;
216
217 while (isdigit (**params))
218 (*params)++;
219 while (**params == ' ')
220 (*params)++;
221
222 if (item_position >= pl->stack_position)
223 {
224 if (from)
225 *from = STACK_FROM_NONE;
226 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
227 return NULL;
228 }
229
230 ob = find_object (pl->stack_items[item_position]);
231 if (!ob)
232 {
233 if (from)
234 *from = STACK_FROM_NONE;
235 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
236 return NULL;
237 }
238
239 if (from)
240 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
241 return ob;
242 }
243
244 /* Next case: 'me' => return pl->ob */
245 if (!strncmp (*params, "me", 2))
246 {
247 if (from)
248 *from = STACK_FROM_NUMBER;
249 dm_stack_push (pl, pl->ob->count);
250
251 /* Skip to next token */
252 (*params) += 2;
253 while (**params == ' ')
254 (*params)++;
255
256 return pl->ob;
257 }
258
259 /* Last case: get stack top */
260 if (from)
261 *from = STACK_FROM_TOP;
262 return dm_stack_peek (pl);
114} 263}
115 264
116/** 265/**
117 * This finds and returns the object which matches the name or 266 * This finds and returns the object which matches the name or
118 * object nubmer (specified via num #whatever). 267 * object nubmer (specified via num #whatever).
168 { 317 {
169 new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); 318 new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str);
170 return 1; 319 return 1;
171 } 320 }
172 321
173 become_follower (ob, god); 322 ob->become_follower (god);
174 return 1; 323 return 1;
175} 324}
176
177// TODO: Rewrite banish in perl and get rid of the following two functions
178int
179command_kick (object *op, char *params)
180{
181 for_all_players (pl)
182 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
183 {
184 object *op = pl->ob;
185
186 if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED))
187 {
188 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &op->name);
189 strcpy (op->contr->killer, "kicked");
190 }
191
192 pl->ns->destroy ();
193 }
194
195 return 1;
196}
197
198//TODO
199#if 0
200int
201command_save_overlay (object *op, char *params)
202{
203 if (!op)
204 return 0;
205
206 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
207 {
208 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't force an overlay save.");
209 return 1;
210 }
211
212 new_save_map (op->map, 2);
213 new_save_map (op->map, 0);
214 new_draw_info (NDI_UNIQUE, 0, op, "Current map has been saved as an" " overlay.");
215
216 ready_map_name (op->map->path, 0);
217
218 return 1;
219}
220#endif
221 325
222int 326int
223command_freeze (object *op, char *params) 327command_freeze (object *op, char *params)
224{ 328{
225 int ticks; 329 int ticks;
280 /* we have nowhere to send the prisoner.... */ 384 /* we have nowhere to send the prisoner.... */
281 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); 385 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them");
282 return 0; 386 return 0;
283 } 387 }
284 388
285 pl->ob->enter_exit (dummy); 389 pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO
286 dummy->destroy (); 390 dummy->destroy ();
391
287 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); 392 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested.");
288 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 393 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
289 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); 394 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name);
290 return 1; 395 return 1;
291} 396}
292 397
293int 398int
294command_summon (object *op, char *params) 399command_summon (object *op, char *params)
295{ 400{
296 int i; 401 int i;
297 object *dummy;
298 player *pl; 402 player *pl;
299 403
300 if (!op) 404 if (!op)
301 return 0; 405 return 0;
302 406
308 412
309 pl = get_other_player_from_name (op, params); 413 pl = get_other_player_from_name (op, params);
310 if (!pl) 414 if (!pl)
311 return 1; 415 return 1;
312 416
313 i = find_free_spot (op, op->map, op->x, op->y, 1, 9); 417 maptile *m = op->map;
418 sint16 nx = op->x;
419 sint16 ny = op->y;
420
421 i = find_free_spot (op, m, nx, ny, 1, SIZEOFFREE1+1);
314 if (i == -1) 422 if (i == -1)
315 { 423 {
316 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); 424 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
317 return 1; 425 return 1;
318 } 426 }
319 427
320 dummy = object::create (); 428 nx += DIRX (i);
321 EXIT_PATH (dummy) = op->map->path; 429 ny += DIRY (i);
322 EXIT_X (dummy) = op->x + freearr_x[i]; 430
323 EXIT_Y (dummy) = op->y + freearr_y[i]; 431 if (!xy_normalise (m, nx, ny))
324 pl->ob->enter_exit (dummy); 432 {
325 dummy->destroy (); 433 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
434 return 1;
435 }
436
437 pl->ob->player_goto (m->path, nx, ny);
326 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); 438 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
327 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 439 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
328 440
329 return 1; 441 return 1;
330} 442}
347int 459int
348command_create (object *op, char *params) 460command_create (object *op, char *params)
349{ 461{
350 object *tmp = NULL; 462 object *tmp = NULL;
351 int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; 463 int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace;
352 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *bp4, *endline; 464 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline;
353 archetype *at, *at_spell = NULL; 465 archetype *at, *at_spell = NULL;
354 artifact *art = NULL; 466 artifact *art = NULL;
355 467
356 if (!op) 468 if (!op)
357 return 0; 469 return 0;
423 * we also set up spell_name which is only 535 * we also set up spell_name which is only
424 * the first word. 536 * the first word.
425 */ 537 */
426 538
427 at_spell = archetype::find (cp); 539 at_spell = archetype::find (cp);
428 if (!at_spell || at_spell->clone.type != SPELL) 540 if (!at_spell || at_spell->type != SPELL)
429 at_spell = find_archetype_by_object_name (cp); 541 at_spell = find_archetype_by_object_name (cp);
430 if (!at_spell || at_spell->clone.type != SPELL) 542 if (!at_spell || at_spell->type != SPELL)
431 { 543 {
432 assign (spell_name, cp); 544 assign (spell_name, cp);
433 fsp = strchr (spell_name, ' '); 545 fsp = strchr (spell_name, ' ');
434 if (fsp) 546 if (fsp)
435 { 547 {
436 *fsp = 0; 548 *fsp = 0;
437 fsp++; 549 fsp++;
438 at_spell = archetype::find (spell_name); 550 at_spell = archetype::find (spell_name);
439 551
440 /* Got a spell, update the first string pointer */ 552 /* Got a spell, update the first string pointer */
441 if (at_spell && at_spell->clone.type == SPELL) 553 if (at_spell && at_spell->type == SPELL)
442 bp2 = cp + strlen (spell_name) + 1; 554 bp2 = cp + strlen (spell_name) + 1;
443 else 555 else
444 at_spell = NULL; 556 at_spell = NULL;
445 } 557 }
446 } 558 }
448 /* OK - we didn't find a spell - presume the 'of' 560 /* OK - we didn't find a spell - presume the 'of'
449 * in this case means its an artifact. 561 * in this case means its an artifact.
450 */ 562 */
451 if (!at_spell) 563 if (!at_spell)
452 { 564 {
453 if (find_artifactlist (at->clone.type) == NULL) 565 if (find_artifactlist (at->type) == NULL)
454 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->clone.type); 566 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->type);
455 else 567 else
456 { 568 {
457 art = find_artifactlist (at->clone.type)->items; 569 art = find_artifactlist (at->type)->items;
458 570
459 while (art) 571 while (art)
460 { 572 {
461 if (!strcmp (art->item->name, cp)) 573 if (!strcmp (&art->item->name, cp))
462 break; 574 break;
463 575
464 art = art->next; 576 art = art->next;
465 } 577 }
466 578
467 if (!art) 579 if (!art)
468 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->clone.type, cp); 580 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->type, cp);
469 } 581 }
470 582
471 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp); 583 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp);
472 } 584 }
473 } /* if cp */ 585 } /* if cp */
474 586
475 if ((at->clone.type == ROD || at->clone.type == WAND || at->clone.type == SCROLL || 587 if ((at->type == ROD || at->type == WAND || at->type == SCROLL ||
476 at->clone.type == HORN || at->clone.type == SPELLBOOK) && !at_spell) 588 at->type == HORN || at->type == SPELLBOOK) && !at_spell)
477 { 589 {
478 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); 590 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);
479 return 1; 591 return 1;
480 } 592 }
481 593
482 /* 594 /*
483 * Rather than have two different blocks with a lot of similar code, 595 * Rather than have two different blocks with a lot of similar code,
484 * just create one object, do all the processing, and then determine 596 * just create one object, do all the processing, and then determine
485 * if that one object should be inserted or if we need to make copies. 597 * if that one object should be inserted or if we need to make copies.
486 */ 598 */
487 tmp = arch_to_object (at); 599 tmp = at->instance ();
488 600
489 if (set_magic) 601 if (set_magic)
490 set_abs_magic (tmp, magic); 602 set_abs_magic (tmp, magic);
491 603
492 if (art) 604 if (art)
493 give_artifact_abilities (tmp, art->item); 605 give_artifact_abilities (tmp, art->item);
494 606
495 if (need_identify (tmp)) 607 if (tmp->need_identify ())
496 { 608 {
497 SET_FLAG (tmp, FLAG_IDENTIFIED); 609 tmp->set_flag (FLAG_IDENTIFIED);
498 CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); 610 tmp->clr_flag (FLAG_KNOWN_MAGICAL);
499 } 611 }
500 612
501 /* 613 /*
502 * This entire block here tries to find variable pairings, 614 * This entire block here tries to find variable pairings,
503 * eg, 'hp 4' or the like. The mess here is that values 615 * eg, 'hp 4' or the like. The mess here is that values
505 * is we want to find two spaces, but if we got a quote, 617 * is we want to find two spaces, but if we got a quote,
506 * any spaces there don't count. 618 * any spaces there don't count.
507 */ 619 */
508 while (*bp2 && bp2 <= endline) 620 while (*bp2 && bp2 <= endline)
509 { 621 {
510 bp4 = NULL;
511 gotspace = 0; 622 gotspace = 0;
512 gotquote = 0; 623 gotquote = 0;
513 624
514 /* find the first quote */ 625 /* find the first quote */
515 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) 626 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++)
572 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2); 683 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2);
573 684
574 bp2 = bp3 + 1; 685 bp2 = bp3 + 1;
575 } 686 }
576 687
577 if (at->clone.nrof) 688 if (at->nrof)
578 { 689 {
579 if (at_spell) 690 if (at_spell)
580 insert_ob_in_ob (arch_to_object (at_spell), tmp); 691 tmp->insert (at_spell->instance ());
581 692
582 tmp->x = op->x; 693 tmp->x = op->x;
583 tmp->y = op->y; 694 tmp->y = op->y;
695 tmp->map = op->map;
584 696
585 if (set_nrof) 697 if (set_nrof)
586 tmp->nrof = nrof; 698 tmp->nrof = nrof;
587 699
588 tmp->map = op->map; 700 op->insert (tmp);
589
590 tmp = insert_ob_in_ob (tmp, op);
591 esrv_send_item (op, tmp);
592 701
593 /* Let's put this created item on stack so dm can access it easily. */ 702 /* Let's put this created item on stack so dm can access it easily. */
594 dm_stack_push (op->contr, tmp->count); 703 dm_stack_push (op->contr, tmp->count);
595 704
596 return 1; 705 return 1;
597 } 706 }
598 else 707 else
599 { 708 {
600 for (i = 0; i < (set_nrof ? nrof : 1); i++) 709 for (i = 0; i < (set_nrof ? nrof : 1); i++)
601 { 710 {
602 archetype *atmp;
603 object *prev = 0, *head = 0; 711 object *prev = 0, *head = 0;
604 712
605 for (atmp = at; atmp; atmp = atmp->more) 713 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
606 { 714 {
607 object *dup = arch_to_object (atmp); 715 object *dup = atmp->instance ();
608 716
609 if (at_spell) 717 if (at_spell)
610 insert_ob_in_ob (arch_to_object (at_spell), dup); 718 insert_ob_in_ob (at_spell->instance (), dup);
611 719
612 /* 720 /*
613 * The head is what contains all the important bits, 721 * The head is what contains all the important bits,
614 * so just copying it over should be fine. 722 * so just copying it over should be fine.
615 */ 723 */
617 { 725 {
618 head = dup; 726 head = dup;
619 tmp->copy_to (dup); 727 tmp->copy_to (dup);
620 } 728 }
621 729
622 dup->x = op->x + dup->arch->clone.x; 730 dup->x = op->x + dup->arch->x;
623 dup->y = op->y + dup->arch->clone.y; 731 dup->y = op->y + dup->arch->y;
624 dup->map = op->map; 732 dup->map = op->map;
625 733
626 if (head != dup) 734 if (head != dup)
627 { 735 {
628 dup->head = head; 736 dup->head = head;
630 } 738 }
631 739
632 prev = dup; 740 prev = dup;
633 } 741 }
634 742
635 if (QUERY_FLAG (head, FLAG_ALIVE)) 743 if (head->flag [FLAG_ALIVE])
636 { 744 {
637 object *check = head; 745 object *check = head;
638 int size_x = 0; 746 int size_x = 0;
639 int size_y = 0; 747 int size_y = 0;
640 748
641 while (check) 749 while (check)
642 { 750 {
643 size_x = MAX (size_x, check->arch->clone.x); 751 size_x = max (size_x, check->arch->x);
644 size_y = MAX (size_y, check->arch->clone.y); 752 size_y = max (size_y, check->arch->y);
645 check = check->more; 753 check = check->more;
646 } 754 }
647 755
648 if (out_of_map (op->map, head->x + size_x, head->y + size_y)) 756 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
649 { 757 {
675 /* Wonder if we really want to push all of these, but since 783 /* Wonder if we really want to push all of these, but since
676 * things like rods have nrof 0, we want to cover those. 784 * things like rods have nrof 0, we want to cover those.
677 */ 785 */
678 dm_stack_push (op->contr, head->count); 786 dm_stack_push (op->contr, head->count);
679 787
680 if (at->clone.randomitems != NULL && !at_spell) 788 if (at->randomitems && !at_spell)
681 create_treasure (at->clone.randomitems, head, GT_APPLY, op->map->difficulty, 0); 789 create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0);
682
683 esrv_send_item (op, head);
684 } 790 }
685 791
686 /* free the one we used to copy */ 792 /* free the one we used to copy */
687 tmp->destroy (); 793 tmp->destroy ();
688 } 794 }
695 */ 801 */
696 802
697int 803int
698command_inventory (object *op, char *params) 804command_inventory (object *op, char *params)
699{ 805{
806 int i;
700 object *tmp; 807 object *tmp;
701 int i;
702 808
703 if (!params) 809 if (!params || !sscanf (params, "%d", &i) || !(tmp = find_object (i)))
704 { 810 {
705 inventory (op, NULL); 811 op->contr->failmsg ("Inventory of what object (nr)?");
706 return 0; 812 return 1;
707 }
708
709 if (!sscanf (params, "%d", &i) || (tmp = find_object (i)) == NULL)
710 { 813 }
711 new_draw_info (NDI_UNIQUE, 0, op, "Inventory of what object (nr)?");
712 return 1;
713 }
714 814
715 inventory (op, tmp); 815 op->contr->infobox (MSG_CHANNEL ("examine"), tmp->query_inventory (op));
816
716 return 1; 817 return 1;
717} 818}
718 819
719/* just show player's their skills for now. Dm's can 820/* just show player's their skills for now. Dm's can
720 * already see skills w/ inventory command - b.t. 821 * already see skills w/ inventory command - b.t.
738 839
739 char *dump = dump_object (tmp); 840 char *dump = dump_object (tmp);
740 new_draw_info (NDI_UNIQUE, 0, op, dump); 841 new_draw_info (NDI_UNIQUE, 0, op, dump);
741 free (dump); 842 free (dump);
742 843
743 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) 844 if (tmp->flag [FLAG_OBJ_ORIGINAL])
744 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); 845 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
745 846
746 return 1; 847 return 1;
747} 848}
748 849
793 { 894 {
794 new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); 895 new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!");
795 return 1; 896 return 1;
796 } 897 }
797 898
798 if (QUERY_FLAG (tmp, FLAG_REMOVED)) 899 if (tmp->flag [FLAG_REMOVED])
799 { 900 {
800 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); 901 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp));
801 return 1; 902 return 1;
802 } 903 }
803 904
842 */ 943 */
843int 944int
844command_addexp (object *op, char *params) 945command_addexp (object *op, char *params)
845{ 946{
846 char buf[MAX_BUF], skill[MAX_BUF]; 947 char buf[MAX_BUF], skill[MAX_BUF];
847 int i, q; 948 int q;
949 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
848 object *skillob = NULL; 950 object *skillob = NULL;
849 951
850 skill[0] = '\0'; 952 skill[0] = '\0';
851 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %d %s", buf, &i, skill)) < 2)) 953 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2))
852 { 954 {
853 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); 955 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
854 return 1; 956 return 1;
855 } 957 }
856 958
892/**************************************************************************/ 994/**************************************************************************/
893 995
894int 996int
895command_stats (object *op, char *params) 997command_stats (object *op, char *params)
896{ 998{
897 char thing[20];
898 char buf[MAX_BUF]; 999 char buf[MAX_BUF];
899 1000
900 thing[0] = '\0'; 1001 if (params == NULL || params[0] == '\0')
901 if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL)
902 { 1002 {
903 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 1003 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
904 return 1; 1004 return 1;
905 } 1005 }
906 1006
907 for_all_players (pl) 1007 for_all_players (pl)
908 if (!strcmp (pl->ob->name, thing)) 1008 if (!strcmp (&pl->ob->name, params))
909 { 1009 {
910 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); 1010 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp);
911 new_draw_info (NDI_UNIQUE, 0, op, buf); 1011 new_draw_info (NDI_UNIQUE, 0, op, buf);
912 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); 1012 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp);
913 new_draw_info (NDI_UNIQUE, 0, op, buf); 1013 new_draw_info (NDI_UNIQUE, 0, op, buf);
929} 1029}
930 1030
931int 1031int
932command_abil (object *op, char *params) 1032command_abil (object *op, char *params)
933{ 1033{
934 char thing[20], thing2[20]; 1034 char thing[80], thing2[80];
935 int iii; 1035 int iii;
936 char buf[MAX_BUF]; 1036 char buf[MAX_BUF];
937 1037
938 iii = 0; 1038 iii = 0;
939 thing[0] = '\0'; 1039 thing[0] = '\0';
940 thing2[0] = '\0'; 1040 thing2[0] = '\0';
941 if (params == NULL || !sscanf (params, "%s %s %d", thing, thing2, &iii) || thing == NULL) 1041 if (!params || 3 != sscanf (params, "%79s %79s %d", thing, thing2, &iii))
942 { 1042 {
943 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 1043 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
944 return 1; 1044 return 1;
945 } 1045 }
946 1046
947 if (thing2 == NULL) 1047 if (!*thing2)
948 { 1048 {
949 new_draw_info (NDI_UNIQUE, 0, op, "You can't change that."); 1049 new_draw_info (NDI_UNIQUE, 0, op, "You can't change that.");
950 return 1; 1050 return 1;
951 } 1051 }
952 1052
956 return 1; 1056 return 1;
957 } 1057 }
958 1058
959 for_all_players (pl) 1059 for_all_players (pl)
960 { 1060 {
961 if (!strcmp (pl->ob->name, thing)) 1061 if (!strcmp (&pl->ob->name, thing))
962 { 1062 {
963 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; 1063 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii;
964 if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; 1064 if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii;
965 if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; 1065 if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii;
966 if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; 1066 if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii;
978 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 1078 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
979 return 1; 1079 return 1;
980} 1080}
981 1081
982int 1082int
983command_nowiz (object *op, char *params)
984{ /* 'nodm' is alias */
985 CLEAR_FLAG (op, FLAG_WIZ);
986 CLEAR_FLAG (op, FLAG_WIZPASS);
987 CLEAR_FLAG (op, FLAG_WIZCAST);
988
989 if (op->contr->hidden)
990 {
991 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
992 op->map->players++;
993 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
994 op->contr->hidden = 0;
995 op->invisible = 1;
996 }
997 else
998 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
999 return 1;
1000}
1001
1002/**
1003 * object *op is trying to become dm.
1004 * pl_name is name supplied by player. Restrictive DM will make it harder
1005 * for socket users to become DM - in that case, it will check for the players
1006 * character name.
1007 */
1008static int
1009checkdm (object *op, const char *pl_name, const char *pl_passwd, const char *pl_host)
1010{
1011 FILE *dmfile;
1012 char buf[MAX_BUF];
1013 char line_buf[160], name[160], passwd[160], host[160];
1014
1015#ifdef RESTRICTIVE_DM
1016 *pl_name = op->name ? op->name : "*";
1017#endif
1018
1019 sprintf (buf, "%s/%s", settings.confdir, DMFILE);
1020 if ((dmfile = fopen (buf, "r")) == NULL)
1021 {
1022 LOG (llevDebug, "Could not find DM file.\n");
1023 return 0;
1024 }
1025
1026 while (fgets (line_buf, 160, dmfile) != NULL)
1027 {
1028 if (line_buf[0] == '#')
1029 continue;
1030 if (sscanf (line_buf, "%[^:]:%[^:]:%s\n", name, passwd, host) != 3)
1031 {
1032 LOG (llevError, "Warning - malformed dm file entry: %s\n", line_buf);
1033 }
1034 else if ((!strcmp (name, "*") || (pl_name && !strcmp (pl_name, name)))
1035 && (!strcmp (passwd, "*") || !strcmp (passwd, pl_passwd)) && (!strcmp (host, "*") || !strcmp (host, pl_host)))
1036 {
1037 fclose (dmfile);
1038 return (1);
1039 }
1040 }
1041 fclose (dmfile);
1042 return (0);
1043}
1044
1045int
1046do_wizard_dm (object *op, char *params, int silent)
1047{
1048 if (!op->contr)
1049 return 0;
1050
1051 if (QUERY_FLAG (op, FLAG_WIZ))
1052 {
1053 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1054 return 0;
1055 }
1056
1057 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1058 {
1059 SET_FLAG (op, FLAG_WIZ);
1060 SET_FLAG (op, FLAG_WIZPASS);
1061 SET_FLAG (op, FLAG_WIZCAST);
1062
1063 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1064 /*
1065 * Remove setting flying here - that won't work, because next
1066 * fix_player() is called that will get cleared - proper solution
1067 * is probably something like a wiz_force which gives that and any
1068 * other desired abilities.
1069 */
1070 clear_los (op);
1071 op->contr->write_buf[0] = '\0';
1072
1073 if (!silent)
1074 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1075
1076 return 1;
1077 }
1078 else
1079 {
1080 new_draw_info (NDI_UNIQUE, 0, op, "Sorry Pal, I don't think so.");
1081 op->contr->write_buf[0] = '\0';
1082 return 0;
1083 }
1084}
1085
1086/*
1087 * Actual command to perhaps become dm. Changed aroun a bit in version 0.92.2
1088 * - allow people on sockets to become dm, and allow better dm file
1089 */
1090int
1091command_dm (object *op, char *params)
1092{
1093 if (!op->contr)
1094 return 0;
1095
1096 do_wizard_dm (op, params, 0);
1097
1098 return 1;
1099}
1100
1101int
1102command_invisible (object *op, char *params) 1083command_invisible (object *op, char *params)
1103{ 1084{
1104 if (op) 1085 if (op)
1105 { 1086 {
1106 op->invisible += 100; 1087 op->invisible += TIME2TICK (60);
1107 update_object (op, UP_OBJ_CHANGE); 1088 update_object (op, UP_OBJ_CHANGE);
1108 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); 1089 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible.");
1109 } 1090 }
1110 1091
1111 return 0; 1092 return 0;
1115 * Returns spell object (from archetypes) by name. 1096 * Returns spell object (from archetypes) by name.
1116 * Returns NULL if 0 or more than one spell matches. 1097 * Returns NULL if 0 or more than one spell matches.
1117 * Used for wizard's learn spell/prayer. 1098 * Used for wizard's learn spell/prayer.
1118 * 1099 *
1119 * op is the player issuing the command. 1100 * op is the player issuing the command.
1120 *
1121 * Ignores archetypes "spelldirect_xxx" since these archetypes are not used
1122 * anymore (but may still be present in some player's inventories and thus
1123 * cannot be removed). We have to ignore them here since they have the same
1124 * name than other "spell_xxx" archetypes and would always conflict.
1125 */ 1101 */
1126static object * 1102static object *
1127get_spell_by_name (object *op, const char *spell_name) 1103get_spell_by_name (object *op, shstr_cmp spell_name)
1128{ 1104{
1129 archetype *ar;
1130 archetype *found;
1131 int conflict_found;
1132 size_t spell_name_length;
1133
1134 /* First check for full name matches. */ 1105 /* First check for full name matches. */
1135 conflict_found = 0; 1106 int conflict_found = 0;
1136 found = NULL; 1107 archetype *found = 0;
1137 for (ar = first_archetype; ar != NULL; ar = ar->next) 1108
1109 for_all_archetypes (at)
1138 { 1110 {
1139 if (ar->clone.type != SPELL) 1111 if (at->type != SPELL)
1140 continue; 1112 continue;
1141 1113
1142 if (strncmp (ar->name, "spelldirect_", 12) == 0) 1114 if (at->object::name != spell_name)
1143 continue; 1115 continue;
1144 1116
1145 if (strcmp (ar->clone.name, spell_name) != 0)
1146 continue;
1147
1148 if (found != NULL) 1117 if (found)
1149 { 1118 {
1150 if (!conflict_found) 1119 if (!conflict_found)
1151 { 1120 {
1152 conflict_found = 1; 1121 conflict_found = 1;
1153 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); 1122 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name);
1154 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->name); 1123 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1155 } 1124 }
1125
1156 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &ar->name); 1126 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1157 continue; 1127 return 0;
1158 } 1128 }
1159 1129
1160 found = ar; 1130 found = at;
1161 } 1131 }
1162
1163 /* No match if more more than one archetype matches. */
1164 if (conflict_found)
1165 return NULL;
1166 1132
1167 /* Return if exactly one archetype matches. */ 1133 /* Return if exactly one archetype matches. */
1168 if (found != NULL) 1134 if (found)
1169 return arch_to_object (found); 1135 return found->instance ();
1170
1171 /* No full match found: now check for partial matches. */
1172 spell_name_length = strlen (spell_name);
1173 conflict_found = 0;
1174 found = NULL;
1175 for (ar = first_archetype; ar != NULL; ar = ar->next)
1176 {
1177 if (ar->clone.type != SPELL)
1178 continue;
1179
1180 if (strncmp (ar->name, "spelldirect_", 12) == 0)
1181 continue;
1182
1183 if (strncmp (ar->clone.name, spell_name, spell_name_length) != 0)
1184 continue;
1185
1186 if (found != NULL)
1187 {
1188 if (!conflict_found)
1189 {
1190 conflict_found = 1;
1191 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name);
1192 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->clone.name);
1193 }
1194 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &ar->clone.name);
1195 continue;
1196 }
1197
1198 found = ar;
1199 }
1200
1201 /* No match if more more than one archetype matches. */
1202 if (conflict_found)
1203 return NULL;
1204
1205 /* Return if exactly one archetype matches. */
1206 if (found != NULL)
1207 return arch_to_object (found);
1208 1136
1209 /* No spell found: just print an error message. */ 1137 /* No spell found: just print an error message. */
1210 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell %s does not exist.", spell_name); 1138 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist.");
1139
1211 return NULL; 1140 return 0;
1212} 1141}
1213 1142
1214static int 1143static int
1215command_learn_spell_or_prayer (object *op, char *params, int special_prayer) 1144command_learn_spell_or_prayer (object *op, char *params, int special_prayer)
1216{ 1145{
1260 { 1189 {
1261 new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); 1190 new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?");
1262 return 0; 1191 return 0;
1263 } 1192 }
1264 1193
1265 spell = lookup_spell_by_name (op, params); 1194 spell = op->find_spell (params);
1266 if (spell == NULL) 1195 if (spell == NULL)
1267 { 1196 {
1268 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); 1197 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params);
1269 return 0; 1198 return 0;
1270 } 1199 }
1271 1200
1272 do_forget_spell (op, spell->name); 1201 do_forget_spell (op, spell->name);
1273 return 1; 1202 return 1;
1274}
1275
1276/**
1277 * Lists all plugins currently loaded with their IDs and full names.
1278 */
1279int
1280command_listplugins (object *op, char *params)
1281{
1282 plugins_display_list (op);
1283 return 1;
1284}
1285
1286/**
1287 * Loads the given plugin. The DM specifies the name of the library to load (no
1288 * pathname is needed). Do not ever attempt to load the same plugin more than
1289 * once at a time, or bad things could happen.
1290 */
1291int
1292command_loadplugin (object *op, char *params)
1293{
1294 char buf[MAX_BUF];
1295
1296 if (params == NULL)
1297 {
1298 new_draw_info (NDI_UNIQUE, 0, op, "Load which plugin?");
1299 return 1;
1300 }
1301
1302 strcpy (buf, LIBDIR);
1303 strcat (buf, "/plugins/");
1304 strcat (buf, params);
1305 LOG (llevDebug, "Requested plugin file is %s\n", buf);
1306 if (plugins_init_plugin (buf) == 0)
1307 new_draw_info (NDI_UNIQUE, 0, op, "Plugin successfully loaded.");
1308 else
1309 new_draw_info (NDI_UNIQUE, 0, op, "Could not load plugin.");
1310 return 1;
1311}
1312
1313/**
1314 * Unloads the given plugin. The DM specified the ID of the library to unload.
1315 * Note that some things may behave strangely if the correct plugins are not
1316 * loaded.
1317 */
1318int
1319command_unloadplugin (object *op, char *params)
1320{
1321 if (params == NULL)
1322 {
1323 new_draw_info (NDI_UNIQUE, 0, op, "Remove which plugin?");
1324 return 1;
1325 }
1326
1327 if (plugins_remove_plugin (params) == 0)
1328 new_draw_info (NDI_UNIQUE, 0, op, "Plugin successfully removed.");
1329 else
1330 new_draw_info (NDI_UNIQUE, 0, op, "Could not remove plugin.");
1331 return 1;
1332}
1333
1334/**
1335 * A players wants to become DM and hide.
1336 * Let's see if that's authorized.
1337 * Make sure to not tell anything to anyone.
1338 */
1339int
1340command_dmhide (object *op, char *params)
1341{
1342 if (!do_wizard_dm (op, params, 1))
1343 return 0;
1344
1345 do_wizard_hide (op, 1);
1346
1347 return 1;
1348}
1349
1350void
1351dm_stack_pop (player *pl)
1352{
1353 if (!pl->stack_items || !pl->stack_position)
1354 {
1355 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1356 return;
1357 }
1358
1359 pl->stack_position--;
1360 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
1361}
1362
1363/**
1364 * Get current stack top item for player.
1365 * Returns NULL if no stacked item.
1366 * If stacked item disappeared (freed), remove it.
1367 *
1368 * Ryo, august 2004
1369 */
1370object *
1371dm_stack_peek (player *pl)
1372{
1373 object *ob;
1374
1375 if (!pl->stack_position)
1376 {
1377 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1378 return NULL;
1379 }
1380
1381 ob = find_object (pl->stack_items[pl->stack_position - 1]);
1382 if (!ob)
1383 {
1384 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
1385 dm_stack_pop (pl);
1386 return NULL;
1387 }
1388
1389 return ob;
1390}
1391
1392/**
1393 * Push specified item on player stack.
1394 * Inform player of position.
1395 * Initializes variables if needed.
1396 */
1397void
1398dm_stack_push (player *pl, tag_t item)
1399{
1400 if (!pl->stack_items)
1401 {
1402 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
1403 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
1404 }
1405
1406 if (pl->stack_position == STACK_SIZE)
1407 {
1408 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
1409 return;
1410 }
1411
1412 pl->stack_items[pl->stack_position] = item;
1413 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
1414 pl->stack_position++;
1415}
1416
1417/**
1418 * Checks 'params' for object code.
1419 *
1420 * Can be:
1421 * * empty => get current object stack top for player
1422 * * number => get item with that tag, stack it for future use
1423 * * $number => get specified stack item
1424 * * "me" => player himself
1425 *
1426 * At function exit, params points to first non-object char
1427 *
1428 * 'from', if not NULL, contains at exit:
1429 * * STACK_FROM_NONE => object not found
1430 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
1431 * * STACK_FROM_STACK => item from somewhere in the stack
1432 * * STACK_FROM_NUMBER => item by number, pushed on stack
1433 *
1434 * Ryo, august 2004
1435 */
1436object *
1437get_dm_object (player *pl, char **params, int *from)
1438{
1439 int item_tag, item_position;
1440 object *ob;
1441
1442 if (!pl)
1443 return NULL;
1444
1445 if (!params || !*params || **params == '\0')
1446 {
1447 if (from)
1448 *from = STACK_FROM_TOP;
1449 /* No parameter => get stack item */
1450 return dm_stack_peek (pl);
1451 }
1452
1453 /* Let's clean white spaces */
1454 while (**params == ' ')
1455 (*params)++;
1456
1457 /* Next case: number => item tag */
1458 if (sscanf (*params, "%d", &item_tag))
1459 {
1460 /* Move parameter to next item */
1461 while (isdigit (**params))
1462 (*params)++;
1463
1464 /* And skip blanks, too */
1465 while (**params == ' ')
1466 (*params)++;
1467
1468 /* Get item */
1469 ob = find_object (item_tag);
1470 if (!ob)
1471 {
1472 if (from)
1473 *from = STACK_FROM_NONE;
1474 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
1475 return NULL;
1476 }
1477
1478 /* Got one, let's push it on stack */
1479 dm_stack_push (pl, item_tag);
1480 if (from)
1481 *from = STACK_FROM_NUMBER;
1482 return ob;
1483 }
1484
1485 /* Next case: $number => stack item */
1486 if (sscanf (*params, "$%d", &item_position))
1487 {
1488 /* Move parameter to next item */
1489 (*params)++;
1490
1491 while (isdigit (**params))
1492 (*params)++;
1493 while (**params == ' ')
1494 (*params)++;
1495
1496 if (item_position >= pl->stack_position)
1497 {
1498 if (from)
1499 *from = STACK_FROM_NONE;
1500 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
1501 return NULL;
1502 }
1503
1504 ob = find_object (pl->stack_items[item_position]);
1505 if (!ob)
1506 {
1507 if (from)
1508 *from = STACK_FROM_NONE;
1509 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
1510 return NULL;
1511 }
1512
1513 if (from)
1514 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
1515 return ob;
1516 }
1517
1518 /* Next case: 'me' => return pl->ob */
1519 if (!strncmp (*params, "me", 2))
1520 {
1521 if (from)
1522 *from = STACK_FROM_NUMBER;
1523 dm_stack_push (pl, pl->ob->count);
1524
1525 /* Skip to next token */
1526 (*params) += 2;
1527 while (**params == ' ')
1528 (*params)++;
1529
1530 return pl->ob;
1531 }
1532
1533 /* Last case: get stack top */
1534 if (from)
1535 *from = STACK_FROM_TOP;
1536 return dm_stack_peek (pl);
1537} 1203}
1538 1204
1539/** 1205/**
1540 * Pop the stack top. 1206 * Pop the stack top.
1541 */ 1207 */
1601} 1267}
1602 1268
1603int 1269int
1604command_insert_into (object *op, char *params) 1270command_insert_into (object *op, char *params)
1605{ 1271{
1606 object *left, *right, *inserted; 1272 object *left, *right;
1607 int left_from, right_from; 1273 int left_from, right_from;
1608 1274
1609 left = get_dm_object (op->contr, &params, &left_from); 1275 left = get_dm_object (op->contr, &params, &left_from);
1610 if (!left) 1276 if (!left)
1611 { 1277 {
1654 { 1320 {
1655 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); 1321 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!");
1656 return 0; 1322 return 0;
1657 } 1323 }
1658 1324
1659 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1325 if (!right->flag [FLAG_REMOVED])
1660 right->remove (); 1326 right->remove ();
1327
1661 inserted = insert_ob_in_ob (right, left); 1328 object *inserted = insert_ob_in_ob (right, left);
1662 if (left->type == PLAYER)
1663 if (inserted == right)
1664 esrv_send_item (left, right);
1665 else
1666 esrv_update_item (UPD_WEIGHT | UPD_NAME | UPD_NROF, left, inserted);
1667 1329
1668 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); 1330 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left));
1669 1331
1670 return 0; 1332 return 0;
1671 1333

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines