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