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.62 by root, Fri Dec 26 10:14:01 2008 UTC vs.
Revision 1.74 by root, Fri Nov 6 12:27:06 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 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;
451 { 640 {
452 art = find_artifactlist (at->type)->items; 641 art = find_artifactlist (at->type)->items;
453 642
454 while (art) 643 while (art)
455 { 644 {
456 if (!strcmp (art->item->name, cp)) 645 if (!strcmp (&art->item->name, cp))
457 break; 646 break;
458 647
459 art = art->next; 648 art = art->next;
460 } 649 }
461 650
832 int q; 1021 int q;
833 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure 1022 long long i; // use sint64 and finally provide format specifiers for sint64 etc. via configure
834 object *skillob = NULL; 1023 object *skillob = NULL;
835 1024
836 skill[0] = '\0'; 1025 skill[0] = '\0';
837 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %s", buf, &i, skill)) < 2)) 1026 if ((params == NULL) || (strlen (params) > MAX_BUF) || ((q = sscanf (params, "%s %lld %[^\n]", buf, &i, skill)) < 2))
838 { 1027 {
839 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>]."); 1028 new_draw_info (NDI_UNIQUE, 0, op, "Usage: addexp <who> <how much> [<skill>].");
840 return 1; 1029 return 1;
841 } 1030 }
842 1031
889 new_draw_info (NDI_UNIQUE, 0, op, "Who?"); 1078 new_draw_info (NDI_UNIQUE, 0, op, "Who?");
890 return 1; 1079 return 1;
891 } 1080 }
892 1081
893 for_all_players (pl) 1082 for_all_players (pl)
894 if (!strcmp (pl->ob->name, thing)) 1083 if (!strcmp (&pl->ob->name, thing))
895 { 1084 {
896 sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); 1085 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); 1086 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); 1087 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); 1088 new_draw_info (NDI_UNIQUE, 0, op, buf);
942 return 1; 1131 return 1;
943 } 1132 }
944 1133
945 for_all_players (pl) 1134 for_all_players (pl)
946 { 1135 {
947 if (!strcmp (pl->ob->name, thing)) 1136 if (!strcmp (&pl->ob->name, thing))
948 { 1137 {
949 if (!strcmp ("str", thing2)) pl->ob->stats.Str = iii, pl->orig_stats.Str = iii; 1138 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; 1139 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; 1140 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; 1141 if (!strcmp ("wis", thing2)) pl->ob->stats.Wis = iii, pl->orig_stats.Wis = iii;
969command_nowiz (object *op, char *params) 1158command_nowiz (object *op, char *params)
970{ /* 'nodm' is alias */ 1159{ /* 'nodm' is alias */
971 CLEAR_FLAG (op, FLAG_WIZ); 1160 CLEAR_FLAG (op, FLAG_WIZ);
972 CLEAR_FLAG (op, FLAG_WIZPASS); 1161 CLEAR_FLAG (op, FLAG_WIZPASS);
973 CLEAR_FLAG (op, FLAG_WIZCAST); 1162 CLEAR_FLAG (op, FLAG_WIZCAST);
1163 CLEAR_FLAG (op, FLAG_WIZLOOK);
1164 op->contr->do_los = 1;
974 1165
975 if (op->contr->hidden) 1166 if (op->contr->hidden)
976 { 1167 {
977 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); 1168 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
978 op->map->players++; 1169 op->map->players++;
980 op->contr->hidden = 0; 1171 op->contr->hidden = 0;
981 op->invisible = 1; 1172 op->invisible = 1;
982 } 1173 }
983 else 1174 else
984 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone.."); 1175 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
1176
985 return 1; 1177 return 1;
986} 1178}
987 1179
988/** 1180/**
989 * object *op is trying to become dm. 1181 * object *op is trying to become dm.
1044 { 1236 {
1045 SET_FLAG (op, FLAG_WIZ); 1237 SET_FLAG (op, FLAG_WIZ);
1046 SET_FLAG (op, FLAG_WIZPASS); 1238 SET_FLAG (op, FLAG_WIZPASS);
1047 SET_FLAG (op, FLAG_WIZCAST); 1239 SET_FLAG (op, FLAG_WIZCAST);
1048 SET_FLAG (op, FLAG_WIZLOOK); 1240 SET_FLAG (op, FLAG_WIZLOOK);
1241 op->contr->do_los = 1;
1049 1242
1050 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); 1243 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1051 op->contr->write_buf[0] = '\0'; 1244 op->contr->write_buf[0] = '\0';
1052 1245
1053 if (!silent) 1246 if (!silent)
1095 * Returns spell object (from archetypes) by name. 1288 * Returns spell object (from archetypes) by name.
1096 * Returns NULL if 0 or more than one spell matches. 1289 * Returns NULL if 0 or more than one spell matches.
1097 * Used for wizard's learn spell/prayer. 1290 * Used for wizard's learn spell/prayer.
1098 * 1291 *
1099 * op is the player issuing the command. 1292 * op is the player issuing the command.
1100 *
1101 * Ignores archetypes "spelldirect_xxx" since these archetypes are not used
1102 * anymore (but may still be present in some player's inventories and thus
1103 * cannot be removed). We have to ignore them here since they have the same
1104 * name than other "spell_xxx" archetypes and would always conflict.
1105 */ 1293 */
1106static object * 1294static object *
1107get_spell_by_name (object *op, const char *spell_name) 1295get_spell_by_name (object *op, shstr_cmp spell_name)
1108{ 1296{
1109 archetype *at; 1297 /* First check for full name matches. */
1298 int conflict_found = 0;
1110 archetype *found; 1299 archetype *found;
1111 int conflict_found;
1112 size_t spell_name_length;
1113
1114 /* First check for full name matches. */
1115 conflict_found = 0;
1116 found = NULL;
1117 for_all_archetypes (at) 1300 for_all_archetypes (at)
1118 { 1301 {
1119 if (at->type != SPELL) 1302 if (at->type != SPELL)
1120 continue; 1303 continue;
1121 1304
1122 if (strncmp (at->archname, "spelldirect_", 12) == 0) 1305 if (at->object::name != spell_name)
1123 continue; 1306 continue;
1124 1307
1125 if (strcmp (at->object::name, spell_name) != 0)
1126 continue;
1127
1128 if (found != NULL) 1308 if (found)
1129 { 1309 {
1130 if (!conflict_found) 1310 if (!conflict_found)
1131 { 1311 {
1132 conflict_found = 1; 1312 conflict_found = 1;
1133 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", spell_name); 1313 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one archetype matches the spell name %s:", &spell_name);
1134 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname); 1314 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->archname);
1135 } 1315 }
1136 1316
1137 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname); 1317 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->archname);
1138 continue; 1318 return 0;
1139 } 1319 }
1140 1320
1141 found = at; 1321 found = at;
1142 } 1322 }
1143 1323
1144 /* No match if more more than one archetype matches. */
1145 if (conflict_found)
1146 return NULL;
1147
1148 /* Return if exactly one archetype matches. */ 1324 /* Return if exactly one archetype matches. */
1149 if (found != NULL) 1325 if (found)
1150 return arch_to_object (found); 1326 return arch_to_object (found);
1151 1327
1152 /* No full match found: now check for partial matches. */
1153 spell_name_length = strlen (spell_name);
1154 conflict_found = 0;
1155 found = NULL;
1156 for_all_archetypes (at)
1157 {
1158 if (at->type != SPELL)
1159 continue;
1160
1161 if (strncmp (at->archname, "spelldirect_", 12) == 0)
1162 continue;
1163
1164 if (strncmp (at->object::name, spell_name, spell_name_length) != 0)
1165 continue;
1166
1167 if (found != NULL)
1168 {
1169 if (!conflict_found)
1170 {
1171 conflict_found = 1;
1172 new_draw_info_format (NDI_UNIQUE, 0, op, "More than one spell matches %s:", spell_name);
1173 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &found->object::name);
1174 }
1175 new_draw_info_format (NDI_UNIQUE, 0, op, "- %s", &at->object::name);
1176 continue;
1177 }
1178
1179 found = at;
1180 }
1181
1182 /* No match if more more than one archetype matches. */
1183 if (conflict_found)
1184 return NULL;
1185
1186 /* Return if exactly one archetype matches. */
1187 if (found != NULL)
1188 return arch_to_object (found);
1189
1190 /* No spell found: just print an error message. */ 1328 /* No spell found: just print an error message. */
1191 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell %s does not exist.", spell_name); 1329 new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist.");
1330
1192 return NULL; 1331 return 0;
1193} 1332}
1194 1333
1195static int 1334static int
1196command_learn_spell_or_prayer (object *op, char *params, int special_prayer) 1335command_learn_spell_or_prayer (object *op, char *params, int special_prayer)
1197{ 1336{
1266 return 0; 1405 return 0;
1267 1406
1268 do_wizard_hide (op, 1); 1407 do_wizard_hide (op, 1);
1269 1408
1270 return 1; 1409 return 1;
1271}
1272
1273void
1274dm_stack_pop (player *pl)
1275{
1276 if (!pl->stack_items || !pl->stack_position)
1277 {
1278 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1279 return;
1280 }
1281
1282 pl->stack_position--;
1283 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Popped item from stack, %d left.", pl->stack_position);
1284}
1285
1286/**
1287 * Get current stack top item for player.
1288 * Returns NULL if no stacked item.
1289 * If stacked item disappeared (freed), remove it.
1290 *
1291 * Ryo, august 2004
1292 */
1293object *
1294dm_stack_peek (player *pl)
1295{
1296 object *ob;
1297
1298 if (!pl->stack_position)
1299 {
1300 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Empty stack!");
1301 return NULL;
1302 }
1303
1304 ob = find_object (pl->stack_items[pl->stack_position - 1]);
1305 if (!ob)
1306 {
1307 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Stacked item was removed!");
1308 dm_stack_pop (pl);
1309 return NULL;
1310 }
1311
1312 return ob;
1313}
1314
1315/**
1316 * Push specified item on player stack.
1317 * Inform player of position.
1318 * Initializes variables if needed.
1319 */
1320void
1321dm_stack_push (player *pl, tag_t item)
1322{
1323 if (!pl->stack_items)
1324 {
1325 pl->stack_items = (tag_t *) malloc (sizeof (tag_t) * STACK_SIZE);
1326 memset (pl->stack_items, 0, sizeof (tag_t) * STACK_SIZE);
1327 }
1328
1329 if (pl->stack_position == STACK_SIZE)
1330 {
1331 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Item stack full!");
1332 return;
1333 }
1334
1335 pl->stack_items[pl->stack_position] = item;
1336 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Item stacked as %d.", pl->stack_position);
1337 pl->stack_position++;
1338}
1339
1340/**
1341 * Checks 'params' for object code.
1342 *
1343 * Can be:
1344 * * empty => get current object stack top for player
1345 * * number => get item with that tag, stack it for future use
1346 * * $number => get specified stack item
1347 * * "me" => player himself
1348 *
1349 * At function exit, params points to first non-object char
1350 *
1351 * 'from', if not NULL, contains at exit:
1352 * * STACK_FROM_NONE => object not found
1353 * * STACK_FROM_TOP => top item stack, may be NULL if stack was empty
1354 * * STACK_FROM_STACK => item from somewhere in the stack
1355 * * STACK_FROM_NUMBER => item by number, pushed on stack
1356 *
1357 * Ryo, august 2004
1358 */
1359object *
1360get_dm_object (player *pl, char **params, int *from)
1361{
1362 int item_tag, item_position;
1363 object *ob;
1364
1365 if (!pl)
1366 return NULL;
1367
1368 if (!params || !*params || **params == '\0')
1369 {
1370 if (from)
1371 *from = STACK_FROM_TOP;
1372 /* No parameter => get stack item */
1373 return dm_stack_peek (pl);
1374 }
1375
1376 /* Let's clean white spaces */
1377 while (**params == ' ')
1378 (*params)++;
1379
1380 /* Next case: number => item tag */
1381 if (sscanf (*params, "%d", &item_tag))
1382 {
1383 /* Move parameter to next item */
1384 while (isdigit (**params))
1385 (*params)++;
1386
1387 /* And skip blanks, too */
1388 while (**params == ' ')
1389 (*params)++;
1390
1391 /* Get item */
1392 ob = find_object (item_tag);
1393 if (!ob)
1394 {
1395 if (from)
1396 *from = STACK_FROM_NONE;
1397 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such item %d!", item_tag);
1398 return NULL;
1399 }
1400
1401 /* Got one, let's push it on stack */
1402 dm_stack_push (pl, item_tag);
1403 if (from)
1404 *from = STACK_FROM_NUMBER;
1405 return ob;
1406 }
1407
1408 /* Next case: $number => stack item */
1409 if (sscanf (*params, "$%d", &item_position))
1410 {
1411 /* Move parameter to next item */
1412 (*params)++;
1413
1414 while (isdigit (**params))
1415 (*params)++;
1416 while (**params == ' ')
1417 (*params)++;
1418
1419 if (item_position >= pl->stack_position)
1420 {
1421 if (from)
1422 *from = STACK_FROM_NONE;
1423 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "No such stack item %d!", item_position);
1424 return NULL;
1425 }
1426
1427 ob = find_object (pl->stack_items[item_position]);
1428 if (!ob)
1429 {
1430 if (from)
1431 *from = STACK_FROM_NONE;
1432 new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Stack item %d was removed.", item_position);
1433 return NULL;
1434 }
1435
1436 if (from)
1437 *from = item_position < pl->stack_position - 1 ? STACK_FROM_STACK : STACK_FROM_TOP;
1438 return ob;
1439 }
1440
1441 /* Next case: 'me' => return pl->ob */
1442 if (!strncmp (*params, "me", 2))
1443 {
1444 if (from)
1445 *from = STACK_FROM_NUMBER;
1446 dm_stack_push (pl, pl->ob->count);
1447
1448 /* Skip to next token */
1449 (*params) += 2;
1450 while (**params == ' ')
1451 (*params)++;
1452
1453 return pl->ob;
1454 }
1455
1456 /* Last case: get stack top */
1457 if (from)
1458 *from = STACK_FROM_TOP;
1459 return dm_stack_peek (pl);
1460} 1410}
1461 1411
1462/** 1412/**
1463 * Pop the stack top. 1413 * Pop the stack top.
1464 */ 1414 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines