ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.75
Committed: Mon Oct 12 14:00:59 2009 UTC (14 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_81
Changes since 1.74: +7 -6 lines
Log Message:
clarify license

File Contents

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