]> git.pond.sub.org Git - empserver/blob - src/lib/commands/grin.c
Update copyright notice.
[empserver] / src / lib / commands / grin.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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  *  grin.c: Grind gold bars into dust
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "xy.h"
37 #include "sect.h"
38 #include "nat.h"
39 #include "nsc.h"
40 #include "file.h"
41 #include "product.h"
42 #include "commands.h"
43
44 int
45 grin(void)
46 {
47     struct nstr_sect nstr;
48     struct sctstr sect;
49     s_char *p;
50     int i, n, qty;
51     int avail;
52     s_char buf[1024];
53     double grind_eff = 0.8;
54
55     if ((p = getstarg(player->argp[1], "Sectors? ", buf)) == 0)
56         return RET_SYN;
57     if (!snxtsct(&nstr, p))
58         return RET_SYN;
59     if ((p = getstarg(player->argp[2], "amount :  ", buf)) == 0 || *p == 0)
60         return RET_SYN;
61     qty = atoi(p);
62     if (qty < 0)
63         return RET_SYN;
64     while (nxtsct(&nstr, &sect)) {
65         if (!player->owner)
66             continue;
67         if (sect.sct_effic < 60 || sect.sct_own != player->cnum)
68             continue;
69         n = sect.sct_item[I_BAR] >= qty ? qty : sect.sct_item[I_BAR];
70         /* work limit */
71         avail = n * 5;
72         if (avail > sect.sct_avail) {
73             n = sect.sct_avail / 5;
74             avail = sect.sct_avail;
75         }
76         /* space limit */
77         for (i = 0; i < MAXPRCON; i++) {
78             if (!pchr[P_BAR].p_camt[i])
79                 continue;
80             if (CANT_HAPPEN(pchr[P_BAR].p_ctype[i] <= I_NONE ||
81                             pchr[P_BAR].p_ctype[i] > I_MAX))
82                 continue;
83             n = min(n,
84                     (double)(ITEM_MAX - sect.sct_item[pchr[P_BAR].p_ctype[i]])
85                     / (pchr[P_BAR].p_camt[i] * grind_eff));
86         }
87
88         if (n > 0) {
89             pr("%d bars ground up in %s\n", n,
90                xyas(sect.sct_x, sect.sct_y, player->cnum));
91             sect.sct_item[I_BAR] -= n;
92             for (i = 0; i < MAXPRCON; i++) {
93                 if (!pchr[P_BAR].p_camt[i])
94                     continue;
95                 if (CANT_HAPPEN(pchr[P_BAR].p_ctype[i] <= I_NONE ||
96                                 pchr[P_BAR].p_ctype[i] > I_MAX))
97                     continue;
98                 sect.sct_item[pchr[P_BAR].p_ctype[i]]
99                     += n * pchr[P_BAR].p_camt[i] * grind_eff;
100             }
101             sect.sct_avail -= avail;
102             putsect(&sect);
103         }
104     }
105     return RET_OK;
106 }