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