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
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.
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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.
28 * nstr.c: compile and execute the item selections on sectors
30 * Known contributors to this file:
46 #include "prototypes.h"
48 static int legal_val(s_char *str, int val);
51 * Compiles and adds "str" to the list of conditionals.
52 * type is the EF typename of the item type we're selecting.
53 * returns amount of "str" used by nstr_comp (i.e. how far
54 * the pointer was advanced). The last is only meaningful
55 * if several conditionals are expected in one string.
58 nstr_comp(struct nscstr *np, int *size, int type, s_char *str)
68 strncpy(arg, str, sizeof(arg) - 1);
69 arg[sizeof(arg) - 1] = 0;
72 while ((c = *cp++) && bp < &ident[sizeof(ident) - 1]) {
73 if (c == '<' || c == '=' || c == '>' || c == '#')
79 pr("'%s'? -- meaningless condition?\n", arg);
84 if ((val = encode(ident, &np[*size].fld1, type)) < 0)
87 np[*size].oper += 255;
89 while ((c = *cp++) && bp < &ident[sizeof(ident) - 1]) {
95 if ((val = encode(ident, &np[*size].fld2, type)) < 0)
98 np[*size].oper += 65535;
102 return str + (cp - arg);
106 encode(register s_char *str, long int *val, int type)
115 if (isdigit(*str) || ((*str == '-') && isdigit(str[1]))) {
117 /* XXX silently truncate to 16 bit int */
118 *val = atoi(str) & 0xffff;
121 #endif /* BIT16ONLY */
124 if ((i = typematch(str, type)) >= 0) {
128 if ((cap = ef_cadef(type)) != 0) {
129 i = stmtch(str, (caddr_t)cap, fldoff(castr, ca_name),
130 sizeof(struct castr));
132 *val = cap[i].ca_code | NSC_OFF;
134 return legal_val(str, *val);
136 if (i == M_NOTUNIQUE) {
137 pr("%s -- ambiguous type selector\n", str);
142 * Only check for commodity selectors on objects which
143 * are allowed to have commodities.
145 if (ef_flags(type) & EFF_COM) {
146 i = stmtch(str, (caddr_t)var_ca, fldoff(castr, ca_name),
147 sizeof(struct castr));
149 *val = var_ca[i].ca_code & ~NSC_ROUND;
150 return legal_val(str, *val);
153 if (i == M_NOTUNIQUE) {
154 pr("%s -- ambiguous commodity selector\n", str);
158 pr("%s -- not a valid selector\n", str);
163 legal_val(s_char *str, int val)
165 if (val & NSC_DEITY && !player->god) {
166 pr("%s -- permission denied\n", str);
174 * The rest of this stuff has been moved to libcommon
175 * so it can be used elsewhere (emp_update, mostly)