1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
* Copyright (©) 1992 Frank Tore Johansen |
7 |
* |
8 |
* Deliantra is free software: you can redistribute it and/or modify it under |
9 |
* the terms of the Affero GNU General Public License as published by the |
10 |
* Free Software Foundation, either version 3 of the License, or (at your |
11 |
* 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 Affero GNU General Public License |
19 |
* and the GNU General Public License along with this program. If not, see |
20 |
* <http://www.gnu.org/licenses/>. |
21 |
* |
22 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
*/ |
24 |
|
25 |
#include <global.h> |
26 |
#include <sproto.h> |
27 |
#include <spells.h> |
28 |
#include <treasure.h> |
29 |
#include <skills.h> |
30 |
|
31 |
/** Defines for DM item stack **/ |
32 |
#define STACK_SIZE 50 /* Stack size, static */ |
33 |
|
34 |
/* Values for 'from' field of get_dm_object */ |
35 |
#define STACK_FROM_NONE 0 /* Item was not found */ |
36 |
#define STACK_FROM_TOP 1 /* Item is stack top */ |
37 |
#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ |
38 |
#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ |
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 |
static void |
76 |
dm_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 |
*/ |
95 |
static object * |
96 |
dm_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 |
*/ |
122 |
void |
123 |
dm_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 |
*/ |
161 |
static object * |
162 |
get_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 |
|
264 |
/** |
265 |
* This finds and returns the object which matches the name or |
266 |
* object nubmer (specified via num #whatever). |
267 |
*/ |
268 |
static object * |
269 |
find_object_both (char *params) |
270 |
{ |
271 |
if (!params) |
272 |
return NULL; |
273 |
|
274 |
if (params[0] == '#') |
275 |
return find_object (atol (params + 1)); |
276 |
else |
277 |
return find_object_name (params); |
278 |
} |
279 |
|
280 |
/** |
281 |
* Sets the god for some objects. params should contain two values - |
282 |
* first the object to change, followed by the god to change it to. |
283 |
*/ |
284 |
int |
285 |
command_setgod (object *op, char *params) |
286 |
{ |
287 |
object *ob, *god; |
288 |
char *str; |
289 |
|
290 |
if (!params || !(str = strchr (params, ' '))) |
291 |
{ |
292 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: setgod object god"); |
293 |
return 0; |
294 |
} |
295 |
|
296 |
/* kill the space, and set string to the next param */ |
297 |
*str++ = '\0'; |
298 |
if (!(ob = find_object_both (params))) |
299 |
{ |
300 |
new_draw_info_format (NDI_UNIQUE, 0, op, "Set whose god - can not find object %s?", params); |
301 |
return 1; |
302 |
} |
303 |
|
304 |
/* |
305 |
* Perhaps this is overly restrictive? Should we perhaps be able |
306 |
* to rebless altars and the like? |
307 |
*/ |
308 |
if (ob->type != PLAYER) |
309 |
{ |
310 |
new_draw_info_format (NDI_UNIQUE, 0, op, "%s is not a player - can not change its god", &ob->name); |
311 |
return 1; |
312 |
} |
313 |
|
314 |
god = find_god (str); |
315 |
if (god == NULL) |
316 |
{ |
317 |
new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); |
318 |
return 1; |
319 |
} |
320 |
|
321 |
ob->become_follower (god); |
322 |
return 1; |
323 |
} |
324 |
|
325 |
int |
326 |
command_freeze (object *op, char *params) |
327 |
{ |
328 |
int ticks; |
329 |
player *pl; |
330 |
|
331 |
if (!params) |
332 |
{ |
333 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: freeze [ticks] <player>."); |
334 |
return 1; |
335 |
} |
336 |
|
337 |
ticks = atoi (params); |
338 |
if (ticks) |
339 |
{ |
340 |
while ((isdigit (*params) || isspace (*params)) && *params != 0) |
341 |
params++; |
342 |
if (*params == 0) |
343 |
{ |
344 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: freeze [ticks] <player>."); |
345 |
return 1; |
346 |
} |
347 |
} |
348 |
else |
349 |
ticks = 100; |
350 |
|
351 |
pl = get_other_player_from_name (op, params); |
352 |
if (!pl) |
353 |
return 1; |
354 |
|
355 |
new_draw_info (NDI_UNIQUE | NDI_RED, 0, pl->ob, "You have been frozen by the DM!"); |
356 |
new_draw_info_format (NDI_UNIQUE, 0, op, "You freeze %s for %d ticks", &pl->ob->name, ticks); |
357 |
pl->ob->speed_left = -(pl->ob->speed * ticks); |
358 |
return 0; |
359 |
} |
360 |
|
361 |
int |
362 |
command_arrest (object *op, char *params) |
363 |
{ |
364 |
object *dummy; |
365 |
player *pl; |
366 |
|
367 |
if (!op) |
368 |
return 0; |
369 |
|
370 |
if (params == NULL) |
371 |
{ |
372 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: arrest <player>."); |
373 |
return 1; |
374 |
} |
375 |
|
376 |
pl = get_other_player_from_name (op, params); |
377 |
if (!pl) |
378 |
return 1; |
379 |
|
380 |
dummy = get_jail_exit (pl->ob); |
381 |
if (!dummy) |
382 |
{ |
383 |
/* we have nowhere to send the prisoner.... */ |
384 |
new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); |
385 |
return 0; |
386 |
} |
387 |
|
388 |
pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO |
389 |
dummy->destroy (); |
390 |
|
391 |
new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); |
392 |
new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
393 |
LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); |
394 |
return 1; |
395 |
} |
396 |
|
397 |
int |
398 |
command_summon (object *op, char *params) |
399 |
{ |
400 |
int i; |
401 |
player *pl; |
402 |
|
403 |
if (!op) |
404 |
return 0; |
405 |
|
406 |
if (params == NULL) |
407 |
{ |
408 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: summon <player>."); |
409 |
return 1; |
410 |
} |
411 |
|
412 |
pl = get_other_player_from_name (op, params); |
413 |
if (!pl) |
414 |
return 1; |
415 |
|
416 |
maptile *m = op->map; |
417 |
sint16 nx = op->x; |
418 |
sint16 ny = op->y; |
419 |
|
420 |
i = find_free_spot (op, m, nx, ny, 1, SIZEOFFREE1+1); |
421 |
if (i == -1) |
422 |
{ |
423 |
new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
424 |
return 1; |
425 |
} |
426 |
|
427 |
nx += freearr_x [i]; |
428 |
ny += freearr_y [i]; |
429 |
|
430 |
if (!xy_normalise (m, nx, ny)) |
431 |
{ |
432 |
new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
433 |
return 1; |
434 |
} |
435 |
|
436 |
pl->ob->player_goto (m->path, nx, ny); |
437 |
new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
438 |
new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
439 |
|
440 |
return 1; |
441 |
} |
442 |
|
443 |
/** |
444 |
* This function is a real mess, because we're stucking getting |
445 |
* the entire item description in one block of text, so we just |
446 |
* can't simply parse it - we need to look for double quotes |
447 |
* for example. This could actually get much simpler with just a |
448 |
* little help from the client - if we could get line breaks, it |
449 |
* makes parsing much easier, eg, something like: |
450 |
* arch dragon |
451 |
* name big nasty creature |
452 |
* hp 5 |
453 |
* sp 30 |
454 |
* Is much easier to parse than |
455 |
* dragon name "big nasty creature" hp 5 sp 30 |
456 |
* for example. |
457 |
*/ |
458 |
int |
459 |
command_create (object *op, char *params) |
460 |
{ |
461 |
object *tmp = NULL; |
462 |
int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
463 |
char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline; |
464 |
archetype *at, *at_spell = NULL; |
465 |
artifact *art = NULL; |
466 |
|
467 |
if (!op) |
468 |
return 0; |
469 |
|
470 |
if (params == NULL) |
471 |
{ |
472 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]"); |
473 |
return 1; |
474 |
} |
475 |
|
476 |
bp = params; |
477 |
|
478 |
/* We need to know where the line ends */ |
479 |
endline = bp + strlen (bp); |
480 |
|
481 |
if (sscanf (bp, "%d ", &nrof)) |
482 |
{ |
483 |
if ((bp = strchr (params, ' ')) == NULL) |
484 |
{ |
485 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]"); |
486 |
return 1; |
487 |
} |
488 |
bp++; |
489 |
set_nrof = 1; |
490 |
LOG (llevDebug, "%s creates: (%d) %s\n", &op->name, nrof, bp); |
491 |
} |
492 |
|
493 |
if (sscanf (bp, "%d ", &magic)) |
494 |
{ |
495 |
if ((bp = strchr (bp, ' ')) == NULL) |
496 |
{ |
497 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]"); |
498 |
return 1; |
499 |
} |
500 |
|
501 |
bp++; |
502 |
set_magic = 1; |
503 |
LOG (llevDebug, "%s creates: (%d) (%d) %s\n", &op->name, nrof, magic, bp); |
504 |
} |
505 |
|
506 |
if ((cp = strstr (bp, " of ")) != NULL) |
507 |
{ |
508 |
*cp = '\0'; |
509 |
cp += 4; |
510 |
} |
511 |
|
512 |
for (bp2 = bp; *bp2; bp2++) |
513 |
{ |
514 |
if (*bp2 == ' ') |
515 |
{ |
516 |
*bp2 = '\0'; |
517 |
bp2++; |
518 |
break; |
519 |
} |
520 |
} |
521 |
|
522 |
if ((at = archetype::find (bp)) == NULL) |
523 |
{ |
524 |
new_draw_info (NDI_UNIQUE, 0, op, "No such archetype."); |
525 |
return 1; |
526 |
} |
527 |
|
528 |
if (cp) |
529 |
{ |
530 |
char spell_name[MAX_BUF], *fsp = NULL; |
531 |
|
532 |
/* |
533 |
* Try to find a spell object for this. Note that |
534 |
* we also set up spell_name which is only |
535 |
* the first word. |
536 |
*/ |
537 |
|
538 |
at_spell = archetype::find (cp); |
539 |
if (!at_spell || at_spell->type != SPELL) |
540 |
at_spell = find_archetype_by_object_name (cp); |
541 |
if (!at_spell || at_spell->type != SPELL) |
542 |
{ |
543 |
assign (spell_name, cp); |
544 |
fsp = strchr (spell_name, ' '); |
545 |
if (fsp) |
546 |
{ |
547 |
*fsp = 0; |
548 |
fsp++; |
549 |
at_spell = archetype::find (spell_name); |
550 |
|
551 |
/* Got a spell, update the first string pointer */ |
552 |
if (at_spell && at_spell->type == SPELL) |
553 |
bp2 = cp + strlen (spell_name) + 1; |
554 |
else |
555 |
at_spell = NULL; |
556 |
} |
557 |
} |
558 |
|
559 |
/* OK - we didn't find a spell - presume the 'of' |
560 |
* in this case means its an artifact. |
561 |
*/ |
562 |
if (!at_spell) |
563 |
{ |
564 |
if (find_artifactlist (at->type) == NULL) |
565 |
new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->type); |
566 |
else |
567 |
{ |
568 |
art = find_artifactlist (at->type)->items; |
569 |
|
570 |
while (art) |
571 |
{ |
572 |
if (!strcmp (&art->item->name, cp)) |
573 |
break; |
574 |
|
575 |
art = art->next; |
576 |
} |
577 |
|
578 |
if (!art) |
579 |
new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->type, cp); |
580 |
} |
581 |
|
582 |
LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp); |
583 |
} |
584 |
} /* if cp */ |
585 |
|
586 |
if ((at->type == ROD || at->type == WAND || at->type == SCROLL || |
587 |
at->type == HORN || at->type == SPELLBOOK) && !at_spell) |
588 |
{ |
589 |
new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find spell %s for object that needs it, or it is of wrong type", cp); |
590 |
return 1; |
591 |
} |
592 |
|
593 |
/* |
594 |
* Rather than have two different blocks with a lot of similar code, |
595 |
* just create one object, do all the processing, and then determine |
596 |
* if that one object should be inserted or if we need to make copies. |
597 |
*/ |
598 |
tmp = at->instance (); |
599 |
|
600 |
if (set_magic) |
601 |
set_abs_magic (tmp, magic); |
602 |
|
603 |
if (art) |
604 |
give_artifact_abilities (tmp, art->item); |
605 |
|
606 |
if (tmp->need_identify ()) |
607 |
{ |
608 |
tmp->set_flag (FLAG_IDENTIFIED); |
609 |
tmp->clr_flag (FLAG_KNOWN_MAGICAL); |
610 |
} |
611 |
|
612 |
/* |
613 |
* This entire block here tries to find variable pairings, |
614 |
* eg, 'hp 4' or the like. The mess here is that values |
615 |
* can be quoted (eg "my cool sword"); So the basic logic |
616 |
* is we want to find two spaces, but if we got a quote, |
617 |
* any spaces there don't count. |
618 |
*/ |
619 |
while (*bp2 && bp2 <= endline) |
620 |
{ |
621 |
gotspace = 0; |
622 |
gotquote = 0; |
623 |
|
624 |
/* find the first quote */ |
625 |
for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) |
626 |
{ |
627 |
|
628 |
/* Found a quote - now lets find the second one */ |
629 |
if (*bp3 == '"') |
630 |
{ |
631 |
*bp3 = ' '; |
632 |
bp2 = bp3 + 1; /* Update start of string */ |
633 |
bp3++; |
634 |
gotquote++; |
635 |
while (*bp3) |
636 |
{ |
637 |
if (*bp3 == '"') |
638 |
{ |
639 |
*bp3 = '\0'; |
640 |
gotquote++; |
641 |
} |
642 |
else |
643 |
bp3++; |
644 |
} |
645 |
} |
646 |
else if (*bp3 == ' ') |
647 |
gotspace++; |
648 |
} |
649 |
|
650 |
/* |
651 |
* If we got two spaces, send the second one to null. |
652 |
* if we've reached the end of the line, increase gotspace - |
653 |
* this is perfectly valid for the list entry listed. |
654 |
*/ |
655 |
if (gotspace == 2 || gotquote == 2) |
656 |
{ |
657 |
bp3--; /* Undo the extra increment */ |
658 |
*bp3 = '\0'; |
659 |
} |
660 |
else if (*bp3 == '\0') |
661 |
gotspace++; |
662 |
|
663 |
if ((gotquote && gotquote != 2) || (gotspace != 2 && gotquote != 2)) |
664 |
{ |
665 |
/* |
666 |
* Unfortunately, we've clobbered lots of values, so printing |
667 |
* out what we have probably isn't useful. Break out, because |
668 |
* trying to recover is probably won't get anything useful |
669 |
* anyways, and we'd be confused about end of line pointers |
670 |
* anyways. |
671 |
*/ |
672 |
new_draw_info_format (NDI_UNIQUE, 0, op, "Malformed create line: %s", bp2); |
673 |
break; |
674 |
} |
675 |
|
676 |
/* bp2 should still point to the start of this line, |
677 |
* with bp3 pointing to the end |
678 |
*/ |
679 |
if (set_variable (tmp, bp2) == -1) |
680 |
new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", bp2); |
681 |
else |
682 |
new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2); |
683 |
|
684 |
bp2 = bp3 + 1; |
685 |
} |
686 |
|
687 |
if (at->nrof) |
688 |
{ |
689 |
if (at_spell) |
690 |
tmp->insert (at_spell->instance ()); |
691 |
|
692 |
tmp->x = op->x; |
693 |
tmp->y = op->y; |
694 |
tmp->map = op->map; |
695 |
|
696 |
if (set_nrof) |
697 |
tmp->nrof = nrof; |
698 |
|
699 |
op->insert (tmp); |
700 |
|
701 |
/* Let's put this created item on stack so dm can access it easily. */ |
702 |
dm_stack_push (op->contr, tmp->count); |
703 |
|
704 |
return 1; |
705 |
} |
706 |
else |
707 |
{ |
708 |
for (i = 0; i < (set_nrof ? nrof : 1); i++) |
709 |
{ |
710 |
object *prev = 0, *head = 0; |
711 |
|
712 |
for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
713 |
{ |
714 |
object *dup = atmp->instance (); |
715 |
|
716 |
if (at_spell) |
717 |
insert_ob_in_ob (at_spell->instance (), dup); |
718 |
|
719 |
/* |
720 |
* The head is what contains all the important bits, |
721 |
* so just copying it over should be fine. |
722 |
*/ |
723 |
if (!head) |
724 |
{ |
725 |
head = dup; |
726 |
tmp->copy_to (dup); |
727 |
} |
728 |
|
729 |
dup->x = op->x + dup->arch->x; |
730 |
dup->y = op->y + dup->arch->y; |
731 |
dup->map = op->map; |
732 |
|
733 |
if (head != dup) |
734 |
{ |
735 |
dup->head = head; |
736 |
prev->more = dup; |
737 |
} |
738 |
|
739 |
prev = dup; |
740 |
} |
741 |
|
742 |
if (head->flag [FLAG_ALIVE]) |
743 |
{ |
744 |
object *check = head; |
745 |
int size_x = 0; |
746 |
int size_y = 0; |
747 |
|
748 |
while (check) |
749 |
{ |
750 |
size_x = max (size_x, check->arch->x); |
751 |
size_y = max (size_y, check->arch->y); |
752 |
check = check->more; |
753 |
} |
754 |
|
755 |
if (out_of_map (op->map, head->x + size_x, head->y + size_y)) |
756 |
{ |
757 |
if (head->x < size_x || head->y < size_y) |
758 |
{ |
759 |
dm_stack_pop (op->contr); |
760 |
head->destroy (); |
761 |
new_draw_info (NDI_UNIQUE, 0, op, "Object too big to insert in map, or wrong position."); |
762 |
tmp->destroy (); |
763 |
return 1; |
764 |
} |
765 |
|
766 |
check = head; |
767 |
|
768 |
while (check) |
769 |
{ |
770 |
check->x -= size_x; |
771 |
check->y -= size_y; |
772 |
check = check->more; |
773 |
} |
774 |
} |
775 |
|
776 |
insert_ob_in_map (head, op->map, op, 0); |
777 |
} |
778 |
else |
779 |
head = insert_ob_in_ob (head, op); |
780 |
|
781 |
/* Let's put this created item on stack so dm can access it easily. */ |
782 |
/* Wonder if we really want to push all of these, but since |
783 |
* things like rods have nrof 0, we want to cover those. |
784 |
*/ |
785 |
dm_stack_push (op->contr, head->count); |
786 |
|
787 |
if (at->randomitems && !at_spell) |
788 |
create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0); |
789 |
} |
790 |
|
791 |
/* free the one we used to copy */ |
792 |
tmp->destroy (); |
793 |
} |
794 |
|
795 |
return 1; |
796 |
} |
797 |
|
798 |
/* |
799 |
* Now follows dm-commands which are also acceptable from sockets |
800 |
*/ |
801 |
|
802 |
int |
803 |
command_inventory (object *op, char *params) |
804 |
{ |
805 |
int i; |
806 |
object *tmp; |
807 |
|
808 |
if (!params || !sscanf (params, "%d", &i) || !(tmp = find_object (i))) |
809 |
{ |
810 |
op->contr->failmsg ("Inventory of what object (nr)?"); |
811 |
return 1; |
812 |
} |
813 |
|
814 |
op->contr->infobox (MSG_CHANNEL ("examine"), tmp->query_inventory (op)); |
815 |
|
816 |
return 1; |
817 |
} |
818 |
|
819 |
/* just show player's their skills for now. Dm's can |
820 |
* already see skills w/ inventory command - b.t. |
821 |
*/ |
822 |
|
823 |
int |
824 |
command_skills (object *op, char *params) |
825 |
{ |
826 |
show_skills (op, params); |
827 |
return 0; |
828 |
} |
829 |
|
830 |
int |
831 |
command_dump (object *op, char *params) |
832 |
{ |
833 |
object *tmp; |
834 |
|
835 |
tmp = get_dm_object (op->contr, ¶ms, NULL); |
836 |
if (!tmp) |
837 |
return 1; |
838 |
|
839 |
char *dump = dump_object (tmp); |
840 |
new_draw_info (NDI_UNIQUE, 0, op, dump); |
841 |
free (dump); |
842 |
|
843 |
if (tmp->flag [FLAG_OBJ_ORIGINAL]) |
844 |
new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); |
845 |
|
846 |
return 1; |
847 |
} |
848 |
|
849 |
int |
850 |
command_patch (object *op, char *params) |
851 |
{ |
852 |
char *arg, *arg2; |
853 |
object *tmp; |
854 |
|
855 |
tmp = get_dm_object (op->contr, ¶ms, NULL); |
856 |
if (!tmp) |
857 |
/* Player already informed of failure */ |
858 |
return 1; |
859 |
|
860 |
/* params set to first value by get_dm_default */ |
861 |
arg = params; |
862 |
if (arg == NULL) |
863 |
{ |
864 |
new_draw_info (NDI_UNIQUE, 0, op, "Patch what values?"); |
865 |
return 1; |
866 |
} |
867 |
|
868 |
if ((arg2 = strchr (arg, ' '))) |
869 |
arg2++; |
870 |
|
871 |
if (set_variable (tmp, arg) == -1) |
872 |
new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", arg); |
873 |
else |
874 |
new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s=%s", &tmp->name, tmp->count, arg, arg2); |
875 |
|
876 |
return 1; |
877 |
} |
878 |
|
879 |
int |
880 |
command_remove (object *op, char *params) |
881 |
{ |
882 |
object *tmp; |
883 |
int from; |
884 |
|
885 |
tmp = get_dm_object (op->contr, ¶ms, &from); |
886 |
if (!tmp) |
887 |
{ |
888 |
new_draw_info (NDI_UNIQUE, 0, op, "Remove what object (nr)?"); |
889 |
return 1; |
890 |
} |
891 |
|
892 |
if (tmp->type == PLAYER) |
893 |
{ |
894 |
new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
895 |
return 1; |
896 |
} |
897 |
|
898 |
if (tmp->flag [FLAG_REMOVED]) |
899 |
{ |
900 |
new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); |
901 |
return 1; |
902 |
} |
903 |
|
904 |
if (from != STACK_FROM_STACK) |
905 |
/* Item is either stack top, or is a number thus is now stack top, let's remove it */ |
906 |
dm_stack_pop (op->contr); |
907 |
|
908 |
/* Always work on the head - otherwise object will get in odd state */ |
909 |
if (tmp->head) |
910 |
tmp = tmp->head; |
911 |
tmp->remove (); |
912 |
return 1; |
913 |
} |
914 |
|
915 |
int |
916 |
command_free (object *op, char *params) |
917 |
{ |
918 |
object *tmp; |
919 |
int from; |
920 |
|
921 |
tmp = get_dm_object (op->contr, ¶ms, &from); |
922 |
|
923 |
if (!tmp) |
924 |
{ |
925 |
new_draw_info (NDI_UNIQUE, 0, op, "Free what object (nr)?"); |
926 |
return 1; |
927 |
} |
928 |
|
929 |
if (from != STACK_FROM_STACK) |
930 |
/* Item is either stack top, or is a number thus is now stack top, let's remove it */ |
931 |
dm_stack_pop (op->contr); |
932 |
|
933 |
if (tmp->head) |
934 |
tmp = tmp->head; |
935 |
|
936 |
tmp->destroy (); |
937 |
return 1; |
938 |
} |
939 |
|
940 |
/** |
941 |
* This adds exp to a player. We now allow adding to a specific skill. |
942 |
*/ |
943 |
int |
944 |
command_addexp (object *op, char *params) |
945 |
{ |
946 |
char buf[MAX_BUF], skill[MAX_BUF]; |
947 |
int q; |
948 |
long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure |
949 |
object *skillob = NULL; |
950 |
|
951 |
skill[0] = '\0'; |
952 |
if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2)) |
953 |
{ |
954 |
new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); |
955 |
return 1; |
956 |
} |
957 |
|
958 |
for_all_players (pl) |
959 |
if (!strncmp (pl->ob->name, buf, MAX_NAME)) |
960 |
{ |
961 |
if (q >= 3) |
962 |
{ |
963 |
skillob = find_skill_by_name (pl->ob, skill); |
964 |
if (!skillob) |
965 |
{ |
966 |
new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s in %s", skill, buf); |
967 |
return 1; |
968 |
} |
969 |
|
970 |
i = check_exp_adjust (skillob, i); |
971 |
skillob->stats.exp += i; |
972 |
calc_perm_exp (skillob); |
973 |
player_lvl_adj (pl->ob, skillob); |
974 |
} |
975 |
|
976 |
pl->ob->stats.exp += i; |
977 |
calc_perm_exp (pl->ob); |
978 |
player_lvl_adj (pl->ob, NULL); |
979 |
|
980 |
return 1; |
981 |
} |
982 |
|
983 |
new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
984 |
return 1; |
985 |
} |
986 |
|
987 |
/**************************************************************************/ |
988 |
|
989 |
/* Mods made by Tyler Van Gorder, May 10-13, 1992. */ |
990 |
|
991 |
/* CSUChico : tvangod@cscihp.ecst.csuchico.edu */ |
992 |
|
993 |
/**************************************************************************/ |
994 |
|
995 |
int |
996 |
command_stats (object *op, char *params) |
997 |
{ |
998 |
char buf[MAX_BUF]; |
999 |
|
1000 |
if (params == NULL || params[0] == '\0') |
1001 |
{ |
1002 |
new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
1003 |
return 1; |
1004 |
} |
1005 |
|
1006 |
for_all_players (pl) |
1007 |
if (!strcmp (&pl->ob->name, params)) |
1008 |
{ |
1009 |
sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
1010 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1011 |
sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
1012 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1013 |
sprintf (buf, "Con : %-2d AC : %-4d WC : %d", pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc); |
1014 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1015 |
sprintf (buf, "Int : %-2d Damage : %d", pl->ob->stats.Int, pl->ob->stats.dam); |
1016 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1017 |
sprintf (buf, "Wis : %-2d EXP : %" PRId64, pl->ob->stats.Wis, pl->ob->stats.exp); |
1018 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1019 |
sprintf (buf, "Pow : %-2d Grace : %d", pl->ob->stats.Pow, pl->ob->stats.grace); |
1020 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1021 |
sprintf (buf, "Cha : %-2d Food : %d", pl->ob->stats.Cha, pl->ob->stats.food); |
1022 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1023 |
return 1; |
1024 |
} |
1025 |
|
1026 |
new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
1027 |
return 1; |
1028 |
} |
1029 |
|
1030 |
int |
1031 |
command_abil (object *op, char *params) |
1032 |
{ |
1033 |
char thing[20], thing2[20]; |
1034 |
int iii; |
1035 |
char buf[MAX_BUF]; |
1036 |
|
1037 |
iii = 0; |
1038 |
thing[0] = '\0'; |
1039 |
thing2[0] = '\0'; |
1040 |
if (params == NULL || !sscanf (params, "%s %s %d", thing, thing2, &iii) || thing == NULL) |
1041 |
{ |
1042 |
new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
1043 |
return 1; |
1044 |
} |
1045 |
|
1046 |
if (thing2 == NULL) |
1047 |
{ |
1048 |
new_draw_info (NDI_UNIQUE, 0, op, "You can't change that."); |
1049 |
return 1; |
1050 |
} |
1051 |
|
1052 |
if (iii < MIN_STAT || iii > MAX_STAT) |
1053 |
{ |
1054 |
new_draw_info (NDI_UNIQUE, 0, op, "Illegal range of stat.\n"); |
1055 |
return 1; |
1056 |
} |
1057 |
|
1058 |
for_all_players (pl) |
1059 |
{ |
1060 |
if (!strcmp (&pl->ob->name, thing)) |
1061 |
{ |
1062 |
if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; |
1063 |
if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; |
1064 |
if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; |
1065 |
if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; |
1066 |
if (!strcmp ("cha", thing2)) pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii; |
1067 |
if (!strcmp ("int", thing2)) pl->ob->stats.Int = iii, pl->orig_stats.Int = iii; |
1068 |
if (!strcmp ("pow", thing2)) pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii; |
1069 |
|
1070 |
sprintf (buf, "%s has been altered.", &pl->ob->name); |
1071 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1072 |
pl->ob->update_stats (); |
1073 |
return 1; |
1074 |
} |
1075 |
} |
1076 |
|
1077 |
new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
1078 |
return 1; |
1079 |
} |
1080 |
|
1081 |
int |
1082 |
command_invisible (object *op, char *params) |
1083 |
{ |
1084 |
if (op) |
1085 |
{ |
1086 |
op->invisible += TIME2TICK (60); |
1087 |
update_object (op, UP_OBJ_CHANGE); |
1088 |
new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); |
1089 |
} |
1090 |
|
1091 |
return 0; |
1092 |
} |
1093 |
|
1094 |
/** |
1095 |
* Returns spell object (from archetypes) by name. |
1096 |
* Returns NULL if 0 or more than one spell matches. |
1097 |
* Used for wizard's learn spell/prayer. |
1098 |
* |
1099 |
* op is the player issuing the command. |
1100 |
*/ |
1101 |
static object * |
1102 |
get_spell_by_name (object *op, shstr_cmp spell_name) |
1103 |
{ |
1104 |
/* First check for full name matches. */ |
1105 |
int conflict_found = 0; |
1106 |
archetype *found = 0; |
1107 |
|
1108 |
for_all_archetypes (at) |
1109 |
{ |
1110 |
if (at->type != SPELL) |
1111 |
continue; |
1112 |
|
1113 |
if (at->object::name != spell_name) |
1114 |
continue; |
1115 |
|
1116 |
if (found) |
1117 |
{ |
1118 |
if (!conflict_found) |
1119 |
{ |
1120 |
conflict_found = 1; |
1121 |
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, "- %s", &found->archname); |
1123 |
} |
1124 |
|
1125 |
new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); |
1126 |
return 0; |
1127 |
} |
1128 |
|
1129 |
found = at; |
1130 |
} |
1131 |
|
1132 |
/* Return if exactly one archetype matches. */ |
1133 |
if (found) |
1134 |
return found->instance (); |
1135 |
|
1136 |
/* No spell found: just print an error message. */ |
1137 |
new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist."); |
1138 |
|
1139 |
return 0; |
1140 |
} |
1141 |
|
1142 |
static int |
1143 |
command_learn_spell_or_prayer (object *op, char *params, int special_prayer) |
1144 |
{ |
1145 |
object *tmp; |
1146 |
|
1147 |
if (op->contr == NULL || params == NULL) |
1148 |
{ |
1149 |
new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to learn?"); |
1150 |
return 0; |
1151 |
} |
1152 |
|
1153 |
tmp = get_spell_by_name (op, params); |
1154 |
if (tmp == NULL) |
1155 |
{ |
1156 |
return 0; |
1157 |
} |
1158 |
|
1159 |
if (check_spell_known (op, tmp->name)) |
1160 |
{ |
1161 |
new_draw_info_format (NDI_UNIQUE, 0, op, "You already know the spell %s.", &tmp->name); |
1162 |
return 0; |
1163 |
} |
1164 |
|
1165 |
do_learn_spell (op, tmp, special_prayer); |
1166 |
tmp->destroy (); |
1167 |
return 1; |
1168 |
} |
1169 |
|
1170 |
int |
1171 |
command_learn_spell (object *op, char *params) |
1172 |
{ |
1173 |
return command_learn_spell_or_prayer (op, params, 0); |
1174 |
} |
1175 |
|
1176 |
int |
1177 |
command_learn_special_prayer (object *op, char *params) |
1178 |
{ |
1179 |
return command_learn_spell_or_prayer (op, params, 1); |
1180 |
} |
1181 |
|
1182 |
int |
1183 |
command_forget_spell (object *op, char *params) |
1184 |
{ |
1185 |
object *spell; |
1186 |
|
1187 |
if (op->contr == NULL || params == NULL) |
1188 |
{ |
1189 |
new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); |
1190 |
return 0; |
1191 |
} |
1192 |
|
1193 |
spell = op->find_spell (params); |
1194 |
if (spell == NULL) |
1195 |
{ |
1196 |
new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); |
1197 |
return 0; |
1198 |
} |
1199 |
|
1200 |
do_forget_spell (op, spell->name); |
1201 |
return 1; |
1202 |
} |
1203 |
|
1204 |
/** |
1205 |
* Pop the stack top. |
1206 |
*/ |
1207 |
int |
1208 |
command_stack_pop (object *op, char *params) |
1209 |
{ |
1210 |
dm_stack_pop (op->contr); |
1211 |
return 0; |
1212 |
} |
1213 |
|
1214 |
/** |
1215 |
* Push specified item on stack. |
1216 |
*/ |
1217 |
int |
1218 |
command_stack_push (object *op, char *params) |
1219 |
{ |
1220 |
object *ob; |
1221 |
int from; |
1222 |
|
1223 |
ob = get_dm_object (op->contr, ¶ms, &from); |
1224 |
|
1225 |
if (ob && from != STACK_FROM_NUMBER) |
1226 |
/* Object was from stack, need to push it again */ |
1227 |
dm_stack_push (op->contr, ob->count); |
1228 |
|
1229 |
return 0; |
1230 |
} |
1231 |
|
1232 |
/** |
1233 |
* Displays stack contents. |
1234 |
*/ |
1235 |
int |
1236 |
command_stack_list (object *op, char *params) |
1237 |
{ |
1238 |
int item; |
1239 |
object *display; |
1240 |
player *pl = op->contr; |
1241 |
|
1242 |
new_draw_info (NDI_UNIQUE, 0, op, "Item stack contents:"); |
1243 |
|
1244 |
for (item = 0; item < pl->stack_position; item++) |
1245 |
{ |
1246 |
display = find_object (pl->stack_items[item]); |
1247 |
if (display) |
1248 |
new_draw_info_format (NDI_UNIQUE, 0, op, " %d : %s [%d]", item, &display->name, display->count); |
1249 |
else |
1250 |
/* Item was freed */ |
1251 |
new_draw_info_format (NDI_UNIQUE, 0, op, " %d : (lost item: %d)", item, pl->stack_items[item]); |
1252 |
} |
1253 |
|
1254 |
return 0; |
1255 |
} |
1256 |
|
1257 |
/** |
1258 |
* Empty DM item stack. |
1259 |
*/ |
1260 |
int |
1261 |
command_stack_clear (object *op, char *params) |
1262 |
{ |
1263 |
op->contr->stack_position = 0; |
1264 |
new_draw_info (NDI_UNIQUE, 0, op, "Item stack cleared."); |
1265 |
return 0; |
1266 |
} |
1267 |
|
1268 |
int |
1269 |
command_insert_into (object *op, char *params) |
1270 |
{ |
1271 |
object *left, *right; |
1272 |
int left_from, right_from; |
1273 |
|
1274 |
left = get_dm_object (op->contr, ¶ms, &left_from); |
1275 |
if (!left) |
1276 |
{ |
1277 |
new_draw_info (NDI_UNIQUE, 0, op, "Insert into what object?"); |
1278 |
return 0; |
1279 |
} |
1280 |
|
1281 |
if (left_from == STACK_FROM_NUMBER) |
1282 |
/* Item was stacked, remove it else right will be the same... */ |
1283 |
dm_stack_pop (op->contr); |
1284 |
|
1285 |
right = get_dm_object (op->contr, ¶ms, &right_from); |
1286 |
|
1287 |
if (!right) |
1288 |
{ |
1289 |
new_draw_info (NDI_UNIQUE, 0, op, "Insert what item?"); |
1290 |
return 0; |
1291 |
} |
1292 |
|
1293 |
if (left_from == STACK_FROM_TOP && right_from == STACK_FROM_TOP) |
1294 |
{ |
1295 |
/* |
1296 |
* Special case: both items were taken from stack top. |
1297 |
* Override the behaviour, taking left as item just below top, if exists. |
1298 |
* See function description for why. |
1299 |
* Besides, can't insert an item into itself. |
1300 |
*/ |
1301 |
if (op->contr->stack_position > 1) |
1302 |
{ |
1303 |
left = find_object (op->contr->stack_items[op->contr->stack_position - 2]); |
1304 |
if (left) |
1305 |
new_draw_info (NDI_UNIQUE, 0, op, "(Note: item to insert into taken from undertop)"); |
1306 |
else |
1307 |
/* Stupid case: item under top was freed, fallback to stack top */ |
1308 |
left = right; |
1309 |
} |
1310 |
} |
1311 |
|
1312 |
if (left == right) |
1313 |
{ |
1314 |
new_draw_info (NDI_UNIQUE, 0, op, "Can't insert an object into itself!"); |
1315 |
return 0; |
1316 |
} |
1317 |
|
1318 |
if (right->type == PLAYER) |
1319 |
{ |
1320 |
new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1321 |
return 0; |
1322 |
} |
1323 |
|
1324 |
if (!right->flag [FLAG_REMOVED]) |
1325 |
right->remove (); |
1326 |
|
1327 |
object *inserted = insert_ob_in_ob (right, left); |
1328 |
|
1329 |
new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); |
1330 |
|
1331 |
return 0; |
1332 |
|
1333 |
} |