src/lib/commands/shoo.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  *  shoo.c: Shoot some conquered populace or pigeons.
00029  * 
00030  *  Known contributors to this file:
00031  *     Dave Pare, 1986
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "commands.h"
00037 #include "item.h"
00038 #include "land.h"
00039 #include "news.h"
00040 #include "path.h"
00041 
00042 int
00043 shoo(void)
00044 {
00045     struct sctstr sect;
00046     struct nstr_sect nstr;
00047     struct nstr_item ni;
00048     int nshot;
00049     double m;
00050     i_type item;
00051     struct ichrstr *ip;
00052     struct lndstr land;
00053     int targets;
00054     char *p;
00055     int mil, nsec;
00056     char prompt[128];
00057     char buf[1024];
00058 
00059     ip = whatitem(player->argp[1], "Shoot what <civ or uw> ");
00060     if (ip == 0 || (ip->i_uid != I_CIVIL && ip->i_uid != I_UW))
00061         return RET_SYN;
00062     item = ip->i_uid;
00063     if (!snxtsct(&nstr, player->argp[2]))
00064         return RET_SYN;
00065     sprintf(prompt, "number of %s to shoot? ", ip->i_name);
00066     p = getstarg(player->argp[3], prompt, buf);
00067     if (p == 0 || (targets = atoi(p)) <= 0)
00068         return RET_SYN;
00069     while (nxtsct(&nstr, &sect)) {
00070         if (!player->owner)
00071             continue;
00072         mil = sect.sct_item[I_MILIT];
00073         nsec = 0;
00074         snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
00075         while (nxtitem(&ni, &land)) {
00076             mil += land.lnd_item[I_MILIT];
00077 
00078             if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
00079                 mil += land.lnd_item[I_MILIT];
00080                 nsec++;
00081             }
00082         }
00083 
00084         if (sect.sct_item[item] == 0 || sect.sct_item[I_CIVIL] > mil * 10)
00085             continue;
00086         nshot = sect.sct_item[item] > targets ? targets : sect.sct_item[item];
00087         if (nshot > sect.sct_mobil * 5)
00088             nshot = sect.sct_mobil * 5;
00089         m = nshot / 5.0;
00090         /*
00091          * Each security unit lowers the cost of
00092          * shooting a person by 10%. However, you
00093          * can't go lower than 50% of normal cost
00094          */
00095         if (nsec > 5)
00096             nsec = 5;
00097         m *= 1.0 - nsec * 0.1;
00098         if (nshot <= 0)
00099             continue;
00100         if (m < 0)
00101             m = 0;
00102         if (m > sect.sct_mobil)
00103             m = sect.sct_mobil;
00104         sect.sct_mobil -= roundavg(m);
00105         sect.sct_item[item] -= nshot;
00106         pr("BANG!! (thump) %d %s shot in %s!\n",
00107            nshot, ip->i_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
00108         if (chance(nshot / 100.0))
00109             nreport(player->cnum, N_SHOOT_CIV, sect.sct_oldown, 1);
00110         if (sect.sct_item[item] <= 0 && item == I_CIVIL
00111             && (sect.sct_own != sect.sct_oldown)) {
00112             sect.sct_oldown = sect.sct_own;
00113             pr("  %s is now completely yours\n",
00114                xyas(sect.sct_x, sect.sct_y, player->cnum));
00115         }
00116         putsect(&sect);
00117     }
00118     return RET_OK;
00119 }

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