]> git.pond.sub.org Git - empserver/blob - src/lib/common/getvar.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / common / getvar.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  *  getvar.c: Routines for manipulating variable lists.
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1989
32  */
33
34 #include "misc.h"
35 #include "var.h"
36 #include "file.h"
37 #include "common.h"
38
39 int
40 getvar(int vtype, s_char *sp, int ptype)
41 {
42     u_char *vtypep;
43     u_short *vamtp;
44     u_char *nvp;
45     int amt;
46
47     if (ef_vars(ptype, sp, &nvp, &vtypep, &vamtp) < 0) {
48         logerror("getvar: ptype %d has no vars", ptype);
49         return 0;
50     }
51     amt = vl_find(vtype, vtypep, vamtp, (int)*nvp);
52     if (amt < 0) {
53         logerror("getvar: vl_find returns %d, vtype %d", amt, vtype);
54         return 0;
55     }
56     return amt;
57 }
58
59 int
60 getvec(int class, int *vec, s_char *sp, int ptype)
61 {
62     u_char *vtypep;
63     u_short *vamtp;
64     u_char *nvp;
65     int nv;
66
67     if (ef_vars(ptype, sp, &nvp, &vtypep, &vamtp) < 0) {
68         logerror("getvec: ptype %d has no vars", ptype);
69         return 0;
70     }
71     nv = vl_getvec(vtypep, vamtp, (int)*nvp, class, vec);
72     if (nv < 0) {
73         logerror("vl_getvec: returns %d, ptype %d\n", nv, ptype);
74         return 0;
75     }
76     return nv;
77 }
78
79 int
80 putvar(int vtype, int amt, s_char *sp, int ptype)
81 {
82     u_char *vtypep;
83     u_short *vamtp;
84     u_char *nvp;
85     int maxv;
86
87     if (vtype < 0 || vtype > V_MAX) {
88         logerror("putvar: bad vtype %d\n", vtype);
89         return 0;
90     }
91     if ((maxv = ef_vars(ptype, sp, &nvp, &vtypep, &vamtp)) < 0) {
92         logerror("putvar: ptype %d has no vars", ptype);
93         return 0;
94     }
95     if (amt < 0)
96         amt = 0;
97     return vl_set(vtype, (u_int)amt, vtypep, vamtp, nvp, maxv);
98 }
99
100 int
101 putvec(int class, int *vec, s_char *sp, int ptype)
102 {
103     u_char *vtypep;
104     u_short *vamtp;
105     u_char *nvp;
106     int maxv, x;
107
108     if ((maxv = ef_vars(ptype, sp, &nvp, &vtypep, &vamtp)) < 0) {
109         logerror("putvec: ptype %d has no vars", ptype);
110         return 0;
111     }
112     for (x = 0; x < I_MAX; x++)
113         if (vec[x] < 0)
114             vec[x] = 0;
115     return vl_setvec(vtypep, vamtp, nvp, maxv, class, vec);
116 }