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