2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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.
51 snxtitem(register struct nstr_item *np, int type, s_char *str)
67 sprintf(prompt, "%s(s)? ", ef_nameof(type));
68 str = getstring(prompt, buf);
73 /* str present, but only <cr>: nil string passed by player */
76 if (type == EF_NATION && isalpha(*str)) {
77 sprintf(natnumber, "%d", natarg(str, ""));
80 flags = ef_flags(type);
81 switch (sarg_type(str)) {
83 if (!(flags & EFF_XY))
85 if (!sarg_area(str, &range))
87 snxtitem_area(np, type, &range);
90 if (!(flags & EFF_XY))
92 if (!sarg_range(str, &cx, &cy, &dist))
94 snxtitem_dist(np, type, cx, cy, dist);
97 snxtitem_all(np, type);
100 if ((n = sarg_list(str, list, NS_LSIZE)) == 0)
102 if (!snxtitem_list(np, type, list, n))
106 if (!(flags & EFF_XY))
108 if (!sarg_xy(str, &cx, &cy))
110 snxtitem_xy(np, type, cx, cy);
113 if (!(flags & EFF_GROUP))
115 snxtitem_group(np, type, *str);
121 if (player->condarg == 0)
123 cp = player->condarg;
124 while ((cp = nstr_comp(np->cond, &np->ncond, type, cp)) && *cp) ;
131 snxtitem_area(register struct nstr_item *np, int type, struct range *range)
133 memset(np, 0, sizeof(*np));
140 np->flags = ef_flags(type);
141 xysize_range(&np->range);
146 snxtitem_dist(register struct nstr_item *np, int type, int cx, int cy,
151 memset(np, 0, sizeof(*np));
152 xydist_range(cx, cy, dist, &range);
162 np->flags = ef_flags(type);
164 /* This is no longer proper. */
165 /* It did the wrong thing for small, hitech worlds. */
166 xysize_range(&np->range);
172 snxtitem_xy(register struct nstr_item *np, int type, coord x, coord y)
174 memset(np, 0, sizeof(*np));
183 np->flags = ef_flags(type);
188 snxtitem_all(register struct nstr_item *np, int type)
190 memset(np, 0, sizeof(*np));
196 np->flags = ef_flags(type);
197 xysize_range(&np->range);
202 snxtitem_group(register struct nstr_item *np, int type, s_char group)
206 memset(np, 0, sizeof(*np));
213 np->flags = ef_flags(type);
214 xysize_range(&np->range);
219 snxtitem_rewind(struct nstr_item *np)
223 ef_zapcache(np->type);
227 snxtitem_list(register 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];