]> git.pond.sub.org Git - empserver/blob - include/nsc.h
Remove leftover declarations that should have been removed along with
[empserver] / include / nsc.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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  *  nsc.h: Definitions for Empire conditionals
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1989
32  *     Markus Armbruster, 2004
33  */
34
35 #ifndef _NSC_H_
36 #define _NSC_H_
37
38 #include <stddef.h>
39 #include "xy.h"
40
41 #define NS_LSIZE        128
42 #define NS_NCOND        16
43
44 /* Value type */
45 typedef enum {
46     NSC_NOTYPE,
47     /* promoted types */
48     NSC_LONG,                   /* long */
49     NSC_DOUBLE,                 /* double */
50     NSC_STRING,                 /* char *, zero-terminated string */
51     NSC_TYPEID,                 /* signed char, index into chr table */
52     /* unpromoted types */
53     NSC_CHAR,                   /* signed char */
54     NSC_UCHAR,                  /* unsigned char */
55     NSC_SHORT,                  /* short */
56     NSC_USHORT,                 /* unsigned short */
57     NSC_INT,                    /* int */
58     NSC_XCOORD,                 /* coord that needs x conversion */
59     NSC_YCOORD,                 /* coord that needs y conversion */
60     NSC_TIME,                   /* time_t */
61     NSC_FLOAT,                  /* float */
62     NSC_STRINGY,                /* char[], zero-terminated string */
63     /* aliases, must match typedefs */
64     NSC_NATID = NSC_UCHAR       /* nation id */
65 } nsc_type;
66 typedef char packed_nsc_type;
67
68 /* Return nsc_type for a signed integer with the same size as TYPE.  */
69 #define NSC_SITYPE(type)                                \
70     (sizeof(type) == 1 ? NSC_CHAR                       \
71      : sizeof(type) == sizeof(short) ? NSC_SHORT        \
72      : sizeof(type) == sizeof(int) ? NSC_INT            \
73      : sizeof(type) == sizeof(long) ? NSC_LONG          \
74      : 1/0)
75
76 /* Value category */
77 typedef enum {
78     NSC_NOCAT,
79     NSC_VAL,                    /* evaluated value */
80     NSC_OFF,                    /* symbolic value: at offset in object */
81     NSC_ID                      /* unresolved identifier (internal use) */
82 } nsc_cat;
83 typedef char packed_nsc_cat;
84
85 enum {
86     NSC_DEITY = bit(0),         /* access restricted to deity */
87     NSC_EXTRA = bit(1)          /* computable from other selectors */
88 };
89 typedef unsigned char nsc_flags;
90
91 /*
92  * Value, possibly symbolic.
93  * If type is NSC_NOTYPE, it's an error value.
94  * If category is NSC_OFF, the value is in a context object at offset
95  * val_as.sym.off + val_as.sym.idx * S, where S is the size of the
96  * value.
97  * If category is NSC_VAL, the value is in val_as, and the type is a
98  * promoted type.
99  */
100 struct valstr {
101     packed_nsc_type val_type;   /* type of value */
102     packed_nsc_cat val_cat;     /* category of value */
103     union {
104         struct {                /* cat NSC_OFF */
105             ptrdiff_t off;
106             int len;
107             int idx;
108         } sym;
109         double dbl;             /* cat NSC_VAL, type NSC_DOUBLE */
110         struct {                /* cat NSC_VAL, type NSC_STRING, cat NSC_ID */
111             char *base;
112             size_t maxsz;
113         } str;
114         long lng;               /* cat NSC_VAL, type NSC_LONG, NSC_TYPEID */
115     } val_as;
116 };
117
118 /* Compiled condition */
119 struct nscstr {
120     char operator;              /* '<', '=', '>', '#' */
121     packed_nsc_type optype;     /* operator type */
122     struct valstr lft;          /* left operand */
123     struct valstr rgt;          /* right operand */
124 };
125
126 /* Selection type */
127 typedef enum {
128     NS_UNDEF,                   /* error value */
129     NS_LIST,                    /* list of IDs */
130     NS_DIST,                    /* circular area */
131     NS_AREA,                    /* rectangular area */
132     NS_ALL,                     /* everything */
133     NS_XY,                      /* one sector area */
134     NS_GROUP                    /* group, i.e. fleet, wing, army */
135 } ns_seltype;
136
137 /* Sector iterator */
138 struct nstr_sect {
139     coord x, y;                 /* current x-y */
140     coord dx, dy;               /* accumlated x,y travel */
141     int id;                     /* return value of sctoff */
142     ns_seltype type;            /* type of query */
143     int curdist;                /* dist query: current range */
144     struct range range;         /* area of coverage */
145     int dist;                   /* dist query: range */
146     coord cx, cy;               /* dist query: center x-y */
147     int (*read)(int type, int id, void *ptr);   /* read function */
148     int ncond;                  /* # of selection conditions */
149     struct nscstr cond[NS_NCOND];       /* selection conditions */
150 };
151
152 /* Item iterator */
153 struct nstr_item {
154     int cur;                    /* current item */
155     ns_seltype sel;             /* selection type */
156     int type;                   /* item type being selected */
157     int curdist;                /* if NS_DIST, current item's dist */
158     struct range range;         /* NS_AREA/NS_DIST: range selector */
159     int dist;                   /* NS_DIST: distance selector */
160     coord cx, cy;               /* NS_DIST: center x-y, NS_XY: xy */
161     int group;                  /* NS_GROUP: fleet/wing match */
162     int size;                   /* NS_LIST: size of list */
163     int index;                  /* NS_LIST: index */
164     int list[NS_LSIZE];         /* NS_LIST: item list */
165     int (*read)(int type, int id, void *ptr);   /* read function */
166     int flags;                  /* ef_flags(TYPE) */
167     int ncond;                  /* # of selection conditions */
168     struct nscstr cond[NS_NCOND]; /* selection conditions */
169 };
170
171 /*
172  * Selector descriptor.
173  * Value is at offset CA_OFF in the context object.
174  */
175 struct castr {
176     packed_nsc_type ca_type;    /* type of value */
177     nsc_flags ca_flags;
178     unsigned short ca_len;      /* non-zero: is an array; #array elements */
179     ptrdiff_t ca_off;
180     char *ca_name;
181 };
182
183 /* variables using the above */
184
185 extern struct castr sect_ca[];
186 extern struct castr ship_ca[];
187 extern struct castr plane_ca[];
188 extern struct castr land_ca[];
189 extern struct castr nuke_ca[];
190 extern struct castr news_ca[];
191 extern struct castr nat_ca[];
192 extern struct castr treaty_ca[];
193 extern struct castr trade_ca[];
194 extern struct castr loan_ca[];
195 extern struct castr lost_ca[];
196 extern struct castr commodity_ca[];
197
198 /* src/lib/subs/nstr.c */
199 extern int nstr_comp(struct nscstr *np, int len, int type, char *str);
200 extern char *nstr_comp_val(char *, struct valstr*, int);
201 extern int nstr_coerce_val(struct valstr *, nsc_type, char *);
202 extern int nstr_exec(struct nscstr *, int, void *);
203 extern void nstr_exec_val(struct valstr *, natid, void *, nsc_type);
204
205 #endif /* _NSC_H_ */