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.75 by root, Mon Oct 12 14:00:59 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 30
67int 31int
68command_motd (object *op, char *params) 32command_motd (object *op, char *params)
69{ 33{
70 display_motd (op); 34 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; 35 return 1;
157} 36}
158 37
159typedef struct 38typedef struct
160{ 39{
161 char namebuf[MAX_BUF]; 40 char namebuf[MAX_BUF];
162 int login_order; 41 int login_order;
163} chars_names; 42} chars_names;
164 43
165int 44int
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) 45command_time (object *op, char *params)
192{ 46{
193 print_tod (op); 47 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; 48 return 1;
335} 49}
336 50
337int 51int
338command_debug (object *op, char *params) 52command_debug (object *op, char *params)
344 { 58 {
345 sprintf (buf, "Global debug level is %d.", settings.debug); 59 sprintf (buf, "Global debug level is %d.", settings.debug);
346 new_draw_info (NDI_UNIQUE, 0, op, buf); 60 new_draw_info (NDI_UNIQUE, 0, op, buf);
347 return 1; 61 return 1;
348 } 62 }
349 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ)) 63
350 { 64 settings.debug = i;
351 new_draw_info (NDI_UNIQUE, 0, op, "Privileged command."); 65
352 return 1;
353 }
354 settings.debug = (enum LogLevel) FABS (i);
355 sprintf (buf, "Set debug level to %d.", i); 66 sprintf (buf, "Set debug level to %d.", i);
356 new_draw_info (NDI_UNIQUE, 0, op, buf); 67 new_draw_info (NDI_UNIQUE, 0, op, buf);
357 return 1; 68 return 1;
358} 69}
359 70
375 } 86 }
376 return 0; 87 return 0;
377} 88}
378 89
379int 90int
380command_dumpfriendlyobjects (object *op, char *params)
381{
382 dump_friendly_objects ();
383 return 0;
384}
385
386int
387command_printlos (object *op, char *params)
388{
389 if (op)
390 print_los (op);
391 return 0;
392}
393
394
395int
396command_version (object *op, char *params) 91command_version (object *op, char *params)
397{ 92{
398 version (op); 93 version (op);
399 return 0; 94 return 0;
400}
401
402#ifndef BUG_LOG
403# define BUG_LOG "bug_log"
404#endif
405void
406bug_report (const char *reportstring)
407{
408 FILE *fp;
409
410 if ((fp = fopen (BUG_LOG, "a")) != NULL)
411 {
412 fprintf (fp, "%s\n", reportstring);
413 fclose (fp);
414 }
415 else
416 {
417 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
418 }
419}
420
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} 95}
479 96
480/* Prints out some useful information for the character. Everything we print 97/* 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 - 98 * 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 99 * rather, we are making it convenient to find the values. params have
485int 102int
486command_statistics (object *pl, char *params) 103command_statistics (object *pl, char *params)
487{ 104{
488 if (!pl->contr) 105 if (!pl->contr)
489 return 1; 106 return 1;
490 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));
492 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
493 107
494 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 108 dynbuf_text &msg = msg_dynbuf; msg.clear ();
495 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 109
496 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 110 msg << " Experience: " << pl->stats.exp << '\n'
497 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); 111 << " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n'
498 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 112 << "\n Stat Nat/Real/Max\n";
499 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 113
500 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 114 for (int i = 0; i < NUM_STATS; ++i)
501 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); 115 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));
502 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 116
503 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 117 msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.';
504 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 118
505 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 119 pl->contr->infobox (MSG_CHANNEL ("statistics"), msg);
506 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);
508 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
509 120
510 /* Can't think of anything else to print right now */ 121 /* Can't think of anything else to print right now */
511 return 0; 122 return 0;
512} 123}
513 124
514int 125int
515command_fix_me (object *op, char *params) 126command_fix_me (object *op, char *params)
516{ 127{
517 sum_weight (op); 128 op->update_weight ();
518 op->update_stats (); 129 op->update_stats ();
519 return 1; 130 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
520}
521 131
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; 132 return 1;
557} 133}
558 134
559int 135int
560command_bowmode (object *op, char *params) 136command_bowmode (object *op, char *params)
561{ 137{
562 bowtype_t oldtype = op->contr->bowtype; 138 bowtype_t oldtype = op->contr->bowtype;
563 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth", 139 static const char *const types[] = {
140 "normal", "threewide", "spreadshot", "firenorth",
564 "firene", "fireeast", "firese", "firesouth", 141 "firene", "fireeast", "firese", "firesouth",
565 "firesw", "firewest", "firenw", "bestarrow" 142 "firesw", "firewest", "firenw", "bestarrow"
566 }; 143 };
567 char buf[MAX_BUF]; 144 char buf[MAX_BUF];
568 int i, found; 145 int i, found;
584 } 161 }
585 162
586 if (!found) 163 if (!found)
587 { 164 {
588 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 165 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
166
589 for (i = 0; i <= bow_bestarrow; i++) 167 for (i = 0; i <= bow_bestarrow; i++)
590 { 168 {
591 strcat (buf, " "); 169 strcat (buf, " ");
592 strcat (buf, types[i]); 170 strcat (buf, types[i]);
593 if (i < bow_nw) 171 if (i < bow_nw)
602 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); 180 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; 181 return 1;
604} 182}
605 183
606int 184int
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;
634}
635
636int
637command_showpets (object *op, char *params) 185command_showpets (object *op, char *params)
638{ 186{
639 objectlink *obl, *next;
640 int counter = 0, target = 0; 187 int counter = 0, target = 0;
641 int have_shown_pet = 0; 188 int have_shown_pet = 0;
642 189
190 dynbuf_text &msg = msg_dynbuf; msg.clear ();
191
643 if (params != NULL) 192 if (params)
644 target = atoi (params); 193 target = atoi (params);
194
645 for (obl = first_friendly_object; obl != NULL; obl = next) 195 for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
646 { 196 {
647 object *ob = obl->ob; 197 object *ob = obl->ob;
648 198
649 next = obl->next;
650 if (ob->owner == op) 199 if (ob->owner == op)
651 { 200 {
652 if (target == 0) 201 if (target == 0)
653 { 202 {
654 if (counter == 0) 203 if (counter == 0)
655 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 204 msg << "T<Pets>\n\n";
205
656 new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level); 206 msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
657 } 207 }
658 else if (!have_shown_pet && ++counter == target) 208 else if (!have_shown_pet && ++counter == target)
659 { 209 {
660 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name); 210 msg.printf ("T<%s>\n\n"
661 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); 211 " level %d\n"
662 /* this is not a nice way to do this, it should be made to be more like the statistics command */ 212 " %d/%d HP, %d/%d SP\n"
663 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); 213 " Str %2d\n"
664 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); 214 " Dex %2d\n"
665 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con); 215 " Con %2d\n"
666 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int); 216 " Int %2d\n"
667 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis); 217 " Wis %2d\n"
668 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha); 218 " Cha %2d\n"
669 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow); 219 " Pow %2d\n"
670 new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac); 220 " wc %d damage %d ac %d\n",
221 &ob->name,
222 &ob->name,
223 ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp,
224 ob->stats.Str,
225 ob->stats.Dex,
226 ob->stats.Con,
227 ob->stats.Int,
228 ob->stats.Wis,
229 ob->stats.Cha,
230 ob->stats.Pow,
231 ob->stats.wc, ob->stats.dam, ob->stats.ac);
232
671 have_shown_pet = 1; 233 have_shown_pet = 1;
672 } 234 }
673 } 235 }
674 } 236 }
237
675 if (counter == 0) 238 if (counter == 0)
676 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets."); 239 msg << "you have no pets.";
677 else if (target != 0 && have_shown_pet == 0) 240 else if (target != 0 && have_shown_pet == 0)
678 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 241 msg << "no such pet.";
679 return 0;
680}
681 242
682int 243 op->contr->infobox (MSG_CHANNEL ("pets"), msg);
683command_usekeys (object *op, char *params)
684{
685 usekeytype oldtype = op->contr->usekeys;
686 static const char *const types[] = { "inventory", "keyrings", "containers" };
687 244
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; 245 return 0;
707} 246}
708 247
709int 248int
710command_resistances (object *op, char *params) 249command_resistances (object *op, char *params)
711{ 250{
712 int i; 251 dynbuf_text &msg = msg_dynbuf; msg.clear ();
713 252
714 if (!op) 253 msg << "Resistances:\n\n";
715 return 0;
716 254
717 for (i = 0; i < NROFATTACKS; i++) 255 for (int i = 0; i < NROFATTACKS; i++)
718 {
719 if (i == ATNR_INTERNAL) 256 if (i != ATNR_INTERNAL)
720 continue; 257 msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]);
721
722 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
723 }
724 258
725 /* If dragon player, let's display natural resistances */ 259 /* If dragon player, let's display natural resistances */
726 if (is_dragon_pl (op)) 260 if (is_dragon_pl (op))
727 {
728 int attack;
729 object *tmp;
730
731 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 261 for (object *tmp = op->inv; tmp; tmp = tmp->below)
732 {
733 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 262 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
734 { 263 {
735 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 264 msg << "\nOf those, these are natural skin resistances:\n\n";
265
736 for (attack = 0; attack < NROFATTACKS; attack++) 266 for (int attack = 0; attack < NROFATTACKS; attack++)
737 {
738 if (atnr_is_dragon_enabled (attack)) 267 if (atnr_is_dragon_enabled (attack))
739 { 268 msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]);
740 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]); 269
741 }
742 }
743 break; 270 break;
744 } 271 }
745 } 272
746 } 273 op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
747 274
748 return 0; 275 return 0;
749} 276}
750 277
751/* 278/*
752 * Actual commands. 279 * Actual commands.
753 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) 280 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
754 */ 281 */
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 282
971int 283int
972onoff_value (const char *line) 284onoff_value (const char *line)
973{ 285{
974 int i; 286 int i;
997 return 0; 309 return 0;
998 } 310 }
999} 311}
1000 312
1001int 313int
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) 314command_title (object *op, char *params)
1020{ 315{
1021 char buf[MAX_BUF]; 316 char buf[MAX_BUF];
1022 317
1023 if (settings.set_title == FALSE) 318 if (settings.set_title == FALSE)
1060 strcpy (op->contr->own_title, params); 355 strcpy (op->contr->own_title, params);
1061 return 1; 356 return 1;
1062} 357}
1063 358
1064int 359int
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) 360command_kill_pets (object *op, char *params)
1118{ 361{
1119 objectlink *obl, *next; 362 objectlink *obl, *next;
1120 int counter = 0, removecount = 0; 363 int counter = 0, removecount = 0;
1121 364
1122 if (params == NULL) 365 if (!params)
1123 { 366 {
1124 terminate_all_pets (op); 367 terminate_all_pets (op);
1125 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 368 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
1126 } 369 }
1127 else 370 else
1128 { 371 {
1129 int target = atoi (params); 372 int target = atoi (params);
1130 373
1131 for (obl = first_friendly_object; obl != NULL; obl = next) 374 for (obl = first_friendly_object; obl; obl = next)
1132 { 375 {
1133 object *ob = obl->ob; 376 object *ob = obl->ob;
1134 377
1135 next = obl->next; 378 next = obl->next;
379
1136 if (ob->owner == op) 380 if (ob->owner == op)
1137 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 381 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
1138 { 382 {
1139 ob->destroy (); 383 ob->destroy ();
1140 removecount++; 384 removecount++;
1141 } 385 }
1142 } 386 }
387
1143 if (removecount != 0) 388 if (removecount != 0)
1144 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 389 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
1145 else 390 else
1146 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 391 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
1147 } 392 }
393
1148 return 0; 394 return 0;
1149} 395}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines