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.52 by pippijn, Fri Mar 2 11:07:59 2007 UTC vs.
Revision 1.84 by root, Sat Apr 23 04:56:55 2011 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,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 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>
27#include <sproto.h> 26#include <sproto.h>
28 27
29/* Handles misc. input request - things like hash table, malloc, maps, 28/* Handles misc. input request - things like hash table, malloc, maps, etc */
30 * who, etc.
31 */
32
33/* This command dumps the body information for object *op.
34 * it doesn't care what the params are.
35 * This is mostly meant as a debug command.
36 */
37int
38command_body (object *op, char *params)
39{
40 int i;
41
42 /* Too hard to try and make a header that lines everything up, so just
43 * give a description.
44 */
45 new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location.");
46 new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has.");
47 new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available.");
48 for (i = 0; i < NUM_BODY_LOCATIONS; i++)
49 {
50 /* really debugging - normally body_used should not be set to anything
51 * if body_info isn't also set.
52 */
53 if (op->body_info[i] || op->body_used[i])
54 {
55 new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]);
56 }
57 }
58 if (!QUERY_FLAG (op, FLAG_USE_ARMOUR))
59 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor");
60 if (!QUERY_FLAG (op, FLAG_USE_WEAPON))
61 new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons");
62
63 return 1;
64}
65
66
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 29
159typedef struct 30typedef struct
160{ 31{
161 char namebuf[MAX_BUF]; 32 char namebuf[MAX_BUF];
162 int login_order; 33 int login_order;
163} chars_names; 34} chars_names;
164 35
165int 36int
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) 37command_time (object *op, char *params)
181{ 38{
182 print_tod (op); 39 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; 40 return 1;
324} 41}
325 42
326int 43int
327command_debug (object *op, char *params) 44command_debug (object *op, char *params)
333 { 50 {
334 sprintf (buf, "Global debug level is %d.", settings.debug); 51 sprintf (buf, "Global debug level is %d.", settings.debug);
335 new_draw_info (NDI_UNIQUE, 0, op, buf); 52 new_draw_info (NDI_UNIQUE, 0, op, buf);
336 return 1; 53 return 1;
337 } 54 }
338 settings.debug = (enum LogLevel) FABS (i); 55
56 settings.debug = i;
57
339 sprintf (buf, "Set debug level to %d.", i); 58 sprintf (buf, "Set debug level to %d.", i);
340 new_draw_info (NDI_UNIQUE, 0, op, buf); 59 new_draw_info (NDI_UNIQUE, 0, op, buf);
341 return 1; 60 return 1;
342} 61}
343
344 62
345/* 63/*
346 * Those dumps should be just one dump with good parser 64 * Those dumps should be just one dump with good parser
347 */ 65 */
348 66
359 } 77 }
360 return 0; 78 return 0;
361} 79}
362 80
363int 81int
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) 82command_version (object *op, char *params)
381{ 83{
382 version (op); 84 version (op);
383 return 0; 85 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} 86}
404 87
405/* Prints out some useful information for the character. Everything we print 88/* Prints out some useful information for the character. Everything we print
406 * out can be determined by the docs, so we aren't revealing anything extra - 89 * out can be determined by the docs, so we aren't revealing anything extra -
407 * rather, we are making it convenient to find the values. params have 90 * rather, we are making it convenient to find the values. params have
410int 93int
411command_statistics (object *pl, char *params) 94command_statistics (object *pl, char *params)
412{ 95{
413 if (!pl->contr) 96 if (!pl->contr)
414 return 1; 97 return 1;
415 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
416 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
417 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
418 98
419 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 99 dynbuf_text &msg = msg_dynbuf; msg.clear ();
420 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 100
421 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 101 msg << " Experience: " << pl->stats.exp << '\n'
422 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); 102 << " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n'
423 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 103 << "\n Stat Nat/Real/Max\n";
424 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 104
425 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 105 for (int i = 0; i < NUM_STATS; ++i)
426 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); 106 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));
427 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 107
428 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 108 msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.';
429 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 109
430 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 110 pl->contr->infobox (MSG_CHANNEL ("statistics"), msg);
431 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
432 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha);
433 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
434 111
435 /* Can't think of anything else to print right now */ 112 /* Can't think of anything else to print right now */
436 return 0; 113 return 0;
437} 114}
438 115
439int 116int
440command_fix_me (object *op, char *params) 117command_fix_me (object *op, char *params)
441{ 118{
442 sum_weight (op); 119 op->update_weight ();
443 op->update_stats (); 120 op->update_stats ();
444 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); 121 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
445 122
446 return 1; 123 return 1;
447} 124}
448 125
449int 126int
450command_logs (object *op, char *params)
451{
452 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
453
454 return 1;
455}
456
457int
458command_bowmode (object *op, char *params) 127command_bowmode (object *op, char *params)
459{ 128{
460 bowtype_t oldtype = op->contr->bowtype; 129 bowtype_t oldtype = op->contr->bowtype;
461 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth", 130 static const char *const types[] = {
131 "normal", "threewide", "spreadshot", "firenorth",
462 "firene", "fireeast", "firese", "firesouth", 132 "firene", "fireeast", "firese", "firesouth",
463 "firesw", "firewest", "firenw", "bestarrow" 133 "firesw", "firewest", "firenw", "bestarrow"
464 }; 134 };
465 char buf[MAX_BUF]; 135 char buf[MAX_BUF];
466 int i, found; 136 int i, found;
482 } 152 }
483 153
484 if (!found) 154 if (!found)
485 { 155 {
486 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 156 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
157
487 for (i = 0; i <= bow_bestarrow; i++) 158 for (i = 0; i <= bow_bestarrow; i++)
488 { 159 {
489 strcat (buf, " "); 160 strcat (buf, " ");
490 strcat (buf, types[i]); 161 strcat (buf, types[i]);
491 if (i < bow_nw) 162 if (i < bow_nw)
502} 173}
503 174
504int 175int
505command_showpets (object *op, char *params) 176command_showpets (object *op, char *params)
506{ 177{
507 objectlink *obl, *next;
508 int counter = 0, target = 0; 178 int counter = 0, target = 0;
509 int have_shown_pet = 0; 179 int have_shown_pet = 0;
510 180
181 dynbuf_text &msg = msg_dynbuf; msg.clear ();
182
511 if (params != NULL) 183 if (params)
512 target = atoi (params); 184 target = atoi (params);
185
513 for (obl = first_friendly_object; obl != NULL; obl = next) 186 for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
514 { 187 {
515 object *ob = obl->ob; 188 object *ob = obl->ob;
516 189
517 next = obl->next;
518 if (ob->owner == op) 190 if (ob->owner == op)
519 { 191 {
520 if (target == 0) 192 if (target == 0)
521 { 193 {
522 if (counter == 0) 194 if (counter == 0)
523 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 195 msg << "T<Pets>\n\n";
196
524 new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level); 197 msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
525 } 198 }
526 else if (!have_shown_pet && ++counter == target) 199 else if (!have_shown_pet && ++counter == target)
527 { 200 {
528 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name); 201 msg.printf ("T<%s>\n\n"
529 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); 202 " level %d\n"
530 /* this is not a nice way to do this, it should be made to be more like the statistics command */ 203 " %d/%d HP, %d/%d SP\n"
531 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); 204 " Str %2d\n"
532 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); 205 " Dex %2d\n"
533 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con); 206 " Con %2d\n"
534 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int); 207 " Int %2d\n"
535 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis); 208 " Wis %2d\n"
536 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha); 209 " Cha %2d\n"
537 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow); 210 " Pow %2d\n"
538 new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac); 211 " wc %d damage %d ac %d\n",
212 &ob->name,
213 ob->level,
214 ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp,
215 ob->stats.Str,
216 ob->stats.Dex,
217 ob->stats.Con,
218 ob->stats.Int,
219 ob->stats.Wis,
220 ob->stats.Cha,
221 ob->stats.Pow,
222 ob->stats.wc, ob->stats.dam, ob->stats.ac);
223
539 have_shown_pet = 1; 224 have_shown_pet = 1;
540 } 225 }
541 } 226 }
542 } 227 }
228
543 if (counter == 0) 229 if (counter == 0)
544 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets."); 230 msg << "you have no pets.";
545 else if (target != 0 && have_shown_pet == 0) 231 else if (target != 0 && have_shown_pet == 0)
546 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 232 msg << "no such pet.";
233
234 op->contr->infobox (MSG_CHANNEL ("pets"), msg);
235
547 return 0; 236 return 0;
548} 237}
549 238
550int 239int
551command_resistances (object *op, char *params) 240command_resistances (object *op, char *params)
552{ 241{
553 int i; 242 dynbuf_text &msg = msg_dynbuf; msg.clear ();
554 243
555 if (!op) 244 msg << "Resistances:\n\n";
556 return 0;
557 245
558 for (i = 0; i < NROFATTACKS; i++) 246 for (int i = 0; i < NROFATTACKS; i++)
559 {
560 if (i == ATNR_INTERNAL) 247 if (i != ATNR_INTERNAL)
561 continue; 248 msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]);
562
563 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
564 }
565 249
566 /* If dragon player, let's display natural resistances */ 250 /* If dragon player, let's display natural resistances */
567 if (is_dragon_pl (op)) 251 if (op->is_dragon ())
568 {
569 int attack;
570 object *tmp;
571
572 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 252 for (object *tmp = op->inv; tmp; tmp = tmp->below)
573 {
574 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 253 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
575 { 254 {
576 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 255 msg << "\nOf those, these are natural skin resistances:\n\n";
256
577 for (attack = 0; attack < NROFATTACKS; attack++) 257 for (int attack = 0; attack < NROFATTACKS; attack++)
578 {
579 if (atnr_is_dragon_enabled (attack)) 258 if (atnr_is_dragon_enabled (attack))
580 { 259 msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]);
581 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]);
582 }
583 }
584 break;
585 }
586 }
587 }
588 260
589 return 0;
590}
591
592/*
593 * Actual commands.
594 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
595 */
596
597
598static void
599help_topics (object *op, int what)
600{
601 DIR *dirp;
602 struct dirent *de;
603 char filename[MAX_BUF], line[80];
604 int namelen, linelen = 0;
605
606 switch (what)
607 {
608 case 1:
609 sprintf (filename, "%s/wizhelp", settings.datadir);
610 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
611 break;
612 case 3:
613 sprintf (filename, "%s/mischelp", settings.datadir);
614 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
615 break;
616 default:
617 sprintf (filename, "%s/help", settings.datadir);
618 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
619 break;
620 }
621
622 if (!(dirp = opendir (filename)))
623 return;
624
625 line[0] = '\0';
626 while ((de = readdir (dirp)))
627 {
628 namelen = strlen (de->d_name);
629 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
630 continue;
631 linelen += namelen + 1;
632 if (linelen > 42)
633 {
634 new_draw_info (NDI_UNIQUE, 0, op, line);
635 sprintf (line, " %s", de->d_name);
636 linelen = namelen + 1;
637 continue;
638 }
639 strcat (line, " ");
640 strcat (line, de->d_name);
641 }
642 new_draw_info (NDI_UNIQUE, 0, op, line);
643 closedir (dirp);
644}
645
646static void
647show_commands (object *op, int what)
648{
649 char line[80];
650 int i, size, namelen, linelen = 0;
651 CommArray_s *ap;
652 extern CommArray_s Commands[], WizCommands[];
653 extern const int CommandsSize, WizCommandsSize;
654
655 switch (what)
656 {
657 case 1:
658 ap = WizCommands;
659 size = WizCommandsSize;
660 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
661 break; 261 break;
662 case 2:
663 ap = CommunicationCommands;
664 size = CommunicationCommandSize;
665 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
666 break;
667 default:
668 ap = Commands;
669 size = CommandsSize;
670 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
671 break;
672 }
673
674 line[0] = '\0';
675 for (i = 0; i < size; i++)
676 {
677 namelen = strlen (ap[i].name);
678 linelen += namelen + 1;
679 if (linelen > 42)
680 { 262 }
681 new_draw_info (NDI_UNIQUE, 0, op, line);
682 sprintf (line, " %s", ap[i].name);
683 linelen = namelen + 1;
684 continue;
685 }
686 strcat (line, " ");
687 strcat (line, ap[i].name);
688 }
689 new_draw_info (NDI_UNIQUE, 0, op, line);
690}
691 263
264 op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
692 265
693int
694command_help (object *op, char *params)
695{
696 struct stat st;
697 FILE *fp;
698 char filename[MAX_BUF], line[MAX_BUF];
699 int len;
700
701 if (op != NULL)
702 clear_win_info (op);
703
704/*
705 * Main help page?
706 */
707 if (!params)
708 {
709 sprintf (filename, "%s/def_help", settings.datadir);
710 if ((fp = fopen (filename, "r")) == NULL)
711 {
712 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
713 return 0;
714 }
715 while (fgets (line, MAX_BUF, fp))
716 {
717 line[MAX_BUF - 1] = '\0';
718 len = strlen (line) - 1;
719 if (line[len] == '\n')
720 line[len] = '\0';
721 new_draw_info (NDI_UNIQUE, 0, op, line);
722 }
723 fclose (fp);
724 return 0; 266 return 0;
725 }
726
727 /*
728 * Topics list
729 */
730 if (!strcmp (params, "topics"))
731 {
732 help_topics (op, 3);
733 help_topics (op, 0);
734 if (QUERY_FLAG (op, FLAG_WIZ))
735 help_topics (op, 1);
736 return 0;
737 }
738
739 /*
740 * Commands list
741 */
742 if (!strcmp (params, "commands"))
743 {
744 show_commands (op, 0);
745 show_commands (op, 2); /* show comm commands */
746 if (QUERY_FLAG (op, FLAG_WIZ))
747 show_commands (op, 1);
748 return 0;
749 }
750
751 /*
752 * User wants info about command
753 */
754 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
755 {
756 sprintf (line, "Illegal characters in '%s'", params);
757 new_draw_info (NDI_UNIQUE, 0, op, line);
758 return 0;
759 }
760
761 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
762 if (stat (filename, &st) || !S_ISREG (st.st_mode))
763 {
764 if (op)
765 {
766 sprintf (filename, "%s/help/%s", settings.datadir, params);
767 if (stat (filename, &st) || !S_ISREG (st.st_mode))
768 {
769 if (QUERY_FLAG (op, FLAG_WIZ))
770 {
771 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
772 if (stat (filename, &st) || !S_ISREG (st.st_mode))
773 goto nohelp;
774 }
775 else
776 goto nohelp;
777 }
778 }
779 }
780
781 /*
782 * Found that. Just cat it to screen.
783 */
784 if ((fp = fopen (filename, "r")) == NULL)
785 {
786 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
787 return 0;
788 }
789 sprintf (line, "Help about '%s'", params);
790 new_draw_info (NDI_UNIQUE, 0, op, line);
791 while (fgets (line, MAX_BUF, fp))
792 {
793 line[MAX_BUF - 1] = '\0';
794 len = strlen (line) - 1;
795 if (line[len] == '\n')
796 line[len] = '\0';
797 new_draw_info (NDI_UNIQUE, 0, op, line);
798 }
799 fclose (fp);
800 return 0;
801
802 /*
803 * No_help -escape
804 */
805nohelp:
806 sprintf (line, "No help available on '%s'", params);
807 new_draw_info (NDI_UNIQUE, 0, op, line);
808 return 0;
809}
810
811
812int
813onoff_value (const char *line)
814{
815 int i;
816
817 if (sscanf (line, "%d", &i))
818 return (i != 0);
819 switch (line[0])
820 {
821 case 'o':
822 switch (line[1])
823 {
824 case 'n':
825 return 1; /* on */
826 default:
827 return 0; /* o[ff] */
828 }
829 case 'y': /* y[es] */
830 case 'k': /* k[ylla] */
831 case 's':
832 case 'd':
833 return 1;
834 case 'n': /* n[o] */
835 case 'e': /* e[i] */
836 case 'u':
837 default:
838 return 0;
839 }
840} 267}
841 268
842int 269int
843command_title (object *op, char *params) 270command_title (object *op, char *params)
844{ 271{
849 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title."); 276 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
850 return 1; 277 return 1;
851 } 278 }
852 279
853 /* dragon players cannot change titles */ 280 /* dragon players cannot change titles */
854 if (is_dragon_pl (op)) 281 if (op->is_dragon ())
855 { 282 {
856 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles."); 283 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
857 return 1; 284 return 1;
858 } 285 }
859 286
889command_kill_pets (object *op, char *params) 316command_kill_pets (object *op, char *params)
890{ 317{
891 objectlink *obl, *next; 318 objectlink *obl, *next;
892 int counter = 0, removecount = 0; 319 int counter = 0, removecount = 0;
893 320
894 if (params == NULL) 321 if (!params)
895 { 322 {
896 terminate_all_pets (op); 323 terminate_all_pets (op);
897 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 324 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
898 } 325 }
899 else 326 else
900 { 327 {
901 int target = atoi (params); 328 int target = atoi (params);
902 329
903 for (obl = first_friendly_object; obl != NULL; obl = next) 330 for (obl = first_friendly_object; obl; obl = next)
904 { 331 {
905 object *ob = obl->ob; 332 object *ob = obl->ob;
906 333
907 next = obl->next; 334 next = obl->next;
335
908 if (ob->owner == op) 336 if (ob->owner == op)
909 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 337 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
910 { 338 {
911 ob->destroy (); 339 ob->destroy ();
912 removecount++; 340 removecount++;
913 } 341 }
914 } 342 }
343
915 if (removecount != 0) 344 if (removecount != 0)
916 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 345 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
917 else 346 else
918 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 347 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
919 } 348 }
349
920 return 0; 350 return 0;
921} 351}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines