]> git.pond.sub.org Git - empserver/blob - src/lib/common/snxtit_subs.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / common / snxtit_subs.c
1 /*
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
5  *
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.
10  *
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.
15  *
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
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  snxtit_subs.c: arrange item selection using one of many criteria.
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1989
32  */
33
34 #include "misc.h"
35 #include "var.h"
36 #include "xy.h"
37 #include "sect.h"
38 #include "nsc.h"
39 #include "file.h"
40 #include "common.h"
41
42 void
43 snxtitem_area(register struct nstr_item *np, int type, struct range *range)
44 {
45     bzero((s_char *)np, sizeof(*np));
46     np->cur = -1;
47     np->type = type;
48     np->sel = NS_AREA;
49     np->index = -1;
50     np->range = *range;
51     np->read = ef_read;
52     np->flags = ef_flags(type);
53     xysize_range(&np->range);
54     ef_zapcache(type);
55 }
56
57 void
58 snxtitem_dist(register struct nstr_item *np, int type, int cx, int cy,
59               int dist)
60 {
61     struct range range;
62
63     bzero((s_char *)np, sizeof(*np));
64     xydist_range(cx, cy, dist, &range);
65     np->cur = -1;
66     np->type = type;
67     np->sel = NS_DIST;
68     np->cx = cx;
69     np->cy = cy;
70     np->index = -1;
71     np->range = range;
72     np->dist = dist;
73     np->read = ef_read;
74     np->flags = ef_flags(type);
75 #if 0
76     /* This is no longer proper. */
77     /* It did the wrong thing for small, hitech worlds. */
78     xysize_range(&np->range);
79 #endif
80     ef_zapcache(type);
81 }
82
83 void
84 snxtitem_xy(register struct nstr_item *np, int type, coord x, coord y)
85 {
86     bzero((s_char *)np, sizeof(*np));
87     np->cur = -1;
88     np->type = type;
89     np->sel = NS_XY;
90     np->cx = xnorm(x);
91     np->cy = ynorm(y);
92     np->index = -1;
93     np->dist = 0;
94     np->read = ef_read;
95     np->flags = ef_flags(type);
96     ef_zapcache(type);
97 }
98
99 void
100 snxtitem_all(register struct nstr_item *np, int type)
101 {
102     bzero((s_char *)np, sizeof(*np));
103     np->cur = -1;
104     np->sel = NS_ALL;
105     np->type = type;
106     np->index = -1;
107     np->read = ef_read;
108     np->flags = ef_flags(type);
109     xysize_range(&np->range);
110     ef_zapcache(type);
111 }
112
113 void
114 snxtitem_group(register struct nstr_item *np, int type, s_char group)
115 {
116     if (group == '~')
117         group = ' ';
118     bzero((s_char *)np, sizeof(*np));
119     np->cur = -1;
120     np->sel = NS_GROUP;
121     np->group = group;
122     np->type = type;
123     np->index = -1;
124     np->read = ef_read;
125     np->flags = ef_flags(type);
126     xysize_range(&np->range);
127     ef_zapcache(type);
128 }
129
130 void
131 snxtitem_rewind(struct nstr_item *np)
132 {
133     np->cur = -1;
134     np->index = -1;
135     ef_zapcache(np->type);
136 }
137
138 int
139 snxtitem_list(register struct nstr_item *np, int type, int *list, int len)
140 {
141     int i;
142
143     bzero((s_char *)np, sizeof(*np));
144     np->cur = -1;
145     np->type = type;
146     np->sel = NS_LIST;
147     np->index = -1;
148     np->read = ef_read;
149     np->flags = ef_flags(type);
150     if (len <= 0 || len > NS_LSIZE)
151         return 0;
152     for (i = 0; i < len; i++)
153         np->list[i] = list[i];
154     np->size = len;
155     ef_zapcache(type);
156     return 1;
157 }