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

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen
7 *
8 * 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 *
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 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 *
22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */
24
25 #include <global.h>
26 #include <sproto.h>
27
28 /* Handles misc. input request - things like hash table, malloc, maps, etc */
29
30 int
31 command_time (object *op, char *params)
32 {
33 print_tod (op);
34 return 1;
35 }
36
37 int
38 command_debug (object *op, char *params)
39 {
40 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 return 1;
48 }
49
50 settings.debug = i;
51
52 sprintf (buf, "Set debug level to %d.", i);
53 new_draw_info (NDI_UNIQUE, 0, op, buf);
54 return 1;
55 }
56
57 /*
58 * Those dumps should be just one dump with good parser
59 */
60
61 int
62 command_dumpbelow (object *op, char *params)
63 {
64 if (op && op->below)
65 {
66 char *dump = dump_object (op->below);
67 new_draw_info (NDI_UNIQUE, 0, op, dump);
68 free (dump);
69 /* Let's push that item on the dm's stack */
70 dm_stack_push (op->contr, op->below->count);
71 }
72 return 0;
73 }
74
75 int
76 command_version (object *op, char *params)
77 {
78 version (op);
79 return 0;
80 }
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 int
88 command_statistics (object *pl, char *params)
89 {
90 if (!pl->contr)
91 return 1;
92
93 dynbuf_text &msg = msg_dynbuf; msg.clear ();
94
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
106 /* Can't think of anything else to print right now */
107 return 0;
108 }
109
110 int
111 command_fix_me (object *op, char *params)
112 {
113 op->update_weight ();
114 op->update_stats ();
115 new_draw_info (NDI_UNIQUE, 0, op, "Your character was fixed.");
116
117 return 1;
118 }
119
120 int
121 command_bowmode (object *op, char *params)
122 {
123 bowtype_t oldtype = op->contr->bowtype;
124 static const char *const types[] = {
125 "normal", "threewide", "spreadshot", "firenorth",
126 "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 }
146 }
147
148 if (!found)
149 {
150 sprintf (buf, "bowmode: Unknown options %s, valid options are:", params);
151
152 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 }
161 new_draw_info_format (NDI_UNIQUE, 0, op, buf);
162 return 0;
163 }
164
165 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 }
168
169 int
170 command_showpets (object *op, char *params)
171 {
172 int counter = 0, target = 0;
173 int have_shown_pet = 0;
174
175 dynbuf_text &msg = msg_dynbuf; msg.clear ();
176
177 if (params)
178 target = atoi (params);
179
180 for (objectlink *obl = first_friendly_object; obl; obl = obl->next)
181 {
182 object *ob = obl->ob;
183
184 if (ob->owner == op)
185 {
186 if (target == 0)
187 {
188 if (counter == 0)
189 msg << "T<Pets>\n\n";
190
191 msg.printf (" %3d %s, level %d\n", ++counter, &ob->name, ob->level);
192 }
193 else if (!have_shown_pet && ++counter == target)
194 {
195 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 ob->level,
208 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 have_shown_pet = 1;
219 }
220 }
221 }
222
223 if (counter == 0)
224 msg << "you have no pets.";
225 else if (target != 0 && have_shown_pet == 0)
226 msg << "no such pet.";
227
228 op->contr->infobox (MSG_CHANNEL ("pets"), msg);
229
230 return 0;
231 }
232
233 int
234 command_resistances (object *op, char *params)
235 {
236 dynbuf_text &msg = msg_dynbuf; msg.clear ();
237
238 msg << "Resistances:\n\n";
239
240 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
244 /* If dragon player, let's display natural resistances */
245 if (op->is_dragon ())
246 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
255 break;
256 }
257
258 op->contr->infobox (MSG_CHANNEL ("resistances"), msg);
259
260 return 0;
261 }
262
263 int
264 command_title (object *op, char *params)
265 {
266 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 }
273
274 /* dragon players cannot change titles */
275 if (op->is_dragon ())
276 {
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 }
308
309 int
310 command_kill_pets (object *op, char *params)
311 {
312 objectlink *obl, *next;
313 int counter = 0, removecount = 0;
314
315 if (!params)
316 {
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 for (obl = first_friendly_object; obl; obl = next)
325 {
326 object *ob = obl->ob;
327
328 next = obl->next;
329
330 if (ob->owner == op)
331 if (++counter == target || (target == 0 && !strcasecmp (ob->name, params)))
332 {
333 ob->destroy ();
334 removecount++;
335 }
336 }
337
338 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 }
343
344 return 0;
345 }