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:
49 * return true if the conditions on this item
53 nstr_exec(struct nscstr *conds, register int ncond, void *ptr, int type)
55 register struct nscstr *nsc;
61 for (nsc=conds; --ncond >= 0; nsc++) {
67 rhs = decode(player->cnum, nsc->fld2, ptr, type);
73 lhs = decode(player->cnum, nsc->fld1, ptr, type);
76 if ((op == '<' && lhs >= rhs) ||
77 (op == '=' && lhs != rhs) ||
78 (op == '>' && lhs <= rhs) ||
79 (op == '#' && lhs == rhs))
86 decode(natid cnum, long int code, void *addr, int type)
89 register int nsc_code;
91 long code_type = (code & NSC_TMASK);
93 val = (code & ~NSC_MASK) & 0xffff;
95 /* handle negative numbers properly */
96 /* this assumes a binary two's complement number representation */
97 if (val>=0x8000) val -= 0x10000;
99 nsc_code = code & NSC_CMASK;
100 if (nsc_code == NSC_VAR) {
101 val = getvar(val, addr, type);
102 } else if (nsc_code == NSC_OFF) {
104 * add offset to value
106 addr = (s_char *)addr + val;
109 val = *((time_t *)addr);
112 val = *((s_char *) addr);
115 val = (int) *((unsigned char *) addr);
118 val = *((short *) addr);
121 val = *((u_short *) addr);
124 val = *((int *) addr);
127 val = *((long *) addr);
130 val = *((short *) addr);
135 val = *((short *) addr);
140 logerror("bad type in decode: %x!\n",
146 if (code & NSC_ROUND)
147 val = roundintby(val, 10);
152 decodep(long int code, void *addr)
154 addr = (char *)addr + ((code & ~NSC_MASK) & 0xffff);
156 if ((code & NSC_TMASK) == NSC_CHARP)
157 return *(s_char **)addr?*((s_char **)addr):(s_char *)"";