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.14 by root, Sat Sep 16 22:24:13 2006 UTC vs.
Revision 1.62 by root, Fri Dec 26 10:14:01 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#ifndef __CEXTRACT__
26# include <sproto.h> 25#include <sproto.h>
27#endif
28#include <spells.h> 26#include <spells.h>
29#include <treasure.h> 27#include <treasure.h>
30#include <skills.h> 28#include <skills.h>
31 29
32/** Defines for DM item stack **/ 30/** Defines for DM item stack **/
47 * other player, or NULL otherwise. 45 * other player, or NULL otherwise.
48 */ 46 */
49static player * 47static player *
50get_other_player_from_name (object *op, char *name) 48get_other_player_from_name (object *op, char *name)
51{ 49{
52 player *pl;
53
54 if (!name) 50 if (!name)
55 return NULL; 51 return NULL;
56 52
57 for (pl = first_player; pl != NULL; pl = pl->next) 53 for_all_players (pl)
58 if (!strncmp (pl->ob->name, name, MAX_NAME)) 54 if (!strncmp (pl->ob->name, name, MAX_NAME))
59 break;
60
61 if (pl == NULL)
62 { 55 {
63 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
64 return NULL;
65 }
66
67 if (pl->ob == op) 56 if (pl->ob == op)
68 { 57 {
69 new_draw_info (NDI_UNIQUE, 0, op, "You can't do that to yourself."); 58 new_draw_info (NDI_UNIQUE, 0, op, "You can't do that to yourself.");
70 return NULL; 59 return NULL;
71 } 60 }
61
72 if (pl->state != ST_PLAYING) 62 if (pl->ns->state != ST_PLAYING)
73 { 63 {
74 new_draw_info (NDI_UNIQUE, 0, op, "That player is in no state for that right now."); 64 new_draw_info (NDI_UNIQUE, 0, op, "That player is in no state for that right now.");
75 return NULL; 65 return NULL;
76 }
77 return pl;
78}
79
80/**
81 * This command will stress server.
82 */
83int
84command_loadtest (object *op, char *params)
85{
86 uint32 x, y;
87 char buf[1024];
88
89 new_draw_info (NDI_UNIQUE, 0, op, "loadtest will stress server through teleporting");
90 new_draw_info (NDI_UNIQUE, 0, op, "at different map places.");
91 new_draw_info (NDI_UNIQUE, 0, op, "use at your own risks.");
92 new_draw_info (NDI_UNIQUE, 0, op, "Very long loop used so server may have to be reset.");
93 new_draw_info (NDI_UNIQUE, 0, op, "type loadtest TRUE to run");
94 new_draw_info_format (NDI_UNIQUE, 0, op, "{%s}", params);
95
96 if (!params)
97 return 0;
98
99 if (strncmp (params, "TRUE", 4))
100 return 0;
101
102 new_draw_info_format (NDI_UNIQUE, 0, op, "gogogo");
103
104 for (x = 0; x < settings.worldmaptilesx; x++)
105 {
106 for (y = 0; y < settings.worldmaptilesy; y++)
107 {
108 sprintf (buf, "/world/world_%d_%d", x + settings.worldmapstartx, y + settings.worldmapstarty);
109 command_goto (op, buf);
110 } 66 }
67
68 return pl;
111 } 69 }
112 70
71 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
113 return 0; 72 return 0;
114} 73}
115 74
116/** 75/**
117 * Actually hides specified player (obviously a DM). 76 * Actually hides specified player (obviously a DM).
126 op->contr->hidden = 0; 85 op->contr->hidden = 0;
127 op->invisible = 1; 86 op->invisible = 1;
128 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); 87 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
129 op->map->players++; 88 op->map->players++;
130 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name); 89 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
90
131 if (!silent_dm) 91 if (!silent_dm)
132 {
133 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); 92 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
134 }
135 } 93 }
136 else 94 else
137 { 95 {
138 op->contr->hidden = 1; 96 op->contr->hidden = 1;
139 new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you."); 97 new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you.");
140 op->map->players--; 98 op->map->players--;
99
141 if (!silent_dm) 100 if (!silent_dm)
142 {
143 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); 101 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
144 } 102
145 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name); 103 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name);
146 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name); 104 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name);
147 } 105 }
148} 106}
149 107
213 171
214 become_follower (ob, god); 172 become_follower (ob, god);
215 return 1; 173 return 1;
216} 174}
217 175
218/** 176// TODO: Rewrite banish in perl and get rid of the following two functions
219 * Add player's IP to ban_file and kick them off the server
220 * I know most people have dynamic IPs but this is more of a short term
221 * solution if they have to get a new IP to play maybe they'll calm down.
222 * This uses the banish_file in the local directory *not* the ban_file
223 * The action is logged with a ! for easy searching. -tm
224 */
225int
226command_banish (object *op, char *params)
227{
228 player *pl;
229 FILE *banishfile;
230 char buf[MAX_BUF];
231 time_t now;
232
233 if (!params)
234 {
235 new_draw_info (NDI_UNIQUE, 0, op, "Usage: banish <player>.");
236 return 1;
237 }
238
239 pl = get_other_player_from_name (op, params);
240 if (!pl)
241 return 1;
242
243 sprintf (buf, "%s/%s", settings.localdir, BANISHFILE);
244
245 if ((banishfile = fopen (buf, "a")) == NULL)
246 {
247 LOG (llevDebug, "Could not find file banish_file.\n");
248 new_draw_info (NDI_UNIQUE, 0, op, "Could not find banish_file.");
249 return 0;
250 }
251
252 now = time (NULL);
253 /*
254 * Record this as a comment - then we don't have to worry about changing
255 * the parsing code.
256 */
257 fprintf (banishfile, "# %s (%s) banned by %s at %s\n", &pl->ob->name, pl->socket.host, &op->name, ctime (&now));
258 fprintf (banishfile, "*@%s\n", pl->socket.host);
259 fclose (banishfile);
260
261 LOG (llevDebug, "! %s banned %s from IP: %s.\n", &op->name, &pl->ob->name, pl->socket.host);
262 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op, "You banish %s", &pl->ob->name);
263 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s banishes %s from the land!", &op->name, &pl->ob->name);
264 command_kick (op, (char *) &pl->ob->name);
265 return 1;
266}
267
268int 177int
269command_kick (object *op, char *params) 178command_kick (object *op, char *params)
270{ 179{
271 for (player *pl = first_player; pl; pl = pl->next) 180 for_all_players (pl)
272 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params))) 181 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
273 { 182 {
274 object *op = pl->ob; 183 object *plop = pl->ob;
275 184
276 if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED)) 185 if (!QUERY_FLAG (plop, FLAG_REMOVED) && !QUERY_FLAG (plop, FLAG_FREED))
277 { 186 {
278 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &op->name); 187 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &plop->name);
279 strcpy (op->contr->killer, "kicked"); 188 plop->contr->killer = op;
280 } 189 }
281 190
282 pl->socket.status = Ns_Dead; 191 pl->ns->destroy ();
283 } 192 }
284 193
285 return 1; 194 return 1;
286} 195}
287 196
197//TODO
198#if 0
288int 199int
289command_save_overlay (object *op, char *params) 200command_save_overlay (object *op, char *params)
290{ 201{
291 if (!op) 202 if (!op)
292 return 0; 203 return 0;
303 214
304 ready_map_name (op->map->path, 0); 215 ready_map_name (op->map->path, 0);
305 216
306 return 1; 217 return 1;
307} 218}
308 219#endif
309int
310command_shutdown (object *op, char *params)
311{
312 struct pl *pl;
313
314 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
315 {
316 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't shutdown the server.");
317 return 1;
318 }
319
320 cleanup ();
321 /* not reached */
322 return 1;
323}
324
325int
326command_goto (object *op, char *params)
327{
328 char *name;
329 object *dummy;
330
331 if (!op)
332 return 0;
333
334 if (params == NULL)
335 {
336 new_draw_info (NDI_UNIQUE, 0, op, "Go to what level?");
337 return 1;
338 }
339
340 name = params;
341 dummy = get_object ();
342 dummy->map = op->map;
343 EXIT_PATH (dummy) = name;
344 dummy->name = name;
345
346 enter_exit (op, dummy);
347 free_object (dummy);
348 if (op->contr->loading == NULL)
349 {
350 new_draw_info_format (NDI_UNIQUE, 0, op, "Difficulty: %d.", op->map->difficulty);
351 }
352
353 return 1;
354}
355
356/* is this function called from somewhere ? -Tero */
357int
358command_generate (object *op, char *params)
359{
360 object *tmp;
361 int nr = 1, i, retry;
362
363 if (!op)
364 return 0;
365
366 if (params != NULL)
367 sscanf (params, "%d", &nr);
368 for (i = 0; i < nr; i++)
369 {
370 retry = 50;
371 while ((tmp = generate_treasure (0, op->map->difficulty)) == NULL && --retry)
372 ;
373 if (tmp != NULL)
374 {
375 tmp = insert_ob_in_ob (tmp, op);
376 if (op->type == PLAYER)
377 esrv_send_item (op, tmp);
378 }
379 }
380
381 return 1;
382}
383 220
384int 221int
385command_freeze (object *op, char *params) 222command_freeze (object *op, char *params)
386{ 223{
387 int ticks; 224 int ticks;
423 object *dummy; 260 object *dummy;
424 player *pl; 261 player *pl;
425 262
426 if (!op) 263 if (!op)
427 return 0; 264 return 0;
265
428 if (params == NULL) 266 if (params == NULL)
429 { 267 {
430 new_draw_info (NDI_UNIQUE, 0, op, "Usage: arrest <player>."); 268 new_draw_info (NDI_UNIQUE, 0, op, "Usage: arrest <player>.");
431 return 1; 269 return 1;
432 } 270 }
271
433 pl = get_other_player_from_name (op, params); 272 pl = get_other_player_from_name (op, params);
434 if (!pl) 273 if (!pl)
435 return 1; 274 return 1;
275
436 dummy = get_jail_exit (pl->ob); 276 dummy = get_jail_exit (pl->ob);
437 if (!dummy) 277 if (!dummy)
438 { 278 {
439 /* we have nowhere to send the prisoner.... */ 279 /* we have nowhere to send the prisoner.... */
440 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); 280 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them");
441 return 0; 281 return 0;
442 } 282 }
443 enter_exit (pl->ob, dummy); 283
444 free_object (dummy); 284 pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO
285 dummy->destroy ();
286
445 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); 287 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested.");
446 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 288 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
447 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); 289 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name);
448 return 1; 290 return 1;
449} 291}
473 { 315 {
474 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); 316 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
475 return 1; 317 return 1;
476 } 318 }
477 319
478 dummy = get_object (); 320 pl->ob->player_goto (op->map->path, op->x + freearr_x[i], op->y + freearr_y[i]);
479 EXIT_PATH (dummy) = op->map->path;
480 EXIT_X (dummy) = op->x + freearr_x[i];
481 EXIT_Y (dummy) = op->y + freearr_y[i];
482 enter_exit (pl->ob, dummy);
483 free_object (dummy);
484 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); 321 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
485 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 322 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
486 323
487 return 1;
488}
489
490/**
491 * Teleport next to target player.
492 */
493
494/* mids 01/16/2002 */
495int
496command_teleport (object *op, char *params)
497{
498 int i;
499 object *dummy;
500 player *pl;
501
502 if (!op)
503 return 0;
504
505 if (params == NULL)
506 {
507 new_draw_info (NDI_UNIQUE, 0, op, "Usage: teleport <player>.");
508 return 1;
509 }
510
511 pl = get_other_player_from_name (op, params);
512 if (!pl)
513 return 1;
514
515 i = find_free_spot (pl->ob, pl->ob->map, pl->ob->x, pl->ob->y, 1, 9);
516 if (i == -1)
517 {
518 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to teleport to.");
519 return 1;
520 }
521
522 dummy = get_object ();
523 EXIT_PATH (dummy) = pl->ob->map->path;
524 EXIT_X (dummy) = pl->ob->x + freearr_x[i];
525 EXIT_Y (dummy) = pl->ob->y + freearr_y[i];
526 enter_exit (op, dummy);
527 free_object (dummy);
528 if (!op->contr->hidden)
529 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You see a portal open.");
530 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
531 return 1; 324 return 1;
532} 325}
533 326
534/** 327/**
535 * This function is a real mess, because we're stucking getting 328 * This function is a real mess, because we're stucking getting
625 * we also set up spell_name which is only 418 * we also set up spell_name which is only
626 * the first word. 419 * the first word.
627 */ 420 */
628 421
629 at_spell = archetype::find (cp); 422 at_spell = archetype::find (cp);
630 if (!at_spell || at_spell->clone.type != SPELL) 423 if (!at_spell || at_spell->type != SPELL)
631 at_spell = find_archetype_by_object_name (cp); 424 at_spell = find_archetype_by_object_name (cp);
632 if (!at_spell || at_spell->clone.type != SPELL) 425 if (!at_spell || at_spell->type != SPELL)
633 { 426 {
634 strcpy (spell_name, cp); 427 assign (spell_name, cp);
635 fsp = strchr (spell_name, ' '); 428 fsp = strchr (spell_name, ' ');
636 if (fsp) 429 if (fsp)
637 { 430 {
638 *fsp = 0; 431 *fsp = 0;
639 fsp++; 432 fsp++;
640 at_spell = archetype::find (spell_name); 433 at_spell = archetype::find (spell_name);
641 434
642 /* Got a spell, update the first string pointer */ 435 /* Got a spell, update the first string pointer */
643 if (at_spell && at_spell->clone.type == SPELL) 436 if (at_spell && at_spell->type == SPELL)
644 bp2 = cp + strlen (spell_name) + 1; 437 bp2 = cp + strlen (spell_name) + 1;
645 else 438 else
646 at_spell = NULL; 439 at_spell = NULL;
647 } 440 }
648 } 441 }
650 /* OK - we didn't find a spell - presume the 'of' 443 /* OK - we didn't find a spell - presume the 'of'
651 * in this case means its an artifact. 444 * in this case means its an artifact.
652 */ 445 */
653 if (!at_spell) 446 if (!at_spell)
654 { 447 {
655 if (find_artifactlist (at->clone.type) == NULL) 448 if (find_artifactlist (at->type) == NULL)
656 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->clone.type); 449 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->type);
657 else 450 else
658 { 451 {
659 art = find_artifactlist (at->clone.type)->items; 452 art = find_artifactlist (at->type)->items;
660 453
661 do 454 while (art)
662 { 455 {
663 if (!strcmp (art->item->name, cp)) 456 if (!strcmp (art->item->name, cp))
664 break; 457 break;
458
665 art = art->next; 459 art = art->next;
666 } 460 }
667 while (art != NULL);
668 461
669 if (!art) 462 if (!art)
670 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->clone.type, cp); 463 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->type, cp);
671 } 464 }
672 465
673 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp); 466 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp);
674 } 467 }
675 } /* if cp */ 468 } /* if cp */
676 469
677 if ((at->clone.type == ROD || at->clone.type == WAND || at->clone.type == SCROLL || 470 if ((at->type == ROD || at->type == WAND || at->type == SCROLL ||
678 at->clone.type == HORN || at->clone.type == SPELLBOOK) && !at_spell) 471 at->type == HORN || at->type == SPELLBOOK) && !at_spell)
679 { 472 {
680 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); 473 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);
681 return 1; 474 return 1;
682 } 475 }
683 476
685 * Rather than have two different blocks with a lot of similar code, 478 * Rather than have two different blocks with a lot of similar code,
686 * just create one object, do all the processing, and then determine 479 * just create one object, do all the processing, and then determine
687 * if that one object should be inserted or if we need to make copies. 480 * if that one object should be inserted or if we need to make copies.
688 */ 481 */
689 tmp = arch_to_object (at); 482 tmp = arch_to_object (at);
690
691 if (settings.real_wiz == FALSE)
692 SET_FLAG (tmp, FLAG_WAS_WIZ);
693 483
694 if (set_magic) 484 if (set_magic)
695 set_abs_magic (tmp, magic); 485 set_abs_magic (tmp, magic);
696 486
697 if (art) 487 if (art)
777 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2); 567 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2);
778 568
779 bp2 = bp3 + 1; 569 bp2 = bp3 + 1;
780 } 570 }
781 571
782 if (at->clone.nrof) 572 if (at->nrof)
783 { 573 {
784 if (at_spell) 574 if (at_spell)
785 insert_ob_in_ob (arch_to_object (at_spell), tmp); 575 tmp->insert (arch_to_object (at_spell));
786 576
787 tmp->x = op->x; 577 tmp->x = op->x;
788 tmp->y = op->y; 578 tmp->y = op->y;
579 tmp->map = op->map;
789 580
790 if (set_nrof) 581 if (set_nrof)
791 tmp->nrof = nrof; 582 tmp->nrof = nrof;
792 583
793 tmp->map = op->map; 584 op->insert (tmp);
794
795 tmp = insert_ob_in_ob (tmp, op);
796 esrv_send_item (op, tmp);
797 585
798 /* Let's put this created item on stack so dm can access it easily. */ 586 /* Let's put this created item on stack so dm can access it easily. */
799 dm_stack_push (op->contr, tmp->count); 587 dm_stack_push (op->contr, tmp->count);
800 588
801 return 1; 589 return 1;
802 } 590 }
803 else 591 else
804 { 592 {
805 for (i = 0; i < (set_nrof ? nrof : 1); i++) 593 for (i = 0; i < (set_nrof ? nrof : 1); i++)
806 { 594 {
807 archetype *atmp;
808 object *prev = 0, *head = 0; 595 object *prev = 0, *head = 0;
809 596
810 for (atmp = at; atmp; atmp = atmp->more) 597 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
811 { 598 {
812 object *dup = arch_to_object (atmp); 599 object *dup = arch_to_object (atmp);
813 600
814 if (at_spell) 601 if (at_spell)
815 insert_ob_in_ob (arch_to_object (at_spell), dup); 602 insert_ob_in_ob (arch_to_object (at_spell), dup);
819 * so just copying it over should be fine. 606 * so just copying it over should be fine.
820 */ 607 */
821 if (!head) 608 if (!head)
822 { 609 {
823 head = dup; 610 head = dup;
824 copy_object (tmp, dup); 611 tmp->copy_to (dup);
825 } 612 }
826 613
827 if (settings.real_wiz == FALSE)
828 SET_FLAG (dup, FLAG_WAS_WIZ);
829
830 dup->x = op->x + dup->arch->clone.x; 614 dup->x = op->x + dup->arch->x;
831 dup->y = op->y + dup->arch->clone.y; 615 dup->y = op->y + dup->arch->y;
832 dup->map = op->map; 616 dup->map = op->map;
833 617
834 if (head != dup) 618 if (head != dup)
835 { 619 {
836 dup->head = head; 620 dup->head = head;
846 int size_x = 0; 630 int size_x = 0;
847 int size_y = 0; 631 int size_y = 0;
848 632
849 while (check) 633 while (check)
850 { 634 {
851 size_x = MAX (size_x, check->arch->clone.x); 635 size_x = MAX (size_x, check->arch->x);
852 size_y = MAX (size_y, check->arch->clone.y); 636 size_y = MAX (size_y, check->arch->y);
853 check = check->more; 637 check = check->more;
854 } 638 }
855 639
856 if (out_of_map (op->map, head->x + size_x, head->y + size_y)) 640 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
857 { 641 {
858 if (head->x < size_x || head->y < size_y) 642 if (head->x < size_x || head->y < size_y)
859 { 643 {
860 dm_stack_pop (op->contr); 644 dm_stack_pop (op->contr);
861 free_object (head); 645 head->destroy ();
862 new_draw_info (NDI_UNIQUE, 0, op, "Object too big to insert in map, or wrong position."); 646 new_draw_info (NDI_UNIQUE, 0, op, "Object too big to insert in map, or wrong position.");
863 free_object (tmp); 647 tmp->destroy ();
864 return 1; 648 return 1;
865 } 649 }
866 650
867 check = head; 651 check = head;
868 652
883 /* Wonder if we really want to push all of these, but since 667 /* Wonder if we really want to push all of these, but since
884 * things like rods have nrof 0, we want to cover those. 668 * things like rods have nrof 0, we want to cover those.
885 */ 669 */
886 dm_stack_push (op->contr, head->count); 670 dm_stack_push (op->contr, head->count);
887 671
888 if (at->clone.randomitems != NULL && !at_spell) 672 if (at->randomitems && !at_spell)
889 create_treasure (at->clone.randomitems, head, GT_APPLY, op->map->difficulty, 0); 673 create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0);
890
891 esrv_send_item (op, head);
892 } 674 }
893 675
894 /* free the one we used to copy */ 676 /* free the one we used to copy */
895 free_object (tmp); 677 tmp->destroy ();
896 } 678 }
897 679
898 return 1; 680 return 1;
899} 681}
900 682
903 */ 685 */
904 686
905int 687int
906command_inventory (object *op, char *params) 688command_inventory (object *op, char *params)
907{ 689{
690 int i;
908 object *tmp; 691 object *tmp;
909 int i;
910 692
911 if (!params) 693 if (!params || !sscanf (params, "%d", &i) || !(tmp = find_object (i)))
912 { 694 {
913 inventory (op, NULL); 695 op->contr->failmsg ("Inventory of what object (nr)?");
914 return 0; 696 return 1;
915 }
916
917 if (!sscanf (params, "%d", &i) || (tmp = find_object (i)) == NULL)
918 { 697 }
919 new_draw_info (NDI_UNIQUE, 0, op, "Inventory of what object (nr)?");
920 return 1;
921 }
922 698
923 inventory (op, tmp); 699 op->contr->infobox (MSG_CHANNEL ("examine"), tmp->query_inventory (op));
700
924 return 1; 701 return 1;
925} 702}
926 703
927/* just show player's their skills for now. Dm's can 704/* just show player's their skills for now. Dm's can
928 * already see skills w/ inventory command - b.t. 705 * already see skills w/ inventory command - b.t.
942 719
943 tmp = get_dm_object (op->contr, &params, NULL); 720 tmp = get_dm_object (op->contr, &params, NULL);
944 if (!tmp) 721 if (!tmp)
945 return 1; 722 return 1;
946 723
947 dump_object (tmp); 724 char *dump = dump_object (tmp);
948 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 725 new_draw_info (NDI_UNIQUE, 0, op, dump);
726 free (dump);
727
949 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) 728 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL))
950 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); 729 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
951 return 1;
952}
953 730
954/**
955 * When DM is possessing a monster, flip aggression on and off, to allow
956 * better motion.
957 */
958int
959command_mon_aggr (object *op, char *params)
960{
961 if (op->enemy || !QUERY_FLAG (op, FLAG_UNAGGRESSIVE))
962 {
963 op->enemy = NULL;
964 SET_FLAG (op, FLAG_UNAGGRESSIVE);
965 new_draw_info (NDI_UNIQUE, 0, op, "Aggression turned OFF");
966 }
967 else
968 {
969 CLEAR_FLAG (op, FLAG_FRIENDLY);
970 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
971 new_draw_info (NDI_UNIQUE, 0, op, "Aggression turned ON");
972 }
973
974 return 1;
975}
976
977/** DM can possess a monster. Basically, this tricks the client into thinking
978 * a given monster, is actually the player it controls. This allows a DM
979 * to inhabit a monster's body, and run around the game with it.
980 * This function is severely broken - it has tons of hardcoded values,
981 */
982int
983command_possess (object *op, char *params)
984{
985 object *victim, *curinv, *nextinv;
986 player *pl;
987 int i;
988 char buf[MAX_BUF];
989
990 victim = NULL;
991 if (params != NULL)
992 {
993 if (sscanf (params, "%d", &i))
994 victim = find_object (i);
995 else if (sscanf (params, "%s", buf))
996 victim = find_object_name (buf);
997 }
998 if (victim == NULL)
999 {
1000 new_draw_info (NDI_UNIQUE, 0, op, "Patch what object (nr)?");
1001 return 1;
1002 }
1003
1004 if (victim == op)
1005 {
1006 new_draw_info (NDI_UNIQUE, 0, op, "As insane as you are, I cannot " "allow you to possess yourself.");
1007 return 1;
1008 }
1009
1010 /* clear out the old inventory */
1011 curinv = op->inv;
1012 while (curinv != NULL)
1013 {
1014 nextinv = curinv->below;
1015 esrv_del_item (op->contr, curinv->count);
1016 curinv = nextinv;
1017 }
1018
1019 /* make the switch */
1020 pl = op->contr;
1021 victim->contr = pl;
1022 pl->ob = victim;
1023 victim->type = PLAYER;
1024 SET_FLAG (victim, FLAG_WIZ);
1025
1026 /* send the inventory to the client */
1027 curinv = victim->inv;
1028 while (curinv != NULL)
1029 {
1030 nextinv = curinv->below;
1031 esrv_send_item (victim, curinv);
1032 curinv = nextinv;
1033 }
1034 /* basic patchup */
1035 /* The use of hard coded values is terrible. Note
1036 * that really, to be fair, this shouldn't get changed at
1037 * all - if you are possessing a kobold, you should have the
1038 * same limitations. As it is, as more body locations are added,
1039 * this will give this player more locations than perhaps
1040 * they should be allowed.
1041 */
1042 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1043 if (i == 1 || i == 6 || i == 8 || i == 9)
1044 victim->body_info[i] = 2;
1045 else
1046 victim->body_info[i] = 1;
1047
1048 esrv_new_player (pl, 80); /* just pick a wieght, we don't care */
1049 esrv_send_inventory (victim, victim);
1050
1051 fix_player (victim);
1052
1053 do_some_living (victim);
1054 return 1; 731 return 1;
1055} 732}
1056 733
1057int 734int
1058command_patch (object *op, char *params) 735command_patch (object *op, char *params)
1073 return 1; 750 return 1;
1074 } 751 }
1075 752
1076 if ((arg2 = strchr (arg, ' '))) 753 if ((arg2 = strchr (arg, ' ')))
1077 arg2++; 754 arg2++;
1078 if (settings.real_wiz == FALSE) 755
1079 SET_FLAG (tmp, FLAG_WAS_WIZ); /* To avoid cheating */
1080 if (set_variable (tmp, arg) == -1) 756 if (set_variable (tmp, arg) == -1)
1081 new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", arg); 757 new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", arg);
1082 else 758 else
1083 {
1084 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s=%s", &tmp->name, tmp->count, arg, arg2); 759 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s=%s", &tmp->name, tmp->count, arg, arg2);
1085 }
1086 760
1087 return 1; 761 return 1;
1088} 762}
1089 763
1090int 764int
1117 dm_stack_pop (op->contr); 791 dm_stack_pop (op->contr);
1118 792
1119 /* Always work on the head - otherwise object will get in odd state */ 793 /* Always work on the head - otherwise object will get in odd state */
1120 if (tmp->head) 794 if (tmp->head)
1121 tmp = tmp->head; 795 tmp = tmp->head;
1122 remove_ob (tmp); 796 tmp->remove ();
1123 return 1; 797 return 1;
1124} 798}
1125 799
1126int 800int
1127command_free (object *op, char *params) 801command_free (object *op, char *params)
1139 813
1140 if (from != STACK_FROM_STACK) 814 if (from != STACK_FROM_STACK)
1141 /* Item is either stack top, or is a number thus is now stack top, let's remove it */ 815 /* Item is either stack top, or is a number thus is now stack top, let's remove it */
1142 dm_stack_pop (op->contr); 816 dm_stack_pop (op->contr);
1143 817
1144 if (!QUERY_FLAG (tmp, FLAG_REMOVED))
1145 {
1146 new_draw_info (NDI_UNIQUE, 0, op, "Warning, item wasn't removed.");
1147 remove_ob (tmp);
1148 }
1149
1150 if (tmp->head) 818 if (tmp->head)
1151 tmp = tmp->head; 819 tmp = tmp->head;
1152 free_object (tmp); 820
821 tmp->destroy ();
1153 return 1; 822 return 1;
1154} 823}
1155 824
1156/** 825/**
1157 * This adds exp to a player. We now allow adding to a specific skill. 826 * This adds exp to a player. We now allow adding to a specific skill.
1158 */ 827 */
1159int 828int
1160command_addexp (object *op, char *params) 829command_addexp (object *op, char *params)
1161{ 830{
1162 char buf[MAX_BUF], skill[MAX_BUF]; 831 char buf[MAX_BUF], skill[MAX_BUF];
1163 int i, q; 832 int q;
833 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
1164 object *skillob = NULL; 834 object *skillob = NULL;
1165 player *pl;
1166 835
1167 skill[0] = '\0'; 836 skill[0] = '\0';
1168 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %d %s", buf, &i, skill)) < 2)) 837 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %s", buf, &i, skill)) < 2))
1169 { 838 {
1170 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); 839 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
1171 return 1; 840 return 1;
1172 } 841 }
1173 842
1174 for (pl = first_player; pl != NULL; pl = pl->next) 843 for_all_players (pl)
1175 if (!strncmp (pl->ob->name, buf, MAX_NAME)) 844 if (!strncmp (pl->ob->name, buf, MAX_NAME))
1176 break;
1177
1178 if (pl == NULL)
1179 { 845 {
1180 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1181 return 1;
1182 }
1183
1184 if (q >= 3) 846 if (q >= 3)
1185 { 847 {
1186 skillob = find_skill_by_name (pl->ob, skill); 848 skillob = find_skill_by_name (pl->ob, skill);
1187 if (!skillob) 849 if (!skillob)
1188 { 850 {
1189 new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s in %s", skill, buf); 851 new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s in %s", skill, buf);
852 return 1;
853 }
854
855 i = check_exp_adjust (skillob, i);
856 skillob->stats.exp += i;
857 calc_perm_exp (skillob);
858 player_lvl_adj (pl->ob, skillob);
859 }
860
861 pl->ob->stats.exp += i;
862 calc_perm_exp (pl->ob);
863 player_lvl_adj (pl->ob, NULL);
864
1190 return 1; 865 return 1;
1191 } 866 }
1192 867
1193 i = check_exp_adjust (skillob, i); 868 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1194 skillob->stats.exp += i;
1195 calc_perm_exp (skillob);
1196 player_lvl_adj (pl->ob, skillob);
1197 }
1198
1199 pl->ob->stats.exp += i;
1200 calc_perm_exp (pl->ob);
1201 player_lvl_adj (pl->ob, NULL);
1202
1203 if (settings.real_wiz == FALSE)
1204 SET_FLAG (pl->ob, FLAG_WAS_WIZ);
1205 return 1; 869 return 1;
1206} 870}
1207 871
1208/**************************************************************************/ 872/**************************************************************************/
1209 873
1215 879
1216int 880int
1217command_stats (object *op, char *params) 881command_stats (object *op, char *params)
1218{ 882{
1219 char thing[20]; 883 char thing[20];
1220 player *pl;
1221 char buf[MAX_BUF]; 884 char buf[MAX_BUF];
1222 885
1223 thing[0] = '\0'; 886 thing[0] = '\0';
1224 if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL) 887 if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL)
1225 { 888 {
1226 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 889 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
1227 return 1; 890 return 1;
1228 } 891 }
1229 892
1230 for (pl = first_player; pl != NULL; pl = pl->next) 893 for_all_players (pl)
1231 if (!strcmp (pl->ob->name, thing)) 894 if (!strcmp (pl->ob->name, thing))
1232 { 895 {
1233 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); 896 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp);
1234 new_draw_info (NDI_UNIQUE, 0, op, buf); 897 new_draw_info (NDI_UNIQUE, 0, op, buf);
1235 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); 898 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp);
1236 new_draw_info (NDI_UNIQUE, 0, op, buf); 899 new_draw_info (NDI_UNIQUE, 0, op, buf);
1237 sprintf (buf, "Con : %-2d AC : %-4d WC : %d", pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc); 900 sprintf (buf, "Con : %-2d AC : %-4d WC : %d", pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc);
1238 new_draw_info (NDI_UNIQUE, 0, op, buf); 901 new_draw_info (NDI_UNIQUE, 0, op, buf);
1239 sprintf (buf, "Int : %-2d Damage : %d", pl->ob->stats.Int, pl->ob->stats.dam); 902 sprintf (buf, "Int : %-2d Damage : %d", pl->ob->stats.Int, pl->ob->stats.dam);
1240 new_draw_info (NDI_UNIQUE, 0, op, buf); 903 new_draw_info (NDI_UNIQUE, 0, op, buf);
1241 sprintf (buf, "Wis : %-2d EXP : %lld", pl->ob->stats.Wis, (long long) pl->ob->stats.exp); 904 sprintf (buf, "Wis : %-2d EXP : %" PRId64, pl->ob->stats.Wis, pl->ob->stats.exp);
1242 new_draw_info (NDI_UNIQUE, 0, op, buf); 905 new_draw_info (NDI_UNIQUE, 0, op, buf);
1243 sprintf (buf, "Pow : %-2d Grace : %d", pl->ob->stats.Pow, pl->ob->stats.grace); 906 sprintf (buf, "Pow : %-2d Grace : %d", pl->ob->stats.Pow, pl->ob->stats.grace);
1244 new_draw_info (NDI_UNIQUE, 0, op, buf); 907 new_draw_info (NDI_UNIQUE, 0, op, buf);
1245 sprintf (buf, "Cha : %-2d Food : %d", pl->ob->stats.Cha, pl->ob->stats.food); 908 sprintf (buf, "Cha : %-2d Food : %d", pl->ob->stats.Cha, pl->ob->stats.food);
1246 new_draw_info (NDI_UNIQUE, 0, op, buf); 909 new_draw_info (NDI_UNIQUE, 0, op, buf);
1247 break; 910 return 1;
1248 } 911 }
1249 if (pl == NULL) 912
1250 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 913 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1251 return 1; 914 return 1;
1252} 915}
1253 916
1254int 917int
1255command_abil (object *op, char *params) 918command_abil (object *op, char *params)
1256{ 919{
1257 char thing[20], thing2[20]; 920 char thing[20], thing2[20];
1258 int iii; 921 int iii;
1259 player *pl;
1260 char buf[MAX_BUF]; 922 char buf[MAX_BUF];
1261 923
1262 iii = 0; 924 iii = 0;
1263 thing[0] = '\0'; 925 thing[0] = '\0';
1264 thing2[0] = '\0'; 926 thing2[0] = '\0';
1278 { 940 {
1279 new_draw_info (NDI_UNIQUE, 0, op, "Illegal range of stat.\n"); 941 new_draw_info (NDI_UNIQUE, 0, op, "Illegal range of stat.\n");
1280 return 1; 942 return 1;
1281 } 943 }
1282 944
1283 for (pl = first_player; pl != NULL; pl = pl->next) 945 for_all_players (pl)
1284 { 946 {
1285 if (!strcmp (pl->ob->name, thing)) 947 if (!strcmp (pl->ob->name, thing))
1286 { 948 {
1287 if (settings.real_wiz == FALSE)
1288 SET_FLAG (pl->ob, FLAG_WAS_WIZ);
1289 if (!strcmp ("str", thing2))
1290 pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; 949 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii;
1291 if (!strcmp ("dex", thing2))
1292 pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; 950 if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii;
1293 if (!strcmp ("con", thing2))
1294 pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; 951 if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii;
1295 if (!strcmp ("wis", thing2))
1296 pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; 952 if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii;
1297 if (!strcmp ("cha", thing2))
1298 pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii; 953 if (!strcmp ("cha", thing2)) pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii;
1299 if (!strcmp ("int", thing2))
1300 pl->ob->stats.Int = iii, pl->orig_stats.Int = iii; 954 if (!strcmp ("int", thing2)) pl->ob->stats.Int = iii, pl->orig_stats.Int = iii;
1301 if (!strcmp ("pow", thing2))
1302 pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii; 955 if (!strcmp ("pow", thing2)) pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii;
956
1303 sprintf (buf, "%s has been altered.", &pl->ob->name); 957 sprintf (buf, "%s has been altered.", &pl->ob->name);
1304 new_draw_info (NDI_UNIQUE, 0, op, buf); 958 new_draw_info (NDI_UNIQUE, 0, op, buf);
1305 fix_player (pl->ob); 959 pl->ob->update_stats ();
1306 return 1; 960 return 1;
1307 } 961 }
1308 } 962 }
1309 963
1310 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 964 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1311 return 1; 965 return 1;
1312} 966}
1313 967
1314int 968int
1315command_reset (object *op, char *params)
1316{
1317 maptile *m;
1318 object *dummy = NULL, *tmp = NULL;
1319
1320 if (params == NULL)
1321 {
1322 new_draw_info (NDI_UNIQUE, 0, op, "Reset what map [name]?");
1323 return 1;
1324 }
1325
1326 if (strcmp (params, ".") == 0)
1327 params = op->map->path;
1328 m = has_been_loaded (params);
1329 if (m == NULL)
1330 {
1331 new_draw_info (NDI_UNIQUE, 0, op, "No such map.");
1332 return 1;
1333 }
1334
1335 if (m->in_memory != MAP_SWAPPED)
1336 {
1337 if (m->in_memory != MAP_IN_MEMORY)
1338 {
1339 LOG (llevError, "Tried to swap out map which was not in memory.\n");
1340 return 0;
1341 }
1342
1343 /*
1344 * Only attempt to remove the player that is doing the reset, and not other
1345 * players or wiz's.
1346 */
1347 if (op->map == m)
1348 {
1349 dummy = get_object ();
1350 dummy->map = NULL;
1351 EXIT_X (dummy) = op->x;
1352 EXIT_Y (dummy) = op->y;
1353 EXIT_PATH (dummy) = op->map->path;
1354 remove_ob (op);
1355 op->map = NULL;
1356 tmp = op;
1357 }
1358 swap_map (m);
1359 }
1360
1361 if (m->in_memory == MAP_SWAPPED)
1362 {
1363 LOG (llevDebug, "Resetting map %s.\n", m->path);
1364
1365 /* setting this effectively causes an immediate reload */
1366 m->reset_time = 1;
1367 flush_old_maps ();
1368 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
1369 if (tmp)
1370 {
1371 enter_exit (tmp, dummy);
1372 free_object (dummy);
1373 }
1374 return 1;
1375 }
1376 else
1377 {
1378 player *pl;
1379 int playercount = 0;
1380
1381 /* Need to re-insert player if swap failed for some reason */
1382 if (tmp)
1383 {
1384 insert_ob_in_map (op, m, NULL, 0);
1385 free_object (dummy);
1386 }
1387
1388 new_draw_info (NDI_UNIQUE, 0, op, "Reset failed, couldn't swap map, the following players are on it:");
1389 for (pl = first_player; pl != NULL; pl = pl->next)
1390 {
1391 if (pl->ob->map == m && pl->ob != op)
1392 {
1393 new_draw_info_format (NDI_UNIQUE, 0, op, "%s", &pl->ob->name);
1394 playercount++;
1395 }
1396 }
1397 if (!playercount)
1398 new_draw_info (NDI_UNIQUE, 0, op, "hmm, I don't see any other players on this map, something else is the problem.");
1399 return 1;
1400 }
1401}
1402
1403int
1404command_nowiz (object *op, char *params) 969command_nowiz (object *op, char *params)
1405{ /* 'noadm' is alias */ 970{ /* 'nodm' is alias */
1406 CLEAR_FLAG (op, FLAG_WIZ); 971 CLEAR_FLAG (op, FLAG_WIZ);
1407 CLEAR_FLAG (op, FLAG_WIZPASS); 972 CLEAR_FLAG (op, FLAG_WIZPASS);
1408 CLEAR_FLAG (op, FLAG_WIZCAST); 973 CLEAR_FLAG (op, FLAG_WIZCAST);
1409 974
1410 if (settings.real_wiz == TRUE)
1411 CLEAR_FLAG (op, FLAG_WAS_WIZ);
1412 if (op->contr->hidden) 975 if (op->contr->hidden)
1413 { 976 {
1414 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); 977 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
1415 op->map->players++; 978 op->map->players++;
1416 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name); 979 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
1475 { 1038 {
1476 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); 1039 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1477 return 0; 1040 return 0;
1478 } 1041 }
1479 1042
1480 if (checkdm (op, op->name, (params ? params : "*"), op->contr->socket.host)) 1043 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1481 { 1044 {
1482 SET_FLAG (op, FLAG_WIZ); 1045 SET_FLAG (op, FLAG_WIZ);
1483 SET_FLAG (op, FLAG_WAS_WIZ);
1484 SET_FLAG (op, FLAG_WIZPASS); 1046 SET_FLAG (op, FLAG_WIZPASS);
1485 SET_FLAG (op, FLAG_WIZCAST); 1047 SET_FLAG (op, FLAG_WIZCAST);
1048 SET_FLAG (op, FLAG_WIZLOOK);
1049
1486 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); 1050 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1487 /*
1488 * Remove setting flying here - that won't work, because next
1489 * fix_player() is called that will get cleared - proper solution
1490 * is probably something like a wiz_force which gives that and any
1491 * other desired abilities.
1492 */
1493 clear_los (op);
1494 op->contr->write_buf[0] = '\0'; 1051 op->contr->write_buf[0] = '\0';
1495 1052
1496 if (!silent) 1053 if (!silent)
1497 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); 1054 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1498 1055
1525command_invisible (object *op, char *params) 1082command_invisible (object *op, char *params)
1526{ 1083{
1527 if (op) 1084 if (op)
1528 { 1085 {
1529 op->invisible += 100; 1086 op->invisible += 100;
1530 update_object (op, UP_OBJ_FACE); 1087 update_object (op, UP_OBJ_CHANGE);
1531 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); 1088 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible.");
1532 } 1089 }
1533 1090
1534 return 0; 1091 return 0;
1535} 1092}
1547 * name than other "spell_xxx" archetypes and would always conflict. 1104 * name than other "spell_xxx" archetypes and would always conflict.
1548 */ 1105 */
1549static object * 1106static object *
1550get_spell_by_name (object *op, const char *spell_name) 1107get_spell_by_name (object *op, const char *spell_name)
1551{ 1108{
1552 archetype *ar; 1109 archetype *at;
1553 archetype *found; 1110 archetype *found;
1554 int conflict_found; 1111 int conflict_found;
1555 size_t spell_name_length; 1112 size_t spell_name_length;
1556 1113
1557 /* First check for full name matches. */ 1114 /* First check for full name matches. */
1558 conflict_found = 0; 1115 conflict_found = 0;
1559 found = NULL; 1116 found = NULL;
1560 for (ar = first_archetype; ar != NULL; ar = ar->next) 1117 for_all_archetypes (at)
1561 { 1118 {
1562 if (ar->clone.type != SPELL) 1119 if (at->type != SPELL)
1563 continue; 1120 continue;
1564 1121
1565 if (strncmp (ar->name, "spelldirect_", 12) == 0) 1122 if (strncmp (at->archname, "spelldirect_", 12) == 0)
1566 continue; 1123 continue;
1567 1124
1568 if (strcmp (ar->clone.name, spell_name) != 0) 1125 if (strcmp (at->object::name, spell_name) != 0)
1569 continue; 1126 continue;
1570 1127
1571 if (found != NULL) 1128 if (found != NULL)
1572 { 1129 {
1573 if (!conflict_found) 1130 if (!conflict_found)
1574 { 1131 {
1575 conflict_found = 1; 1132 conflict_found = 1;
1576 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); 1133 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name);
1577 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->name); 1134 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1578 } 1135 }
1136
1579 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &ar->name); 1137 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1580 continue; 1138 continue;
1581 } 1139 }
1582 1140
1583 found = ar; 1141 found = at;
1584 } 1142 }
1585 1143
1586 /* No match if more more than one archetype matches. */ 1144 /* No match if more more than one archetype matches. */
1587 if (conflict_found) 1145 if (conflict_found)
1588 return NULL; 1146 return NULL;
1593 1151
1594 /* No full match found: now check for partial matches. */ 1152 /* No full match found: now check for partial matches. */
1595 spell_name_length = strlen (spell_name); 1153 spell_name_length = strlen (spell_name);
1596 conflict_found = 0; 1154 conflict_found = 0;
1597 found = NULL; 1155 found = NULL;
1598 for (ar = first_archetype; ar != NULL; ar = ar->next) 1156 for_all_archetypes (at)
1599 { 1157 {
1600 if (ar->clone.type != SPELL) 1158 if (at->type != SPELL)
1601 continue; 1159 continue;
1602 1160
1603 if (strncmp (ar->name, "spelldirect_", 12) == 0) 1161 if (strncmp (at->archname, "spelldirect_", 12) == 0)
1604 continue; 1162 continue;
1605 1163
1606 if (strncmp (ar->clone.name, spell_name, spell_name_length) != 0) 1164 if (strncmp (at->object::name, spell_name, spell_name_length) != 0)
1607 continue; 1165 continue;
1608 1166
1609 if (found != NULL) 1167 if (found != NULL)
1610 { 1168 {
1611 if (!conflict_found) 1169 if (!conflict_found)
1612 { 1170 {
1613 conflict_found = 1; 1171 conflict_found = 1;
1614 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name); 1172 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name);
1615 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->clone.name); 1173 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->object::name);
1616 } 1174 }
1617 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &ar->clone.name); 1175 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->object::name);
1618 continue; 1176 continue;
1619 } 1177 }
1620 1178
1621 found = ar; 1179 found = at;
1622 } 1180 }
1623 1181
1624 /* No match if more more than one archetype matches. */ 1182 /* No match if more more than one archetype matches. */
1625 if (conflict_found) 1183 if (conflict_found)
1626 return NULL; 1184 return NULL;
1656 new_draw_info_format (NDI_UNIQUE, 0, op, "You already know the spell %s.", &tmp->name); 1214 new_draw_info_format (NDI_UNIQUE, 0, op, "You already know the spell %s.", &tmp->name);
1657 return 0; 1215 return 0;
1658 } 1216 }
1659 1217
1660 do_learn_spell (op, tmp, special_prayer); 1218 do_learn_spell (op, tmp, special_prayer);
1661 free_object (tmp); 1219 tmp->destroy ();
1662 return 1; 1220 return 1;
1663} 1221}
1664 1222
1665int 1223int
1666command_learn_spell (object *op, char *params) 1224command_learn_spell (object *op, char *params)
1691 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); 1249 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params);
1692 return 0; 1250 return 0;
1693 } 1251 }
1694 1252
1695 do_forget_spell (op, spell->name); 1253 do_forget_spell (op, spell->name);
1696 return 1;
1697}
1698
1699/**
1700 * Lists all plugins currently loaded with their IDs and full names.
1701 */
1702int
1703command_listplugins (object *op, char *params)
1704{
1705 plugins_display_list (op);
1706 return 1;
1707}
1708
1709/**
1710 * Loads the given plugin. The DM specifies the name of the library to load (no
1711 * pathname is needed). Do not ever attempt to load the same plugin more than
1712 * once at a time, or bad things could happen.
1713 */
1714int
1715command_loadplugin (object *op, char *params)
1716{
1717 char buf[MAX_BUF];
1718
1719 if (params == NULL)
1720 {
1721 new_draw_info (NDI_UNIQUE, 0, op, "Load which plugin?");
1722 return 1;
1723 }
1724
1725 strcpy (buf, LIBDIR);
1726 strcat (buf, "/plugins/");
1727 strcat (buf, params);
1728 LOG (llevDebug, "Requested plugin file is %s\n", buf);
1729 if (plugins_init_plugin (buf) == 0)
1730 new_draw_info (NDI_UNIQUE, 0, op, "Plugin successfully loaded.");
1731 else
1732 new_draw_info (NDI_UNIQUE, 0, op, "Could not load plugin.");
1733 return 1;
1734}
1735
1736/**
1737 * Unloads the given plugin. The DM specified the ID of the library to unload.
1738 * Note that some things may behave strangely if the correct plugins are not
1739 * loaded.
1740 */
1741int
1742command_unloadplugin (object *op, char *params)
1743{
1744 if (params == NULL)
1745 {
1746 new_draw_info (NDI_UNIQUE, 0, op, "Remove which plugin?");
1747 return 1;
1748 }
1749
1750 if (plugins_remove_plugin (params) == 0)
1751 new_draw_info (NDI_UNIQUE, 0, op, "Plugin successfully removed.");
1752 else
1753 new_draw_info (NDI_UNIQUE, 0, op, "Could not remove plugin.");
1754 return 1; 1254 return 1;
1755} 1255}
1756 1256
1757/** 1257/**
1758 * A players wants to become DM and hide. 1258 * A players wants to become DM and hide.
2078 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); 1578 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!");
2079 return 0; 1579 return 0;
2080 } 1580 }
2081 1581
2082 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1582 if (!QUERY_FLAG (right, FLAG_REMOVED))
2083 remove_ob (right); 1583 right->remove ();
1584
2084 inserted = insert_ob_in_ob (right, left); 1585 insert_ob_in_ob (right, left);
2085 if (left->type == PLAYER)
2086 if (inserted == right)
2087 esrv_send_item (left, right);
2088 else
2089 esrv_update_item (UPD_WEIGHT | UPD_NAME | UPD_NROF, left, inserted);
2090 1586
2091 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); 1587 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left));
2092 1588
2093 return 0; 1589 return 0;
2094 1590

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines