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