1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 |
* Copyright (©) 1992,2007 Frank Tore Johansen |
7 |
* |
8 |
* Deliantra is free software: you can redistribute it and/or modify it under |
9 |
* the terms of the Affero GNU General Public License as published by the |
10 |
* Free Software Foundation, either version 3 of the License, or (at your |
11 |
* 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 Affero GNU General Public License |
19 |
* and the GNU General Public License along with this program. If not, see |
20 |
* <http://www.gnu.org/licenses/>. |
21 |
* |
22 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
*/ |
24 |
|
25 |
#include <global.h> |
26 |
#include <loader.h> |
27 |
#include <sproto.h> |
28 |
|
29 |
/* Handles misc. input request - things like hash table, malloc, maps, etc */ |
30 |
|
31 |
typedef struct |
32 |
{ |
33 |
char namebuf[MAX_BUF]; |
34 |
int login_order; |
35 |
} chars_names; |
36 |
|
37 |
int |
38 |
command_time (object *op, char *params) |
39 |
{ |
40 |
print_tod (op); |
41 |
return 1; |
42 |
} |
43 |
|
44 |
int |
45 |
command_debug (object *op, char *params) |
46 |
{ |
47 |
int i; |
48 |
char buf[MAX_BUF]; |
49 |
|
50 |
if (params == NULL || !sscanf (params, "%d", &i)) |
51 |
{ |
52 |
sprintf (buf, "Global debug level is %d.", settings.debug); |
53 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
54 |
return 1; |
55 |
} |
56 |
|
57 |
settings.debug = i; |
58 |
|
59 |
sprintf (buf, "Set debug level to %d.", i); |
60 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
61 |
return 1; |
62 |
} |
63 |
|
64 |
/* |
65 |
* Those dumps should be just one dump with good parser |
66 |
*/ |
67 |
|
68 |
int |
69 |
command_dumpbelow (object *op, char *params) |
70 |
{ |
71 |
if (op && op->below) |
72 |
{ |
73 |
char *dump = dump_object (op->below); |
74 |
new_draw_info (NDI_UNIQUE, 0, op, dump); |
75 |
free (dump); |
76 |
/* Let's push that item on the dm's stack */ |
77 |
dm_stack_push (op->contr, op->below->count); |
78 |
} |
79 |
return 0; |
80 |
} |
81 |
|
82 |
int |
83 |
command_version (object *op, char *params) |
84 |
{ |
85 |
version (op); |
86 |
return 0; |
87 |
} |
88 |
|
89 |
/* Prints out some useful information for the character. Everything we print |
90 |
* out can be determined by the docs, so we aren't revealing anything extra - |
91 |
* rather, we are making it convenient to find the values. params have |
92 |
* no meaning here. |
93 |
*/ |
94 |
int |
95 |
command_statistics (object *pl, char *params) |
96 |
{ |
97 |
if (!pl->contr) |
98 |
return 1; |
99 |
|
100 |
dynbuf_text &msg = msg_dynbuf; msg.clear (); |
101 |
|
102 |
msg << " Experience: " << pl->stats.exp << '\n' |
103 |
<< " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n' |
104 |
<< "\n Stat Nat/Real/Max\n"; |
105 |
|
106 |
for (int i = 0; i < NUM_STATS; ++i) |
107 |
msg.printf (" %s %2d/ %3d/%3d\n", short_stat_name [i], pl->contr->orig_stats.stat (i), pl->stats.stat (i), 20 + pl->arch->stats.stat (i)); |
108 |
|
109 |
msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.'; |
110 |
|
111 |
pl->contr->infobox (MSG_CHANNEL ("statistics"), msg); |
112 |
|
113 |
/* Can't think of anything else to print right now */ |
114 |
return 0; |
115 |
} |
116 |
|
117 |
int |
118 |
command_fix_me (object *op, char *params) |
119 |
{ |
120 |
op->update_weight (); |
121 |
op->update_stats (); |
122 |
new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed."); |
123 |
|
124 |
return 1; |
125 |
} |
126 |
|
127 |
int |
128 |
command_bowmode (object *op, char *params) |
129 |
{ |
130 |
bowtype_t oldtype = op->contr->bowtype; |
131 |
static const char *const types[] = { |
132 |
"normal", "threewide", "spreadshot", "firenorth", |
133 |
"firene", "fireeast", "firese", "firesouth", |
134 |
"firesw", "firewest", "firenw", "bestarrow" |
135 |
}; |
136 |
char buf[MAX_BUF]; |
137 |
int i, found; |
138 |
|
139 |
if (!params) |
140 |
{ |
141 |
new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]); |
142 |
return 1; |
143 |
} |
144 |
|
145 |
for (i = 0, found = 0; i <= bow_bestarrow; i++) |
146 |
{ |
147 |
if (!strcmp (params, types[i])) |
148 |
{ |
149 |
found++; |
150 |
op->contr->bowtype = (bowtype_t) i; |
151 |
break; |
152 |
} |
153 |
} |
154 |
|
155 |
if (!found) |
156 |
{ |
157 |
sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
158 |
|
159 |
for (i = 0; i <= bow_bestarrow; i++) |
160 |
{ |
161 |
strcat (buf, " "); |
162 |
strcat (buf, types[i]); |
163 |
if (i < bow_nw) |
164 |
strcat (buf, ","); |
165 |
else |
166 |
strcat (buf, "."); |
167 |
} |
168 |
new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
169 |
return 0; |
170 |
} |
171 |
|
172 |
new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
173 |
return 1; |
174 |
} |
175 |
|
176 |
int |
177 |
command_showpets (object *op, char *params) |
178 |
{ |
179 |
int counter = 0, target = 0; |
180 |
int have_shown_pet = 0; |
181 |
|
182 |
dynbuf_text &msg = msg_dynbuf; msg.clear (); |
183 |
|
184 |
if (params) |
185 |
target = atoi (params); |
186 |
|
187 |
for (objectlink *obl = first_friendly_object; obl; obl = obl->next) |
188 |
{ |
189 |
object *ob = obl->ob; |
190 |
|
191 |
if (ob->owner == op) |
192 |
{ |
193 |
if (target == 0) |
194 |
{ |
195 |
if (counter == 0) |
196 |
msg << "T<Pets>\n\n"; |
197 |
|
198 |
msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level); |
199 |
} |
200 |
else if (!have_shown_pet && ++counter == target) |
201 |
{ |
202 |
msg.printf ("T<%s>\n\n" |
203 |
" level %d\n" |
204 |
" %d/%d HP, %d/%d SP\n" |
205 |
" Str %2d\n" |
206 |
" Dex %2d\n" |
207 |
" Con %2d\n" |
208 |
" Int %2d\n" |
209 |
" Wis %2d\n" |
210 |
" Cha %2d\n" |
211 |
" Pow %2d\n" |
212 |
" wc %d damage %d ac %d\n", |
213 |
&ob->name, |
214 |
&ob->name, |
215 |
ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp, |
216 |
ob->stats.Str, |
217 |
ob->stats.Dex, |
218 |
ob->stats.Con, |
219 |
ob->stats.Int, |
220 |
ob->stats.Wis, |
221 |
ob->stats.Cha, |
222 |
ob->stats.Pow, |
223 |
ob->stats.wc, ob->stats.dam, ob->stats.ac); |
224 |
|
225 |
have_shown_pet = 1; |
226 |
} |
227 |
} |
228 |
} |
229 |
|
230 |
if (counter == 0) |
231 |
msg << "you have no pets."; |
232 |
else if (target != 0 && have_shown_pet == 0) |
233 |
msg << "no such pet."; |
234 |
|
235 |
op->contr->infobox (MSG_CHANNEL ("pets"), msg); |
236 |
|
237 |
return 0; |
238 |
} |
239 |
|
240 |
int |
241 |
command_resistances (object *op, char *params) |
242 |
{ |
243 |
dynbuf_text &msg = msg_dynbuf; msg.clear (); |
244 |
|
245 |
msg << "Resistances:\n\n"; |
246 |
|
247 |
for (int i = 0; i < NROFATTACKS; i++) |
248 |
if (i != ATNR_INTERNAL) |
249 |
msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]); |
250 |
|
251 |
/* If dragon player, let's display natural resistances */ |
252 |
if (is_dragon_pl (op)) |
253 |
for (object *tmp = op->inv; tmp; tmp = tmp->below) |
254 |
if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force) |
255 |
{ |
256 |
msg << "\nOf those, these are natural skin resistances:\n\n"; |
257 |
|
258 |
for (int attack = 0; attack < NROFATTACKS; attack++) |
259 |
if (atnr_is_dragon_enabled (attack)) |
260 |
msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]); |
261 |
|
262 |
break; |
263 |
} |
264 |
|
265 |
op->contr->infobox (MSG_CHANNEL ("resistances"), msg); |
266 |
|
267 |
return 0; |
268 |
} |
269 |
|
270 |
/* |
271 |
* Actual commands. |
272 |
* Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...) |
273 |
*/ |
274 |
static int |
275 |
onoff_value (const char *line) |
276 |
{ |
277 |
int i; |
278 |
|
279 |
if (sscanf (line, "%d", &i)) |
280 |
return (i != 0); |
281 |
switch (line[0]) |
282 |
{ |
283 |
case 'o': |
284 |
switch (line[1]) |
285 |
{ |
286 |
case 'n': |
287 |
return 1; /* on */ |
288 |
default: |
289 |
return 0; /* o[ff] */ |
290 |
} |
291 |
case 'y': /* y[es] */ |
292 |
case 'k': /* k[ylla] */ |
293 |
case 's': |
294 |
case 'd': |
295 |
return 1; |
296 |
case 'n': /* n[o] */ |
297 |
case 'e': /* e[i] */ |
298 |
case 'u': |
299 |
default: |
300 |
return 0; |
301 |
} |
302 |
} |
303 |
|
304 |
int |
305 |
command_title (object *op, char *params) |
306 |
{ |
307 |
char buf[MAX_BUF]; |
308 |
|
309 |
if (settings.set_title == FALSE) |
310 |
{ |
311 |
new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title."); |
312 |
return 1; |
313 |
} |
314 |
|
315 |
/* dragon players cannot change titles */ |
316 |
if (is_dragon_pl (op)) |
317 |
{ |
318 |
new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles."); |
319 |
return 1; |
320 |
} |
321 |
|
322 |
if (params == NULL) |
323 |
{ |
324 |
if (op->contr->own_title[0] == '\0') |
325 |
sprintf (buf, "Your title is '%s'.", op->contr->title); |
326 |
else |
327 |
sprintf (buf, "Your title is '%s'.", op->contr->own_title); |
328 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
329 |
return 1; |
330 |
} |
331 |
if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0) |
332 |
{ |
333 |
if (op->contr->own_title[0] == '\0') |
334 |
new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title."); |
335 |
else |
336 |
new_draw_info (NDI_UNIQUE, 0, op, "Title set to default."); |
337 |
op->contr->own_title[0] = '\0'; |
338 |
return 1; |
339 |
} |
340 |
|
341 |
if ((int) strlen (params) >= MAX_NAME) |
342 |
{ |
343 |
new_draw_info (NDI_UNIQUE, 0, op, "Title too long."); |
344 |
return 1; |
345 |
} |
346 |
strcpy (op->contr->own_title, params); |
347 |
return 1; |
348 |
} |
349 |
|
350 |
int |
351 |
command_kill_pets (object *op, char *params) |
352 |
{ |
353 |
objectlink *obl, *next; |
354 |
int counter = 0, removecount = 0; |
355 |
|
356 |
if (!params) |
357 |
{ |
358 |
terminate_all_pets (op); |
359 |
new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed."); |
360 |
} |
361 |
else |
362 |
{ |
363 |
int target = atoi (params); |
364 |
|
365 |
for (obl = first_friendly_object; obl; obl = next) |
366 |
{ |
367 |
object *ob = obl->ob; |
368 |
|
369 |
next = obl->next; |
370 |
|
371 |
if (ob->owner == op) |
372 |
if (++counter == target || (target == 0 && !strcasecmp (ob->name, params))) |
373 |
{ |
374 |
ob->destroy (); |
375 |
removecount++; |
376 |
} |
377 |
} |
378 |
|
379 |
if (removecount != 0) |
380 |
new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount); |
381 |
else |
382 |
new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n"); |
383 |
} |
384 |
|
385 |
return 0; |
386 |
} |