]> git.pond.sub.org Git - empserver/blob - src/lib/common/snxtit_subs.c
Import of Empire 4.2.12
[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, int dist)
59 {
60         struct  range range;
61
62         bzero((s_char *)np, sizeof(*np));
63         xydist_range(cx, cy, dist, &range);
64         np->cur = -1;
65         np->type = type;
66         np->sel = NS_DIST;
67         np->cx = cx;
68         np->cy = cy;
69         np->index = -1;
70         np->range = range;
71         np->dist = dist;
72         np->read = ef_read;
73         np->flags = ef_flags(type);
74 #if 0
75         /* This is no longer proper. */
76         /* It did the wrong thing for small, hitech worlds. */
77         xysize_range(&np->range);
78 #endif
79         ef_zapcache(type);
80 }
81
82 void
83 snxtitem_xy(register struct nstr_item *np, int type, coord x, coord y)
84 {
85         bzero((s_char *)np, sizeof(*np));
86         np->cur = -1;
87         np->type = type;
88         np->sel = NS_XY;
89         np->cx = xnorm(x);
90         np->cy = ynorm(y);
91         np->index = -1;
92         np->dist = 0;
93         np->read = ef_read;
94         np->flags = ef_flags(type);
95         ef_zapcache(type);
96 }
97
98 void
99 snxtitem_all(register struct nstr_item *np, int type)
100 {
101         bzero((s_char *)np, sizeof(*np));
102         np->cur = -1;
103         np->sel = NS_ALL;
104         np->type = type;
105         np->index = -1;
106         np->read = ef_read;
107         np->flags = ef_flags(type);
108         xysize_range(&np->range);
109         ef_zapcache(type);
110 }
111
112 void
113 snxtitem_group(register struct nstr_item *np, int type, s_char group)
114 {
115         if (group == '~')
116                 group = ' ';
117         bzero((s_char *)np, sizeof(*np));
118         np->cur = -1;
119         np->sel = NS_GROUP;
120         np->group = group;
121         np->type = type;
122         np->index = -1;
123         np->read = ef_read;
124         np->flags = ef_flags(type);
125         xysize_range(&np->range);
126         ef_zapcache(type);
127 }
128
129 void
130 snxtitem_rewind(struct nstr_item *np)
131 {
132         np->cur = -1;
133         np->index = -1;
134         ef_zapcache(np->type);
135 }
136
137 int
138 snxtitem_list(register struct nstr_item *np, int type, int *list, int len)
139 {
140         int     i;
141
142         bzero((s_char *)np, sizeof(*np));
143         np->cur = -1;
144         np->type = type;
145         np->sel = NS_LIST;
146         np->index = -1;
147         np->read = ef_read;
148         np->flags = ef_flags(type);
149         if (len <= 0 || len > NS_LSIZE)
150                 return 0;
151         for (i=0; i<len; i++)
152                 np->list[i] = list[i];
153         np->size = len;
154         ef_zapcache(type);
155         return 1;
156 }