ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_misc.C
Revision: 1.89
Committed: Sat Nov 17 23:40:03 2018 UTC (5 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.88: +1 -0 lines
Log Message:
copyright update 2018

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