1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <loader.h> |
25 | #include <loader.h> |
27 | #include <sproto.h> |
26 | #include <sproto.h> |
28 | |
27 | |
29 | /* Handles misc. input request - things like hash table, malloc, maps, |
28 | /* Handles misc. input request - things like hash table, malloc, maps, etc */ |
30 | * who, etc. |
|
|
31 | */ |
|
|
32 | |
|
|
33 | /* This command dumps the body information for object *op. |
|
|
34 | * it doesn't care what the params are. |
|
|
35 | * This is mostly meant as a debug command. |
|
|
36 | */ |
|
|
37 | int |
|
|
38 | command_body (object *op, char *params) |
|
|
39 | { |
|
|
40 | int i; |
|
|
41 | |
|
|
42 | /* Too hard to try and make a header that lines everything up, so just |
|
|
43 | * give a description. |
|
|
44 | */ |
|
|
45 | new_draw_info (NDI_UNIQUE, 0, op, "The first column is the name of the body location."); |
|
|
46 | new_draw_info (NDI_UNIQUE, 0, op, "The second column is how many of those locations your body has."); |
|
|
47 | new_draw_info (NDI_UNIQUE, 0, op, "The third column is how many slots in that location are available."); |
|
|
48 | for (i = 0; i < NUM_BODY_LOCATIONS; i++) |
|
|
49 | { |
|
|
50 | /* really debugging - normally body_used should not be set to anything |
|
|
51 | * if body_info isn't also set. |
|
|
52 | */ |
|
|
53 | if (op->body_info[i] || op->body_used[i]) |
|
|
54 | { |
|
|
55 | new_draw_info_format (NDI_UNIQUE, 0, op, "%-30s %5d %5d", body_locations[i].use_name, op->body_info[i], op->body_used[i]); |
|
|
56 | } |
|
|
57 | } |
|
|
58 | if (!QUERY_FLAG (op, FLAG_USE_ARMOUR)) |
|
|
59 | new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to wear armor"); |
|
|
60 | if (!QUERY_FLAG (op, FLAG_USE_WEAPON)) |
|
|
61 | new_draw_info (NDI_UNIQUE, 0, op, "You are not allowed to use weapons"); |
|
|
62 | |
|
|
63 | return 1; |
|
|
64 | } |
|
|
65 | |
|
|
66 | |
29 | |
67 | int |
30 | int |
68 | command_motd (object *op, char *params) |
31 | command_motd (object *op, char *params) |
69 | { |
32 | { |
70 | display_motd (op); |
33 | display_motd (op); |
71 | return 1; |
|
|
72 | } |
|
|
73 | |
|
|
74 | #ifdef DEBUG_MALLOC_LEVEL |
|
|
75 | int |
|
|
76 | command_malloc_verify (object *op, char *parms) |
|
|
77 | { |
|
|
78 | extern int malloc_verify (void); |
|
|
79 | |
|
|
80 | if (!malloc_verify ()) |
|
|
81 | new_draw_info (NDI_UNIQUE, 0, op, "Heap is corrupted."); |
|
|
82 | else |
|
|
83 | new_draw_info (NDI_UNIQUE, 0, op, "Heap checks out OK."); |
|
|
84 | return 1; |
|
|
85 | } |
|
|
86 | #endif |
|
|
87 | |
|
|
88 | int |
|
|
89 | command_whereabouts (object *op, char *params) |
|
|
90 | { |
|
|
91 | //TODO: should obviously not waste space in struct region for this. |
|
|
92 | /* |
|
|
93 | * reset the counter on the region, then use it to store the number of |
|
|
94 | * players there. |
|
|
95 | * I don't know how thread-safe this would be, I suspect not very.... |
|
|
96 | */ |
|
|
97 | for_all_regions (rgn) |
|
|
98 | rgn->counter = 0; |
|
|
99 | |
|
|
100 | for_all_players (pl) |
|
|
101 | if (pl->ob->map) |
|
|
102 | ++pl->ob->region ()->counter; |
|
|
103 | |
|
|
104 | /* we only want to print out by places with a 'longname' field... */ |
|
|
105 | for_all_regions (rgn) |
|
|
106 | { |
|
|
107 | if (!rgn->longname && rgn->counter > 0) |
|
|
108 | { |
|
|
109 | if (rgn->parent) |
|
|
110 | { |
|
|
111 | rgn->parent->counter += rgn->counter; |
|
|
112 | rgn->counter = 0; |
|
|
113 | } |
|
|
114 | else /*uh oh, we shouldn't be here. */ |
|
|
115 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", &rgn->name); |
|
|
116 | } |
|
|
117 | } |
|
|
118 | |
|
|
119 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
|
|
120 | |
|
|
121 | for_all_regions (rgn) |
|
|
122 | if (rgn->counter) |
|
|
123 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players %s", rgn->counter, &rgn->longname); |
|
|
124 | |
|
|
125 | return 1; |
34 | return 1; |
126 | } |
35 | } |
127 | |
36 | |
128 | typedef struct |
37 | typedef struct |
129 | { |
38 | { |
… | |
… | |
137 | print_tod (op); |
46 | print_tod (op); |
138 | return 1; |
47 | return 1; |
139 | } |
48 | } |
140 | |
49 | |
141 | int |
50 | int |
142 | command_weather (object *op, char *params) |
|
|
143 | { |
|
|
144 | #if 0 |
|
|
145 | int wx, wy, temp, sky; |
|
|
146 | char buf[MAX_BUF]; |
|
|
147 | |
|
|
148 | if (settings.dynamiclevel < 1) |
|
|
149 | return 1; |
|
|
150 | |
|
|
151 | if (op->map == NULL) |
|
|
152 | return 1; |
|
|
153 | |
|
|
154 | if (worldmap_to_weathermap (op->x, op->y, &wx, &wy, op->map) != 0) |
|
|
155 | return 1; |
|
|
156 | |
|
|
157 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
158 | { |
|
|
159 | /* dump the weather, Dm style! Yo! */ |
|
|
160 | new_draw_info_format (NDI_UNIQUE, 0, op, "Real temp: %d", real_world_temperature (op->x, op->y, op->map)); |
|
|
161 | new_draw_info_format (NDI_UNIQUE, 0, op, "Base temp: %d", weathermap[wx][wy].temp); |
|
|
162 | new_draw_info_format (NDI_UNIQUE, 0, op, "Humid: %d", weathermap[wx][wy].humid); |
|
|
163 | new_draw_info_format (NDI_UNIQUE, 0, op, "Wind: dir=%d speed=%d", weathermap[wx][wy].winddir, weathermap[wx][wy].windspeed); |
|
|
164 | new_draw_info_format (NDI_UNIQUE, 0, op, "Pressure: %d", weathermap[wx][wy].pressure); |
|
|
165 | new_draw_info_format (NDI_UNIQUE, 0, op, "Avg Elevation: %d", weathermap[wx][wy].avgelev); |
|
|
166 | new_draw_info_format (NDI_UNIQUE, 0, op, "Rainfall: %d Water: %d", weathermap[wx][wy].rainfall, weathermap[wx][wy].water); |
|
|
167 | } |
|
|
168 | |
|
|
169 | temp = real_world_temperature (op->x, op->y, op->map); |
|
|
170 | new_draw_info_format (NDI_UNIQUE, 0, op, "It's currently %d degrees " "Centigrade out.", temp); |
|
|
171 | |
|
|
172 | /* humid */ |
|
|
173 | if (weathermap[wx][wy].humid < 20) |
|
|
174 | new_draw_info (NDI_UNIQUE, 0, op, "It is very dry."); |
|
|
175 | else if (weathermap[wx][wy].humid < 40) |
|
|
176 | new_draw_info (NDI_UNIQUE, 0, op, "It is very comfortable today."); |
|
|
177 | else if (weathermap[wx][wy].humid < 60) |
|
|
178 | new_draw_info (NDI_UNIQUE, 0, op, "It is a bit muggy."); |
|
|
179 | else if (weathermap[wx][wy].humid < 80) |
|
|
180 | new_draw_info (NDI_UNIQUE, 0, op, "It is muggy."); |
|
|
181 | else |
|
|
182 | new_draw_info (NDI_UNIQUE, 0, op, "It is uncomfortably muggy."); |
|
|
183 | |
|
|
184 | /* wind */ |
|
|
185 | switch (weathermap[wx][wy].winddir) |
|
|
186 | { |
|
|
187 | case 1: |
|
|
188 | sprintf (buf, "north"); |
|
|
189 | break; |
|
|
190 | case 2: |
|
|
191 | sprintf (buf, "northeast"); |
|
|
192 | break; |
|
|
193 | case 3: |
|
|
194 | sprintf (buf, "east"); |
|
|
195 | break; |
|
|
196 | case 4: |
|
|
197 | sprintf (buf, "southeast"); |
|
|
198 | break; |
|
|
199 | case 5: |
|
|
200 | sprintf (buf, "south"); |
|
|
201 | break; |
|
|
202 | case 6: |
|
|
203 | sprintf (buf, "southwest"); |
|
|
204 | break; |
|
|
205 | case 7: |
|
|
206 | sprintf (buf, "west"); |
|
|
207 | break; |
|
|
208 | case 8: |
|
|
209 | sprintf (buf, "northwest"); |
|
|
210 | break; |
|
|
211 | } |
|
|
212 | if (weathermap[wx][wy].windspeed < 5) |
|
|
213 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a mild breeze " "coming from the %s.", buf); |
|
|
214 | else if (weathermap[wx][wy].windspeed < 10) |
|
|
215 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong breeze " "coming from the %s.", buf); |
|
|
216 | else if (weathermap[wx][wy].windspeed < 15) |
|
|
217 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a light wind " "coming from the %s.", buf); |
|
|
218 | else if (weathermap[wx][wy].windspeed < 25) |
|
|
219 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a strong wind " "coming from the %s.", buf); |
|
|
220 | else if (weathermap[wx][wy].windspeed < 35) |
|
|
221 | new_draw_info_format (NDI_UNIQUE, 0, op, "There is a heavy wind " "coming from the %s.", buf); |
|
|
222 | else |
|
|
223 | new_draw_info_format (NDI_UNIQUE, 0, op, "The wind from the %s is " "incredibly strong!", buf); |
|
|
224 | |
|
|
225 | sky = weathermap[wx][wy].sky; |
|
|
226 | if (temp <= 0 && sky > SKY_OVERCAST && sky < SKY_FOG) |
|
|
227 | sky += 10; /*let it snow */ |
|
|
228 | switch (sky) |
|
|
229 | { |
|
|
230 | case SKY_CLEAR: |
|
|
231 | new_draw_info (NDI_UNIQUE, 0, op, "There isn''t a cloud in the sky."); |
|
|
232 | break; |
|
|
233 | case SKY_LIGHTCLOUD: |
|
|
234 | new_draw_info (NDI_UNIQUE, 0, op, "There are a few light clouds in the sky."); |
|
|
235 | break; |
|
|
236 | case SKY_OVERCAST: |
|
|
237 | new_draw_info (NDI_UNIQUE, 0, op, "The sky is cloudy and dreary."); |
|
|
238 | break; |
|
|
239 | case SKY_LIGHT_RAIN: |
|
|
240 | new_draw_info (NDI_UNIQUE, 0, op, "It is raining softly."); |
|
|
241 | break; |
|
|
242 | case SKY_RAIN: |
|
|
243 | new_draw_info (NDI_UNIQUE, 0, op, "It is raining."); |
|
|
244 | break; |
|
|
245 | case SKY_HEAVY_RAIN: |
|
|
246 | new_draw_info (NDI_UNIQUE, 0, op, "It is raining heavily."); |
|
|
247 | break; |
|
|
248 | case SKY_HURRICANE: |
|
|
249 | new_draw_info (NDI_UNIQUE, 0, op, "There is a heavy storm! You should go inside!"); |
|
|
250 | break; |
|
|
251 | case SKY_FOG: |
|
|
252 | new_draw_info (NDI_UNIQUE, 0, op, "It''s foggy and miserable."); |
|
|
253 | break; |
|
|
254 | case SKY_HAIL: |
|
|
255 | new_draw_info (NDI_UNIQUE, 0, op, "It''s hailing out! Take cover!"); |
|
|
256 | break; |
|
|
257 | case SKY_LIGHT_SNOW: |
|
|
258 | new_draw_info (NDI_UNIQUE, 0, op, "Snow is gently falling from the sky."); |
|
|
259 | break; |
|
|
260 | case SKY_SNOW: |
|
|
261 | new_draw_info (NDI_UNIQUE, 0, op, "It''s snowing out."); |
|
|
262 | break; |
|
|
263 | case SKY_HEAVY_SNOW: |
|
|
264 | new_draw_info (NDI_UNIQUE, 0, op, "The snow is falling very heavily now."); |
|
|
265 | break; |
|
|
266 | case SKY_BLIZZARD: |
|
|
267 | new_draw_info (NDI_UNIQUE, 0, op, "A full blown blizzard is in effect. You might want to take cover!"); |
|
|
268 | break; |
|
|
269 | } |
|
|
270 | #endif |
|
|
271 | return 1; |
|
|
272 | } |
|
|
273 | |
|
|
274 | int |
|
|
275 | command_hiscore (object *op, char *params) |
|
|
276 | { |
|
|
277 | display_high_score (op, op == NULL ? 9999 : 50, params); |
|
|
278 | return 1; |
|
|
279 | } |
|
|
280 | |
|
|
281 | int |
|
|
282 | command_debug (object *op, char *params) |
51 | command_debug (object *op, char *params) |
283 | { |
52 | { |
284 | int i; |
53 | int i; |
285 | char buf[MAX_BUF]; |
54 | char buf[MAX_BUF]; |
286 | |
55 | |
… | |
… | |
288 | { |
57 | { |
289 | sprintf (buf, "Global debug level is %d.", settings.debug); |
58 | sprintf (buf, "Global debug level is %d.", settings.debug); |
290 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
59 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
291 | return 1; |
60 | return 1; |
292 | } |
61 | } |
293 | settings.debug = (enum LogLevel) FABS (i); |
62 | |
|
|
63 | settings.debug = i; |
|
|
64 | |
294 | sprintf (buf, "Set debug level to %d.", i); |
65 | sprintf (buf, "Set debug level to %d.", i); |
295 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
66 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
296 | return 1; |
67 | return 1; |
297 | } |
68 | } |
298 | |
69 | |
… | |
… | |
321 | dump_friendly_objects (); |
92 | dump_friendly_objects (); |
322 | return 0; |
93 | return 0; |
323 | } |
94 | } |
324 | |
95 | |
325 | int |
96 | int |
326 | command_printlos (object *op, char *params) |
|
|
327 | { |
|
|
328 | if (op) |
|
|
329 | print_los (op); |
|
|
330 | return 0; |
|
|
331 | } |
|
|
332 | |
|
|
333 | |
|
|
334 | int |
|
|
335 | command_version (object *op, char *params) |
97 | command_version (object *op, char *params) |
336 | { |
98 | { |
337 | version (op); |
99 | version (op); |
338 | return 0; |
100 | return 0; |
339 | } |
101 | } |
… | |
… | |
370 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp); |
132 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp); |
371 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul)); |
133 | new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul)); |
372 | new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); |
134 | new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); |
373 | |
135 | |
374 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", |
136 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", |
375 | pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); |
137 | pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->stats.Str); |
376 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", |
138 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", |
377 | pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->clone.stats.Dex); |
139 | pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->stats.Dex); |
378 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", |
140 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d", |
379 | pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->clone.stats.Con); |
141 | pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->stats.Con); |
380 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", |
142 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d", |
381 | pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->clone.stats.Int); |
143 | pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->stats.Int); |
382 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", |
144 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d", |
383 | pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->clone.stats.Wis); |
145 | pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->stats.Wis); |
384 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", |
146 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d", |
385 | pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->clone.stats.Pow); |
147 | pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->stats.Pow); |
386 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d", |
148 | new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d", |
387 | pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->clone.stats.Cha); |
149 | pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->stats.Cha); |
388 | new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile"); |
150 | new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile"); |
389 | |
151 | |
390 | /* Can't think of anything else to print right now */ |
152 | /* Can't think of anything else to print right now */ |
391 | return 0; |
153 | return 0; |
392 | } |
154 | } |
393 | |
155 | |
394 | int |
156 | int |
395 | command_fix_me (object *op, char *params) |
157 | command_fix_me (object *op, char *params) |
396 | { |
158 | { |
397 | sum_weight (op); |
159 | op->update_weight (); |
398 | op->update_stats (); |
160 | op->update_stats (); |
399 | new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); |
161 | new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); |
400 | |
|
|
401 | return 1; |
|
|
402 | } |
|
|
403 | |
|
|
404 | int |
|
|
405 | command_logs (object *op, char *params) |
|
|
406 | { |
|
|
407 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
|
|
408 | |
162 | |
409 | return 1; |
163 | return 1; |
410 | } |
164 | } |
411 | |
165 | |
412 | int |
166 | int |
… | |
… | |
524 | int attack; |
278 | int attack; |
525 | object *tmp; |
279 | object *tmp; |
526 | |
280 | |
527 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
281 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
528 | { |
282 | { |
529 | if ((tmp->type == FORCE) && (strcmp (tmp->arch->name, "dragon_skin_force") == 0)) |
283 | if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force) |
530 | { |
284 | { |
531 | new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); |
285 | new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:"); |
532 | for (attack = 0; attack < NROFATTACKS; attack++) |
286 | for (attack = 0; attack < NROFATTACKS; attack++) |
533 | { |
287 | { |
534 | if (atnr_is_dragon_enabled (attack)) |
288 | if (atnr_is_dragon_enabled (attack)) |
… | |
… | |
546 | |
300 | |
547 | /* |
301 | /* |
548 | * Actual commands. |
302 | * Actual commands. |
549 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
303 | * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
550 | */ |
304 | */ |
551 | |
|
|
552 | |
|
|
553 | static void |
|
|
554 | help_topics (object *op, int what) |
|
|
555 | { |
|
|
556 | DIR *dirp; |
|
|
557 | struct dirent *de; |
|
|
558 | char filename[MAX_BUF], line[80]; |
|
|
559 | int namelen, linelen = 0; |
|
|
560 | |
|
|
561 | switch (what) |
|
|
562 | { |
|
|
563 | case 1: |
|
|
564 | sprintf (filename, "%s/wizhelp", settings.datadir); |
|
|
565 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
566 | break; |
|
|
567 | case 3: |
|
|
568 | sprintf (filename, "%s/mischelp", settings.datadir); |
|
|
569 | new_draw_info (NDI_UNIQUE, 0, op, " Misc help:"); |
|
|
570 | break; |
|
|
571 | default: |
|
|
572 | sprintf (filename, "%s/help", settings.datadir); |
|
|
573 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
574 | break; |
|
|
575 | } |
|
|
576 | |
|
|
577 | if (!(dirp = opendir (filename))) |
|
|
578 | return; |
|
|
579 | |
|
|
580 | line[0] = '\0'; |
|
|
581 | while ((de = readdir (dirp))) |
|
|
582 | { |
|
|
583 | namelen = strlen (de->d_name); |
|
|
584 | if (namelen <= 2 && *de->d_name == '.' && (namelen == 1 || de->d_name[1] == '.')) |
|
|
585 | continue; |
|
|
586 | linelen += namelen + 1; |
|
|
587 | if (linelen > 42) |
|
|
588 | { |
|
|
589 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
590 | sprintf (line, " %s", de->d_name); |
|
|
591 | linelen = namelen + 1; |
|
|
592 | continue; |
|
|
593 | } |
|
|
594 | strcat (line, " "); |
|
|
595 | strcat (line, de->d_name); |
|
|
596 | } |
|
|
597 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
598 | closedir (dirp); |
|
|
599 | } |
|
|
600 | |
|
|
601 | static void |
|
|
602 | show_commands (object *op, int what) |
|
|
603 | { |
|
|
604 | char line[80]; |
|
|
605 | int i, size, namelen, linelen = 0; |
|
|
606 | CommArray_s *ap; |
|
|
607 | extern CommArray_s Commands[], WizCommands[]; |
|
|
608 | extern const int CommandsSize, WizCommandsSize; |
|
|
609 | |
|
|
610 | switch (what) |
|
|
611 | { |
|
|
612 | case 1: |
|
|
613 | ap = WizCommands; |
|
|
614 | size = WizCommandsSize; |
|
|
615 | new_draw_info (NDI_UNIQUE, 0, op, " Wiz commands:"); |
|
|
616 | break; |
|
|
617 | case 2: |
|
|
618 | ap = CommunicationCommands; |
|
|
619 | size = CommunicationCommandSize; |
|
|
620 | new_draw_info (NDI_UNIQUE, 0, op, " Communication commands:"); |
|
|
621 | break; |
|
|
622 | default: |
|
|
623 | ap = Commands; |
|
|
624 | size = CommandsSize; |
|
|
625 | new_draw_info (NDI_UNIQUE, 0, op, " Commands:"); |
|
|
626 | break; |
|
|
627 | } |
|
|
628 | |
|
|
629 | line[0] = '\0'; |
|
|
630 | for (i = 0; i < size; i++) |
|
|
631 | { |
|
|
632 | namelen = strlen (ap[i].name); |
|
|
633 | linelen += namelen + 1; |
|
|
634 | if (linelen > 42) |
|
|
635 | { |
|
|
636 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
637 | sprintf (line, " %s", ap[i].name); |
|
|
638 | linelen = namelen + 1; |
|
|
639 | continue; |
|
|
640 | } |
|
|
641 | strcat (line, " "); |
|
|
642 | strcat (line, ap[i].name); |
|
|
643 | } |
|
|
644 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
645 | } |
|
|
646 | |
|
|
647 | |
|
|
648 | int |
|
|
649 | command_help (object *op, char *params) |
|
|
650 | { |
|
|
651 | struct stat st; |
|
|
652 | FILE *fp; |
|
|
653 | char filename[MAX_BUF], line[MAX_BUF]; |
|
|
654 | int len; |
|
|
655 | |
|
|
656 | if (op != NULL) |
|
|
657 | clear_win_info (op); |
|
|
658 | |
|
|
659 | /* |
|
|
660 | * Main help page? |
|
|
661 | */ |
|
|
662 | if (!params) |
|
|
663 | { |
|
|
664 | sprintf (filename, "%s/def_help", settings.datadir); |
|
|
665 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
666 | { |
|
|
667 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
668 | return 0; |
|
|
669 | } |
|
|
670 | while (fgets (line, MAX_BUF, fp)) |
|
|
671 | { |
|
|
672 | line[MAX_BUF - 1] = '\0'; |
|
|
673 | len = strlen (line) - 1; |
|
|
674 | if (line[len] == '\n') |
|
|
675 | line[len] = '\0'; |
|
|
676 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
677 | } |
|
|
678 | fclose (fp); |
|
|
679 | return 0; |
|
|
680 | } |
|
|
681 | |
|
|
682 | /* |
|
|
683 | * Topics list |
|
|
684 | */ |
|
|
685 | if (!strcmp (params, "topics")) |
|
|
686 | { |
|
|
687 | help_topics (op, 3); |
|
|
688 | help_topics (op, 0); |
|
|
689 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
690 | help_topics (op, 1); |
|
|
691 | return 0; |
|
|
692 | } |
|
|
693 | |
|
|
694 | /* |
|
|
695 | * Commands list |
|
|
696 | */ |
|
|
697 | if (!strcmp (params, "commands")) |
|
|
698 | { |
|
|
699 | show_commands (op, 0); |
|
|
700 | show_commands (op, 2); /* show comm commands */ |
|
|
701 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
702 | show_commands (op, 1); |
|
|
703 | return 0; |
|
|
704 | } |
|
|
705 | |
|
|
706 | /* |
|
|
707 | * User wants info about command |
|
|
708 | */ |
|
|
709 | if (strchr (params, '.') || strchr (params, ' ') || strchr (params, '/')) |
|
|
710 | { |
|
|
711 | sprintf (line, "Illegal characters in '%s'", params); |
|
|
712 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
713 | return 0; |
|
|
714 | } |
|
|
715 | |
|
|
716 | sprintf (filename, "%s/mischelp/%s", settings.datadir, params); |
|
|
717 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
718 | { |
|
|
719 | if (op) |
|
|
720 | { |
|
|
721 | sprintf (filename, "%s/help/%s", settings.datadir, params); |
|
|
722 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
723 | { |
|
|
724 | if (QUERY_FLAG (op, FLAG_WIZ)) |
|
|
725 | { |
|
|
726 | sprintf (filename, "%s/wizhelp/%s", settings.datadir, params); |
|
|
727 | if (stat (filename, &st) || !S_ISREG (st.st_mode)) |
|
|
728 | goto nohelp; |
|
|
729 | } |
|
|
730 | else |
|
|
731 | goto nohelp; |
|
|
732 | } |
|
|
733 | } |
|
|
734 | } |
|
|
735 | |
|
|
736 | /* |
|
|
737 | * Found that. Just cat it to screen. |
|
|
738 | */ |
|
|
739 | if ((fp = fopen (filename, "r")) == NULL) |
|
|
740 | { |
|
|
741 | LOG (llevError, "Cannot open help file %s: %s\n", filename, strerror (errno)); |
|
|
742 | return 0; |
|
|
743 | } |
|
|
744 | sprintf (line, "Help about '%s'", params); |
|
|
745 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
746 | while (fgets (line, MAX_BUF, fp)) |
|
|
747 | { |
|
|
748 | line[MAX_BUF - 1] = '\0'; |
|
|
749 | len = strlen (line) - 1; |
|
|
750 | if (line[len] == '\n') |
|
|
751 | line[len] = '\0'; |
|
|
752 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
753 | } |
|
|
754 | fclose (fp); |
|
|
755 | return 0; |
|
|
756 | |
|
|
757 | /* |
|
|
758 | * No_help -escape |
|
|
759 | */ |
|
|
760 | nohelp: |
|
|
761 | sprintf (line, "No help available on '%s'", params); |
|
|
762 | new_draw_info (NDI_UNIQUE, 0, op, line); |
|
|
763 | return 0; |
|
|
764 | } |
|
|
765 | |
|
|
766 | |
305 | |
767 | int |
306 | int |
768 | onoff_value (const char *line) |
307 | onoff_value (const char *line) |
769 | { |
308 | { |
770 | int i; |
309 | int i; |
… | |
… | |
844 | command_kill_pets (object *op, char *params) |
383 | command_kill_pets (object *op, char *params) |
845 | { |
384 | { |
846 | objectlink *obl, *next; |
385 | objectlink *obl, *next; |
847 | int counter = 0, removecount = 0; |
386 | int counter = 0, removecount = 0; |
848 | |
387 | |
849 | if (params == NULL) |
388 | if (!params) |
850 | { |
389 | { |
851 | terminate_all_pets (op); |
390 | terminate_all_pets (op); |
852 | new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
391 | new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
853 | } |
392 | } |
854 | else |
393 | else |
855 | { |
394 | { |
856 | int target = atoi (params); |
395 | int target = atoi (params); |
857 | |
396 | |
858 | for (obl = first_friendly_object; obl != NULL; obl = next) |
397 | for (obl = first_friendly_object; obl; obl = next) |
859 | { |
398 | { |
860 | object *ob = obl->ob; |
399 | object *ob = obl->ob; |
861 | |
400 | |
862 | next = obl->next; |
401 | next = obl->next; |
|
|
402 | |
863 | if (ob->owner == op) |
403 | if (ob->owner == op) |
864 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
404 | if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
865 | { |
405 | { |
866 | ob->destroy (); |
406 | ob->destroy (); |
867 | removecount++; |
407 | removecount++; |
868 | } |
408 | } |
869 | } |
409 | } |
|
|
410 | |
870 | if (removecount != 0) |
411 | if (removecount != 0) |
871 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
412 | new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
872 | else |
413 | else |
873 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
414 | new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
874 | } |
415 | } |
|
|
416 | |
875 | return 0; |
417 | return 0; |
876 | } |
418 | } |