]> git.pond.sub.org Git - empserver/blob - src/lib/commands/newe.c
Doc fix.
[empserver] / src / lib / commands / newe.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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 <config.h>
35
36 #include "misc.h"
37 #include "player.h"
38 #include "xy.h"
39 #include "nsc.h"
40 #include "sect.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, lcms, hcms;
54     int nsect;
55     int civs = 0;
56     int uws = 0;
57     int bwork;
58     int twork;
59     int type;
60     int eff;
61     int maxpop;
62
63     if (!snxtsct(&nstr, player->argp[1]))
64         return RET_SYN;
65     player->simulation = 1;
66     prdate();
67     nsect = 0;
68     while (nxtsct(&nstr, &sect)) {
69         if (!player->owner)
70             continue;
71         if (!sect.sct_off) {
72             civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
73             uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
74             natp = getnatp(sect.sct_own);
75             maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
76             work = new_work(&sect,
77                             total_work(sect.sct_work, etu_per_update,
78                                        civs, sect.sct_item[I_MILIT], uws,
79                                        maxpop));
80             bwork = work / 2;
81
82             type = sect.sct_type;
83             eff = sect.sct_effic;
84             if (sect.sct_newtype != type) {
85                 twork = (eff + 3) / 4;
86                 if (twork > bwork) {
87                     twork = bwork;
88                 }
89                 work -= twork;
90                 bwork -= twork;
91                 eff -= twork * 4;
92                 if (eff <= 0) {
93                     type = sect.sct_newtype;
94                     eff = 0;
95                 }
96
97                 twork = 100 - eff;
98                 if (twork > bwork) {
99                     twork = bwork;
100                 }
101                 if (dchr[type].d_lcms > 0) {
102                     lcms = sect.sct_item[I_LCM];
103                     lcms = (int)(lcms / dchr[type].d_lcms);
104                     if (twork > lcms)
105                         twork = lcms;
106                 }
107                 if (dchr[type].d_hcms > 0) {
108                     hcms = sect.sct_item[I_HCM];
109                     hcms = (int)(hcms / dchr[type].d_hcms);
110                     if (twork > hcms)
111                         twork = hcms;
112                 }
113                 work -= twork;
114                 eff += twork;
115             } else if (eff < 100) {
116                 twork = 100 - eff;
117                 if (twork > bwork) {
118                     twork = bwork;
119                 }
120                 if (dchr[type].d_lcms > 0) {
121                     lcms = sect.sct_item[I_LCM];
122                     lcms = (int)(lcms / dchr[type].d_lcms);
123                     if (twork > lcms)
124                         twork = lcms;
125                 }
126                 if (dchr[type].d_hcms > 0) {
127                     hcms = sect.sct_item[I_HCM];
128                     hcms = (int)(hcms / dchr[type].d_hcms);
129                     if (twork > hcms)
130                         twork = hcms;
131                 }
132                 work -= twork;
133                 eff += twork;
134             }
135         } else {
136             eff = sect.sct_effic;
137             type = sect.sct_type;
138         }
139         if (nsect++ == 0) {
140             pr("EFFICIENCY SIMULATION\n");
141             pr("   sect  des    projected eff\n");
142         }
143         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
144         pr(" %c", dchr[type].d_mnem);
145         pr("    %3d%%\n", eff);
146     }
147     player->simulation = 0;
148     if (nsect == 0) {
149         if (player->argp[1])
150             pr("%s: No sector(s)\n", player->argp[1]);
151         else
152             pr("%s: No sector(s)\n", "");
153         return RET_FAIL;
154     } else
155         pr("%d sector%s\n", nsect, splur(nsect));
156     return RET_OK;
157 }