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.46 by pippijn, Thu Mar 1 13:18:37 2007 UTC vs.
Revision 1.71 by root, Mon Sep 29 10:32:50 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 (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * 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
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <loader.h> 25#include <loader.h>
27#include <sproto.h> 26#include <sproto.h>
28 27
29/* Handles misc. input request - things like hash table, malloc, maps, 28/* Handles misc. input request - things like hash table, malloc, maps, etc */
30 * who, etc.
31 */
32
33/* This command dumps the body information for object *op.
34 * it doesn't care what the params are.
35 * This is mostly meant as a debug command.
36 */
37int
38command_body (object *op, char *params)
39{
40 int i;
41
42 /* Too hard to try and make a header that lines everything up, so just
43 * give a description.
44 */
45 new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location.");
46 new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has.");
47 new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available.");
48 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
49 {
50 /* really debugging - normally body_used should not be set to anything
51 * if body_info isn't also set.
52 */
53 if (op->body_info[i] || op->body_used[i])
54 {
55 new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]);
56 }
57 }
58 if (!QUERY_FLAG (op, FLAG_USE_ARMOUR))
59 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor");
60 if (!QUERY_FLAG (op, FLAG_USE_WEAPON))
61 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons");
62
63 return 1;
64}
65
66 29
67int 30int
68command_motd (object *op, char *params) 31command_motd (object *op, char *params)
69{ 32{
70 display_motd (op); 33 display_motd (op);
71 return 1;
72}
73
74/*
75 * Pretty much identical to current map_info, but on a bigger scale
76 * This function returns the name of the players current region, and
77 * a description of it. It is there merely for flavour text.
78 */
79void
80current_region_info (object *op)
81{
82 if (region *reg = op->region ())
83 new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", &reg->longname, &reg->msg);
84}
85
86void
87current_map_info (object *op)
88{
89 maptile *m = op->map;
90
91 if (!m)
92 return;
93
94 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) %s", &m->name, &m->path, &op->region ()->longname);
95
96 if (QUERY_FLAG (op, FLAG_WIZ))
97 new_draw_info_format (NDI_UNIQUE, 0, op,
98 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld",
99 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout);
100
101 if (m->msg)
102 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
103}
104
105#ifdef DEBUG_MALLOC_LEVEL
106int
107command_malloc_verify (object *op, char *parms)
108{
109 extern int malloc_verify (void);
110
111 if (!malloc_verify ())
112 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
113 else
114 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
115 return 1;
116}
117#endif
118
119int
120command_whereabouts (object *op, char *params)
121{
122 //TODO: should obviously not waste space in struct region for this.
123 /*
124 * reset the counter on the region, then use it to store the number of
125 * players there.
126 * I don't know how thread-safe this would be, I suspect not very....
127 */
128 for_all_regions (rgn)
129 rgn->counter = 0;
130
131 for_all_players (pl)
132 if (pl->ob->map)
133 ++pl->ob->region ()->counter;
134
135 /* we only want to print out by places with a 'longname' field... */
136 for_all_regions (rgn)
137 {
138 if (!rgn->longname && rgn->counter > 0)
139 {
140 if (rgn->parent)
141 {
142 rgn->parent->counter += rgn->counter;
143 rgn->counter = 0;
144 }
145 else /*uh oh, we shouldn't be here. */
146 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name);
147 }
148 }
149
150 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
151
152 for_all_regions (rgn)
153 if (rgn->counter)
154 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname);
155
156 return 1; 34 return 1;
157} 35}
158 36
159typedef struct 37typedef struct
160{ 38{
161 char namebuf[MAX_BUF]; 39 char namebuf[MAX_BUF];
162 int login_order; 40 int login_order;
163} chars_names; 41} chars_names;
164 42
165int 43int
166command_afk (object *op, char *params)
167{
168 if ((op->contr->ns->afk = !op->contr->ns->afk))
169 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
170 else
171 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
172
173 return 1;
174}
175
176int
177command_mapinfo (object *op, char *params)
178{
179 current_map_info (op);
180 return 1;
181}
182
183int
184command_whereami (object *op, char *params)
185{
186 current_region_info (op);
187 return 1;
188}
189
190int
191command_time (object *op, char *params) 44command_time (object *op, char *params)
192{ 45{
193 print_tod (op); 46 print_tod (op);
194 return 1;
195}
196
197int
198command_weather (object *op, char *params)
199{
200#if 0
201 int wx, wy, temp, sky;
202 char buf[MAX_BUF];
203
204 if (settings.dynamiclevel < 1)
205 return 1;
206
207 if (op->map == NULL)
208 return 1;
209
210 if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0)
211 return 1;
212
213 if (QUERY_FLAG (op, FLAG_WIZ))
214 {
215 /* dump the weather, Dm style! Yo! */
216 new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map));
217 new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp);
218 new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid);
219 new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed);
220 new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure);
221 new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev);
222 new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water);
223 }
224
225 temp = real_world_temperature (op->x, op->y, op->map);
226 new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp);
227
228 /* humid */
229 if (weathermap[wx][wy].humid < 20)
230 new_draw_info (NDI_UNIQUE, 0, op, "It is very dry.");
231 else if (weathermap[wx][wy].humid < 40)
232 new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today.");
233 else if (weathermap[wx][wy].humid < 60)
234 new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy.");
235 else if (weathermap[wx][wy].humid < 80)
236 new_draw_info (NDI_UNIQUE, 0, op, "It is muggy.");
237 else
238 new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy.");
239
240 /* wind */
241 switch (weathermap[wx][wy].winddir)
242 {
243 case 1:
244 sprintf (buf, "north");
245 break;
246 case 2:
247 sprintf (buf, "northeast");
248 break;
249 case 3:
250 sprintf (buf, "east");
251 break;
252 case 4:
253 sprintf (buf, "southeast");
254 break;
255 case 5:
256 sprintf (buf, "south");
257 break;
258 case 6:
259 sprintf (buf, "southwest");
260 break;
261 case 7:
262 sprintf (buf, "west");
263 break;
264 case 8:
265 sprintf (buf, "northwest");
266 break;
267 }
268 if (weathermap[wx][wy].windspeed < 5)
269 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf);
270 else if (weathermap[wx][wy].windspeed < 10)
271 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf);
272 else if (weathermap[wx][wy].windspeed < 15)
273 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf);
274 else if (weathermap[wx][wy].windspeed < 25)
275 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf);
276 else if (weathermap[wx][wy].windspeed < 35)
277 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf);
278 else
279 new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf);
280
281 sky = weathermap[wx][wy].sky;
282 if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG)
283 sky += 10; /*let it snow */
284 switch (sky)
285 {
286 case SKY_CLEAR:
287 new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky.");
288 break;
289 case SKY_LIGHTCLOUD:
290 new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky.");
291 break;
292 case SKY_OVERCAST:
293 new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary.");
294 break;
295 case SKY_LIGHT_RAIN:
296 new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly.");
297 break;
298 case SKY_RAIN:
299 new_draw_info (NDI_UNIQUE, 0, op, "It is raining.");
300 break;
301 case SKY_HEAVY_RAIN:
302 new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily.");
303 break;
304 case SKY_HURRICANE:
305 new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!");
306 break;
307 case SKY_FOG:
308 new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable.");
309 break;
310 case SKY_HAIL:
311 new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!");
312 break;
313 case SKY_LIGHT_SNOW:
314 new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky.");
315 break;
316 case SKY_SNOW:
317 new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out.");
318 break;
319 case SKY_HEAVY_SNOW:
320 new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now.");
321 break;
322 case SKY_BLIZZARD:
323 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
324 break;
325 }
326#endif
327 return 1;
328}
329
330int
331command_hiscore (object *op, char *params)
332{
333 display_high_score (op, op == NULL ? 9999 : 50, params);
334 return 1; 47 return 1;
335} 48}
336 49
337int 50int
338command_debug (object *op, char *params) 51command_debug (object *op, char *params)
344 { 57 {
345 sprintf (buf, "Global debug level is %d.", settings.debug); 58 sprintf (buf, "Global debug level is %d.", settings.debug);
346 new_draw_info (NDI_UNIQUE, 0, op, buf); 59 new_draw_info (NDI_UNIQUE, 0, op, buf);
347 return 1; 60 return 1;
348 } 61 }
349 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) 62
350 { 63 settings.debug = i;
351 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); 64
352 return 1;
353 }
354 settings.debug = (enum LogLevel) FABS (i);
355 sprintf (buf, "Set debug level to %d.", i); 65 sprintf (buf, "Set debug level to %d.", i);
356 new_draw_info (NDI_UNIQUE, 0, op, buf); 66 new_draw_info (NDI_UNIQUE, 0, op, buf);
357 return 1; 67 return 1;
358} 68}
359 69
416 { 126 {
417 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno)); 127 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
418 } 128 }
419} 129}
420 130
421int
422command_output_sync (object *op, char *params)
423{
424 int val;
425
426 if (!params)
427 {
428 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
429 return 1;
430 }
431 val = atoi (params);
432 if (val > 0)
433 {
434 op->contr->outputs_sync = val;
435 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
436 }
437 else
438 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
439
440 return 1;
441}
442
443int
444command_output_count (object *op, char *params)
445{
446 int val;
447
448 if (!params)
449 {
450 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
451 return 1;
452 }
453 val = atoi (params);
454 if (val > 0)
455 {
456 op->contr->outputs_count = val;
457 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
458 }
459 else
460 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
461
462 return 1;
463}
464
465int
466command_listen (object *op, char *params)
467{
468 int i;
469
470 if (params == NULL || !sscanf (params, "%d", &i))
471 {
472 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
473 return 1;
474 }
475 op->contr->listening = (char) i;
476 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
477 return 1;
478}
479
480/* Prints out some useful information for the character. Everything we print 131/* Prints out some useful information for the character. Everything we print
481 * out can be determined by the docs, so we aren't revealing anything extra - 132 * out can be determined by the docs, so we aren't revealing anything extra -
482 * rather, we are making it convenient to find the values. params have 133 * rather, we are making it convenient to find the values. params have
483 * no meaning here. 134 * no meaning here.
484 */ 135 */
490 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp); 141 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
491 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul)); 142 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
492 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); 143 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
493 144
494 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 145 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
495 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 146 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->stats.Str);
496 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 147 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
497 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); 148 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->stats.Dex);
498 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 149 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d",
499 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 150 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->stats.Con);
500 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 151 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d",
501 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); 152 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->stats.Int);
502 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 153 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d",
503 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 154 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->stats.Wis);
504 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 155 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d",
505 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 156 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->stats.Pow);
506 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d", 157 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
507 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha); 158 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->stats.Cha);
508 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile"); 159 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
509 160
510 /* Can't think of anything else to print right now */ 161 /* Can't think of anything else to print right now */
511 return 0; 162 return 0;
512} 163}
513 164
514int 165int
515command_fix_me (object *op, char *params) 166command_fix_me (object *op, char *params)
516{ 167{
517 sum_weight (op); 168 op->update_weight ();
518 op->update_stats (); 169 op->update_stats ();
519 return 1; 170 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
520}
521 171
522int
523command_logs (object *op, char *params)
524{
525 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
526
527 return 1;
528}
529
530int
531command_applymode (object *op, char *params)
532{
533 unapplymode unapply = op->contr->unapply;
534 static const char *const types[] = { "nochoice", "never", "always" };
535
536 if (!params)
537 {
538 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
539 return 1;
540 }
541
542 if (!strcmp (params, "nochoice"))
543 op->contr->unapply = unapply_nochoice;
544 else if (!strcmp (params, "never"))
545 op->contr->unapply = unapply_never;
546 else if (!strcmp (params, "always"))
547 op->contr->unapply = unapply_always;
548 else
549 {
550 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
551 return 0;
552 }
553
554 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
555 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
556 return 1; 172 return 1;
557} 173}
558 174
559int 175int
560command_bowmode (object *op, char *params) 176command_bowmode (object *op, char *params)
598 new_draw_info_format (NDI_UNIQUE, 0, op, buf); 214 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
599 return 0; 215 return 0;
600 } 216 }
601 217
602 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 218 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
603 return 1;
604}
605
606int
607command_petmode (object *op, char *params)
608{
609 petmode_t oldtype = op->contr->petmode;
610 static const char *const types[] = { "normal", "sad", "defend", "arena" };
611
612 if (!params)
613 {
614 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
615 return 1;
616 }
617
618 if (!strcmp (params, "normal"))
619 op->contr->petmode = pet_normal;
620 else if (!strcmp (params, "sad"))
621 op->contr->petmode = pet_sad;
622 else if (!strcmp (params, "defend"))
623 op->contr->petmode = pet_defend;
624 else if (!strcmp (params, "arena"))
625 op->contr->petmode = pet_arena;
626 else
627 {
628 new_draw_info_format (NDI_UNIQUE, 0, op,
629 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
630 return 0;
631 }
632 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
633 return 1; 219 return 1;
634} 220}
635 221
636int 222int
637command_showpets (object *op, char *params) 223command_showpets (object *op, char *params)
678 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 264 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
679 return 0; 265 return 0;
680} 266}
681 267
682int 268int
683command_usekeys (object *op, char *params)
684{
685 usekeytype oldtype = op->contr->usekeys;
686 static const char *const types[] = { "inventory", "keyrings", "containers" };
687
688 if (!params)
689 {
690 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
691 return 1;
692 }
693
694 if (!strcmp (params, "inventory"))
695 op->contr->usekeys = key_inventory;
696 else if (!strcmp (params, "keyrings"))
697 op->contr->usekeys = keyrings;
698 else if (!strcmp (params, "containers"))
699 op->contr->usekeys = containers;
700 else
701 {
702 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
703 return 0;
704 }
705 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
706 return 1;
707}
708
709int
710command_resistances (object *op, char *params) 269command_resistances (object *op, char *params)
711{ 270{
712 int i; 271 int i;
713 272
714 if (!op) 273 if (!op)
728 int attack; 287 int attack;
729 object *tmp; 288 object *tmp;
730 289
731 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 290 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
732 { 291 {
733 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 292 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
734 { 293 {
735 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 294 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
736 for (attack = 0; attack < NROFATTACKS; attack++) 295 for (attack = 0; attack < NROFATTACKS; attack++)
737 { 296 {
738 if (atnr_is_dragon_enabled (attack)) 297 if (atnr_is_dragon_enabled (attack))
750 309
751/* 310/*
752 * Actual commands. 311 * Actual commands.
753 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) 312 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
754 */ 313 */
755
756
757static void
758help_topics (object *op, int what)
759{
760 DIR *dirp;
761 struct dirent *de;
762 char filename[MAX_BUF], line[80];
763 int namelen, linelen = 0;
764
765 switch (what)
766 {
767 case 1:
768 sprintf (filename, "%s/wizhelp", settings.datadir);
769 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
770 break;
771 case 3:
772 sprintf (filename, "%s/mischelp", settings.datadir);
773 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
774 break;
775 default:
776 sprintf (filename, "%s/help", settings.datadir);
777 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
778 break;
779 }
780
781 if (!(dirp = opendir (filename)))
782 return;
783
784 line[0] = '\0';
785 while ((de = readdir (dirp)))
786 {
787 namelen = strlen (de->d_name);
788 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
789 continue;
790 linelen += namelen + 1;
791 if (linelen > 42)
792 {
793 new_draw_info (NDI_UNIQUE, 0, op, line);
794 sprintf (line, " %s", de->d_name);
795 linelen = namelen + 1;
796 continue;
797 }
798 strcat (line, " ");
799 strcat (line, de->d_name);
800 }
801 new_draw_info (NDI_UNIQUE, 0, op, line);
802 closedir (dirp);
803}
804
805static void
806show_commands (object *op, int what)
807{
808 char line[80];
809 int i, size, namelen, linelen = 0;
810 CommArray_s *ap;
811 extern CommArray_s Commands[], WizCommands[];
812 extern const int CommandsSize, WizCommandsSize;
813
814 switch (what)
815 {
816 case 1:
817 ap = WizCommands;
818 size = WizCommandsSize;
819 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
820 break;
821 case 2:
822 ap = CommunicationCommands;
823 size = CommunicationCommandSize;
824 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
825 break;
826 default:
827 ap = Commands;
828 size = CommandsSize;
829 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
830 break;
831 }
832
833 line[0] = '\0';
834 for (i = 0; i < size; i++)
835 {
836 namelen = strlen (ap[i].name);
837 linelen += namelen + 1;
838 if (linelen > 42)
839 {
840 new_draw_info (NDI_UNIQUE, 0, op, line);
841 sprintf (line, " %s", ap[i].name);
842 linelen = namelen + 1;
843 continue;
844 }
845 strcat (line, " ");
846 strcat (line, ap[i].name);
847 }
848 new_draw_info (NDI_UNIQUE, 0, op, line);
849}
850
851
852int
853command_help (object *op, char *params)
854{
855 struct stat st;
856 FILE *fp;
857 char filename[MAX_BUF], line[MAX_BUF];
858 int len;
859
860 if (op != NULL)
861 clear_win_info (op);
862
863/*
864 * Main help page?
865 */
866 if (!params)
867 {
868 sprintf (filename, "%s/def_help", settings.datadir);
869 if ((fp = fopen (filename, "r")) == NULL)
870 {
871 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
872 return 0;
873 }
874 while (fgets (line, MAX_BUF, fp))
875 {
876 line[MAX_BUF - 1] = '\0';
877 len = strlen (line) - 1;
878 if (line[len] == '\n')
879 line[len] = '\0';
880 new_draw_info (NDI_UNIQUE, 0, op, line);
881 }
882 fclose (fp);
883 return 0;
884 }
885
886 /*
887 * Topics list
888 */
889 if (!strcmp (params, "topics"))
890 {
891 help_topics (op, 3);
892 help_topics (op, 0);
893 if (QUERY_FLAG (op, FLAG_WIZ))
894 help_topics (op, 1);
895 return 0;
896 }
897
898 /*
899 * Commands list
900 */
901 if (!strcmp (params, "commands"))
902 {
903 show_commands (op, 0);
904 show_commands (op, 2); /* show comm commands */
905 if (QUERY_FLAG (op, FLAG_WIZ))
906 show_commands (op, 1);
907 return 0;
908 }
909
910 /*
911 * User wants info about command
912 */
913 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
914 {
915 sprintf (line, "Illegal characters in '%s'", params);
916 new_draw_info (NDI_UNIQUE, 0, op, line);
917 return 0;
918 }
919
920 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
921 if (stat (filename, &st) || !S_ISREG (st.st_mode))
922 {
923 if (op)
924 {
925 sprintf (filename, "%s/help/%s", settings.datadir, params);
926 if (stat (filename, &st) || !S_ISREG (st.st_mode))
927 {
928 if (QUERY_FLAG (op, FLAG_WIZ))
929 {
930 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
931 if (stat (filename, &st) || !S_ISREG (st.st_mode))
932 goto nohelp;
933 }
934 else
935 goto nohelp;
936 }
937 }
938 }
939
940 /*
941 * Found that. Just cat it to screen.
942 */
943 if ((fp = fopen (filename, "r")) == NULL)
944 {
945 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
946 return 0;
947 }
948 sprintf (line, "Help about '%s'", params);
949 new_draw_info (NDI_UNIQUE, 0, op, line);
950 while (fgets (line, MAX_BUF, fp))
951 {
952 line[MAX_BUF - 1] = '\0';
953 len = strlen (line) - 1;
954 if (line[len] == '\n')
955 line[len] = '\0';
956 new_draw_info (NDI_UNIQUE, 0, op, line);
957 }
958 fclose (fp);
959 return 0;
960
961 /*
962 * No_help -escape
963 */
964nohelp:
965 sprintf (line, "No help available on '%s'", params);
966 new_draw_info (NDI_UNIQUE, 0, op, line);
967 return 0;
968}
969
970 314
971int 315int
972onoff_value (const char *line) 316onoff_value (const char *line)
973{ 317{
974 int i; 318 int i;
997 return 0; 341 return 0;
998 } 342 }
999} 343}
1000 344
1001int 345int
1002command_sound (object *op, char *params)
1003{
1004 if (op->contr->ns->sound)
1005 {
1006 op->contr->ns->sound = 0;
1007 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1008 }
1009 else
1010 {
1011 op->contr->ns->sound = 1;
1012 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1013 }
1014
1015 return 1;
1016}
1017
1018int
1019command_title (object *op, char *params) 346command_title (object *op, char *params)
1020{ 347{
1021 char buf[MAX_BUF]; 348 char buf[MAX_BUF];
1022 349
1023 if (settings.set_title == FALSE) 350 if (settings.set_title == FALSE)
1060 strcpy (op->contr->own_title, params); 387 strcpy (op->contr->own_title, params);
1061 return 1; 388 return 1;
1062} 389}
1063 390
1064int 391int
1065command_peaceful (object *op, char *params)
1066{
1067 new_draw_info (NDI_UNIQUE, 0, op,
1068 "You cannot change your peaceful setting with this command."
1069 " Please speak to the priest in the temple of Gorokh"
1070 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1071
1072/*
1073 if((op->contr->peaceful=!op->contr->peaceful))
1074 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1075 else
1076 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1077*/
1078 return 1;
1079}
1080
1081int
1082command_wimpy (object *op, char *params)
1083{
1084 int i;
1085 char buf[MAX_BUF];
1086
1087 if (params == NULL || !sscanf (params, "%d", &i))
1088 {
1089 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1090 new_draw_info (NDI_UNIQUE, 0, op, buf);
1091 return 1;
1092 }
1093 sprintf (buf, "Your new wimpy level is %d.", i);
1094 new_draw_info (NDI_UNIQUE, 0, op, buf);
1095 op->run_away = i;
1096 return 1;
1097}
1098
1099int
1100command_brace (object *op, char *params)
1101{
1102 if (!params)
1103 op->contr->braced = !op->contr->braced;
1104 else
1105 op->contr->braced = onoff_value (params);
1106
1107 if (op->contr->braced)
1108 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1109 else
1110 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1111
1112 op->update_stats ();
1113 return 0;
1114}
1115
1116int
1117command_kill_pets (object *op, char *params) 392command_kill_pets (object *op, char *params)
1118{ 393{
1119 objectlink *obl, *next; 394 objectlink *obl, *next;
1120 int counter = 0, removecount = 0; 395 int counter = 0, removecount = 0;
1121 396
1122 if (params == NULL) 397 if (!params)
1123 { 398 {
1124 terminate_all_pets (op); 399 terminate_all_pets (op);
1125 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 400 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1126 } 401 }
1127 else 402 else
1128 { 403 {
1129 int target = atoi (params); 404 int target = atoi (params);
1130 405
1131 for (obl = first_friendly_object; obl != NULL; obl = next) 406 for (obl = first_friendly_object; obl; obl = next)
1132 { 407 {
1133 object *ob = obl->ob; 408 object *ob = obl->ob;
1134 409
1135 next = obl->next; 410 next = obl->next;
411
1136 if (ob->owner == op) 412 if (ob->owner == op)
1137 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 413 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1138 { 414 {
1139 ob->destroy (); 415 ob->destroy ();
1140 removecount++; 416 removecount++;
1141 } 417 }
1142 } 418 }
419
1143 if (removecount != 0) 420 if (removecount != 0)
1144 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 421 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1145 else 422 else
1146 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 423 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1147 } 424 }
425
1148 return 0; 426 return 0;
1149} 427}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines