src/lib/commands/sabo.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  *  sabo.c: Spy terrorist bombing
00029  * 
00030  *  Known contributors to this file:
00031  *     John Yockey, 2001
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "commands.h"
00037 #include "land.h"
00038 
00039 int
00040 sabo(void)
00041 {
00042     struct nstr_item ni;
00043     struct lndstr land;
00044     struct sctstr sect;
00045     double odds;
00046     int dam;
00047 
00048     if (!snxtitem(&ni, EF_LAND, player->argp[1]))
00049         return RET_SYN;
00050 
00051     while (nxtitem(&ni, &land)) {
00052         if (!player->owner)
00053             continue;
00054         if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
00055             pr("%s is not a spy.\n", prland(&land));
00056             continue;
00057         }
00058         if (land.lnd_ship >= 0) {
00059             pr("%s is on ship %d.\n", prland(&land), land.lnd_ship);
00060             continue;
00061         }
00062         if (land.lnd_land >= 0) {
00063             pr("%s is on unit %d.\n", prland(&land), land.lnd_land);
00064             continue;
00065         }
00066         if (!getsect(land.lnd_x, land.lnd_y, &sect))
00067             continue;
00068         if (land.lnd_item[I_SHELL] == 0) {
00069             pr("%s has no shells.\n", prland(&land));
00070             continue;
00071         }
00072         --land.lnd_item[I_SHELL];
00073 
00074         odds = LND_SPY_DETECT_CHANCE(land.lnd_effic);
00075         if (chance(odds)) {
00076             wu(0, sect.sct_own,
00077                "%s spy shot in %s during sabotage attempt.\n",
00078                cname(player->cnum),
00079                xyas(sect.sct_x, sect.sct_y, sect.sct_own));
00080             pr("%s was shot and killed.\n", prland(&land));
00081             land.lnd_effic = 0;
00082             putland(land.lnd_uid, &land);
00083             continue;
00084         }
00085 
00086         dam = landgun(3 * land.lnd_effic, 7);
00087         if (sect.sct_item[I_SHELL] > 20)
00088             dam += seagun(land.lnd_effic,
00089                           random() % (sect.sct_item[I_SHELL] / 10));
00090         if (sect.sct_item[I_PETROL] > 100)
00091             dam += seagun(land.lnd_effic,
00092                           random() % (sect.sct_item[I_PETROL] / 50));
00093 
00094         pr("Explosion in %s causes %d damage.\n",
00095            xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam);
00096         if (sect.sct_own) {
00097             wu(0, sect.sct_own,
00098                "Sabotage in sector %s caused %d damage.\n",
00099                xyas(sect.sct_x, sect.sct_y, sect.sct_own), dam);
00100         }
00101 
00102         /* hack: hide the spy so it don't gets blasted by sectdamage() */
00103         land.lnd_own = 0;
00104         putland(land.lnd_uid, &land);
00105 
00106         sectdamage(&sect, dam, 0);
00107         putsect(&sect);
00108 
00109         land.lnd_own = player->cnum;
00110         if (chance(odds)) {
00111             pr("%s dies in explosion.\n", prland(&land));
00112             land.lnd_effic = 0;
00113         }
00114         putland(land.lnd_uid, &land);
00115     }
00116     return RET_OK;
00117 }

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