]> git.pond.sub.org Git - empserver/blob - src/lib/commands/thre.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / commands / thre.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  *  thre.c: Describe/set threshold for given commodity
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  *     Steve McClure, 1998
33  */
34
35 #include "misc.h"
36 #include "player.h"
37 #include "var.h"
38 #include "sect.h"
39 #include "xy.h"
40 #include "item.h"
41 #include "nsc.h"
42 #include "nat.h"
43 #include "file.h"
44 #include "commands.h"
45
46 /*
47  * threshold <COMM> <SECTS> <THRESH>
48  */
49 int
50 thre(void)
51 {
52     extern struct ichrstr *whatitem();
53     struct sctstr sect;
54     struct nstr_sect nstr;
55     int val;
56     struct ichrstr *ip;
57     s_char *p;
58     int thresh;
59     int type;
60     s_char prompt[128];
61     s_char buf[128];
62
63     if ((ip = whatitem(player->argp[1], "What commodity? ")) == 0)
64         return RET_SYN;
65     if (!snxtsct(&nstr, player->argp[2]))
66         return RET_SYN;
67     type = V_DIST(ip->i_vtype & (~VT_TYPE));
68     if (player->argp[3] && *player->argp[3] &&
69         (*player->argp[3] < '0' || *player->argp[3] > '9')) {
70         pr("Threshold must be a number\n");
71         return RET_SYN;
72     }
73     while (!player->aborted && nxtsct(&nstr, &sect)) {
74         if (!player->owner)
75             continue;
76         val = getvar(type, (s_char *)&sect, EF_SECTOR);
77         if (val > 0)
78             sprintf(prompt, "%s %s  old threshold %d new? ",
79                     xyas(nstr.x, nstr.y, player->cnum),
80                     dchr[sect.sct_type].d_name, val);
81         else
82             sprintf(prompt, "%s %s  threshold? ",
83                     xyas(nstr.x, nstr.y, player->cnum),
84                     dchr[sect.sct_type].d_name);
85         if ((p = getstarg(player->argp[3], prompt, buf)) == 0)
86             return RET_FAIL;
87         if (!check_sect_ok(&sect))
88             return RET_FAIL;
89         if (*p == '\0' || *p == '-')
90             continue;
91         thresh = atoi(p);
92         if (thresh > 10000)
93             thresh = 10000;
94         if ((val > 0) && (val == thresh)) {
95             pr("%s threshold unchanged (left at %d)\n",
96                xyas(nstr.x, nstr.y, player->cnum), val);
97             continue;
98         }
99         if (val > 0 && (player->argp[3] != 0 && *player->argp[3] != 0))
100             pr("%s old threshold %d\n",
101                xyas(nstr.x, nstr.y, player->cnum), val);
102         if (putvar(type, thresh, (s_char *)&sect, EF_SECTOR) < 0)
103             pr("No room for threshold in %s\n",
104                xyas(nstr.x, nstr.y, player->cnum));
105         putsect(&sect);
106     }
107     return RET_OK;
108 }