]> git.pond.sub.org Git - empserver/blob - src/lib/commands/newe.c
Declare all configuration variables in optlist.h. Include that
[empserver] / src / lib / commands / newe.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  *  newe.c: Show new sector efficiency (projected)
29  * 
30  *  Known contributors to this file:
31  *     Thomas Ruschak, 1993
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "var.h"
37 #include "xy.h"
38 #include "nsc.h"
39 #include "sect.h"
40 #include "product.h"
41 #include "nat.h"
42 #include "item.h"
43 #include "file.h"
44 #include "commands.h"
45 #include "optlist.h"
46
47 int
48 newe(void)
49 {
50     struct natstr *natp;
51     struct sctstr sect;
52     struct nstr_sect nstr;
53     double work, wforce, lcms, hcms;
54     int items[I_MAX + 1];
55     int nsect;
56     int civs = 0;
57     int uws = 0;
58     int bwork;
59     int twork;
60     int type;
61     int eff;
62     int maxpop;
63
64     if (!snxtsct(&nstr, player->argp[1]))
65         return RET_SYN;
66     player->simulation = 1;
67     prdate();
68     nsect = 0;
69     while (nxtsct(&nstr, &sect)) {
70         if (!player->owner)
71             continue;
72         if (!sect.sct_off) {
73             getvec(VT_ITEM, items, (s_char *)&sect, EF_SECTOR);
74
75             civs = min(999, (int)((obrate * (double)etu_per_update + 1.0)
76                                   * (double)items[I_CIVIL]));
77             uws = min(999, (int)((uwbrate * (double)etu_per_update + 1.0)
78                                  * (double)items[I_UW]));
79             natp = getnatp(sect.sct_own);
80             maxpop = max_pop((float)natp->nat_level[NAT_RLEV], &sect);
81             civs = min(civs, maxpop);
82             uws = min(uws, maxpop);
83             /* This isn't quite right, since research might rise/fall */
84             /* during the update, but it's the best we can really do  */
85             wforce = (int)((civs * sect.sct_work) / 100.0
86                            + uws + items[I_MILIT] * 2 / 5.0);
87
88             work = etu_per_update * wforce / 100.0;
89             if (opt_ROLLOVER_AVAIL) {
90                 if (sect.sct_type == sect.sct_newtype) {
91                     work += sect.sct_avail;
92                 }
93                 if (work > 999) work = 999;
94             }
95
96             bwork = work / 2;
97
98             type = sect.sct_type;
99             eff = sect.sct_effic;
100             if (sect.sct_newtype != type) {
101                 twork = (eff + 3) / 4;
102                 if (twork > bwork) {
103                     twork = bwork;
104                 }
105                 work -= twork;
106                 bwork -= twork;
107                 eff -= twork * 4;
108                 if (eff <= 0) {
109                     type = sect.sct_newtype;
110                     eff = 0;
111                 }
112
113                 twork = 100 - eff;
114                 if (twork > bwork) {
115                     twork = bwork;
116                 }
117                 if (dchr[type].d_lcms > 0) {
118                     lcms = items[I_LCM];
119                     lcms = (int)(lcms / dchr[type].d_lcms);
120                     if (twork > lcms)
121                         twork = lcms;
122                 }
123                 if (dchr[type].d_hcms > 0) {
124                     hcms = items[I_HCM];
125                     hcms = (int)(hcms / dchr[type].d_hcms);
126                     if (twork > hcms)
127                         twork = hcms;
128                 }
129                 work -= twork;
130                 eff += twork;
131             } else if (eff < 100) {
132                 twork = 100 - eff;
133                 if (twork > bwork) {
134                     twork = bwork;
135                 }
136                 if (dchr[type].d_lcms > 0) {
137                     lcms = items[I_LCM];
138                     lcms = (int)(lcms / dchr[type].d_lcms);
139                     if (twork > lcms)
140                         twork = lcms;
141                 }
142                 if (dchr[type].d_hcms > 0) {
143                     hcms = items[I_HCM];
144                     hcms = (int)(hcms / dchr[type].d_hcms);
145                     if (twork > hcms)
146                         twork = hcms;
147                 }
148                 work -= twork;
149                 eff += twork;
150             }
151         } else {
152             eff = sect.sct_effic;
153             type = sect.sct_type;
154         }
155         if (nsect++ == 0) {
156             pr("EFFICIENCY SIMULATION\n");
157             pr("   sect  des    projected eff\n");
158         }
159         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
160         pr(" %c", dchr[type].d_mnem);
161         pr("    %3d%%\n", eff);
162     }
163     player->simulation = 0;
164     if (nsect == 0) {
165         if (player->argp[1])
166             pr("%s: No sector(s)\n", player->argp[1]);
167         else
168             pr("%s: No sector(s)\n", "");
169         return RET_FAIL;
170     } else
171         pr("%d sector%s\n", nsect, splur(nsect));
172     return RET_OK;
173 }