ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.80
Committed: Sat Nov 7 18:30:05 2009 UTC (14 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_92
Changes since 1.79: +1 -1 lines
Log Message:
lots of cleanups

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 root 1.80 ob->level,
215 root 1.73 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     int
271     command_title (object *op, char *params)
272 elmex 1.1 {
273 root 1.7 char buf[MAX_BUF];
274    
275     if (settings.set_title == FALSE)
276     {
277     new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
278     return 1;
279 elmex 1.1 }
280 root 1.7
281     /* dragon players cannot change titles */
282     if (is_dragon_pl (op))
283     {
284     new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
285     return 1;
286     }
287    
288     if (params == NULL)
289     {
290     if (op->contr->own_title[0] == '\0')
291     sprintf (buf, "Your title is '%s'.", op->contr->title);
292     else
293     sprintf (buf, "Your title is '%s'.", op->contr->own_title);
294     new_draw_info (NDI_UNIQUE, 0, op, buf);
295     return 1;
296     }
297     if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0)
298     {
299     if (op->contr->own_title[0] == '\0')
300     new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title.");
301     else
302     new_draw_info (NDI_UNIQUE, 0, op, "Title set to default.");
303     op->contr->own_title[0] = '\0';
304     return 1;
305     }
306    
307     if ((int) strlen (params) >= MAX_NAME)
308     {
309     new_draw_info (NDI_UNIQUE, 0, op, "Title too long.");
310     return 1;
311     }
312     strcpy (op->contr->own_title, params);
313     return 1;
314 elmex 1.1 }
315    
316 root 1.7 int
317     command_kill_pets (object *op, char *params)
318 elmex 1.1 {
319 root 1.7 objectlink *obl, *next;
320     int counter = 0, removecount = 0;
321    
322 root 1.57 if (!params)
323 root 1.7 {
324     terminate_all_pets (op);
325     new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
326     }
327     else
328     {
329     int target = atoi (params);
330    
331 root 1.57 for (obl = first_friendly_object; obl; obl = next)
332 root 1.7 {
333     object *ob = obl->ob;
334    
335     next = obl->next;
336 root 1.56
337 root 1.22 if (ob->owner == op)
338 root 1.7 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
339     {
340 root 1.71 ob->destroy ();
341 root 1.3 removecount++;
342 root 1.7 }
343 root 1.3 }
344 root 1.56
345 root 1.7 if (removecount != 0)
346     new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
347     else
348     new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
349 elmex 1.1 }
350 root 1.56
351 root 1.7 return 0;
352 elmex 1.1 }