00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include "commands.h"
00037 #include "item.h"
00038 #include "optlist.h"
00039
00040 int
00041 newe(void)
00042 {
00043 struct natstr *natp;
00044 struct sctstr sect;
00045 struct nstr_sect nstr;
00046 double work, lcms, hcms;
00047 int nsect;
00048 int civs = 0;
00049 int uws = 0;
00050 int bwork;
00051 int twork;
00052 int type;
00053 int eff;
00054 int maxpop;
00055
00056 if (!snxtsct(&nstr, player->argp[1]))
00057 return RET_SYN;
00058 player->simulation = 1;
00059 prdate();
00060 nsect = 0;
00061 while (nxtsct(&nstr, §)) {
00062 if (!player->owner)
00063 continue;
00064 if (!sect.sct_off) {
00065 civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
00066 uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
00067 natp = getnatp(sect.sct_own);
00068 maxpop = max_pop(natp->nat_level[NAT_RLEV], §);
00069 work = new_work(§,
00070 total_work(sect.sct_work, etu_per_update,
00071 civs, sect.sct_item[I_MILIT], uws,
00072 maxpop));
00073 bwork = work / 2;
00074
00075 type = sect.sct_type;
00076 eff = sect.sct_effic;
00077 if (sect.sct_newtype != type) {
00078 twork = (eff + 3) / 4;
00079 if (twork > bwork) {
00080 twork = bwork;
00081 }
00082 work -= twork;
00083 bwork -= twork;
00084 eff -= twork * 4;
00085 if (eff <= 0) {
00086 type = sect.sct_newtype;
00087 eff = 0;
00088 }
00089
00090 twork = 100 - eff;
00091 if (twork > bwork) {
00092 twork = bwork;
00093 }
00094 if (dchr[type].d_lcms > 0) {
00095 lcms = sect.sct_item[I_LCM];
00096 lcms = (int)(lcms / dchr[type].d_lcms);
00097 if (twork > lcms)
00098 twork = lcms;
00099 }
00100 if (dchr[type].d_hcms > 0) {
00101 hcms = sect.sct_item[I_HCM];
00102 hcms = (int)(hcms / dchr[type].d_hcms);
00103 if (twork > hcms)
00104 twork = hcms;
00105 }
00106 work -= twork;
00107 eff += twork;
00108 } else if (eff < 100) {
00109 twork = 100 - eff;
00110 if (twork > bwork) {
00111 twork = bwork;
00112 }
00113 if (dchr[type].d_lcms > 0) {
00114 lcms = sect.sct_item[I_LCM];
00115 lcms = (int)(lcms / dchr[type].d_lcms);
00116 if (twork > lcms)
00117 twork = lcms;
00118 }
00119 if (dchr[type].d_hcms > 0) {
00120 hcms = sect.sct_item[I_HCM];
00121 hcms = (int)(hcms / dchr[type].d_hcms);
00122 if (twork > hcms)
00123 twork = hcms;
00124 }
00125 work -= twork;
00126 eff += twork;
00127 }
00128 } else {
00129 eff = sect.sct_effic;
00130 type = sect.sct_type;
00131 }
00132 if (nsect++ == 0) {
00133 pr("EFFICIENCY SIMULATION\n");
00134 pr(" sect des projected eff\n");
00135 }
00136 prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
00137 pr(" %c", dchr[type].d_mnem);
00138 pr(" %3d%%\n", eff);
00139 }
00140 player->simulation = 0;
00141 if (nsect == 0) {
00142 if (player->argp[1])
00143 pr("%s: No sector(s)\n", player->argp[1]);
00144 else
00145 pr("%s: No sector(s)\n", "");
00146 return RET_FAIL;
00147 } else
00148 pr("%d sector%s\n", nsect, splur(nsect));
00149 return RET_OK;
00150 }