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.62 by root, Fri Dec 26 10:14:01 2008 UTC vs.
Revision 1.95 by root, Sat Nov 17 23:40:03 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / 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 * Deliantra is free software: you can redistribute it and/or modify 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 10 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License 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 19 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
20 * 22 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 24 */
23 25
24#include <global.h> 26#include <global.h>
25#include <sproto.h> 27#include <sproto.h>
33/* Values for 'from' field of get_dm_object */ 35/* Values for 'from' field of get_dm_object */
34#define STACK_FROM_NONE 0 /* Item was not found */ 36#define STACK_FROM_NONE 0 /* Item was not found */
35#define STACK_FROM_TOP 1 /* Item is stack top */ 37#define STACK_FROM_TOP 1 /* Item is stack top */
36#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ 38#define STACK_FROM_STACK 2 /* Item is somewhere in stack */
37#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) */
38
39 40
40/** 41/**
41 * 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
42 * it out to a seperate function. name is the person 43 * it out to a seperate function. name is the person
43 * being saught, rq is who is looking for them. This 44 * being saught, rq is who is looking for them. This
70 71
71 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 72 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
72 return 0; 73 return 0;
73} 74}
74 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
75/** 89/**
76 * Actually hides specified player (obviously a DM). 90 * Get current stack top item for player.
77 * If 'silent_dm' is non zero, other players are informed of DM entering/leaving, 91 * Returns NULL if no stacked item.
78 * 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.
79 */ 122 */
80void 123void
81do_wizard_hide (object *op, int silent_dm) 124dm_stack_push (player *pl, tag_t item)
82{ 125{
83 if (op->contr->hidden) 126 if (!pl->stack_items)
84 {
85 op->contr->hidden = 0;
86 op->invisible = 1;
87 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
88 op->map->players++;
89 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
90
91 if (!silent_dm)
92 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
93 } 127 {
94 else 128 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
129 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
95 { 130 }
96 op->contr->hidden = 1;
97 new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you.");
98 op->map->players--;
99 131
100 if (!silent_dm) 132 if (pl->stack_position == STACK_SIZE)
101 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
102
103 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name);
104 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name);
105 } 133 {
106} 134 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
107
108int
109command_hide (object *op, char *params)
110{
111 do_wizard_hide (op, 0);
112 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);
113} 263}
114 264
115/** 265/**
116 * This finds and returns the object which matches the name or 266 * This finds and returns the object which matches the name or
117 * object nubmer (specified via num #whatever). 267 * object nubmer (specified via num #whatever).
167 { 317 {
168 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);
169 return 1; 319 return 1;
170 } 320 }
171 321
172 become_follower (ob, god); 322 ob->become_follower (god);
173 return 1; 323 return 1;
174} 324}
175
176// TODO: Rewrite banish in perl and get rid of the following two functions
177int
178command_kick (object *op, char *params)
179{
180 for_all_players (pl)
181 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
182 {
183 object *plop = pl->ob;
184
185 if (!QUERY_FLAG (plop, FLAG_REMOVED) && !QUERY_FLAG (plop, FLAG_FREED))
186 {
187 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &plop->name);
188 plop->contr->killer = op;
189 }
190
191 pl->ns->destroy ();
192 }
193
194 return 1;
195}
196
197//TODO
198#if 0
199int
200command_save_overlay (object *op, char *params)
201{
202 if (!op)
203 return 0;
204
205 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
206 {
207 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't force an overlay save.");
208 return 1;
209 }
210
211 new_save_map (op->map, 2);
212 new_save_map (op->map, 0);
213 new_draw_info (NDI_UNIQUE, 0, op, "Current map has been saved as an" " overlay.");
214
215 ready_map_name (op->map->path, 0);
216
217 return 1;
218}
219#endif
220 325
221int 326int
222command_freeze (object *op, char *params) 327command_freeze (object *op, char *params)
223{ 328{
224 int ticks; 329 int ticks;
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 pl->ob->player_goto (op->map->path, op->x + freearr_x[i], op->y + freearr_y[i]); 428 nx += DIRX (i);
429 ny += DIRY (i);
430
431 if (!xy_normalise (m, nx, ny))
432 {
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);
321 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); 438 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
322 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 439 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
323 440
324 return 1; 441 return 1;
325} 442}
342int 459int
343command_create (object *op, char *params) 460command_create (object *op, char *params)
344{ 461{
345 object *tmp = NULL; 462 object *tmp = NULL;
346 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;
347 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *bp4, *endline; 464 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline;
348 archetype *at, *at_spell = NULL; 465 archetype *at, *at_spell = NULL;
349 artifact *art = NULL; 466 artifact *art = NULL;
350 467
351 if (!op) 468 if (!op)
352 return 0; 469 return 0;
451 { 568 {
452 art = find_artifactlist (at->type)->items; 569 art = find_artifactlist (at->type)->items;
453 570
454 while (art) 571 while (art)
455 { 572 {
456 if (!strcmp (art->item->name, cp)) 573 if (!strcmp (&art->item->name, cp))
457 break; 574 break;
458 575
459 art = art->next; 576 art = art->next;
460 } 577 }
461 578
477 /* 594 /*
478 * 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,
479 * just create one object, do all the processing, and then determine 596 * just create one object, do all the processing, and then determine
480 * 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.
481 */ 598 */
482 tmp = arch_to_object (at); 599 tmp = at->instance ();
483 600
484 if (set_magic) 601 if (set_magic)
485 set_abs_magic (tmp, magic); 602 set_abs_magic (tmp, magic);
486 603
487 if (art) 604 if (art)
488 give_artifact_abilities (tmp, art->item); 605 give_artifact_abilities (tmp, art->item);
489 606
490 if (need_identify (tmp)) 607 if (tmp->need_identify ())
491 { 608 {
492 SET_FLAG (tmp, FLAG_IDENTIFIED); 609 tmp->set_flag (FLAG_IDENTIFIED);
493 CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); 610 tmp->clr_flag (FLAG_KNOWN_MAGICAL);
494 } 611 }
495 612
496 /* 613 /*
497 * This entire block here tries to find variable pairings, 614 * This entire block here tries to find variable pairings,
498 * 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
500 * 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,
501 * any spaces there don't count. 618 * any spaces there don't count.
502 */ 619 */
503 while (*bp2 && bp2 <= endline) 620 while (*bp2 && bp2 <= endline)
504 { 621 {
505 bp4 = NULL;
506 gotspace = 0; 622 gotspace = 0;
507 gotquote = 0; 623 gotquote = 0;
508 624
509 /* find the first quote */ 625 /* find the first quote */
510 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) 626 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++)
570 } 686 }
571 687
572 if (at->nrof) 688 if (at->nrof)
573 { 689 {
574 if (at_spell) 690 if (at_spell)
575 tmp->insert (arch_to_object (at_spell)); 691 tmp->insert (at_spell->instance ());
576 692
577 tmp->x = op->x; 693 tmp->x = op->x;
578 tmp->y = op->y; 694 tmp->y = op->y;
579 tmp->map = op->map; 695 tmp->map = op->map;
580 696
594 { 710 {
595 object *prev = 0, *head = 0; 711 object *prev = 0, *head = 0;
596 712
597 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) 713 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
598 { 714 {
599 object *dup = arch_to_object (atmp); 715 object *dup = atmp->instance ();
600 716
601 if (at_spell) 717 if (at_spell)
602 insert_ob_in_ob (arch_to_object (at_spell), dup); 718 insert_ob_in_ob (at_spell->instance (), dup);
603 719
604 /* 720 /*
605 * The head is what contains all the important bits, 721 * The head is what contains all the important bits,
606 * so just copying it over should be fine. 722 * so just copying it over should be fine.
607 */ 723 */
622 } 738 }
623 739
624 prev = dup; 740 prev = dup;
625 } 741 }
626 742
627 if (QUERY_FLAG (head, FLAG_ALIVE)) 743 if (head->flag [FLAG_ALIVE])
628 { 744 {
629 object *check = head; 745 object *check = head;
630 int size_x = 0; 746 int size_x = 0;
631 int size_y = 0; 747 int size_y = 0;
632 748
633 while (check) 749 while (check)
634 { 750 {
635 size_x = MAX (size_x, check->arch->x); 751 size_x = max (size_x, check->arch->x);
636 size_y = MAX (size_y, check->arch->y); 752 size_y = max (size_y, check->arch->y);
637 check = check->more; 753 check = check->more;
638 } 754 }
639 755
640 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))
641 { 757 {
723 839
724 char *dump = dump_object (tmp); 840 char *dump = dump_object (tmp);
725 new_draw_info (NDI_UNIQUE, 0, op, dump); 841 new_draw_info (NDI_UNIQUE, 0, op, dump);
726 free (dump); 842 free (dump);
727 843
728 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) 844 if (tmp->flag [FLAG_OBJ_ORIGINAL])
729 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); 845 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
730 846
731 return 1; 847 return 1;
732} 848}
733 849
778 { 894 {
779 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!");
780 return 1; 896 return 1;
781 } 897 }
782 898
783 if (QUERY_FLAG (tmp, FLAG_REMOVED)) 899 if (tmp->flag [FLAG_REMOVED])
784 { 900 {
785 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));
786 return 1; 902 return 1;
787 } 903 }
788 904
832 int q; 948 int q;
833 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure 949 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
834 object *skillob = NULL; 950 object *skillob = NULL;
835 951
836 skill[0] = '\0'; 952 skill[0] = '\0';
837 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %s", buf, &i, skill)) < 2)) 953 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2))
838 { 954 {
839 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>].");
840 return 1; 956 return 1;
841 } 957 }
842 958
878/**************************************************************************/ 994/**************************************************************************/
879 995
880int 996int
881command_stats (object *op, char *params) 997command_stats (object *op, char *params)
882{ 998{
883 char thing[20];
884 char buf[MAX_BUF]; 999 char buf[MAX_BUF];
885 1000
886 thing[0] = '\0'; 1001 if (params == NULL || params[0] == '\0')
887 if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL)
888 { 1002 {
889 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 1003 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
890 return 1; 1004 return 1;
891 } 1005 }
892 1006
893 for_all_players (pl) 1007 for_all_players (pl)
894 if (!strcmp (pl->ob->name, thing)) 1008 if (!strcmp (&pl->ob->name, params))
895 { 1009 {
896 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);
897 new_draw_info (NDI_UNIQUE, 0, op, buf); 1011 new_draw_info (NDI_UNIQUE, 0, op, buf);
898 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);
899 new_draw_info (NDI_UNIQUE, 0, op, buf); 1013 new_draw_info (NDI_UNIQUE, 0, op, buf);
942 return 1; 1056 return 1;
943 } 1057 }
944 1058
945 for_all_players (pl) 1059 for_all_players (pl)
946 { 1060 {
947 if (!strcmp (pl->ob->name, thing)) 1061 if (!strcmp (&pl->ob->name, thing))
948 { 1062 {
949 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;
950 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;
951 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;
952 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;
964 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 1078 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
965 return 1; 1079 return 1;
966} 1080}
967 1081
968int 1082int
969command_nowiz (object *op, char *params)
970{ /* 'nodm' is alias */
971 CLEAR_FLAG (op, FLAG_WIZ);
972 CLEAR_FLAG (op, FLAG_WIZPASS);
973 CLEAR_FLAG (op, FLAG_WIZCAST);
974
975 if (op->contr->hidden)
976 {
977 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
978 op->map->players++;
979 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
980 op->contr->hidden = 0;
981 op->invisible = 1;
982 }
983 else
984 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
985 return 1;
986}
987
988/**
989 * object *op is trying to become dm.
990 * pl_name is name supplied by player. Restrictive DM will make it harder
991 * for socket users to become DM - in that case, it will check for the players
992 * character name.
993 */
994static int
995checkdm (object *op, const char *pl_name, const char *pl_passwd, const char *pl_host)
996{
997 FILE *dmfile;
998 char buf[MAX_BUF];
999 char line_buf[160], name[160], passwd[160], host[160];
1000
1001#ifdef RESTRICTIVE_DM
1002 *pl_name = op->name ? op->name : "*";
1003#endif
1004
1005 sprintf (buf, "%s/%s", settings.confdir, DMFILE);
1006 if ((dmfile = fopen (buf, "r")) == NULL)
1007 {
1008 LOG (llevDebug, "Could not find DM file.\n");
1009 return 0;
1010 }
1011
1012 while (fgets (line_buf, 160, dmfile) != NULL)
1013 {
1014 if (line_buf[0] == '#')
1015 continue;
1016 if (sscanf (line_buf, "%[^:]:%[^:]:%s\n", name, passwd, host) != 3)
1017 {
1018 LOG (llevError, "Warning - malformed dm file entry: %s\n", line_buf);
1019 }
1020 else if ((!strcmp (name, "*") || (pl_name && !strcmp (pl_name, name)))
1021 && (!strcmp (passwd, "*") || !strcmp (passwd, pl_passwd)) && (!strcmp (host, "*") || !strcmp (host, pl_host)))
1022 {
1023 fclose (dmfile);
1024 return (1);
1025 }
1026 }
1027 fclose (dmfile);
1028 return (0);
1029}
1030
1031int
1032do_wizard_dm (object *op, char *params, int silent)
1033{
1034 if (!op->contr)
1035 return 0;
1036
1037 if (QUERY_FLAG (op, FLAG_WIZ))
1038 {
1039 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1040 return 0;
1041 }
1042
1043 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1044 {
1045 SET_FLAG (op, FLAG_WIZ);
1046 SET_FLAG (op, FLAG_WIZPASS);
1047 SET_FLAG (op, FLAG_WIZCAST);
1048 SET_FLAG (op, FLAG_WIZLOOK);
1049
1050 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1051 op->contr->write_buf[0] = '\0';
1052
1053 if (!silent)
1054 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1055
1056 return 1;
1057 }
1058 else
1059 {
1060 new_draw_info (NDI_UNIQUE, 0, op, "Sorry Pal, I don't think so.");
1061 op->contr->write_buf[0] = '\0';
1062 return 0;
1063 }
1064}
1065
1066/*
1067 * Actual command to perhaps become dm. Changed aroun a bit in version 0.92.2
1068 * - allow people on sockets to become dm, and allow better dm file
1069 */
1070int
1071command_dm (object *op, char *params)
1072{
1073 if (!op->contr)
1074 return 0;
1075
1076 do_wizard_dm (op, params, 0);
1077
1078 return 1;
1079}
1080
1081int
1082command_invisible (object *op, char *params) 1083command_invisible (object *op, char *params)
1083{ 1084{
1084 if (op) 1085 if (op)
1085 { 1086 {
1086 op->invisible += 100; 1087 op->invisible += TIME2TICK (60);
1087 update_object (op, UP_OBJ_CHANGE); 1088 update_object (op, UP_OBJ_CHANGE);
1088 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); 1089 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible.");
1089 } 1090 }
1090 1091
1091 return 0; 1092 return 0;
1095 * Returns spell object (from archetypes) by name. 1096 * Returns spell object (from archetypes) by name.
1096 * Returns NULL if 0 or more than one spell matches. 1097 * Returns NULL if 0 or more than one spell matches.
1097 * Used for wizard's learn spell/prayer. 1098 * Used for wizard's learn spell/prayer.
1098 * 1099 *
1099 * op is the player issuing the command. 1100 * op is the player issuing the command.
1100 *
1101 * Ignores archetypes "spelldirect_xxx" since these archetypes are not used
1102 * anymore (but may still be present in some player's inventories and thus
1103 * cannot be removed). We have to ignore them here since they have the same
1104 * name than other "spell_xxx" archetypes and would always conflict.
1105 */ 1101 */
1106static object * 1102static object *
1107get_spell_by_name (object *op, const char *spell_name) 1103get_spell_by_name (object *op, shstr_cmp spell_name)
1108{ 1104{
1109 archetype *at;
1110 archetype *found;
1111 int conflict_found;
1112 size_t spell_name_length;
1113
1114 /* First check for full name matches. */ 1105 /* First check for full name matches. */
1115 conflict_found = 0; 1106 int conflict_found = 0;
1116 found = NULL; 1107 archetype *found = 0;
1108
1117 for_all_archetypes (at) 1109 for_all_archetypes (at)
1118 { 1110 {
1119 if (at->type != SPELL) 1111 if (at->type != SPELL)
1120 continue; 1112 continue;
1121 1113
1122 if (strncmp (at->archname, "spelldirect_", 12) == 0) 1114 if (at->object::name != spell_name)
1123 continue; 1115 continue;
1124 1116
1125 if (strcmp (at->object::name, spell_name) != 0)
1126 continue;
1127
1128 if (found != NULL) 1117 if (found)
1129 { 1118 {
1130 if (!conflict_found) 1119 if (!conflict_found)
1131 { 1120 {
1132 conflict_found = 1; 1121 conflict_found = 1;
1133 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);
1134 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); 1123 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1135 } 1124 }
1136 1125
1137 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); 1126 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1138 continue; 1127 return 0;
1139 } 1128 }
1140 1129
1141 found = at; 1130 found = at;
1142 } 1131 }
1143 1132
1144 /* No match if more more than one archetype matches. */
1145 if (conflict_found)
1146 return NULL;
1147
1148 /* Return if exactly one archetype matches. */ 1133 /* Return if exactly one archetype matches. */
1149 if (found != NULL) 1134 if (found)
1150 return arch_to_object (found); 1135 return found->instance ();
1151
1152 /* No full match found: now check for partial matches. */
1153 spell_name_length = strlen (spell_name);
1154 conflict_found = 0;
1155 found = NULL;
1156 for_all_archetypes (at)
1157 {
1158 if (at->type != SPELL)
1159 continue;
1160
1161 if (strncmp (at->archname, "spelldirect_", 12) == 0)
1162 continue;
1163
1164 if (strncmp (at->object::name, spell_name, spell_name_length) != 0)
1165 continue;
1166
1167 if (found != NULL)
1168 {
1169 if (!conflict_found)
1170 {
1171 conflict_found = 1;
1172 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name);
1173 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->object::name);
1174 }
1175 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->object::name);
1176 continue;
1177 }
1178
1179 found = at;
1180 }
1181
1182 /* No match if more more than one archetype matches. */
1183 if (conflict_found)
1184 return NULL;
1185
1186 /* Return if exactly one archetype matches. */
1187 if (found != NULL)
1188 return arch_to_object (found);
1189 1136
1190 /* No spell found: just print an error message. */ 1137 /* No spell found: just print an error message. */
1191 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
1192 return NULL; 1140 return 0;
1193} 1141}
1194 1142
1195static int 1143static int
1196command_learn_spell_or_prayer (object *op, char *params, int special_prayer) 1144command_learn_spell_or_prayer (object *op, char *params, int special_prayer)
1197{ 1145{
1241 { 1189 {
1242 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?");
1243 return 0; 1191 return 0;
1244 } 1192 }
1245 1193
1246 spell = lookup_spell_by_name (op, params); 1194 spell = op->find_spell (params);
1247 if (spell == NULL) 1195 if (spell == NULL)
1248 { 1196 {
1249 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);
1250 return 0; 1198 return 0;
1251 } 1199 }
1252 1200
1253 do_forget_spell (op, spell->name); 1201 do_forget_spell (op, spell->name);
1254 return 1; 1202 return 1;
1255}
1256
1257/**
1258 * A players wants to become DM and hide.
1259 * Let's see if that's authorized.
1260 * Make sure to not tell anything to anyone.
1261 */
1262int
1263command_dmhide (object *op, char *params)
1264{
1265 if (!do_wizard_dm (op, params, 1))
1266 return 0;
1267
1268 do_wizard_hide (op, 1);
1269
1270 return 1;
1271}
1272
1273void
1274dm_stack_pop (player *pl)
1275{
1276 if (!pl->stack_items || !pl->stack_position)
1277 {
1278 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1279 return;
1280 }
1281
1282 pl->stack_position--;
1283 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
1284}
1285
1286/**
1287 * Get current stack top item for player.
1288 * Returns NULL if no stacked item.
1289 * If stacked item disappeared (freed), remove it.
1290 *
1291 * Ryo, august 2004
1292 */
1293object *
1294dm_stack_peek (player *pl)
1295{
1296 object *ob;
1297
1298 if (!pl->stack_position)
1299 {
1300 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1301 return NULL;
1302 }
1303
1304 ob = find_object (pl->stack_items[pl->stack_position - 1]);
1305 if (!ob)
1306 {
1307 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
1308 dm_stack_pop (pl);
1309 return NULL;
1310 }
1311
1312 return ob;
1313}
1314
1315/**
1316 * Push specified item on player stack.
1317 * Inform player of position.
1318 * Initializes variables if needed.
1319 */
1320void
1321dm_stack_push (player *pl, tag_t item)
1322{
1323 if (!pl->stack_items)
1324 {
1325 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
1326 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
1327 }
1328
1329 if (pl->stack_position == STACK_SIZE)
1330 {
1331 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
1332 return;
1333 }
1334
1335 pl->stack_items[pl->stack_position] = item;
1336 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
1337 pl->stack_position++;
1338}
1339
1340/**
1341 * Checks 'params' for object code.
1342 *
1343 * Can be:
1344 * * empty => get current object stack top for player
1345 * * number => get item with that tag, stack it for future use
1346 * * $number => get specified stack item
1347 * * "me" => player himself
1348 *
1349 * At function exit, params points to first non-object char
1350 *
1351 * 'from', if not NULL, contains at exit:
1352 * * STACK_FROM_NONE => object not found
1353 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
1354 * * STACK_FROM_STACK => item from somewhere in the stack
1355 * * STACK_FROM_NUMBER => item by number, pushed on stack
1356 *
1357 * Ryo, august 2004
1358 */
1359object *
1360get_dm_object (player *pl, char **params, int *from)
1361{
1362 int item_tag, item_position;
1363 object *ob;
1364
1365 if (!pl)
1366 return NULL;
1367
1368 if (!params || !*params || **params == '\0')
1369 {
1370 if (from)
1371 *from = STACK_FROM_TOP;
1372 /* No parameter => get stack item */
1373 return dm_stack_peek (pl);
1374 }
1375
1376 /* Let's clean white spaces */
1377 while (**params == ' ')
1378 (*params)++;
1379
1380 /* Next case: number => item tag */
1381 if (sscanf (*params, "%d", &item_tag))
1382 {
1383 /* Move parameter to next item */
1384 while (isdigit (**params))
1385 (*params)++;
1386
1387 /* And skip blanks, too */
1388 while (**params == ' ')
1389 (*params)++;
1390
1391 /* Get item */
1392 ob = find_object (item_tag);
1393 if (!ob)
1394 {
1395 if (from)
1396 *from = STACK_FROM_NONE;
1397 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
1398 return NULL;
1399 }
1400
1401 /* Got one, let's push it on stack */
1402 dm_stack_push (pl, item_tag);
1403 if (from)
1404 *from = STACK_FROM_NUMBER;
1405 return ob;
1406 }
1407
1408 /* Next case: $number => stack item */
1409 if (sscanf (*params, "$%d", &item_position))
1410 {
1411 /* Move parameter to next item */
1412 (*params)++;
1413
1414 while (isdigit (**params))
1415 (*params)++;
1416 while (**params == ' ')
1417 (*params)++;
1418
1419 if (item_position >= pl->stack_position)
1420 {
1421 if (from)
1422 *from = STACK_FROM_NONE;
1423 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
1424 return NULL;
1425 }
1426
1427 ob = find_object (pl->stack_items[item_position]);
1428 if (!ob)
1429 {
1430 if (from)
1431 *from = STACK_FROM_NONE;
1432 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
1433 return NULL;
1434 }
1435
1436 if (from)
1437 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
1438 return ob;
1439 }
1440
1441 /* Next case: 'me' => return pl->ob */
1442 if (!strncmp (*params, "me", 2))
1443 {
1444 if (from)
1445 *from = STACK_FROM_NUMBER;
1446 dm_stack_push (pl, pl->ob->count);
1447
1448 /* Skip to next token */
1449 (*params) += 2;
1450 while (**params == ' ')
1451 (*params)++;
1452
1453 return pl->ob;
1454 }
1455
1456 /* Last case: get stack top */
1457 if (from)
1458 *from = STACK_FROM_TOP;
1459 return dm_stack_peek (pl);
1460} 1203}
1461 1204
1462/** 1205/**
1463 * Pop the stack top. 1206 * Pop the stack top.
1464 */ 1207 */
1524} 1267}
1525 1268
1526int 1269int
1527command_insert_into (object *op, char *params) 1270command_insert_into (object *op, char *params)
1528{ 1271{
1529 object *left, *right, *inserted; 1272 object *left, *right;
1530 int left_from, right_from; 1273 int left_from, right_from;
1531 1274
1532 left = get_dm_object (op->contr, &params, &left_from); 1275 left = get_dm_object (op->contr, &params, &left_from);
1533 if (!left) 1276 if (!left)
1534 { 1277 {
1577 { 1320 {
1578 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!");
1579 return 0; 1322 return 0;
1580 } 1323 }
1581 1324
1582 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1325 if (!right->flag [FLAG_REMOVED])
1583 right->remove (); 1326 right->remove ();
1584 1327
1585 insert_ob_in_ob (right, left); 1328 object *inserted = insert_ob_in_ob (right, left);
1586 1329
1587 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));
1588 1331
1589 return 0; 1332 return 0;
1590 1333

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines