src/lib/commands/newe.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  newe.c: Show new sector efficiency (projected)
00029  * 
00030  *  Known contributors to this file:
00031  *     Thomas Ruschak, 1993
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, &sect)) {
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], &sect);
00069             work = new_work(&sect,
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 }

Generated on Fri Mar 28 11:01:12 2008 for empserver by  doxygen 1.5.2