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.51 by pippijn, Fri Mar 2 10:55:00 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
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;
157}
158 30
159typedef struct 31typedef struct
160{ 32{
161 char namebuf[MAX_BUF]; 33 char namebuf[MAX_BUF];
162 int login_order; 34 int login_order;
163} chars_names; 35} chars_names;
164 36
165int 37int
166command_mapinfo (object *op, char *params)
167{
168 current_map_info (op);
169 return 1;
170}
171
172int
173command_whereami (object *op, char *params)
174{
175 current_region_info (op);
176 return 1;
177}
178
179int
180command_time (object *op, char *params) 38command_time (object *op, char *params)
181{ 39{
182 print_tod (op); 40 print_tod (op);
183 return 1;
184}
185
186int
187command_weather (object *op, char *params)
188{
189#if 0
190 int wx, wy, temp, sky;
191 char buf[MAX_BUF];
192
193 if (settings.dynamiclevel < 1)
194 return 1;
195
196 if (op->map == NULL)
197 return 1;
198
199 if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0)
200 return 1;
201
202 if (QUERY_FLAG (op, FLAG_WIZ))
203 {
204 /* dump the weather, Dm style! Yo! */
205 new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map));
206 new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp);
207 new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid);
208 new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed);
209 new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure);
210 new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev);
211 new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water);
212 }
213
214 temp = real_world_temperature (op->x, op->y, op->map);
215 new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp);
216
217 /* humid */
218 if (weathermap[wx][wy].humid < 20)
219 new_draw_info (NDI_UNIQUE, 0, op, "It is very dry.");
220 else if (weathermap[wx][wy].humid < 40)
221 new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today.");
222 else if (weathermap[wx][wy].humid < 60)
223 new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy.");
224 else if (weathermap[wx][wy].humid < 80)
225 new_draw_info (NDI_UNIQUE, 0, op, "It is muggy.");
226 else
227 new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy.");
228
229 /* wind */
230 switch (weathermap[wx][wy].winddir)
231 {
232 case 1:
233 sprintf (buf, "north");
234 break;
235 case 2:
236 sprintf (buf, "northeast");
237 break;
238 case 3:
239 sprintf (buf, "east");
240 break;
241 case 4:
242 sprintf (buf, "southeast");
243 break;
244 case 5:
245 sprintf (buf, "south");
246 break;
247 case 6:
248 sprintf (buf, "southwest");
249 break;
250 case 7:
251 sprintf (buf, "west");
252 break;
253 case 8:
254 sprintf (buf, "northwest");
255 break;
256 }
257 if (weathermap[wx][wy].windspeed < 5)
258 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf);
259 else if (weathermap[wx][wy].windspeed < 10)
260 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf);
261 else if (weathermap[wx][wy].windspeed < 15)
262 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf);
263 else if (weathermap[wx][wy].windspeed < 25)
264 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf);
265 else if (weathermap[wx][wy].windspeed < 35)
266 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf);
267 else
268 new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf);
269
270 sky = weathermap[wx][wy].sky;
271 if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG)
272 sky += 10; /*let it snow */
273 switch (sky)
274 {
275 case SKY_CLEAR:
276 new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky.");
277 break;
278 case SKY_LIGHTCLOUD:
279 new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky.");
280 break;
281 case SKY_OVERCAST:
282 new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary.");
283 break;
284 case SKY_LIGHT_RAIN:
285 new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly.");
286 break;
287 case SKY_RAIN:
288 new_draw_info (NDI_UNIQUE, 0, op, "It is raining.");
289 break;
290 case SKY_HEAVY_RAIN:
291 new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily.");
292 break;
293 case SKY_HURRICANE:
294 new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!");
295 break;
296 case SKY_FOG:
297 new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable.");
298 break;
299 case SKY_HAIL:
300 new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!");
301 break;
302 case SKY_LIGHT_SNOW:
303 new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky.");
304 break;
305 case SKY_SNOW:
306 new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out.");
307 break;
308 case SKY_HEAVY_SNOW:
309 new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now.");
310 break;
311 case SKY_BLIZZARD:
312 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
313 break;
314 }
315#endif
316 return 1;
317}
318
319int
320command_hiscore (object *op, char *params)
321{
322 display_high_score (op, op == NULL ? 9999 : 50, params);
323 return 1; 41 return 1;
324} 42}
325 43
326int 44int
327command_debug (object *op, char *params) 45command_debug (object *op, char *params)
333 { 51 {
334 sprintf (buf, "Global debug level is %d.", settings.debug); 52 sprintf (buf, "Global debug level is %d.", settings.debug);
335 new_draw_info (NDI_UNIQUE, 0, op, buf); 53 new_draw_info (NDI_UNIQUE, 0, op, buf);
336 return 1; 54 return 1;
337 } 55 }
338 settings.debug = (enum LogLevel) FABS (i); 56
57 settings.debug = i;
58
339 sprintf (buf, "Set debug level to %d.", i); 59 sprintf (buf, "Set debug level to %d.", i);
340 new_draw_info (NDI_UNIQUE, 0, op, buf); 60 new_draw_info (NDI_UNIQUE, 0, op, buf);
341 return 1; 61 return 1;
342} 62}
343
344 63
345/* 64/*
346 * Those dumps should be just one dump with good parser 65 * Those dumps should be just one dump with good parser
347 */ 66 */
348 67
359 } 78 }
360 return 0; 79 return 0;
361} 80}
362 81
363int 82int
364command_dumpfriendlyobjects (object *op, char *params)
365{
366 dump_friendly_objects ();
367 return 0;
368}
369
370int
371command_printlos (object *op, char *params)
372{
373 if (op)
374 print_los (op);
375 return 0;
376}
377
378
379int
380command_version (object *op, char *params) 83command_version (object *op, char *params)
381{ 84{
382 version (op); 85 version (op);
383 return 0; 86 return 0;
384}
385
386#ifndef BUG_LOG
387# define BUG_LOG "bug_log"
388#endif
389void
390bug_report (const char *reportstring)
391{
392 FILE *fp;
393
394 if ((fp = fopen (BUG_LOG, "a")) != NULL)
395 {
396 fprintf (fp, "%s\n", reportstring);
397 fclose (fp);
398 }
399 else
400 {
401 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
402 }
403}
404
405int
406command_output_sync (object *op, char *params)
407{
408 int val;
409
410 if (!params)
411 {
412 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time is presently %d", op->contr->outputs_sync);
413 return 1;
414 }
415 val = atoi (params);
416 if (val > 0)
417 {
418 op->contr->outputs_sync = val;
419 new_draw_info_format (NDI_UNIQUE, 0, op, "Output sync time now set to %d", op->contr->outputs_sync);
420 }
421 else
422 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_sync.");
423
424 return 1;
425}
426
427int
428command_output_count (object *op, char *params)
429{
430 int val;
431
432 if (!params)
433 {
434 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count is presently %d", op->contr->outputs_count);
435 return 1;
436 }
437 val = atoi (params);
438 if (val > 0)
439 {
440 op->contr->outputs_count = val;
441 new_draw_info_format (NDI_UNIQUE, 0, op, "Output count now set to %d", op->contr->outputs_count);
442 }
443 else
444 new_draw_info (NDI_UNIQUE, 0, op, "Invalid value for output_count.");
445
446 return 1;
447} 87}
448 88
449/* Prints out some useful information for the character. Everything we print 89/* Prints out some useful information for the character. Everything we print
450 * 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 -
451 * 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
454int 94int
455command_statistics (object *pl, char *params) 95command_statistics (object *pl, char *params)
456{ 96{
457 if (!pl->contr) 97 if (!pl->contr)
458 return 1; 98 return 1;
459 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
460 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
461 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
462 99
463 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 100 dynbuf_text &msg = msg_dynbuf; msg.clear ();
464 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 101
465 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 102 msg << " Experience: " << pl->stats.exp << '\n'
466 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'
467 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 104 << "\n Stat Nat/Real/Max\n";
468 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 105
469 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 106 for (int i = 0; i < NUM_STATS; ++i)
470 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));
471 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 108
472 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 109 msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.';
473 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 110
474 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 111 pl->contr->infobox (MSG_CHANNEL ("statistics"), msg);
475 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
476 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha);
477 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
478 112
479 /* Can't think of anything else to print right now */ 113 /* Can't think of anything else to print right now */
480 return 0; 114 return 0;
481} 115}
482 116
483int 117int
484command_fix_me (object *op, char *params) 118command_fix_me (object *op, char *params)
485{ 119{
486 sum_weight (op); 120 op->update_weight ();
487 op->update_stats (); 121 op->update_stats ();
488 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); 122 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
489 123
490 return 1; 124 return 1;
491} 125}
492 126
493int 127int
494command_logs (object *op, char *params)
495{
496 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
497
498 return 1;
499}
500
501int
502command_bowmode (object *op, char *params) 128command_bowmode (object *op, char *params)
503{ 129{
504 bowtype_t oldtype = op->contr->bowtype; 130 bowtype_t oldtype = op->contr->bowtype;
505 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth", 131 static const char *const types[] = {
132 "normal", "threewide", "spreadshot", "firenorth",
506 "firene", "fireeast", "firese", "firesouth", 133 "firene", "fireeast", "firese", "firesouth",
507 "firesw", "firewest", "firenw", "bestarrow" 134 "firesw", "firewest", "firenw", "bestarrow"
508 }; 135 };
509 char buf[MAX_BUF]; 136 char buf[MAX_BUF];
510 int i, found; 137 int i, found;
526 } 153 }
527 154
528 if (!found) 155 if (!found)
529 { 156 {
530 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 157 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
158
531 for (i = 0; i <= bow_bestarrow; i++) 159 for (i = 0; i <= bow_bestarrow; i++)
532 { 160 {
533 strcat (buf, " "); 161 strcat (buf, " ");
534 strcat (buf, types[i]); 162 strcat (buf, types[i]);
535 if (i < bow_nw) 163 if (i < bow_nw)
546} 174}
547 175
548int 176int
549command_showpets (object *op, char *params) 177command_showpets (object *op, char *params)
550{ 178{
551 objectlink *obl, *next;
552 int counter = 0, target = 0; 179 int counter = 0, target = 0;
553 int have_shown_pet = 0; 180 int have_shown_pet = 0;
554 181
182 dynbuf_text &msg = msg_dynbuf; msg.clear ();
183
555 if (params != NULL) 184 if (params)
556 target = atoi (params); 185 target = atoi (params);
186
557 for (obl = first_friendly_object; obl != NULL; obl = next) 187 for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
558 { 188 {
559 object *ob = obl->ob; 189 object *ob = obl->ob;
560 190
561 next = obl->next;
562 if (ob->owner == op) 191 if (ob->owner == op)
563 { 192 {
564 if (target == 0) 193 if (target == 0)
565 { 194 {
566 if (counter == 0) 195 if (counter == 0)
567 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 196 msg << "T<Pets>\n\n";
197
568 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);
569 } 199 }
570 else if (!have_shown_pet && ++counter == target) 200 else if (!have_shown_pet && ++counter == target)
571 { 201 {
572 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name); 202 msg.printf ("T<%s>\n\n"
573 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"
574 /* 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"
575 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); 205 " Str %2d\n"
576 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); 206 " Dex %2d\n"
577 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con); 207 " Con %2d\n"
578 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int); 208 " Int %2d\n"
579 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis); 209 " Wis %2d\n"
580 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha); 210 " Cha %2d\n"
581 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow); 211 " Pow %2d\n"
582 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
583 have_shown_pet = 1; 225 have_shown_pet = 1;
584 } 226 }
585 } 227 }
586 } 228 }
229
587 if (counter == 0) 230 if (counter == 0)
588 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets."); 231 msg << "you have no pets.";
589 else if (target != 0 && have_shown_pet == 0) 232 else if (target != 0 && have_shown_pet == 0)
590 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 233 msg << "no such pet.";
234
235 op->contr->infobox (MSG_CHANNEL ("pets"), msg);
236
591 return 0; 237 return 0;
592} 238}
593 239
594int 240int
595command_resistances (object *op, char *params) 241command_resistances (object *op, char *params)
596{ 242{
597 int i; 243 dynbuf_text &msg = msg_dynbuf; msg.clear ();
598 244
599 if (!op) 245 msg << "Resistances:\n\n";
600 return 0;
601 246
602 for (i = 0; i < NROFATTACKS; i++) 247 for (int i = 0; i < NROFATTACKS; i++)
603 {
604 if (i == ATNR_INTERNAL) 248 if (i != ATNR_INTERNAL)
605 continue; 249 msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]);
606
607 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
608 }
609 250
610 /* If dragon player, let's display natural resistances */ 251 /* If dragon player, let's display natural resistances */
611 if (is_dragon_pl (op)) 252 if (is_dragon_pl (op))
612 {
613 int attack;
614 object *tmp;
615
616 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 253 for (object *tmp = op->inv; tmp; tmp = tmp->below)
617 {
618 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 254 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
619 { 255 {
620 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 256 msg << "\nOf those, these are natural skin resistances:\n\n";
257
621 for (attack = 0; attack < NROFATTACKS; attack++) 258 for (int attack = 0; attack < NROFATTACKS; attack++)
622 {
623 if (atnr_is_dragon_enabled (attack)) 259 if (atnr_is_dragon_enabled (attack))
624 { 260 msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]);
625 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]); 261
626 }
627 }
628 break; 262 break;
629 } 263 }
630 } 264
631 } 265 op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
632 266
633 return 0; 267 return 0;
634} 268}
635 269
636/* 270/*
637 * Actual commands. 271 * Actual commands.
638 * 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,...)
639 */ 273 */
640
641
642static void 274static int
643help_topics (object *op, int what)
644{
645 DIR *dirp;
646 struct dirent *de;
647 char filename[MAX_BUF], line[80];
648 int namelen, linelen = 0;
649
650 switch (what)
651 {
652 case 1:
653 sprintf (filename, "%s/wizhelp", settings.datadir);
654 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
655 break;
656 case 3:
657 sprintf (filename, "%s/mischelp", settings.datadir);
658 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
659 break;
660 default:
661 sprintf (filename, "%s/help", settings.datadir);
662 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
663 break;
664 }
665
666 if (!(dirp = opendir (filename)))
667 return;
668
669 line[0] = '\0';
670 while ((de = readdir (dirp)))
671 {
672 namelen = strlen (de->d_name);
673 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
674 continue;
675 linelen += namelen + 1;
676 if (linelen > 42)
677 {
678 new_draw_info (NDI_UNIQUE, 0, op, line);
679 sprintf (line, " %s", de->d_name);
680 linelen = namelen + 1;
681 continue;
682 }
683 strcat (line, " ");
684 strcat (line, de->d_name);
685 }
686 new_draw_info (NDI_UNIQUE, 0, op, line);
687 closedir (dirp);
688}
689
690static void
691show_commands (object *op, int what)
692{
693 char line[80];
694 int i, size, namelen, linelen = 0;
695 CommArray_s *ap;
696 extern CommArray_s Commands[], WizCommands[];
697 extern const int CommandsSize, WizCommandsSize;
698
699 switch (what)
700 {
701 case 1:
702 ap = WizCommands;
703 size = WizCommandsSize;
704 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
705 break;
706 case 2:
707 ap = CommunicationCommands;
708 size = CommunicationCommandSize;
709 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
710 break;
711 default:
712 ap = Commands;
713 size = CommandsSize;
714 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
715 break;
716 }
717
718 line[0] = '\0';
719 for (i = 0; i < size; i++)
720 {
721 namelen = strlen (ap[i].name);
722 linelen += namelen + 1;
723 if (linelen > 42)
724 {
725 new_draw_info (NDI_UNIQUE, 0, op, line);
726 sprintf (line, " %s", ap[i].name);
727 linelen = namelen + 1;
728 continue;
729 }
730 strcat (line, " ");
731 strcat (line, ap[i].name);
732 }
733 new_draw_info (NDI_UNIQUE, 0, op, line);
734}
735
736
737int
738command_help (object *op, char *params)
739{
740 struct stat st;
741 FILE *fp;
742 char filename[MAX_BUF], line[MAX_BUF];
743 int len;
744
745 if (op != NULL)
746 clear_win_info (op);
747
748/*
749 * Main help page?
750 */
751 if (!params)
752 {
753 sprintf (filename, "%s/def_help", settings.datadir);
754 if ((fp = fopen (filename, "r")) == NULL)
755 {
756 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
757 return 0;
758 }
759 while (fgets (line, MAX_BUF, fp))
760 {
761 line[MAX_BUF - 1] = '\0';
762 len = strlen (line) - 1;
763 if (line[len] == '\n')
764 line[len] = '\0';
765 new_draw_info (NDI_UNIQUE, 0, op, line);
766 }
767 fclose (fp);
768 return 0;
769 }
770
771 /*
772 * Topics list
773 */
774 if (!strcmp (params, "topics"))
775 {
776 help_topics (op, 3);
777 help_topics (op, 0);
778 if (QUERY_FLAG (op, FLAG_WIZ))
779 help_topics (op, 1);
780 return 0;
781 }
782
783 /*
784 * Commands list
785 */
786 if (!strcmp (params, "commands"))
787 {
788 show_commands (op, 0);
789 show_commands (op, 2); /* show comm commands */
790 if (QUERY_FLAG (op, FLAG_WIZ))
791 show_commands (op, 1);
792 return 0;
793 }
794
795 /*
796 * User wants info about command
797 */
798 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
799 {
800 sprintf (line, "Illegal characters in '%s'", params);
801 new_draw_info (NDI_UNIQUE, 0, op, line);
802 return 0;
803 }
804
805 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
806 if (stat (filename, &st) || !S_ISREG (st.st_mode))
807 {
808 if (op)
809 {
810 sprintf (filename, "%s/help/%s", settings.datadir, params);
811 if (stat (filename, &st) || !S_ISREG (st.st_mode))
812 {
813 if (QUERY_FLAG (op, FLAG_WIZ))
814 {
815 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
816 if (stat (filename, &st) || !S_ISREG (st.st_mode))
817 goto nohelp;
818 }
819 else
820 goto nohelp;
821 }
822 }
823 }
824
825 /*
826 * Found that. Just cat it to screen.
827 */
828 if ((fp = fopen (filename, "r")) == NULL)
829 {
830 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
831 return 0;
832 }
833 sprintf (line, "Help about '%s'", params);
834 new_draw_info (NDI_UNIQUE, 0, op, line);
835 while (fgets (line, MAX_BUF, fp))
836 {
837 line[MAX_BUF - 1] = '\0';
838 len = strlen (line) - 1;
839 if (line[len] == '\n')
840 line[len] = '\0';
841 new_draw_info (NDI_UNIQUE, 0, op, line);
842 }
843 fclose (fp);
844 return 0;
845
846 /*
847 * No_help -escape
848 */
849nohelp:
850 sprintf (line, "No help available on '%s'", params);
851 new_draw_info (NDI_UNIQUE, 0, op, line);
852 return 0;
853}
854
855
856int
857onoff_value (const char *line) 275onoff_value (const char *line)
858{ 276{
859 int i; 277 int i;
860 278
861 if (sscanf (line, "%d", &i)) 279 if (sscanf (line, "%d", &i))
933command_kill_pets (object *op, char *params) 351command_kill_pets (object *op, char *params)
934{ 352{
935 objectlink *obl, *next; 353 objectlink *obl, *next;
936 int counter = 0, removecount = 0; 354 int counter = 0, removecount = 0;
937 355
938 if (params == NULL) 356 if (!params)
939 { 357 {
940 terminate_all_pets (op); 358 terminate_all_pets (op);
941 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.");
942 } 360 }
943 else 361 else
944 { 362 {
945 int target = atoi (params); 363 int target = atoi (params);
946 364
947 for (obl = first_friendly_object; obl != NULL; obl = next) 365 for (obl = first_friendly_object; obl; obl = next)
948 { 366 {
949 object *ob = obl->ob; 367 object *ob = obl->ob;
950 368
951 next = obl->next; 369 next = obl->next;
370
952 if (ob->owner == op) 371 if (ob->owner == op)
953 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 372 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
954 { 373 {
955 ob->destroy (); 374 ob->destroy ();
956 removecount++; 375 removecount++;
957 } 376 }
958 } 377 }
378
959 if (removecount != 0) 379 if (removecount != 0)
960 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);
961 else 381 else
962 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");
963 } 383 }
384
964 return 0; 385 return 0;
965} 386}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines