2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * snxtitem.c: Arrange item selection using one of many criteria.
30 * Known contributors to this file:
42 #include "prototypes.h"
45 * setup the nstr structure for sector selection.
46 * can select on NS_ALL, NS_AREA, NS_DIST, and NS_LIST.
47 * iterate thru the "condarg" string looking
48 * for arguments to compile into the nstr.
49 * Using this function for anything but command arguments is usually
50 * incorrect, because it respects conditionals. Use the snxtitem_FOO()
54 snxtitem(struct nstr_item *np, int type, char *str, char *prompt)
69 sprintf(promptbuf, "%s(s)? ", ef_nameof(type));
72 str = getstring(prompt, buf);
77 /* empty string passed by player */
80 if (type == EF_NATION && isalpha(*str)) {
81 cnum = natarg(str, NULL);
84 sprintf(buf, "%d", cnum);
87 flags = ef_flags(type);
88 switch (sarg_type(str)) {
90 if (!(flags & EFF_XY))
92 if (!sarg_area(str, &range))
94 snxtitem_area(np, type, &range);
97 if (!(flags & EFF_XY))
99 if (!sarg_range(str, &cx, &cy, &dist))
101 snxtitem_dist(np, type, cx, cy, dist);
104 snxtitem_all(np, type);
107 if ((n = sarg_list(str, list, NS_LSIZE)) == 0)
109 if (!snxtitem_list(np, type, list, n))
113 if (!(flags & EFF_XY))
115 if (!sarg_xy(str, &cx, &cy))
117 snxtitem_xy(np, type, cx, cy);
120 if (!(flags & EFF_GROUP))
122 snxtitem_group(np, type, *str);
128 if (player->condarg == 0)
130 n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond), type,
132 np->ncond = n >= 0 ? n : 0;
137 snxtitem_area(struct nstr_item *np, int type, struct range *range)
139 memset(np, 0, sizeof(*np));
146 np->flags = ef_flags(type);
147 xysize_range(&np->range);
151 snxtitem_dist(struct nstr_item *np, int type, int cx, int cy,
156 memset(np, 0, sizeof(*np));
157 xydist_range(cx, cy, dist, &range);
167 np->flags = ef_flags(type);
169 /* This is no longer proper. */
170 /* It did the wrong thing for small, hitech worlds. */
171 xysize_range(&np->range);
176 snxtitem_xy(struct nstr_item *np, int type, coord x, coord y)
178 memset(np, 0, sizeof(*np));
187 np->flags = ef_flags(type);
191 snxtitem_all(struct nstr_item *np, int type)
193 memset(np, 0, sizeof(*np));
199 np->flags = ef_flags(type);
200 xysize_range(&np->range);
204 snxtitem_group(struct nstr_item *np, int type, char group)
208 memset(np, 0, sizeof(*np));
215 np->flags = ef_flags(type);
216 xysize_range(&np->range);
220 snxtitem_rewind(struct nstr_item *np)
227 snxtitem_list(struct nstr_item *np, int type, int *list, int len)
231 memset(np, 0, sizeof(*np));
237 np->flags = ef_flags(type);
238 if (len <= 0 || len > NS_LSIZE)
240 for (i = 0; i < len; i++)
241 np->list[i] = list[i];