1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * 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 |
9 | * 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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * 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/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <sproto.h> |
26 | #include <sproto.h> |
26 | #include <spells.h> |
27 | #include <spells.h> |
… | |
… | |
33 | /* Values for 'from' field of get_dm_object */ |
34 | /* Values for 'from' field of get_dm_object */ |
34 | #define STACK_FROM_NONE 0 /* Item was not found */ |
35 | #define STACK_FROM_NONE 0 /* Item was not found */ |
35 | #define STACK_FROM_TOP 1 /* Item is stack top */ |
36 | #define STACK_FROM_TOP 1 /* Item is stack top */ |
36 | #define STACK_FROM_STACK 2 /* Item is somewhere in stack */ |
37 | #define STACK_FROM_STACK 2 /* Item is somewhere in stack */ |
37 | #define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ |
38 | #define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ |
38 | |
|
|
39 | |
39 | |
40 | /** |
40 | /** |
41 | * Enough of the DM functions seem to need this that I broke |
41 | * Enough of the DM functions seem to need this that I broke |
42 | * it out to a seperate function. name is the person |
42 | * it out to a seperate function. name is the person |
43 | * being saught, rq is who is looking for them. This |
43 | * being saught, rq is who is looking for them. This |
… | |
… | |
70 | |
70 | |
71 | new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
71 | new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
72 | return 0; |
72 | return 0; |
73 | } |
73 | } |
74 | |
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 | |
75 | /** |
264 | /** |
76 | * Actually hides specified player (obviously a DM). |
265 | * Actually hides specified player (obviously a DM). |
77 | * If 'silent_dm' is non zero, other players are informed of DM entering/leaving, |
266 | * If 'silent_dm' is non zero, other players are informed of DM entering/leaving, |
78 | * else they just think someone left/entered. |
267 | * else they just think someone left/entered. |
79 | */ |
268 | */ |
80 | void |
269 | static void |
81 | do_wizard_hide (object *op, int silent_dm) |
270 | do_wizard_hide (object *op, int silent_dm) |
82 | { |
271 | { |
83 | if (op->contr->hidden) |
272 | if (op->contr->hidden) |
84 | { |
273 | { |
85 | op->contr->hidden = 0; |
274 | op->contr->hidden = 0; |
… | |
… | |
167 | { |
356 | { |
168 | new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); |
357 | new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); |
169 | return 1; |
358 | return 1; |
170 | } |
359 | } |
171 | |
360 | |
172 | become_follower (ob, god); |
361 | ob->become_follower (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 *op = pl->ob; |
|
|
184 | |
|
|
185 | if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED)) |
|
|
186 | { |
|
|
187 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &op->name); |
|
|
188 | strcpy (op->contr->killer, "kicked"); |
|
|
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; |
362 | 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 | } |
363 | } |
219 | #endif |
|
|
220 | |
364 | |
221 | int |
365 | int |
222 | command_freeze (object *op, char *params) |
366 | command_freeze (object *op, char *params) |
223 | { |
367 | { |
224 | int ticks; |
368 | int ticks; |
… | |
… | |
279 | /* we have nowhere to send the prisoner.... */ |
423 | /* 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"); |
424 | new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); |
281 | return 0; |
425 | return 0; |
282 | } |
426 | } |
283 | |
427 | |
284 | pl->ob->enter_exit (dummy); |
428 | pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO |
285 | dummy->destroy (); |
429 | dummy->destroy (); |
|
|
430 | |
286 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); |
431 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); |
287 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
432 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
288 | LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); |
433 | LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); |
289 | return 1; |
434 | return 1; |
290 | } |
435 | } |
291 | |
436 | |
292 | int |
437 | int |
293 | command_summon (object *op, char *params) |
438 | command_summon (object *op, char *params) |
294 | { |
439 | { |
295 | int i; |
440 | int i; |
296 | object *dummy; |
|
|
297 | player *pl; |
441 | player *pl; |
298 | |
442 | |
299 | if (!op) |
443 | if (!op) |
300 | return 0; |
444 | return 0; |
301 | |
445 | |
… | |
… | |
307 | |
451 | |
308 | pl = get_other_player_from_name (op, params); |
452 | pl = get_other_player_from_name (op, params); |
309 | if (!pl) |
453 | if (!pl) |
310 | return 1; |
454 | return 1; |
311 | |
455 | |
312 | i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
456 | maptile *m = op->map; |
|
|
457 | sint16 nx = op->x; |
|
|
458 | sint16 ny = op->y; |
|
|
459 | |
|
|
460 | i = find_free_spot (op, m, nx, ny, 1, SIZEOFFREE1+1); |
313 | if (i == -1) |
461 | if (i == -1) |
314 | { |
462 | { |
315 | new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
463 | new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
316 | return 1; |
464 | return 1; |
317 | } |
465 | } |
318 | |
466 | |
319 | dummy = object::create (); |
467 | nx += freearr_x [i]; |
320 | EXIT_PATH (dummy) = op->map->path; |
468 | ny += freearr_y [i]; |
321 | EXIT_X (dummy) = op->x + freearr_x[i]; |
469 | |
322 | EXIT_Y (dummy) = op->y + freearr_y[i]; |
470 | if (!xy_normalise (m, nx, ny)) |
323 | pl->ob->enter_exit (dummy); |
471 | { |
324 | dummy->destroy (); |
472 | new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
|
|
473 | return 1; |
|
|
474 | } |
|
|
475 | |
|
|
476 | pl->ob->player_goto (m->path, nx, ny); |
325 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
477 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
326 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
478 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
327 | |
479 | |
328 | return 1; |
480 | return 1; |
329 | } |
481 | } |
… | |
… | |
346 | int |
498 | int |
347 | command_create (object *op, char *params) |
499 | command_create (object *op, char *params) |
348 | { |
500 | { |
349 | object *tmp = NULL; |
501 | object *tmp = NULL; |
350 | int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
502 | int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
351 | char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *bp4, *endline; |
503 | char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline; |
352 | archetype *at, *at_spell = NULL; |
504 | archetype *at, *at_spell = NULL; |
353 | artifact *art = NULL; |
505 | artifact *art = NULL; |
354 | |
506 | |
355 | if (!op) |
507 | if (!op) |
356 | return 0; |
508 | return 0; |
… | |
… | |
455 | { |
607 | { |
456 | art = find_artifactlist (at->type)->items; |
608 | art = find_artifactlist (at->type)->items; |
457 | |
609 | |
458 | while (art) |
610 | while (art) |
459 | { |
611 | { |
460 | if (!strcmp (art->item->name, cp)) |
612 | if (!strcmp (&art->item->name, cp)) |
461 | break; |
613 | break; |
462 | |
614 | |
463 | art = art->next; |
615 | art = art->next; |
464 | } |
616 | } |
465 | |
617 | |
… | |
… | |
481 | /* |
633 | /* |
482 | * Rather than have two different blocks with a lot of similar code, |
634 | * Rather than have two different blocks with a lot of similar code, |
483 | * just create one object, do all the processing, and then determine |
635 | * just create one object, do all the processing, and then determine |
484 | * if that one object should be inserted or if we need to make copies. |
636 | * if that one object should be inserted or if we need to make copies. |
485 | */ |
637 | */ |
486 | tmp = arch_to_object (at); |
638 | tmp = at->instance (); |
487 | |
639 | |
488 | if (set_magic) |
640 | if (set_magic) |
489 | set_abs_magic (tmp, magic); |
641 | set_abs_magic (tmp, magic); |
490 | |
642 | |
491 | if (art) |
643 | if (art) |
492 | give_artifact_abilities (tmp, art->item); |
644 | give_artifact_abilities (tmp, art->item); |
493 | |
645 | |
494 | if (need_identify (tmp)) |
646 | if (tmp->need_identify ()) |
495 | { |
647 | { |
496 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
648 | tmp->set_flag (FLAG_IDENTIFIED); |
497 | CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); |
649 | tmp->clr_flag (FLAG_KNOWN_MAGICAL); |
498 | } |
650 | } |
499 | |
651 | |
500 | /* |
652 | /* |
501 | * This entire block here tries to find variable pairings, |
653 | * This entire block here tries to find variable pairings, |
502 | * eg, 'hp 4' or the like. The mess here is that values |
654 | * eg, 'hp 4' or the like. The mess here is that values |
… | |
… | |
504 | * is we want to find two spaces, but if we got a quote, |
656 | * is we want to find two spaces, but if we got a quote, |
505 | * any spaces there don't count. |
657 | * any spaces there don't count. |
506 | */ |
658 | */ |
507 | while (*bp2 && bp2 <= endline) |
659 | while (*bp2 && bp2 <= endline) |
508 | { |
660 | { |
509 | bp4 = NULL; |
|
|
510 | gotspace = 0; |
661 | gotspace = 0; |
511 | gotquote = 0; |
662 | gotquote = 0; |
512 | |
663 | |
513 | /* find the first quote */ |
664 | /* find the first quote */ |
514 | for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) |
665 | for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) |
… | |
… | |
574 | } |
725 | } |
575 | |
726 | |
576 | if (at->nrof) |
727 | if (at->nrof) |
577 | { |
728 | { |
578 | if (at_spell) |
729 | if (at_spell) |
579 | insert_ob_in_ob (arch_to_object (at_spell), tmp); |
730 | tmp->insert (at_spell->instance ()); |
580 | |
731 | |
581 | tmp->x = op->x; |
732 | tmp->x = op->x; |
582 | tmp->y = op->y; |
733 | tmp->y = op->y; |
|
|
734 | tmp->map = op->map; |
583 | |
735 | |
584 | if (set_nrof) |
736 | if (set_nrof) |
585 | tmp->nrof = nrof; |
737 | tmp->nrof = nrof; |
586 | |
738 | |
587 | tmp->map = op->map; |
739 | op->insert (tmp); |
588 | |
|
|
589 | tmp = insert_ob_in_ob (tmp, op); |
|
|
590 | esrv_send_item (op, tmp); |
|
|
591 | |
740 | |
592 | /* Let's put this created item on stack so dm can access it easily. */ |
741 | /* Let's put this created item on stack so dm can access it easily. */ |
593 | dm_stack_push (op->contr, tmp->count); |
742 | dm_stack_push (op->contr, tmp->count); |
594 | |
743 | |
595 | return 1; |
744 | return 1; |
… | |
… | |
600 | { |
749 | { |
601 | object *prev = 0, *head = 0; |
750 | object *prev = 0, *head = 0; |
602 | |
751 | |
603 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
752 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
604 | { |
753 | { |
605 | object *dup = arch_to_object (atmp); |
754 | object *dup = atmp->instance (); |
606 | |
755 | |
607 | if (at_spell) |
756 | if (at_spell) |
608 | insert_ob_in_ob (arch_to_object (at_spell), dup); |
757 | insert_ob_in_ob (at_spell->instance (), dup); |
609 | |
758 | |
610 | /* |
759 | /* |
611 | * The head is what contains all the important bits, |
760 | * The head is what contains all the important bits, |
612 | * so just copying it over should be fine. |
761 | * so just copying it over should be fine. |
613 | */ |
762 | */ |
… | |
… | |
628 | } |
777 | } |
629 | |
778 | |
630 | prev = dup; |
779 | prev = dup; |
631 | } |
780 | } |
632 | |
781 | |
633 | if (QUERY_FLAG (head, FLAG_ALIVE)) |
782 | if (head->flag [FLAG_ALIVE]) |
634 | { |
783 | { |
635 | object *check = head; |
784 | object *check = head; |
636 | int size_x = 0; |
785 | int size_x = 0; |
637 | int size_y = 0; |
786 | int size_y = 0; |
638 | |
787 | |
639 | while (check) |
788 | while (check) |
640 | { |
789 | { |
641 | size_x = MAX (size_x, check->arch->x); |
790 | size_x = max (size_x, check->arch->x); |
642 | size_y = MAX (size_y, check->arch->y); |
791 | size_y = max (size_y, check->arch->y); |
643 | check = check->more; |
792 | check = check->more; |
644 | } |
793 | } |
645 | |
794 | |
646 | if (out_of_map (op->map, head->x + size_x, head->y + size_y)) |
795 | if (out_of_map (op->map, head->x + size_x, head->y + size_y)) |
647 | { |
796 | { |
… | |
… | |
673 | /* Wonder if we really want to push all of these, but since |
822 | /* Wonder if we really want to push all of these, but since |
674 | * things like rods have nrof 0, we want to cover those. |
823 | * things like rods have nrof 0, we want to cover those. |
675 | */ |
824 | */ |
676 | dm_stack_push (op->contr, head->count); |
825 | dm_stack_push (op->contr, head->count); |
677 | |
826 | |
678 | if (at->randomitems != NULL && !at_spell) |
827 | if (at->randomitems && !at_spell) |
679 | create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0); |
828 | create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0); |
680 | |
|
|
681 | esrv_send_item (op, head); |
|
|
682 | } |
829 | } |
683 | |
830 | |
684 | /* free the one we used to copy */ |
831 | /* free the one we used to copy */ |
685 | tmp->destroy (); |
832 | tmp->destroy (); |
686 | } |
833 | } |
… | |
… | |
731 | |
878 | |
732 | char *dump = dump_object (tmp); |
879 | char *dump = dump_object (tmp); |
733 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
880 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
734 | free (dump); |
881 | free (dump); |
735 | |
882 | |
736 | if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) |
883 | if (tmp->flag [FLAG_OBJ_ORIGINAL]) |
737 | new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); |
884 | new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); |
738 | |
885 | |
739 | return 1; |
886 | return 1; |
740 | } |
887 | } |
741 | |
888 | |
… | |
… | |
786 | { |
933 | { |
787 | new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
934 | new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
788 | return 1; |
935 | return 1; |
789 | } |
936 | } |
790 | |
937 | |
791 | if (QUERY_FLAG (tmp, FLAG_REMOVED)) |
938 | if (tmp->flag [FLAG_REMOVED]) |
792 | { |
939 | { |
793 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); |
940 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); |
794 | return 1; |
941 | return 1; |
795 | } |
942 | } |
796 | |
943 | |
… | |
… | |
840 | int q; |
987 | int q; |
841 | long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure |
988 | long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure |
842 | object *skillob = NULL; |
989 | object *skillob = NULL; |
843 | |
990 | |
844 | skill[0] = '\0'; |
991 | skill[0] = '\0'; |
845 | if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %s", buf, &i, skill)) < 2)) |
992 | if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2)) |
846 | { |
993 | { |
847 | new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); |
994 | new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); |
848 | return 1; |
995 | return 1; |
849 | } |
996 | } |
850 | |
997 | |
… | |
… | |
897 | new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
1044 | new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
898 | return 1; |
1045 | return 1; |
899 | } |
1046 | } |
900 | |
1047 | |
901 | for_all_players (pl) |
1048 | for_all_players (pl) |
902 | if (!strcmp (pl->ob->name, thing)) |
1049 | if (!strcmp (&pl->ob->name, thing)) |
903 | { |
1050 | { |
904 | sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
1051 | sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
905 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1052 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
906 | sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
1053 | sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
907 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1054 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
… | |
… | |
950 | return 1; |
1097 | return 1; |
951 | } |
1098 | } |
952 | |
1099 | |
953 | for_all_players (pl) |
1100 | for_all_players (pl) |
954 | { |
1101 | { |
955 | if (!strcmp (pl->ob->name, thing)) |
1102 | if (!strcmp (&pl->ob->name, thing)) |
956 | { |
1103 | { |
957 | if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; |
1104 | if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; |
958 | if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; |
1105 | if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; |
959 | if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; |
1106 | if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; |
960 | if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; |
1107 | if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; |
… | |
… | |
974 | } |
1121 | } |
975 | |
1122 | |
976 | int |
1123 | int |
977 | command_nowiz (object *op, char *params) |
1124 | command_nowiz (object *op, char *params) |
978 | { /* 'nodm' is alias */ |
1125 | { /* 'nodm' is alias */ |
979 | CLEAR_FLAG (op, FLAG_WIZ); |
1126 | op->clr_flag (FLAG_WIZ); |
980 | CLEAR_FLAG (op, FLAG_WIZPASS); |
1127 | op->clr_flag (FLAG_WIZPASS); |
981 | CLEAR_FLAG (op, FLAG_WIZCAST); |
1128 | op->clr_flag (FLAG_WIZCAST); |
|
|
1129 | op->clr_flag (FLAG_WIZLOOK); |
|
|
1130 | op->contr->do_los = 1; |
982 | |
1131 | |
983 | if (op->contr->hidden) |
1132 | if (op->contr->hidden) |
984 | { |
1133 | { |
985 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); |
1134 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); |
986 | op->map->players++; |
1135 | op->map->players++; |
… | |
… | |
988 | op->contr->hidden = 0; |
1137 | op->contr->hidden = 0; |
989 | op->invisible = 1; |
1138 | op->invisible = 1; |
990 | } |
1139 | } |
991 | else |
1140 | else |
992 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); |
1141 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); |
|
|
1142 | |
993 | return 1; |
1143 | return 1; |
994 | } |
1144 | } |
995 | |
1145 | |
996 | /** |
1146 | /** |
997 | * object *op is trying to become dm. |
1147 | * object *op is trying to become dm. |
… | |
… | |
1034 | } |
1184 | } |
1035 | fclose (dmfile); |
1185 | fclose (dmfile); |
1036 | return (0); |
1186 | return (0); |
1037 | } |
1187 | } |
1038 | |
1188 | |
1039 | int |
1189 | static int |
1040 | do_wizard_dm (object *op, char *params, int silent) |
1190 | do_wizard_dm (object *op, char *params, int silent) |
1041 | { |
1191 | { |
1042 | if (!op->contr) |
1192 | if (!op->contr) |
1043 | return 0; |
1193 | return 0; |
1044 | |
1194 | |
1045 | if (QUERY_FLAG (op, FLAG_WIZ)) |
1195 | if (op->flag [FLAG_WIZ]) |
1046 | { |
1196 | { |
1047 | new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); |
1197 | new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); |
1048 | return 0; |
1198 | return 0; |
1049 | } |
1199 | } |
1050 | |
1200 | |
1051 | if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) |
1201 | if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) |
1052 | { |
1202 | { |
1053 | SET_FLAG (op, FLAG_WIZ); |
1203 | op->set_flag (FLAG_WIZ); |
1054 | SET_FLAG (op, FLAG_WIZPASS); |
1204 | op->set_flag (FLAG_WIZPASS); |
1055 | SET_FLAG (op, FLAG_WIZCAST); |
1205 | op->set_flag (FLAG_WIZCAST); |
|
|
1206 | op->set_flag (FLAG_WIZLOOK); |
|
|
1207 | op->contr->do_los = 1; |
1056 | |
1208 | |
1057 | new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); |
1209 | new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); |
1058 | /* |
|
|
1059 | * Remove setting flying here - that won't work, because next |
|
|
1060 | * fix_player() is called that will get cleared - proper solution |
|
|
1061 | * is probably something like a wiz_force which gives that and any |
|
|
1062 | * other desired abilities. |
|
|
1063 | */ |
|
|
1064 | clear_los (op->contr); |
|
|
1065 | op->contr->write_buf[0] = '\0'; |
1210 | op->contr->write_buf[0] = '\0'; |
1066 | |
1211 | |
1067 | if (!silent) |
1212 | if (!silent) |
1068 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); |
1213 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); |
1069 | |
1214 | |
… | |
… | |
1109 | * Returns spell object (from archetypes) by name. |
1254 | * Returns spell object (from archetypes) by name. |
1110 | * Returns NULL if 0 or more than one spell matches. |
1255 | * Returns NULL if 0 or more than one spell matches. |
1111 | * Used for wizard's learn spell/prayer. |
1256 | * Used for wizard's learn spell/prayer. |
1112 | * |
1257 | * |
1113 | * op is the player issuing the command. |
1258 | * op is the player issuing the command. |
1114 | * |
|
|
1115 | * Ignores archetypes "spelldirect_xxx" since these archetypes are not used |
|
|
1116 | * anymore (but may still be present in some player's inventories and thus |
|
|
1117 | * cannot be removed). We have to ignore them here since they have the same |
|
|
1118 | * name than other "spell_xxx" archetypes and would always conflict. |
|
|
1119 | */ |
1259 | */ |
1120 | static object * |
1260 | static object * |
1121 | get_spell_by_name (object *op, const char *spell_name) |
1261 | get_spell_by_name (object *op, shstr_cmp spell_name) |
1122 | { |
1262 | { |
1123 | archetype *at; |
|
|
1124 | archetype *found; |
|
|
1125 | int conflict_found; |
|
|
1126 | size_t spell_name_length; |
|
|
1127 | |
|
|
1128 | /* First check for full name matches. */ |
1263 | /* First check for full name matches. */ |
1129 | conflict_found = 0; |
1264 | int conflict_found = 0; |
1130 | found = NULL; |
1265 | archetype *found = 0; |
|
|
1266 | |
1131 | for_all_archetypes (at) |
1267 | for_all_archetypes (at) |
1132 | { |
1268 | { |
1133 | if (at->type != SPELL) |
1269 | if (at->type != SPELL) |
1134 | continue; |
1270 | continue; |
1135 | |
1271 | |
1136 | if (strncmp (at->archname, "spelldirect_", 12) == 0) |
1272 | if (at->object::name != spell_name) |
1137 | continue; |
1273 | continue; |
1138 | |
1274 | |
1139 | if (strcmp (at->object::name, spell_name) != 0) |
|
|
1140 | continue; |
|
|
1141 | |
|
|
1142 | if (found != NULL) |
1275 | if (found) |
1143 | { |
1276 | { |
1144 | if (!conflict_found) |
1277 | if (!conflict_found) |
1145 | { |
1278 | { |
1146 | conflict_found = 1; |
1279 | conflict_found = 1; |
1147 | new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); |
1280 | new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name); |
1148 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); |
1281 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); |
1149 | } |
1282 | } |
1150 | |
1283 | |
1151 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); |
1284 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); |
1152 | continue; |
1285 | return 0; |
1153 | } |
1286 | } |
1154 | |
1287 | |
1155 | found = at; |
1288 | found = at; |
1156 | } |
1289 | } |
1157 | |
1290 | |
1158 | /* No match if more more than one archetype matches. */ |
|
|
1159 | if (conflict_found) |
|
|
1160 | return NULL; |
|
|
1161 | |
|
|
1162 | /* Return if exactly one archetype matches. */ |
1291 | /* Return if exactly one archetype matches. */ |
1163 | if (found != NULL) |
1292 | if (found) |
1164 | return arch_to_object (found); |
1293 | return found->instance (); |
1165 | |
|
|
1166 | /* No full match found: now check for partial matches. */ |
|
|
1167 | spell_name_length = strlen (spell_name); |
|
|
1168 | conflict_found = 0; |
|
|
1169 | found = NULL; |
|
|
1170 | for_all_archetypes (at) |
|
|
1171 | { |
|
|
1172 | if (at->type != SPELL) |
|
|
1173 | continue; |
|
|
1174 | |
|
|
1175 | if (strncmp (at->archname, "spelldirect_", 12) == 0) |
|
|
1176 | continue; |
|
|
1177 | |
|
|
1178 | if (strncmp (at->object::name, spell_name, spell_name_length) != 0) |
|
|
1179 | continue; |
|
|
1180 | |
|
|
1181 | if (found != NULL) |
|
|
1182 | { |
|
|
1183 | if (!conflict_found) |
|
|
1184 | { |
|
|
1185 | conflict_found = 1; |
|
|
1186 | new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name); |
|
|
1187 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->object::name); |
|
|
1188 | } |
|
|
1189 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->object::name); |
|
|
1190 | continue; |
|
|
1191 | } |
|
|
1192 | |
|
|
1193 | found = at; |
|
|
1194 | } |
|
|
1195 | |
|
|
1196 | /* No match if more more than one archetype matches. */ |
|
|
1197 | if (conflict_found) |
|
|
1198 | return NULL; |
|
|
1199 | |
|
|
1200 | /* Return if exactly one archetype matches. */ |
|
|
1201 | if (found != NULL) |
|
|
1202 | return arch_to_object (found); |
|
|
1203 | |
1294 | |
1204 | /* No spell found: just print an error message. */ |
1295 | /* No spell found: just print an error message. */ |
1205 | new_draw_info_format (NDI_UNIQUE, 0, op, "The spell %s does not exist.", spell_name); |
1296 | new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist."); |
|
|
1297 | |
1206 | return NULL; |
1298 | return 0; |
1207 | } |
1299 | } |
1208 | |
1300 | |
1209 | static int |
1301 | static int |
1210 | command_learn_spell_or_prayer (object *op, char *params, int special_prayer) |
1302 | command_learn_spell_or_prayer (object *op, char *params, int special_prayer) |
1211 | { |
1303 | { |
… | |
… | |
1280 | return 0; |
1372 | return 0; |
1281 | |
1373 | |
1282 | do_wizard_hide (op, 1); |
1374 | do_wizard_hide (op, 1); |
1283 | |
1375 | |
1284 | return 1; |
1376 | return 1; |
1285 | } |
|
|
1286 | |
|
|
1287 | void |
|
|
1288 | dm_stack_pop (player *pl) |
|
|
1289 | { |
|
|
1290 | if (!pl->stack_items || !pl->stack_position) |
|
|
1291 | { |
|
|
1292 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!"); |
|
|
1293 | return; |
|
|
1294 | } |
|
|
1295 | |
|
|
1296 | pl->stack_position--; |
|
|
1297 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position); |
|
|
1298 | } |
|
|
1299 | |
|
|
1300 | /** |
|
|
1301 | * Get current stack top item for player. |
|
|
1302 | * Returns NULL if no stacked item. |
|
|
1303 | * If stacked item disappeared (freed), remove it. |
|
|
1304 | * |
|
|
1305 | * Ryo, august 2004 |
|
|
1306 | */ |
|
|
1307 | object * |
|
|
1308 | dm_stack_peek (player *pl) |
|
|
1309 | { |
|
|
1310 | object *ob; |
|
|
1311 | |
|
|
1312 | if (!pl->stack_position) |
|
|
1313 | { |
|
|
1314 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!"); |
|
|
1315 | return NULL; |
|
|
1316 | } |
|
|
1317 | |
|
|
1318 | ob = find_object (pl->stack_items[pl->stack_position - 1]); |
|
|
1319 | if (!ob) |
|
|
1320 | { |
|
|
1321 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!"); |
|
|
1322 | dm_stack_pop (pl); |
|
|
1323 | return NULL; |
|
|
1324 | } |
|
|
1325 | |
|
|
1326 | return ob; |
|
|
1327 | } |
|
|
1328 | |
|
|
1329 | /** |
|
|
1330 | * Push specified item on player stack. |
|
|
1331 | * Inform player of position. |
|
|
1332 | * Initializes variables if needed. |
|
|
1333 | */ |
|
|
1334 | void |
|
|
1335 | dm_stack_push (player *pl, tag_t item) |
|
|
1336 | { |
|
|
1337 | if (!pl->stack_items) |
|
|
1338 | { |
|
|
1339 | pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE); |
|
|
1340 | memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE); |
|
|
1341 | } |
|
|
1342 | |
|
|
1343 | if (pl->stack_position == STACK_SIZE) |
|
|
1344 | { |
|
|
1345 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!"); |
|
|
1346 | return; |
|
|
1347 | } |
|
|
1348 | |
|
|
1349 | pl->stack_items[pl->stack_position] = item; |
|
|
1350 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position); |
|
|
1351 | pl->stack_position++; |
|
|
1352 | } |
|
|
1353 | |
|
|
1354 | /** |
|
|
1355 | * Checks 'params' for object code. |
|
|
1356 | * |
|
|
1357 | * Can be: |
|
|
1358 | * * empty => get current object stack top for player |
|
|
1359 | * * number => get item with that tag, stack it for future use |
|
|
1360 | * * $number => get specified stack item |
|
|
1361 | * * "me" => player himself |
|
|
1362 | * |
|
|
1363 | * At function exit, params points to first non-object char |
|
|
1364 | * |
|
|
1365 | * 'from', if not NULL, contains at exit: |
|
|
1366 | * * STACK_FROM_NONE => object not found |
|
|
1367 | * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty |
|
|
1368 | * * STACK_FROM_STACK => item from somewhere in the stack |
|
|
1369 | * * STACK_FROM_NUMBER => item by number, pushed on stack |
|
|
1370 | * |
|
|
1371 | * Ryo, august 2004 |
|
|
1372 | */ |
|
|
1373 | object * |
|
|
1374 | get_dm_object (player *pl, char **params, int *from) |
|
|
1375 | { |
|
|
1376 | int item_tag, item_position; |
|
|
1377 | object *ob; |
|
|
1378 | |
|
|
1379 | if (!pl) |
|
|
1380 | return NULL; |
|
|
1381 | |
|
|
1382 | if (!params || !*params || **params == '\0') |
|
|
1383 | { |
|
|
1384 | if (from) |
|
|
1385 | *from = STACK_FROM_TOP; |
|
|
1386 | /* No parameter => get stack item */ |
|
|
1387 | return dm_stack_peek (pl); |
|
|
1388 | } |
|
|
1389 | |
|
|
1390 | /* Let's clean white spaces */ |
|
|
1391 | while (**params == ' ') |
|
|
1392 | (*params)++; |
|
|
1393 | |
|
|
1394 | /* Next case: number => item tag */ |
|
|
1395 | if (sscanf (*params, "%d", &item_tag)) |
|
|
1396 | { |
|
|
1397 | /* Move parameter to next item */ |
|
|
1398 | while (isdigit (**params)) |
|
|
1399 | (*params)++; |
|
|
1400 | |
|
|
1401 | /* And skip blanks, too */ |
|
|
1402 | while (**params == ' ') |
|
|
1403 | (*params)++; |
|
|
1404 | |
|
|
1405 | /* Get item */ |
|
|
1406 | ob = find_object (item_tag); |
|
|
1407 | if (!ob) |
|
|
1408 | { |
|
|
1409 | if (from) |
|
|
1410 | *from = STACK_FROM_NONE; |
|
|
1411 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag); |
|
|
1412 | return NULL; |
|
|
1413 | } |
|
|
1414 | |
|
|
1415 | /* Got one, let's push it on stack */ |
|
|
1416 | dm_stack_push (pl, item_tag); |
|
|
1417 | if (from) |
|
|
1418 | *from = STACK_FROM_NUMBER; |
|
|
1419 | return ob; |
|
|
1420 | } |
|
|
1421 | |
|
|
1422 | /* Next case: $number => stack item */ |
|
|
1423 | if (sscanf (*params, "$%d", &item_position)) |
|
|
1424 | { |
|
|
1425 | /* Move parameter to next item */ |
|
|
1426 | (*params)++; |
|
|
1427 | |
|
|
1428 | while (isdigit (**params)) |
|
|
1429 | (*params)++; |
|
|
1430 | while (**params == ' ') |
|
|
1431 | (*params)++; |
|
|
1432 | |
|
|
1433 | if (item_position >= pl->stack_position) |
|
|
1434 | { |
|
|
1435 | if (from) |
|
|
1436 | *from = STACK_FROM_NONE; |
|
|
1437 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position); |
|
|
1438 | return NULL; |
|
|
1439 | } |
|
|
1440 | |
|
|
1441 | ob = find_object (pl->stack_items[item_position]); |
|
|
1442 | if (!ob) |
|
|
1443 | { |
|
|
1444 | if (from) |
|
|
1445 | *from = STACK_FROM_NONE; |
|
|
1446 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position); |
|
|
1447 | return NULL; |
|
|
1448 | } |
|
|
1449 | |
|
|
1450 | if (from) |
|
|
1451 | *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP; |
|
|
1452 | return ob; |
|
|
1453 | } |
|
|
1454 | |
|
|
1455 | /* Next case: 'me' => return pl->ob */ |
|
|
1456 | if (!strncmp (*params, "me", 2)) |
|
|
1457 | { |
|
|
1458 | if (from) |
|
|
1459 | *from = STACK_FROM_NUMBER; |
|
|
1460 | dm_stack_push (pl, pl->ob->count); |
|
|
1461 | |
|
|
1462 | /* Skip to next token */ |
|
|
1463 | (*params) += 2; |
|
|
1464 | while (**params == ' ') |
|
|
1465 | (*params)++; |
|
|
1466 | |
|
|
1467 | return pl->ob; |
|
|
1468 | } |
|
|
1469 | |
|
|
1470 | /* Last case: get stack top */ |
|
|
1471 | if (from) |
|
|
1472 | *from = STACK_FROM_TOP; |
|
|
1473 | return dm_stack_peek (pl); |
|
|
1474 | } |
1377 | } |
1475 | |
1378 | |
1476 | /** |
1379 | /** |
1477 | * Pop the stack top. |
1380 | * Pop the stack top. |
1478 | */ |
1381 | */ |
… | |
… | |
1538 | } |
1441 | } |
1539 | |
1442 | |
1540 | int |
1443 | int |
1541 | command_insert_into (object *op, char *params) |
1444 | command_insert_into (object *op, char *params) |
1542 | { |
1445 | { |
1543 | object *left, *right, *inserted; |
1446 | object *left, *right; |
1544 | int left_from, right_from; |
1447 | int left_from, right_from; |
1545 | |
1448 | |
1546 | left = get_dm_object (op->contr, ¶ms, &left_from); |
1449 | left = get_dm_object (op->contr, ¶ms, &left_from); |
1547 | if (!left) |
1450 | if (!left) |
1548 | { |
1451 | { |
… | |
… | |
1591 | { |
1494 | { |
1592 | new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1495 | new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1593 | return 0; |
1496 | return 0; |
1594 | } |
1497 | } |
1595 | |
1498 | |
1596 | if (!QUERY_FLAG (right, FLAG_REMOVED)) |
1499 | if (!right->flag [FLAG_REMOVED]) |
1597 | right->remove (); |
1500 | right->remove (); |
|
|
1501 | |
1598 | inserted = insert_ob_in_ob (right, left); |
1502 | object *inserted = insert_ob_in_ob (right, left); |
1599 | if (left->type == PLAYER) |
|
|
1600 | if (inserted == right) |
|
|
1601 | esrv_send_item (left, right); |
|
|
1602 | else |
|
|
1603 | esrv_update_item (UPD_WEIGHT | UPD_NAME | UPD_NROF, left, inserted); |
|
|
1604 | |
1503 | |
1605 | new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); |
1504 | new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); |
1606 | |
1505 | |
1607 | return 0; |
1506 | return 0; |
1608 | |
1507 | |