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.75 by root, Fri Nov 6 12:49:19 2009 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 (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * 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 9 * 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) 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * 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 19 * and the GNU General Public License along with this program. If not, see
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <sproto.h> 26#include <sproto.h>
27#include <spells.h> 27#include <spells.h>
34/* Values for 'from' field of get_dm_object */ 34/* Values for 'from' field of get_dm_object */
35#define STACK_FROM_NONE 0 /* Item was not found */ 35#define STACK_FROM_NONE 0 /* Item was not found */
36#define STACK_FROM_TOP 1 /* Item is stack top */ 36#define STACK_FROM_TOP 1 /* Item is stack top */
37#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ 37#define STACK_FROM_STACK 2 /* Item is somewhere in stack */
38#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ 38#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */
39
40 39
41/** 40/**
42 * Enough of the DM functions seem to need this that I broke 41 * Enough of the DM functions seem to need this that I broke
43 * it out to a seperate function. name is the person 42 * it out to a seperate function. name is the person
44 * being saught, rq is who is looking for them. This 43 * being saught, rq is who is looking for them. This
71 70
72 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 71 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
73 return 0; 72 return 0;
74} 73}
75 74
75static void
76dm_stack_pop (player *pl)
77{
78 if (!pl->stack_items || !pl->stack_position)
79 {
80 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
81 return;
82 }
83
84 pl->stack_position--;
85 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
86}
87
88/**
89 * Get current stack top item for player.
90 * Returns NULL if no stacked item.
91 * If stacked item disappeared (freed), remove it.
92 *
93 * Ryo, august 2004
94 */
95static object *
96dm_stack_peek (player *pl)
97{
98 object *ob;
99
100 if (!pl->stack_position)
101 {
102 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
103 return NULL;
104 }
105
106 ob = find_object (pl->stack_items[pl->stack_position - 1]);
107 if (!ob)
108 {
109 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
110 dm_stack_pop (pl);
111 return NULL;
112 }
113
114 return ob;
115}
116
117/**
118 * Push specified item on player stack.
119 * Inform player of position.
120 * Initializes variables if needed.
121 */
122void
123dm_stack_push (player *pl, tag_t item)
124{
125 if (!pl->stack_items)
126 {
127 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
128 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
129 }
130
131 if (pl->stack_position == STACK_SIZE)
132 {
133 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
134 return;
135 }
136
137 pl->stack_items[pl->stack_position] = item;
138 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
139 pl->stack_position++;
140}
141
142/**
143 * Checks 'params' for object code.
144 *
145 * Can be:
146 * * empty => get current object stack top for player
147 * * number => get item with that tag, stack it for future use
148 * * $number => get specified stack item
149 * * "me" => player himself
150 *
151 * At function exit, params points to first non-object char
152 *
153 * 'from', if not NULL, contains at exit:
154 * * STACK_FROM_NONE => object not found
155 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
156 * * STACK_FROM_STACK => item from somewhere in the stack
157 * * STACK_FROM_NUMBER => item by number, pushed on stack
158 *
159 * Ryo, august 2004
160 */
161static object *
162get_dm_object (player *pl, char **params, int *from)
163{
164 int item_tag, item_position;
165 object *ob;
166
167 if (!pl)
168 return NULL;
169
170 if (!params || !*params || **params == '\0')
171 {
172 if (from)
173 *from = STACK_FROM_TOP;
174 /* No parameter => get stack item */
175 return dm_stack_peek (pl);
176 }
177
178 /* Let's clean white spaces */
179 while (**params == ' ')
180 (*params)++;
181
182 /* Next case: number => item tag */
183 if (sscanf (*params, "%d", &item_tag))
184 {
185 /* Move parameter to next item */
186 while (isdigit (**params))
187 (*params)++;
188
189 /* And skip blanks, too */
190 while (**params == ' ')
191 (*params)++;
192
193 /* Get item */
194 ob = find_object (item_tag);
195 if (!ob)
196 {
197 if (from)
198 *from = STACK_FROM_NONE;
199 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
200 return NULL;
201 }
202
203 /* Got one, let's push it on stack */
204 dm_stack_push (pl, item_tag);
205 if (from)
206 *from = STACK_FROM_NUMBER;
207 return ob;
208 }
209
210 /* Next case: $number => stack item */
211 if (sscanf (*params, "$%d", &item_position))
212 {
213 /* Move parameter to next item */
214 (*params)++;
215
216 while (isdigit (**params))
217 (*params)++;
218 while (**params == ' ')
219 (*params)++;
220
221 if (item_position >= pl->stack_position)
222 {
223 if (from)
224 *from = STACK_FROM_NONE;
225 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
226 return NULL;
227 }
228
229 ob = find_object (pl->stack_items[item_position]);
230 if (!ob)
231 {
232 if (from)
233 *from = STACK_FROM_NONE;
234 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
235 return NULL;
236 }
237
238 if (from)
239 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
240 return ob;
241 }
242
243 /* Next case: 'me' => return pl->ob */
244 if (!strncmp (*params, "me", 2))
245 {
246 if (from)
247 *from = STACK_FROM_NUMBER;
248 dm_stack_push (pl, pl->ob->count);
249
250 /* Skip to next token */
251 (*params) += 2;
252 while (**params == ' ')
253 (*params)++;
254
255 return pl->ob;
256 }
257
258 /* Last case: get stack top */
259 if (from)
260 *from = STACK_FROM_TOP;
261 return dm_stack_peek (pl);
262}
263
76/** 264/**
77 * Actually hides specified player (obviously a DM). 265 * Actually hides specified player (obviously a DM).
78 * If 'silent_dm' is non zero, other players are informed of DM entering/leaving, 266 * If 'silent_dm' is non zero, other players are informed of DM entering/leaving,
79 * else they just think someone left/entered. 267 * else they just think someone left/entered.
80 */ 268 */
81void 269static void
82do_wizard_hide (object *op, int silent_dm) 270do_wizard_hide (object *op, int silent_dm)
83{ 271{
84 if (op->contr->hidden) 272 if (op->contr->hidden)
85 { 273 {
86 op->contr->hidden = 0; 274 op->contr->hidden = 0;
173 become_follower (ob, god); 361 become_follower (ob, god);
174 return 1; 362 return 1;
175} 363}
176 364
177// TODO: Rewrite banish in perl and get rid of the following two functions 365// TODO: Rewrite banish in perl and get rid of the following two functions
178int 366static int
179command_kick (object *op, char *params) 367command_kick (object *op, char *params)
180{ 368{
181 for_all_players (pl) 369 for_all_players (pl)
182 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params))) 370 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
183 { 371 {
184 object *op = pl->ob; 372 object *plop = pl->ob;
185 373
186 if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED)) 374 if (!QUERY_FLAG (plop, FLAG_REMOVED) && !QUERY_FLAG (plop, FLAG_FREED))
187 { 375 {
188 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &op->name); 376 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &plop->name);
189 strcpy (op->contr->killer, "kicked"); 377 plop->contr->killer = op;
190 } 378 }
191 379
192 pl->ns->destroy (); 380 pl->ns->destroy ();
193 } 381 }
194 382
280 /* we have nowhere to send the prisoner.... */ 468 /* 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"); 469 new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them");
282 return 0; 470 return 0;
283 } 471 }
284 472
285 pl->ob->enter_exit (dummy); 473 pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO
286 dummy->destroy (); 474 dummy->destroy ();
475
287 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); 476 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested.");
288 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 477 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
289 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); 478 LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name);
290 return 1; 479 return 1;
291} 480}
315 { 504 {
316 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); 505 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
317 return 1; 506 return 1;
318 } 507 }
319 508
320 dummy = object::create (); 509 pl->ob->player_goto (op->map->path, op->x + freearr_x[i], op->y + freearr_y[i]);
321 EXIT_PATH (dummy) = op->map->path;
322 EXIT_X (dummy) = op->x + freearr_x[i];
323 EXIT_Y (dummy) = op->y + freearr_y[i];
324 pl->ob->enter_exit (dummy);
325 dummy->destroy ();
326 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); 510 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
327 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 511 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
328 512
329 return 1; 513 return 1;
330} 514}
423 * we also set up spell_name which is only 607 * we also set up spell_name which is only
424 * the first word. 608 * the first word.
425 */ 609 */
426 610
427 at_spell = archetype::find (cp); 611 at_spell = archetype::find (cp);
428 if (!at_spell || at_spell->clone.type != SPELL) 612 if (!at_spell || at_spell->type != SPELL)
429 at_spell = find_archetype_by_object_name (cp); 613 at_spell = find_archetype_by_object_name (cp);
430 if (!at_spell || at_spell->clone.type != SPELL) 614 if (!at_spell || at_spell->type != SPELL)
431 { 615 {
432 assign (spell_name, cp); 616 assign (spell_name, cp);
433 fsp = strchr (spell_name, ' '); 617 fsp = strchr (spell_name, ' ');
434 if (fsp) 618 if (fsp)
435 { 619 {
436 *fsp = 0; 620 *fsp = 0;
437 fsp++; 621 fsp++;
438 at_spell = archetype::find (spell_name); 622 at_spell = archetype::find (spell_name);
439 623
440 /* Got a spell, update the first string pointer */ 624 /* Got a spell, update the first string pointer */
441 if (at_spell && at_spell->clone.type == SPELL) 625 if (at_spell && at_spell->type == SPELL)
442 bp2 = cp + strlen (spell_name) + 1; 626 bp2 = cp + strlen (spell_name) + 1;
443 else 627 else
444 at_spell = NULL; 628 at_spell = NULL;
445 } 629 }
446 } 630 }
448 /* OK - we didn't find a spell - presume the 'of' 632 /* OK - we didn't find a spell - presume the 'of'
449 * in this case means its an artifact. 633 * in this case means its an artifact.
450 */ 634 */
451 if (!at_spell) 635 if (!at_spell)
452 { 636 {
453 if (find_artifactlist (at->clone.type) == NULL) 637 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); 638 new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->type);
455 else 639 else
456 { 640 {
457 art = find_artifactlist (at->clone.type)->items; 641 art = find_artifactlist (at->type)->items;
458 642
459 while (art) 643 while (art)
460 { 644 {
461 if (!strcmp (art->item->name, cp)) 645 if (!strcmp (&art->item->name, cp))
462 break; 646 break;
463 647
464 art = art->next; 648 art = art->next;
465 } 649 }
466 650
467 if (!art) 651 if (!art)
468 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->clone.type, cp); 652 new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->type, cp);
469 } 653 }
470 654
471 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp); 655 LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp);
472 } 656 }
473 } /* if cp */ 657 } /* if cp */
474 658
475 if ((at->clone.type == ROD || at->clone.type == WAND || at->clone.type == SCROLL || 659 if ((at->type == ROD || at->type == WAND || at->type == SCROLL ||
476 at->clone.type == HORN || at->clone.type == SPELLBOOK) && !at_spell) 660 at->type == HORN || at->type == SPELLBOOK) && !at_spell)
477 { 661 {
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); 662 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; 663 return 1;
480 } 664 }
481 665
572 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2); 756 new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2);
573 757
574 bp2 = bp3 + 1; 758 bp2 = bp3 + 1;
575 } 759 }
576 760
577 if (at->clone.nrof) 761 if (at->nrof)
578 { 762 {
579 if (at_spell) 763 if (at_spell)
580 insert_ob_in_ob (arch_to_object (at_spell), tmp); 764 tmp->insert (arch_to_object (at_spell));
581 765
582 tmp->x = op->x; 766 tmp->x = op->x;
583 tmp->y = op->y; 767 tmp->y = op->y;
768 tmp->map = op->map;
584 769
585 if (set_nrof) 770 if (set_nrof)
586 tmp->nrof = nrof; 771 tmp->nrof = nrof;
587 772
588 tmp->map = op->map; 773 op->insert (tmp);
589
590 tmp = insert_ob_in_ob (tmp, op);
591 esrv_send_item (op, tmp);
592 774
593 /* Let's put this created item on stack so dm can access it easily. */ 775 /* Let's put this created item on stack so dm can access it easily. */
594 dm_stack_push (op->contr, tmp->count); 776 dm_stack_push (op->contr, tmp->count);
595 777
596 return 1; 778 return 1;
597 } 779 }
598 else 780 else
599 { 781 {
600 for (i = 0; i < (set_nrof ? nrof : 1); i++) 782 for (i = 0; i < (set_nrof ? nrof : 1); i++)
601 { 783 {
602 archetype *atmp;
603 object *prev = 0, *head = 0; 784 object *prev = 0, *head = 0;
604 785
605 for (atmp = at; atmp; atmp = atmp->more) 786 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
606 { 787 {
607 object *dup = arch_to_object (atmp); 788 object *dup = arch_to_object (atmp);
608 789
609 if (at_spell) 790 if (at_spell)
610 insert_ob_in_ob (arch_to_object (at_spell), dup); 791 insert_ob_in_ob (arch_to_object (at_spell), dup);
617 { 798 {
618 head = dup; 799 head = dup;
619 tmp->copy_to (dup); 800 tmp->copy_to (dup);
620 } 801 }
621 802
622 dup->x = op->x + dup->arch->clone.x; 803 dup->x = op->x + dup->arch->x;
623 dup->y = op->y + dup->arch->clone.y; 804 dup->y = op->y + dup->arch->y;
624 dup->map = op->map; 805 dup->map = op->map;
625 806
626 if (head != dup) 807 if (head != dup)
627 { 808 {
628 dup->head = head; 809 dup->head = head;
638 int size_x = 0; 819 int size_x = 0;
639 int size_y = 0; 820 int size_y = 0;
640 821
641 while (check) 822 while (check)
642 { 823 {
643 size_x = MAX (size_x, check->arch->clone.x); 824 size_x = MAX (size_x, check->arch->x);
644 size_y = MAX (size_y, check->arch->clone.y); 825 size_y = MAX (size_y, check->arch->y);
645 check = check->more; 826 check = check->more;
646 } 827 }
647 828
648 if (out_of_map (op->map, head->x + size_x, head->y + size_y)) 829 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
649 { 830 {
675 /* Wonder if we really want to push all of these, but since 856 /* Wonder if we really want to push all of these, but since
676 * things like rods have nrof 0, we want to cover those. 857 * things like rods have nrof 0, we want to cover those.
677 */ 858 */
678 dm_stack_push (op->contr, head->count); 859 dm_stack_push (op->contr, head->count);
679 860
680 if (at->clone.randomitems != NULL && !at_spell) 861 if (at->randomitems && !at_spell)
681 create_treasure (at->clone.randomitems, head, GT_APPLY, op->map->difficulty, 0); 862 create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0);
682
683 esrv_send_item (op, head);
684 } 863 }
685 864
686 /* free the one we used to copy */ 865 /* free the one we used to copy */
687 tmp->destroy (); 866 tmp->destroy ();
688 } 867 }
695 */ 874 */
696 875
697int 876int
698command_inventory (object *op, char *params) 877command_inventory (object *op, char *params)
699{ 878{
879 int i;
700 object *tmp; 880 object *tmp;
701 int i;
702 881
703 if (!params) 882 if (!params || !sscanf (params, "%d", &i) || !(tmp = find_object (i)))
704 { 883 {
705 inventory (op, NULL); 884 op->contr->failmsg ("Inventory of what object (nr)?");
706 return 0; 885 return 1;
707 }
708
709 if (!sscanf (params, "%d", &i) || (tmp = find_object (i)) == NULL)
710 { 886 }
711 new_draw_info (NDI_UNIQUE, 0, op, "Inventory of what object (nr)?");
712 return 1;
713 }
714 887
715 inventory (op, tmp); 888 op->contr->infobox (MSG_CHANNEL ("examine"), tmp->query_inventory (op));
889
716 return 1; 890 return 1;
717} 891}
718 892
719/* just show player's their skills for now. Dm's can 893/* just show player's their skills for now. Dm's can
720 * already see skills w/ inventory command - b.t. 894 * already see skills w/ inventory command - b.t.
842 */ 1016 */
843int 1017int
844command_addexp (object *op, char *params) 1018command_addexp (object *op, char *params)
845{ 1019{
846 char buf[MAX_BUF], skill[MAX_BUF]; 1020 char buf[MAX_BUF], skill[MAX_BUF];
847 int i, q; 1021 int q;
1022 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
848 object *skillob = NULL; 1023 object *skillob = NULL;
849 1024
850 skill[0] = '\0'; 1025 skill[0] = '\0';
851 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %d %s", buf, &i, skill)) < 2)) 1026 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2))
852 { 1027 {
853 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); 1028 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
854 return 1; 1029 return 1;
855 } 1030 }
856 1031
903 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 1078 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
904 return 1; 1079 return 1;
905 } 1080 }
906 1081
907 for_all_players (pl) 1082 for_all_players (pl)
908 if (!strcmp (pl->ob->name, thing)) 1083 if (!strcmp (&pl->ob->name, thing))
909 { 1084 {
910 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); 1085 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); 1086 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); 1087 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); 1088 new_draw_info (NDI_UNIQUE, 0, op, buf);
956 return 1; 1131 return 1;
957 } 1132 }
958 1133
959 for_all_players (pl) 1134 for_all_players (pl)
960 { 1135 {
961 if (!strcmp (pl->ob->name, thing)) 1136 if (!strcmp (&pl->ob->name, thing))
962 { 1137 {
963 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; 1138 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; 1139 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; 1140 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; 1141 if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii;
983command_nowiz (object *op, char *params) 1158command_nowiz (object *op, char *params)
984{ /* 'nodm' is alias */ 1159{ /* 'nodm' is alias */
985 CLEAR_FLAG (op, FLAG_WIZ); 1160 CLEAR_FLAG (op, FLAG_WIZ);
986 CLEAR_FLAG (op, FLAG_WIZPASS); 1161 CLEAR_FLAG (op, FLAG_WIZPASS);
987 CLEAR_FLAG (op, FLAG_WIZCAST); 1162 CLEAR_FLAG (op, FLAG_WIZCAST);
1163 CLEAR_FLAG (op, FLAG_WIZLOOK);
1164 op->contr->do_los = 1;
988 1165
989 if (op->contr->hidden) 1166 if (op->contr->hidden)
990 { 1167 {
991 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); 1168 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
992 op->map->players++; 1169 op->map->players++;
994 op->contr->hidden = 0; 1171 op->contr->hidden = 0;
995 op->invisible = 1; 1172 op->invisible = 1;
996 } 1173 }
997 else 1174 else
998 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); 1175 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
1176
999 return 1; 1177 return 1;
1000} 1178}
1001 1179
1002/** 1180/**
1003 * object *op is trying to become dm. 1181 * object *op is trying to become dm.
1040 } 1218 }
1041 fclose (dmfile); 1219 fclose (dmfile);
1042 return (0); 1220 return (0);
1043} 1221}
1044 1222
1045int 1223static int
1046do_wizard_dm (object *op, char *params, int silent) 1224do_wizard_dm (object *op, char *params, int silent)
1047{ 1225{
1048 if (!op->contr) 1226 if (!op->contr)
1049 return 0; 1227 return 0;
1050 1228
1057 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) 1235 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1058 { 1236 {
1059 SET_FLAG (op, FLAG_WIZ); 1237 SET_FLAG (op, FLAG_WIZ);
1060 SET_FLAG (op, FLAG_WIZPASS); 1238 SET_FLAG (op, FLAG_WIZPASS);
1061 SET_FLAG (op, FLAG_WIZCAST); 1239 SET_FLAG (op, FLAG_WIZCAST);
1240 SET_FLAG (op, FLAG_WIZLOOK);
1241 op->contr->do_los = 1;
1062 1242
1063 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); 1243 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'; 1244 op->contr->write_buf[0] = '\0';
1072 1245
1073 if (!silent) 1246 if (!silent)
1074 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); 1247 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1075 1248
1115 * Returns spell object (from archetypes) by name. 1288 * Returns spell object (from archetypes) by name.
1116 * Returns NULL if 0 or more than one spell matches. 1289 * Returns NULL if 0 or more than one spell matches.
1117 * Used for wizard's learn spell/prayer. 1290 * Used for wizard's learn spell/prayer.
1118 * 1291 *
1119 * op is the player issuing the command. 1292 * 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 */ 1293 */
1126static object * 1294static object *
1127get_spell_by_name (object *op, const char *spell_name) 1295get_spell_by_name (object *op, shstr_cmp spell_name)
1128{ 1296{
1129 archetype *ar; 1297 /* First check for full name matches. */
1298 int conflict_found = 0;
1130 archetype *found; 1299 archetype *found;
1131 int conflict_found; 1300 for_all_archetypes (at)
1132 size_t spell_name_length;
1133
1134 /* First check for full name matches. */
1135 conflict_found = 0;
1136 found = NULL;
1137 for (ar = first_archetype; ar != NULL; ar = ar->next)
1138 { 1301 {
1139 if (ar->clone.type != SPELL) 1302 if (at->type != SPELL)
1140 continue; 1303 continue;
1141 1304
1142 if (strncmp (ar->name, "spelldirect_", 12) == 0) 1305 if (at->object::name != spell_name)
1143 continue; 1306 continue;
1144 1307
1145 if (strcmp (ar->clone.name, spell_name) != 0)
1146 continue;
1147
1148 if (found != NULL) 1308 if (found)
1149 { 1309 {
1150 if (!conflict_found) 1310 if (!conflict_found)
1151 { 1311 {
1152 conflict_found = 1; 1312 conflict_found = 1;
1153 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); 1313 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); 1314 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1155 } 1315 }
1316
1156 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &ar->name); 1317 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1157 continue; 1318 return 0;
1158 } 1319 }
1159 1320
1160 found = ar; 1321 found = at;
1161 } 1322 }
1162
1163 /* No match if more more than one archetype matches. */
1164 if (conflict_found)
1165 return NULL;
1166 1323
1167 /* Return if exactly one archetype matches. */ 1324 /* Return if exactly one archetype matches. */
1168 if (found != NULL) 1325 if (found)
1169 return arch_to_object (found); 1326 return arch_to_object (found);
1170 1327
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
1209 /* No spell found: just print an error message. */ 1328 /* 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); 1329 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist.");
1330
1211 return NULL; 1331 return 0;
1212} 1332}
1213 1333
1214static int 1334static int
1215command_learn_spell_or_prayer (object *op, char *params, int special_prayer) 1335command_learn_spell_or_prayer (object *op, char *params, int special_prayer)
1216{ 1336{
1268 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); 1388 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params);
1269 return 0; 1389 return 0;
1270 } 1390 }
1271 1391
1272 do_forget_spell (op, spell->name); 1392 do_forget_spell (op, spell->name);
1273 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; 1393 return 1;
1332} 1394}
1333 1395
1334/** 1396/**
1335 * A players wants to become DM and hide. 1397 * A players wants to become DM and hide.
1343 return 0; 1405 return 0;
1344 1406
1345 do_wizard_hide (op, 1); 1407 do_wizard_hide (op, 1);
1346 1408
1347 return 1; 1409 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} 1410}
1538 1411
1539/** 1412/**
1540 * Pop the stack top. 1413 * Pop the stack top.
1541 */ 1414 */
1656 return 0; 1529 return 0;
1657 } 1530 }
1658 1531
1659 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1532 if (!QUERY_FLAG (right, FLAG_REMOVED))
1660 right->remove (); 1533 right->remove ();
1534
1661 inserted = insert_ob_in_ob (right, left); 1535 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 1536
1668 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); 1537 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left));
1669 1538
1670 return 0; 1539 return 0;
1671 1540

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines