ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.73
Committed: Thu Jan 8 00:54:55 2009 UTC (15 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_76, rel-2_77, rel-2_75, rel-2_78
Changes since 1.72: +69 -93 lines
Log Message:
more commands to tabs

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