ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_wiz.C
(Generate patch)

Comparing deliantra/server/server/c_wiz.C (file contents):
Revision 1.73 by root, Thu Nov 5 16:00:25 2009 UTC vs.
Revision 1.88 by root, Fri Jan 27 22:00:40 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 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 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 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
35#define STACK_FROM_NONE 0 /* Item was not found */ 35#define STACK_FROM_NONE 0 /* Item was not found */
36#define STACK_FROM_TOP 1 /* Item is stack top */ 36#define STACK_FROM_TOP 1 /* Item is stack top */
37#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ 37#define STACK_FROM_STACK 2 /* Item is somewhere in stack */
38#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */ 38#define STACK_FROM_NUMBER 3 /* Item is a number (may be top) */
39 39
40
41/** 40/**
42 * Enough of the DM functions seem to need this that I broke 41 * Enough of the DM functions seem to need this that I broke
43 * it out to a seperate function. name is the person 42 * it out to a seperate function. name is the person
44 * being saught, rq is who is looking for them. This 43 * being saught, rq is who is looking for them. This
45 * prints diagnostics messages, and returns the 44 * prints diagnostics messages, and returns the
71 70
72 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 71 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
73 return 0; 72 return 0;
74} 73}
75 74
75static void
76dm_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 */
95static object *
96dm_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 */
122void
123dm_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 */
161static object *
162get_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
76/** 264/**
77 * Actually hides specified player (obviously a DM). 265 * Actually hides specified player (obviously a DM).
78 * If 'silent_dm' is non zero, other players are informed of DM entering/leaving, 266 * If 'silent_dm' is non zero, other players are informed of DM entering/leaving,
79 * else they just think someone left/entered. 267 * else they just think someone left/entered.
80 */ 268 */
81void 269static void
82do_wizard_hide (object *op, int silent_dm) 270do_wizard_hide (object *op, int silent_dm)
83{ 271{
84 if (op->contr->hidden) 272 if (op->contr->hidden)
85 { 273 {
86 op->contr->hidden = 0; 274 op->contr->hidden = 0;
168 { 356 {
169 new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); 357 new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str);
170 return 1; 358 return 1;
171 } 359 }
172 360
173 become_follower (ob, god); 361 ob->become_follower (god);
174 return 1;
175}
176
177// TODO: Rewrite banish in perl and get rid of the following two functions
178int
179command_kick (object *op, char *params)
180{
181 for_all_players (pl)
182 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
183 {
184 object *plop = pl->ob;
185
186 if (!QUERY_FLAG (plop, FLAG_REMOVED) && !QUERY_FLAG (plop, FLAG_FREED))
187 {
188 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &plop->name);
189 plop->contr->killer = op;
190 }
191
192 pl->ns->destroy ();
193 }
194
195 return 1;
196}
197
198//TODO
199#if 0
200int
201command_save_overlay (object *op, char *params)
202{
203 if (!op)
204 return 0;
205
206 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
207 {
208 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't force an overlay save.");
209 return 1; 362 return 1;
210 }
211
212 new_save_map (op->map, 2);
213 new_save_map (op->map, 0);
214 new_draw_info (NDI_UNIQUE, 0, op, "Current map has been saved as an" " overlay.");
215
216 ready_map_name (op->map->path, 0);
217
218 return 1;
219} 363}
220#endif
221 364
222int 365int
223command_freeze (object *op, char *params) 366command_freeze (object *op, char *params)
224{ 367{
225 int ticks; 368 int ticks;
293 436
294int 437int
295command_summon (object *op, char *params) 438command_summon (object *op, char *params)
296{ 439{
297 int i; 440 int i;
298 object *dummy;
299 player *pl; 441 player *pl;
300 442
301 if (!op) 443 if (!op)
302 return 0; 444 return 0;
303 445
309 451
310 pl = get_other_player_from_name (op, params); 452 pl = get_other_player_from_name (op, params);
311 if (!pl) 453 if (!pl)
312 return 1; 454 return 1;
313 455
314 i = find_free_spot (op, op->map, op->x, op->y, 1, 9); 456 maptile *m = op->map;
457 sint16 nx = op->x;
458 sint16 ny = op->y;
459
460 i = find_free_spot (op, m, nx, ny, 1, SIZEOFFREE1+1);
315 if (i == -1) 461 if (i == -1)
316 { 462 {
317 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); 463 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
318 return 1; 464 return 1;
319 } 465 }
320 466
321 pl->ob->player_goto (op->map->path, op->x + freearr_x[i], op->y + freearr_y[i]); 467 nx += freearr_x [i];
468 ny += freearr_y [i];
469
470 if (!xy_normalise (m, nx, ny))
471 {
472 new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player.");
473 return 1;
474 }
475
476 pl->ob->player_goto (m->path, nx, ny);
322 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); 477 new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned.");
323 new_draw_info (NDI_UNIQUE, 0, op, "OK."); 478 new_draw_info (NDI_UNIQUE, 0, op, "OK.");
324 479
325 return 1; 480 return 1;
326} 481}
343int 498int
344command_create (object *op, char *params) 499command_create (object *op, char *params)
345{ 500{
346 object *tmp = NULL; 501 object *tmp = NULL;
347 int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; 502 int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace;
348 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *bp4, *endline; 503 char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline;
349 archetype *at, *at_spell = NULL; 504 archetype *at, *at_spell = NULL;
350 artifact *art = NULL; 505 artifact *art = NULL;
351 506
352 if (!op) 507 if (!op)
353 return 0; 508 return 0;
478 /* 633 /*
479 * Rather than have two different blocks with a lot of similar code, 634 * Rather than have two different blocks with a lot of similar code,
480 * just create one object, do all the processing, and then determine 635 * just create one object, do all the processing, and then determine
481 * if that one object should be inserted or if we need to make copies. 636 * if that one object should be inserted or if we need to make copies.
482 */ 637 */
483 tmp = arch_to_object (at); 638 tmp = at->instance ();
484 639
485 if (set_magic) 640 if (set_magic)
486 set_abs_magic (tmp, magic); 641 set_abs_magic (tmp, magic);
487 642
488 if (art) 643 if (art)
489 give_artifact_abilities (tmp, art->item); 644 give_artifact_abilities (tmp, art->item);
490 645
491 if (need_identify (tmp)) 646 if (tmp->need_identify ())
492 { 647 {
493 SET_FLAG (tmp, FLAG_IDENTIFIED); 648 tmp->set_flag (FLAG_IDENTIFIED);
494 CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); 649 tmp->clr_flag (FLAG_KNOWN_MAGICAL);
495 } 650 }
496 651
497 /* 652 /*
498 * This entire block here tries to find variable pairings, 653 * This entire block here tries to find variable pairings,
499 * eg, 'hp 4' or the like. The mess here is that values 654 * eg, 'hp 4' or the like. The mess here is that values
501 * is we want to find two spaces, but if we got a quote, 656 * is we want to find two spaces, but if we got a quote,
502 * any spaces there don't count. 657 * any spaces there don't count.
503 */ 658 */
504 while (*bp2 && bp2 <= endline) 659 while (*bp2 && bp2 <= endline)
505 { 660 {
506 bp4 = NULL;
507 gotspace = 0; 661 gotspace = 0;
508 gotquote = 0; 662 gotquote = 0;
509 663
510 /* find the first quote */ 664 /* find the first quote */
511 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) 665 for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++)
571 } 725 }
572 726
573 if (at->nrof) 727 if (at->nrof)
574 { 728 {
575 if (at_spell) 729 if (at_spell)
576 tmp->insert (arch_to_object (at_spell)); 730 tmp->insert (at_spell->instance ());
577 731
578 tmp->x = op->x; 732 tmp->x = op->x;
579 tmp->y = op->y; 733 tmp->y = op->y;
580 tmp->map = op->map; 734 tmp->map = op->map;
581 735
595 { 749 {
596 object *prev = 0, *head = 0; 750 object *prev = 0, *head = 0;
597 751
598 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) 752 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
599 { 753 {
600 object *dup = arch_to_object (atmp); 754 object *dup = atmp->instance ();
601 755
602 if (at_spell) 756 if (at_spell)
603 insert_ob_in_ob (arch_to_object (at_spell), dup); 757 insert_ob_in_ob (at_spell->instance (), dup);
604 758
605 /* 759 /*
606 * The head is what contains all the important bits, 760 * The head is what contains all the important bits,
607 * so just copying it over should be fine. 761 * so just copying it over should be fine.
608 */ 762 */
623 } 777 }
624 778
625 prev = dup; 779 prev = dup;
626 } 780 }
627 781
628 if (QUERY_FLAG (head, FLAG_ALIVE)) 782 if (head->flag [FLAG_ALIVE])
629 { 783 {
630 object *check = head; 784 object *check = head;
631 int size_x = 0; 785 int size_x = 0;
632 int size_y = 0; 786 int size_y = 0;
633 787
634 while (check) 788 while (check)
635 { 789 {
636 size_x = MAX (size_x, check->arch->x); 790 size_x = max (size_x, check->arch->x);
637 size_y = MAX (size_y, check->arch->y); 791 size_y = max (size_y, check->arch->y);
638 check = check->more; 792 check = check->more;
639 } 793 }
640 794
641 if (out_of_map (op->map, head->x + size_x, head->y + size_y)) 795 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
642 { 796 {
724 878
725 char *dump = dump_object (tmp); 879 char *dump = dump_object (tmp);
726 new_draw_info (NDI_UNIQUE, 0, op, dump); 880 new_draw_info (NDI_UNIQUE, 0, op, dump);
727 free (dump); 881 free (dump);
728 882
729 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) 883 if (tmp->flag [FLAG_OBJ_ORIGINAL])
730 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); 884 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
731 885
732 return 1; 886 return 1;
733} 887}
734 888
779 { 933 {
780 new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); 934 new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!");
781 return 1; 935 return 1;
782 } 936 }
783 937
784 if (QUERY_FLAG (tmp, FLAG_REMOVED)) 938 if (tmp->flag [FLAG_REMOVED])
785 { 939 {
786 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); 940 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp));
787 return 1; 941 return 1;
788 } 942 }
789 943
967} 1121}
968 1122
969int 1123int
970command_nowiz (object *op, char *params) 1124command_nowiz (object *op, char *params)
971{ /* 'nodm' is alias */ 1125{ /* 'nodm' is alias */
972 CLEAR_FLAG (op, FLAG_WIZ); 1126 op->clr_flag (FLAG_WIZ);
973 CLEAR_FLAG (op, FLAG_WIZPASS); 1127 op->clr_flag (FLAG_WIZPASS);
974 CLEAR_FLAG (op, FLAG_WIZCAST); 1128 op->clr_flag (FLAG_WIZCAST);
975 CLEAR_FLAG (op, FLAG_WIZLOOK); 1129 op->clr_flag (FLAG_WIZLOOK);
976 op->contr->do_los = 1; 1130 op->contr->do_los = 1;
977 1131
978 if (op->contr->hidden) 1132 if (op->contr->hidden)
979 { 1133 {
980 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); 1134 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
1030 } 1184 }
1031 fclose (dmfile); 1185 fclose (dmfile);
1032 return (0); 1186 return (0);
1033} 1187}
1034 1188
1035int 1189static int
1036do_wizard_dm (object *op, char *params, int silent) 1190do_wizard_dm (object *op, char *params, int silent)
1037{ 1191{
1038 if (!op->contr) 1192 if (!op->contr)
1039 return 0; 1193 return 0;
1040 1194
1041 if (QUERY_FLAG (op, FLAG_WIZ)) 1195 if (op->flag [FLAG_WIZ])
1042 { 1196 {
1043 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); 1197 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1044 return 0; 1198 return 0;
1045 } 1199 }
1046 1200
1047 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) 1201 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1048 { 1202 {
1049 SET_FLAG (op, FLAG_WIZ); 1203 op->set_flag (FLAG_WIZ);
1050 SET_FLAG (op, FLAG_WIZPASS); 1204 op->set_flag (FLAG_WIZPASS);
1051 SET_FLAG (op, FLAG_WIZCAST); 1205 op->set_flag (FLAG_WIZCAST);
1052 SET_FLAG (op, FLAG_WIZLOOK); 1206 op->set_flag (FLAG_WIZLOOK);
1053 op->contr->do_los = 1; 1207 op->contr->do_los = 1;
1054 1208
1055 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); 1209 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1056 op->contr->write_buf[0] = '\0'; 1210 op->contr->write_buf[0] = '\0';
1057 1211
1106static object * 1260static object *
1107get_spell_by_name (object *op, shstr_cmp spell_name) 1261get_spell_by_name (object *op, shstr_cmp spell_name)
1108{ 1262{
1109 /* First check for full name matches. */ 1263 /* First check for full name matches. */
1110 int conflict_found = 0; 1264 int conflict_found = 0;
1111 archetype *found; 1265 archetype *found = 0;
1266
1112 for_all_archetypes (at) 1267 for_all_archetypes (at)
1113 { 1268 {
1114 if (at->type != SPELL) 1269 if (at->type != SPELL)
1115 continue; 1270 continue;
1116 1271
1133 found = at; 1288 found = at;
1134 } 1289 }
1135 1290
1136 /* Return if exactly one archetype matches. */ 1291 /* Return if exactly one archetype matches. */
1137 if (found) 1292 if (found)
1138 return arch_to_object (found); 1293 return found->instance ();
1139 1294
1140 /* No spell found: just print an error message. */ 1295 /* No spell found: just print an error message. */
1141 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist."); 1296 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist.");
1142 1297
1143 return 0; 1298 return 0;
1217 return 0; 1372 return 0;
1218 1373
1219 do_wizard_hide (op, 1); 1374 do_wizard_hide (op, 1);
1220 1375
1221 return 1; 1376 return 1;
1222}
1223
1224void
1225dm_stack_pop (player *pl)
1226{
1227 if (!pl->stack_items || !pl->stack_position)
1228 {
1229 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1230 return;
1231 }
1232
1233 pl->stack_position--;
1234 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
1235}
1236
1237/**
1238 * Get current stack top item for player.
1239 * Returns NULL if no stacked item.
1240 * If stacked item disappeared (freed), remove it.
1241 *
1242 * Ryo, august 2004
1243 */
1244object *
1245dm_stack_peek (player *pl)
1246{
1247 object *ob;
1248
1249 if (!pl->stack_position)
1250 {
1251 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1252 return NULL;
1253 }
1254
1255 ob = find_object (pl->stack_items[pl->stack_position - 1]);
1256 if (!ob)
1257 {
1258 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
1259 dm_stack_pop (pl);
1260 return NULL;
1261 }
1262
1263 return ob;
1264}
1265
1266/**
1267 * Push specified item on player stack.
1268 * Inform player of position.
1269 * Initializes variables if needed.
1270 */
1271void
1272dm_stack_push (player *pl, tag_t item)
1273{
1274 if (!pl->stack_items)
1275 {
1276 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
1277 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
1278 }
1279
1280 if (pl->stack_position == STACK_SIZE)
1281 {
1282 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
1283 return;
1284 }
1285
1286 pl->stack_items[pl->stack_position] = item;
1287 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
1288 pl->stack_position++;
1289}
1290
1291/**
1292 * Checks 'params' for object code.
1293 *
1294 * Can be:
1295 * * empty => get current object stack top for player
1296 * * number => get item with that tag, stack it for future use
1297 * * $number => get specified stack item
1298 * * "me" => player himself
1299 *
1300 * At function exit, params points to first non-object char
1301 *
1302 * 'from', if not NULL, contains at exit:
1303 * * STACK_FROM_NONE => object not found
1304 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
1305 * * STACK_FROM_STACK => item from somewhere in the stack
1306 * * STACK_FROM_NUMBER => item by number, pushed on stack
1307 *
1308 * Ryo, august 2004
1309 */
1310object *
1311get_dm_object (player *pl, char **params, int *from)
1312{
1313 int item_tag, item_position;
1314 object *ob;
1315
1316 if (!pl)
1317 return NULL;
1318
1319 if (!params || !*params || **params == '\0')
1320 {
1321 if (from)
1322 *from = STACK_FROM_TOP;
1323 /* No parameter => get stack item */
1324 return dm_stack_peek (pl);
1325 }
1326
1327 /* Let's clean white spaces */
1328 while (**params == ' ')
1329 (*params)++;
1330
1331 /* Next case: number => item tag */
1332 if (sscanf (*params, "%d", &item_tag))
1333 {
1334 /* Move parameter to next item */
1335 while (isdigit (**params))
1336 (*params)++;
1337
1338 /* And skip blanks, too */
1339 while (**params == ' ')
1340 (*params)++;
1341
1342 /* Get item */
1343 ob = find_object (item_tag);
1344 if (!ob)
1345 {
1346 if (from)
1347 *from = STACK_FROM_NONE;
1348 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
1349 return NULL;
1350 }
1351
1352 /* Got one, let's push it on stack */
1353 dm_stack_push (pl, item_tag);
1354 if (from)
1355 *from = STACK_FROM_NUMBER;
1356 return ob;
1357 }
1358
1359 /* Next case: $number => stack item */
1360 if (sscanf (*params, "$%d", &item_position))
1361 {
1362 /* Move parameter to next item */
1363 (*params)++;
1364
1365 while (isdigit (**params))
1366 (*params)++;
1367 while (**params == ' ')
1368 (*params)++;
1369
1370 if (item_position >= pl->stack_position)
1371 {
1372 if (from)
1373 *from = STACK_FROM_NONE;
1374 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
1375 return NULL;
1376 }
1377
1378 ob = find_object (pl->stack_items[item_position]);
1379 if (!ob)
1380 {
1381 if (from)
1382 *from = STACK_FROM_NONE;
1383 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
1384 return NULL;
1385 }
1386
1387 if (from)
1388 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
1389 return ob;
1390 }
1391
1392 /* Next case: 'me' => return pl->ob */
1393 if (!strncmp (*params, "me", 2))
1394 {
1395 if (from)
1396 *from = STACK_FROM_NUMBER;
1397 dm_stack_push (pl, pl->ob->count);
1398
1399 /* Skip to next token */
1400 (*params) += 2;
1401 while (**params == ' ')
1402 (*params)++;
1403
1404 return pl->ob;
1405 }
1406
1407 /* Last case: get stack top */
1408 if (from)
1409 *from = STACK_FROM_TOP;
1410 return dm_stack_peek (pl);
1411} 1377}
1412 1378
1413/** 1379/**
1414 * Pop the stack top. 1380 * Pop the stack top.
1415 */ 1381 */
1475} 1441}
1476 1442
1477int 1443int
1478command_insert_into (object *op, char *params) 1444command_insert_into (object *op, char *params)
1479{ 1445{
1480 object *left, *right, *inserted; 1446 object *left, *right;
1481 int left_from, right_from; 1447 int left_from, right_from;
1482 1448
1483 left = get_dm_object (op->contr, &params, &left_from); 1449 left = get_dm_object (op->contr, &params, &left_from);
1484 if (!left) 1450 if (!left)
1485 { 1451 {
1528 { 1494 {
1529 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); 1495 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!");
1530 return 0; 1496 return 0;
1531 } 1497 }
1532 1498
1533 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1499 if (!right->flag [FLAG_REMOVED])
1534 right->remove (); 1500 right->remove ();
1535 1501
1536 insert_ob_in_ob (right, left); 1502 object *inserted = insert_ob_in_ob (right, left);
1537 1503
1538 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); 1504 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left));
1539 1505
1540 return 0; 1506 return 0;
1541 1507

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines