]> git.pond.sub.org Git - empserver/blob - src/lib/commands/mult.c
(interix, INTERIXCFLAGS, INTERIXLFLAGS, INTERIXMASTER): New, from Ron
[empserver] / src / lib / commands / mult.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  *  mult.c: Set per-nation list of price multipliers
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "var.h"
37 #include "nat.h"
38 #include "file.h"
39 #include "xy.h"
40 #include "nsc.h"
41 #include "commands.h"
42 #include "optlist.h"
43 #include <math.h>               /* bailey@math-cs.kent.edu */
44
45 static void multsingle(natid us, natid them, struct natstr *natp);
46
47 int
48 mult(void)
49 {
50     struct nstr_item ni;
51     struct natstr nat;
52     int nats;
53
54     if (!opt_MARKET) {
55         pr("The market is disabled.\n");
56         return RET_FAIL;
57     }
58     pr("The mult command is no longer used.\n");
59     if (!snxtitem(&ni, EF_NATION, player->argp[1]))
60         return RET_SYN;
61     if (commread() < 0) {
62         pr("Unable to read commodity file; get help!\n");
63         return RET_SYS;
64     }
65     nats = 0;
66     while (!player->aborted && nxtitem(&ni, (s_char *)&nat)) {
67         if ((nat.nat_stat & STAT_NORM) == 0)
68             continue;
69         multsingle(player->cnum, (natid)ni.cur, &nat);
70         nats++;
71     }
72     pr("%d nation multipliers changed\n", nats);
73     return RET_OK;
74 }
75
76 /*
77  * Set the multipler for a single country.
78  */
79 static void
80 multsingle(natid us, natid them, struct natstr *natp)
81 {
82     double price;
83     s_char *p;
84     s_char prompt[128];
85     s_char buf[1024];
86
87     sprintf(prompt, "%s (%7.3f) : ", natp->nat_cnam, multread(us, them));
88     p = getstarg(player->argp[2], prompt, buf);
89     if (p == 0 || *p == 0)
90         return;
91     if ((price = atof(p)) == 0.0)
92         return;
93 #if defined(HUGE)
94     if ((price == HUGE) || (price > 1000000.0)) /* Inf causes overflow. */
95 #else
96     if (price > 1000000.0)
97 #endif
98         price = 1000000.0;      /* bailey@math-cs.kent.edu */
99     /*
100      * no free lunches!
101      */
102     if (price <= minmult)
103         price = minmult;
104     if (price >= maxmult)
105         price = maxmult;
106     if (commread() < 0) {
107         pr("Unable to re-read commodity file; get help!\n");
108         return;
109     }
110     multset(them, price);
111     if (commwrite() < 0) {
112         pr("Unable to write out commodity file; get help!\n");
113     }
114 }