ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.72
Committed: Fri Dec 19 22:47:29 2008 UTC (15 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_74
Changes since 1.71: +0 -9 lines
Log Message:
new los code

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_dumpfriendlyobjects (object *op, char *params)
91 {
92 dump_friendly_objects ();
93 return 0;
94 }
95
96 int
97 command_version (object *op, char *params)
98 {
99 version (op);
100 return 0;
101 }
102
103 #ifndef BUG_LOG
104 # define BUG_LOG "bug_log"
105 #endif
106 void
107 bug_report (const char *reportstring)
108 {
109 FILE *fp;
110
111 if ((fp = fopen (BUG_LOG, "a")) != NULL)
112 {
113 fprintf (fp, "%s\n", reportstring);
114 fclose (fp);
115 }
116 else
117 {
118 LOG (llevError, "Cannot write bugs file %s: %s\n", BUG_LOG, strerror (errno));
119 }
120 }
121
122 /* Prints out some useful information for the character. Everything we print
123 * out can be determined by the docs, so we aren't revealing anything extra -
124 * rather, we are making it convenient to find the values. params have
125 * no meaning here.
126 */
127 int
128 command_statistics (object *pl, char *params)
129 {
130 if (!pl->contr)
131 return 1;
132 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
133 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
134 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
135
136 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
137 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->stats.Str);
138 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
139 pl->contr->orig_stats.Dex, pl->stats.Dex, 20 + pl->arch->stats.Dex);
140 new_draw_info_format (NDI_UNIQUE, 0, pl, "Con %2d/ %3d/%3d",
141 pl->contr->orig_stats.Con, pl->stats.Con, 20 + pl->arch->stats.Con);
142 new_draw_info_format (NDI_UNIQUE, 0, pl, "Int %2d/ %3d/%3d",
143 pl->contr->orig_stats.Int, pl->stats.Int, 20 + pl->arch->stats.Int);
144 new_draw_info_format (NDI_UNIQUE, 0, pl, "Wis %2d/ %3d/%3d",
145 pl->contr->orig_stats.Wis, pl->stats.Wis, 20 + pl->arch->stats.Wis);
146 new_draw_info_format (NDI_UNIQUE, 0, pl, "Pow %2d/ %3d/%3d",
147 pl->contr->orig_stats.Pow, pl->stats.Pow, 20 + pl->arch->stats.Pow);
148 new_draw_info_format (NDI_UNIQUE, 0, pl, "Cha %2d/ %3d/%3d",
149 pl->contr->orig_stats.Cha, pl->stats.Cha, 20 + pl->arch->stats.Cha);
150 new_draw_info_format (NDI_UNIQUE, 0, pl, "\nAttack Mode: %s", pl->contr->peaceful ? "Peaceful" : "Hostile");
151
152 /* Can't think of anything else to print right now */
153 return 0;
154 }
155
156 int
157 command_fix_me (object *op, char *params)
158 {
159 op->update_weight ();
160 op->update_stats ();
161 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
162
163 return 1;
164 }
165
166 int
167 command_bowmode (object *op, char *params)
168 {
169 bowtype_t oldtype = op->contr->bowtype;
170 static const char *const types[] = { "normal", "threewide", "spreadshot", "firenorth",
171 "firene", "fireeast", "firese", "firesouth",
172 "firesw", "firewest", "firenw", "bestarrow"
173 };
174 char buf[MAX_BUF];
175 int i, found;
176
177 if (!params)
178 {
179 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]);
180 return 1;
181 }
182
183 for (i = 0, found = 0; i <= bow_bestarrow; i++)
184 {
185 if (!strcmp (params, types[i]))
186 {
187 found++;
188 op->contr->bowtype = (bowtype_t) i;
189 break;
190 }
191 }
192
193 if (!found)
194 {
195 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
196 for (i = 0; i <= bow_bestarrow; i++)
197 {
198 strcat (buf, " ");
199 strcat (buf, types[i]);
200 if (i < bow_nw)
201 strcat (buf, ",");
202 else
203 strcat (buf, ".");
204 }
205 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
206 return 0;
207 }
208
209 new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]);
210 return 1;
211 }
212
213 int
214 command_showpets (object *op, char *params)
215 {
216 objectlink *obl, *next;
217 int counter = 0, target = 0;
218 int have_shown_pet = 0;
219
220 if (params != NULL)
221 target = atoi (params);
222 for (obl = first_friendly_object; obl != NULL; obl = next)
223 {
224 object *ob = obl->ob;
225
226 next = obl->next;
227 if (ob->owner == op)
228 {
229 if (target == 0)
230 {
231 if (counter == 0)
232 new_draw_info (NDI_UNIQUE, 0, op, "Pets:");
233 new_draw_info_format (NDI_UNIQUE, 0, op, "%d %s - level %d", ++counter, &ob->name, ob->level);
234 }
235 else if (!have_shown_pet && ++counter == target)
236 {
237 new_draw_info_format (NDI_UNIQUE, 0, op, "level %d %s", ob->level, &ob->name);
238 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);
239 /* this is not a nice way to do this, it should be made to be more like the statistics command */
240 new_draw_info_format (NDI_UNIQUE, 0, op, "Str %d", ob->stats.Str);
241 new_draw_info_format (NDI_UNIQUE, 0, op, "Dex %d", ob->stats.Dex);
242 new_draw_info_format (NDI_UNIQUE, 0, op, "Con %d", ob->stats.Con);
243 new_draw_info_format (NDI_UNIQUE, 0, op, "Int %d", ob->stats.Int);
244 new_draw_info_format (NDI_UNIQUE, 0, op, "Wis %d", ob->stats.Wis);
245 new_draw_info_format (NDI_UNIQUE, 0, op, "Cha %d", ob->stats.Cha);
246 new_draw_info_format (NDI_UNIQUE, 0, op, "Pow %d", ob->stats.Pow);
247 new_draw_info_format (NDI_UNIQUE, 0, op, "wc %d damage %d ac %d ", ob->stats.wc, ob->stats.dam, ob->stats.ac);
248 have_shown_pet = 1;
249 }
250 }
251 }
252 if (counter == 0)
253 new_draw_info (NDI_UNIQUE, 0, op, "you have no pets.");
254 else if (target != 0 && have_shown_pet == 0)
255 new_draw_info (NDI_UNIQUE, 0, op, "no such pet.");
256 return 0;
257 }
258
259 int
260 command_resistances (object *op, char *params)
261 {
262 int i;
263
264 if (!op)
265 return 0;
266
267 for (i = 0; i < NROFATTACKS; i++)
268 {
269 if (i == ATNR_INTERNAL)
270 continue;
271
272 new_draw_info_format (NDI_UNIQUE, 0, op, "%-20s %+5d", attacktype_desc[i], op->resist[i]);
273 }
274
275 /* If dragon player, let's display natural resistances */
276 if (is_dragon_pl (op))
277 {
278 int attack;
279 object *tmp;
280
281 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
282 {
283 if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
284 {
285 new_draw_info (NDI_UNIQUE, 0, op, "\nNatural skin resistances:");
286 for (attack = 0; attack < NROFATTACKS; attack++)
287 {
288 if (atnr_is_dragon_enabled (attack))
289 {
290 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %d", change_resist_msg[attack], tmp->resist[attack]);
291 }
292 }
293 break;
294 }
295 }
296 }
297
298 return 0;
299 }
300
301 /*
302 * Actual commands.
303 * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
304 */
305
306 int
307 onoff_value (const char *line)
308 {
309 int i;
310
311 if (sscanf (line, "%d", &i))
312 return (i != 0);
313 switch (line[0])
314 {
315 case 'o':
316 switch (line[1])
317 {
318 case 'n':
319 return 1; /* on */
320 default:
321 return 0; /* o[ff] */
322 }
323 case 'y': /* y[es] */
324 case 'k': /* k[ylla] */
325 case 's':
326 case 'd':
327 return 1;
328 case 'n': /* n[o] */
329 case 'e': /* e[i] */
330 case 'u':
331 default:
332 return 0;
333 }
334 }
335
336 int
337 command_title (object *op, char *params)
338 {
339 char buf[MAX_BUF];
340
341 if (settings.set_title == FALSE)
342 {
343 new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
344 return 1;
345 }
346
347 /* dragon players cannot change titles */
348 if (is_dragon_pl (op))
349 {
350 new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
351 return 1;
352 }
353
354 if (params == NULL)
355 {
356 if (op->contr->own_title[0] == '\0')
357 sprintf (buf, "Your title is '%s'.", op->contr->title);
358 else
359 sprintf (buf, "Your title is '%s'.", op->contr->own_title);
360 new_draw_info (NDI_UNIQUE, 0, op, buf);
361 return 1;
362 }
363 if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0)
364 {
365 if (op->contr->own_title[0] == '\0')
366 new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title.");
367 else
368 new_draw_info (NDI_UNIQUE, 0, op, "Title set to default.");
369 op->contr->own_title[0] = '\0';
370 return 1;
371 }
372
373 if ((int) strlen (params) >= MAX_NAME)
374 {
375 new_draw_info (NDI_UNIQUE, 0, op, "Title too long.");
376 return 1;
377 }
378 strcpy (op->contr->own_title, params);
379 return 1;
380 }
381
382 int
383 command_kill_pets (object *op, char *params)
384 {
385 objectlink *obl, *next;
386 int counter = 0, removecount = 0;
387
388 if (!params)
389 {
390 terminate_all_pets (op);
391 new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
392 }
393 else
394 {
395 int target = atoi (params);
396
397 for (obl = first_friendly_object; obl; obl = next)
398 {
399 object *ob = obl->ob;
400
401 next = obl->next;
402
403 if (ob->owner == op)
404 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
405 {
406 ob->destroy ();
407 removecount++;
408 }
409 }
410
411 if (removecount != 0)
412 new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
413 else
414 new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
415 }
416
417 return 0;
418 }