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.44 by root, Thu Feb 15 04:04:22 2007 UTC vs.
Revision 1.78 by root, Fri Nov 6 13:03:34 2009 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 it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * 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 Affero GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <loader.h> 26#include <loader.h>
27#include <sproto.h> 27#include <sproto.h>
28 28
29/* Handles misc. input request - things like hash table, malloc, maps, 29/* 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
67int
68command_motd (object *op, char *params)
69{
70 display_motd (op);
71 return 1;
72}
73
74int
75command_bug (object *op, char *params)
76{
77 char buf[MAX_BUF];
78
79 if (params == NULL)
80 {
81 new_draw_info (NDI_UNIQUE, 0, op, "what bugs?");
82 return 1;
83 }
84 assign (buf, op->name);
85 strcat (buf, " bug-reports: ");
86 strncat (buf, ++params, MAX_BUF - strlen (buf));
87 buf[MAX_BUF - 1] = '\0';
88 bug_report (buf);
89 LOG (llevError, "%s\n", buf);
90 new_draw_info (NDI_ALL | NDI_UNIQUE, 1, NULL, buf);
91 new_draw_info (NDI_UNIQUE, 0, op, "OK, thanks!");
92 return 1;
93}
94
95/*
96 * Pretty much identical to current map_info, but on a bigger scale
97 * This function returns the name of the players current region, and
98 * a description of it. It is there merely for flavour text.
99 */
100void
101current_region_info (object *op)
102{
103 if (region *reg = op->region ())
104 new_draw_info_format (NDI_UNIQUE, 0, op, "You are %s.\n%s", &reg->longname, &reg->msg);
105}
106
107void
108current_map_info (object *op)
109{
110 maptile *m = op->map;
111
112 if (!m)
113 return;
114
115 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) %s", &m->name, &m->path, &op->region ()->longname);
116
117 if (QUERY_FLAG (op, FLAG_WIZ))
118 new_draw_info_format (NDI_UNIQUE, 0, op,
119 "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld",
120 m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout);
121
122 if (m->msg)
123 new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg);
124}
125
126#ifdef DEBUG_MALLOC_LEVEL
127int
128command_malloc_verify (object *op, char *parms)
129{
130 extern int malloc_verify (void);
131
132 if (!malloc_verify ())
133 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
134 else
135 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
136 return 1;
137}
138#endif
139
140int
141command_whereabouts (object *op, char *params)
142{
143 //TODO: should obviously not waste space in struct region for this.
144 /*
145 * reset the counter on the region, then use it to store the number of
146 * players there.
147 * I don't know how thread-safe this would be, I suspect not very....
148 */
149 for_all_regions (rgn)
150 rgn->counter = 0;
151
152 for_all_players (pl)
153 if (pl->ob->map)
154 ++pl->ob->region ()->counter;
155
156 /* we only want to print out by places with a 'longname' field... */
157 for_all_regions (rgn)
158 {
159 if (!rgn->longname && rgn->counter > 0)
160 {
161 if (rgn->parent)
162 {
163 rgn->parent->counter += rgn->counter;
164 rgn->counter = 0;
165 }
166 else /*uh oh, we shouldn't be here. */
167 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name);
168 }
169 }
170
171 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
172
173 for_all_regions (rgn)
174 if (rgn->counter)
175 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname);
176
177 return 1;
178}
179 30
180typedef struct 31typedef struct
181{ 32{
182 char namebuf[MAX_BUF]; 33 char namebuf[MAX_BUF];
183 int login_order; 34 int login_order;
184} chars_names; 35} chars_names;
185 36
186int 37int
187command_afk (object *op, char *params)
188{
189 if ((op->contr->ns->afk = !op->contr->ns->afk))
190 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer AFK");
191 else
192 new_draw_info (NDI_UNIQUE, 0, op, "You are now AFK");
193
194 return 1;
195}
196
197int
198command_mapinfo (object *op, char *params)
199{
200 current_map_info (op);
201 return 1;
202}
203
204int
205command_whereami (object *op, char *params)
206{
207 current_region_info (op);
208 return 1;
209}
210
211int
212command_time (object *op, char *params) 38command_time (object *op, char *params)
213{ 39{
214 print_tod (op); 40 print_tod (op);
215 return 1;
216}
217
218int
219command_weather (object *op, char *params)
220{
221#if 0
222 int wx, wy, temp, sky;
223 char buf[MAX_BUF];
224
225 if (settings.dynamiclevel < 1)
226 return 1;
227
228 if (op->map == NULL)
229 return 1;
230
231 if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0)
232 return 1;
233
234 if (QUERY_FLAG (op, FLAG_WIZ))
235 {
236 /* dump the weather, Dm style! Yo! */
237 new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map));
238 new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp);
239 new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid);
240 new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed);
241 new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure);
242 new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev);
243 new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water);
244 }
245
246 temp = real_world_temperature (op->x, op->y, op->map);
247 new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp);
248
249 /* humid */
250 if (weathermap[wx][wy].humid < 20)
251 new_draw_info (NDI_UNIQUE, 0, op, "It is very dry.");
252 else if (weathermap[wx][wy].humid < 40)
253 new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today.");
254 else if (weathermap[wx][wy].humid < 60)
255 new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy.");
256 else if (weathermap[wx][wy].humid < 80)
257 new_draw_info (NDI_UNIQUE, 0, op, "It is muggy.");
258 else
259 new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy.");
260
261 /* wind */
262 switch (weathermap[wx][wy].winddir)
263 {
264 case 1:
265 sprintf (buf, "north");
266 break;
267 case 2:
268 sprintf (buf, "northeast");
269 break;
270 case 3:
271 sprintf (buf, "east");
272 break;
273 case 4:
274 sprintf (buf, "southeast");
275 break;
276 case 5:
277 sprintf (buf, "south");
278 break;
279 case 6:
280 sprintf (buf, "southwest");
281 break;
282 case 7:
283 sprintf (buf, "west");
284 break;
285 case 8:
286 sprintf (buf, "northwest");
287 break;
288 }
289 if (weathermap[wx][wy].windspeed < 5)
290 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf);
291 else if (weathermap[wx][wy].windspeed < 10)
292 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf);
293 else if (weathermap[wx][wy].windspeed < 15)
294 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf);
295 else if (weathermap[wx][wy].windspeed < 25)
296 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf);
297 else if (weathermap[wx][wy].windspeed < 35)
298 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf);
299 else
300 new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf);
301
302 sky = weathermap[wx][wy].sky;
303 if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG)
304 sky += 10; /*let it snow */
305 switch (sky)
306 {
307 case SKY_CLEAR:
308 new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky.");
309 break;
310 case SKY_LIGHTCLOUD:
311 new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky.");
312 break;
313 case SKY_OVERCAST:
314 new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary.");
315 break;
316 case SKY_LIGHT_RAIN:
317 new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly.");
318 break;
319 case SKY_RAIN:
320 new_draw_info (NDI_UNIQUE, 0, op, "It is raining.");
321 break;
322 case SKY_HEAVY_RAIN:
323 new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily.");
324 break;
325 case SKY_HURRICANE:
326 new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!");
327 break;
328 case SKY_FOG:
329 new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable.");
330 break;
331 case SKY_HAIL:
332 new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!");
333 break;
334 case SKY_LIGHT_SNOW:
335 new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky.");
336 break;
337 case SKY_SNOW:
338 new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out.");
339 break;
340 case SKY_HEAVY_SNOW:
341 new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now.");
342 break;
343 case SKY_BLIZZARD:
344 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
345 break;
346 }
347#endif
348 return 1;
349}
350
351int
352command_hiscore (object *op, char *params)
353{
354 display_high_score (op, op == NULL ? 9999 : 50, params);
355 return 1; 41 return 1;
356} 42}
357 43
358int 44int
359command_debug (object *op, char *params) 45command_debug (object *op, char *params)
365 { 51 {
366 sprintf (buf, "Global debug level is %d.", settings.debug); 52 sprintf (buf, "Global debug level is %d.", settings.debug);
367 new_draw_info (NDI_UNIQUE, 0, op, buf); 53 new_draw_info (NDI_UNIQUE, 0, op, buf);
368 return 1; 54 return 1;
369 } 55 }
370 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) 56
371 { 57 settings.debug = i;
372 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); 58
373 return 1;
374 }
375 settings.debug = (enum LogLevel) FABS (i);
376 sprintf (buf, "Set debug level to %d.", i); 59 sprintf (buf, "Set debug level to %d.", i);
377 new_draw_info (NDI_UNIQUE, 0, op, buf); 60 new_draw_info (NDI_UNIQUE, 0, op, buf);
378 return 1; 61 return 1;
379} 62}
380
381 63
382/* 64/*
383 * Those dumps should be just one dump with good parser 65 * Those dumps should be just one dump with good parser
384 */ 66 */
385 67
396 } 78 }
397 return 0; 79 return 0;
398} 80}
399 81
400int 82int
401command_dumpfriendlyobjects (object *op, char *params)
402{
403 dump_friendly_objects ();
404 return 0;
405}
406
407int
408command_printlos (object *op, char *params)
409{
410 if (op)
411 print_los (op);
412 return 0;
413}
414
415
416int
417command_version (object *op, char *params) 83command_version (object *op, char *params)
418{ 84{
419 version (op); 85 version (op);
420 return 0; 86 return 0;
421}
422
423#ifndef BUG_LOG
424# define BUG_LOG "bug_log"
425#endif
426void
427bug_report (const char *reportstring)
428{
429 FILE *fp;
430
431 if ((fp = fopen (BUG_LOG, "a")) != NULL)
432 {
433 fprintf (fp, "%s\n", reportstring);
434 fclose (fp);
435 }
436 else
437 {
438 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
439 }
440}
441
442int
443command_output_sync (object *op, char *params)
444{
445 int val;
446
447 if (!params)
448 {
449 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
450 return 1;
451 }
452 val = atoi (params);
453 if (val > 0)
454 {
455 op->contr->outputs_sync = val;
456 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
457 }
458 else
459 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
460
461 return 1;
462}
463
464int
465command_output_count (object *op, char *params)
466{
467 int val;
468
469 if (!params)
470 {
471 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
472 return 1;
473 }
474 val = atoi (params);
475 if (val > 0)
476 {
477 op->contr->outputs_count = val;
478 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
479 }
480 else
481 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
482
483 return 1;
484}
485
486int
487command_listen (object *op, char *params)
488{
489 int i;
490
491 if (params == NULL || !sscanf (params, "%d", &i))
492 {
493 new_draw_info_format (NDI_UNIQUE, 0, op, "Set listen to what (presently %d)?", op->contr->listening);
494 return 1;
495 }
496 op->contr->listening = (char) i;
497 new_draw_info_format (NDI_UNIQUE, 0, op, "Your verbose level is now %d.", i);
498 return 1;
499} 87}
500 88
501/* Prints out some useful information for the character. Everything we print 89/* Prints out some useful information for the character. Everything we print
502 * out can be determined by the docs, so we aren't revealing anything extra - 90 * out can be determined by the docs, so we aren't revealing anything extra -
503 * rather, we are making it convenient to find the values. params have 91 * rather, we are making it convenient to find the values. params have
506int 94int
507command_statistics (object *pl, char *params) 95command_statistics (object *pl, char *params)
508{ 96{
509 if (!pl->contr) 97 if (!pl->contr)
510 return 1; 98 return 1;
511 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
512 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
513 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
514 99
515 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 100 dynbuf_text &msg = msg_dynbuf; msg.clear ();
516 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 101
517 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 102 msg << " Experience: " << pl->stats.exp << '\n'
518 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); 103 << " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n'
519 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 104 << "\n Stat Nat/Real/Max\n";
520 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 105
521 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 106 for (int i = 0; i < NUM_STATS; ++i)
522 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); 107 msg.printf (" %s %2d/ %3d/%3d\n", short_stat_name [i], pl->contr->orig_stats.stat (i), pl->stats.stat (i), 20 + pl->arch->stats.stat (i));
523 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 108
524 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 109 msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.';
525 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 110
526 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 111 pl->contr->infobox (MSG_CHANNEL ("statistics"), msg);
527 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
528 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha);
529 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
530 112
531 /* Can't think of anything else to print right now */ 113 /* Can't think of anything else to print right now */
532 return 0; 114 return 0;
533} 115}
534 116
535int 117int
536command_fix_me (object *op, char *params) 118command_fix_me (object *op, char *params)
537{ 119{
538 sum_weight (op); 120 op->update_weight ();
539 op->update_stats (); 121 op->update_stats ();
540 return 1; 122 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
541}
542 123
543int
544command_logs (object *op, char *params)
545{
546 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
547
548 return 1;
549}
550
551int
552command_applymode (object *op, char *params)
553{
554 unapplymode unapply = op->contr->unapply;
555 static const char *const types[] = { "nochoice", "never", "always" };
556
557 if (!params)
558 {
559 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode is set to %s", types[op->contr->unapply]);
560 return 1;
561 }
562
563 if (!strcmp (params, "nochoice"))
564 op->contr->unapply = unapply_nochoice;
565 else if (!strcmp (params, "never"))
566 op->contr->unapply = unapply_never;
567 else if (!strcmp (params, "always"))
568 op->contr->unapply = unapply_always;
569 else
570 {
571 new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params);
572 return 0;
573 }
574
575 new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s",
576 (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]);
577 return 1; 124 return 1;
578} 125}
579 126
580int 127int
581command_bowmode (object *op, char *params) 128command_bowmode (object *op, char *params)
582{ 129{
583 bowtype_t oldtype = op->contr->bowtype; 130 bowtype_t oldtype = op->contr->bowtype;
584 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth", 131 static const char *const types[] = {
132 "normal", "threewide", "spreadshot", "firenorth",
585 "firene", "fireeast", "firese", "firesouth", 133 "firene", "fireeast", "firese", "firesouth",
586 "firesw", "firewest", "firenw", "bestarrow" 134 "firesw", "firewest", "firenw", "bestarrow"
587 }; 135 };
588 char buf[MAX_BUF]; 136 char buf[MAX_BUF];
589 int i, found; 137 int i, found;
605 } 153 }
606 154
607 if (!found) 155 if (!found)
608 { 156 {
609 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 157 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
158
610 for (i = 0; i <= bow_bestarrow; i++) 159 for (i = 0; i <= bow_bestarrow; i++)
611 { 160 {
612 strcat (buf, " "); 161 strcat (buf, " ");
613 strcat (buf, types[i]); 162 strcat (buf, types[i]);
614 if (i < bow_nw) 163 if (i < bow_nw)
623 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 172 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
624 return 1; 173 return 1;
625} 174}
626 175
627int 176int
628command_petmode (object *op, char *params)
629{
630 petmode_t oldtype = op->contr->petmode;
631 static const char *const types[] = { "normal", "sad", "defend", "arena" };
632
633 if (!params)
634 {
635 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode is set to %s", types[op->contr->petmode]);
636 return 1;
637 }
638
639 if (!strcmp (params, "normal"))
640 op->contr->petmode = pet_normal;
641 else if (!strcmp (params, "sad"))
642 op->contr->petmode = pet_sad;
643 else if (!strcmp (params, "defend"))
644 op->contr->petmode = pet_defend;
645 else if (!strcmp (params, "arena"))
646 op->contr->petmode = pet_arena;
647 else
648 {
649 new_draw_info_format (NDI_UNIQUE, 0, op,
650 "petmode: Unknown options %s, valid options are normal," "sad (seek and destroy), defend, arena", params);
651 return 0;
652 }
653 new_draw_info_format (NDI_UNIQUE, 0, op, "petmode %s set to %s", (oldtype == op->contr->petmode ? "" : "now"), types[op->contr->petmode]);
654 return 1;
655}
656
657int
658command_showpets (object *op, char *params) 177command_showpets (object *op, char *params)
659{ 178{
660 objectlink *obl, *next;
661 int counter = 0, target = 0; 179 int counter = 0, target = 0;
662 int have_shown_pet = 0; 180 int have_shown_pet = 0;
663 181
182 dynbuf_text &msg = msg_dynbuf; msg.clear ();
183
664 if (params != NULL) 184 if (params)
665 target = atoi (params); 185 target = atoi (params);
186
666 for (obl = first_friendly_object; obl != NULL; obl = next) 187 for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
667 { 188 {
668 object *ob = obl->ob; 189 object *ob = obl->ob;
669 190
670 next = obl->next;
671 if (ob->owner == op) 191 if (ob->owner == op)
672 { 192 {
673 if (target == 0) 193 if (target == 0)
674 { 194 {
675 if (counter == 0) 195 if (counter == 0)
676 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 196 msg << "T<Pets>\n\n";
197
677 new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level); 198 msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
678 } 199 }
679 else if (!have_shown_pet && ++counter == target) 200 else if (!have_shown_pet && ++counter == target)
680 { 201 {
681 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name); 202 msg.printf ("T<%s>\n\n"
682 new_draw_info_format (NDI_UNIQUE, 0, op, "%d/%d HP, %d/%d SP", ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp); 203 " level %d\n"
683 /* this is not a nice way to do this, it should be made to be more like the statistics command */ 204 " %d/%d HP, %d/%d SP\n"
684 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); 205 " Str %2d\n"
685 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); 206 " Dex %2d\n"
686 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con); 207 " Con %2d\n"
687 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int); 208 " Int %2d\n"
688 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis); 209 " Wis %2d\n"
689 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha); 210 " Cha %2d\n"
690 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow); 211 " Pow %2d\n"
691 new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac); 212 " wc %d damage %d ac %d\n",
213 &ob->name,
214 &ob->name,
215 ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp,
216 ob->stats.Str,
217 ob->stats.Dex,
218 ob->stats.Con,
219 ob->stats.Int,
220 ob->stats.Wis,
221 ob->stats.Cha,
222 ob->stats.Pow,
223 ob->stats.wc, ob->stats.dam, ob->stats.ac);
224
692 have_shown_pet = 1; 225 have_shown_pet = 1;
693 } 226 }
694 } 227 }
695 } 228 }
229
696 if (counter == 0) 230 if (counter == 0)
697 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets."); 231 msg << "you have no pets.";
698 else if (target != 0 && have_shown_pet == 0) 232 else if (target != 0 && have_shown_pet == 0)
699 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 233 msg << "no such pet.";
700 return 0;
701}
702 234
703int 235 op->contr->infobox (MSG_CHANNEL ("pets"), msg);
704command_usekeys (object *op, char *params)
705{
706 usekeytype oldtype = op->contr->usekeys;
707 static const char *const types[] = { "inventory", "keyrings", "containers" };
708 236
709 if (!params)
710 {
711 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys is set to %s", types[op->contr->usekeys]);
712 return 1;
713 }
714
715 if (!strcmp (params, "inventory"))
716 op->contr->usekeys = key_inventory;
717 else if (!strcmp (params, "keyrings"))
718 op->contr->usekeys = keyrings;
719 else if (!strcmp (params, "containers"))
720 op->contr->usekeys = containers;
721 else
722 {
723 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys: Unknown options %s, valid options are inventory, keyrings, containers", params);
724 return 0;
725 }
726 new_draw_info_format (NDI_UNIQUE, 0, op, "usekeys %s set to %s", (oldtype == op->contr->usekeys ? "" : "now"), types[op->contr->usekeys]);
727 return 1; 237 return 0;
728} 238}
729 239
730int 240int
731command_resistances (object *op, char *params) 241command_resistances (object *op, char *params)
732{ 242{
733 int i; 243 dynbuf_text &msg = msg_dynbuf; msg.clear ();
734 244
735 if (!op) 245 msg << "Resistances:\n\n";
736 return 0;
737 246
738 for (i = 0; i < NROFATTACKS; i++) 247 for (int i = 0; i < NROFATTACKS; i++)
739 {
740 if (i == ATNR_INTERNAL) 248 if (i != ATNR_INTERNAL)
741 continue; 249 msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]);
742
743 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
744 }
745 250
746 /* If dragon player, let's display natural resistances */ 251 /* If dragon player, let's display natural resistances */
747 if (is_dragon_pl (op)) 252 if (is_dragon_pl (op))
748 {
749 int attack;
750 object *tmp;
751
752 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 253 for (object *tmp = op->inv; tmp; tmp = tmp->below)
753 {
754 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 254 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
755 { 255 {
756 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 256 msg << "\nOf those, these are natural skin resistances:\n\n";
257
757 for (attack = 0; attack < NROFATTACKS; attack++) 258 for (int attack = 0; attack < NROFATTACKS; attack++)
758 {
759 if (atnr_is_dragon_enabled (attack)) 259 if (atnr_is_dragon_enabled (attack))
760 { 260 msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]);
761 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]); 261
762 }
763 }
764 break; 262 break;
765 } 263 }
766 } 264
767 } 265 op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
768 266
769 return 0; 267 return 0;
770} 268}
771 269
772/* 270/*
773 * Actual commands. 271 * Actual commands.
774 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) 272 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
775 */ 273 */
776
777
778static void 274static int
779help_topics (object *op, int what)
780{
781 DIR *dirp;
782 struct dirent *de;
783 char filename[MAX_BUF], line[80];
784 int namelen, linelen = 0;
785
786 switch (what)
787 {
788 case 1:
789 sprintf (filename, "%s/wizhelp", settings.datadir);
790 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
791 break;
792 case 3:
793 sprintf (filename, "%s/mischelp", settings.datadir);
794 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
795 break;
796 default:
797 sprintf (filename, "%s/help", settings.datadir);
798 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
799 break;
800 }
801
802 if (!(dirp = opendir (filename)))
803 return;
804
805 line[0] = '\0';
806 while (de = readdir (dirp))
807 {
808 namelen = strlen (de->d_name);
809 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
810 continue;
811 linelen += namelen + 1;
812 if (linelen > 42)
813 {
814 new_draw_info (NDI_UNIQUE, 0, op, line);
815 sprintf (line, " %s", de->d_name);
816 linelen = namelen + 1;
817 continue;
818 }
819 strcat (line, " ");
820 strcat (line, de->d_name);
821 }
822 new_draw_info (NDI_UNIQUE, 0, op, line);
823 closedir (dirp);
824}
825
826static void
827show_commands (object *op, int what)
828{
829 char line[80];
830 int i, size, namelen, linelen = 0;
831 CommArray_s *ap;
832 extern CommArray_s Commands[], WizCommands[];
833 extern const int CommandsSize, WizCommandsSize;
834
835 switch (what)
836 {
837 case 1:
838 ap = WizCommands;
839 size = WizCommandsSize;
840 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
841 break;
842 case 2:
843 ap = CommunicationCommands;
844 size = CommunicationCommandSize;
845 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
846 break;
847 default:
848 ap = Commands;
849 size = CommandsSize;
850 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
851 break;
852 }
853
854 line[0] = '\0';
855 for (i = 0; i < size; i++)
856 {
857 namelen = strlen (ap[i].name);
858 linelen += namelen + 1;
859 if (linelen > 42)
860 {
861 new_draw_info (NDI_UNIQUE, 0, op, line);
862 sprintf (line, " %s", ap[i].name);
863 linelen = namelen + 1;
864 continue;
865 }
866 strcat (line, " ");
867 strcat (line, ap[i].name);
868 }
869 new_draw_info (NDI_UNIQUE, 0, op, line);
870}
871
872
873int
874command_help (object *op, char *params)
875{
876 struct stat st;
877 FILE *fp;
878 char filename[MAX_BUF], line[MAX_BUF];
879 int len;
880
881 if (op != NULL)
882 clear_win_info (op);
883
884/*
885 * Main help page?
886 */
887 if (!params)
888 {
889 sprintf (filename, "%s/def_help", settings.datadir);
890 if ((fp = fopen (filename, "r")) == NULL)
891 {
892 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
893 return 0;
894 }
895 while (fgets (line, MAX_BUF, fp))
896 {
897 line[MAX_BUF - 1] = '\0';
898 len = strlen (line) - 1;
899 if (line[len] == '\n')
900 line[len] = '\0';
901 new_draw_info (NDI_UNIQUE, 0, op, line);
902 }
903 fclose (fp);
904 return 0;
905 }
906
907 /*
908 * Topics list
909 */
910 if (!strcmp (params, "topics"))
911 {
912 help_topics (op, 3);
913 help_topics (op, 0);
914 if (QUERY_FLAG (op, FLAG_WIZ))
915 help_topics (op, 1);
916 return 0;
917 }
918
919 /*
920 * Commands list
921 */
922 if (!strcmp (params, "commands"))
923 {
924 show_commands (op, 0);
925 show_commands (op, 2); /* show comm commands */
926 if (QUERY_FLAG (op, FLAG_WIZ))
927 show_commands (op, 1);
928 return 0;
929 }
930
931 /*
932 * User wants info about command
933 */
934 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
935 {
936 sprintf (line, "Illegal characters in '%s'", params);
937 new_draw_info (NDI_UNIQUE, 0, op, line);
938 return 0;
939 }
940
941 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
942 if (stat (filename, &st) || !S_ISREG (st.st_mode))
943 {
944 if (op)
945 {
946 sprintf (filename, "%s/help/%s", settings.datadir, params);
947 if (stat (filename, &st) || !S_ISREG (st.st_mode))
948 {
949 if (QUERY_FLAG (op, FLAG_WIZ))
950 {
951 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
952 if (stat (filename, &st) || !S_ISREG (st.st_mode))
953 goto nohelp;
954 }
955 else
956 goto nohelp;
957 }
958 }
959 }
960
961 /*
962 * Found that. Just cat it to screen.
963 */
964 if ((fp = fopen (filename, "r")) == NULL)
965 {
966 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
967 return 0;
968 }
969 sprintf (line, "Help about '%s'", params);
970 new_draw_info (NDI_UNIQUE, 0, op, line);
971 while (fgets (line, MAX_BUF, fp))
972 {
973 line[MAX_BUF - 1] = '\0';
974 len = strlen (line) - 1;
975 if (line[len] == '\n')
976 line[len] = '\0';
977 new_draw_info (NDI_UNIQUE, 0, op, line);
978 }
979 fclose (fp);
980 return 0;
981
982 /*
983 * No_help -escape
984 */
985nohelp:
986 sprintf (line, "No help available on '%s'", params);
987 new_draw_info (NDI_UNIQUE, 0, op, line);
988 return 0;
989}
990
991
992int
993onoff_value (const char *line) 275onoff_value (const char *line)
994{ 276{
995 int i; 277 int i;
996 278
997 if (sscanf (line, "%d", &i)) 279 if (sscanf (line, "%d", &i))
1018 return 0; 300 return 0;
1019 } 301 }
1020} 302}
1021 303
1022int 304int
1023command_sound (object *op, char *params)
1024{
1025 if (op->contr->ns->sound)
1026 {
1027 op->contr->ns->sound = 0;
1028 new_draw_info (NDI_UNIQUE, 0, op, "Silence is golden...");
1029 }
1030 else
1031 {
1032 op->contr->ns->sound = 1;
1033 new_draw_info (NDI_UNIQUE, 0, op, "The sounds are enabled.");
1034 }
1035
1036 return 1;
1037}
1038
1039int
1040command_title (object *op, char *params) 305command_title (object *op, char *params)
1041{ 306{
1042 char buf[MAX_BUF]; 307 char buf[MAX_BUF];
1043 308
1044 if (settings.set_title == FALSE) 309 if (settings.set_title == FALSE)
1081 strcpy (op->contr->own_title, params); 346 strcpy (op->contr->own_title, params);
1082 return 1; 347 return 1;
1083} 348}
1084 349
1085int 350int
1086command_peaceful (object *op, char *params)
1087{
1088 new_draw_info (NDI_UNIQUE, 0, op,
1089 "You cannot change your peaceful setting with this command."
1090 " Please speak to the priest in the temple of Gorokh"
1091 " if you want to become hostile or in temple of Valriel" " if you want to become peaceful again.");
1092
1093/*
1094 if((op->contr->peaceful=!op->contr->peaceful))
1095 new_draw_info(NDI_UNIQUE, 0,op,"You will not attack other players.");
1096 else
1097 new_draw_info(NDI_UNIQUE, 0,op,"You will attack other players.");
1098*/
1099 return 1;
1100}
1101
1102int
1103command_wimpy (object *op, char *params)
1104{
1105 int i;
1106 char buf[MAX_BUF];
1107
1108 if (params == NULL || !sscanf (params, "%d", &i))
1109 {
1110 sprintf (buf, "Your current wimpy level is %d.", op->run_away);
1111 new_draw_info (NDI_UNIQUE, 0, op, buf);
1112 return 1;
1113 }
1114 sprintf (buf, "Your new wimpy level is %d.", i);
1115 new_draw_info (NDI_UNIQUE, 0, op, buf);
1116 op->run_away = i;
1117 return 1;
1118}
1119
1120int
1121command_brace (object *op, char *params)
1122{
1123 if (!params)
1124 op->contr->braced = !op->contr->braced;
1125 else
1126 op->contr->braced = onoff_value (params);
1127
1128 if (op->contr->braced)
1129 new_draw_info (NDI_UNIQUE, 0, op, "You are braced.");
1130 else
1131 new_draw_info (NDI_UNIQUE, 0, op, "Not braced.");
1132
1133 op->update_stats ();
1134 return 0;
1135}
1136
1137int
1138command_kill_pets (object *op, char *params) 351command_kill_pets (object *op, char *params)
1139{ 352{
1140 objectlink *obl, *next; 353 objectlink *obl, *next;
1141 int counter = 0, removecount = 0; 354 int counter = 0, removecount = 0;
1142 355
1143 if (params == NULL) 356 if (!params)
1144 { 357 {
1145 terminate_all_pets (op); 358 terminate_all_pets (op);
1146 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 359 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1147 } 360 }
1148 else 361 else
1149 { 362 {
1150 int target = atoi (params); 363 int target = atoi (params);
1151 364
1152 for (obl = first_friendly_object; obl != NULL; obl = next) 365 for (obl = first_friendly_object; obl; obl = next)
1153 { 366 {
1154 object *ob = obl->ob; 367 object *ob = obl->ob;
1155 368
1156 next = obl->next; 369 next = obl->next;
370
1157 if (ob->owner == op) 371 if (ob->owner == op)
1158 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 372 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1159 { 373 {
1160 ob->destroy (); 374 ob->destroy ();
1161 removecount++; 375 removecount++;
1162 } 376 }
1163 } 377 }
378
1164 if (removecount != 0) 379 if (removecount != 0)
1165 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 380 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1166 else 381 else
1167 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 382 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1168 } 383 }
384
1169 return 0; 385 return 0;
1170} 386}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines