2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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:
41 #include "prototypes.h"
44 * setup the nstr structure for sector selection.
45 * can select on NS_ALL, NS_AREA, NS_DIST, and NS_LIST.
46 * iterate thru the "condarg" string looking
47 * for arguments to compile into the nstr.
50 snxtitem(struct nstr_item *np, int type, s_char *str)
65 sprintf(prompt, "%s(s)? ", ef_nameof(type));
66 str = getstring(prompt, buf);
71 /* str present, but only <cr>: nil string passed by player */
74 if (type == EF_NATION && isalpha(*str)) {
75 sprintf(natnumber, "%d", natarg(str, ""));
78 flags = ef_flags(type);
79 switch (sarg_type(str)) {
81 if (!(flags & EFF_XY))
83 if (!sarg_area(str, &range))
85 snxtitem_area(np, type, &range);
88 if (!(flags & EFF_XY))
90 if (!sarg_range(str, &cx, &cy, &dist))
92 snxtitem_dist(np, type, cx, cy, dist);
95 snxtitem_all(np, type);
98 if ((n = sarg_list(str, list, NS_LSIZE)) == 0)
100 if (!snxtitem_list(np, type, list, n))
104 if (!(flags & EFF_XY))
106 if (!sarg_xy(str, &cx, &cy))
108 snxtitem_xy(np, type, cx, cy);
111 if (!(flags & EFF_GROUP))
113 snxtitem_group(np, type, *str);
119 if (player->condarg == 0)
121 n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond), type,
123 np->ncond = n >= 0 ? n : 0;
128 snxtitem_area(struct nstr_item *np, int type, struct range *range)
130 memset(np, 0, sizeof(*np));
137 np->flags = ef_flags(type);
138 xysize_range(&np->range);
143 snxtitem_dist(struct nstr_item *np, int type, int cx, int cy,
148 memset(np, 0, sizeof(*np));
149 xydist_range(cx, cy, dist, &range);
159 np->flags = ef_flags(type);
161 /* This is no longer proper. */
162 /* It did the wrong thing for small, hitech worlds. */
163 xysize_range(&np->range);
169 snxtitem_xy(struct nstr_item *np, int type, coord x, coord y)
171 memset(np, 0, sizeof(*np));
180 np->flags = ef_flags(type);
185 snxtitem_all(struct nstr_item *np, int type)
187 memset(np, 0, sizeof(*np));
193 np->flags = ef_flags(type);
194 xysize_range(&np->range);
199 snxtitem_group(struct nstr_item *np, int type, s_char group)
203 memset(np, 0, sizeof(*np));
210 np->flags = ef_flags(type);
211 xysize_range(&np->range);
216 snxtitem_rewind(struct nstr_item *np)
220 ef_zapcache(np->type);
224 snxtitem_list(struct nstr_item *np, int type, int *list, int len)
228 memset(np, 0, sizeof(*np));
234 np->flags = ef_flags(type);
235 if (len <= 0 || len > NS_LSIZE)
237 for (i = 0; i < len; i++)
238 np->list[i] = list[i];