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