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

# User Rev Content
1 elmex 1.1 /*
2 root 1.65 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.36 *
4 root 1.68 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.59 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992,2007 Frank Tore Johansen
7 pippijn 1.36 *
8 root 1.75 * 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 pippijn 1.36 *
13 root 1.62 * 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 pippijn 1.36 *
18 root 1.75 * 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 root 1.59 *
22 root 1.65 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.36 */
24 elmex 1.1
25     #include <global.h>
26     #include <loader.h>
27 root 1.21 #include <sproto.h>
28    
29 pippijn 1.55 /* Handles misc. input request - things like hash table, malloc, maps, etc */
30 elmex 1.1
31 root 1.7 int
32     command_motd (object *op, char *params)
33 elmex 1.1 {
34 root 1.7 display_motd (op);
35     return 1;
36 elmex 1.1 }
37    
38     typedef struct
39 root 1.7 {
40     char namebuf[MAX_BUF];
41     int login_order;
42     } chars_names;
43 elmex 1.1
44 root 1.7 int
45     command_time (object *op, char *params)
46 elmex 1.1 {
47 root 1.2 print_tod (op);
48     return 1;
49     }
50 elmex 1.1
51 root 1.7 int
52     command_debug (object *op, char *params)
53 elmex 1.1 {
54 root 1.7 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 elmex 1.1 return 1;
62     }
63 root 1.58
64     settings.debug = i;
65    
66 root 1.7 sprintf (buf, "Set debug level to %d.", i);
67     new_draw_info (NDI_UNIQUE, 0, op, buf);
68     return 1;
69     }
70 elmex 1.1
71    
72     /*
73     * Those dumps should be just one dump with good parser
74     */
75    
76 root 1.7 int
77     command_dumpbelow (object *op, char *params)
78 elmex 1.1 {
79 root 1.7 if (op && op->below)
80     {
81 root 1.14 char *dump = dump_object (op->below);
82     new_draw_info (NDI_UNIQUE, 0, op, dump);
83     free (dump);
84 elmex 1.1 /* Let's push that item on the dm's stack */
85 root 1.7 dm_stack_push (op->contr, op->below->count);
86     }
87 elmex 1.1 return 0;
88     }
89    
90 root 1.7 int
91     command_version (object *op, char *params)
92 elmex 1.1 {
93 root 1.7 version (op);
94     return 0;
95 elmex 1.1 }
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 root 1.7 int
103     command_statistics (object *pl, char *params)
104 elmex 1.1 {
105 root 1.7 if (!pl->contr)
106     return 1;
107 root 1.73
108 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
109 root 1.73
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 elmex 1.1
121 root 1.7 /* Can't think of anything else to print right now */
122     return 0;
123 elmex 1.1 }
124    
125 root 1.7 int
126     command_fix_me (object *op, char *params)
127 elmex 1.1 {
128 root 1.67 op->update_weight ();
129 root 1.27 op->update_stats ();
130 pippijn 1.51 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
131    
132 root 1.7 return 1;
133 elmex 1.1 }
134    
135 root 1.7 int
136     command_bowmode (object *op, char *params)
137 elmex 1.1 {
138 root 1.7 bowtype_t oldtype = op->contr->bowtype;
139 root 1.73 static const char *const types[] = {
140     "normal", "threewide", "spreadshot", "firenorth",
141 root 1.7 "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 root 1.3 }
161 elmex 1.1 }
162 root 1.38
163 root 1.7 if (!found)
164     {
165     sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
166 root 1.73
167 root 1.7 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 root 1.3 }
176 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
177     return 0;
178 elmex 1.1 }
179 root 1.38
180 root 1.7 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 elmex 1.1 }
183    
184 root 1.7 int
185     command_showpets (object *op, char *params)
186 elmex 1.1 {
187 root 1.7 int counter = 0, target = 0;
188     int have_shown_pet = 0;
189    
190 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
191 root 1.73
192     if (params)
193 root 1.7 target = atoi (params);
194 root 1.73
195     for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
196 root 1.7 {
197     object *ob = obl->ob;
198    
199 root 1.22 if (ob->owner == op)
200 root 1.7 {
201     if (target == 0)
202     {
203     if (counter == 0)
204 root 1.73 msg << "T<Pets>\n\n";
205    
206     msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
207 root 1.7 }
208     else if (!have_shown_pet && ++counter == target)
209     {
210 root 1.73 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 root 1.7 have_shown_pet = 1;
234 root 1.3 }
235     }
236 elmex 1.1 }
237 root 1.73
238 root 1.7 if (counter == 0)
239 root 1.73 msg << "you have no pets.";
240 root 1.7 else if (target != 0 && have_shown_pet == 0)
241 root 1.73 msg << "no such pet.";
242    
243     op->contr->infobox (MSG_CHANNEL ("pets"), msg);
244    
245 root 1.7 return 0;
246 elmex 1.1 }
247    
248 root 1.7 int
249     command_resistances (object *op, char *params)
250 elmex 1.1 {
251 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
252 elmex 1.1
253 root 1.73 msg << "Resistances:\n\n";
254 elmex 1.1
255 root 1.73 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 elmex 1.1
259 root 1.7 /* If dragon player, let's display natural resistances */
260     if (is_dragon_pl (op))
261 root 1.73 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 root 1.7
270 root 1.73 break;
271 elmex 1.1 }
272 root 1.73
273     op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
274 elmex 1.1
275 root 1.7 return 0;
276 elmex 1.1 }
277 root 1.7
278 elmex 1.1 /*
279     * Actual commands.
280     * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
281     */
282    
283 root 1.7 int
284     onoff_value (const char *line)
285 elmex 1.1 {
286     int i;
287    
288 root 1.7 if (sscanf (line, "%d", &i))
289 elmex 1.1 return (i != 0);
290 root 1.7 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 elmex 1.1 }
312    
313 root 1.7 int
314     command_title (object *op, char *params)
315 elmex 1.1 {
316 root 1.7 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 elmex 1.1 }
323 root 1.7
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 elmex 1.1 }
358    
359 root 1.7 int
360     command_kill_pets (object *op, char *params)
361 elmex 1.1 {
362 root 1.7 objectlink *obl, *next;
363     int counter = 0, removecount = 0;
364    
365 root 1.57 if (!params)
366 root 1.7 {
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 root 1.57 for (obl = first_friendly_object; obl; obl = next)
375 root 1.7 {
376     object *ob = obl->ob;
377    
378     next = obl->next;
379 root 1.56
380 root 1.22 if (ob->owner == op)
381 root 1.7 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
382     {
383 root 1.71 ob->destroy ();
384 root 1.3 removecount++;
385 root 1.7 }
386 root 1.3 }
387 root 1.56
388 root 1.7 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 elmex 1.1 }
393 root 1.56
394 root 1.7 return 0;
395 elmex 1.1 }