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.55 by pippijn, Fri Mar 2 11:41:15 2007 UTC vs.
Revision 1.89 by root, Sat Nov 17 23:40:03 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * 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 10 * 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 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the GNU General Public License 19 * 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 20 * and the GNU General Public License along with this program. If not, see
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <global.h> 26#include <global.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, etc */ 29/* Handles misc. input request - things like hash table, malloc, maps, etc */
30 30
31int 31int
32command_motd (object *op, char *params)
33{
34 display_motd (op);
35 return 1;
36}
37
38#ifdef DEBUG_MALLOC_LEVEL
39int
40command_malloc_verify (object *op, char *parms)
41{
42 extern int malloc_verify (void);
43
44 if (!malloc_verify ())
45 new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted.");
46 else
47 new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK.");
48 return 1;
49}
50#endif
51
52int
53command_whereabouts (object *op, char *params)
54{
55 //TODO: should obviously not waste space in struct region for this.
56 /*
57 * reset the counter on the region, then use it to store the number of
58 * players there.
59 * I don't know how thread-safe this would be, I suspect not very....
60 */
61 for_all_regions (rgn)
62 rgn->counter = 0;
63
64 for_all_players (pl)
65 if (pl->ob->map)
66 ++pl->ob->region ()->counter;
67
68 /* we only want to print out by places with a 'longname' field... */
69 for_all_regions (rgn)
70 {
71 if (!rgn->longname && rgn->counter > 0)
72 {
73 if (rgn->parent)
74 {
75 rgn->parent->counter += rgn->counter;
76 rgn->counter = 0;
77 }
78 else /*uh oh, we shouldn't be here. */
79 LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name);
80 }
81 }
82
83 new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:");
84
85 for_all_regions (rgn)
86 if (rgn->counter)
87 new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname);
88
89 return 1;
90}
91
92typedef struct
93{
94 char namebuf[MAX_BUF];
95 int login_order;
96} chars_names;
97
98int
99command_time (object *op, char *params) 32command_time (object *op, char *params)
100{ 33{
101 print_tod (op); 34 print_tod (op);
102 return 1;
103}
104
105int
106command_weather (object *op, char *params)
107{
108#if 0
109 int wx, wy, temp, sky;
110 char buf[MAX_BUF];
111
112 if (settings.dynamiclevel < 1)
113 return 1;
114
115 if (op->map == NULL)
116 return 1;
117
118 if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0)
119 return 1;
120
121 if (QUERY_FLAG (op, FLAG_WIZ))
122 {
123 /* dump the weather, Dm style! Yo! */
124 new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map));
125 new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp);
126 new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid);
127 new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed);
128 new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure);
129 new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev);
130 new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water);
131 }
132
133 temp = real_world_temperature (op->x, op->y, op->map);
134 new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp);
135
136 /* humid */
137 if (weathermap[wx][wy].humid < 20)
138 new_draw_info (NDI_UNIQUE, 0, op, "It is very dry.");
139 else if (weathermap[wx][wy].humid < 40)
140 new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today.");
141 else if (weathermap[wx][wy].humid < 60)
142 new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy.");
143 else if (weathermap[wx][wy].humid < 80)
144 new_draw_info (NDI_UNIQUE, 0, op, "It is muggy.");
145 else
146 new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy.");
147
148 /* wind */
149 switch (weathermap[wx][wy].winddir)
150 {
151 case 1:
152 sprintf (buf, "north");
153 break;
154 case 2:
155 sprintf (buf, "northeast");
156 break;
157 case 3:
158 sprintf (buf, "east");
159 break;
160 case 4:
161 sprintf (buf, "southeast");
162 break;
163 case 5:
164 sprintf (buf, "south");
165 break;
166 case 6:
167 sprintf (buf, "southwest");
168 break;
169 case 7:
170 sprintf (buf, "west");
171 break;
172 case 8:
173 sprintf (buf, "northwest");
174 break;
175 }
176 if (weathermap[wx][wy].windspeed < 5)
177 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf);
178 else if (weathermap[wx][wy].windspeed < 10)
179 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf);
180 else if (weathermap[wx][wy].windspeed < 15)
181 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf);
182 else if (weathermap[wx][wy].windspeed < 25)
183 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf);
184 else if (weathermap[wx][wy].windspeed < 35)
185 new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf);
186 else
187 new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf);
188
189 sky = weathermap[wx][wy].sky;
190 if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG)
191 sky += 10; /*let it snow */
192 switch (sky)
193 {
194 case SKY_CLEAR:
195 new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky.");
196 break;
197 case SKY_LIGHTCLOUD:
198 new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky.");
199 break;
200 case SKY_OVERCAST:
201 new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary.");
202 break;
203 case SKY_LIGHT_RAIN:
204 new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly.");
205 break;
206 case SKY_RAIN:
207 new_draw_info (NDI_UNIQUE, 0, op, "It is raining.");
208 break;
209 case SKY_HEAVY_RAIN:
210 new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily.");
211 break;
212 case SKY_HURRICANE:
213 new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!");
214 break;
215 case SKY_FOG:
216 new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable.");
217 break;
218 case SKY_HAIL:
219 new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!");
220 break;
221 case SKY_LIGHT_SNOW:
222 new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky.");
223 break;
224 case SKY_SNOW:
225 new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out.");
226 break;
227 case SKY_HEAVY_SNOW:
228 new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now.");
229 break;
230 case SKY_BLIZZARD:
231 new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!");
232 break;
233 }
234#endif
235 return 1;
236}
237
238int
239command_hiscore (object *op, char *params)
240{
241 display_high_score (op, op == NULL ? 9999 : 50, params);
242 return 1; 35 return 1;
243} 36}
244 37
245int 38int
246command_debug (object *op, char *params) 39command_debug (object *op, char *params)
252 { 45 {
253 sprintf (buf, "Global debug level is %d.", settings.debug); 46 sprintf (buf, "Global debug level is %d.", settings.debug);
254 new_draw_info (NDI_UNIQUE, 0, op, buf); 47 new_draw_info (NDI_UNIQUE, 0, op, buf);
255 return 1; 48 return 1;
256 } 49 }
257 settings.debug = (enum LogLevel) FABS (i); 50
51 settings.debug = i;
52
258 sprintf (buf, "Set debug level to %d.", i); 53 sprintf (buf, "Set debug level to %d.", i);
259 new_draw_info (NDI_UNIQUE, 0, op, buf); 54 new_draw_info (NDI_UNIQUE, 0, op, buf);
260 return 1; 55 return 1;
261} 56}
262
263 57
264/* 58/*
265 * Those dumps should be just one dump with good parser 59 * Those dumps should be just one dump with good parser
266 */ 60 */
267 61
278 } 72 }
279 return 0; 73 return 0;
280} 74}
281 75
282int 76int
283command_dumpfriendlyobjects (object *op, char *params)
284{
285 dump_friendly_objects ();
286 return 0;
287}
288
289int
290command_printlos (object *op, char *params)
291{
292 if (op)
293 print_los (op);
294 return 0;
295}
296
297
298int
299command_version (object *op, char *params) 77command_version (object *op, char *params)
300{ 78{
301 version (op); 79 version (op);
302 return 0; 80 return 0;
303}
304
305#ifndef BUG_LOG
306# define BUG_LOG "bug_log"
307#endif
308void
309bug_report (const char *reportstring)
310{
311 FILE *fp;
312
313 if ((fp = fopen (BUG_LOG, "a")) != NULL)
314 {
315 fprintf (fp, "%s\n", reportstring);
316 fclose (fp);
317 }
318 else
319 {
320 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
321 }
322} 81}
323 82
324/* Prints out some useful information for the character. Everything we print 83/* Prints out some useful information for the character. Everything we print
325 * out can be determined by the docs, so we aren't revealing anything extra - 84 * out can be determined by the docs, so we aren't revealing anything extra -
326 * rather, we are making it convenient to find the values. params have 85 * rather, we are making it convenient to find the values. params have
329int 88int
330command_statistics (object *pl, char *params) 89command_statistics (object *pl, char *params)
331{ 90{
332 if (!pl->contr) 91 if (!pl->contr)
333 return 1; 92 return 1;
334 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
335 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
336 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
337 93
338 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 94 dynbuf_text &msg = msg_dynbuf; msg.clear ();
339 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 95
340 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 96 msg << " Experience: " << pl->stats.exp << '\n'
341 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); 97 << " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n'
342 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", 98 << "\n Stat Nat/Real/Max\n";
343 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); 99
344 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", 100 for (int i = 0; i < NUM_STATS; ++i)
345 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); 101 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));
346 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", 102
347 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); 103 msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.';
348 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", 104
349 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); 105 pl->contr->infobox (MSG_CHANNEL ("statistics"), msg);
350 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
351 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha);
352 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
353 106
354 /* Can't think of anything else to print right now */ 107 /* Can't think of anything else to print right now */
355 return 0; 108 return 0;
356} 109}
357 110
358int 111int
359command_fix_me (object *op, char *params) 112command_fix_me (object *op, char *params)
360{ 113{
361 sum_weight (op); 114 op->update_weight ();
362 op->update_stats (); 115 op->update_stats ();
363 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); 116 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
364 117
365 return 1; 118 return 1;
366} 119}
367 120
368int 121int
369command_logs (object *op, char *params)
370{
371 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
372
373 return 1;
374}
375
376int
377command_bowmode (object *op, char *params) 122command_bowmode (object *op, char *params)
378{ 123{
379 bowtype_t oldtype = op->contr->bowtype; 124 bowtype_t oldtype = op->contr->bowtype;
380 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth", 125 static const char *const types[] = {
126 "normal", "threewide", "spreadshot", "firenorth",
381 "firene", "fireeast", "firese", "firesouth", 127 "firene", "fireeast", "firese", "firesouth",
382 "firesw", "firewest", "firenw", "bestarrow" 128 "firesw", "firewest", "firenw", "bestarrow"
383 }; 129 };
384 char buf[MAX_BUF]; 130 char buf[MAX_BUF];
385 int i, found; 131 int i, found;
401 } 147 }
402 148
403 if (!found) 149 if (!found)
404 { 150 {
405 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); 151 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
152
406 for (i = 0; i <= bow_bestarrow; i++) 153 for (i = 0; i <= bow_bestarrow; i++)
407 { 154 {
408 strcat (buf, " "); 155 strcat (buf, " ");
409 strcat (buf, types[i]); 156 strcat (buf, types[i]);
410 if (i < bow_nw) 157 if (i < bow_nw)
421} 168}
422 169
423int 170int
424command_showpets (object *op, char *params) 171command_showpets (object *op, char *params)
425{ 172{
426 objectlink *obl, *next;
427 int counter = 0, target = 0; 173 int counter = 0, target = 0;
428 int have_shown_pet = 0; 174 int have_shown_pet = 0;
429 175
176 dynbuf_text &msg = msg_dynbuf; msg.clear ();
177
430 if (params != NULL) 178 if (params)
431 target = atoi (params); 179 target = atoi (params);
180
432 for (obl = first_friendly_object; obl != NULL; obl = next) 181 for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
433 { 182 {
434 object *ob = obl->ob; 183 object *ob = obl->ob;
435 184
436 next = obl->next;
437 if (ob->owner == op) 185 if (ob->owner == op)
438 { 186 {
439 if (target == 0) 187 if (target == 0)
440 { 188 {
441 if (counter == 0) 189 if (counter == 0)
442 new_draw_info (NDI_UNIQUE, 0, op, "Pets:"); 190 msg << "T<Pets>\n\n";
191
443 new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level); 192 msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
444 } 193 }
445 else if (!have_shown_pet && ++counter == target) 194 else if (!have_shown_pet && ++counter == target)
446 { 195 {
447 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name); 196 msg.printf ("T<%s>\n\n"
448 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); 197 " level %d\n"
449 /* this is not a nice way to do this, it should be made to be more like the statistics command */ 198 " %d/%d HP, %d/%d SP\n"
450 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str); 199 " Str %2d\n"
451 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex); 200 " Dex %2d\n"
452 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con); 201 " Con %2d\n"
453 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int); 202 " Int %2d\n"
454 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis); 203 " Wis %2d\n"
455 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha); 204 " Cha %2d\n"
456 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow); 205 " Pow %2d\n"
457 new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac); 206 " wc %d damage %d ac %d\n",
207 &ob->name,
208 ob->level,
209 ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp,
210 ob->stats.Str,
211 ob->stats.Dex,
212 ob->stats.Con,
213 ob->stats.Int,
214 ob->stats.Wis,
215 ob->stats.Cha,
216 ob->stats.Pow,
217 ob->stats.wc, ob->stats.dam, ob->stats.ac);
218
458 have_shown_pet = 1; 219 have_shown_pet = 1;
459 } 220 }
460 } 221 }
461 } 222 }
223
462 if (counter == 0) 224 if (counter == 0)
463 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets."); 225 msg << "you have no pets.";
464 else if (target != 0 && have_shown_pet == 0) 226 else if (target != 0 && have_shown_pet == 0)
465 new_draw_info (NDI_UNIQUE, 0, op, "no such pet."); 227 msg << "no such pet.";
228
229 op->contr->infobox (MSG_CHANNEL ("pets"), msg);
230
466 return 0; 231 return 0;
467} 232}
468 233
469int 234int
470command_resistances (object *op, char *params) 235command_resistances (object *op, char *params)
471{ 236{
472 int i; 237 dynbuf_text &msg = msg_dynbuf; msg.clear ();
473 238
474 if (!op) 239 msg << "Resistances:\n\n";
475 return 0;
476 240
477 for (i = 0; i < NROFATTACKS; i++) 241 for (int i = 0; i < NROFATTACKS; i++)
478 {
479 if (i == ATNR_INTERNAL) 242 if (i != ATNR_INTERNAL)
480 continue; 243 msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]);
481
482 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
483 }
484 244
485 /* If dragon player, let's display natural resistances */ 245 /* If dragon player, let's display natural resistances */
486 if (is_dragon_pl (op)) 246 if (op->is_dragon ())
487 {
488 int attack;
489 object *tmp;
490
491 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 247 for (object *tmp = op->inv; tmp; tmp = tmp->below)
492 {
493 if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) 248 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
494 { 249 {
495 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); 250 msg << "\nOf those, these are natural skin resistances:\n\n";
251
496 for (attack = 0; attack < NROFATTACKS; attack++) 252 for (int attack = 0; attack < NROFATTACKS; attack++)
497 {
498 if (atnr_is_dragon_enabled (attack)) 253 if (atnr_is_dragon_enabled (attack))
499 { 254 msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]);
500 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]);
501 }
502 }
503 break;
504 }
505 }
506 }
507 255
508 return 0;
509}
510
511/*
512 * Actual commands.
513 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
514 */
515
516
517static void
518help_topics (object *op, int what)
519{
520 DIR *dirp;
521 struct dirent *de;
522 char filename[MAX_BUF], line[80];
523 int namelen, linelen = 0;
524
525 switch (what)
526 {
527 case 1:
528 sprintf (filename, "%s/wizhelp", settings.datadir);
529 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
530 break;
531 case 3:
532 sprintf (filename, "%s/mischelp", settings.datadir);
533 new_draw_info (NDI_UNIQUE, 0, op, " Misc help:");
534 break;
535 default:
536 sprintf (filename, "%s/help", settings.datadir);
537 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
538 break;
539 }
540
541 if (!(dirp = opendir (filename)))
542 return;
543
544 line[0] = '\0';
545 while ((de = readdir (dirp)))
546 {
547 namelen = strlen (de->d_name);
548 if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.'))
549 continue;
550 linelen += namelen + 1;
551 if (linelen > 42)
552 {
553 new_draw_info (NDI_UNIQUE, 0, op, line);
554 sprintf (line, " %s", de->d_name);
555 linelen = namelen + 1;
556 continue;
557 }
558 strcat (line, " ");
559 strcat (line, de->d_name);
560 }
561 new_draw_info (NDI_UNIQUE, 0, op, line);
562 closedir (dirp);
563}
564
565static void
566show_commands (object *op, int what)
567{
568 char line[80];
569 int i, size, namelen, linelen = 0;
570 CommArray_s *ap;
571 extern CommArray_s Commands[], WizCommands[];
572 extern const int CommandsSize, WizCommandsSize;
573
574 switch (what)
575 {
576 case 1:
577 ap = WizCommands;
578 size = WizCommandsSize;
579 new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:");
580 break; 256 break;
581 case 2:
582 ap = CommunicationCommands;
583 size = CommunicationCommandSize;
584 new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:");
585 break;
586 default:
587 ap = Commands;
588 size = CommandsSize;
589 new_draw_info (NDI_UNIQUE, 0, op, " Commands:");
590 break;
591 }
592
593 line[0] = '\0';
594 for (i = 0; i < size; i++)
595 {
596 namelen = strlen (ap[i].name);
597 linelen += namelen + 1;
598 if (linelen > 42)
599 { 257 }
600 new_draw_info (NDI_UNIQUE, 0, op, line);
601 sprintf (line, " %s", ap[i].name);
602 linelen = namelen + 1;
603 continue;
604 }
605 strcat (line, " ");
606 strcat (line, ap[i].name);
607 }
608 new_draw_info (NDI_UNIQUE, 0, op, line);
609}
610 258
259 op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
611 260
612int
613command_help (object *op, char *params)
614{
615 struct stat st;
616 FILE *fp;
617 char filename[MAX_BUF], line[MAX_BUF];
618 int len;
619
620 if (op != NULL)
621 clear_win_info (op);
622
623/*
624 * Main help page?
625 */
626 if (!params)
627 {
628 sprintf (filename, "%s/def_help", settings.datadir);
629 if ((fp = fopen (filename, "r")) == NULL)
630 {
631 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
632 return 0;
633 }
634 while (fgets (line, MAX_BUF, fp))
635 {
636 line[MAX_BUF - 1] = '\0';
637 len = strlen (line) - 1;
638 if (line[len] == '\n')
639 line[len] = '\0';
640 new_draw_info (NDI_UNIQUE, 0, op, line);
641 }
642 fclose (fp);
643 return 0; 261 return 0;
644 }
645
646 /*
647 * Topics list
648 */
649 if (!strcmp (params, "topics"))
650 {
651 help_topics (op, 3);
652 help_topics (op, 0);
653 if (QUERY_FLAG (op, FLAG_WIZ))
654 help_topics (op, 1);
655 return 0;
656 }
657
658 /*
659 * Commands list
660 */
661 if (!strcmp (params, "commands"))
662 {
663 show_commands (op, 0);
664 show_commands (op, 2); /* show comm commands */
665 if (QUERY_FLAG (op, FLAG_WIZ))
666 show_commands (op, 1);
667 return 0;
668 }
669
670 /*
671 * User wants info about command
672 */
673 if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/'))
674 {
675 sprintf (line, "Illegal characters in '%s'", params);
676 new_draw_info (NDI_UNIQUE, 0, op, line);
677 return 0;
678 }
679
680 sprintf (filename, "%s/mischelp/%s", settings.datadir, params);
681 if (stat (filename, &st) || !S_ISREG (st.st_mode))
682 {
683 if (op)
684 {
685 sprintf (filename, "%s/help/%s", settings.datadir, params);
686 if (stat (filename, &st) || !S_ISREG (st.st_mode))
687 {
688 if (QUERY_FLAG (op, FLAG_WIZ))
689 {
690 sprintf (filename, "%s/wizhelp/%s", settings.datadir, params);
691 if (stat (filename, &st) || !S_ISREG (st.st_mode))
692 goto nohelp;
693 }
694 else
695 goto nohelp;
696 }
697 }
698 }
699
700 /*
701 * Found that. Just cat it to screen.
702 */
703 if ((fp = fopen (filename, "r")) == NULL)
704 {
705 LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno));
706 return 0;
707 }
708 sprintf (line, "Help about '%s'", params);
709 new_draw_info (NDI_UNIQUE, 0, op, line);
710 while (fgets (line, MAX_BUF, fp))
711 {
712 line[MAX_BUF - 1] = '\0';
713 len = strlen (line) - 1;
714 if (line[len] == '\n')
715 line[len] = '\0';
716 new_draw_info (NDI_UNIQUE, 0, op, line);
717 }
718 fclose (fp);
719 return 0;
720
721 /*
722 * No_help -escape
723 */
724nohelp:
725 sprintf (line, "No help available on '%s'", params);
726 new_draw_info (NDI_UNIQUE, 0, op, line);
727 return 0;
728}
729
730
731int
732onoff_value (const char *line)
733{
734 int i;
735
736 if (sscanf (line, "%d", &i))
737 return (i != 0);
738 switch (line[0])
739 {
740 case 'o':
741 switch (line[1])
742 {
743 case 'n':
744 return 1; /* on */
745 default:
746 return 0; /* o[ff] */
747 }
748 case 'y': /* y[es] */
749 case 'k': /* k[ylla] */
750 case 's':
751 case 'd':
752 return 1;
753 case 'n': /* n[o] */
754 case 'e': /* e[i] */
755 case 'u':
756 default:
757 return 0;
758 }
759} 262}
760 263
761int 264int
762command_title (object *op, char *params) 265command_title (object *op, char *params)
763{ 266{
768 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title."); 271 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
769 return 1; 272 return 1;
770 } 273 }
771 274
772 /* dragon players cannot change titles */ 275 /* dragon players cannot change titles */
773 if (is_dragon_pl (op)) 276 if (op->is_dragon ())
774 { 277 {
775 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles."); 278 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
776 return 1; 279 return 1;
777 } 280 }
778 281
808command_kill_pets (object *op, char *params) 311command_kill_pets (object *op, char *params)
809{ 312{
810 objectlink *obl, *next; 313 objectlink *obl, *next;
811 int counter = 0, removecount = 0; 314 int counter = 0, removecount = 0;
812 315
813 if (params == NULL) 316 if (!params)
814 { 317 {
815 terminate_all_pets (op); 318 terminate_all_pets (op);
816 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); 319 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
817 } 320 }
818 else 321 else
819 { 322 {
820 int target = atoi (params); 323 int target = atoi (params);
821 324
822 for (obl = first_friendly_object; obl != NULL; obl = next) 325 for (obl = first_friendly_object; obl; obl = next)
823 { 326 {
824 object *ob = obl->ob; 327 object *ob = obl->ob;
825 328
826 next = obl->next; 329 next = obl->next;
330
827 if (ob->owner == op) 331 if (ob->owner == op)
828 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) 332 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
829 { 333 {
830 ob->destroy (); 334 ob->destroy ();
831 removecount++; 335 removecount++;
832 } 336 }
833 } 337 }
338
834 if (removecount != 0) 339 if (removecount != 0)
835 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); 340 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
836 else 341 else
837 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); 342 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
838 } 343 }
344
839 return 0; 345 return 0;
840} 346}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines