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.61 by root, Sat Dec 20 02:32:31 2008 UTC vs.
Revision 1.84 by root, Thu Apr 15 02:51:39 2010 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 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 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
33/* Values for 'from' field of get_dm_object */ 34/* Values for 'from' field of get_dm_object */
34#define STACK_FROM_NONE 0 /* Item was not found */ 35#define STACK_FROM_NONE 0 /* Item was not found */
35#define STACK_FROM_TOP 1 /* Item is stack top */ 36#define STACK_FROM_TOP 1 /* Item is stack top */
36#define STACK_FROM_STACK 2 /* Item is somewhere in stack */ 37#define STACK_FROM_STACK 2 /* Item is somewhere in stack */
37#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) */
38
39 39
40/** 40/**
41 * 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
42 * it out to a seperate function. name is the person 42 * it out to a seperate function. name is the person
43 * being saught, rq is who is looking for them. This 43 * being saught, rq is who is looking for them. This
70 70
71 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 71 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
72 return 0; 72 return 0;
73} 73}
74 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
75/** 264/**
76 * Actually hides specified player (obviously a DM). 265 * Actually hides specified player (obviously a DM).
77 * 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,
78 * else they just think someone left/entered. 267 * else they just think someone left/entered.
79 */ 268 */
80void 269static void
81do_wizard_hide (object *op, int silent_dm) 270do_wizard_hide (object *op, int silent_dm)
82{ 271{
83 if (op->contr->hidden) 272 if (op->contr->hidden)
84 { 273 {
85 op->contr->hidden = 0; 274 op->contr->hidden = 0;
167 { 356 {
168 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);
169 return 1; 358 return 1;
170 } 359 }
171 360
172 become_follower (ob, god); 361 ob->become_follower (god);
173 return 1;
174}
175
176// TODO: Rewrite banish in perl and get rid of the following two functions
177int
178command_kick (object *op, char *params)
179{
180 for_all_players (pl)
181 if ((params == NULL || !strcmp (&pl->ob->name, params)) && !INVOKE_PLAYER (KICK, pl, ARG_STRING (params)))
182 {
183 object *plop = pl->ob;
184
185 if (!QUERY_FLAG (plop, FLAG_REMOVED) && !QUERY_FLAG (plop, FLAG_FREED))
186 {
187 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 5, op, "%s is kicked out of the game.", &plop->name);
188 plop->contr->killer = op;
189 }
190
191 pl->ns->destroy ();
192 }
193
194 return 1;
195}
196
197//TODO
198#if 0
199int
200command_save_overlay (object *op, char *params)
201{
202 if (!op)
203 return 0;
204
205 if (op != NULL && !QUERY_FLAG (op, FLAG_WIZ))
206 {
207 new_draw_info (NDI_UNIQUE, 0, op, "Sorry, you can't force an overlay save.");
208 return 1; 362 return 1;
209 }
210
211 new_save_map (op->map, 2);
212 new_save_map (op->map, 0);
213 new_draw_info (NDI_UNIQUE, 0, op, "Current map has been saved as an" " overlay.");
214
215 ready_map_name (op->map->path, 0);
216
217 return 1;
218} 363}
219#endif
220 364
221int 365int
222command_freeze (object *op, char *params) 366command_freeze (object *op, char *params)
223{ 367{
224 int ticks; 368 int ticks;
451 { 595 {
452 art = find_artifactlist (at->type)->items; 596 art = find_artifactlist (at->type)->items;
453 597
454 while (art) 598 while (art)
455 { 599 {
456 if (!strcmp (art->item->name, cp)) 600 if (!strcmp (&art->item->name, cp))
457 break; 601 break;
458 602
459 art = art->next; 603 art = art->next;
460 } 604 }
461 605
477 /* 621 /*
478 * Rather than have two different blocks with a lot of similar code, 622 * Rather than have two different blocks with a lot of similar code,
479 * just create one object, do all the processing, and then determine 623 * just create one object, do all the processing, and then determine
480 * if that one object should be inserted or if we need to make copies. 624 * if that one object should be inserted or if we need to make copies.
481 */ 625 */
482 tmp = arch_to_object (at); 626 tmp = at->instance ();
483 627
484 if (set_magic) 628 if (set_magic)
485 set_abs_magic (tmp, magic); 629 set_abs_magic (tmp, magic);
486 630
487 if (art) 631 if (art)
488 give_artifact_abilities (tmp, art->item); 632 give_artifact_abilities (tmp, art->item);
489 633
490 if (need_identify (tmp)) 634 if (tmp->need_identify ())
491 { 635 {
492 SET_FLAG (tmp, FLAG_IDENTIFIED); 636 tmp->set_flag (FLAG_IDENTIFIED);
493 CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); 637 tmp->clr_flag (FLAG_KNOWN_MAGICAL);
494 } 638 }
495 639
496 /* 640 /*
497 * This entire block here tries to find variable pairings, 641 * This entire block here tries to find variable pairings,
498 * eg, 'hp 4' or the like. The mess here is that values 642 * eg, 'hp 4' or the like. The mess here is that values
570 } 714 }
571 715
572 if (at->nrof) 716 if (at->nrof)
573 { 717 {
574 if (at_spell) 718 if (at_spell)
575 tmp->insert (arch_to_object (at_spell)); 719 tmp->insert (at_spell->instance ());
576 720
577 tmp->x = op->x; 721 tmp->x = op->x;
578 tmp->y = op->y; 722 tmp->y = op->y;
579 tmp->map = op->map; 723 tmp->map = op->map;
580 724
594 { 738 {
595 object *prev = 0, *head = 0; 739 object *prev = 0, *head = 0;
596 740
597 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) 741 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
598 { 742 {
599 object *dup = arch_to_object (atmp); 743 object *dup = atmp->instance ();
600 744
601 if (at_spell) 745 if (at_spell)
602 insert_ob_in_ob (arch_to_object (at_spell), dup); 746 insert_ob_in_ob (at_spell->instance (), dup);
603 747
604 /* 748 /*
605 * The head is what contains all the important bits, 749 * The head is what contains all the important bits,
606 * so just copying it over should be fine. 750 * so just copying it over should be fine.
607 */ 751 */
622 } 766 }
623 767
624 prev = dup; 768 prev = dup;
625 } 769 }
626 770
627 if (QUERY_FLAG (head, FLAG_ALIVE)) 771 if (head->flag [FLAG_ALIVE])
628 { 772 {
629 object *check = head; 773 object *check = head;
630 int size_x = 0; 774 int size_x = 0;
631 int size_y = 0; 775 int size_y = 0;
632 776
633 while (check) 777 while (check)
634 { 778 {
635 size_x = MAX (size_x, check->arch->x); 779 size_x = max (size_x, check->arch->x);
636 size_y = MAX (size_y, check->arch->y); 780 size_y = max (size_y, check->arch->y);
637 check = check->more; 781 check = check->more;
638 } 782 }
639 783
640 if (out_of_map (op->map, head->x + size_x, head->y + size_y)) 784 if (out_of_map (op->map, head->x + size_x, head->y + size_y))
641 { 785 {
723 867
724 char *dump = dump_object (tmp); 868 char *dump = dump_object (tmp);
725 new_draw_info (NDI_UNIQUE, 0, op, dump); 869 new_draw_info (NDI_UNIQUE, 0, op, dump);
726 free (dump); 870 free (dump);
727 871
728 if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) 872 if (tmp->flag [FLAG_OBJ_ORIGINAL])
729 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); 873 new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original");
730 874
731 return 1; 875 return 1;
732} 876}
733 877
778 { 922 {
779 new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); 923 new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!");
780 return 1; 924 return 1;
781 } 925 }
782 926
783 if (QUERY_FLAG (tmp, FLAG_REMOVED)) 927 if (tmp->flag [FLAG_REMOVED])
784 { 928 {
785 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); 929 new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp));
786 return 1; 930 return 1;
787 } 931 }
788 932
832 int q; 976 int q;
833 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure 977 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
834 object *skillob = NULL; 978 object *skillob = NULL;
835 979
836 skill[0] = '\0'; 980 skill[0] = '\0';
837 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %s", buf, &i, skill)) < 2)) 981 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2))
838 { 982 {
839 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); 983 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
840 return 1; 984 return 1;
841 } 985 }
842 986
889 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 1033 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
890 return 1; 1034 return 1;
891 } 1035 }
892 1036
893 for_all_players (pl) 1037 for_all_players (pl)
894 if (!strcmp (pl->ob->name, thing)) 1038 if (!strcmp (&pl->ob->name, thing))
895 { 1039 {
896 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); 1040 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp);
897 new_draw_info (NDI_UNIQUE, 0, op, buf); 1041 new_draw_info (NDI_UNIQUE, 0, op, buf);
898 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); 1042 sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp);
899 new_draw_info (NDI_UNIQUE, 0, op, buf); 1043 new_draw_info (NDI_UNIQUE, 0, op, buf);
942 return 1; 1086 return 1;
943 } 1087 }
944 1088
945 for_all_players (pl) 1089 for_all_players (pl)
946 { 1090 {
947 if (!strcmp (pl->ob->name, thing)) 1091 if (!strcmp (&pl->ob->name, thing))
948 { 1092 {
949 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; 1093 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii;
950 if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii; 1094 if (!strcmp ("dex", thing2)) pl->ob->stats.Dex = iii, pl->orig_stats.Dex = iii;
951 if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii; 1095 if (!strcmp ("con", thing2)) pl->ob->stats.Con = iii, pl->orig_stats.Con = iii;
952 if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii; 1096 if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii;
966} 1110}
967 1111
968int 1112int
969command_nowiz (object *op, char *params) 1113command_nowiz (object *op, char *params)
970{ /* 'nodm' is alias */ 1114{ /* 'nodm' is alias */
971 CLEAR_FLAG (op, FLAG_WIZ); 1115 op->clr_flag (FLAG_WIZ);
972 CLEAR_FLAG (op, FLAG_WIZPASS); 1116 op->clr_flag (FLAG_WIZPASS);
973 CLEAR_FLAG (op, FLAG_WIZCAST); 1117 op->clr_flag (FLAG_WIZCAST);
1118 op->clr_flag (FLAG_WIZLOOK);
1119 op->contr->do_los = 1;
974 1120
975 if (op->contr->hidden) 1121 if (op->contr->hidden)
976 { 1122 {
977 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); 1123 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
978 op->map->players++; 1124 op->map->players++;
980 op->contr->hidden = 0; 1126 op->contr->hidden = 0;
981 op->invisible = 1; 1127 op->invisible = 1;
982 } 1128 }
983 else 1129 else
984 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); 1130 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
1131
985 return 1; 1132 return 1;
986} 1133}
987 1134
988/** 1135/**
989 * object *op is trying to become dm. 1136 * object *op is trying to become dm.
1026 } 1173 }
1027 fclose (dmfile); 1174 fclose (dmfile);
1028 return (0); 1175 return (0);
1029} 1176}
1030 1177
1031int 1178static int
1032do_wizard_dm (object *op, char *params, int silent) 1179do_wizard_dm (object *op, char *params, int silent)
1033{ 1180{
1034 if (!op->contr) 1181 if (!op->contr)
1035 return 0; 1182 return 0;
1036 1183
1037 if (QUERY_FLAG (op, FLAG_WIZ)) 1184 if (op->flag [FLAG_WIZ])
1038 { 1185 {
1039 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); 1186 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1040 return 0; 1187 return 0;
1041 } 1188 }
1042 1189
1043 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) 1190 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1044 { 1191 {
1045 SET_FLAG (op, FLAG_WIZ); 1192 op->set_flag (FLAG_WIZ);
1046 SET_FLAG (op, FLAG_WIZPASS); 1193 op->set_flag (FLAG_WIZPASS);
1047 SET_FLAG (op, FLAG_WIZCAST); 1194 op->set_flag (FLAG_WIZCAST);
1195 op->set_flag (FLAG_WIZLOOK);
1196 op->contr->do_los = 1;
1048 1197
1049 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); 1198 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1050 /*
1051 * Remove setting flying here - that won't work, because next
1052 * fix_player() is called that will get cleared - proper solution
1053 * is probably something like a wiz_force which gives that and any
1054 * other desired abilities.
1055 */
1056 op->contr->clear_los (0);
1057 op->contr->write_buf[0] = '\0'; 1199 op->contr->write_buf[0] = '\0';
1058 1200
1059 if (!silent) 1201 if (!silent)
1060 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!"); 1202 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1061 1203
1101 * Returns spell object (from archetypes) by name. 1243 * Returns spell object (from archetypes) by name.
1102 * Returns NULL if 0 or more than one spell matches. 1244 * Returns NULL if 0 or more than one spell matches.
1103 * Used for wizard's learn spell/prayer. 1245 * Used for wizard's learn spell/prayer.
1104 * 1246 *
1105 * op is the player issuing the command. 1247 * op is the player issuing the command.
1106 *
1107 * Ignores archetypes "spelldirect_xxx" since these archetypes are not used
1108 * anymore (but may still be present in some player's inventories and thus
1109 * cannot be removed). We have to ignore them here since they have the same
1110 * name than other "spell_xxx" archetypes and would always conflict.
1111 */ 1248 */
1112static object * 1249static object *
1113get_spell_by_name (object *op, const char *spell_name) 1250get_spell_by_name (object *op, shstr_cmp spell_name)
1114{ 1251{
1115 archetype *at;
1116 archetype *found;
1117 int conflict_found;
1118 size_t spell_name_length;
1119
1120 /* First check for full name matches. */ 1252 /* First check for full name matches. */
1121 conflict_found = 0; 1253 int conflict_found = 0;
1122 found = NULL; 1254 archetype *found = 0;
1255
1123 for_all_archetypes (at) 1256 for_all_archetypes (at)
1124 { 1257 {
1125 if (at->type != SPELL) 1258 if (at->type != SPELL)
1126 continue; 1259 continue;
1127 1260
1128 if (strncmp (at->archname, "spelldirect_", 12) == 0) 1261 if (at->object::name != spell_name)
1129 continue; 1262 continue;
1130 1263
1131 if (strcmp (at->object::name, spell_name) != 0)
1132 continue;
1133
1134 if (found != NULL) 1264 if (found)
1135 { 1265 {
1136 if (!conflict_found) 1266 if (!conflict_found)
1137 { 1267 {
1138 conflict_found = 1; 1268 conflict_found = 1;
1139 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); 1269 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name);
1140 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); 1270 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1141 } 1271 }
1142 1272
1143 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); 1273 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1144 continue; 1274 return 0;
1145 } 1275 }
1146 1276
1147 found = at; 1277 found = at;
1148 } 1278 }
1149 1279
1150 /* No match if more more than one archetype matches. */
1151 if (conflict_found)
1152 return NULL;
1153
1154 /* Return if exactly one archetype matches. */ 1280 /* Return if exactly one archetype matches. */
1155 if (found != NULL) 1281 if (found)
1156 return arch_to_object (found); 1282 return found->instance ();
1157
1158 /* No full match found: now check for partial matches. */
1159 spell_name_length = strlen (spell_name);
1160 conflict_found = 0;
1161 found = NULL;
1162 for_all_archetypes (at)
1163 {
1164 if (at->type != SPELL)
1165 continue;
1166
1167 if (strncmp (at->archname, "spelldirect_", 12) == 0)
1168 continue;
1169
1170 if (strncmp (at->object::name, spell_name, spell_name_length) != 0)
1171 continue;
1172
1173 if (found != NULL)
1174 {
1175 if (!conflict_found)
1176 {
1177 conflict_found = 1;
1178 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name);
1179 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->object::name);
1180 }
1181 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->object::name);
1182 continue;
1183 }
1184
1185 found = at;
1186 }
1187
1188 /* No match if more more than one archetype matches. */
1189 if (conflict_found)
1190 return NULL;
1191
1192 /* Return if exactly one archetype matches. */
1193 if (found != NULL)
1194 return arch_to_object (found);
1195 1283
1196 /* No spell found: just print an error message. */ 1284 /* No spell found: just print an error message. */
1197 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell %s does not exist.", spell_name); 1285 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist.");
1286
1198 return NULL; 1287 return 0;
1199} 1288}
1200 1289
1201static int 1290static int
1202command_learn_spell_or_prayer (object *op, char *params, int special_prayer) 1291command_learn_spell_or_prayer (object *op, char *params, int special_prayer)
1203{ 1292{
1272 return 0; 1361 return 0;
1273 1362
1274 do_wizard_hide (op, 1); 1363 do_wizard_hide (op, 1);
1275 1364
1276 return 1; 1365 return 1;
1277}
1278
1279void
1280dm_stack_pop (player *pl)
1281{
1282 if (!pl->stack_items || !pl->stack_position)
1283 {
1284 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1285 return;
1286 }
1287
1288 pl->stack_position--;
1289 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
1290}
1291
1292/**
1293 * Get current stack top item for player.
1294 * Returns NULL if no stacked item.
1295 * If stacked item disappeared (freed), remove it.
1296 *
1297 * Ryo, august 2004
1298 */
1299object *
1300dm_stack_peek (player *pl)
1301{
1302 object *ob;
1303
1304 if (!pl->stack_position)
1305 {
1306 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1307 return NULL;
1308 }
1309
1310 ob = find_object (pl->stack_items[pl->stack_position - 1]);
1311 if (!ob)
1312 {
1313 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
1314 dm_stack_pop (pl);
1315 return NULL;
1316 }
1317
1318 return ob;
1319}
1320
1321/**
1322 * Push specified item on player stack.
1323 * Inform player of position.
1324 * Initializes variables if needed.
1325 */
1326void
1327dm_stack_push (player *pl, tag_t item)
1328{
1329 if (!pl->stack_items)
1330 {
1331 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
1332 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
1333 }
1334
1335 if (pl->stack_position == STACK_SIZE)
1336 {
1337 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
1338 return;
1339 }
1340
1341 pl->stack_items[pl->stack_position] = item;
1342 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
1343 pl->stack_position++;
1344}
1345
1346/**
1347 * Checks 'params' for object code.
1348 *
1349 * Can be:
1350 * * empty => get current object stack top for player
1351 * * number => get item with that tag, stack it for future use
1352 * * $number => get specified stack item
1353 * * "me" => player himself
1354 *
1355 * At function exit, params points to first non-object char
1356 *
1357 * 'from', if not NULL, contains at exit:
1358 * * STACK_FROM_NONE => object not found
1359 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
1360 * * STACK_FROM_STACK => item from somewhere in the stack
1361 * * STACK_FROM_NUMBER => item by number, pushed on stack
1362 *
1363 * Ryo, august 2004
1364 */
1365object *
1366get_dm_object (player *pl, char **params, int *from)
1367{
1368 int item_tag, item_position;
1369 object *ob;
1370
1371 if (!pl)
1372 return NULL;
1373
1374 if (!params || !*params || **params == '\0')
1375 {
1376 if (from)
1377 *from = STACK_FROM_TOP;
1378 /* No parameter => get stack item */
1379 return dm_stack_peek (pl);
1380 }
1381
1382 /* Let's clean white spaces */
1383 while (**params == ' ')
1384 (*params)++;
1385
1386 /* Next case: number => item tag */
1387 if (sscanf (*params, "%d", &item_tag))
1388 {
1389 /* Move parameter to next item */
1390 while (isdigit (**params))
1391 (*params)++;
1392
1393 /* And skip blanks, too */
1394 while (**params == ' ')
1395 (*params)++;
1396
1397 /* Get item */
1398 ob = find_object (item_tag);
1399 if (!ob)
1400 {
1401 if (from)
1402 *from = STACK_FROM_NONE;
1403 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
1404 return NULL;
1405 }
1406
1407 /* Got one, let's push it on stack */
1408 dm_stack_push (pl, item_tag);
1409 if (from)
1410 *from = STACK_FROM_NUMBER;
1411 return ob;
1412 }
1413
1414 /* Next case: $number => stack item */
1415 if (sscanf (*params, "$%d", &item_position))
1416 {
1417 /* Move parameter to next item */
1418 (*params)++;
1419
1420 while (isdigit (**params))
1421 (*params)++;
1422 while (**params == ' ')
1423 (*params)++;
1424
1425 if (item_position >= pl->stack_position)
1426 {
1427 if (from)
1428 *from = STACK_FROM_NONE;
1429 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
1430 return NULL;
1431 }
1432
1433 ob = find_object (pl->stack_items[item_position]);
1434 if (!ob)
1435 {
1436 if (from)
1437 *from = STACK_FROM_NONE;
1438 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
1439 return NULL;
1440 }
1441
1442 if (from)
1443 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
1444 return ob;
1445 }
1446
1447 /* Next case: 'me' => return pl->ob */
1448 if (!strncmp (*params, "me", 2))
1449 {
1450 if (from)
1451 *from = STACK_FROM_NUMBER;
1452 dm_stack_push (pl, pl->ob->count);
1453
1454 /* Skip to next token */
1455 (*params) += 2;
1456 while (**params == ' ')
1457 (*params)++;
1458
1459 return pl->ob;
1460 }
1461
1462 /* Last case: get stack top */
1463 if (from)
1464 *from = STACK_FROM_TOP;
1465 return dm_stack_peek (pl);
1466} 1366}
1467 1367
1468/** 1368/**
1469 * Pop the stack top. 1369 * Pop the stack top.
1470 */ 1370 */
1530} 1430}
1531 1431
1532int 1432int
1533command_insert_into (object *op, char *params) 1433command_insert_into (object *op, char *params)
1534{ 1434{
1535 object *left, *right, *inserted; 1435 object *left, *right;
1536 int left_from, right_from; 1436 int left_from, right_from;
1537 1437
1538 left = get_dm_object (op->contr, &params, &left_from); 1438 left = get_dm_object (op->contr, &params, &left_from);
1539 if (!left) 1439 if (!left)
1540 { 1440 {
1583 { 1483 {
1584 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); 1484 new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!");
1585 return 0; 1485 return 0;
1586 } 1486 }
1587 1487
1588 if (!QUERY_FLAG (right, FLAG_REMOVED)) 1488 if (!right->flag [FLAG_REMOVED])
1589 right->remove (); 1489 right->remove ();
1590 1490
1591 insert_ob_in_ob (right, left); 1491 object *inserted = insert_ob_in_ob (right, left);
1592 1492
1593 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); 1493 new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left));
1594 1494
1595 return 0; 1495 return 0;
1596 1496

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines