1 |
/* |
2 |
* static char *rcsid_c_wiz_c = |
3 |
* "$Id$"; |
4 |
*/ |
5 |
|
6 |
/* |
7 |
CrossFire, A Multiplayer game for X-windows |
8 |
|
9 |
Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
10 |
Copyright (C) 1992 Frank Tore Johansen |
11 |
|
12 |
This program is free software; you can redistribute it and/or modify |
13 |
it under the terms of the GNU General Public License as published by |
14 |
the Free Software Foundation; either version 2 of the License, or |
15 |
(at your option) any later version. |
16 |
|
17 |
This program is distributed in the hope that it will be useful, |
18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 |
GNU General Public License for more details. |
21 |
|
22 |
You should have received a copy of the GNU General Public License |
23 |
along with this program; if not, write to the Free Software |
24 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
25 |
|
26 |
The authors can be reached via e-mail at crossfire-devel@real-time.com |
27 |
*/ |
28 |
|
29 |
#include <global.h> |
30 |
#ifndef __CEXTRACT__ |
31 |
#include <sproto.h> |
32 |
#endif |
33 |
#include <spells.h> |
34 |
#include <treasure.h> |
35 |
#include <skills.h> |
36 |
|
37 |
/** Defines for DM item stack **/ |
38 |
#define STACK_SIZE 50 /* Stack size, static */ |
39 |
/* Values for 'from' field of get_dm_object */ |
40 |
#define STACK_FROM_NONE 0 /* Item was not found */ |
41 |
#define STACK_FROM_TOP 1 /* Item is stack top */ |
42 |
#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ |
43 |
#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ |
44 |
|
45 |
|
46 |
/** |
47 |
* Enough of the DM functions seem to need this that I broke |
48 |
* it out to a seperate function. name is the person |
49 |
* being saught, rq is who is looking for them. This |
50 |
* prints diagnostics messages, and returns the |
51 |
* other player, or NULL otherwise. |
52 |
*/ |
53 |
static player *get_other_player_from_name(object *op, char *name) { |
54 |
player *pl; |
55 |
|
56 |
if (!name) |
57 |
return NULL; |
58 |
|
59 |
for (pl = first_player; pl != NULL; pl = pl->next) |
60 |
if (!strncmp(pl->ob->name, name, MAX_NAME)) |
61 |
break; |
62 |
|
63 |
if (pl == NULL) { |
64 |
new_draw_info(NDI_UNIQUE, 0, op, "No such player."); |
65 |
return NULL; |
66 |
} |
67 |
|
68 |
if (pl->ob == op) { |
69 |
new_draw_info(NDI_UNIQUE, 0, op, "You can't do that to yourself."); |
70 |
return NULL; |
71 |
} |
72 |
if (pl->state != ST_PLAYING) { |
73 |
new_draw_info(NDI_UNIQUE, 0, op, "That player is in no state for that right now."); |
74 |
return NULL; |
75 |
} |
76 |
return pl; |
77 |
} |
78 |
|
79 |
/** |
80 |
* This command will stress server. |
81 |
*/ |
82 |
int command_loadtest(object *op, char *params) { |
83 |
uint32 x, y; |
84 |
char buf[1024]; |
85 |
|
86 |
new_draw_info(NDI_UNIQUE, 0, op, "loadtest will stress server through teleporting"); |
87 |
new_draw_info(NDI_UNIQUE, 0, op, "at different map places."); |
88 |
new_draw_info(NDI_UNIQUE, 0, op, "use at your own risks."); |
89 |
new_draw_info(NDI_UNIQUE, 0, op, "Very long loop used so server may have to be reset."); |
90 |
new_draw_info(NDI_UNIQUE, 0, op, "type loadtest TRUE to run"); |
91 |
new_draw_info_format(NDI_UNIQUE, 0, op, "{%s}", params); |
92 |
if (!params) |
93 |
return 0; |
94 |
if (strncmp (params, "TRUE", 4)) |
95 |
return 0; |
96 |
|
97 |
new_draw_info_format(NDI_UNIQUE, 0, op, "gogogo"); |
98 |
for (x = 0; x < settings.worldmaptilesx; x++) { |
99 |
for (y = 0; y < settings.worldmaptilesy; y++) { |
100 |
sprintf(buf, "/world/world_%d_%d", x+settings.worldmapstartx, y+settings.worldmapstarty); |
101 |
command_goto(op, buf); |
102 |
} |
103 |
} |
104 |
|
105 |
return 0; |
106 |
} |
107 |
|
108 |
/** |
109 |
* Actually hides specified player (obviously a DM). |
110 |
* If 'silent_dm' is non zero, other players are informed of DM entering/leaving, |
111 |
* else they just think someone left/entered. |
112 |
*/ |
113 |
void do_wizard_hide(object *op, int silent_dm) { |
114 |
if (op->contr->hidden) { |
115 |
op->contr->hidden = 0; |
116 |
op->invisible = 1; |
117 |
new_draw_info(NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); |
118 |
op->map->players++; |
119 |
new_draw_info_format(NDI_UNIQUE|NDI_ALL|NDI_DK_ORANGE, 5, NULL, |
120 |
"%s has entered the game.", op->name); |
121 |
if (!silent_dm) { |
122 |
new_draw_info(NDI_UNIQUE|NDI_ALL|NDI_LT_GREEN, 1, NULL, |
123 |
"The Dungeon Master has arrived!"); |
124 |
} |
125 |
} else { |
126 |
op->contr->hidden = 1; |
127 |
new_draw_info(NDI_UNIQUE, 0, op, "Other players will no longer see you."); |
128 |
op->map->players--; |
129 |
if (!silent_dm) { |
130 |
new_draw_info(NDI_UNIQUE|NDI_ALL|NDI_LT_GREEN, 1, NULL, |
131 |
"The Dungeon Master is gone.."); |
132 |
} |
133 |
new_draw_info_format(NDI_UNIQUE|NDI_ALL|NDI_DK_ORANGE, 5, NULL, |
134 |
"%s leaves the game.", op->name); |
135 |
new_draw_info_format(NDI_UNIQUE|NDI_ALL|NDI_DK_ORANGE, 5, NULL, |
136 |
"%s left the game.", op->name); |
137 |
} |
138 |
} |
139 |
|
140 |
int command_hide(object *op, char *params) |
141 |
{ |
142 |
do_wizard_hide(op, 0); |
143 |
return 1; |
144 |
} |
145 |
|
146 |
/** |
147 |
* This finds and returns the object which matches the name or |
148 |
* object nubmer (specified via num #whatever). |
149 |
*/ |
150 |
static object *find_object_both(char *params) { |
151 |
if (!params) |
152 |
return NULL; |
153 |
if (params[0] == '#') |
154 |
return find_object(atol(params+1)); |
155 |
else |
156 |
return find_object_name(params); |
157 |
} |
158 |
|
159 |
/** |
160 |
* Sets the god for some objects. params should contain two values - |
161 |
* first the object to change, followed by the god to change it to. |
162 |
*/ |
163 |
int command_setgod(object *op, char *params) { |
164 |
object *ob, *god; |
165 |
char *str; |
166 |
|
167 |
if (!params || !(str = strchr(params, ' '))) { |
168 |
new_draw_info(NDI_UNIQUE, 0, op, "Usage: setgod object god"); |
169 |
return 0; |
170 |
} |
171 |
|
172 |
/* kill the space, and set string to the next param */ |
173 |
*str++ = '\0'; |
174 |
if (!(ob = find_object_both(params))) { |
175 |
new_draw_info_format(NDI_UNIQUE, 0, op, "Set whose god - can not find object %s?", params); |
176 |
return 1; |
177 |
} |
178 |
|
179 |
/* |
180 |
* Perhaps this is overly restrictive? Should we perhaps be able |
181 |
* to rebless altars and the like? |
182 |
*/ |
183 |
if (ob->type != PLAYER) { |
184 |
new_draw_info_format(NDI_UNIQUE, 0, op, "%s is not a player - can not change its god", ob->name); |
185 |
return 1; |
186 |
} |
187 |
|
188 |
god = find_god(str); |
189 |
if (god==NULL) { |
190 |
new_draw_info_format(NDI_UNIQUE, 0, op, "No such god %s.", str); |
191 |
return 1; |
192 |
} |
193 |
|
194 |
become_follower(ob, god); |
195 |
return 1; |
196 |
} |
197 |
|
198 |
/** |
199 |
* Add player's IP to ban_file and kick them off the server |
200 |
* I know most people have dynamic IPs but this is more of a short term |
201 |
* solution if they have to get a new IP to play maybe they'll calm down. |
202 |
* This uses the banish_file in the local directory *not* the ban_file |
203 |
* The action is logged with a ! for easy searching. -tm |
204 |
*/ |
205 |
int command_banish(object *op, char *params) { |
206 |
player *pl; |
207 |
FILE *banishfile; |
208 |
char buf[MAX_BUF]; |
209 |
time_t now; |
210 |
|
211 |
if (!params) { |
212 |
new_draw_info(NDI_UNIQUE, 0, op, "Usage: banish <player>."); |
213 |
return 1; |
214 |
} |
215 |
|
216 |
pl = get_other_player_from_name(op, params); |
217 |
if (!pl) |
218 |
return 1; |
219 |
|
220 |
sprintf(buf, "%s/%s", settings.localdir, BANISHFILE); |
221 |
|
222 |
if ((banishfile = fopen(buf, "a")) == NULL) { |
223 |
LOG (llevDebug, "Could not find file banish_file.\n"); |
224 |
new_draw_info(NDI_UNIQUE, 0, op, "Could not find banish_file."); |
225 |
return 0; |
226 |
} |
227 |
|
228 |
now = time(NULL); |
229 |
/* |
230 |
* Record this as a comment - then we don't have to worry about changing |
231 |
* the parsing code. |
232 |
*/ |
233 |
fprintf(banishfile, "# %s (%s) banned by %s at %s\n", pl->ob->name, |
234 |
pl->socket.host, op->name, ctime(&now)); |
235 |
fprintf(banishfile, "*@%s\n", pl->socket.host); |
236 |
fclose(banishfile); |
237 |
|
238 |
LOG(llevDebug, "! %s banned %s from IP: %s.\n", op->name, pl->ob->name, pl->socket.host); |
239 |
new_draw_info_format(NDI_UNIQUE|NDI_RED, 0, op, "You banish %s", pl->ob->name); |
240 |
new_draw_info_format(NDI_UNIQUE|NDI_ALL|NDI_RED, 5, op, |
241 |
"%s banishes %s from the land!", op->name, pl->ob->name); |
242 |
command_kick(op, pl->ob->name); |
243 |
return 1; |
244 |
} |
245 |
|
246 |
int |
247 |
command_kick (object *op, char *params) |
248 |
{ |
249 |
struct pl *pl; |
250 |
|
251 |
for (pl = first_player; pl != NULL; pl = pl->next) |
252 |
if (params == NULL || !strcmp (pl->ob->name, params)) |
253 |
{ |
254 |
object *op = pl->ob; |
255 |
|
256 |
if (!QUERY_FLAG (op, FLAG_REMOVED) && !QUERY_FLAG (op, FLAG_FREED)) |
257 |
{ |
258 |
/* Avion : Here we handle the KICK global event */ |
259 |
execute_global_event (EVENT_KICK, op, params); |
260 |
|
261 |
new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, |
262 |
"%s is kicked out of the game.", |
263 |
op->name); |
264 |
strcpy (op->contr->killer, "kicked"); |
265 |
} |
266 |
|
267 |
pl->socket.status = Ns_Dead; |
268 |
} |
269 |
|
270 |
return 1; |
271 |
} |
272 |
|
273 |
int command_save_overlay(object *op, char *params) { |
274 |
if (!op) |
275 |
return 0; |
276 |
|
277 |
if (op != NULL && !QUERY_FLAG(op, FLAG_WIZ)) { |
278 |
new_draw_info(NDI_UNIQUE, 0, op, |
279 |
"Sorry, you can't force an overlay save."); |
280 |
return 1; |
281 |
} |
282 |
|
283 |
new_save_map(op->map, 2); |
284 |
new_save_map(op->map, 0); |
285 |
new_draw_info(NDI_UNIQUE, 0, op, "Current map has been saved as an" |
286 |
" overlay."); |
287 |
|
288 |
ready_map_name(op->map->path, 0); |
289 |
|
290 |
return 1; |
291 |
} |
292 |
|
293 |
/* |
294 |
* A simple toggle for the no_shout field. |
295 |
* AKA the MUZZLE command |
296 |
*/ |
297 |
int command_toggle_shout(object *op, char *params) { |
298 |
player *pl; |
299 |
|
300 |
if (!params) { |
301 |
new_draw_info(NDI_UNIQUE, 0, op, "Usage: toggle_shout <player>."); |
302 |
return 1; |
303 |
} |
304 |
|
305 |
pl = get_other_player_from_name(op, params); |
306 |
if (!pl) |
307 |
return 1; |
308 |
|
309 |
if (pl->ob->contr->no_shout == 0) { |
310 |
pl->ob->contr->no_shout = 1; |
311 |
|
312 |
new_draw_info(NDI_UNIQUE|NDI_RED, 0, pl->ob, "You have been muzzled by the DM!"); |
313 |
new_draw_info_format(NDI_UNIQUE, 0, op, "You muzzle %s.", pl->ob->name); |
314 |
|
315 |
/* Avion : Here we handle the MUZZLE global event */ |
316 |
execute_global_event(EVENT_MUZZLE, pl->ob, params); |
317 |
|
318 |
return 1; |
319 |
} else { |
320 |
pl->ob->contr->no_shout = 0; |
321 |
new_draw_info(NDI_UNIQUE|NDI_ORANGE, 0, pl->ob, |
322 |
"You are allowed to shout and chat again."); |
323 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
324 |
"You remove %s's muzzle.", pl->ob->name); |
325 |
return 1; |
326 |
} |
327 |
} |
328 |
|
329 |
int |
330 |
command_shutdown (object * op, char *params) |
331 |
{ |
332 |
struct pl *pl; |
333 |
|
334 |
if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) |
335 |
{ |
336 |
new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't shutdown the server."); |
337 |
return 1; |
338 |
} |
339 |
|
340 |
for (pl = first_player; pl != NULL; pl = pl->next) |
341 |
save_player (pl->ob, 0); |
342 |
|
343 |
cleanup (); |
344 |
/* not reached */ |
345 |
return 1; |
346 |
} |
347 |
|
348 |
int command_goto(object *op, char *params) |
349 |
{ |
350 |
char *name; |
351 |
object *dummy; |
352 |
|
353 |
if (!op) |
354 |
return 0; |
355 |
|
356 |
if (params == NULL) { |
357 |
new_draw_info(NDI_UNIQUE, 0, op, "Go to what level?"); |
358 |
return 1; |
359 |
} |
360 |
|
361 |
name = params; |
362 |
dummy=get_object(); |
363 |
dummy->map = op->map; |
364 |
EXIT_PATH(dummy) = add_string (name); |
365 |
dummy->name = add_string(name); |
366 |
|
367 |
enter_exit(op, dummy); |
368 |
free_object(dummy); |
369 |
if (op->contr->loading == NULL) { |
370 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
371 |
"Difficulty: %d.", op->map->difficulty); |
372 |
} |
373 |
|
374 |
return 1; |
375 |
} |
376 |
|
377 |
/* is this function called from somewhere ? -Tero */ |
378 |
int command_generate (object *op, char *params) |
379 |
{ |
380 |
object *tmp; |
381 |
int nr = 1, i, retry; |
382 |
|
383 |
if (!op) |
384 |
return 0; |
385 |
|
386 |
if (params != NULL) |
387 |
sscanf(params, "%d", &nr); |
388 |
for (i = 0; i < nr; i++) { |
389 |
retry = 50; |
390 |
while ((tmp=generate_treasure(0, op->map->difficulty)) == NULL && --retry) |
391 |
; |
392 |
if (tmp != NULL) { |
393 |
tmp = insert_ob_in_ob(tmp, op); |
394 |
if (op->type == PLAYER) |
395 |
esrv_send_item(op, tmp); |
396 |
} |
397 |
} |
398 |
|
399 |
return 1; |
400 |
} |
401 |
|
402 |
int command_freeze(object *op, char *params) { |
403 |
int ticks; |
404 |
player *pl; |
405 |
|
406 |
if (!params) { |
407 |
new_draw_info(NDI_UNIQUE, 0, op, "Usage: freeze [ticks] <player>."); |
408 |
return 1; |
409 |
} |
410 |
|
411 |
ticks = atoi(params); |
412 |
if (ticks) { |
413 |
while ((isdigit(*params) || isspace(*params)) && *params != 0) |
414 |
params++; |
415 |
if (*params == 0) { |
416 |
new_draw_info(NDI_UNIQUE, 0, op, "Usage: freeze [ticks] <player>."); |
417 |
return 1; |
418 |
} |
419 |
} else |
420 |
ticks = 100; |
421 |
|
422 |
pl = get_other_player_from_name(op, params); |
423 |
if (!pl) |
424 |
return 1; |
425 |
|
426 |
new_draw_info(NDI_UNIQUE|NDI_RED, 0, pl->ob, "You have been frozen by the DM!"); |
427 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
428 |
"You freeze %s for %d ticks", pl->ob->name, ticks); |
429 |
pl->ob->speed_left = -(pl->ob->speed*ticks); |
430 |
return 0; |
431 |
} |
432 |
|
433 |
int command_arrest(object *op, char *params) { |
434 |
object *dummy; |
435 |
player *pl; |
436 |
if (!op) return 0; |
437 |
if(params==NULL) { |
438 |
new_draw_info(NDI_UNIQUE, 0,op,"Usage: arrest <player>."); |
439 |
return 1; |
440 |
} |
441 |
pl = get_other_player_from_name(op, params); |
442 |
if (!pl) return 1; |
443 |
dummy=get_jail_exit(pl->ob); |
444 |
if (!dummy) { |
445 |
/* we have nowhere to send the prisoner....*/ |
446 |
new_draw_info(NDI_UNIQUE, 0,op,"can't jail player, there is no map to hold them"); |
447 |
return 0; |
448 |
} |
449 |
enter_exit(pl->ob, dummy); |
450 |
free_object(dummy); |
451 |
new_draw_info(NDI_UNIQUE, 0,pl->ob,"You have been arrested."); |
452 |
new_draw_info(NDI_UNIQUE, 0,op,"OK."); |
453 |
LOG(llevInfo, "Player %s arrested by %s\n", pl->ob->name, op->name); |
454 |
return 1; |
455 |
} |
456 |
|
457 |
int command_summon(object *op, char *params) { |
458 |
int i; |
459 |
object *dummy; |
460 |
player *pl; |
461 |
|
462 |
if (!op) |
463 |
return 0; |
464 |
|
465 |
if (params == NULL) { |
466 |
new_draw_info(NDI_UNIQUE, 0, op, "Usage: summon <player>."); |
467 |
return 1; |
468 |
} |
469 |
|
470 |
pl = get_other_player_from_name(op, params); |
471 |
if (!pl) |
472 |
return 1; |
473 |
|
474 |
i = find_free_spot(op, op->map, op->x, op->y, 1, 9); |
475 |
if (i == -1) { |
476 |
new_draw_info(NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
477 |
return 1; |
478 |
} |
479 |
|
480 |
dummy = get_object(); |
481 |
EXIT_PATH(dummy) = add_string(op->map->path); |
482 |
EXIT_X(dummy) = op->x+freearr_x[i]; |
483 |
EXIT_Y(dummy) = op->y+freearr_y[i]; |
484 |
enter_exit(pl->ob, dummy); |
485 |
free_object(dummy); |
486 |
new_draw_info(NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
487 |
new_draw_info(NDI_UNIQUE, 0, op, "OK."); |
488 |
|
489 |
return 1; |
490 |
} |
491 |
|
492 |
/** |
493 |
* Teleport next to target player. |
494 |
*/ |
495 |
/* mids 01/16/2002 */ |
496 |
int command_teleport(object *op, char *params) { |
497 |
int i; |
498 |
object *dummy; |
499 |
player *pl; |
500 |
|
501 |
if (!op) |
502 |
return 0; |
503 |
|
504 |
if (params == NULL) { |
505 |
new_draw_info(NDI_UNIQUE, 0, op, "Usage: teleport <player>."); |
506 |
return 1; |
507 |
} |
508 |
|
509 |
pl = get_other_player_from_name(op, params); |
510 |
if (!pl) |
511 |
return 1; |
512 |
|
513 |
i = find_free_spot(pl->ob, pl->ob->map, pl->ob->x, pl->ob->y, 1, 9); |
514 |
if (i == -1) { |
515 |
new_draw_info(NDI_UNIQUE, 0, op, "Can not find a free spot to teleport to."); |
516 |
return 1; |
517 |
} |
518 |
|
519 |
dummy = get_object(); |
520 |
EXIT_PATH(dummy) = add_string(pl->ob->map->path); |
521 |
EXIT_X(dummy) = pl->ob->x + freearr_x[i]; |
522 |
EXIT_Y(dummy) = pl->ob->y + freearr_y[i]; |
523 |
enter_exit(op, dummy); |
524 |
free_object(dummy); |
525 |
if (!op->contr->hidden) |
526 |
new_draw_info(NDI_UNIQUE, 0, pl->ob, "You see a portal open."); |
527 |
new_draw_info(NDI_UNIQUE, 0, op, "OK."); |
528 |
return 1; |
529 |
} |
530 |
|
531 |
/** |
532 |
* This function is a real mess, because we're stucking getting |
533 |
* the entire item description in one block of text, so we just |
534 |
* can't simply parse it - we need to look for double quotes |
535 |
* for example. This could actually get much simpler with just a |
536 |
* little help from the client - if we could get line breaks, it |
537 |
* makes parsing much easier, eg, something like: |
538 |
* arch dragon |
539 |
* name big nasty creature |
540 |
* hp 5 |
541 |
* sp 30 |
542 |
* Is much easier to parse than |
543 |
* dragon name "big nasty creature" hp 5 sp 30 |
544 |
* for example. |
545 |
*/ |
546 |
int command_create(object *op, char *params) { |
547 |
object *tmp = NULL; |
548 |
int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
549 |
char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *bp4, *endline; |
550 |
archetype *at, *at_spell = NULL; |
551 |
artifact *art = NULL; |
552 |
|
553 |
if (!op) |
554 |
return 0; |
555 |
|
556 |
if (params == NULL) { |
557 |
new_draw_info(NDI_UNIQUE, 0, op, |
558 |
"Usage: create [nr] [magic] <archetype> [ of <artifact>]" |
559 |
" [variable_to_patch setting]"); |
560 |
return 1; |
561 |
} |
562 |
bp = params; |
563 |
|
564 |
/* We need to know where the line ends */ |
565 |
endline = bp+strlen(bp); |
566 |
|
567 |
if (sscanf(bp, "%d ", &nrof)) { |
568 |
if ((bp = strchr(params, ' ')) == NULL) { |
569 |
new_draw_info(NDI_UNIQUE, 0, op, |
570 |
"Usage: create [nr] [magic] <archetype> [ of <artifact>]" |
571 |
" [variable_to_patch setting]"); |
572 |
return 1; |
573 |
} |
574 |
bp++; |
575 |
set_nrof = 1; |
576 |
LOG(llevDebug, "%s creates: (%d) %s\n", op->name, nrof, bp); |
577 |
} |
578 |
if (sscanf(bp, "%d ", &magic)) { |
579 |
if ((bp = strchr(bp, ' ')) == NULL) { |
580 |
new_draw_info(NDI_UNIQUE, 0, op, |
581 |
"Usage: create [nr] [magic] <archetype> [ of <artifact>]" |
582 |
" [variable_to_patch setting]"); |
583 |
return 1; |
584 |
} |
585 |
bp++; |
586 |
set_magic = 1; |
587 |
LOG(llevDebug, "%s creates: (%d) (%d) %s\n", op->name, nrof, magic, bp); |
588 |
} |
589 |
if ((cp = strstr(bp, " of ")) != NULL) { |
590 |
*cp = '\0'; |
591 |
cp += 4; |
592 |
} |
593 |
for (bp2 = bp; *bp2; bp2++) { |
594 |
if (*bp2 == ' ') { |
595 |
*bp2 = '\0'; |
596 |
bp2++; |
597 |
break; |
598 |
} |
599 |
} |
600 |
|
601 |
if ((at = find_archetype(bp)) == NULL) { |
602 |
new_draw_info(NDI_UNIQUE, 0, op, "No such archetype."); |
603 |
return 1; |
604 |
} |
605 |
|
606 |
if (cp) { |
607 |
char spell_name[MAX_BUF], *fsp = NULL; |
608 |
|
609 |
/* |
610 |
* Try to find a spell object for this. Note that |
611 |
* we also set up spell_name which is only |
612 |
* the first word. |
613 |
*/ |
614 |
|
615 |
at_spell = find_archetype(cp); |
616 |
if (!at_spell || at_spell->clone.type != SPELL) |
617 |
at_spell = find_archetype_by_object_name(cp); |
618 |
if (!at_spell || at_spell->clone.type != SPELL) { |
619 |
strcpy(spell_name, cp); |
620 |
fsp = strchr(spell_name, ' '); |
621 |
if (fsp) { |
622 |
*fsp = 0; |
623 |
fsp++; |
624 |
at_spell = find_archetype(spell_name); |
625 |
|
626 |
/* Got a spell, update the first string pointer */ |
627 |
if (at_spell && at_spell->clone.type == SPELL) |
628 |
bp2 = cp+strlen(spell_name)+1; |
629 |
else |
630 |
at_spell = NULL; |
631 |
} |
632 |
} |
633 |
|
634 |
/* OK - we didn't find a spell - presume the 'of' |
635 |
* in this case means its an artifact. |
636 |
*/ |
637 |
if (!at_spell) { |
638 |
if (find_artifactlist(at->clone.type) == NULL) { |
639 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
640 |
"No artifact list for type %d\n", at->clone.type); |
641 |
} else { |
642 |
art = find_artifactlist(at->clone.type)->items; |
643 |
|
644 |
do { |
645 |
if (!strcmp(art->item->name, cp)) |
646 |
break; |
647 |
art = art->next; |
648 |
} while (art != NULL); |
649 |
if (!art) { |
650 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
651 |
"No such artifact ([%d] of %s)", at->clone.type, cp); |
652 |
} |
653 |
} |
654 |
LOG(llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", op->name, |
655 |
set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp); |
656 |
} |
657 |
} /* if cp */ |
658 |
|
659 |
if ((at->clone.type == ROD || at->clone.type == WAND || at->clone.type == SCROLL || |
660 |
at->clone.type == HORN || at->clone.type == SPELLBOOK) && !at_spell) { |
661 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
662 |
"Unable to find spell %s for object that needs it, or it is of wrong type", |
663 |
cp); |
664 |
return 1; |
665 |
} |
666 |
|
667 |
/* |
668 |
* Rather than have two different blocks with a lot of similar code, |
669 |
* just create one object, do all the processing, and then determine |
670 |
* if that one object should be inserted or if we need to make copies. |
671 |
*/ |
672 |
tmp = arch_to_object(at); |
673 |
if (settings.real_wiz == FALSE) |
674 |
SET_FLAG(tmp, FLAG_WAS_WIZ); |
675 |
if (set_magic) |
676 |
set_abs_magic(tmp, magic); |
677 |
if (art) |
678 |
give_artifact_abilities(tmp, art->item); |
679 |
if (need_identify(tmp)) { |
680 |
SET_FLAG(tmp, FLAG_IDENTIFIED); |
681 |
CLEAR_FLAG(tmp, FLAG_KNOWN_MAGICAL); |
682 |
} |
683 |
|
684 |
/* |
685 |
* This entire block here tries to find variable pairings, |
686 |
* eg, 'hp 4' or the like. The mess here is that values |
687 |
* can be quoted (eg "my cool sword"); So the basic logic |
688 |
* is we want to find two spaces, but if we got a quote, |
689 |
* any spaces there don't count. |
690 |
*/ |
691 |
while (*bp2 && bp2 <= endline) { |
692 |
bp4 = NULL; |
693 |
gotspace = 0; |
694 |
gotquote = 0; |
695 |
/* find the first quote */ |
696 |
for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) { |
697 |
|
698 |
/* Found a quote - now lets find the second one */ |
699 |
if (*bp3 == '"') { |
700 |
*bp3 = ' '; |
701 |
bp2 = bp3+1; /* Update start of string */ |
702 |
bp3++; |
703 |
gotquote++; |
704 |
while (*bp3) { |
705 |
if (*bp3 == '"') { |
706 |
*bp3 = '\0'; |
707 |
gotquote++; |
708 |
} else |
709 |
bp3++; |
710 |
} |
711 |
} else if (*bp3==' ') { |
712 |
gotspace++; |
713 |
} |
714 |
} |
715 |
|
716 |
/* |
717 |
* If we got two spaces, send the second one to null. |
718 |
* if we've reached the end of the line, increase gotspace - |
719 |
* this is perfectly valid for the list entry listed. |
720 |
*/ |
721 |
if (gotspace == 2 || gotquote == 2) { |
722 |
bp3--; /* Undo the extra increment */ |
723 |
*bp3 = '\0'; |
724 |
} else if (*bp3=='\0') |
725 |
gotspace++; |
726 |
|
727 |
if ((gotquote && gotquote != 2) || (gotspace != 2 && gotquote != 2)) { |
728 |
/* |
729 |
* Unfortunately, we've clobbered lots of values, so printing |
730 |
* out what we have probably isn't useful. Break out, because |
731 |
* trying to recover is probably won't get anything useful |
732 |
* anyways, and we'd be confused about end of line pointers |
733 |
* anyways. |
734 |
*/ |
735 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
736 |
"Malformed create line: %s", bp2); |
737 |
break; |
738 |
} |
739 |
/* bp2 should still point to the start of this line, |
740 |
* with bp3 pointing to the end |
741 |
*/ |
742 |
if (set_variable(tmp, bp2) == -1) |
743 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
744 |
"Unknown variable %s", bp2); |
745 |
else |
746 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
747 |
"(%s#%d)->%s", tmp->name, tmp->count, bp2); |
748 |
bp2 = bp3+1; |
749 |
} |
750 |
|
751 |
if (at->clone.nrof) { |
752 |
if (at_spell) |
753 |
insert_ob_in_ob(arch_to_object(at_spell), tmp); |
754 |
|
755 |
tmp->x = op->x; |
756 |
tmp->y = op->y; |
757 |
if (set_nrof) |
758 |
tmp->nrof = nrof; |
759 |
tmp->map = op->map; |
760 |
|
761 |
tmp = insert_ob_in_ob(tmp, op); |
762 |
esrv_send_item(op, tmp); |
763 |
|
764 |
/* Let's put this created item on stack so dm can access it easily. */ |
765 |
dm_stack_push(op->contr, tmp->count); |
766 |
|
767 |
return 1; |
768 |
} else { |
769 |
for (i = 0 ; i < (set_nrof ? nrof : 1); i++) { |
770 |
archetype *atmp; |
771 |
object *prev = NULL, *head = NULL, *dup; |
772 |
|
773 |
for (atmp = at; atmp != NULL; atmp = atmp->more) { |
774 |
dup = arch_to_object(atmp); |
775 |
|
776 |
if (at_spell) |
777 |
insert_ob_in_ob(arch_to_object(at_spell), dup); |
778 |
|
779 |
/* |
780 |
* The head is what contains all the important bits, |
781 |
* so just copying it over should be fine. |
782 |
*/ |
783 |
if (head == NULL) { |
784 |
head=dup; |
785 |
copy_object(tmp, dup); |
786 |
} |
787 |
if (settings.real_wiz == FALSE) |
788 |
SET_FLAG(dup, FLAG_WAS_WIZ); |
789 |
dup->x = op->x+dup->arch->clone.x; |
790 |
dup->y = op->y+dup->arch->clone.y; |
791 |
dup->map = op->map; |
792 |
|
793 |
if (head != dup) { |
794 |
dup->head = head; |
795 |
prev->more = dup; |
796 |
} |
797 |
prev = dup; |
798 |
} |
799 |
|
800 |
if (QUERY_FLAG(head, FLAG_ALIVE)) { |
801 |
object *check = head; |
802 |
int size_x = 0; |
803 |
int size_y = 0; |
804 |
|
805 |
while (check) { |
806 |
size_x = MAX(size_x, check->arch->clone.x); |
807 |
size_y = MAX(size_y, check->arch->clone.y); |
808 |
check = check->more; |
809 |
} |
810 |
|
811 |
if (out_of_map(op->map, head->x+size_x, head->y+size_y)) { |
812 |
if (head->x < size_x || head->y < size_y) { |
813 |
dm_stack_pop(op->contr); |
814 |
free_object(head); |
815 |
new_draw_info(NDI_UNIQUE, 0, op, "Object too big to insert in map, or wrong position."); |
816 |
free_object(tmp); |
817 |
return 1; |
818 |
} |
819 |
|
820 |
check = head; |
821 |
while (check) { |
822 |
check->x -= size_x; |
823 |
check->y -= size_y; |
824 |
check = check->more; |
825 |
} |
826 |
} |
827 |
|
828 |
insert_ob_in_map(head, op->map, op, 0); |
829 |
} else |
830 |
head = insert_ob_in_ob(head, op); |
831 |
|
832 |
/* Let's put this created item on stack so dm can access it easily. */ |
833 |
/* Wonder if we really want to push all of these, but since |
834 |
* things like rods have nrof 0, we want to cover those. |
835 |
*/ |
836 |
dm_stack_push(op->contr, head->count); |
837 |
|
838 |
if (at->clone.randomitems != NULL && !at_spell) |
839 |
create_treasure(at->clone.randomitems, head, GT_APPLY, |
840 |
op->map->difficulty, 0); |
841 |
esrv_send_item(op, head); |
842 |
} |
843 |
|
844 |
/* free the one we used to copy */ |
845 |
free_object(tmp); |
846 |
} |
847 |
|
848 |
return 1; |
849 |
} |
850 |
|
851 |
/* |
852 |
* Now follows dm-commands which are also acceptable from sockets |
853 |
*/ |
854 |
|
855 |
int command_inventory(object *op, char *params) { |
856 |
object *tmp; |
857 |
int i; |
858 |
|
859 |
if (!params) { |
860 |
inventory(op, NULL); |
861 |
return 0; |
862 |
} |
863 |
|
864 |
if (!sscanf(params, "%d", &i) || (tmp = find_object(i)) == NULL) { |
865 |
new_draw_info(NDI_UNIQUE, 0, op, "Inventory of what object (nr)?"); |
866 |
return 1; |
867 |
} |
868 |
|
869 |
inventory(op, tmp); |
870 |
return 1; |
871 |
} |
872 |
|
873 |
/* just show player's their skills for now. Dm's can |
874 |
* already see skills w/ inventory command - b.t. |
875 |
*/ |
876 |
|
877 |
int command_skills (object *op, char *params) { |
878 |
show_skills(op, params); |
879 |
return 0; |
880 |
} |
881 |
|
882 |
int command_dump (object *op, char *params) { |
883 |
object *tmp; |
884 |
|
885 |
tmp = get_dm_object(op->contr, ¶ms, NULL); |
886 |
if (!tmp) |
887 |
return 1; |
888 |
|
889 |
dump_object(tmp); |
890 |
new_draw_info(NDI_UNIQUE, 0, op, errmsg); |
891 |
if (QUERY_FLAG(tmp, FLAG_OBJ_ORIGINAL)) |
892 |
new_draw_info(NDI_UNIQUE, 0, op, "Object is marked original"); |
893 |
return 1; |
894 |
} |
895 |
|
896 |
/** |
897 |
* When DM is possessing a monster, flip aggression on and off, to allow |
898 |
* better motion. |
899 |
*/ |
900 |
int command_mon_aggr(object *op, char *params) { |
901 |
if (op->enemy || !QUERY_FLAG(op, FLAG_UNAGGRESSIVE)) { |
902 |
op->enemy = NULL; |
903 |
SET_FLAG(op, FLAG_UNAGGRESSIVE); |
904 |
new_draw_info(NDI_UNIQUE, 0, op, "Aggression turned OFF"); |
905 |
} else { |
906 |
CLEAR_FLAG(op, FLAG_FRIENDLY); |
907 |
CLEAR_FLAG(op, FLAG_UNAGGRESSIVE); |
908 |
new_draw_info(NDI_UNIQUE, 0, op, "Aggression turned ON"); |
909 |
} |
910 |
|
911 |
return 1; |
912 |
} |
913 |
|
914 |
/** DM can possess a monster. Basically, this tricks the client into thinking |
915 |
* a given monster, is actually the player it controls. This allows a DM |
916 |
* to inhabit a monster's body, and run around the game with it. |
917 |
* This function is severely broken - it has tons of hardcoded values, |
918 |
*/ |
919 |
int command_possess(object *op, char *params) { |
920 |
object *victim, *curinv, *nextinv; |
921 |
player *pl; |
922 |
int i; |
923 |
char buf[MAX_BUF]; |
924 |
|
925 |
victim = NULL; |
926 |
if (params != NULL) { |
927 |
if (sscanf(params, "%d", &i)) |
928 |
victim = find_object(i); |
929 |
else if (sscanf(params, "%s", buf)) |
930 |
victim = find_object_name(buf); |
931 |
} |
932 |
if (victim == NULL) { |
933 |
new_draw_info(NDI_UNIQUE, 0, op, "Patch what object (nr)?"); |
934 |
return 1; |
935 |
} |
936 |
|
937 |
if (victim == op) { |
938 |
new_draw_info(NDI_UNIQUE, 0, op, "As insane as you are, I cannot " |
939 |
"allow you to possess yourself."); |
940 |
return 1; |
941 |
} |
942 |
|
943 |
/* clear out the old inventory */ |
944 |
curinv = op->inv; |
945 |
while (curinv != NULL) { |
946 |
nextinv = curinv->below; |
947 |
esrv_del_item(op->contr, curinv->count); |
948 |
curinv = nextinv; |
949 |
} |
950 |
|
951 |
/* make the switch */ |
952 |
pl = op->contr; |
953 |
victim->contr = pl; |
954 |
pl->ob = victim; |
955 |
victim->type = PLAYER; |
956 |
SET_FLAG(victim, FLAG_WIZ); |
957 |
|
958 |
/* send the inventory to the client */ |
959 |
curinv = victim->inv; |
960 |
while (curinv != NULL) { |
961 |
nextinv = curinv->below; |
962 |
esrv_send_item(victim, curinv); |
963 |
curinv = nextinv; |
964 |
} |
965 |
/* basic patchup */ |
966 |
/* The use of hard coded values is terrible. Note |
967 |
* that really, to be fair, this shouldn't get changed at |
968 |
* all - if you are possessing a kobold, you should have the |
969 |
* same limitations. As it is, as more body locations are added, |
970 |
* this will give this player more locations than perhaps |
971 |
* they should be allowed. |
972 |
*/ |
973 |
for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
974 |
if (i == 1 || i == 6 || i == 8 || i == 9) |
975 |
victim->body_info[i] = 2; |
976 |
else |
977 |
victim->body_info[i] = 1; |
978 |
|
979 |
esrv_new_player(pl, 80); /* just pick a wieght, we don't care */ |
980 |
esrv_send_inventory(victim, victim); |
981 |
|
982 |
fix_player(victim); |
983 |
|
984 |
do_some_living(victim); |
985 |
return 1; |
986 |
} |
987 |
|
988 |
int command_patch(object *op, char *params) { |
989 |
char *arg, *arg2; |
990 |
object *tmp; |
991 |
|
992 |
tmp = get_dm_object(op->contr, ¶ms, NULL); |
993 |
if (!tmp) |
994 |
/* Player already informed of failure */ |
995 |
return 1; |
996 |
|
997 |
/* params set to first value by get_dm_default */ |
998 |
arg = params; |
999 |
if (arg == NULL) { |
1000 |
new_draw_info(NDI_UNIQUE, 0, op, "Patch what values?"); |
1001 |
return 1; |
1002 |
} |
1003 |
|
1004 |
if ((arg2 = strchr(arg, ' '))) |
1005 |
arg2++; |
1006 |
if (settings.real_wiz == FALSE) |
1007 |
SET_FLAG(tmp, FLAG_WAS_WIZ); /* To avoid cheating */ |
1008 |
if (set_variable(tmp, arg) == -1) |
1009 |
new_draw_info_format(NDI_UNIQUE, 0, op, "Unknown variable %s", arg); |
1010 |
else { |
1011 |
new_draw_info_format(NDI_UNIQUE, 0, op, |
1012 |
"(%s#%d)->%s=%s", tmp->name, tmp->count, arg, arg2); |
1013 |
} |
1014 |
|
1015 |
return 1; |
1016 |
} |
1017 |
|
1018 |
int command_remove (object *op, char *params) { |
1019 |
object *tmp; |
1020 |
int from; |
1021 |
|
1022 |
tmp = get_dm_object(op->contr, ¶ms, &from); |
1023 |
if (!tmp) { |
1024 |
new_draw_info(NDI_UNIQUE, 0, op, "Remove what object (nr)?"); |
1025 |
return 1; |
1026 |
} |
1027 |
|
1028 |
if (tmp->type == PLAYER) { |
1029 |
new_draw_info(NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
1030 |
return 1; |
1031 |
} |
1032 |
|
1033 |
if (QUERY_FLAG(tmp, FLAG_REMOVED)) { |
1034 |
new_draw_info_format(NDI_UNIQUE, 0, op, "%s is already removed!", |
1035 |
query_name(tmp)); |
1036 |
return 1; |
1037 |
} |
1038 |
|
1039 |
if (from != STACK_FROM_STACK) |
1040 |
/* Item is either stack top, or is a number thus is now stack top, let's remove it */ |
1041 |
dm_stack_pop(op->contr); |
1042 |
|
1043 |
/* Always work on the head - otherwise object will get in odd state */ |
1044 |
if (tmp->head) |
1045 |
tmp = tmp->head; |
1046 |
remove_ob(tmp); |
1047 |
return 1; |
1048 |
} |
1049 |
|
1050 |
int command_free(object *op, char *params) { |
1051 |
object *tmp; |
1052 |
int from; |
1053 |
|
1054 |
tmp = get_dm_object(op->contr, ¶ms, &from); |
1055 |
|
1056 |
if (!tmp) { |
1057 |
new_draw_info(NDI_UNIQUE, 0, op, "Free what object (nr)?"); |
1058 |
return 1; |
1059 |
} |
1060 |
|
1061 |
if (from != STACK_FROM_STACK) |
1062 |
/* Item is either stack top, or is a number thus is now stack top, let's remove it */ |
1063 |
dm_stack_pop(op->contr); |
1064 |
|
1065 |
if (!QUERY_FLAG(tmp, FLAG_REMOVED)) { |
1066 |
new_draw_info(NDI_UNIQUE, 0, op, "Warning, item wasn't removed."); |
1067 |
remove_ob(tmp); |
1068 |
} |
1069 |
|
1070 |
if (tmp->head) |
1071 |
tmp = tmp->head; |
1072 |
free_object(tmp); |
1073 |
return 1; |
1074 |
} |
1075 |
|
1076 |
/** |
1077 |
* This adds exp to a player. We now allow adding to a specific skill. |
1078 |
*/ |
1079 |
int command_addexp(object *op, char *params) { |
1080 |
char buf[MAX_BUF], skill[MAX_BUF]; |
1081 |
int i, q; |
1082 |
object *skillob = NULL; |
1083 |
player *pl; |
1084 |
|
1085 |
if (params == NULL || ((q = sscanf(params, "%s %d", buf, &i)) < 2)) { |
1086 |
new_draw_info(NDI_UNIQUE, 0, op, "Usage: addexp [who] [how much]."); |
1087 |
return 1; |
1088 |
} |
1089 |
|
1090 |
for (pl = first_player; pl != NULL; pl = pl->next) |
1091 |
if (!strncmp(pl->ob->name, buf, MAX_NAME)) |
1092 |
break; |
1093 |
|
1094 |
if (pl == NULL) { |
1095 |
new_draw_info(NDI_UNIQUE, 0, op, "No such player."); |
1096 |
return 1; |
1097 |
} |
1098 |
|
1099 |
if (q >= 3) { |
1100 |
skillob = find_skill_by_name(pl->ob, skill); |
1101 |
if (!skillob) { |
1102 |
new_draw_info_format(NDI_UNIQUE, 0, op, "Unable to find skill %s in %s", skill, buf); |
1103 |
return 1; |
1104 |
} |
1105 |
|
1106 |
i = check_exp_adjust(skillob, i); |
1107 |
skillob->stats.exp += i; |
1108 |
calc_perm_exp(skillob); |
1109 |
player_lvl_adj(pl->ob, skillob); |
1110 |
} |
1111 |
|
1112 |
pl->ob->stats.exp += i; |
1113 |
calc_perm_exp(pl->ob); |
1114 |
player_lvl_adj(pl->ob, NULL); |
1115 |
|
1116 |
if (settings.real_wiz == FALSE) |
1117 |
SET_FLAG(pl->ob, FLAG_WAS_WIZ); |
1118 |
return 1; |
1119 |
} |
1120 |
|
1121 |
int command_speed(object *op, char *params) { |
1122 |
int i; |
1123 |
|
1124 |
if (params == NULL || !sscanf(params, "%d", &i)) { |
1125 |
sprintf(errmsg, "Current speed is %ld", max_time); |
1126 |
new_draw_info(NDI_UNIQUE, 0, op, errmsg); |
1127 |
return 1; |
1128 |
} |
1129 |
|
1130 |
set_max_time(i); |
1131 |
reset_sleep(); |
1132 |
new_draw_info(NDI_UNIQUE, 0, op, "The speed is changed."); |
1133 |
return 1; |
1134 |
} |
1135 |
|
1136 |
/**************************************************************************/ |
1137 |
/* Mods made by Tyler Van Gorder, May 10-13, 1992. */ |
1138 |
/* CSUChico : tvangod@cscihp.ecst.csuchico.edu */ |
1139 |
/**************************************************************************/ |
1140 |
|
1141 |
int command_stats(object *op, char *params) { |
1142 |
char thing[20]; |
1143 |
player *pl; |
1144 |
char buf[MAX_BUF]; |
1145 |
|
1146 |
thing[0] = '\0'; |
1147 |
if (params == NULL || !sscanf(params, "%s", thing) || thing == NULL) { |
1148 |
new_draw_info(NDI_UNIQUE, 0, op, "Who?"); |
1149 |
return 1; |
1150 |
} |
1151 |
|
1152 |
for (pl = first_player; pl != NULL; pl = pl->next) |
1153 |
if (!strcmp(pl->ob->name, thing)) { |
1154 |
sprintf(buf, "Str : %-2d H.P. : %-4d MAX : %d", |
1155 |
pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
1156 |
new_draw_info(NDI_UNIQUE, 0, op, buf); |
1157 |
sprintf(buf, "Dex : %-2d S.P. : %-4d MAX : %d", |
1158 |
pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
1159 |
new_draw_info(NDI_UNIQUE, 0, op, buf); |
1160 |
sprintf(buf, "Con : %-2d AC : %-4d WC : %d", |
1161 |
pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc) ; |
1162 |
new_draw_info(NDI_UNIQUE, 0, op, buf); |
1163 |
sprintf(buf, "Int : %-2d Damage : %d", |
1164 |
pl->ob->stats.Int, pl->ob->stats.dam); |
1165 |
new_draw_info(NDI_UNIQUE, 0, op, buf); |
1166 |
#ifndef WIN32 |
1167 |
sprintf(buf, "Wis : %-2d EXP : %lld", |
1168 |
pl->ob->stats.Wis, pl->ob->stats.exp); |
1169 |
#else |
1170 |
sprintf(buf, "Wis : %-2d EXP : %I64d", |
1171 |
pl->ob->stats.Wis, pl->ob->stats.exp); |
1172 |
#endif |
1173 |
new_draw_info(NDI_UNIQUE, 0, op, buf); |
1174 |
sprintf(buf, "Pow : %-2d Grace : %d", |
1175 |
pl->ob->stats.Pow, pl->ob->stats.grace); |
1176 |
new_draw_info(NDI_UNIQUE, 0, op, buf); |
1177 |
sprintf(buf, "Cha : %-2d Food : %d", |
1178 |
pl->ob->stats.Cha, pl->ob->stats.food); |
1179 |
new_draw_info(NDI_UNIQUE, 0, op, buf); |
1180 |
break; |
1181 |
} |
1182 |
if (pl == NULL) |
1183 |
new_draw_info(NDI_UNIQUE, 0, op, "No such player."); |
1184 |
return 1; |
1185 |
} |
1186 |
|
1187 |
int command_abil(object *op, char *params) { |
1188 |
char thing[20], thing2[20]; |
1189 |
int iii; |
1190 |
player *pl; |
1191 |
char buf[MAX_BUF]; |
1192 |
|
1193 |
iii = 0; |
1194 |
thing[0] = '\0'; |
1195 |
thing2[0] = '\0'; |
1196 |
if (params == NULL || !sscanf(params, "%s %s %d", thing, thing2, &iii) || |
1197 |
thing==NULL) { |
1198 |
new_draw_info(NDI_UNIQUE, 0, op, "Who?"); |
1199 |
return 1; |
1200 |
} |
1201 |
|
1202 |
if (thing2 == NULL){ |
1203 |
new_draw_info(NDI_UNIQUE, 0, op, "You can't change that."); |
1204 |
return 1; |
1205 |
} |
1206 |
|
1207 |
if (iii < MIN_STAT || iii > MAX_STAT) { |
1208 |
new_draw_info(NDI_UNIQUE, 0, op, "Illegal range of stat.\n"); |
1209 |
return 1; |
1210 |
} |
1211 |
|
1212 |
for (pl = first_player; pl != NULL; pl = pl->next) { |
1213 |
if (!strcmp(pl->ob->name, thing)) { |
1214 |
if (settings.real_wiz == FALSE) |
1215 |
SET_FLAG(pl->ob, FLAG_WAS_WIZ); |
1216 |
if (!strcmp("str", thing2)) |
1217 |
pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; |
1218 |
if (!strcmp("dex", thing2)) |
1219 |
pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; |
1220 |
if (!strcmp("con", thing2)) |
1221 |
pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; |
1222 |
if (!strcmp("wis", thing2)) |
1223 |
pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; |
1224 |
if (!strcmp("cha", thing2)) |
1225 |
pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii; |
1226 |
if (!strcmp("int", thing2)) |
1227 |
pl->ob->stats.Int = iii, pl->orig_stats.Int = iii; |
1228 |
if (!strcmp("pow", thing2)) |
1229 |
pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii; |
1230 |
sprintf(buf, "%s has been altered.", pl->ob->name); |
1231 |
new_draw_info(NDI_UNIQUE, 0, op, buf); |
1232 |
fix_player(pl->ob); |
1233 |
return 1; |
1234 |
} |
1235 |
} |
1236 |
|
1237 |
new_draw_info(NDI_UNIQUE, 0, op, "No such player."); |
1238 |
return 1; |
1239 |
} |
1240 |
|
1241 |
int command_reset (object *op, char *params) { |
1242 |
mapstruct *m; |
1243 |
object *dummy = NULL, *tmp = NULL; |
1244 |
|
1245 |
if (params == NULL) { |
1246 |
new_draw_info(NDI_UNIQUE, 0, op, "Reset what map [name]?"); |
1247 |
return 1; |
1248 |
} |
1249 |
|
1250 |
if (strcmp(params, ".") == 0) |
1251 |
params = op->map->path; |
1252 |
m = has_been_loaded(params); |
1253 |
if (m == NULL) { |
1254 |
new_draw_info(NDI_UNIQUE, 0, op, "No such map."); |
1255 |
return 1; |
1256 |
} |
1257 |
|
1258 |
if (m->in_memory != MAP_SWAPPED) { |
1259 |
if (m->in_memory != MAP_IN_MEMORY) { |
1260 |
LOG(llevError, "Tried to swap out map which was not in memory.\n"); |
1261 |
return 0; |
1262 |
} |
1263 |
|
1264 |
/* |
1265 |
* Only attempt to remove the player that is doing the reset, and not other |
1266 |
* players or wiz's. |
1267 |
*/ |
1268 |
if (op->map == m) { |
1269 |
dummy = get_object(); |
1270 |
dummy->map = NULL; |
1271 |
EXIT_X(dummy) = op->x; |
1272 |
EXIT_Y(dummy) = op->y; |
1273 |
EXIT_PATH(dummy) = add_string(op->map->path); |
1274 |
remove_ob(op); |
1275 |
op->map = NULL; |
1276 |
tmp = op; |
1277 |
} |
1278 |
swap_map(m); |
1279 |
} |
1280 |
|
1281 |
if (m->in_memory == MAP_SWAPPED) { |
1282 |
LOG(llevDebug, "Resetting map %s.\n", m->path); |
1283 |
|
1284 |
/* setting this effectively causes an immediate reload */ |
1285 |
m->reset_time = 1; |
1286 |
flush_old_maps(); |
1287 |
new_draw_info(NDI_UNIQUE, 0, op, "OK."); |
1288 |
if (tmp) { |
1289 |
enter_exit(tmp, dummy); |
1290 |
free_object(dummy); |
1291 |
} |
1292 |
return 1; |
1293 |
} else { |
1294 |
player *pl; |
1295 |
int playercount = 0; |
1296 |
|
1297 |
/* Need to re-insert player if swap failed for some reason */ |
1298 |
if (tmp) { |
1299 |
insert_ob_in_map(op, m, NULL, 0); |
1300 |
free_object(dummy); |
1301 |
} |
1302 |
|
1303 |
new_draw_info(NDI_UNIQUE, 0, op, |
1304 |
"Reset failed, couldn't swap map, the following players are on it:"); |
1305 |
for (pl = first_player; pl != NULL; pl = pl->next) { |
1306 |
if (pl->ob->map == m && pl->ob != op) { |
1307 |
new_draw_info_format(NDI_UNIQUE, 0, op, "%s", pl->ob->name); |
1308 |
playercount++; |
1309 |
} |
1310 |
} |
1311 |
if (!playercount) |
1312 |
new_draw_info(NDI_UNIQUE, 0, op, |
1313 |
"hmm, I don't see any other players on this map, something else is the problem."); |
1314 |
return 1; |
1315 |
} |
1316 |
} |
1317 |
|
1318 |
int command_nowiz(object *op, char *params) { /* 'noadm' is alias */ |
1319 |
CLEAR_FLAG(op, FLAG_WIZ); |
1320 |
CLEAR_FLAG(op, FLAG_WIZPASS); |
1321 |
CLEAR_FLAG(op, FLAG_WIZCAST); |
1322 |
|
1323 |
if (settings.real_wiz == TRUE) |
1324 |
CLEAR_FLAG(op, FLAG_WAS_WIZ); |
1325 |
if (op->contr->hidden) { |
1326 |
new_draw_info(NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); |
1327 |
op->map->players++; |
1328 |
new_draw_info_format(NDI_UNIQUE|NDI_ALL|NDI_DK_ORANGE, 5, NULL, |
1329 |
"%s has entered the game.", op->name); |
1330 |
op->contr->hidden = 0; |
1331 |
op->invisible = 1; |
1332 |
} else |
1333 |
new_draw_info(NDI_UNIQUE|NDI_ALL|NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); |
1334 |
return 1; |
1335 |
} |
1336 |
|
1337 |
/** |
1338 |
* object *op is trying to become dm. |
1339 |
* pl_name is name supplied by player. Restrictive DM will make it harder |
1340 |
* for socket users to become DM - in that case, it will check for the players |
1341 |
* character name. |
1342 |
*/ |
1343 |
static int checkdm(object *op, const char *pl_name, const char *pl_passwd, const char *pl_host) |
1344 |
{ |
1345 |
FILE *dmfile; |
1346 |
char buf[MAX_BUF]; |
1347 |
char line_buf[160], name[160], passwd[160], host[160]; |
1348 |
|
1349 |
#ifdef RESTRICTIVE_DM |
1350 |
*pl_name = op->name ? op->name : "*"; |
1351 |
#endif |
1352 |
|
1353 |
sprintf(buf, "%s/%s", settings.confdir, DMFILE); |
1354 |
if ((dmfile = fopen(buf, "r")) == NULL) { |
1355 |
LOG(llevDebug, "Could not find DM file.\n"); |
1356 |
return 0; |
1357 |
} |
1358 |
|
1359 |
while (fgets(line_buf, 160, dmfile) != NULL) { |
1360 |
if (line_buf[0] == '#') |
1361 |
continue; |
1362 |
if (sscanf(line_buf, "%[^:]:%[^:]:%s\n", name, passwd, host) != 3) { |
1363 |
LOG(llevError, "Warning - malformed dm file entry: %s\n", line_buf); |
1364 |
} else if ((!strcmp(name, "*") || (pl_name && !strcmp(pl_name, name))) |
1365 |
&& (!strcmp(passwd, "*") || !strcmp(passwd, pl_passwd)) && |
1366 |
(!strcmp(host, "*") || !strcmp(host, pl_host))) { |
1367 |
fclose(dmfile); |
1368 |
return (1); |
1369 |
} |
1370 |
} |
1371 |
fclose(dmfile); |
1372 |
return (0); |
1373 |
} |
1374 |
|
1375 |
int do_wizard_dm(object *op, char *params, int silent) { |
1376 |
if (!op->contr) |
1377 |
return 0; |
1378 |
|
1379 |
if (QUERY_FLAG(op, FLAG_WIZ)) { |
1380 |
new_draw_info(NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); |
1381 |
return 0; |
1382 |
} |
1383 |
|
1384 |
if (checkdm(op, op->name, |
1385 |
(params ? params : "*"), op->contr->socket.host)) { |
1386 |
SET_FLAG(op, FLAG_WIZ); |
1387 |
SET_FLAG(op, FLAG_WAS_WIZ); |
1388 |
SET_FLAG(op, FLAG_WIZPASS); |
1389 |
SET_FLAG(op, FLAG_WIZCAST); |
1390 |
new_draw_info(NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); |
1391 |
/* |
1392 |
* Remove setting flying here - that won't work, because next |
1393 |
* fix_player() is called that will get cleared - proper solution |
1394 |
* is probably something like a wiz_force which gives that and any |
1395 |
* other desired abilities. |
1396 |
*/ |
1397 |
clear_los(op); |
1398 |
op->contr->write_buf[0] ='\0'; |
1399 |
|
1400 |
if (!silent) |
1401 |
new_draw_info(NDI_UNIQUE|NDI_ALL|NDI_LT_GREEN, 1, NULL, |
1402 |
"The Dungeon Master has arrived!"); |
1403 |
|
1404 |
return 1; |
1405 |
} else { |
1406 |
new_draw_info(NDI_UNIQUE, 0, op, "Sorry Pal, I don't think so."); |
1407 |
op->contr->write_buf[0] ='\0'; |
1408 |
return 0; |
1409 |
} |
1410 |
} |
1411 |
|
1412 |
/* |
1413 |
* Actual command to perhaps become dm. Changed aroun a bit in version 0.92.2 |
1414 |
* - allow people on sockets to become dm, and allow better dm file |
1415 |
*/ |
1416 |
int command_dm(object *op, char *params) { |
1417 |
if (!op->contr) |
1418 |
return 0; |
1419 |
|
1420 |
do_wizard_dm(op, params, 0); |
1421 |
|
1422 |
return 1; |
1423 |
} |
1424 |
|
1425 |
int command_invisible(object *op, char *params) { |
1426 |
if (op) { |
1427 |
op->invisible += 100; |
1428 |
update_object(op, UP_OBJ_FACE); |
1429 |
new_draw_info(NDI_UNIQUE, 0, op, "You turn invisible."); |
1430 |
} |
1431 |
|
1432 |
return 0; |
1433 |
} |
1434 |
|
1435 |
/** |
1436 |
* Returns spell object (from archetypes) by name. |
1437 |
* Returns NULL if 0 or more than one spell matches. |
1438 |
* Used for wizard's learn spell/prayer. |
1439 |
* |
1440 |
* op is the player issuing the command. |
1441 |
* |
1442 |
* Ignores archetypes "spelldirect_xxx" since these archetypes are not used |
1443 |
* anymore (but may still be present in some player's inventories and thus |
1444 |
* cannot be removed). We have to ignore them here since they have the same |
1445 |
* name than other "spell_xxx" archetypes and would always conflict. |
1446 |
*/ |
1447 |
static object *get_spell_by_name(object *op, const char *spell_name) { |
1448 |
archetype *ar; |
1449 |
archetype *found; |
1450 |
int conflict_found; |
1451 |
size_t spell_name_length; |
1452 |
|
1453 |
/* First check for full name matches. */ |
1454 |
conflict_found = 0; |
1455 |
found = NULL; |
1456 |
for (ar = first_archetype; ar != NULL; ar = ar->next) { |
1457 |
if (ar->clone.type != SPELL) |
1458 |
continue; |
1459 |
|
1460 |
if (strncmp(ar->name, "spelldirect_", 12) == 0) |
1461 |
continue; |
1462 |
|
1463 |
if (strcmp(ar->clone.name, spell_name) != 0) |
1464 |
continue; |
1465 |
|
1466 |
if (found != NULL) { |
1467 |
if (!conflict_found) { |
1468 |
conflict_found = 1; |
1469 |
new_draw_info_format(NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); |
1470 |
new_draw_info_format(NDI_UNIQUE, 0, op, "- %s", found->name); |
1471 |
} |
1472 |
new_draw_info_format(NDI_UNIQUE, 0, op, "- %s", ar->name); |
1473 |
continue; |
1474 |
} |
1475 |
|
1476 |
found = ar; |
1477 |
} |
1478 |
|
1479 |
/* No match if more more than one archetype matches. */ |
1480 |
if (conflict_found) |
1481 |
return NULL; |
1482 |
|
1483 |
/* Return if exactly one archetype matches. */ |
1484 |
if (found != NULL) |
1485 |
return arch_to_object(found); |
1486 |
|
1487 |
/* No full match found: now check for partial matches. */ |
1488 |
spell_name_length = strlen(spell_name); |
1489 |
conflict_found = 0; |
1490 |
found = NULL; |
1491 |
for (ar = first_archetype; ar != NULL; ar = ar->next) { |
1492 |
if (ar->clone.type != SPELL) |
1493 |
continue; |
1494 |
|
1495 |
if (strncmp(ar->name, "spelldirect_", 12) == 0) |
1496 |
continue; |
1497 |
|
1498 |
if (strncmp(ar->clone.name, spell_name, spell_name_length) != 0) |
1499 |
continue; |
1500 |
|
1501 |
if (found != NULL) { |
1502 |
if (!conflict_found) { |
1503 |
conflict_found = 1; |
1504 |
new_draw_info_format(NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name); |
1505 |
new_draw_info_format(NDI_UNIQUE, 0, op, "- %s", found->clone.name); |
1506 |
} |
1507 |
new_draw_info_format(NDI_UNIQUE, 0, op, "- %s", ar->clone.name); |
1508 |
continue; |
1509 |
} |
1510 |
|
1511 |
found = ar; |
1512 |
} |
1513 |
|
1514 |
/* No match if more more than one archetype matches. */ |
1515 |
if (conflict_found) |
1516 |
return NULL; |
1517 |
|
1518 |
/* Return if exactly one archetype matches. */ |
1519 |
if (found != NULL) |
1520 |
return arch_to_object(found); |
1521 |
|
1522 |
/* No spell found: just print an error message. */ |
1523 |
new_draw_info_format(NDI_UNIQUE, 0, op, "The spell %s does not exist.", spell_name); |
1524 |
return NULL; |
1525 |
} |
1526 |
|
1527 |
static int command_learn_spell_or_prayer(object *op, char *params, |
1528 |
int special_prayer) { |
1529 |
object *tmp; |
1530 |
|
1531 |
if (op->contr == NULL || params == NULL) { |
1532 |
new_draw_info(NDI_UNIQUE, 0, op, "Which spell do you want to learn?"); |
1533 |
return 0; |
1534 |
} |
1535 |
|
1536 |
tmp = get_spell_by_name(op, params); |
1537 |
if (tmp == NULL) { |
1538 |
return 0; |
1539 |
} |
1540 |
|
1541 |
if (check_spell_known(op, tmp->name)) { |
1542 |
new_draw_info_format(NDI_UNIQUE, 0, op, "You already know the spell %s.", tmp->name); |
1543 |
return 0; |
1544 |
} |
1545 |
|
1546 |
do_learn_spell(op, tmp, special_prayer); |
1547 |
free_object(tmp); |
1548 |
return 1; |
1549 |
} |
1550 |
|
1551 |
int command_learn_spell(object *op, char *params) { |
1552 |
return command_learn_spell_or_prayer(op, params, 0); |
1553 |
} |
1554 |
|
1555 |
int command_learn_special_prayer(object *op, char *params) |
1556 |
{ |
1557 |
return command_learn_spell_or_prayer(op, params, 1); |
1558 |
} |
1559 |
|
1560 |
int command_forget_spell(object *op, char *params) |
1561 |
{ |
1562 |
object *spell; |
1563 |
|
1564 |
if (op->contr == NULL || params == NULL) { |
1565 |
new_draw_info(NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); |
1566 |
return 0; |
1567 |
} |
1568 |
|
1569 |
spell = lookup_spell_by_name(op, params); |
1570 |
if (spell == NULL) { |
1571 |
new_draw_info_format(NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); |
1572 |
return 0; |
1573 |
} |
1574 |
|
1575 |
do_forget_spell(op, spell->name); |
1576 |
return 1; |
1577 |
} |
1578 |
|
1579 |
/** |
1580 |
* Lists all plugins currently loaded with their IDs and full names. |
1581 |
*/ |
1582 |
int command_listplugins(object *op, char *params) |
1583 |
{ |
1584 |
plugins_display_list(op); |
1585 |
return 1; |
1586 |
} |
1587 |
|
1588 |
/** |
1589 |
* Loads the given plugin. The DM specifies the name of the library to load (no |
1590 |
* pathname is needed). Do not ever attempt to load the same plugin more than |
1591 |
* once at a time, or bad things could happen. |
1592 |
*/ |
1593 |
int command_loadplugin(object *op, char *params) { |
1594 |
char buf[MAX_BUF]; |
1595 |
|
1596 |
if (params == NULL) { |
1597 |
new_draw_info(NDI_UNIQUE, 0, op, "Load which plugin?"); |
1598 |
return 1; |
1599 |
} |
1600 |
|
1601 |
strcpy(buf, LIBDIR); |
1602 |
strcat(buf, "/plugins/"); |
1603 |
strcat(buf, params); |
1604 |
LOG(llevDebug, "Requested plugin file is %s\n", buf); |
1605 |
if (plugins_init_plugin(buf) == 0) |
1606 |
new_draw_info(NDI_UNIQUE, 0, op, "Plugin successfully loaded."); |
1607 |
else |
1608 |
new_draw_info(NDI_UNIQUE, 0, op, "Could not load plugin."); |
1609 |
return 1; |
1610 |
} |
1611 |
|
1612 |
/** |
1613 |
* Unloads the given plugin. The DM specified the ID of the library to unload. |
1614 |
* Note that some things may behave strangely if the correct plugins are not |
1615 |
* loaded. |
1616 |
*/ |
1617 |
int command_unloadplugin(object *op, char *params) |
1618 |
{ |
1619 |
if (params == NULL) { |
1620 |
new_draw_info(NDI_UNIQUE, 0, op, "Remove which plugin?"); |
1621 |
return 1; |
1622 |
} |
1623 |
|
1624 |
if (plugins_remove_plugin(params) == 0) |
1625 |
new_draw_info(NDI_UNIQUE, 0, op, "Plugin successfully removed."); |
1626 |
else |
1627 |
new_draw_info(NDI_UNIQUE, 0, op, "Could not remove plugin."); |
1628 |
return 1; |
1629 |
} |
1630 |
|
1631 |
/** |
1632 |
* A players wants to become DM and hide. |
1633 |
* Let's see if that's authorized. |
1634 |
* Make sure to not tell anything to anyone. |
1635 |
*/ |
1636 |
int command_dmhide(object *op, char *params) { |
1637 |
if (!do_wizard_dm(op, params, 1)) |
1638 |
return 0; |
1639 |
|
1640 |
do_wizard_hide(op, 1); |
1641 |
|
1642 |
return 1; |
1643 |
} |
1644 |
|
1645 |
void dm_stack_pop(player *pl) { |
1646 |
if (!pl->stack_items || !pl->stack_position) { |
1647 |
new_draw_info(NDI_UNIQUE, 0, pl->ob, "Empty stack!"); |
1648 |
return; |
1649 |
} |
1650 |
|
1651 |
pl->stack_position--; |
1652 |
new_draw_info_format(NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position); |
1653 |
} |
1654 |
|
1655 |
/** |
1656 |
* Get current stack top item for player. |
1657 |
* Returns NULL if no stacked item. |
1658 |
* If stacked item disappeared (freed), remove it. |
1659 |
* |
1660 |
* Ryo, august 2004 |
1661 |
*/ |
1662 |
object *dm_stack_peek(player *pl) { |
1663 |
object* ob; |
1664 |
|
1665 |
if (!pl->stack_position) { |
1666 |
new_draw_info(NDI_UNIQUE, 0, pl->ob, "Empty stack!"); |
1667 |
return NULL; |
1668 |
} |
1669 |
|
1670 |
ob = find_object(pl->stack_items[pl->stack_position-1]); |
1671 |
if (!ob) { |
1672 |
new_draw_info(NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!"); |
1673 |
dm_stack_pop(pl); |
1674 |
return NULL; |
1675 |
} |
1676 |
|
1677 |
return ob; |
1678 |
} |
1679 |
|
1680 |
/** |
1681 |
* Push specified item on player stack. |
1682 |
* Inform player of position. |
1683 |
* Initializes variables if needed. |
1684 |
*/ |
1685 |
void dm_stack_push(player *pl, tag_t item) { |
1686 |
if (!pl->stack_items) { |
1687 |
pl->stack_items = (tag_t *)malloc(sizeof(tag_t)*STACK_SIZE); |
1688 |
memset(pl->stack_items, 0, sizeof(tag_t)*STACK_SIZE); |
1689 |
} |
1690 |
|
1691 |
if (pl->stack_position == STACK_SIZE) { |
1692 |
new_draw_info(NDI_UNIQUE, 0, pl->ob, "Item stack full!"); |
1693 |
return; |
1694 |
} |
1695 |
|
1696 |
pl->stack_items[pl->stack_position] = item; |
1697 |
new_draw_info_format(NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position); |
1698 |
pl->stack_position++; |
1699 |
} |
1700 |
|
1701 |
/** |
1702 |
* Checks 'params' for object code. |
1703 |
* |
1704 |
* Can be: |
1705 |
* * empty => get current object stack top for player |
1706 |
* * number => get item with that tag, stack it for future use |
1707 |
* * $number => get specified stack item |
1708 |
* * "me" => player himself |
1709 |
* |
1710 |
* At function exit, params points to first non-object char |
1711 |
* |
1712 |
* 'from', if not NULL, contains at exit: |
1713 |
* * STACK_FROM_NONE => object not found |
1714 |
* * STACK_FROM_TOP => top item stack, may be NULL if stack was empty |
1715 |
* * STACK_FROM_STACK => item from somewhere in the stack |
1716 |
* * STACK_FROM_NUMBER => item by number, pushed on stack |
1717 |
* |
1718 |
* Ryo, august 2004 |
1719 |
*/ |
1720 |
object *get_dm_object(player *pl, char **params, int *from) { |
1721 |
int item_tag, item_position; |
1722 |
object *ob; |
1723 |
|
1724 |
if (!pl) |
1725 |
return NULL; |
1726 |
|
1727 |
if (!params || !*params || **params == '\0') { |
1728 |
if (from) |
1729 |
*from = STACK_FROM_TOP; |
1730 |
/* No parameter => get stack item */ |
1731 |
return dm_stack_peek(pl); |
1732 |
} |
1733 |
|
1734 |
/* Let's clean white spaces */ |
1735 |
while (**params == ' ') |
1736 |
(*params)++; |
1737 |
|
1738 |
/* Next case: number => item tag */ |
1739 |
if (sscanf(*params, "%d", &item_tag)) { |
1740 |
/* Move parameter to next item */ |
1741 |
while (isdigit(**params)) |
1742 |
(*params)++; |
1743 |
|
1744 |
/* And skip blanks, too */ |
1745 |
while (**params == ' ') |
1746 |
(*params)++; |
1747 |
|
1748 |
/* Get item */ |
1749 |
ob = find_object(item_tag); |
1750 |
if (!ob) { |
1751 |
if (from) |
1752 |
*from = STACK_FROM_NONE; |
1753 |
new_draw_info_format(NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag); |
1754 |
return NULL; |
1755 |
} |
1756 |
|
1757 |
/* Got one, let's push it on stack */ |
1758 |
dm_stack_push(pl, item_tag); |
1759 |
if (from) |
1760 |
*from = STACK_FROM_NUMBER; |
1761 |
return ob; |
1762 |
} |
1763 |
|
1764 |
/* Next case: $number => stack item */ |
1765 |
if (sscanf(*params, "$%d", &item_position)) { |
1766 |
/* Move parameter to next item */ |
1767 |
(*params)++; |
1768 |
|
1769 |
while (isdigit(**params)) |
1770 |
(*params)++; |
1771 |
while (**params == ' ') |
1772 |
(*params)++; |
1773 |
|
1774 |
if (item_position >= pl->stack_position) { |
1775 |
if (from) |
1776 |
*from = STACK_FROM_NONE; |
1777 |
new_draw_info_format(NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position); |
1778 |
return NULL; |
1779 |
} |
1780 |
|
1781 |
ob = find_object(pl->stack_items[item_position]); |
1782 |
if (!ob) { |
1783 |
if (from) |
1784 |
*from = STACK_FROM_NONE; |
1785 |
new_draw_info_format(NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position); |
1786 |
return NULL; |
1787 |
} |
1788 |
|
1789 |
if (from) |
1790 |
*from = item_position < pl->stack_position-1 ? STACK_FROM_STACK : STACK_FROM_TOP; |
1791 |
return ob; |
1792 |
} |
1793 |
|
1794 |
/* Next case: 'me' => return pl->ob */ |
1795 |
if (!strncmp(*params, "me", 2)) { |
1796 |
if (from) |
1797 |
*from = STACK_FROM_NUMBER; |
1798 |
dm_stack_push(pl, pl->ob->count); |
1799 |
|
1800 |
/* Skip to next token */ |
1801 |
(*params) += 2; |
1802 |
while (**params == ' ') |
1803 |
(*params)++; |
1804 |
|
1805 |
return pl->ob; |
1806 |
} |
1807 |
|
1808 |
/* Last case: get stack top */ |
1809 |
if (from) |
1810 |
*from = STACK_FROM_TOP; |
1811 |
return dm_stack_peek(pl); |
1812 |
} |
1813 |
|
1814 |
/** |
1815 |
* Pop the stack top. |
1816 |
*/ |
1817 |
int command_stack_pop(object *op, char *params) { |
1818 |
dm_stack_pop(op->contr); |
1819 |
return 0; |
1820 |
} |
1821 |
|
1822 |
/** |
1823 |
* Push specified item on stack. |
1824 |
*/ |
1825 |
int command_stack_push(object *op, char *params) { |
1826 |
object *ob; |
1827 |
int from; |
1828 |
ob = get_dm_object(op->contr, ¶ms, &from); |
1829 |
|
1830 |
if (ob && from != STACK_FROM_NUMBER) |
1831 |
/* Object was from stack, need to push it again */ |
1832 |
dm_stack_push(op->contr, ob->count); |
1833 |
|
1834 |
return 0; |
1835 |
} |
1836 |
|
1837 |
/** |
1838 |
* Displays stack contents. |
1839 |
*/ |
1840 |
int command_stack_list(object *op, char *params) { |
1841 |
int item; |
1842 |
object *display; |
1843 |
player *pl = op->contr; |
1844 |
|
1845 |
new_draw_info(NDI_UNIQUE, 0, op, "Item stack contents:"); |
1846 |
|
1847 |
for (item = 0; item < pl->stack_position; item++) { |
1848 |
display = find_object(pl->stack_items[item]); |
1849 |
if (display) |
1850 |
new_draw_info_format(NDI_UNIQUE, 0, op, " %d : %s [%d]", item, display->name, display->count); |
1851 |
else |
1852 |
/* Item was freed */ |
1853 |
new_draw_info_format(NDI_UNIQUE, 0, op, " %d : (lost item: %d)", item, pl->stack_items[item]); |
1854 |
} |
1855 |
|
1856 |
return 0; |
1857 |
} |
1858 |
|
1859 |
/** |
1860 |
* Empty DM item stack. |
1861 |
*/ |
1862 |
int command_stack_clear(object *op, char *params) { |
1863 |
op->contr->stack_position = 0; |
1864 |
new_draw_info(NDI_UNIQUE, 0, op, "Item stack cleared."); |
1865 |
return 0; |
1866 |
} |
1867 |
|
1868 |
/** |
1869 |
* Get a diff of specified items. |
1870 |
* Second item is compared to first, and differences displayed. |
1871 |
* Note: get_ob_diff works the opposite way (first compared to 2nd), |
1872 |
* but it's easier with stack functions to do it this way, so you can do: |
1873 |
* * stack_push <base> |
1874 |
* * stack_push <object to be compared> |
1875 |
* * diff |
1876 |
* * patch xxx <---- applies to object compared to base, easier :) |
1877 |
* |
1878 |
* Ryo, august 2004 |
1879 |
*/ |
1880 |
int command_diff(object *op, char *params) { |
1881 |
object *left, *right, *top; |
1882 |
const char *diff; |
1883 |
int left_from, right_from; |
1884 |
|
1885 |
top = NULL; |
1886 |
|
1887 |
left = get_dm_object(op->contr, ¶ms, &left_from); |
1888 |
if (!left) { |
1889 |
new_draw_info(NDI_UNIQUE, 0, op, "Compare to what item?"); |
1890 |
return 0; |
1891 |
} |
1892 |
|
1893 |
if (left_from == STACK_FROM_NUMBER) |
1894 |
/* Item was stacked, remove it else right will be the same... */ |
1895 |
dm_stack_pop(op->contr); |
1896 |
|
1897 |
right = get_dm_object(op->contr, ¶ms, &right_from); |
1898 |
|
1899 |
if (!right) { |
1900 |
new_draw_info(NDI_UNIQUE, 0, op, "Compare what item?"); |
1901 |
return 0; |
1902 |
} |
1903 |
|
1904 |
new_draw_info(NDI_UNIQUE, 0, op, "Item difference:"); |
1905 |
|
1906 |
if (left_from == STACK_FROM_TOP && right_from == STACK_FROM_TOP) { |
1907 |
/* |
1908 |
* Special case: both items were taken from stack top. |
1909 |
* Override the behaviour, taking left as item just below top, if exists. |
1910 |
* See function description for why. |
1911 |
* Besides, if we don't do anything, compare an item to itself, not really useful. |
1912 |
*/ |
1913 |
if (op->contr->stack_position > 1) { |
1914 |
left = find_object(op->contr->stack_items[op->contr->stack_position-2]); |
1915 |
if (left) |
1916 |
new_draw_info(NDI_UNIQUE, 0, op, "(Note: first item taken from undertop)"); |
1917 |
else |
1918 |
/* Stupid case: item under top was freed, fallback to stack top */ |
1919 |
left = right; |
1920 |
} |
1921 |
} |
1922 |
|
1923 |
diff = get_ob_diff(left, right); |
1924 |
|
1925 |
if (!diff) { |
1926 |
new_draw_info(NDI_UNIQUE, 0, op, "Objects are the same."); |
1927 |
return 0; |
1928 |
} |
1929 |
|
1930 |
new_draw_info(NDI_UNIQUE, 0, op, diff); |
1931 |
return 0; |
1932 |
} |
1933 |
|
1934 |
int command_insert_into(object* op, char *params) |
1935 |
{ |
1936 |
object *left, *right, *inserted; |
1937 |
const char *diff; |
1938 |
int left_from, right_from; |
1939 |
|
1940 |
left = get_dm_object(op->contr, ¶ms, &left_from); |
1941 |
if (!left) { |
1942 |
new_draw_info(NDI_UNIQUE, 0, op, "Insert into what object?"); |
1943 |
return 0; |
1944 |
} |
1945 |
|
1946 |
if (left_from == STACK_FROM_NUMBER) |
1947 |
/* Item was stacked, remove it else right will be the same... */ |
1948 |
dm_stack_pop(op->contr); |
1949 |
|
1950 |
right = get_dm_object(op->contr, ¶ms, &right_from); |
1951 |
|
1952 |
if (!right) { |
1953 |
new_draw_info(NDI_UNIQUE, 0, op, "Insert what item?"); |
1954 |
return 0; |
1955 |
} |
1956 |
|
1957 |
if (left_from == STACK_FROM_TOP && right_from == STACK_FROM_TOP) { |
1958 |
/* |
1959 |
* Special case: both items were taken from stack top. |
1960 |
* Override the behaviour, taking left as item just below top, if exists. |
1961 |
* See function description for why. |
1962 |
* Besides, can't insert an item into itself. |
1963 |
*/ |
1964 |
if (op->contr->stack_position > 1) { |
1965 |
left = find_object(op->contr->stack_items[op->contr->stack_position-2]); |
1966 |
if (left) |
1967 |
new_draw_info(NDI_UNIQUE, 0, op, "(Note: item to insert into taken from undertop)"); |
1968 |
else |
1969 |
/* Stupid case: item under top was freed, fallback to stack top */ |
1970 |
left = right; |
1971 |
} |
1972 |
} |
1973 |
|
1974 |
if (left == right) |
1975 |
{ |
1976 |
new_draw_info(NDI_UNIQUE, 0, op, "Can't insert an object into itself!"); |
1977 |
return 0; |
1978 |
} |
1979 |
|
1980 |
if (right->type == PLAYER) |
1981 |
{ |
1982 |
new_draw_info(NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1983 |
return 0; |
1984 |
} |
1985 |
|
1986 |
if (!QUERY_FLAG(right,FLAG_REMOVED)) |
1987 |
remove_ob(right); |
1988 |
inserted = insert_ob_in_ob(right,left); |
1989 |
if (left->type == PLAYER) |
1990 |
if (inserted == right) |
1991 |
esrv_send_item(left,right); |
1992 |
else |
1993 |
esrv_update_item(UPD_WEIGHT|UPD_NAME|UPD_NROF,left,inserted); |
1994 |
|
1995 |
new_draw_info_format(NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name(inserted),query_name(left)); |
1996 |
|
1997 |
return 0; |
1998 |
|
1999 |
} |