1 |
elmex |
1.1 |
/* |
2 |
root |
1.53 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
root |
1.90 |
* |
4 |
root |
1.93 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.80 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
7 |
root |
1.90 |
* |
8 |
root |
1.72 |
* 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.90 |
* |
13 |
root |
1.49 |
* 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.90 |
* |
18 |
root |
1.72 |
* 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.90 |
* |
22 |
root |
1.53 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
pippijn |
1.32 |
*/ |
24 |
elmex |
1.1 |
|
25 |
|
|
#include <global.h> |
26 |
root |
1.29 |
#include <sproto.h> |
27 |
elmex |
1.1 |
#include <spells.h> |
28 |
|
|
#include <treasure.h> |
29 |
|
|
#include <skills.h> |
30 |
|
|
|
31 |
|
|
/** Defines for DM item stack **/ |
32 |
|
|
#define STACK_SIZE 50 /* Stack size, static */ |
33 |
root |
1.8 |
|
34 |
elmex |
1.1 |
/* Values for 'from' field of get_dm_object */ |
35 |
|
|
#define STACK_FROM_NONE 0 /* Item was not found */ |
36 |
|
|
#define STACK_FROM_TOP 1 /* Item is stack top */ |
37 |
|
|
#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ |
38 |
|
|
#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* Enough of the DM functions seem to need this that I broke |
42 |
|
|
* it out to a seperate function. name is the person |
43 |
|
|
* being saught, rq is who is looking for them. This |
44 |
|
|
* prints diagnostics messages, and returns the |
45 |
|
|
* other player, or NULL otherwise. |
46 |
|
|
*/ |
47 |
root |
1.8 |
static player * |
48 |
|
|
get_other_player_from_name (object *op, char *name) |
49 |
|
|
{ |
50 |
|
|
if (!name) |
51 |
|
|
return NULL; |
52 |
elmex |
1.1 |
|
53 |
root |
1.27 |
for_all_players (pl) |
54 |
root |
1.8 |
if (!strncmp (pl->ob->name, name, MAX_NAME)) |
55 |
root |
1.27 |
{ |
56 |
|
|
if (pl->ob == op) |
57 |
|
|
{ |
58 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "You can't do that to yourself."); |
59 |
|
|
return NULL; |
60 |
|
|
} |
61 |
elmex |
1.1 |
|
62 |
root |
1.27 |
if (pl->ns->state != ST_PLAYING) |
63 |
|
|
{ |
64 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "That player is in no state for that right now."); |
65 |
|
|
return NULL; |
66 |
|
|
} |
67 |
elmex |
1.1 |
|
68 |
root |
1.27 |
return pl; |
69 |
|
|
} |
70 |
root |
1.25 |
|
71 |
root |
1.27 |
new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
72 |
|
|
return 0; |
73 |
elmex |
1.1 |
} |
74 |
|
|
|
75 |
root |
1.74 |
static void |
76 |
|
|
dm_stack_pop (player *pl) |
77 |
|
|
{ |
78 |
|
|
if (!pl->stack_items || !pl->stack_position) |
79 |
|
|
{ |
80 |
|
|
new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!"); |
81 |
|
|
return; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
pl->stack_position--; |
85 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
/** |
89 |
|
|
* Get current stack top item for player. |
90 |
|
|
* Returns NULL if no stacked item. |
91 |
|
|
* If stacked item disappeared (freed), remove it. |
92 |
|
|
* |
93 |
|
|
* Ryo, august 2004 |
94 |
|
|
*/ |
95 |
|
|
static object * |
96 |
|
|
dm_stack_peek (player *pl) |
97 |
|
|
{ |
98 |
|
|
object *ob; |
99 |
|
|
|
100 |
|
|
if (!pl->stack_position) |
101 |
|
|
{ |
102 |
|
|
new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!"); |
103 |
|
|
return NULL; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
ob = find_object (pl->stack_items[pl->stack_position - 1]); |
107 |
|
|
if (!ob) |
108 |
|
|
{ |
109 |
|
|
new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!"); |
110 |
|
|
dm_stack_pop (pl); |
111 |
|
|
return NULL; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
return ob; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
/** |
118 |
|
|
* Push specified item on player stack. |
119 |
|
|
* Inform player of position. |
120 |
|
|
* Initializes variables if needed. |
121 |
|
|
*/ |
122 |
|
|
void |
123 |
|
|
dm_stack_push (player *pl, tag_t item) |
124 |
|
|
{ |
125 |
|
|
if (!pl->stack_items) |
126 |
|
|
{ |
127 |
|
|
pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE); |
128 |
|
|
memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
if (pl->stack_position == STACK_SIZE) |
132 |
|
|
{ |
133 |
|
|
new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!"); |
134 |
|
|
return; |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
pl->stack_items[pl->stack_position] = item; |
138 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position); |
139 |
|
|
pl->stack_position++; |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
/** |
143 |
|
|
* Checks 'params' for object code. |
144 |
|
|
* |
145 |
|
|
* Can be: |
146 |
|
|
* * empty => get current object stack top for player |
147 |
|
|
* * number => get item with that tag, stack it for future use |
148 |
|
|
* * $number => get specified stack item |
149 |
|
|
* * "me" => player himself |
150 |
|
|
* |
151 |
|
|
* At function exit, params points to first non-object char |
152 |
|
|
* |
153 |
|
|
* 'from', if not NULL, contains at exit: |
154 |
|
|
* * STACK_FROM_NONE => object not found |
155 |
|
|
* * STACK_FROM_TOP => top item stack, may be NULL if stack was empty |
156 |
|
|
* * STACK_FROM_STACK => item from somewhere in the stack |
157 |
|
|
* * STACK_FROM_NUMBER => item by number, pushed on stack |
158 |
|
|
* |
159 |
|
|
* Ryo, august 2004 |
160 |
|
|
*/ |
161 |
|
|
static object * |
162 |
|
|
get_dm_object (player *pl, char **params, int *from) |
163 |
|
|
{ |
164 |
|
|
int item_tag, item_position; |
165 |
|
|
object *ob; |
166 |
|
|
|
167 |
|
|
if (!pl) |
168 |
|
|
return NULL; |
169 |
|
|
|
170 |
|
|
if (!params || !*params || **params == '\0') |
171 |
|
|
{ |
172 |
|
|
if (from) |
173 |
|
|
*from = STACK_FROM_TOP; |
174 |
|
|
/* No parameter => get stack item */ |
175 |
|
|
return dm_stack_peek (pl); |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
/* Let's clean white spaces */ |
179 |
|
|
while (**params == ' ') |
180 |
|
|
(*params)++; |
181 |
|
|
|
182 |
|
|
/* Next case: number => item tag */ |
183 |
|
|
if (sscanf (*params, "%d", &item_tag)) |
184 |
|
|
{ |
185 |
|
|
/* Move parameter to next item */ |
186 |
|
|
while (isdigit (**params)) |
187 |
|
|
(*params)++; |
188 |
|
|
|
189 |
|
|
/* And skip blanks, too */ |
190 |
|
|
while (**params == ' ') |
191 |
|
|
(*params)++; |
192 |
|
|
|
193 |
|
|
/* Get item */ |
194 |
|
|
ob = find_object (item_tag); |
195 |
|
|
if (!ob) |
196 |
|
|
{ |
197 |
|
|
if (from) |
198 |
|
|
*from = STACK_FROM_NONE; |
199 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag); |
200 |
|
|
return NULL; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
/* Got one, let's push it on stack */ |
204 |
|
|
dm_stack_push (pl, item_tag); |
205 |
|
|
if (from) |
206 |
|
|
*from = STACK_FROM_NUMBER; |
207 |
|
|
return ob; |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
/* Next case: $number => stack item */ |
211 |
|
|
if (sscanf (*params, "$%d", &item_position)) |
212 |
|
|
{ |
213 |
|
|
/* Move parameter to next item */ |
214 |
|
|
(*params)++; |
215 |
|
|
|
216 |
|
|
while (isdigit (**params)) |
217 |
|
|
(*params)++; |
218 |
|
|
while (**params == ' ') |
219 |
|
|
(*params)++; |
220 |
|
|
|
221 |
|
|
if (item_position >= pl->stack_position) |
222 |
|
|
{ |
223 |
|
|
if (from) |
224 |
|
|
*from = STACK_FROM_NONE; |
225 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position); |
226 |
|
|
return NULL; |
227 |
|
|
} |
228 |
|
|
|
229 |
|
|
ob = find_object (pl->stack_items[item_position]); |
230 |
|
|
if (!ob) |
231 |
|
|
{ |
232 |
|
|
if (from) |
233 |
|
|
*from = STACK_FROM_NONE; |
234 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position); |
235 |
|
|
return NULL; |
236 |
|
|
} |
237 |
|
|
|
238 |
|
|
if (from) |
239 |
|
|
*from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP; |
240 |
|
|
return ob; |
241 |
|
|
} |
242 |
|
|
|
243 |
|
|
/* Next case: 'me' => return pl->ob */ |
244 |
|
|
if (!strncmp (*params, "me", 2)) |
245 |
|
|
{ |
246 |
|
|
if (from) |
247 |
|
|
*from = STACK_FROM_NUMBER; |
248 |
|
|
dm_stack_push (pl, pl->ob->count); |
249 |
|
|
|
250 |
|
|
/* Skip to next token */ |
251 |
|
|
(*params) += 2; |
252 |
|
|
while (**params == ' ') |
253 |
|
|
(*params)++; |
254 |
|
|
|
255 |
|
|
return pl->ob; |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
/* Last case: get stack top */ |
259 |
|
|
if (from) |
260 |
|
|
*from = STACK_FROM_TOP; |
261 |
|
|
return dm_stack_peek (pl); |
262 |
|
|
} |
263 |
|
|
|
264 |
elmex |
1.1 |
/** |
265 |
|
|
* This finds and returns the object which matches the name or |
266 |
|
|
* object nubmer (specified via num #whatever). |
267 |
|
|
*/ |
268 |
root |
1.8 |
static object * |
269 |
|
|
find_object_both (char *params) |
270 |
|
|
{ |
271 |
|
|
if (!params) |
272 |
|
|
return NULL; |
273 |
root |
1.9 |
|
274 |
root |
1.8 |
if (params[0] == '#') |
275 |
|
|
return find_object (atol (params + 1)); |
276 |
|
|
else |
277 |
|
|
return find_object_name (params); |
278 |
elmex |
1.1 |
} |
279 |
|
|
|
280 |
|
|
/** |
281 |
|
|
* Sets the god for some objects. params should contain two values - |
282 |
|
|
* first the object to change, followed by the god to change it to. |
283 |
|
|
*/ |
284 |
root |
1.8 |
int |
285 |
|
|
command_setgod (object *op, char *params) |
286 |
|
|
{ |
287 |
|
|
object *ob, *god; |
288 |
|
|
char *str; |
289 |
elmex |
1.1 |
|
290 |
root |
1.8 |
if (!params || !(str = strchr (params, ' '))) |
291 |
|
|
{ |
292 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: setgod object god"); |
293 |
|
|
return 0; |
294 |
elmex |
1.1 |
} |
295 |
|
|
|
296 |
root |
1.8 |
/* kill the space, and set string to the next param */ |
297 |
|
|
*str++ = '\0'; |
298 |
|
|
if (!(ob = find_object_both (params))) |
299 |
|
|
{ |
300 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "Set whose god - can not find object %s?", params); |
301 |
|
|
return 1; |
302 |
elmex |
1.1 |
} |
303 |
|
|
|
304 |
root |
1.8 |
/* |
305 |
|
|
* Perhaps this is overly restrictive? Should we perhaps be able |
306 |
|
|
* to rebless altars and the like? |
307 |
|
|
*/ |
308 |
|
|
if (ob->type != PLAYER) |
309 |
|
|
{ |
310 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "%s is not a player - can not change its god", &ob->name); |
311 |
|
|
return 1; |
312 |
elmex |
1.1 |
} |
313 |
|
|
|
314 |
root |
1.8 |
god = find_god (str); |
315 |
|
|
if (god == NULL) |
316 |
|
|
{ |
317 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); |
318 |
|
|
return 1; |
319 |
elmex |
1.1 |
} |
320 |
|
|
|
321 |
root |
1.83 |
ob->become_follower (god); |
322 |
root |
1.8 |
return 1; |
323 |
elmex |
1.1 |
} |
324 |
|
|
|
325 |
|
|
int |
326 |
root |
1.8 |
command_freeze (object *op, char *params) |
327 |
elmex |
1.1 |
{ |
328 |
root |
1.8 |
int ticks; |
329 |
|
|
player *pl; |
330 |
elmex |
1.1 |
|
331 |
root |
1.8 |
if (!params) |
332 |
|
|
{ |
333 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: freeze [ticks] <player>."); |
334 |
|
|
return 1; |
335 |
|
|
} |
336 |
elmex |
1.1 |
|
337 |
root |
1.8 |
ticks = atoi (params); |
338 |
|
|
if (ticks) |
339 |
|
|
{ |
340 |
|
|
while ((isdigit (*params) || isspace (*params)) && *params != 0) |
341 |
|
|
params++; |
342 |
|
|
if (*params == 0) |
343 |
|
|
{ |
344 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: freeze [ticks] <player>."); |
345 |
|
|
return 1; |
346 |
elmex |
1.1 |
} |
347 |
|
|
} |
348 |
root |
1.8 |
else |
349 |
|
|
ticks = 100; |
350 |
elmex |
1.1 |
|
351 |
root |
1.8 |
pl = get_other_player_from_name (op, params); |
352 |
|
|
if (!pl) |
353 |
elmex |
1.1 |
return 1; |
354 |
root |
1.8 |
|
355 |
|
|
new_draw_info (NDI_UNIQUE | NDI_RED, 0, pl->ob, "You have been frozen by the DM!"); |
356 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "You freeze %s for %d ticks", &pl->ob->name, ticks); |
357 |
|
|
pl->ob->speed_left = -(pl->ob->speed * ticks); |
358 |
|
|
return 0; |
359 |
elmex |
1.1 |
} |
360 |
|
|
|
361 |
root |
1.8 |
int |
362 |
|
|
command_arrest (object *op, char *params) |
363 |
|
|
{ |
364 |
|
|
object *dummy; |
365 |
|
|
player *pl; |
366 |
|
|
|
367 |
|
|
if (!op) |
368 |
elmex |
1.1 |
return 0; |
369 |
root |
1.28 |
|
370 |
root |
1.8 |
if (params == NULL) |
371 |
|
|
{ |
372 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: arrest <player>."); |
373 |
|
|
return 1; |
374 |
|
|
} |
375 |
root |
1.28 |
|
376 |
root |
1.8 |
pl = get_other_player_from_name (op, params); |
377 |
|
|
if (!pl) |
378 |
|
|
return 1; |
379 |
root |
1.28 |
|
380 |
root |
1.8 |
dummy = get_jail_exit (pl->ob); |
381 |
|
|
if (!dummy) |
382 |
|
|
{ |
383 |
|
|
/* we have nowhere to send the prisoner.... */ |
384 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "can't jail player, there is no map to hold them"); |
385 |
|
|
return 0; |
386 |
|
|
} |
387 |
root |
1.28 |
|
388 |
root |
1.57 |
pl->ob->player_goto (dummy->slaying, dummy->stats.hp, dummy->stats.sp);//TODO |
389 |
root |
1.60 |
dummy->destroy (); |
390 |
root |
1.59 |
|
391 |
root |
1.8 |
new_draw_info (NDI_UNIQUE, 0, pl->ob, "You have been arrested."); |
392 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
393 |
|
|
LOG (llevInfo, "Player %s arrested by %s\n", &pl->ob->name, &op->name); |
394 |
|
|
return 1; |
395 |
elmex |
1.1 |
} |
396 |
|
|
|
397 |
root |
1.8 |
int |
398 |
|
|
command_summon (object *op, char *params) |
399 |
|
|
{ |
400 |
|
|
int i; |
401 |
|
|
player *pl; |
402 |
|
|
|
403 |
|
|
if (!op) |
404 |
|
|
return 0; |
405 |
|
|
|
406 |
|
|
if (params == NULL) |
407 |
|
|
{ |
408 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: summon <player>."); |
409 |
|
|
return 1; |
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
pl = get_other_player_from_name (op, params); |
413 |
|
|
if (!pl) |
414 |
elmex |
1.1 |
return 1; |
415 |
|
|
|
416 |
root |
1.85 |
maptile *m = op->map; |
417 |
|
|
sint16 nx = op->x; |
418 |
|
|
sint16 ny = op->y; |
419 |
|
|
|
420 |
|
|
i = find_free_spot (op, m, nx, ny, 1, SIZEOFFREE1+1); |
421 |
root |
1.8 |
if (i == -1) |
422 |
|
|
{ |
423 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
424 |
|
|
return 1; |
425 |
|
|
} |
426 |
|
|
|
427 |
root |
1.85 |
nx += freearr_x [i]; |
428 |
|
|
ny += freearr_y [i]; |
429 |
|
|
|
430 |
|
|
if (!xy_normalise (m, nx, ny)) |
431 |
|
|
{ |
432 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
433 |
|
|
return 1; |
434 |
|
|
} |
435 |
|
|
|
436 |
|
|
pl->ob->player_goto (m->path, nx, ny); |
437 |
root |
1.8 |
new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
438 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
439 |
elmex |
1.1 |
|
440 |
root |
1.8 |
return 1; |
441 |
elmex |
1.1 |
} |
442 |
|
|
|
443 |
|
|
/** |
444 |
|
|
* This function is a real mess, because we're stucking getting |
445 |
|
|
* the entire item description in one block of text, so we just |
446 |
|
|
* can't simply parse it - we need to look for double quotes |
447 |
|
|
* for example. This could actually get much simpler with just a |
448 |
|
|
* little help from the client - if we could get line breaks, it |
449 |
|
|
* makes parsing much easier, eg, something like: |
450 |
|
|
* arch dragon |
451 |
|
|
* name big nasty creature |
452 |
|
|
* hp 5 |
453 |
|
|
* sp 30 |
454 |
|
|
* Is much easier to parse than |
455 |
|
|
* dragon name "big nasty creature" hp 5 sp 30 |
456 |
|
|
* for example. |
457 |
|
|
*/ |
458 |
root |
1.8 |
int |
459 |
|
|
command_create (object *op, char *params) |
460 |
|
|
{ |
461 |
|
|
object *tmp = NULL; |
462 |
|
|
int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
463 |
root |
1.88 |
char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline; |
464 |
root |
1.8 |
archetype *at, *at_spell = NULL; |
465 |
|
|
artifact *art = NULL; |
466 |
|
|
|
467 |
|
|
if (!op) |
468 |
|
|
return 0; |
469 |
|
|
|
470 |
|
|
if (params == NULL) |
471 |
|
|
{ |
472 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]"); |
473 |
|
|
return 1; |
474 |
|
|
} |
475 |
root |
1.9 |
|
476 |
root |
1.8 |
bp = params; |
477 |
|
|
|
478 |
|
|
/* We need to know where the line ends */ |
479 |
|
|
endline = bp + strlen (bp); |
480 |
|
|
|
481 |
|
|
if (sscanf (bp, "%d ", &nrof)) |
482 |
|
|
{ |
483 |
|
|
if ((bp = strchr (params, ' ')) == NULL) |
484 |
|
|
{ |
485 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]"); |
486 |
|
|
return 1; |
487 |
|
|
} |
488 |
|
|
bp++; |
489 |
|
|
set_nrof = 1; |
490 |
|
|
LOG (llevDebug, "%s creates: (%d) %s\n", &op->name, nrof, bp); |
491 |
|
|
} |
492 |
root |
1.9 |
|
493 |
root |
1.8 |
if (sscanf (bp, "%d ", &magic)) |
494 |
|
|
{ |
495 |
|
|
if ((bp = strchr (bp, ' ')) == NULL) |
496 |
|
|
{ |
497 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: create [nr] [magic] <archetype> [ of <artifact>]" " [variable_to_patch setting]"); |
498 |
|
|
return 1; |
499 |
|
|
} |
500 |
root |
1.9 |
|
501 |
root |
1.8 |
bp++; |
502 |
|
|
set_magic = 1; |
503 |
|
|
LOG (llevDebug, "%s creates: (%d) (%d) %s\n", &op->name, nrof, magic, bp); |
504 |
|
|
} |
505 |
root |
1.9 |
|
506 |
root |
1.8 |
if ((cp = strstr (bp, " of ")) != NULL) |
507 |
|
|
{ |
508 |
|
|
*cp = '\0'; |
509 |
|
|
cp += 4; |
510 |
|
|
} |
511 |
root |
1.9 |
|
512 |
root |
1.8 |
for (bp2 = bp; *bp2; bp2++) |
513 |
|
|
{ |
514 |
|
|
if (*bp2 == ' ') |
515 |
|
|
{ |
516 |
|
|
*bp2 = '\0'; |
517 |
|
|
bp2++; |
518 |
|
|
break; |
519 |
|
|
} |
520 |
|
|
} |
521 |
|
|
|
522 |
root |
1.11 |
if ((at = archetype::find (bp)) == NULL) |
523 |
root |
1.8 |
{ |
524 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "No such archetype."); |
525 |
|
|
return 1; |
526 |
|
|
} |
527 |
|
|
|
528 |
|
|
if (cp) |
529 |
|
|
{ |
530 |
|
|
char spell_name[MAX_BUF], *fsp = NULL; |
531 |
|
|
|
532 |
|
|
/* |
533 |
|
|
* Try to find a spell object for this. Note that |
534 |
|
|
* we also set up spell_name which is only |
535 |
|
|
* the first word. |
536 |
|
|
*/ |
537 |
|
|
|
538 |
root |
1.11 |
at_spell = archetype::find (cp); |
539 |
root |
1.47 |
if (!at_spell || at_spell->type != SPELL) |
540 |
root |
1.8 |
at_spell = find_archetype_by_object_name (cp); |
541 |
root |
1.47 |
if (!at_spell || at_spell->type != SPELL) |
542 |
root |
1.8 |
{ |
543 |
root |
1.34 |
assign (spell_name, cp); |
544 |
root |
1.8 |
fsp = strchr (spell_name, ' '); |
545 |
|
|
if (fsp) |
546 |
|
|
{ |
547 |
|
|
*fsp = 0; |
548 |
|
|
fsp++; |
549 |
root |
1.11 |
at_spell = archetype::find (spell_name); |
550 |
root |
1.8 |
|
551 |
|
|
/* Got a spell, update the first string pointer */ |
552 |
root |
1.47 |
if (at_spell && at_spell->type == SPELL) |
553 |
root |
1.8 |
bp2 = cp + strlen (spell_name) + 1; |
554 |
|
|
else |
555 |
|
|
at_spell = NULL; |
556 |
elmex |
1.1 |
} |
557 |
|
|
} |
558 |
|
|
|
559 |
root |
1.8 |
/* OK - we didn't find a spell - presume the 'of' |
560 |
|
|
* in this case means its an artifact. |
561 |
|
|
*/ |
562 |
|
|
if (!at_spell) |
563 |
|
|
{ |
564 |
root |
1.47 |
if (find_artifactlist (at->type) == NULL) |
565 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "No artifact list for type %d\n", at->type); |
566 |
root |
1.8 |
else |
567 |
|
|
{ |
568 |
root |
1.47 |
art = find_artifactlist (at->type)->items; |
569 |
root |
1.8 |
|
570 |
root |
1.42 |
while (art) |
571 |
root |
1.8 |
{ |
572 |
root |
1.66 |
if (!strcmp (&art->item->name, cp)) |
573 |
root |
1.8 |
break; |
574 |
root |
1.42 |
|
575 |
root |
1.8 |
art = art->next; |
576 |
|
|
} |
577 |
root |
1.9 |
|
578 |
root |
1.8 |
if (!art) |
579 |
root |
1.47 |
new_draw_info_format (NDI_UNIQUE, 0, op, "No such artifact ([%d] of %s)", at->type, cp); |
580 |
elmex |
1.1 |
} |
581 |
root |
1.9 |
|
582 |
root |
1.8 |
LOG (llevDebug, "%s creates: (%d) (%d) (%s) of (%s)\n", &op->name, set_nrof ? nrof : 0, set_magic ? magic : 0, bp, cp); |
583 |
elmex |
1.1 |
} |
584 |
root |
1.8 |
} /* if cp */ |
585 |
|
|
|
586 |
root |
1.47 |
if ((at->type == ROD || at->type == WAND || at->type == SCROLL || |
587 |
|
|
at->type == HORN || at->type == SPELLBOOK) && !at_spell) |
588 |
root |
1.8 |
{ |
589 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find spell %s for object that needs it, or it is of wrong type", cp); |
590 |
|
|
return 1; |
591 |
|
|
} |
592 |
elmex |
1.1 |
|
593 |
root |
1.8 |
/* |
594 |
|
|
* Rather than have two different blocks with a lot of similar code, |
595 |
|
|
* just create one object, do all the processing, and then determine |
596 |
|
|
* if that one object should be inserted or if we need to make copies. |
597 |
|
|
*/ |
598 |
root |
1.79 |
tmp = at->instance (); |
599 |
root |
1.9 |
|
600 |
root |
1.8 |
if (set_magic) |
601 |
|
|
set_abs_magic (tmp, magic); |
602 |
root |
1.9 |
|
603 |
root |
1.8 |
if (art) |
604 |
|
|
give_artifact_abilities (tmp, art->item); |
605 |
root |
1.9 |
|
606 |
root |
1.84 |
if (tmp->need_identify ()) |
607 |
root |
1.8 |
{ |
608 |
root |
1.82 |
tmp->set_flag (FLAG_IDENTIFIED); |
609 |
|
|
tmp->clr_flag (FLAG_KNOWN_MAGICAL); |
610 |
root |
1.8 |
} |
611 |
|
|
|
612 |
|
|
/* |
613 |
|
|
* This entire block here tries to find variable pairings, |
614 |
|
|
* eg, 'hp 4' or the like. The mess here is that values |
615 |
|
|
* can be quoted (eg "my cool sword"); So the basic logic |
616 |
|
|
* is we want to find two spaces, but if we got a quote, |
617 |
|
|
* any spaces there don't count. |
618 |
|
|
*/ |
619 |
|
|
while (*bp2 && bp2 <= endline) |
620 |
|
|
{ |
621 |
|
|
gotspace = 0; |
622 |
|
|
gotquote = 0; |
623 |
root |
1.9 |
|
624 |
root |
1.8 |
/* find the first quote */ |
625 |
|
|
for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) |
626 |
|
|
{ |
627 |
|
|
|
628 |
|
|
/* Found a quote - now lets find the second one */ |
629 |
|
|
if (*bp3 == '"') |
630 |
|
|
{ |
631 |
|
|
*bp3 = ' '; |
632 |
|
|
bp2 = bp3 + 1; /* Update start of string */ |
633 |
|
|
bp3++; |
634 |
|
|
gotquote++; |
635 |
|
|
while (*bp3) |
636 |
|
|
{ |
637 |
|
|
if (*bp3 == '"') |
638 |
|
|
{ |
639 |
|
|
*bp3 = '\0'; |
640 |
|
|
gotquote++; |
641 |
|
|
} |
642 |
|
|
else |
643 |
|
|
bp3++; |
644 |
elmex |
1.1 |
} |
645 |
root |
1.8 |
} |
646 |
|
|
else if (*bp3 == ' ') |
647 |
root |
1.9 |
gotspace++; |
648 |
elmex |
1.1 |
} |
649 |
|
|
|
650 |
root |
1.8 |
/* |
651 |
|
|
* If we got two spaces, send the second one to null. |
652 |
|
|
* if we've reached the end of the line, increase gotspace - |
653 |
|
|
* this is perfectly valid for the list entry listed. |
654 |
|
|
*/ |
655 |
|
|
if (gotspace == 2 || gotquote == 2) |
656 |
|
|
{ |
657 |
|
|
bp3--; /* Undo the extra increment */ |
658 |
|
|
*bp3 = '\0'; |
659 |
|
|
} |
660 |
|
|
else if (*bp3 == '\0') |
661 |
|
|
gotspace++; |
662 |
|
|
|
663 |
|
|
if ((gotquote && gotquote != 2) || (gotspace != 2 && gotquote != 2)) |
664 |
|
|
{ |
665 |
|
|
/* |
666 |
|
|
* Unfortunately, we've clobbered lots of values, so printing |
667 |
|
|
* out what we have probably isn't useful. Break out, because |
668 |
|
|
* trying to recover is probably won't get anything useful |
669 |
|
|
* anyways, and we'd be confused about end of line pointers |
670 |
|
|
* anyways. |
671 |
|
|
*/ |
672 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "Malformed create line: %s", bp2); |
673 |
|
|
break; |
674 |
|
|
} |
675 |
root |
1.9 |
|
676 |
root |
1.8 |
/* bp2 should still point to the start of this line, |
677 |
|
|
* with bp3 pointing to the end |
678 |
|
|
*/ |
679 |
|
|
if (set_variable (tmp, bp2) == -1) |
680 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", bp2); |
681 |
|
|
else |
682 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s", &tmp->name, tmp->count, bp2); |
683 |
root |
1.9 |
|
684 |
root |
1.8 |
bp2 = bp3 + 1; |
685 |
|
|
} |
686 |
|
|
|
687 |
root |
1.47 |
if (at->nrof) |
688 |
root |
1.8 |
{ |
689 |
|
|
if (at_spell) |
690 |
root |
1.79 |
tmp->insert (at_spell->instance ()); |
691 |
root |
1.8 |
|
692 |
root |
1.54 |
tmp->x = op->x; |
693 |
|
|
tmp->y = op->y; |
694 |
|
|
tmp->map = op->map; |
695 |
root |
1.9 |
|
696 |
root |
1.8 |
if (set_nrof) |
697 |
|
|
tmp->nrof = nrof; |
698 |
root |
1.9 |
|
699 |
root |
1.54 |
op->insert (tmp); |
700 |
root |
1.8 |
|
701 |
|
|
/* Let's put this created item on stack so dm can access it easily. */ |
702 |
|
|
dm_stack_push (op->contr, tmp->count); |
703 |
|
|
|
704 |
|
|
return 1; |
705 |
|
|
} |
706 |
|
|
else |
707 |
|
|
{ |
708 |
|
|
for (i = 0; i < (set_nrof ? nrof : 1); i++) |
709 |
|
|
{ |
710 |
root |
1.10 |
object *prev = 0, *head = 0; |
711 |
root |
1.8 |
|
712 |
root |
1.48 |
for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
713 |
root |
1.8 |
{ |
714 |
root |
1.79 |
object *dup = atmp->instance (); |
715 |
root |
1.8 |
|
716 |
|
|
if (at_spell) |
717 |
root |
1.79 |
insert_ob_in_ob (at_spell->instance (), dup); |
718 |
root |
1.8 |
|
719 |
|
|
/* |
720 |
|
|
* The head is what contains all the important bits, |
721 |
|
|
* so just copying it over should be fine. |
722 |
|
|
*/ |
723 |
root |
1.10 |
if (!head) |
724 |
root |
1.8 |
{ |
725 |
|
|
head = dup; |
726 |
root |
1.22 |
tmp->copy_to (dup); |
727 |
elmex |
1.1 |
} |
728 |
root |
1.9 |
|
729 |
root |
1.47 |
dup->x = op->x + dup->arch->x; |
730 |
|
|
dup->y = op->y + dup->arch->y; |
731 |
root |
1.8 |
dup->map = op->map; |
732 |
|
|
|
733 |
|
|
if (head != dup) |
734 |
|
|
{ |
735 |
|
|
dup->head = head; |
736 |
|
|
prev->more = dup; |
737 |
elmex |
1.1 |
} |
738 |
root |
1.9 |
|
739 |
root |
1.8 |
prev = dup; |
740 |
elmex |
1.1 |
} |
741 |
|
|
|
742 |
root |
1.82 |
if (head->flag [FLAG_ALIVE]) |
743 |
root |
1.8 |
{ |
744 |
|
|
object *check = head; |
745 |
|
|
int size_x = 0; |
746 |
|
|
int size_y = 0; |
747 |
|
|
|
748 |
|
|
while (check) |
749 |
|
|
{ |
750 |
root |
1.77 |
size_x = max (size_x, check->arch->x); |
751 |
|
|
size_y = max (size_y, check->arch->y); |
752 |
root |
1.8 |
check = check->more; |
753 |
elmex |
1.1 |
} |
754 |
|
|
|
755 |
root |
1.8 |
if (out_of_map (op->map, head->x + size_x, head->y + size_y)) |
756 |
|
|
{ |
757 |
|
|
if (head->x < size_x || head->y < size_y) |
758 |
|
|
{ |
759 |
|
|
dm_stack_pop (op->contr); |
760 |
root |
1.60 |
head->destroy (); |
761 |
root |
1.8 |
new_draw_info (NDI_UNIQUE, 0, op, "Object too big to insert in map, or wrong position."); |
762 |
root |
1.60 |
tmp->destroy (); |
763 |
root |
1.8 |
return 1; |
764 |
elmex |
1.1 |
} |
765 |
|
|
|
766 |
root |
1.8 |
check = head; |
767 |
root |
1.9 |
|
768 |
root |
1.8 |
while (check) |
769 |
|
|
{ |
770 |
|
|
check->x -= size_x; |
771 |
|
|
check->y -= size_y; |
772 |
|
|
check = check->more; |
773 |
elmex |
1.1 |
} |
774 |
|
|
} |
775 |
|
|
|
776 |
root |
1.8 |
insert_ob_in_map (head, op->map, op, 0); |
777 |
|
|
} |
778 |
|
|
else |
779 |
|
|
head = insert_ob_in_ob (head, op); |
780 |
|
|
|
781 |
|
|
/* Let's put this created item on stack so dm can access it easily. */ |
782 |
|
|
/* Wonder if we really want to push all of these, but since |
783 |
|
|
* things like rods have nrof 0, we want to cover those. |
784 |
|
|
*/ |
785 |
|
|
dm_stack_push (op->contr, head->count); |
786 |
|
|
|
787 |
root |
1.54 |
if (at->randomitems && !at_spell) |
788 |
root |
1.47 |
create_treasure (at->randomitems, head, GT_APPLY, op->map->difficulty, 0); |
789 |
elmex |
1.1 |
} |
790 |
|
|
|
791 |
root |
1.8 |
/* free the one we used to copy */ |
792 |
root |
1.60 |
tmp->destroy (); |
793 |
elmex |
1.1 |
} |
794 |
|
|
|
795 |
root |
1.8 |
return 1; |
796 |
elmex |
1.1 |
} |
797 |
|
|
|
798 |
|
|
/* |
799 |
|
|
* Now follows dm-commands which are also acceptable from sockets |
800 |
|
|
*/ |
801 |
|
|
|
802 |
root |
1.8 |
int |
803 |
|
|
command_inventory (object *op, char *params) |
804 |
|
|
{ |
805 |
root |
1.52 |
int i; |
806 |
root |
1.8 |
object *tmp; |
807 |
elmex |
1.1 |
|
808 |
root |
1.52 |
if (!params || !sscanf (params, "%d", &i) || !(tmp = find_object (i))) |
809 |
root |
1.8 |
{ |
810 |
root |
1.52 |
op->contr->failmsg ("Inventory of what object (nr)?"); |
811 |
|
|
return 1; |
812 |
elmex |
1.1 |
} |
813 |
|
|
|
814 |
root |
1.52 |
op->contr->infobox (MSG_CHANNEL ("examine"), tmp->query_inventory (op)); |
815 |
elmex |
1.1 |
|
816 |
root |
1.8 |
return 1; |
817 |
elmex |
1.1 |
} |
818 |
|
|
|
819 |
|
|
/* just show player's their skills for now. Dm's can |
820 |
|
|
* already see skills w/ inventory command - b.t. |
821 |
|
|
*/ |
822 |
|
|
|
823 |
root |
1.8 |
int |
824 |
|
|
command_skills (object *op, char *params) |
825 |
|
|
{ |
826 |
|
|
show_skills (op, params); |
827 |
|
|
return 0; |
828 |
elmex |
1.1 |
} |
829 |
|
|
|
830 |
root |
1.8 |
int |
831 |
|
|
command_dump (object *op, char *params) |
832 |
|
|
{ |
833 |
|
|
object *tmp; |
834 |
elmex |
1.1 |
|
835 |
root |
1.8 |
tmp = get_dm_object (op->contr, ¶ms, NULL); |
836 |
|
|
if (!tmp) |
837 |
elmex |
1.1 |
return 1; |
838 |
root |
1.8 |
|
839 |
root |
1.16 |
char *dump = dump_object (tmp); |
840 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, dump); |
841 |
|
|
free (dump); |
842 |
|
|
|
843 |
root |
1.82 |
if (tmp->flag [FLAG_OBJ_ORIGINAL]) |
844 |
root |
1.8 |
new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); |
845 |
root |
1.16 |
|
846 |
root |
1.8 |
return 1; |
847 |
elmex |
1.1 |
} |
848 |
|
|
|
849 |
root |
1.8 |
int |
850 |
|
|
command_patch (object *op, char *params) |
851 |
|
|
{ |
852 |
|
|
char *arg, *arg2; |
853 |
|
|
object *tmp; |
854 |
|
|
|
855 |
|
|
tmp = get_dm_object (op->contr, ¶ms, NULL); |
856 |
|
|
if (!tmp) |
857 |
|
|
/* Player already informed of failure */ |
858 |
elmex |
1.1 |
return 1; |
859 |
|
|
|
860 |
root |
1.8 |
/* params set to first value by get_dm_default */ |
861 |
|
|
arg = params; |
862 |
|
|
if (arg == NULL) |
863 |
|
|
{ |
864 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Patch what values?"); |
865 |
elmex |
1.1 |
return 1; |
866 |
|
|
} |
867 |
|
|
|
868 |
root |
1.8 |
if ((arg2 = strchr (arg, ' '))) |
869 |
|
|
arg2++; |
870 |
root |
1.43 |
|
871 |
root |
1.8 |
if (set_variable (tmp, arg) == -1) |
872 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "Unknown variable %s", arg); |
873 |
|
|
else |
874 |
root |
1.43 |
new_draw_info_format (NDI_UNIQUE, 0, op, "(%s#%d)->%s=%s", &tmp->name, tmp->count, arg, arg2); |
875 |
elmex |
1.1 |
|
876 |
root |
1.8 |
return 1; |
877 |
|
|
} |
878 |
elmex |
1.1 |
|
879 |
root |
1.8 |
int |
880 |
|
|
command_remove (object *op, char *params) |
881 |
|
|
{ |
882 |
|
|
object *tmp; |
883 |
|
|
int from; |
884 |
elmex |
1.1 |
|
885 |
root |
1.8 |
tmp = get_dm_object (op->contr, ¶ms, &from); |
886 |
|
|
if (!tmp) |
887 |
|
|
{ |
888 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Remove what object (nr)?"); |
889 |
|
|
return 1; |
890 |
elmex |
1.1 |
} |
891 |
|
|
|
892 |
root |
1.8 |
if (tmp->type == PLAYER) |
893 |
|
|
{ |
894 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
895 |
|
|
return 1; |
896 |
elmex |
1.1 |
} |
897 |
|
|
|
898 |
root |
1.82 |
if (tmp->flag [FLAG_REMOVED]) |
899 |
root |
1.8 |
{ |
900 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); |
901 |
|
|
return 1; |
902 |
elmex |
1.1 |
} |
903 |
|
|
|
904 |
root |
1.8 |
if (from != STACK_FROM_STACK) |
905 |
|
|
/* Item is either stack top, or is a number thus is now stack top, let's remove it */ |
906 |
|
|
dm_stack_pop (op->contr); |
907 |
|
|
|
908 |
|
|
/* Always work on the head - otherwise object will get in odd state */ |
909 |
|
|
if (tmp->head) |
910 |
|
|
tmp = tmp->head; |
911 |
root |
1.21 |
tmp->remove (); |
912 |
root |
1.8 |
return 1; |
913 |
elmex |
1.1 |
} |
914 |
|
|
|
915 |
root |
1.8 |
int |
916 |
|
|
command_free (object *op, char *params) |
917 |
|
|
{ |
918 |
|
|
object *tmp; |
919 |
|
|
int from; |
920 |
elmex |
1.1 |
|
921 |
root |
1.8 |
tmp = get_dm_object (op->contr, ¶ms, &from); |
922 |
elmex |
1.1 |
|
923 |
root |
1.8 |
if (!tmp) |
924 |
|
|
{ |
925 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Free what object (nr)?"); |
926 |
|
|
return 1; |
927 |
elmex |
1.1 |
} |
928 |
|
|
|
929 |
root |
1.8 |
if (from != STACK_FROM_STACK) |
930 |
|
|
/* Item is either stack top, or is a number thus is now stack top, let's remove it */ |
931 |
|
|
dm_stack_pop (op->contr); |
932 |
elmex |
1.1 |
|
933 |
root |
1.8 |
if (tmp->head) |
934 |
|
|
tmp = tmp->head; |
935 |
root |
1.22 |
|
936 |
root |
1.60 |
tmp->destroy (); |
937 |
root |
1.8 |
return 1; |
938 |
elmex |
1.1 |
} |
939 |
|
|
|
940 |
|
|
/** |
941 |
|
|
* This adds exp to a player. We now allow adding to a specific skill. |
942 |
|
|
*/ |
943 |
root |
1.8 |
int |
944 |
|
|
command_addexp (object *op, char *params) |
945 |
|
|
{ |
946 |
|
|
char buf[MAX_BUF], skill[MAX_BUF]; |
947 |
root |
1.50 |
int q; |
948 |
|
|
long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure |
949 |
root |
1.8 |
object *skillob = NULL; |
950 |
elmex |
1.1 |
|
951 |
root |
1.8 |
skill[0] = '\0'; |
952 |
root |
1.73 |
if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2)) |
953 |
root |
1.8 |
{ |
954 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); |
955 |
|
|
return 1; |
956 |
elmex |
1.1 |
} |
957 |
|
|
|
958 |
root |
1.27 |
for_all_players (pl) |
959 |
root |
1.8 |
if (!strncmp (pl->ob->name, buf, MAX_NAME)) |
960 |
root |
1.27 |
{ |
961 |
|
|
if (q >= 3) |
962 |
|
|
{ |
963 |
|
|
skillob = find_skill_by_name (pl->ob, skill); |
964 |
|
|
if (!skillob) |
965 |
|
|
{ |
966 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s in %s", skill, buf); |
967 |
|
|
return 1; |
968 |
|
|
} |
969 |
|
|
|
970 |
|
|
i = check_exp_adjust (skillob, i); |
971 |
|
|
skillob->stats.exp += i; |
972 |
|
|
calc_perm_exp (skillob); |
973 |
|
|
player_lvl_adj (pl->ob, skillob); |
974 |
|
|
} |
975 |
elmex |
1.1 |
|
976 |
root |
1.27 |
pl->ob->stats.exp += i; |
977 |
|
|
calc_perm_exp (pl->ob); |
978 |
|
|
player_lvl_adj (pl->ob, NULL); |
979 |
elmex |
1.1 |
|
980 |
root |
1.27 |
return 1; |
981 |
|
|
} |
982 |
elmex |
1.1 |
|
983 |
root |
1.27 |
new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
984 |
root |
1.8 |
return 1; |
985 |
elmex |
1.1 |
} |
986 |
|
|
|
987 |
|
|
/**************************************************************************/ |
988 |
root |
1.8 |
|
989 |
elmex |
1.1 |
/* Mods made by Tyler Van Gorder, May 10-13, 1992. */ |
990 |
root |
1.8 |
|
991 |
elmex |
1.1 |
/* CSUChico : tvangod@cscihp.ecst.csuchico.edu */ |
992 |
root |
1.8 |
|
993 |
elmex |
1.1 |
/**************************************************************************/ |
994 |
|
|
|
995 |
root |
1.8 |
int |
996 |
|
|
command_stats (object *op, char *params) |
997 |
|
|
{ |
998 |
|
|
char buf[MAX_BUF]; |
999 |
|
|
|
1000 |
sf-kernelpanic |
1.89 |
if (params == NULL || params[0] == '\0') |
1001 |
root |
1.8 |
{ |
1002 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
1003 |
|
|
return 1; |
1004 |
|
|
} |
1005 |
|
|
|
1006 |
root |
1.27 |
for_all_players (pl) |
1007 |
sf-kernelpanic |
1.89 |
if (!strcmp (&pl->ob->name, params)) |
1008 |
root |
1.8 |
{ |
1009 |
|
|
sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
1010 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1011 |
|
|
sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
1012 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1013 |
|
|
sprintf (buf, "Con : %-2d AC : %-4d WC : %d", pl->ob->stats.Con, pl->ob->stats.ac, pl->ob->stats.wc); |
1014 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1015 |
|
|
sprintf (buf, "Int : %-2d Damage : %d", pl->ob->stats.Int, pl->ob->stats.dam); |
1016 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1017 |
root |
1.20 |
sprintf (buf, "Wis : %-2d EXP : %" PRId64, pl->ob->stats.Wis, pl->ob->stats.exp); |
1018 |
root |
1.8 |
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1019 |
|
|
sprintf (buf, "Pow : %-2d Grace : %d", pl->ob->stats.Pow, pl->ob->stats.grace); |
1020 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1021 |
|
|
sprintf (buf, "Cha : %-2d Food : %d", pl->ob->stats.Cha, pl->ob->stats.food); |
1022 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1023 |
root |
1.27 |
return 1; |
1024 |
root |
1.8 |
} |
1025 |
root |
1.27 |
|
1026 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
1027 |
root |
1.8 |
return 1; |
1028 |
|
|
} |
1029 |
|
|
|
1030 |
|
|
int |
1031 |
|
|
command_abil (object *op, char *params) |
1032 |
|
|
{ |
1033 |
|
|
char thing[20], thing2[20]; |
1034 |
|
|
int iii; |
1035 |
|
|
char buf[MAX_BUF]; |
1036 |
|
|
|
1037 |
|
|
iii = 0; |
1038 |
|
|
thing[0] = '\0'; |
1039 |
|
|
thing2[0] = '\0'; |
1040 |
|
|
if (params == NULL || !sscanf (params, "%s %s %d", thing, thing2, &iii) || thing == NULL) |
1041 |
|
|
{ |
1042 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
1043 |
|
|
return 1; |
1044 |
|
|
} |
1045 |
|
|
|
1046 |
|
|
if (thing2 == NULL) |
1047 |
|
|
{ |
1048 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "You can't change that."); |
1049 |
|
|
return 1; |
1050 |
|
|
} |
1051 |
|
|
|
1052 |
|
|
if (iii < MIN_STAT || iii > MAX_STAT) |
1053 |
|
|
{ |
1054 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Illegal range of stat.\n"); |
1055 |
|
|
return 1; |
1056 |
|
|
} |
1057 |
|
|
|
1058 |
root |
1.27 |
for_all_players (pl) |
1059 |
root |
1.8 |
{ |
1060 |
root |
1.66 |
if (!strcmp (&pl->ob->name, thing)) |
1061 |
root |
1.8 |
{ |
1062 |
root |
1.43 |
if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; |
1063 |
|
|
if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; |
1064 |
|
|
if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; |
1065 |
|
|
if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; |
1066 |
|
|
if (!strcmp ("cha", thing2)) pl->ob->stats.Cha = iii, pl->orig_stats.Cha = iii; |
1067 |
|
|
if (!strcmp ("int", thing2)) pl->ob->stats.Int = iii, pl->orig_stats.Int = iii; |
1068 |
|
|
if (!strcmp ("pow", thing2)) pl->ob->stats.Pow = iii, pl->orig_stats.Pow = iii; |
1069 |
|
|
|
1070 |
root |
1.8 |
sprintf (buf, "%s has been altered.", &pl->ob->name); |
1071 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, buf); |
1072 |
root |
1.26 |
pl->ob->update_stats (); |
1073 |
root |
1.8 |
return 1; |
1074 |
elmex |
1.1 |
} |
1075 |
root |
1.8 |
} |
1076 |
|
|
|
1077 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "No such player."); |
1078 |
|
|
return 1; |
1079 |
elmex |
1.1 |
} |
1080 |
|
|
|
1081 |
root |
1.8 |
int |
1082 |
|
|
command_invisible (object *op, char *params) |
1083 |
|
|
{ |
1084 |
|
|
if (op) |
1085 |
|
|
{ |
1086 |
root |
1.92 |
op->invisible += TIME2TICK (60); |
1087 |
root |
1.41 |
update_object (op, UP_OBJ_CHANGE); |
1088 |
root |
1.8 |
new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); |
1089 |
elmex |
1.1 |
} |
1090 |
|
|
|
1091 |
root |
1.8 |
return 0; |
1092 |
elmex |
1.1 |
} |
1093 |
|
|
|
1094 |
|
|
/** |
1095 |
|
|
* Returns spell object (from archetypes) by name. |
1096 |
|
|
* Returns NULL if 0 or more than one spell matches. |
1097 |
|
|
* Used for wizard's learn spell/prayer. |
1098 |
|
|
* |
1099 |
|
|
* op is the player issuing the command. |
1100 |
|
|
*/ |
1101 |
root |
1.8 |
static object * |
1102 |
root |
1.66 |
get_spell_by_name (object *op, shstr_cmp spell_name) |
1103 |
root |
1.8 |
{ |
1104 |
root |
1.69 |
/* First check for full name matches. */ |
1105 |
|
|
int conflict_found = 0; |
1106 |
elmex |
1.78 |
archetype *found = 0; |
1107 |
|
|
|
1108 |
root |
1.47 |
for_all_archetypes (at) |
1109 |
root |
1.8 |
{ |
1110 |
root |
1.47 |
if (at->type != SPELL) |
1111 |
root |
1.8 |
continue; |
1112 |
|
|
|
1113 |
root |
1.66 |
if (at->object::name != spell_name) |
1114 |
root |
1.8 |
continue; |
1115 |
|
|
|
1116 |
root |
1.65 |
if (found) |
1117 |
root |
1.8 |
{ |
1118 |
|
|
if (!conflict_found) |
1119 |
|
|
{ |
1120 |
|
|
conflict_found = 1; |
1121 |
root |
1.67 |
new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name); |
1122 |
root |
1.46 |
new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); |
1123 |
elmex |
1.1 |
} |
1124 |
root |
1.46 |
|
1125 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); |
1126 |
root |
1.69 |
return 0; |
1127 |
elmex |
1.1 |
} |
1128 |
|
|
|
1129 |
root |
1.46 |
found = at; |
1130 |
elmex |
1.1 |
} |
1131 |
|
|
|
1132 |
root |
1.8 |
/* Return if exactly one archetype matches. */ |
1133 |
root |
1.68 |
if (found) |
1134 |
root |
1.79 |
return found->instance (); |
1135 |
elmex |
1.1 |
|
1136 |
root |
1.8 |
/* No spell found: just print an error message. */ |
1137 |
root |
1.70 |
new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist."); |
1138 |
root |
1.68 |
|
1139 |
root |
1.71 |
return 0; |
1140 |
elmex |
1.1 |
} |
1141 |
|
|
|
1142 |
root |
1.8 |
static int |
1143 |
|
|
command_learn_spell_or_prayer (object *op, char *params, int special_prayer) |
1144 |
|
|
{ |
1145 |
|
|
object *tmp; |
1146 |
elmex |
1.1 |
|
1147 |
root |
1.8 |
if (op->contr == NULL || params == NULL) |
1148 |
|
|
{ |
1149 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to learn?"); |
1150 |
|
|
return 0; |
1151 |
elmex |
1.1 |
} |
1152 |
|
|
|
1153 |
root |
1.8 |
tmp = get_spell_by_name (op, params); |
1154 |
|
|
if (tmp == NULL) |
1155 |
|
|
{ |
1156 |
|
|
return 0; |
1157 |
elmex |
1.1 |
} |
1158 |
|
|
|
1159 |
root |
1.8 |
if (check_spell_known (op, tmp->name)) |
1160 |
|
|
{ |
1161 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "You already know the spell %s.", &tmp->name); |
1162 |
|
|
return 0; |
1163 |
elmex |
1.1 |
} |
1164 |
|
|
|
1165 |
root |
1.8 |
do_learn_spell (op, tmp, special_prayer); |
1166 |
root |
1.60 |
tmp->destroy (); |
1167 |
root |
1.8 |
return 1; |
1168 |
elmex |
1.1 |
} |
1169 |
|
|
|
1170 |
root |
1.8 |
int |
1171 |
|
|
command_learn_spell (object *op, char *params) |
1172 |
|
|
{ |
1173 |
|
|
return command_learn_spell_or_prayer (op, params, 0); |
1174 |
elmex |
1.1 |
} |
1175 |
|
|
|
1176 |
root |
1.8 |
int |
1177 |
|
|
command_learn_special_prayer (object *op, char *params) |
1178 |
elmex |
1.1 |
{ |
1179 |
root |
1.8 |
return command_learn_spell_or_prayer (op, params, 1); |
1180 |
elmex |
1.1 |
} |
1181 |
|
|
|
1182 |
root |
1.8 |
int |
1183 |
|
|
command_forget_spell (object *op, char *params) |
1184 |
elmex |
1.1 |
{ |
1185 |
root |
1.8 |
object *spell; |
1186 |
elmex |
1.1 |
|
1187 |
root |
1.8 |
if (op->contr == NULL || params == NULL) |
1188 |
|
|
{ |
1189 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); |
1190 |
|
|
return 0; |
1191 |
elmex |
1.1 |
} |
1192 |
|
|
|
1193 |
root |
1.91 |
spell = op->find_spell (params); |
1194 |
root |
1.8 |
if (spell == NULL) |
1195 |
|
|
{ |
1196 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); |
1197 |
|
|
return 0; |
1198 |
elmex |
1.1 |
} |
1199 |
|
|
|
1200 |
root |
1.8 |
do_forget_spell (op, spell->name); |
1201 |
|
|
return 1; |
1202 |
elmex |
1.1 |
} |
1203 |
|
|
|
1204 |
|
|
/** |
1205 |
|
|
* Pop the stack top. |
1206 |
|
|
*/ |
1207 |
root |
1.8 |
int |
1208 |
|
|
command_stack_pop (object *op, char *params) |
1209 |
|
|
{ |
1210 |
|
|
dm_stack_pop (op->contr); |
1211 |
|
|
return 0; |
1212 |
elmex |
1.1 |
} |
1213 |
|
|
|
1214 |
|
|
/** |
1215 |
|
|
* Push specified item on stack. |
1216 |
|
|
*/ |
1217 |
root |
1.8 |
int |
1218 |
|
|
command_stack_push (object *op, char *params) |
1219 |
|
|
{ |
1220 |
|
|
object *ob; |
1221 |
|
|
int from; |
1222 |
|
|
|
1223 |
|
|
ob = get_dm_object (op->contr, ¶ms, &from); |
1224 |
elmex |
1.1 |
|
1225 |
root |
1.8 |
if (ob && from != STACK_FROM_NUMBER) |
1226 |
|
|
/* Object was from stack, need to push it again */ |
1227 |
|
|
dm_stack_push (op->contr, ob->count); |
1228 |
|
|
|
1229 |
|
|
return 0; |
1230 |
elmex |
1.1 |
} |
1231 |
|
|
|
1232 |
|
|
/** |
1233 |
|
|
* Displays stack contents. |
1234 |
|
|
*/ |
1235 |
root |
1.8 |
int |
1236 |
|
|
command_stack_list (object *op, char *params) |
1237 |
|
|
{ |
1238 |
|
|
int item; |
1239 |
|
|
object *display; |
1240 |
|
|
player *pl = op->contr; |
1241 |
|
|
|
1242 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Item stack contents:"); |
1243 |
|
|
|
1244 |
|
|
for (item = 0; item < pl->stack_position; item++) |
1245 |
|
|
{ |
1246 |
|
|
display = find_object (pl->stack_items[item]); |
1247 |
|
|
if (display) |
1248 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, " %d : %s [%d]", item, &display->name, display->count); |
1249 |
|
|
else |
1250 |
|
|
/* Item was freed */ |
1251 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, " %d : (lost item: %d)", item, pl->stack_items[item]); |
1252 |
elmex |
1.1 |
} |
1253 |
|
|
|
1254 |
root |
1.8 |
return 0; |
1255 |
elmex |
1.1 |
} |
1256 |
|
|
|
1257 |
|
|
/** |
1258 |
|
|
* Empty DM item stack. |
1259 |
|
|
*/ |
1260 |
root |
1.8 |
int |
1261 |
|
|
command_stack_clear (object *op, char *params) |
1262 |
|
|
{ |
1263 |
|
|
op->contr->stack_position = 0; |
1264 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Item stack cleared."); |
1265 |
|
|
return 0; |
1266 |
elmex |
1.1 |
} |
1267 |
|
|
|
1268 |
root |
1.8 |
int |
1269 |
|
|
command_insert_into (object *op, char *params) |
1270 |
elmex |
1.1 |
{ |
1271 |
root |
1.77 |
object *left, *right; |
1272 |
root |
1.8 |
int left_from, right_from; |
1273 |
elmex |
1.1 |
|
1274 |
root |
1.8 |
left = get_dm_object (op->contr, ¶ms, &left_from); |
1275 |
|
|
if (!left) |
1276 |
|
|
{ |
1277 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Insert into what object?"); |
1278 |
|
|
return 0; |
1279 |
elmex |
1.1 |
} |
1280 |
|
|
|
1281 |
root |
1.8 |
if (left_from == STACK_FROM_NUMBER) |
1282 |
|
|
/* Item was stacked, remove it else right will be the same... */ |
1283 |
|
|
dm_stack_pop (op->contr); |
1284 |
elmex |
1.1 |
|
1285 |
root |
1.8 |
right = get_dm_object (op->contr, ¶ms, &right_from); |
1286 |
elmex |
1.1 |
|
1287 |
root |
1.8 |
if (!right) |
1288 |
|
|
{ |
1289 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "Insert what item?"); |
1290 |
|
|
return 0; |
1291 |
elmex |
1.1 |
} |
1292 |
|
|
|
1293 |
root |
1.8 |
if (left_from == STACK_FROM_TOP && right_from == STACK_FROM_TOP) |
1294 |
|
|
{ |
1295 |
|
|
/* |
1296 |
|
|
* Special case: both items were taken from stack top. |
1297 |
|
|
* Override the behaviour, taking left as item just below top, if exists. |
1298 |
|
|
* See function description for why. |
1299 |
|
|
* Besides, can't insert an item into itself. |
1300 |
|
|
*/ |
1301 |
|
|
if (op->contr->stack_position > 1) |
1302 |
|
|
{ |
1303 |
|
|
left = find_object (op->contr->stack_items[op->contr->stack_position - 2]); |
1304 |
|
|
if (left) |
1305 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "(Note: item to insert into taken from undertop)"); |
1306 |
|
|
else |
1307 |
|
|
/* Stupid case: item under top was freed, fallback to stack top */ |
1308 |
|
|
left = right; |
1309 |
elmex |
1.1 |
} |
1310 |
|
|
} |
1311 |
|
|
|
1312 |
root |
1.8 |
if (left == right) |
1313 |
elmex |
1.1 |
{ |
1314 |
root |
1.8 |
new_draw_info (NDI_UNIQUE, 0, op, "Can't insert an object into itself!"); |
1315 |
|
|
return 0; |
1316 |
elmex |
1.1 |
} |
1317 |
|
|
|
1318 |
root |
1.8 |
if (right->type == PLAYER) |
1319 |
elmex |
1.1 |
{ |
1320 |
root |
1.8 |
new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1321 |
|
|
return 0; |
1322 |
elmex |
1.1 |
} |
1323 |
|
|
|
1324 |
root |
1.82 |
if (!right->flag [FLAG_REMOVED]) |
1325 |
root |
1.21 |
right->remove (); |
1326 |
root |
1.54 |
|
1327 |
root |
1.77 |
object *inserted = insert_ob_in_ob (right, left); |
1328 |
elmex |
1.1 |
|
1329 |
root |
1.8 |
new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); |
1330 |
elmex |
1.1 |
|
1331 |
root |
1.8 |
return 0; |
1332 |
elmex |
1.1 |
|
1333 |
|
|
} |