2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * snxtsct.c: Arrange sector selection using either distance or area
29 * Known contributors to this file:
31 * Markus Armbruster, 2006-2011
42 #include "prototypes.h"
46 * setup the nstr_sect structure for sector selection.
47 * can select on either NS_ALL, NS_AREA, or NS_DIST
48 * iterate thru the "condarg" string looking
49 * for arguments to compile into the nstr.
50 * Using this function for anything but command arguments is usually
51 * incorrect, because it respects conditionals. Use the snxtsct_FOO()
55 snxtsct(struct nstr_sect *np, char *str)
64 if (!(str = getstring("(sects)? ", buf)))
67 make_stale_if_command_arg(str);
68 switch (sarg_type(str)) {
70 if (!sarg_area(str, &range))
72 snxtsct_area(np, &range);
75 if (!sarg_range(str, &cx, &cy, &dist))
77 snxtsct_dist(np, cx, cy, dist);
81 * Can't use snxtsct_all(), as it would disclose the real
82 * origin. Use a world-sized area instead.
84 natp = getnatp(player->cnum);
85 range.lx = xabs(natp, -WORLD_X / 2);
86 range.ly = yabs(natp, -WORLD_Y / 2);
87 range.hx = xnorm(range.lx + WORLD_X - 1);
88 range.hy = ynorm(range.ly + WORLD_Y - 1);
90 snxtsct_area(np, &range);
95 return snxtsct_use_condarg(np);
99 snxtsct_all(struct nstr_sect *np)
101 struct range worldrange;
105 worldrange.hx = WORLD_X - 1;
106 worldrange.hy = WORLD_Y - 1;
107 xysize_range(&worldrange);
108 snxtsct_area(np, &worldrange);
112 snxtsct_area(struct nstr_sect *np, struct range *range)
114 memset(np, 0, sizeof(*np));
118 np->x = np->range.lx - 1;
119 np->y = np->range.ly;
125 snxtsct_use_condarg(struct nstr_sect *np)
129 if (!player->condarg)
131 n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond),
132 EF_SECTOR, player->condarg);
140 snxtsct_rewind(struct nstr_sect *np)
142 np->x = np->range.lx - 1;
143 np->y = np->range.ly;
150 snxtsct_dist(struct nstr_sect *np, coord cx, coord cy, int dist)
152 memset(np, 0, sizeof(*np));
153 xydist_range(cx, cy, dist, &np->range);
159 np->x = np->range.lx - 1;
160 np->y = np->range.ly;