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