ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.78
Committed: Fri Nov 6 13:03:34 2009 UTC (14 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.77: +1 -2 lines
Log Message:
make effectively static symbols actually static, part 2

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     typedef struct
32 root 1.7 {
33     char namebuf[MAX_BUF];
34     int login_order;
35     } chars_names;
36 elmex 1.1
37 root 1.7 int
38     command_time (object *op, char *params)
39 elmex 1.1 {
40 root 1.2 print_tod (op);
41     return 1;
42     }
43 elmex 1.1
44 root 1.7 int
45     command_debug (object *op, char *params)
46 elmex 1.1 {
47 root 1.7 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 elmex 1.1 return 1;
55     }
56 root 1.58
57     settings.debug = i;
58    
59 root 1.7 sprintf (buf, "Set debug level to %d.", i);
60     new_draw_info (NDI_UNIQUE, 0, op, buf);
61     return 1;
62     }
63 elmex 1.1
64     /*
65     * Those dumps should be just one dump with good parser
66     */
67    
68 root 1.7 int
69     command_dumpbelow (object *op, char *params)
70 elmex 1.1 {
71 root 1.7 if (op && op->below)
72     {
73 root 1.14 char *dump = dump_object (op->below);
74     new_draw_info (NDI_UNIQUE, 0, op, dump);
75     free (dump);
76 elmex 1.1 /* Let's push that item on the dm's stack */
77 root 1.7 dm_stack_push (op->contr, op->below->count);
78     }
79 elmex 1.1 return 0;
80     }
81    
82 root 1.7 int
83     command_version (object *op, char *params)
84 elmex 1.1 {
85 root 1.7 version (op);
86     return 0;
87 elmex 1.1 }
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 root 1.7 int
95     command_statistics (object *pl, char *params)
96 elmex 1.1 {
97 root 1.7 if (!pl->contr)
98     return 1;
99 root 1.73
100 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
101 root 1.73
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 elmex 1.1
113 root 1.7 /* Can't think of anything else to print right now */
114     return 0;
115 elmex 1.1 }
116    
117 root 1.7 int
118     command_fix_me (object *op, char *params)
119 elmex 1.1 {
120 root 1.67 op->update_weight ();
121 root 1.27 op->update_stats ();
122 pippijn 1.51 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
123    
124 root 1.7 return 1;
125 elmex 1.1 }
126    
127 root 1.7 int
128     command_bowmode (object *op, char *params)
129 elmex 1.1 {
130 root 1.7 bowtype_t oldtype = op->contr->bowtype;
131 root 1.73 static const char *const types[] = {
132     "normal", "threewide", "spreadshot", "firenorth",
133 root 1.7 "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 root 1.3 }
153 elmex 1.1 }
154 root 1.38
155 root 1.7 if (!found)
156     {
157     sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
158 root 1.73
159 root 1.7 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 root 1.3 }
168 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
169     return 0;
170 elmex 1.1 }
171 root 1.38
172 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]);
173     return 1;
174 elmex 1.1 }
175    
176 root 1.7 int
177     command_showpets (object *op, char *params)
178 elmex 1.1 {
179 root 1.7 int counter = 0, target = 0;
180     int have_shown_pet = 0;
181    
182 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
183 root 1.73
184     if (params)
185 root 1.7 target = atoi (params);
186 root 1.73
187     for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
188 root 1.7 {
189     object *ob = obl->ob;
190    
191 root 1.22 if (ob->owner == op)
192 root 1.7 {
193     if (target == 0)
194     {
195     if (counter == 0)
196 root 1.73 msg << "T<Pets>\n\n";
197    
198     msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
199 root 1.7 }
200     else if (!have_shown_pet && ++counter == target)
201     {
202 root 1.73 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 root 1.7 have_shown_pet = 1;
226 root 1.3 }
227     }
228 elmex 1.1 }
229 root 1.73
230 root 1.7 if (counter == 0)
231 root 1.73 msg << "you have no pets.";
232 root 1.7 else if (target != 0 && have_shown_pet == 0)
233 root 1.73 msg << "no such pet.";
234    
235     op->contr->infobox (MSG_CHANNEL ("pets"), msg);
236    
237 root 1.7 return 0;
238 elmex 1.1 }
239    
240 root 1.7 int
241     command_resistances (object *op, char *params)
242 elmex 1.1 {
243 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
244 elmex 1.1
245 root 1.73 msg << "Resistances:\n\n";
246 elmex 1.1
247 root 1.73 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 elmex 1.1
251 root 1.7 /* If dragon player, let's display natural resistances */
252     if (is_dragon_pl (op))
253 root 1.73 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 root 1.7
262 root 1.73 break;
263 elmex 1.1 }
264 root 1.73
265     op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
266 elmex 1.1
267 root 1.7 return 0;
268 elmex 1.1 }
269 root 1.7
270 elmex 1.1 /*
271     * Actual commands.
272     * Those should be in small separate files (c_object.c, c_wiz.c, cmove.c,...)
273     */
274 root 1.78 static int
275 root 1.7 onoff_value (const char *line)
276 elmex 1.1 {
277     int i;
278    
279 root 1.7 if (sscanf (line, "%d", &i))
280 elmex 1.1 return (i != 0);
281 root 1.7 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 elmex 1.1 }
303    
304 root 1.7 int
305     command_title (object *op, char *params)
306 elmex 1.1 {
307 root 1.7 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 elmex 1.1 }
314 root 1.7
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 elmex 1.1 }
349    
350 root 1.7 int
351     command_kill_pets (object *op, char *params)
352 elmex 1.1 {
353 root 1.7 objectlink *obl, *next;
354     int counter = 0, removecount = 0;
355    
356 root 1.57 if (!params)
357 root 1.7 {
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 root 1.57 for (obl = first_friendly_object; obl; obl = next)
366 root 1.7 {
367     object *ob = obl->ob;
368    
369     next = obl->next;
370 root 1.56
371 root 1.22 if (ob->owner == op)
372 root 1.7 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
373     {
374 root 1.71 ob->destroy ();
375 root 1.3 removecount++;
376 root 1.7 }
377 root 1.3 }
378 root 1.56
379 root 1.7 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 elmex 1.1 }
384 root 1.56
385 root 1.7 return 0;
386 elmex 1.1 }