ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.87
Committed: Mon Oct 29 23:55:55 2012 UTC (11 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-3_1
Changes since 1.86: +5 -5 lines
Log Message:
trailing space removal

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.65 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.87 *
4 root 1.85 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.83 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992 Frank Tore Johansen
7 root 1.87 *
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 root 1.87 *
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 root 1.87 *
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.87 *
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 root 1.21 #include <sproto.h>
27    
28 pippijn 1.55 /* Handles misc. input request - things like hash table, malloc, maps, etc */
29 elmex 1.1
30 root 1.7 int
31     command_time (object *op, char *params)
32 elmex 1.1 {
33 root 1.2 print_tod (op);
34     return 1;
35     }
36 elmex 1.1
37 root 1.7 int
38     command_debug (object *op, char *params)
39 elmex 1.1 {
40 root 1.7 int i;
41     char buf[MAX_BUF];
42    
43     if (params == NULL || !sscanf (params, "%d", &i))
44     {
45     sprintf (buf, "Global debug level is %d.", settings.debug);
46     new_draw_info (NDI_UNIQUE, 0, op, buf);
47 elmex 1.1 return 1;
48     }
49 root 1.58
50     settings.debug = i;
51    
52 root 1.7 sprintf (buf, "Set debug level to %d.", i);
53     new_draw_info (NDI_UNIQUE, 0, op, buf);
54     return 1;
55     }
56 elmex 1.1
57     /*
58     * Those dumps should be just one dump with good parser
59     */
60    
61 root 1.7 int
62     command_dumpbelow (object *op, char *params)
63 elmex 1.1 {
64 root 1.7 if (op && op->below)
65     {
66 root 1.14 char *dump = dump_object (op->below);
67     new_draw_info (NDI_UNIQUE, 0, op, dump);
68     free (dump);
69 elmex 1.1 /* Let's push that item on the dm's stack */
70 root 1.7 dm_stack_push (op->contr, op->below->count);
71     }
72 elmex 1.1 return 0;
73     }
74    
75 root 1.7 int
76     command_version (object *op, char *params)
77 elmex 1.1 {
78 root 1.7 version (op);
79     return 0;
80 elmex 1.1 }
81    
82     /* Prints out some useful information for the character. Everything we print
83     * out can be determined by the docs, so we aren't revealing anything extra -
84     * rather, we are making it convenient to find the values. params have
85     * no meaning here.
86     */
87 root 1.7 int
88     command_statistics (object *pl, char *params)
89 elmex 1.1 {
90 root 1.7 if (!pl->contr)
91     return 1;
92 root 1.73
93 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
94 root 1.73
95     msg << " Experience: " << pl->stats.exp << '\n'
96     << " Next Level: " << level_exp (pl->level + 1, pl->expmul) << '\n'
97     << "\n Stat Nat/Real/Max\n";
98    
99     for (int i = 0; i < NUM_STATS; ++i)
100     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));
101    
102     msg << "\nYou are " << (pl->contr->peaceful ? "peaceful" : "hostile") << '.';
103    
104     pl->contr->infobox (MSG_CHANNEL ("statistics"), msg);
105 elmex 1.1
106 root 1.7 /* Can't think of anything else to print right now */
107     return 0;
108 elmex 1.1 }
109    
110 root 1.7 int
111     command_fix_me (object *op, char *params)
112 elmex 1.1 {
113 root 1.67 op->update_weight ();
114 root 1.27 op->update_stats ();
115 pippijn 1.51 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
116    
117 root 1.7 return 1;
118 elmex 1.1 }
119    
120 root 1.7 int
121     command_bowmode (object *op, char *params)
122 elmex 1.1 {
123 root 1.7 bowtype_t oldtype = op->contr->bowtype;
124 root 1.73 static const char *const types[] = {
125     "normal", "threewide", "spreadshot", "firenorth",
126 root 1.7 "firene", "fireeast", "firese", "firesouth",
127     "firesw", "firewest", "firenw", "bestarrow"
128     };
129     char buf[MAX_BUF];
130     int i, found;
131    
132     if (!params)
133     {
134     new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode is set to %s", types[op->contr->bowtype]);
135     return 1;
136     }
137    
138     for (i = 0, found = 0; i <= bow_bestarrow; i++)
139     {
140     if (!strcmp (params, types[i]))
141     {
142     found++;
143     op->contr->bowtype = (bowtype_t) i;
144     break;
145 root 1.3 }
146 elmex 1.1 }
147 root 1.38
148 root 1.7 if (!found)
149     {
150     sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
151 root 1.73
152 root 1.7 for (i = 0; i <= bow_bestarrow; i++)
153     {
154     strcat (buf, " ");
155     strcat (buf, types[i]);
156     if (i < bow_nw)
157     strcat (buf, ",");
158     else
159     strcat (buf, ".");
160 root 1.3 }
161 root 1.7 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
162     return 0;
163 elmex 1.1 }
164 root 1.38
165 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]);
166     return 1;
167 elmex 1.1 }
168    
169 root 1.7 int
170     command_showpets (object *op, char *params)
171 elmex 1.1 {
172 root 1.7 int counter = 0, target = 0;
173     int have_shown_pet = 0;
174    
175 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
176 root 1.73
177     if (params)
178 root 1.7 target = atoi (params);
179 root 1.73
180     for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
181 root 1.7 {
182     object *ob = obl->ob;
183    
184 root 1.22 if (ob->owner == op)
185 root 1.7 {
186     if (target == 0)
187     {
188     if (counter == 0)
189 root 1.73 msg << "T<Pets>\n\n";
190    
191     msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
192 root 1.7 }
193     else if (!have_shown_pet && ++counter == target)
194     {
195 root 1.73 msg.printf ("T<%s>\n\n"
196     " level %d\n"
197     " %d/%d HP, %d/%d SP\n"
198     " Str %2d\n"
199     " Dex %2d\n"
200     " Con %2d\n"
201     " Int %2d\n"
202     " Wis %2d\n"
203     " Cha %2d\n"
204     " Pow %2d\n"
205     " wc %d damage %d ac %d\n",
206     &ob->name,
207 root 1.80 ob->level,
208 root 1.73 ob->stats.hp, ob->stats.maxhp, ob->stats.sp, ob->stats.maxsp,
209     ob->stats.Str,
210     ob->stats.Dex,
211     ob->stats.Con,
212     ob->stats.Int,
213     ob->stats.Wis,
214     ob->stats.Cha,
215     ob->stats.Pow,
216     ob->stats.wc, ob->stats.dam, ob->stats.ac);
217    
218 root 1.7 have_shown_pet = 1;
219 root 1.3 }
220     }
221 elmex 1.1 }
222 root 1.73
223 root 1.7 if (counter == 0)
224 root 1.73 msg << "you have no pets.";
225 root 1.7 else if (target != 0 && have_shown_pet == 0)
226 root 1.73 msg << "no such pet.";
227    
228     op->contr->infobox (MSG_CHANNEL ("pets"), msg);
229    
230 root 1.7 return 0;
231 elmex 1.1 }
232    
233 root 1.7 int
234     command_resistances (object *op, char *params)
235 elmex 1.1 {
236 root 1.74 dynbuf_text &msg = msg_dynbuf; msg.clear ();
237 elmex 1.1
238 root 1.73 msg << "Resistances:\n\n";
239 elmex 1.1
240 root 1.73 for (int i = 0; i < NROFATTACKS; i++)
241     if (i != ATNR_INTERNAL)
242     msg.printf (" %-20s %+4d\n", attacktype_desc [i], op->resist [i]);
243 elmex 1.1
244 root 1.7 /* If dragon player, let's display natural resistances */
245 root 1.82 if (op->is_dragon ())
246 root 1.73 for (object *tmp = op->inv; tmp; tmp = tmp->below)
247     if ((tmp->type == FORCE) && tmp->arch->archname == shstr_dragon_skin_force)
248     {
249     msg << "\nOf those, these are natural skin resistances:\n\n";
250    
251     for (int attack = 0; attack < NROFATTACKS; attack++)
252     if (atnr_is_dragon_enabled (attack))
253     msg.printf (" %-20s %+4d\n", change_resist_msg [attack], tmp->resist [attack]);
254 root 1.7
255 root 1.73 break;
256 elmex 1.1 }
257 root 1.73
258     op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
259 elmex 1.1
260 root 1.7 return 0;
261 elmex 1.1 }
262 root 1.7
263     int
264     command_title (object *op, char *params)
265 elmex 1.1 {
266 root 1.7 char buf[MAX_BUF];
267    
268     if (settings.set_title == FALSE)
269     {
270     new_draw_info (NDI_UNIQUE, 0, op, "You cannot change your title.");
271     return 1;
272 elmex 1.1 }
273 root 1.7
274     /* dragon players cannot change titles */
275 root 1.82 if (op->is_dragon ())
276 root 1.7 {
277     new_draw_info (NDI_UNIQUE, 0, op, "Dragons cannot change titles.");
278     return 1;
279     }
280    
281     if (params == NULL)
282     {
283     if (op->contr->own_title[0] == '\0')
284     sprintf (buf, "Your title is '%s'.", op->contr->title);
285     else
286     sprintf (buf, "Your title is '%s'.", op->contr->own_title);
287     new_draw_info (NDI_UNIQUE, 0, op, buf);
288     return 1;
289     }
290     if (strcmp (params, "clear") == 0 || strcmp (params, "default") == 0)
291     {
292     if (op->contr->own_title[0] == '\0')
293     new_draw_info (NDI_UNIQUE, 0, op, "Your title is the default title.");
294     else
295     new_draw_info (NDI_UNIQUE, 0, op, "Title set to default.");
296     op->contr->own_title[0] = '\0';
297     return 1;
298     }
299    
300     if ((int) strlen (params) >= MAX_NAME)
301     {
302     new_draw_info (NDI_UNIQUE, 0, op, "Title too long.");
303     return 1;
304     }
305     strcpy (op->contr->own_title, params);
306     return 1;
307 elmex 1.1 }
308    
309 root 1.7 int
310     command_kill_pets (object *op, char *params)
311 elmex 1.1 {
312 root 1.7 objectlink *obl, *next;
313     int counter = 0, removecount = 0;
314    
315 root 1.57 if (!params)
316 root 1.7 {
317     terminate_all_pets (op);
318     new_draw_info (NDI_UNIQUE, 0, op, "Your pets have been killed.");
319     }
320     else
321     {
322     int target = atoi (params);
323    
324 root 1.57 for (obl = first_friendly_object; obl; obl = next)
325 root 1.7 {
326     object *ob = obl->ob;
327    
328     next = obl->next;
329 root 1.56
330 root 1.22 if (ob->owner == op)
331 root 1.7 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
332     {
333 root 1.71 ob->destroy ();
334 root 1.3 removecount++;
335 root 1.7 }
336 root 1.3 }
337 root 1.56
338 root 1.7 if (removecount != 0)
339     new_draw_info_format (NDI_UNIQUE, 0, op, "killed %d pets.\n", removecount);
340     else
341     new_draw_info (NDI_UNIQUE, 0, op, "Couldn't find any suitable pets to kill.\n");
342 elmex 1.1 }
343 root 1.56
344 root 1.7 return 0;
345 elmex 1.1 }