ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
(Generate patch)

Comparing deliantra/server/server/c_misc.C (file contents):
Revision 1.12 by root, Mon Oct 2 00:10:58 2006 UTC vs.
Revision 1.72 by root, Fri Dec 19 22:47:29 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <loader.h> 25#include <loader.h>
26#ifndef __CEXTRACT__
27# include <sproto.h> 26#include <sproto.h>
28#endif
29 27
30extern weathermap_t **weathermap;
31
32/* Handles misc. input request - things like hash table, malloc, maps, 28/* Handles misc. input request - things like hash table, malloc, maps, etc */
33 * who, etc.
34 */
35
36void
37map_info (object *op, char *search)
38{
39 maptile *m;
40 char buf[MAX_BUF], map_path[MAX_BUF];
41 long sec = seconds ();
42
43 new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
44 new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset");
45 for (m = first_map; m != NULL; m = m->next)
46 {
47
48 if (search && strstr (m->path, search) == NULL)
49 continue; /* Skip unwanted maps */
50 /* Print out the last 18 characters of the map name... */
51 if (strlen (m->path) <= 18)
52 strcpy (map_path, m->path);
53 else
54 strcpy (map_path, m->path + strlen (m->path) - 18);
55 sprintf (buf, "%-18.18s %2d %2d %1d %4d %2d %02d:%02d:%02d",
56 map_path, m->players, players_on_map (m, FALSE),
57 m->in_memory, m->timeout, m->difficulty,
58 (MAP_WHEN_RESET (m) % 86400) / 3600, (MAP_WHEN_RESET (m) % 3600) / 60, MAP_WHEN_RESET (m) % 60);
59 new_draw_info (NDI_UNIQUE, 0, op, buf);
60 }
61}
62
63/* This command dumps the body information for object *op.
64 * it doesn't care what the params are.
65 * This is mostly meant as a debug command.
66 */
67int
68command_body (object *op, char *params)
69{
70 int i;
71
72 /* Too hard to try and make a header that lines everything up, so just
73 * give a description.
74 */
75 new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location.");
76 new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has.");
77 new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available.");
78 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
79 {
80 /* really debugging - normally body_used should not be set to anything
81 * if body_info isn't also set.
82 */
83 if (op->body_info[i] || op->body_used[i])
84 {
85 new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]);
86 }
87 }
88 if (!QUERY_FLAG (op, FLAG_USE_ARMOUR))
89 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor");
90 if (!QUERY_FLAG (op, FLAG_USE_WEAPON))
91 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons");
92
93 return 1;
94}
95
96 29
97int 30int
98command_motd (object *op, char *params) 31command_motd (object *op, char *params)
99{ 32{
100 display_motd (op); 33 display_motd (op);
101 return 1;
102}
103
104int
105command_bug (object *op, char *params)
106{
107 char buf[MAX_BUF];
108
109 if (params == NULL)
110 {
111 new_draw_info (NDI_UNIQUE, 0, op, "what bugs?");
112 return 1;
113 }
114 strcpy (buf, op->name);
115 strcat (buf, " bug-reports: ");
116 strncat (buf, ++params, MAX_BUF - strlen (buf));
117 buf[MAX_BUF - 1] = '\0';
118 bug_report (buf);
119 LOG (llevError, "%s\n", buf);
120 new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf);
121 new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!");
122 return 1;
123}
124
125/*
126 * Pretty much identical to current map_info, but on a bigger scale
127 * This function returns the name of the players current region, and
128 * a description of it. It is there merely for flavour text.
129 */
130void
131current_region_info (object *op)
132{
133 /*
134 * Ok I /suppose/ I should write a seperate function for this, but it isn't
135 * going to be /that/ slow, and won't get called much
136 */
137 region *r = get_region_by_name (get_name_of_region_for_map (op->map));
138
139 if (!r)
140 return;
141 /* This should only be possible if regions are not operating on this server. */
142
143 new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r));
144}
145
146void
147current_map_info (object *op)
148{
149 maptile *m = op->map;
150
151 if (!m)
152 return;
153
154 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m));
155
156 if (QUERY_FLAG (op, FLAG_WIZ))
157 {
158 new_draw_info_format (NDI_UNIQUE, 0, op,
159 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld",
160 m->players, m->difficulty, MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m), MAP_TIMEOUT (m));
161
162 }
163 if (m->msg)
164 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
165}
166
167#ifdef DEBUG_MALLOC_LEVEL
168int
169command_malloc_verify (object *op, char *parms)
170{
171 extern int malloc_verify (void);
172
173 if (!malloc_verify ())
174 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
175 else
176 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
177 return 1;
178}
179#endif
180
181int
182command_whereabouts (object *op, char *params)
183{
184
185 region *reg;
186 player *pl;
187
188 /*
189 * reset the counter on the region, then use it to store the number of
190 * players there.
191 * I don't know how thread-safe this would be, I suspect not very....
192 */
193 for (reg = first_region; reg != NULL; reg = reg->next)
194 {
195 reg->counter = 0;
196 }
197 for (pl = first_player; pl != NULL; pl = pl->next)
198 if (pl->ob->map != NULL)
199 get_region_by_map (pl->ob->map)->counter++;
200
201 /* we only want to print out by places with a 'longname' field... */
202 for (reg = first_region; reg != NULL; reg = reg->next)
203 {
204 if (reg->longname == NULL && reg->counter > 0)
205 {
206 if (reg->parent != NULL)
207 {
208 reg->parent->counter += reg->counter;
209 reg->counter = 0;
210 }
211 else /*uh oh, we shouldn't be here. */
212 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name);
213 }
214 }
215 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
216 for (reg = first_region; reg != NULL; reg = reg->next)
217 if (reg->counter > 0)
218 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg));
219 return 1; 34 return 1;
220} 35}
221 36
222typedef struct 37typedef struct
223{ 38{
224 char namebuf[MAX_BUF]; 39 char namebuf[MAX_BUF];
225 int login_order; 40 int login_order;
226} chars_names; 41} chars_names;
227 42
228/*local functon for qsort comparison*/
229static int
230name_cmp (const chars_names * c1, const chars_names * c2)
231{
232 return strcasecmp (c1->namebuf, c2->namebuf);
233}
234
235int
236command_afk (object *op, char *params)
237{
238 if QUERY_FLAG
239 (op, FLAG_AFK)
240 {
241 CLEAR_FLAG (op, FLAG_AFK);
242 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
243 }
244 else
245 {
246 SET_FLAG (op, FLAG_AFK);
247 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
248 }
249 return 1;
250}
251
252int
253command_mapinfo (object *op, char *params)
254{
255 current_map_info (op);
256 return 1;
257}
258
259int
260command_whereami (object *op, char *params)
261{
262 current_region_info (op);
263 return 1;
264}
265
266int
267command_maps (object *op, char *params)
268{
269 map_info (op, params);
270 return 1;
271}
272
273int 43int
274command_time (object *op, char *params) 44command_time (object *op, char *params)
275{ 45{
276 print_tod (op); 46 print_tod (op);
277 return 1;
278}
279
280int
281command_weather (object *op, char *params)
282{
283 int wx, wy, temp, sky;
284 char buf[MAX_BUF];
285
286 if (settings.dynamiclevel < 1)
287 return 1;
288
289 if (op->map == NULL)
290 return 1;
291
292 if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0)
293 return 1;
294
295 if (QUERY_FLAG (op, FLAG_WIZ))
296 {
297 /* dump the weather, Dm style! Yo! */
298 new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map));
299 new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp);
300 new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid);
301 new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed);
302 new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure);
303 new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev);
304 new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water);
305 }
306
307 temp = real_world_temperature (op->x, op->y, op->map);
308 new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp);
309
310 /* humid */
311 if (weathermap[wx][wy].humid < 20)
312 new_draw_info (NDI_UNIQUE, 0, op, "It is very dry.");
313 else if (weathermap[wx][wy].humid < 40)
314 new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today.");
315 else if (weathermap[wx][wy].humid < 60)
316 new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy.");
317 else if (weathermap[wx][wy].humid < 80)
318 new_draw_info (NDI_UNIQUE, 0, op, "It is muggy.");
319 else
320 new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy.");
321
322 /* wind */
323 switch (weathermap[wx][wy].winddir)
324 {
325 case 1:
326 sprintf (buf, "north");
327 break;
328 case 2:
329 sprintf (buf, "northeast");
330 break;
331 case 3:
332 sprintf (buf, "east");
333 break;
334 case 4:
335 sprintf (buf, "southeast");
336 break;
337 case 5:
338 sprintf (buf, "south");
339 break;
340 case 6:
341 sprintf (buf, "southwest");
342 break;
343 case 7:
344 sprintf (buf, "west");
345 break;
346 case 8:
347 sprintf (buf, "northwest");
348 break;
349 }
350 if (weathermap[wx][wy].windspeed < 5)
351 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf);
352 else if (weathermap[wx][wy].windspeed < 10)
353 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf);
354 else if (weathermap[wx][wy].windspeed < 15)
355 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf);
356 else if (weathermap[wx][wy].windspeed < 25)
357 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf);
358 else if (weathermap[wx][wy].windspeed < 35)
359 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf);
360 else
361 new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf);
362
363 sky = weathermap[wx][wy].sky;
364 if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG)
365 sky += 10; /*let it snow */
366 switch (sky)
367 {
368 case SKY_CLEAR:
369 new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky.");
370 break;
371 case SKY_LIGHTCLOUD:
372 new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky.");
373 break;
374 case SKY_OVERCAST:
375 new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary.");
376 break;
377 case SKY_LIGHT_RAIN:
378 new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly.");
379 break;
380 case SKY_RAIN:
381 new_draw_info (NDI_UNIQUE, 0, op, "It is raining.");
382 break;
383 case SKY_HEAVY_RAIN:
384 new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily.");
385 break;
386 case SKY_HURRICANE:
387 new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!");
388 break;
389 case SKY_FOG:
390 new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable.");
391 break;
392 case SKY_HAIL:
393 new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!");
394 break;
395 case SKY_LIGHT_SNOW:
396 new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky.");
397 break;
398 case SKY_SNOW:
399 new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out.");
400 break;
401 case SKY_HEAVY_SNOW:
402 new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now.");
403 break;
404 case SKY_BLIZZARD:
405 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
406 break;
407 }
408 return 1;
409}
410
411int
412command_archs (object *op, char *params)
413{
414 arch_info (op);
415 return 1;
416}
417
418int
419command_hiscore (object *op, char *params)
420{
421 display_high_score (op, op == NULL ? 9999 : 50, params);
422 return 1; 47 return 1;
423} 48}
424 49
425int 50int
426command_debug (object *op, char *params) 51command_debug (object *op, char *params)
432 { 57 {
433 sprintf (buf, "Global debug level is %d.", settings.debug); 58 sprintf (buf, "Global debug level is %d.", settings.debug);
434 new_draw_info (NDI_UNIQUE, 0, op, buf); 59 new_draw_info (NDI_UNIQUE, 0, op, buf);
435 return 1; 60 return 1;
436 } 61 }
437 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) 62
438 { 63 settings.debug = i;
439 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); 64
440 return 1;
441 }
442 settings.debug = (enum LogLevel) FABS (i);
443 sprintf (buf, "Set debug level to %d.", i); 65 sprintf (buf, "Set debug level to %d.", i);
444 new_draw_info (NDI_UNIQUE, 0, op, buf); 66 new_draw_info (NDI_UNIQUE, 0, op, buf);
445 return 1; 67 return 1;
446} 68}
447 69
453int 75int
454command_dumpbelow (object *op, char *params) 76command_dumpbelow (object *op, char *params)
455{ 77{
456 if (op && op->below) 78 if (op && op->below)
457 { 79 {
458 dump_object (op->below); 80 char *dump = dump_object (op->below);
459 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 81 new_draw_info (NDI_UNIQUE, 0, op, dump);
82 free (dump);
460 /* Let's push that item on the dm's stack */ 83 /* Let's push that item on the dm's stack */
461 dm_stack_push (op->contr, op->below->count); 84 dm_stack_push (op->contr, op->below->count);
462 } 85 }
463 return 0; 86 return 0;
464} 87}
465 88
466int 89int
467command_wizcast (object *op, char *params)
468{
469 int i;
470
471 if (!op)
472 return 0;
473
474 if (!params)
475 i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1;
476 else
477 i = onoff_value (params);
478
479 if (i)
480 {
481 new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere.");
482 SET_FLAG (op, FLAG_WIZCAST);
483 }
484 else
485 {
486 new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas.");
487 CLEAR_FLAG (op, FLAG_WIZCAST);
488 }
489 return 0;
490}
491
492int
493command_dumpallobjects (object *op, char *params)
494{
495 dump_all_objects ();
496 return 0;
497}
498
499int
500command_dumpfriendlyobjects (object *op, char *params) 90command_dumpfriendlyobjects (object *op, char *params)
501{ 91{
502 dump_friendly_objects (); 92 dump_friendly_objects ();
503 return 0; 93 return 0;
504} 94}
505 95
506int 96int
507command_dumpallarchetypes (object *op, char *params)
508{
509 dump_all_archetypes ();
510 return 0;
511}
512
513int
514command_dumpmap (object *op, char *params)
515{
516 if (op)
517 dump_map (op->map);
518 return 0;
519}
520
521int
522command_dumpallmaps (object *op, char *params)
523{
524 dump_all_maps ();
525 return 0;
526}
527
528int
529command_printlos (object *op, char *params)
530{
531 if (op)
532 print_los (op);
533 return 0;
534}
535
536
537int
538command_version (object *op, char *params) 97command_version (object *op, char *params)
539{ 98{
540 version (op); 99 version (op);
541 return 0; 100 return 0;
542} 101}
543
544 102
545#ifndef BUG_LOG 103#ifndef BUG_LOG
546# define BUG_LOG "bug_log" 104# define BUG_LOG "bug_log"
547#endif 105#endif
548void 106void
559 { 117 {
560 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); 118 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
561 } 119 }
562} 120}
563 121
564int
565command_output_sync (object *op, char *params)
566{
567 int val;
568
569 if (!params)
570 {
571 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
572 return 1;
573 }
574 val = atoi (params);
575 if (val > 0)
576 {
577 op->contr->outputs_sync = val;
578 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
579 }
580 else
581 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
582
583 return 1;
584}
585
586int
587command_output_count (object *op, char *params)
588{
589 int val;
590
591 if (!params)
592 {
593 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
594 return 1;
595 }
596 val = atoi (params);
597 if (val > 0)
598 {
599 op->contr->outputs_count = val;
600 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
601 }
602 else
603 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
604
605 return 1;
606}
607
608int
609command_listen (object *op, char *params)
610{
611 int i;
612
613 if (params == NULL || !sscanf (params, "%d", &i))
614 {
615 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
616 return 1;
617 }
618 op->contr->listening = (char) i;
619 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
620 return 1;
621}
622
623/* Prints out some useful information for the character. Everything we print 122/* Prints out some useful information for the character. Everything we print
624 * out can be determined by the docs, so we aren't revealing anything extra - 123 * out can be determined by the docs, so we aren't revealing anything extra -
625 * rather, we are making it convenient to find the values. params have 124 * rather, we are making it convenient to find the values. params have
626 * no meaning here. 125 * no meaning here.
627 */ 126 */
628int 127int
629command_statistics (object *pl, char *params) 128command_statistics (object *pl, char *params)
630{ 129{
631 if (!pl->contr) 130 if (!pl->contr)
632 return 1; 131 return 1;
633#ifndef WIN32
634 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp);
635 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul));
636#else
637 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp); 132 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
638 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul)); 133 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
639#endif
640 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); 134 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
641 135
642 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 136 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
643 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 137 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->stats.Str);
644 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 138 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
645 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); 139 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->stats.Dex);
646 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 140 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d",
647 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 141 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->stats.Con);
648 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 142 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d",
649 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); 143 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->stats.Int);
650 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 144 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d",
651 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 145 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->stats.Wis);
652 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 146 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d",
653 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 147 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->stats.Pow);
654 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d", 148 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
655 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha); 149 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->stats.Cha);
656 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile"); 150 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
657 151
658 /* Can't think of anything else to print right now */ 152 /* Can't think of anything else to print right now */
659 return 0; 153 return 0;
660} 154}
661 155
662int 156int
663command_fix_me (object *op, char *params) 157command_fix_me (object *op, char *params)
664{ 158{
665 sum_weight (op); 159 op->update_weight ();
666 fix_player (op); 160 op->update_stats ();
667 return 1; 161 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
668}
669 162
670int
671command_players (object *op, char *paramss)
672{
673 char buf[MAX_BUF];
674 char *t;
675 DIR *Dir;
676
677 sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir);
678 t = buf + strlen (buf);
679 if ((Dir = opendir (buf)) != NULL)
680 {
681 const struct dirent *Entry;
682
683 while ((Entry = readdir (Dir)) != NULL)
684 {
685 /* skip '.' , '..' */
686 if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') ||
687 (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0')))
688 {
689 struct stat Stat;
690
691 strcpy (t, Entry->d_name);
692 if (stat (buf, &Stat) == 0)
693 {
694 /* This was not posix compatible
695 * if ((Stat.st_mode & S_IFMT)==S_IFDIR) {
696 */
697 if (S_ISDIR (Stat.st_mode))
698 {
699 char buf2[MAX_BUF];
700 struct tm *tm = localtime (&Stat.st_mtime);
701
702 sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d",
703 Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
704 new_draw_info (NDI_UNIQUE, 0, op, buf2);
705 }
706 }
707 }
708 }
709 }
710 closedir (Dir);
711 return 0;
712}
713
714
715
716int
717command_logs (object *op, char *params)
718{
719 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
720
721 return 1;
722}
723
724int
725command_applymode (object *op, char *params)
726{
727 unapplymode unapply = op->contr->unapply;
728 static const char *const types[] = { "nochoice", "never", "always" };
729
730 if (!params)
731 {
732 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
733 return 1;
734 }
735
736 if (!strcmp (params, "nochoice"))
737 op->contr->unapply = unapply_nochoice;
738 else if (!strcmp (params, "never"))
739 op->contr->unapply = unapply_never;
740 else if (!strcmp (params, "always"))
741 op->contr->unapply = unapply_always;
742 else
743 {
744 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
745 return 0;
746 }
747 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
748 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
749 return 1; 163 return 1;
750} 164}
751 165
752int 166int
753command_bowmode (object *op, char *params) 167command_bowmode (object *op, char *params)
773 found++; 187 found++;
774 op->contr->bowtype = (bowtype_t) i; 188 op->contr->bowtype = (bowtype_t) i;
775 break; 189 break;
776 } 190 }
777 } 191 }
192
778 if (!found) 193 if (!found)
779 { 194 {
780 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 195 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
781 for (i = 0; i <= bow_bestarrow; i++) 196 for (i = 0; i <= bow_bestarrow; i++)
782 { 197 {
788 strcat (buf, "."); 203 strcat (buf, ".");
789 } 204 }
790 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 205 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
791 return 0; 206 return 0;
792 } 207 }
208
793 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 209 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
794 return 1;
795}
796
797int
798command_petmode (object *op, char *params)
799{
800 petmode_t oldtype = op->contr->petmode;
801 static const char *const types[] = { "normal", "sad", "defend", "arena" };
802
803 if (!params)
804 {
805 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
806 return 1;
807 }
808
809 if (!strcmp (params, "normal"))
810 op->contr->petmode = pet_normal;
811 else if (!strcmp (params, "sad"))
812 op->contr->petmode = pet_sad;
813 else if (!strcmp (params, "defend"))
814 op->contr->petmode = pet_defend;
815 else if (!strcmp (params, "arena"))
816 op->contr->petmode = pet_arena;
817 else
818 {
819 new_draw_info_format (NDI_UNIQUE, 0, op,
820 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
821 return 0;
822 }
823 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
824 return 1; 210 return 1;
825} 211}
826 212
827int 213int
828command_showpets (object *op, char *params) 214command_showpets (object *op, char *params)
836 for (obl = first_friendly_object; obl != NULL; obl = next) 222 for (obl = first_friendly_object; obl != NULL; obl = next)
837 { 223 {
838 object *ob = obl->ob; 224 object *ob = obl->ob;
839 225
840 next = obl->next; 226 next = obl->next;
841 if (get_owner (ob) == op) 227 if (ob->owner == op)
842 { 228 {
843 if (target == 0) 229 if (target == 0)
844 { 230 {
845 if (counter == 0) 231 if (counter == 0)
846 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 232 new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
869 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 255 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
870 return 0; 256 return 0;
871} 257}
872 258
873int 259int
874command_usekeys (object *op, char *params)
875{
876 usekeytype oldtype = op->contr->usekeys;
877 static const char *const types[] = { "inventory", "keyrings", "containers" };
878
879 if (!params)
880 {
881 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
882 return 1;
883 }
884
885 if (!strcmp (params, "inventory"))
886 op->contr->usekeys = key_inventory;
887 else if (!strcmp (params, "keyrings"))
888 op->contr->usekeys = keyrings;
889 else if (!strcmp (params, "containers"))
890 op->contr->usekeys = containers;
891 else
892 {
893 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
894 return 0;
895 }
896 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
897 return 1;
898}
899
900int
901command_resistances (object *op, char *params) 260command_resistances (object *op, char *params)
902{ 261{
903 int i; 262 int i;
904 263
905 if (!op) 264 if (!op)
919 int attack; 278 int attack;
920 object *tmp; 279 object *tmp;
921 280
922 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 281 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
923 { 282 {
924 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 283 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
925 { 284 {
926 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 285 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
927 for (attack = 0; attack < NROFATTACKS; attack++) 286 for (attack = 0; attack < NROFATTACKS; attack++)
928 { 287 {
929 if (atnr_is_dragon_enabled (attack)) 288 if (atnr_is_dragon_enabled (attack))
941 300
942/* 301/*
943 * Actual commands. 302 * Actual commands.
944 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) 303 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
945 */ 304 */
946
947
948static void
949help_topics (object *op, int what)
950{
951 DIR *dirp;
952 struct dirent *de;
953 char filename[MAX_BUF], line[80];
954 int namelen, linelen = 0;
955
956 switch (what)
957 {
958 case 1:
959 sprintf (filename, "%s/wizhelp", settings.datadir);
960 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
961 break;
962 case 3:
963 sprintf (filename, "%s/mischelp", settings.datadir);
964 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
965 break;
966 default:
967 sprintf (filename, "%s/help", settings.datadir);
968 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
969 break;
970 }
971 if (!(dirp = opendir (filename)))
972 return;
973
974 line[0] = '\0';
975 for (de = readdir (dirp); de; de = readdir (dirp))
976 {
977 namelen = NAMLEN (de);
978 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
979 continue;
980 linelen += namelen + 1;
981 if (linelen > 42)
982 {
983 new_draw_info (NDI_UNIQUE, 0, op, line);
984 sprintf (line, " %s", de->d_name);
985 linelen = namelen + 1;
986 continue;
987 }
988 strcat (line, " ");
989 strcat (line, de->d_name);
990 }
991 new_draw_info (NDI_UNIQUE, 0, op, line);
992 closedir (dirp);
993}
994
995static void
996show_commands (object *op, int what)
997{
998 char line[80];
999 int i, size, namelen, linelen = 0;
1000 CommArray_s *ap;
1001 extern CommArray_s Commands[], WizCommands[];
1002 extern const int CommandsSize, WizCommandsSize;
1003
1004 switch (what)
1005 {
1006 case 1:
1007 ap = WizCommands;
1008 size = WizCommandsSize;
1009 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
1010 break;
1011 case 2:
1012 ap = CommunicationCommands;
1013 size = CommunicationCommandSize;
1014 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
1015 break;
1016 default:
1017 ap = Commands;
1018 size = CommandsSize;
1019 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
1020 break;
1021 }
1022
1023 line[0] = '\0';
1024 for (i = 0; i < size; i++)
1025 {
1026 namelen = strlen (ap[i].name);
1027 linelen += namelen + 1;
1028 if (linelen > 42)
1029 {
1030 new_draw_info (NDI_UNIQUE, 0, op, line);
1031 sprintf (line, " %s", ap[i].name);
1032 linelen = namelen + 1;
1033 continue;
1034 }
1035 strcat (line, " ");
1036 strcat (line, ap[i].name);
1037 }
1038 new_draw_info (NDI_UNIQUE, 0, op, line);
1039}
1040
1041
1042int
1043command_help (object *op, char *params)
1044{
1045 struct stat st;
1046 FILE *fp;
1047 char filename[MAX_BUF], line[MAX_BUF];
1048 int len;
1049
1050 if (op != NULL)
1051 clear_win_info (op);
1052
1053/*
1054 * Main help page?
1055 */
1056 if (!params)
1057 {
1058 sprintf (filename, "%s/def_help", settings.datadir);
1059 if ((fp = fopen (filename, "r")) == NULL)
1060 {
1061 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1062 return 0;
1063 }
1064 while (fgets (line, MAX_BUF, fp))
1065 {
1066 line[MAX_BUF - 1] = '\0';
1067 len = strlen (line) - 1;
1068 if (line[len] == '\n')
1069 line[len] = '\0';
1070 new_draw_info (NDI_UNIQUE, 0, op, line);
1071 }
1072 fclose (fp);
1073 return 0;
1074 }
1075
1076 /*
1077 * Topics list
1078 */
1079 if (!strcmp (params, "topics"))
1080 {
1081 help_topics (op, 3);
1082 help_topics (op, 0);
1083 if (QUERY_FLAG (op, FLAG_WIZ))
1084 help_topics (op, 1);
1085 return 0;
1086 }
1087
1088 /*
1089 * Commands list
1090 */
1091 if (!strcmp (params, "commands"))
1092 {
1093 show_commands (op, 0);
1094 show_commands (op, 2); /* show comm commands */
1095 if (QUERY_FLAG (op, FLAG_WIZ))
1096 show_commands (op, 1);
1097 return 0;
1098 }
1099
1100 /*
1101 * User wants info about command
1102 */
1103 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
1104 {
1105 sprintf (line, "Illegal characters in '%s'", params);
1106 new_draw_info (NDI_UNIQUE, 0, op, line);
1107 return 0;
1108 }
1109
1110 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
1111 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1112 {
1113 if (op)
1114 {
1115 sprintf (filename, "%s/help/%s", settings.datadir, params);
1116 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1117 {
1118 if (QUERY_FLAG (op, FLAG_WIZ))
1119 {
1120 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
1121 if (stat (filename, &st) || !S_ISREG (st.st_mode))
1122 goto nohelp;
1123 }
1124 else
1125 goto nohelp;
1126 }
1127 }
1128 }
1129
1130 /*
1131 * Found that. Just cat it to screen.
1132 */
1133 if ((fp = fopen (filename, "r")) == NULL)
1134 {
1135 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
1136 return 0;
1137 }
1138 sprintf (line, "Help about '%s'", params);
1139 new_draw_info (NDI_UNIQUE, 0, op, line);
1140 while (fgets (line, MAX_BUF, fp))
1141 {
1142 line[MAX_BUF - 1] = '\0';
1143 len = strlen (line) - 1;
1144 if (line[len] == '\n')
1145 line[len] = '\0';
1146 new_draw_info (NDI_UNIQUE, 0, op, line);
1147 }
1148 fclose (fp);
1149 return 0;
1150
1151 /*
1152 * No_help -escape
1153 */
1154nohelp:
1155 sprintf (line, "No help available on '%s'", params);
1156 new_draw_info (NDI_UNIQUE, 0, op, line);
1157 return 0;
1158}
1159
1160 305
1161int 306int
1162onoff_value (const char *line) 307onoff_value (const char *line)
1163{ 308{
1164 int i; 309 int i;
1187 return 0; 332 return 0;
1188 } 333 }
1189} 334}
1190 335
1191int 336int
1192command_quit (object *op, char *params)
1193{
1194 new_draw_info (NDI_UNIQUE, 0, op,
1195 "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit.");
1196 return 1;
1197}
1198
1199int
1200command_real_quit (object *op, char *params)
1201{
1202 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Quitting will delete your character.\nAre you sure you want to quit (y/n):");
1203
1204 op->contr->state = ST_CONFIRM_QUIT;
1205 return 1;
1206}
1207
1208/*
1209 * don't allow people to exit explore mode. It otherwise becomes
1210 * really easy to abuse this.
1211 */
1212int
1213command_explore (object *op, char *params)
1214{
1215 if (settings.explore_mode == FALSE)
1216 return 1;
1217 /*
1218 * I guess this is the best way to see if we are solo or not. Actually,
1219 * are there any cases when first_player->next==NULL and we are not solo?
1220 */
1221 if ((first_player != op->contr) || (first_player->next != NULL))
1222 {
1223 new_draw_info (NDI_UNIQUE, 0, op, "You can not enter explore mode if you are in a party");
1224 }
1225 else if (op->contr->explore)
1226 new_draw_info (NDI_UNIQUE, 0, op, "There is no return from explore mode");
1227 else
1228 {
1229 op->contr->explore = 1;
1230 new_draw_info (NDI_UNIQUE, 0, op, "You are now in explore mode");
1231 }
1232 return 1;
1233}
1234
1235int
1236command_sound (object *op, char *params)
1237{
1238 if (op->contr->socket.sound)
1239 {
1240 op->contr->socket.sound = 0;
1241 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1242 }
1243 else
1244 {
1245 op->contr->socket.sound = 1;
1246 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1247 }
1248 return 1;
1249}
1250
1251/* Perhaps these should be in player.c, but that file is
1252 * already a bit big.
1253 */
1254
1255void
1256receive_player_name (object *op, char k)
1257{
1258
1259 if (!check_name (op->contr, op->contr->write_buf + 1))
1260 {
1261 get_name (op);
1262 return;
1263 }
1264 op->name = op->contr->write_buf + 1;
1265 op->name_pl = op->contr->write_buf + 1;
1266 new_draw_info (NDI_UNIQUE, 0, op, op->contr->write_buf);
1267 op->contr->name_changed = 1;
1268 get_password (op);
1269}
1270
1271void
1272receive_player_password (object *op, char k)
1273{
1274
1275 unsigned int pwd_len = strlen (op->contr->write_buf);
1276
1277 if (pwd_len <= 1 || pwd_len > 17)
1278 {
1279 get_name (op);
1280 return;
1281 }
1282 new_draw_info (NDI_UNIQUE, 0, op, " "); /* To hide the password better */
1283
1284 if (checkbanned (op->name, op->contr->socket.host))
1285 {
1286 LOG (llevInfo, "Banned player tried to add: [%s@%s]\n", &op->name, op->contr->socket.host);
1287 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, "You are not allowed to play.");
1288 get_name (op);
1289 return;
1290 }
1291
1292 if (op->contr->state == ST_CONFIRM_PASSWORD)
1293 {
1294 if (!check_password (op->contr->write_buf + 1, op->contr->password))
1295 {
1296 new_draw_info (NDI_UNIQUE, 0, op, "The passwords did not match.");
1297 get_name (op);
1298 return;
1299 }
1300 clear_win_info (op);
1301 display_motd (op);
1302 new_draw_info (NDI_UNIQUE, 0, op, " ");
1303 new_draw_info (NDI_UNIQUE, 0, op, "Welcome, Brave New Warrior!");
1304 new_draw_info (NDI_UNIQUE, 0, op, " ");
1305 Roll_Again (op);
1306 op->contr->state = ST_ROLL_STAT;
1307 return;
1308 }
1309 strcpy (op->contr->password, crypt_string (op->contr->write_buf + 1, NULL));
1310 op->contr->state = ST_ROLL_STAT;
1311 check_login (op);
1312 return;
1313}
1314
1315
1316int
1317explore_mode (void)
1318{
1319 player *pl;
1320
1321 if (settings.explore_mode == TRUE)
1322 {
1323 for (pl = first_player; pl != (player *) NULL; pl = pl->next)
1324 if (pl->explore)
1325 return 1;
1326 }
1327 return 0;
1328}
1329
1330
1331int
1332command_title (object *op, char *params) 337command_title (object *op, char *params)
1333{ 338{
1334 char buf[MAX_BUF]; 339 char buf[MAX_BUF];
1335 340
1336 if (settings.set_title == FALSE) 341 if (settings.set_title == FALSE)
1373 strcpy (op->contr->own_title, params); 378 strcpy (op->contr->own_title, params);
1374 return 1; 379 return 1;
1375} 380}
1376 381
1377int 382int
1378command_save (object *op, char *params)
1379{
1380// if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_CLERIC) {
1381// new_draw_info(NDI_UNIQUE, 0, op, "You can not save on unholy ground");
1382// } else
1383 if (!op->stats.exp)
1384 {
1385 new_draw_info (NDI_UNIQUE, 0, op, "You don't deserve to save yet.");
1386 }
1387 else
1388 {
1389 if (save_player (op, 1))
1390 new_draw_info (NDI_UNIQUE, 0, op, "You have been saved.");
1391 else
1392 new_draw_info (NDI_UNIQUE, 0, op, "SAVE FAILED!");
1393 }
1394 return 1;
1395}
1396
1397
1398int
1399command_peaceful (object *op, char *params)
1400{
1401 new_draw_info (NDI_UNIQUE, 0, op,
1402 "You cannot change your peaceful setting with this command."
1403 " Please speak to the priest in the temple of Gorokh"
1404 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1405
1406/*
1407 if((op->contr->peaceful=!op->contr->peaceful))
1408 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1409 else
1410 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1411*/
1412 return 1;
1413}
1414
1415
1416
1417int
1418command_wimpy (object *op, char *params)
1419{
1420 int i;
1421 char buf[MAX_BUF];
1422
1423 if (params == NULL || !sscanf (params, "%d", &i))
1424 {
1425 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1426 new_draw_info (NDI_UNIQUE, 0, op, buf);
1427 return 1;
1428 }
1429 sprintf (buf, "Your new wimpy level is %d.", i);
1430 new_draw_info (NDI_UNIQUE, 0, op, buf);
1431 op->run_away = i;
1432 return 1;
1433}
1434
1435
1436int
1437command_brace (object *op, char *params)
1438{
1439 if (!params)
1440 op->contr->braced = !op->contr->braced;
1441 else
1442 op->contr->braced = onoff_value (params);
1443
1444 if (op->contr->braced)
1445 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1446 else
1447 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1448
1449 fix_player (op);
1450 return 0;
1451}
1452
1453int
1454command_style_map_info (object *op, char *params)
1455{
1456 extern maptile *styles;
1457 maptile *mp;
1458 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1459 object *tmp;
1460
1461 for (mp = styles; mp != NULL; mp = mp->next)
1462 {
1463 maps_used++;
1464 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1465 for (x = 0; x < MAP_WIDTH (mp); x++)
1466 {
1467 for (y = 0; y < MAP_HEIGHT (mp); y++)
1468 {
1469 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above)
1470 objects_used++;
1471 }
1472 }
1473 }
1474 new_draw_info_format (NDI_UNIQUE, 0, op, "Style maps loaded: %d", maps_used);
1475 new_draw_info (NDI_UNIQUE, 0, op, "Memory used, not");
1476 new_draw_info_format (NDI_UNIQUE, 0, op, "including objects: %d", mapmem);
1477 new_draw_info_format (NDI_UNIQUE, 0, op, "Style objects: %d", objects_used);
1478 new_draw_info_format (NDI_UNIQUE, 0, op, "Mem for objects: %d", objects_used * sizeof (object));
1479 return 0;
1480}
1481
1482int
1483command_kill_pets (object *op, char *params) 383command_kill_pets (object *op, char *params)
1484{ 384{
1485 objectlink *obl, *next; 385 objectlink *obl, *next;
1486 int counter = 0, removecount = 0; 386 int counter = 0, removecount = 0;
1487 387
1488 if (params == NULL) 388 if (!params)
1489 { 389 {
1490 terminate_all_pets (op); 390 terminate_all_pets (op);
1491 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 391 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1492 } 392 }
1493 else 393 else
1494 { 394 {
1495 int target = atoi (params); 395 int target = atoi (params);
1496 396
1497 for (obl = first_friendly_object; obl != NULL; obl = next) 397 for (obl = first_friendly_object; obl; obl = next)
1498 { 398 {
1499 object *ob = obl->ob; 399 object *ob = obl->ob;
1500 400
1501 next = obl->next; 401 next = obl->next;
402
1502 if (get_owner (ob) == op) 403 if (ob->owner == op)
1503 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 404 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1504 { 405 {
1505 if (!QUERY_FLAG (ob, FLAG_REMOVED))
1506 remove_ob (ob);
1507 remove_friendly_object (ob);
1508 free_object (ob); 406 ob->destroy ();
1509 removecount++; 407 removecount++;
1510 } 408 }
1511 } 409 }
410
1512 if (removecount != 0) 411 if (removecount != 0)
1513 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 412 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1514 else 413 else
1515 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 414 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1516 } 415 }
416
1517 return 0; 417 return 0;
1518} 418}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines