src/lib/commands/stre.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  *  stre.c: Calculate military strengths of sectors
00029  * 
00030  *  Known contributors to this file:
00031  *     Ken Stevens, 1995
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "combat.h"
00037 #include "commands.h"
00038 #include "land.h"
00039 #include "path.h"
00040 #include "ship.h"
00041 
00042 static double units_in_sector(struct combat *def);
00043 static void stre_hdr(void);
00044 
00045 int
00046 stre(void)
00047 {
00048     struct sctstr sect;
00049     int nsect = 0;
00050     struct nstr_sect nstr;
00051     double dtotal, r_total, eff;
00052     struct combat def[1];
00053     int dummy;
00054 
00055     if (!snxtsct(&nstr, player->argp[1]))
00056         return RET_SYN;
00057     prdate();
00058     nsect = 0;
00059     att_combat_init(def, EF_SECTOR);
00060     while (nxtsct(&nstr, &sect)) {
00061         if (!player->owner)
00062             continue;
00063         if (nsect++ == 0)
00064             stre_hdr();
00065         if (player->god)
00066             pr("%3d ", sect.sct_own);
00067         prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum);
00068         pr(" %c", dchr[sect.sct_type].d_mnem);
00069         pr("%4d%%", sect.sct_effic);
00070         def->x = nstr.x;
00071         def->y = nstr.y;
00072         def->set = 0;
00073         att_get_combat(def, 1);
00074         if (def->mil)
00075             pr("%5d", def->mil);
00076         else
00077             pr("%5s", "");
00078         dtotal = units_in_sector(def);
00079         if (dtotal > 0)
00080             pr("%7d", (int)dtotal);
00081         else
00082             pr("%7s", "");
00083 
00084         if (def->sct_type != SCT_MOUNT)
00085             r_total = att_reacting_units(def, 0, 0, &dummy, 9999999);
00086         else
00087             r_total = 0.0;
00088         def->own = 0;
00089         eff = att_combat_eff(def);
00090         if (sect.sct_own == sect.sct_oldown || player->god) {
00091             if (sect.sct_mines > 0)
00092                 pr("%7d", sect.sct_mines);
00093             else
00094                 pr("%7s", "");
00095             eff *= (1.0 + MIN(sect.sct_mines, 20) * 0.02);
00096         } else {
00097             pr("%7s", "?");
00098         }
00099         pr("%6.2f", eff);
00100         pr("%9d", (int)((dtotal + def->mil) * eff));
00101         if (r_total > 0)
00102             pr(" %9d", (int)(r_total * eff));
00103         else
00104             pr(" %9s", "");
00105         pr("%9d\n", (int)((dtotal + def->mil + r_total) * eff));
00106         /*
00107          * This command is quite compute intensive.  Yield the
00108          * processor after every sector, to keep the game responsive
00109          * for other players.
00110          */
00111         empth_yield();
00112     }
00113     if (!nsect) {
00114         if (player->argp[1])
00115             pr("%s: No sector(s)\n", player->argp[1]);
00116         else
00117             pr("%s: No sector(s)\n", "");
00118         return RET_FAIL;
00119     } else
00120         pr("%d sector%s\n", nsect, splur(nsect));
00121     return 0;
00122 }
00123 
00124 static double
00125 units_in_sector(struct combat *def)
00126 {
00127     double d_unit;
00128     double dtotal = 0.0;
00129     struct nstr_item ni;
00130     struct lndstr land;
00131 
00132     snxtitem_xy(&ni, EF_LAND, def->x, def->y);
00133     while (nxtitem(&ni, &land)) {
00134         if (land.lnd_own == 0)
00135             continue;
00136         if (land.lnd_own != def->own)
00137             continue;
00138         if (land.lnd_ship >= 0)
00139             continue;
00140         d_unit = defense_val(&land);
00141         if (!has_supply(&land))
00142             d_unit /= 2.0;
00143         dtotal += d_unit;
00144     }
00145     return dtotal;
00146 }
00147 
00148 static void
00149 stre_hdr(void)
00150 {
00151     if (player->god)
00152         pr("    ");
00153     pr("DEFENSE STRENGTH               land  sect   sector  reacting    total\n");
00154     if (player->god)
00155         pr("own ");
00156     pr("  sect       eff  mil  units  mines  mult  defense     units  defense\n");
00157 }

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