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,2013,2014,2015,2016 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 it |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, but |
13 | * This program is distributed in the hope that it will be useful, |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <sproto.h> |
26 | #include <sproto.h> |
27 | #include <spells.h> |
27 | #include <spells.h> |
… | |
… | |
34 | /* Values for 'from' field of get_dm_object */ |
34 | /* Values for 'from' field of get_dm_object */ |
35 | #define STACK_FROM_NONE 0 /* Item was not found */ |
35 | #define STACK_FROM_NONE 0 /* Item was not found */ |
36 | #define STACK_FROM_TOP 1 /* Item is stack top */ |
36 | #define STACK_FROM_TOP 1 /* Item is stack top */ |
37 | #define STACK_FROM_STACK 2 /* Item is somewhere in stack */ |
37 | #define STACK_FROM_STACK 2 /* Item is somewhere in stack */ |
38 | #define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ |
38 | #define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ |
39 | |
|
|
40 | |
39 | |
41 | /** |
40 | /** |
42 | * Enough of the DM functions seem to need this that I broke |
41 | * Enough of the DM functions seem to need this that I broke |
43 | * it out to a seperate function. name is the person |
42 | * it out to a seperate function. name is the person |
44 | * being saught, rq is who is looking for them. This |
43 | * being saught, rq is who is looking for them. This |
… | |
… | |
71 | |
70 | |
72 | new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
71 | new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
73 | return 0; |
72 | return 0; |
74 | } |
73 | } |
75 | |
74 | |
|
|
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 | |
76 | /** |
88 | /** |
77 | * Actually hides specified player (obviously a DM). |
89 | * Get current stack top item for player. |
78 | * If 'silent_dm' is non zero, other players are informed of DM entering/leaving, |
90 | * Returns NULL if no stacked item. |
79 | * else they just think someone left/entered. |
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. |
80 | */ |
121 | */ |
81 | void |
122 | void |
82 | do_wizard_hide (object *op, int silent_dm) |
123 | dm_stack_push (player *pl, tag_t item) |
83 | { |
124 | { |
84 | if (op->contr->hidden) |
125 | if (!pl->stack_items) |
85 | { |
|
|
86 | op->contr->hidden = 0; |
|
|
87 | op->invisible = 1; |
|
|
88 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); |
|
|
89 | op->map->players++; |
|
|
90 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name); |
|
|
91 | |
|
|
92 | if (!silent_dm) |
|
|
93 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); |
|
|
94 | } |
126 | { |
95 | else |
127 | pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE); |
|
|
128 | memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE); |
96 | { |
129 | } |
97 | op->contr->hidden = 1; |
|
|
98 | new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you."); |
|
|
99 | op->map->players--; |
|
|
100 | |
130 | |
101 | if (!silent_dm) |
131 | if (pl->stack_position == STACK_SIZE) |
102 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); |
|
|
103 | |
|
|
104 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name); |
|
|
105 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name); |
|
|
106 | } |
132 | { |
107 | } |
133 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!"); |
108 | |
|
|
109 | int |
|
|
110 | command_hide (object *op, char *params) |
|
|
111 | { |
|
|
112 | do_wizard_hide (op, 0); |
|
|
113 | return 1; |
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); |
114 | } |
262 | } |
115 | |
263 | |
116 | /** |
264 | /** |
117 | * This finds and returns the object which matches the name or |
265 | * This finds and returns the object which matches the name or |
118 | * object nubmer (specified via num #whatever). |
266 | * object nubmer (specified via num #whatever). |
… | |
… | |
168 | { |
316 | { |
169 | new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); |
317 | new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); |
170 | return 1; |
318 | return 1; |
171 | } |
319 | } |
172 | |
320 | |
173 | become_follower (ob, god); |
321 | ob->become_follower (god); |
174 | return 1; |
322 | return 1; |
175 | } |
323 | } |
176 | |
|
|
177 | // TODO: Rewrite banish in perl and get rid of the following two functions |
|
|
178 | int |
|
|
179 | command_kick (object *op, char *params) |
|
|
180 | { |
|
|
181 | for_all_players (pl) |
|
|
182 | if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params))) |
|
|
183 | { |
|
|
184 | object *op = pl->ob; |
|
|
185 | |
|
|
186 | if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED)) |
|
|
187 | { |
|
|
188 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &op->name); |
|
|
189 | strcpy (op->contr->killer, "kicked"); |
|
|
190 | } |
|
|
191 | |
|
|
192 | pl->ns->destroy (); |
|
|
193 | } |
|
|
194 | |
|
|
195 | return 1; |
|
|
196 | } |
|
|
197 | |
|
|
198 | //TODO |
|
|
199 | #if 0 |
|
|
200 | int |
|
|
201 | command_save_overlay (object *op, char *params) |
|
|
202 | { |
|
|
203 | if (!op) |
|
|
204 | return 0; |
|
|
205 | |
|
|
206 | if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) |
|
|
207 | { |
|
|
208 | new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't force an overlay save."); |
|
|
209 | return 1; |
|
|
210 | } |
|
|
211 | |
|
|
212 | new_save_map (op->map, 2); |
|
|
213 | new_save_map (op->map, 0); |
|
|
214 | new_draw_info (NDI_UNIQUE, 0, op, "Current map has been saved as an" " overlay."); |
|
|
215 | |
|
|
216 | ready_map_name (op->map->path, 0); |
|
|
217 | |
|
|
218 | return 1; |
|
|
219 | } |
|
|
220 | #endif |
|
|
221 | |
324 | |
222 | int |
325 | int |
223 | command_freeze (object *op, char *params) |
326 | command_freeze (object *op, char *params) |
224 | { |
327 | { |
225 | int ticks; |
328 | int ticks; |
… | |
… | |
280 | /* we have nowhere to send the prisoner.... */ |
383 | /* we have nowhere to send the prisoner.... */ |
281 | new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); |
384 | new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); |
282 | return 0; |
385 | return 0; |
283 | } |
386 | } |
284 | |
387 | |
285 | pl->ob->enter_exit (dummy); |
388 | pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO |
286 | dummy->destroy (); |
389 | dummy->destroy (); |
|
|
390 | |
287 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); |
391 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); |
288 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
392 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
289 | LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); |
393 | LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); |
290 | return 1; |
394 | return 1; |
291 | } |
395 | } |
292 | |
396 | |
293 | int |
397 | int |
294 | command_summon (object *op, char *params) |
398 | command_summon (object *op, char *params) |
295 | { |
399 | { |
296 | int i; |
400 | int i; |
297 | object *dummy; |
|
|
298 | player *pl; |
401 | player *pl; |
299 | |
402 | |
300 | if (!op) |
403 | if (!op) |
301 | return 0; |
404 | return 0; |
302 | |
405 | |
… | |
… | |
308 | |
411 | |
309 | pl = get_other_player_from_name (op, params); |
412 | pl = get_other_player_from_name (op, params); |
310 | if (!pl) |
413 | if (!pl) |
311 | return 1; |
414 | return 1; |
312 | |
415 | |
313 | i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
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); |
314 | if (i == -1) |
421 | if (i == -1) |
315 | { |
422 | { |
316 | new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
423 | new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
317 | return 1; |
424 | return 1; |
318 | } |
425 | } |
319 | |
426 | |
320 | dummy = object::create (); |
427 | nx += DIRX (i); |
321 | EXIT_PATH (dummy) = op->map->path; |
428 | ny += DIRY (i); |
322 | EXIT_X (dummy) = op->x + freearr_x[i]; |
429 | |
323 | EXIT_Y (dummy) = op->y + freearr_y[i]; |
430 | if (!xy_normalise (m, nx, ny)) |
324 | pl->ob->enter_exit (dummy); |
431 | { |
325 | dummy->destroy (); |
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); |
326 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
437 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
327 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
438 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
328 | |
439 | |
329 | return 1; |
440 | return 1; |
330 | } |
441 | } |
… | |
… | |
347 | int |
458 | int |
348 | command_create (object *op, char *params) |
459 | command_create (object *op, char *params) |
349 | { |
460 | { |
350 | object *tmp = NULL; |
461 | object *tmp = NULL; |
351 | int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
462 | int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
352 | char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *bp4, *endline; |
463 | char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline; |
353 | archetype *at, *at_spell = NULL; |
464 | archetype *at, *at_spell = NULL; |
354 | artifact *art = NULL; |
465 | artifact *art = NULL; |
355 | |
466 | |
356 | if (!op) |
467 | if (!op) |
357 | return 0; |
468 | return 0; |
… | |
… | |
456 | { |
567 | { |
457 | art = find_artifactlist (at->type)->items; |
568 | art = find_artifactlist (at->type)->items; |
458 | |
569 | |
459 | while (art) |
570 | while (art) |
460 | { |
571 | { |
461 | if (!strcmp (art->item->name, cp)) |
572 | if (!strcmp (&art->item->name, cp)) |
462 | break; |
573 | break; |
463 | |
574 | |
464 | art = art->next; |
575 | art = art->next; |
465 | } |
576 | } |
466 | |
577 | |
… | |
… | |
482 | /* |
593 | /* |
483 | * Rather than have two different blocks with a lot of similar code, |
594 | * Rather than have two different blocks with a lot of similar code, |
484 | * just create one object, do all the processing, and then determine |
595 | * just create one object, do all the processing, and then determine |
485 | * if that one object should be inserted or if we need to make copies. |
596 | * if that one object should be inserted or if we need to make copies. |
486 | */ |
597 | */ |
487 | tmp = arch_to_object (at); |
598 | tmp = at->instance (); |
488 | |
599 | |
489 | if (set_magic) |
600 | if (set_magic) |
490 | set_abs_magic (tmp, magic); |
601 | set_abs_magic (tmp, magic); |
491 | |
602 | |
492 | if (art) |
603 | if (art) |
493 | give_artifact_abilities (tmp, art->item); |
604 | give_artifact_abilities (tmp, art->item); |
494 | |
605 | |
495 | if (need_identify (tmp)) |
606 | if (tmp->need_identify ()) |
496 | { |
607 | { |
497 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
608 | tmp->set_flag (FLAG_IDENTIFIED); |
498 | CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); |
609 | tmp->clr_flag (FLAG_KNOWN_MAGICAL); |
499 | } |
610 | } |
500 | |
611 | |
501 | /* |
612 | /* |
502 | * This entire block here tries to find variable pairings, |
613 | * This entire block here tries to find variable pairings, |
503 | * eg, 'hp 4' or the like. The mess here is that values |
614 | * eg, 'hp 4' or the like. The mess here is that values |
… | |
… | |
505 | * is we want to find two spaces, but if we got a quote, |
616 | * is we want to find two spaces, but if we got a quote, |
506 | * any spaces there don't count. |
617 | * any spaces there don't count. |
507 | */ |
618 | */ |
508 | while (*bp2 && bp2 <= endline) |
619 | while (*bp2 && bp2 <= endline) |
509 | { |
620 | { |
510 | bp4 = NULL; |
|
|
511 | gotspace = 0; |
621 | gotspace = 0; |
512 | gotquote = 0; |
622 | gotquote = 0; |
513 | |
623 | |
514 | /* find the first quote */ |
624 | /* find the first quote */ |
515 | for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) |
625 | for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) |
… | |
… | |
575 | } |
685 | } |
576 | |
686 | |
577 | if (at->nrof) |
687 | if (at->nrof) |
578 | { |
688 | { |
579 | if (at_spell) |
689 | if (at_spell) |
580 | insert_ob_in_ob (arch_to_object (at_spell), tmp); |
690 | tmp->insert (at_spell->instance ()); |
581 | |
691 | |
582 | tmp->x = op->x; |
692 | tmp->x = op->x; |
583 | tmp->y = op->y; |
693 | tmp->y = op->y; |
|
|
694 | tmp->map = op->map; |
584 | |
695 | |
585 | if (set_nrof) |
696 | if (set_nrof) |
586 | tmp->nrof = nrof; |
697 | tmp->nrof = nrof; |
587 | |
698 | |
588 | tmp->map = op->map; |
699 | op->insert (tmp); |
589 | |
|
|
590 | tmp = insert_ob_in_ob (tmp, op); |
|
|
591 | esrv_send_item (op, tmp); |
|
|
592 | |
700 | |
593 | /* Let's put this created item on stack so dm can access it easily. */ |
701 | /* Let's put this created item on stack so dm can access it easily. */ |
594 | dm_stack_push (op->contr, tmp->count); |
702 | dm_stack_push (op->contr, tmp->count); |
595 | |
703 | |
596 | return 1; |
704 | return 1; |
… | |
… | |
601 | { |
709 | { |
602 | object *prev = 0, *head = 0; |
710 | object *prev = 0, *head = 0; |
603 | |
711 | |
604 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
712 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
605 | { |
713 | { |
606 | object *dup = arch_to_object (atmp); |
714 | object *dup = atmp->instance (); |
607 | |
715 | |
608 | if (at_spell) |
716 | if (at_spell) |
609 | insert_ob_in_ob (arch_to_object (at_spell), dup); |
717 | insert_ob_in_ob (at_spell->instance (), dup); |
610 | |
718 | |
611 | /* |
719 | /* |
612 | * The head is what contains all the important bits, |
720 | * The head is what contains all the important bits, |
613 | * so just copying it over should be fine. |
721 | * so just copying it over should be fine. |
614 | */ |
722 | */ |
… | |
… | |
629 | } |
737 | } |
630 | |
738 | |
631 | prev = dup; |
739 | prev = dup; |
632 | } |
740 | } |
633 | |
741 | |
634 | if (QUERY_FLAG (head, FLAG_ALIVE)) |
742 | if (head->flag [FLAG_ALIVE]) |
635 | { |
743 | { |
636 | object *check = head; |
744 | object *check = head; |
637 | int size_x = 0; |
745 | int size_x = 0; |
638 | int size_y = 0; |
746 | int size_y = 0; |
639 | |
747 | |
640 | while (check) |
748 | while (check) |
641 | { |
749 | { |
642 | size_x = MAX (size_x, check->arch->x); |
750 | size_x = max (size_x, check->arch->x); |
643 | size_y = MAX (size_y, check->arch->y); |
751 | size_y = max (size_y, check->arch->y); |
644 | check = check->more; |
752 | check = check->more; |
645 | } |
753 | } |
646 | |
754 | |
647 | if (out_of_map (op->map, head->x + size_x, head->y + size_y)) |
755 | if (out_of_map (op->map, head->x + size_x, head->y + size_y)) |
648 | { |
756 | { |
… | |
… | |
674 | /* Wonder if we really want to push all of these, but since |
782 | /* Wonder if we really want to push all of these, but since |
675 | * things like rods have nrof 0, we want to cover those. |
783 | * things like rods have nrof 0, we want to cover those. |
676 | */ |
784 | */ |
677 | dm_stack_push (op->contr, head->count); |
785 | dm_stack_push (op->contr, head->count); |
678 | |
786 | |
679 | if (at->randomitems != NULL && !at_spell) |
787 | if (at->randomitems && !at_spell) |
680 | create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0); |
788 | create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0); |
681 | |
|
|
682 | esrv_send_item (op, head); |
|
|
683 | } |
789 | } |
684 | |
790 | |
685 | /* free the one we used to copy */ |
791 | /* free the one we used to copy */ |
686 | tmp->destroy (); |
792 | tmp->destroy (); |
687 | } |
793 | } |
… | |
… | |
694 | */ |
800 | */ |
695 | |
801 | |
696 | int |
802 | int |
697 | command_inventory (object *op, char *params) |
803 | command_inventory (object *op, char *params) |
698 | { |
804 | { |
|
|
805 | int i; |
699 | object *tmp; |
806 | object *tmp; |
700 | int i; |
|
|
701 | |
807 | |
702 | if (!params) |
808 | if (!params || !sscanf (params, "%d", &i) || !(tmp = find_object (i))) |
703 | { |
809 | { |
704 | inventory (op, NULL); |
810 | op->contr->failmsg ("Inventory of what object (nr)?"); |
705 | return 0; |
811 | return 1; |
706 | } |
|
|
707 | |
|
|
708 | if (!sscanf (params, "%d", &i) || (tmp = find_object (i)) == NULL) |
|
|
709 | { |
812 | } |
710 | new_draw_info (NDI_UNIQUE, 0, op, "Inventory of what object (nr)?"); |
|
|
711 | return 1; |
|
|
712 | } |
|
|
713 | |
813 | |
714 | inventory (op, tmp); |
814 | op->contr->infobox (MSG_CHANNEL ("examine"), tmp->query_inventory (op)); |
|
|
815 | |
715 | return 1; |
816 | return 1; |
716 | } |
817 | } |
717 | |
818 | |
718 | /* just show player's their skills for now. Dm's can |
819 | /* just show player's their skills for now. Dm's can |
719 | * already see skills w/ inventory command - b.t. |
820 | * already see skills w/ inventory command - b.t. |
… | |
… | |
737 | |
838 | |
738 | char *dump = dump_object (tmp); |
839 | char *dump = dump_object (tmp); |
739 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
840 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
740 | free (dump); |
841 | free (dump); |
741 | |
842 | |
742 | if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) |
843 | if (tmp->flag [FLAG_OBJ_ORIGINAL]) |
743 | new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); |
844 | new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); |
744 | |
845 | |
745 | return 1; |
846 | return 1; |
746 | } |
847 | } |
747 | |
848 | |
… | |
… | |
792 | { |
893 | { |
793 | new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
894 | new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
794 | return 1; |
895 | return 1; |
795 | } |
896 | } |
796 | |
897 | |
797 | if (QUERY_FLAG (tmp, FLAG_REMOVED)) |
898 | if (tmp->flag [FLAG_REMOVED]) |
798 | { |
899 | { |
799 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); |
900 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); |
800 | return 1; |
901 | return 1; |
801 | } |
902 | } |
802 | |
903 | |
… | |
… | |
841 | */ |
942 | */ |
842 | int |
943 | int |
843 | command_addexp (object *op, char *params) |
944 | command_addexp (object *op, char *params) |
844 | { |
945 | { |
845 | char buf[MAX_BUF], skill[MAX_BUF]; |
946 | char buf[MAX_BUF], skill[MAX_BUF]; |
846 | int i, q; |
947 | int q; |
|
|
948 | long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure |
847 | object *skillob = NULL; |
949 | object *skillob = NULL; |
848 | |
950 | |
849 | skill[0] = '\0'; |
951 | skill[0] = '\0'; |
850 | if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %d %s", buf, &i, skill)) < 2)) |
952 | if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2)) |
851 | { |
953 | { |
852 | new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); |
954 | new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); |
853 | return 1; |
955 | return 1; |
854 | } |
956 | } |
855 | |
957 | |
… | |
… | |
891 | /**************************************************************************/ |
993 | /**************************************************************************/ |
892 | |
994 | |
893 | int |
995 | int |
894 | command_stats (object *op, char *params) |
996 | command_stats (object *op, char *params) |
895 | { |
997 | { |
896 | char thing[20]; |
|
|
897 | char buf[MAX_BUF]; |
998 | char buf[MAX_BUF]; |
898 | |
999 | |
899 | thing[0] = '\0'; |
1000 | if (params == NULL || params[0] == '\0') |
900 | if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL) |
|
|
901 | { |
1001 | { |
902 | new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
1002 | new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
903 | return 1; |
1003 | return 1; |
904 | } |
1004 | } |
905 | |
1005 | |
906 | for_all_players (pl) |
1006 | for_all_players (pl) |
907 | if (!strcmp (pl->ob->name, thing)) |
1007 | if (!strcmp (&pl->ob->name, params)) |
908 | { |
1008 | { |
909 | sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
1009 | sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
910 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1010 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
911 | sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
1011 | sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
912 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1012 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
… | |
… | |
955 | return 1; |
1055 | return 1; |
956 | } |
1056 | } |
957 | |
1057 | |
958 | for_all_players (pl) |
1058 | for_all_players (pl) |
959 | { |
1059 | { |
960 | if (!strcmp (pl->ob->name, thing)) |
1060 | if (!strcmp (&pl->ob->name, thing)) |
961 | { |
1061 | { |
962 | if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; |
1062 | if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; |
963 | if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; |
1063 | if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; |
964 | if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; |
1064 | if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; |
965 | if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; |
1065 | if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; |
… | |
… | |
977 | new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
1077 | new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
978 | return 1; |
1078 | return 1; |
979 | } |
1079 | } |
980 | |
1080 | |
981 | int |
1081 | int |
982 | command_nowiz (object *op, char *params) |
|
|
983 | { /* 'nodm' is alias */ |
|
|
984 | CLEAR_FLAG (op, FLAG_WIZ); |
|
|
985 | CLEAR_FLAG (op, FLAG_WIZPASS); |
|
|
986 | CLEAR_FLAG (op, FLAG_WIZCAST); |
|
|
987 | |
|
|
988 | if (op->contr->hidden) |
|
|
989 | { |
|
|
990 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); |
|
|
991 | op->map->players++; |
|
|
992 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name); |
|
|
993 | op->contr->hidden = 0; |
|
|
994 | op->invisible = 1; |
|
|
995 | } |
|
|
996 | else |
|
|
997 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); |
|
|
998 | return 1; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | /** |
|
|
1002 | * object *op is trying to become dm. |
|
|
1003 | * pl_name is name supplied by player. Restrictive DM will make it harder |
|
|
1004 | * for socket users to become DM - in that case, it will check for the players |
|
|
1005 | * character name. |
|
|
1006 | */ |
|
|
1007 | static int |
|
|
1008 | checkdm (object *op, const char *pl_name, const char *pl_passwd, const char *pl_host) |
|
|
1009 | { |
|
|
1010 | FILE *dmfile; |
|
|
1011 | char buf[MAX_BUF]; |
|
|
1012 | char line_buf[160], name[160], passwd[160], host[160]; |
|
|
1013 | |
|
|
1014 | #ifdef RESTRICTIVE_DM |
|
|
1015 | *pl_name = op->name ? op->name : "*"; |
|
|
1016 | #endif |
|
|
1017 | |
|
|
1018 | sprintf (buf, "%s/%s", settings.confdir, DMFILE); |
|
|
1019 | if ((dmfile = fopen (buf, "r")) == NULL) |
|
|
1020 | { |
|
|
1021 | LOG (llevDebug, "Could not find DM file.\n"); |
|
|
1022 | return 0; |
|
|
1023 | } |
|
|
1024 | |
|
|
1025 | while (fgets (line_buf, 160, dmfile) != NULL) |
|
|
1026 | { |
|
|
1027 | if (line_buf[0] == '#') |
|
|
1028 | continue; |
|
|
1029 | if (sscanf (line_buf, "%[^:]:%[^:]:%s\n", name, passwd, host) != 3) |
|
|
1030 | { |
|
|
1031 | LOG (llevError, "Warning - malformed dm file entry: %s\n", line_buf); |
|
|
1032 | } |
|
|
1033 | else if ((!strcmp (name, "*") || (pl_name && !strcmp (pl_name, name))) |
|
|
1034 | && (!strcmp (passwd, "*") || !strcmp (passwd, pl_passwd)) && (!strcmp (host, "*") || !strcmp (host, pl_host))) |
|
|
1035 | { |
|
|
1036 | fclose (dmfile); |
|
|
1037 | return (1); |
|
|
1038 | } |
|
|
1039 | } |
|
|
1040 | fclose (dmfile); |
|
|
1041 | return (0); |
|
|
1042 | } |
|
|
1043 | |
|
|
1044 | int |
|
|
1045 | do_wizard_dm (object *op, char *params, int silent) |
|
|
1046 | { |
|
|
1047 | if (!op->contr) |
|
|
1048 | return 0; |
|
|
1049 | |
|
|
1050 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
1051 | { |
|
|
1052 | new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); |
|
|
1053 | return 0; |
|
|
1054 | } |
|
|
1055 | |
|
|
1056 | if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) |
|
|
1057 | { |
|
|
1058 | SET_FLAG (op, FLAG_WIZ); |
|
|
1059 | SET_FLAG (op, FLAG_WIZPASS); |
|
|
1060 | SET_FLAG (op, FLAG_WIZCAST); |
|
|
1061 | |
|
|
1062 | new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); |
|
|
1063 | /* |
|
|
1064 | * Remove setting flying here - that won't work, because next |
|
|
1065 | * fix_player() is called that will get cleared - proper solution |
|
|
1066 | * is probably something like a wiz_force which gives that and any |
|
|
1067 | * other desired abilities. |
|
|
1068 | */ |
|
|
1069 | clear_los (op->contr); |
|
|
1070 | op->contr->write_buf[0] = '\0'; |
|
|
1071 | |
|
|
1072 | if (!silent) |
|
|
1073 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); |
|
|
1074 | |
|
|
1075 | return 1; |
|
|
1076 | } |
|
|
1077 | else |
|
|
1078 | { |
|
|
1079 | new_draw_info (NDI_UNIQUE, 0, op, "Sorry Pal, I don't think so."); |
|
|
1080 | op->contr->write_buf[0] = '\0'; |
|
|
1081 | return 0; |
|
|
1082 | } |
|
|
1083 | } |
|
|
1084 | |
|
|
1085 | /* |
|
|
1086 | * Actual command to perhaps become dm. Changed aroun a bit in version 0.92.2 |
|
|
1087 | * - allow people on sockets to become dm, and allow better dm file |
|
|
1088 | */ |
|
|
1089 | int |
|
|
1090 | command_dm (object *op, char *params) |
|
|
1091 | { |
|
|
1092 | if (!op->contr) |
|
|
1093 | return 0; |
|
|
1094 | |
|
|
1095 | do_wizard_dm (op, params, 0); |
|
|
1096 | |
|
|
1097 | return 1; |
|
|
1098 | } |
|
|
1099 | |
|
|
1100 | int |
|
|
1101 | command_invisible (object *op, char *params) |
1082 | command_invisible (object *op, char *params) |
1102 | { |
1083 | { |
1103 | if (op) |
1084 | if (op) |
1104 | { |
1085 | { |
1105 | op->invisible += 100; |
1086 | op->invisible += TIME2TICK (60); |
1106 | update_object (op, UP_OBJ_CHANGE); |
1087 | update_object (op, UP_OBJ_CHANGE); |
1107 | new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); |
1088 | new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); |
1108 | } |
1089 | } |
1109 | |
1090 | |
1110 | return 0; |
1091 | return 0; |
… | |
… | |
1114 | * Returns spell object (from archetypes) by name. |
1095 | * Returns spell object (from archetypes) by name. |
1115 | * Returns NULL if 0 or more than one spell matches. |
1096 | * Returns NULL if 0 or more than one spell matches. |
1116 | * Used for wizard's learn spell/prayer. |
1097 | * Used for wizard's learn spell/prayer. |
1117 | * |
1098 | * |
1118 | * op is the player issuing the command. |
1099 | * op is the player issuing the command. |
1119 | * |
|
|
1120 | * Ignores archetypes "spelldirect_xxx" since these archetypes are not used |
|
|
1121 | * anymore (but may still be present in some player's inventories and thus |
|
|
1122 | * cannot be removed). We have to ignore them here since they have the same |
|
|
1123 | * name than other "spell_xxx" archetypes and would always conflict. |
|
|
1124 | */ |
1100 | */ |
1125 | static object * |
1101 | static object * |
1126 | get_spell_by_name (object *op, const char *spell_name) |
1102 | get_spell_by_name (object *op, shstr_cmp spell_name) |
1127 | { |
1103 | { |
1128 | archetype *at; |
|
|
1129 | archetype *found; |
|
|
1130 | int conflict_found; |
|
|
1131 | size_t spell_name_length; |
|
|
1132 | |
|
|
1133 | /* First check for full name matches. */ |
1104 | /* First check for full name matches. */ |
1134 | conflict_found = 0; |
1105 | int conflict_found = 0; |
1135 | found = NULL; |
1106 | archetype *found = 0; |
|
|
1107 | |
1136 | for_all_archetypes (at) |
1108 | for_all_archetypes (at) |
1137 | { |
1109 | { |
1138 | if (at->type != SPELL) |
1110 | if (at->type != SPELL) |
1139 | continue; |
1111 | continue; |
1140 | |
1112 | |
1141 | if (strncmp (at->archname, "spelldirect_", 12) == 0) |
1113 | if (at->object::name != spell_name) |
1142 | continue; |
1114 | continue; |
1143 | |
1115 | |
1144 | if (strcmp (at->object::name, spell_name) != 0) |
|
|
1145 | continue; |
|
|
1146 | |
|
|
1147 | if (found != NULL) |
1116 | if (found) |
1148 | { |
1117 | { |
1149 | if (!conflict_found) |
1118 | if (!conflict_found) |
1150 | { |
1119 | { |
1151 | conflict_found = 1; |
1120 | conflict_found = 1; |
1152 | new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); |
1121 | new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name); |
1153 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); |
1122 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); |
1154 | } |
1123 | } |
1155 | |
1124 | |
1156 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); |
1125 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); |
1157 | continue; |
1126 | return 0; |
1158 | } |
1127 | } |
1159 | |
1128 | |
1160 | found = at; |
1129 | found = at; |
1161 | } |
1130 | } |
1162 | |
1131 | |
1163 | /* No match if more more than one archetype matches. */ |
|
|
1164 | if (conflict_found) |
|
|
1165 | return NULL; |
|
|
1166 | |
|
|
1167 | /* Return if exactly one archetype matches. */ |
1132 | /* Return if exactly one archetype matches. */ |
1168 | if (found != NULL) |
1133 | if (found) |
1169 | return arch_to_object (found); |
1134 | return found->instance (); |
1170 | |
|
|
1171 | /* No full match found: now check for partial matches. */ |
|
|
1172 | spell_name_length = strlen (spell_name); |
|
|
1173 | conflict_found = 0; |
|
|
1174 | found = NULL; |
|
|
1175 | for_all_archetypes (at) |
|
|
1176 | { |
|
|
1177 | if (at->type != SPELL) |
|
|
1178 | continue; |
|
|
1179 | |
|
|
1180 | if (strncmp (at->archname, "spelldirect_", 12) == 0) |
|
|
1181 | continue; |
|
|
1182 | |
|
|
1183 | if (strncmp (at->object::name, spell_name, spell_name_length) != 0) |
|
|
1184 | continue; |
|
|
1185 | |
|
|
1186 | if (found != NULL) |
|
|
1187 | { |
|
|
1188 | if (!conflict_found) |
|
|
1189 | { |
|
|
1190 | conflict_found = 1; |
|
|
1191 | new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name); |
|
|
1192 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->object::name); |
|
|
1193 | } |
|
|
1194 | new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->object::name); |
|
|
1195 | continue; |
|
|
1196 | } |
|
|
1197 | |
|
|
1198 | found = at; |
|
|
1199 | } |
|
|
1200 | |
|
|
1201 | /* No match if more more than one archetype matches. */ |
|
|
1202 | if (conflict_found) |
|
|
1203 | return NULL; |
|
|
1204 | |
|
|
1205 | /* Return if exactly one archetype matches. */ |
|
|
1206 | if (found != NULL) |
|
|
1207 | return arch_to_object (found); |
|
|
1208 | |
1135 | |
1209 | /* No spell found: just print an error message. */ |
1136 | /* No spell found: just print an error message. */ |
1210 | new_draw_info_format (NDI_UNIQUE, 0, op, "The spell %s does not exist.", spell_name); |
1137 | new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist."); |
|
|
1138 | |
1211 | return NULL; |
1139 | return 0; |
1212 | } |
1140 | } |
1213 | |
1141 | |
1214 | static int |
1142 | static int |
1215 | command_learn_spell_or_prayer (object *op, char *params, int special_prayer) |
1143 | command_learn_spell_or_prayer (object *op, char *params, int special_prayer) |
1216 | { |
1144 | { |
… | |
… | |
1260 | { |
1188 | { |
1261 | new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); |
1189 | new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); |
1262 | return 0; |
1190 | return 0; |
1263 | } |
1191 | } |
1264 | |
1192 | |
1265 | spell = lookup_spell_by_name (op, params); |
1193 | spell = op->find_spell (params); |
1266 | if (spell == NULL) |
1194 | if (spell == NULL) |
1267 | { |
1195 | { |
1268 | new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); |
1196 | new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); |
1269 | return 0; |
1197 | return 0; |
1270 | } |
1198 | } |
1271 | |
1199 | |
1272 | do_forget_spell (op, spell->name); |
1200 | do_forget_spell (op, spell->name); |
1273 | return 1; |
1201 | return 1; |
1274 | } |
|
|
1275 | |
|
|
1276 | /** |
|
|
1277 | * Lists all plugins currently loaded with their IDs and full names. |
|
|
1278 | */ |
|
|
1279 | int |
|
|
1280 | command_listplugins (object *op, char *params) |
|
|
1281 | { |
|
|
1282 | plugins_display_list (op); |
|
|
1283 | return 1; |
|
|
1284 | } |
|
|
1285 | |
|
|
1286 | /** |
|
|
1287 | * Loads the given plugin. The DM specifies the name of the library to load (no |
|
|
1288 | * pathname is needed). Do not ever attempt to load the same plugin more than |
|
|
1289 | * once at a time, or bad things could happen. |
|
|
1290 | */ |
|
|
1291 | int |
|
|
1292 | command_loadplugin (object *op, char *params) |
|
|
1293 | { |
|
|
1294 | char buf[MAX_BUF]; |
|
|
1295 | |
|
|
1296 | if (params == NULL) |
|
|
1297 | { |
|
|
1298 | new_draw_info (NDI_UNIQUE, 0, op, "Load which plugin?"); |
|
|
1299 | return 1; |
|
|
1300 | } |
|
|
1301 | |
|
|
1302 | strcpy (buf, LIBDIR); |
|
|
1303 | strcat (buf, "/plugins/"); |
|
|
1304 | strcat (buf, params); |
|
|
1305 | LOG (llevDebug, "Requested plugin file is %s\n", buf); |
|
|
1306 | if (plugins_init_plugin (buf) == 0) |
|
|
1307 | new_draw_info (NDI_UNIQUE, 0, op, "Plugin successfully loaded."); |
|
|
1308 | else |
|
|
1309 | new_draw_info (NDI_UNIQUE, 0, op, "Could not load plugin."); |
|
|
1310 | return 1; |
|
|
1311 | } |
|
|
1312 | |
|
|
1313 | /** |
|
|
1314 | * Unloads the given plugin. The DM specified the ID of the library to unload. |
|
|
1315 | * Note that some things may behave strangely if the correct plugins are not |
|
|
1316 | * loaded. |
|
|
1317 | */ |
|
|
1318 | int |
|
|
1319 | command_unloadplugin (object *op, char *params) |
|
|
1320 | { |
|
|
1321 | if (params == NULL) |
|
|
1322 | { |
|
|
1323 | new_draw_info (NDI_UNIQUE, 0, op, "Remove which plugin?"); |
|
|
1324 | return 1; |
|
|
1325 | } |
|
|
1326 | |
|
|
1327 | if (plugins_remove_plugin (params) == 0) |
|
|
1328 | new_draw_info (NDI_UNIQUE, 0, op, "Plugin successfully removed."); |
|
|
1329 | else |
|
|
1330 | new_draw_info (NDI_UNIQUE, 0, op, "Could not remove plugin."); |
|
|
1331 | return 1; |
|
|
1332 | } |
|
|
1333 | |
|
|
1334 | /** |
|
|
1335 | * A players wants to become DM and hide. |
|
|
1336 | * Let's see if that's authorized. |
|
|
1337 | * Make sure to not tell anything to anyone. |
|
|
1338 | */ |
|
|
1339 | int |
|
|
1340 | command_dmhide (object *op, char *params) |
|
|
1341 | { |
|
|
1342 | if (!do_wizard_dm (op, params, 1)) |
|
|
1343 | return 0; |
|
|
1344 | |
|
|
1345 | do_wizard_hide (op, 1); |
|
|
1346 | |
|
|
1347 | return 1; |
|
|
1348 | } |
|
|
1349 | |
|
|
1350 | void |
|
|
1351 | dm_stack_pop (player *pl) |
|
|
1352 | { |
|
|
1353 | if (!pl->stack_items || !pl->stack_position) |
|
|
1354 | { |
|
|
1355 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!"); |
|
|
1356 | return; |
|
|
1357 | } |
|
|
1358 | |
|
|
1359 | pl->stack_position--; |
|
|
1360 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position); |
|
|
1361 | } |
|
|
1362 | |
|
|
1363 | /** |
|
|
1364 | * Get current stack top item for player. |
|
|
1365 | * Returns NULL if no stacked item. |
|
|
1366 | * If stacked item disappeared (freed), remove it. |
|
|
1367 | * |
|
|
1368 | * Ryo, august 2004 |
|
|
1369 | */ |
|
|
1370 | object * |
|
|
1371 | dm_stack_peek (player *pl) |
|
|
1372 | { |
|
|
1373 | object *ob; |
|
|
1374 | |
|
|
1375 | if (!pl->stack_position) |
|
|
1376 | { |
|
|
1377 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!"); |
|
|
1378 | return NULL; |
|
|
1379 | } |
|
|
1380 | |
|
|
1381 | ob = find_object (pl->stack_items[pl->stack_position - 1]); |
|
|
1382 | if (!ob) |
|
|
1383 | { |
|
|
1384 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!"); |
|
|
1385 | dm_stack_pop (pl); |
|
|
1386 | return NULL; |
|
|
1387 | } |
|
|
1388 | |
|
|
1389 | return ob; |
|
|
1390 | } |
|
|
1391 | |
|
|
1392 | /** |
|
|
1393 | * Push specified item on player stack. |
|
|
1394 | * Inform player of position. |
|
|
1395 | * Initializes variables if needed. |
|
|
1396 | */ |
|
|
1397 | void |
|
|
1398 | dm_stack_push (player *pl, tag_t item) |
|
|
1399 | { |
|
|
1400 | if (!pl->stack_items) |
|
|
1401 | { |
|
|
1402 | pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE); |
|
|
1403 | memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE); |
|
|
1404 | } |
|
|
1405 | |
|
|
1406 | if (pl->stack_position == STACK_SIZE) |
|
|
1407 | { |
|
|
1408 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!"); |
|
|
1409 | return; |
|
|
1410 | } |
|
|
1411 | |
|
|
1412 | pl->stack_items[pl->stack_position] = item; |
|
|
1413 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position); |
|
|
1414 | pl->stack_position++; |
|
|
1415 | } |
|
|
1416 | |
|
|
1417 | /** |
|
|
1418 | * Checks 'params' for object code. |
|
|
1419 | * |
|
|
1420 | * Can be: |
|
|
1421 | * * empty => get current object stack top for player |
|
|
1422 | * * number => get item with that tag, stack it for future use |
|
|
1423 | * * $number => get specified stack item |
|
|
1424 | * * "me" => player himself |
|
|
1425 | * |
|
|
1426 | * At function exit, params points to first non-object char |
|
|
1427 | * |
|
|
1428 | * 'from', if not NULL, contains at exit: |
|
|
1429 | * * STACK_FROM_NONE => object not found |
|
|
1430 | * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty |
|
|
1431 | * * STACK_FROM_STACK => item from somewhere in the stack |
|
|
1432 | * * STACK_FROM_NUMBER => item by number, pushed on stack |
|
|
1433 | * |
|
|
1434 | * Ryo, august 2004 |
|
|
1435 | */ |
|
|
1436 | object * |
|
|
1437 | get_dm_object (player *pl, char **params, int *from) |
|
|
1438 | { |
|
|
1439 | int item_tag, item_position; |
|
|
1440 | object *ob; |
|
|
1441 | |
|
|
1442 | if (!pl) |
|
|
1443 | return NULL; |
|
|
1444 | |
|
|
1445 | if (!params || !*params || **params == '\0') |
|
|
1446 | { |
|
|
1447 | if (from) |
|
|
1448 | *from = STACK_FROM_TOP; |
|
|
1449 | /* No parameter => get stack item */ |
|
|
1450 | return dm_stack_peek (pl); |
|
|
1451 | } |
|
|
1452 | |
|
|
1453 | /* Let's clean white spaces */ |
|
|
1454 | while (**params == ' ') |
|
|
1455 | (*params)++; |
|
|
1456 | |
|
|
1457 | /* Next case: number => item tag */ |
|
|
1458 | if (sscanf (*params, "%d", &item_tag)) |
|
|
1459 | { |
|
|
1460 | /* Move parameter to next item */ |
|
|
1461 | while (isdigit (**params)) |
|
|
1462 | (*params)++; |
|
|
1463 | |
|
|
1464 | /* And skip blanks, too */ |
|
|
1465 | while (**params == ' ') |
|
|
1466 | (*params)++; |
|
|
1467 | |
|
|
1468 | /* Get item */ |
|
|
1469 | ob = find_object (item_tag); |
|
|
1470 | if (!ob) |
|
|
1471 | { |
|
|
1472 | if (from) |
|
|
1473 | *from = STACK_FROM_NONE; |
|
|
1474 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag); |
|
|
1475 | return NULL; |
|
|
1476 | } |
|
|
1477 | |
|
|
1478 | /* Got one, let's push it on stack */ |
|
|
1479 | dm_stack_push (pl, item_tag); |
|
|
1480 | if (from) |
|
|
1481 | *from = STACK_FROM_NUMBER; |
|
|
1482 | return ob; |
|
|
1483 | } |
|
|
1484 | |
|
|
1485 | /* Next case: $number => stack item */ |
|
|
1486 | if (sscanf (*params, "$%d", &item_position)) |
|
|
1487 | { |
|
|
1488 | /* Move parameter to next item */ |
|
|
1489 | (*params)++; |
|
|
1490 | |
|
|
1491 | while (isdigit (**params)) |
|
|
1492 | (*params)++; |
|
|
1493 | while (**params == ' ') |
|
|
1494 | (*params)++; |
|
|
1495 | |
|
|
1496 | if (item_position >= pl->stack_position) |
|
|
1497 | { |
|
|
1498 | if (from) |
|
|
1499 | *from = STACK_FROM_NONE; |
|
|
1500 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position); |
|
|
1501 | return NULL; |
|
|
1502 | } |
|
|
1503 | |
|
|
1504 | ob = find_object (pl->stack_items[item_position]); |
|
|
1505 | if (!ob) |
|
|
1506 | { |
|
|
1507 | if (from) |
|
|
1508 | *from = STACK_FROM_NONE; |
|
|
1509 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position); |
|
|
1510 | return NULL; |
|
|
1511 | } |
|
|
1512 | |
|
|
1513 | if (from) |
|
|
1514 | *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP; |
|
|
1515 | return ob; |
|
|
1516 | } |
|
|
1517 | |
|
|
1518 | /* Next case: 'me' => return pl->ob */ |
|
|
1519 | if (!strncmp (*params, "me", 2)) |
|
|
1520 | { |
|
|
1521 | if (from) |
|
|
1522 | *from = STACK_FROM_NUMBER; |
|
|
1523 | dm_stack_push (pl, pl->ob->count); |
|
|
1524 | |
|
|
1525 | /* Skip to next token */ |
|
|
1526 | (*params) += 2; |
|
|
1527 | while (**params == ' ') |
|
|
1528 | (*params)++; |
|
|
1529 | |
|
|
1530 | return pl->ob; |
|
|
1531 | } |
|
|
1532 | |
|
|
1533 | /* Last case: get stack top */ |
|
|
1534 | if (from) |
|
|
1535 | *from = STACK_FROM_TOP; |
|
|
1536 | return dm_stack_peek (pl); |
|
|
1537 | } |
1202 | } |
1538 | |
1203 | |
1539 | /** |
1204 | /** |
1540 | * Pop the stack top. |
1205 | * Pop the stack top. |
1541 | */ |
1206 | */ |
… | |
… | |
1601 | } |
1266 | } |
1602 | |
1267 | |
1603 | int |
1268 | int |
1604 | command_insert_into (object *op, char *params) |
1269 | command_insert_into (object *op, char *params) |
1605 | { |
1270 | { |
1606 | object *left, *right, *inserted; |
1271 | object *left, *right; |
1607 | int left_from, right_from; |
1272 | int left_from, right_from; |
1608 | |
1273 | |
1609 | left = get_dm_object (op->contr, ¶ms, &left_from); |
1274 | left = get_dm_object (op->contr, ¶ms, &left_from); |
1610 | if (!left) |
1275 | if (!left) |
1611 | { |
1276 | { |
… | |
… | |
1654 | { |
1319 | { |
1655 | new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1320 | new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1656 | return 0; |
1321 | return 0; |
1657 | } |
1322 | } |
1658 | |
1323 | |
1659 | if (!QUERY_FLAG (right, FLAG_REMOVED)) |
1324 | if (!right->flag [FLAG_REMOVED]) |
1660 | right->remove (); |
1325 | right->remove (); |
|
|
1326 | |
1661 | inserted = insert_ob_in_ob (right, left); |
1327 | object *inserted = insert_ob_in_ob (right, left); |
1662 | if (left->type == PLAYER) |
|
|
1663 | if (inserted == right) |
|
|
1664 | esrv_send_item (left, right); |
|
|
1665 | else |
|
|
1666 | esrv_update_item (UPD_WEIGHT | UPD_NAME | UPD_NROF, left, inserted); |
|
|
1667 | |
1328 | |
1668 | new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); |
1329 | new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); |
1669 | |
1330 | |
1670 | return 0; |
1331 | return 0; |
1671 | |
1332 | |