]> git.pond.sub.org Git - empserver/blob - include/nsc.h
Selector rewrite: values other than long, interpret identifiers
[empserver] / include / nsc.h
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  *  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 enum nsc_type {
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 };
63 typedef enum nsc_type nsc_type;
64 typedef char packed_nsc_type;
65
66 /* Value category */
67 enum nsc_cat {
68     NSC_NOCAT,
69     NSC_VAL,                    /* evaluated value */
70     NSC_OFF                     /* symbolic value: at offset in object */
71 };
72 typedef enum nsc_cat nsc_cat;
73 typedef char packed_nsc_cat;
74
75 enum {
76     NSC_DEITY = 1               /* access restricted to deity */
77 };
78 typedef unsigned char nsc_flags;
79
80 /*
81  * Value, possibly symbolic.
82  * If type is NSC_NOTYPE, it's an error value.
83  * If category is NSC_OFF, the value is at offset val_as.off in the
84  * context object.
85  * If category is NSC_VAL, the value is in val_as, and the type is a
86  * promoted type.
87  * Some values can also be interpreted as an object type.  The values
88  * consumer chooses how to interpret it, depending on context.
89  */
90 struct valstr {
91     packed_nsc_type val_type;   /* type of value */
92     packed_nsc_cat val_cat;     /* category of value */
93     signed char val_as_type;    /* value interpreted as object type */
94     union {
95         ptrdiff_t off;          /* cat NSC_OFF */
96         double dbl;             /* cat NSC_VAL, types NSC_DOUBLE */
97         char *str;              /* cat NSC_VAL, type NSC_STRING */
98         long lng;               /* cat NSC_VAL, type NSC_LONG */
99     } val_as;
100 };
101
102 /* Compiled condition */
103 struct nscstr {
104     char operator;              /* '<', '=', '>', '#' */
105     packed_nsc_type optype;     /* operator type */
106     struct valstr lft;          /* left operand */
107     struct valstr rgt;          /* right operand */
108 };
109
110 struct nstr_sect {
111     coord x, y;                 /* current x-y */
112     coord dx, dy;               /* accumlated x,y travel */
113     int id;                     /* return value of sctoff */
114     int type;                   /* type of query */
115     int curdist;                /* dist query: current range */
116     struct range range;         /* area of coverage */
117     int dist;                   /* dist query: range */
118     coord cx, cy;               /* dist query: center x-y */
119     int (*read)(int type, int id, caddr_t ptr); /* read function */
120     int ncond;                  /* # of selection conditions */
121     struct nscstr cond[NS_NCOND];       /* selection conditions */
122 };
123
124 struct nstr_item {
125     int cur;                    /* current item */
126     int sel;                    /* selection type */
127     int type;                   /* item type being selected */
128     int curdist;                /* if NS_DIST, current item's dist */
129     struct range range;         /* NS_AREA/NS_DIST: range selector */
130     int dist;                   /* NS_DIST: distance selector */
131     coord cx, cy;               /* NS_DIST: center x-y, NS_XY: xy */
132     int group;                  /* NS_GROUP: fleet/wing match */
133     int size;                   /* NS_LIST: size of list */
134     int index;                  /* NS_LIST: index */
135     int list[NS_LSIZE];         /* NS_LIST: item list */
136     int (*read)(int type, int id, caddr_t ptr); /* read function */
137     int flags;                  /* EFF_ flags */
138     int ncond;                  /* # of selection conditions */
139     struct nscstr cond[NS_NCOND];       /* selection conditions */
140 };
141
142 #define NS_UNDEF        0
143 #define NS_LIST         1
144 #define NS_DIST         2
145 #define NS_AREA         3
146 #define NS_ALL          4
147 #define NS_XY           5
148 #define NS_GROUP        6
149
150 /*
151  * Selector descriptor.
152  * Value is at offset CA_OFF in the context object.
153  */
154 struct castr {
155     packed_nsc_type ca_type;    /* type of value */
156     nsc_flags ca_flags;
157     unsigned short ca_len;      /* non-zero: is an array; #array elements */
158     ptrdiff_t ca_off;
159     char *ca_name;
160 };
161
162 /* variables using the above */
163
164 extern struct castr sect_ca[];
165 extern struct castr ship_ca[];
166 extern struct castr plane_ca[];
167 extern struct castr land_ca[];
168 extern struct castr nuke_ca[];
169 extern struct castr news_ca[];
170 extern struct castr nat_ca[];
171 extern struct castr treaty_ca[];
172 extern struct castr trade_ca[];
173 extern struct castr loan_ca[];
174 extern struct castr genitem_ca[];
175 extern struct castr lost_ca[];
176 extern struct castr commodity_ca[];
177
178 /* src/lib/subs/nstr.c */
179 extern int nstr_comp(struct nscstr *np, int len, int type, char *str);
180 extern char *nstr_comp_val(char *, struct valstr*, int);
181 extern int nstr_coerce_val(struct valstr *, nsc_type, char *);
182 extern int nstr_exec(struct nscstr *, int, void *);
183 extern void nstr_exec_val(struct valstr *, natid, void *, nsc_type);
184
185 #endif /* _NSC_H_ */