]> git.pond.sub.org Git - empserver/blob - src/lib/commands/sabo.c
Update copyright notice
[empserver] / src / lib / commands / sabo.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  sabo.c: Spy terrorist bombing
29  *
30  *  Known contributors to this file:
31  *     John Yockey, 2001
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37 #include "land.h"
38
39 int
40 sabo(void)
41 {
42     struct nstr_item ni;
43     struct lndstr land;
44     struct sctstr sect;
45     double odds;
46     int dam;
47
48     if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
49         return RET_SYN;
50
51     while (nxtitem(&ni, &land)) {
52         if (!player->owner)
53             continue;
54         if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
55             pr("%s is not a spy.\n", prland(&land));
56             continue;
57         }
58         if (land.lnd_ship >= 0) {
59             pr("%s is on ship %d.\n", prland(&land), land.lnd_ship);
60             continue;
61         }
62         if (land.lnd_land >= 0) {
63             pr("%s is on unit %d.\n", prland(&land), land.lnd_land);
64             continue;
65         }
66         if (!getsect(land.lnd_x, land.lnd_y, &sect))
67             continue;
68         if (land.lnd_item[I_SHELL] == 0) {
69             pr("%s has no shells.\n", prland(&land));
70             continue;
71         }
72         --land.lnd_item[I_SHELL];
73
74         odds = LND_SPY_DETECT_CHANCE(land.lnd_effic);
75         if (chance(odds)) {
76             wu(0, sect.sct_own,
77                "%s spy shot in %s during sabotage attempt.\n",
78                cname(player->cnum),
79                xyas(sect.sct_x, sect.sct_y, sect.sct_own));
80             pr("%s was shot and killed.\n", prland(&land));
81             land.lnd_effic = 0;
82             putland(land.lnd_uid, &land);
83             continue;
84         }
85
86         dam = fortgun(3 * land.lnd_effic, 7);
87         if (sect.sct_item[I_SHELL] > 20)
88             dam += seagun(land.lnd_effic,
89                           random() % (sect.sct_item[I_SHELL] / 10));
90         if (sect.sct_item[I_PETROL] > 100)
91             dam += seagun(land.lnd_effic,
92                           random() % (sect.sct_item[I_PETROL] / 50));
93
94         pr("Explosion in %s causes %d damage.\n",
95            xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam);
96         if (sect.sct_own) {
97             wu(0, sect.sct_own,
98                "Sabotage in sector %s caused %d damage.\n",
99                xyas(sect.sct_x, sect.sct_y, sect.sct_own), dam);
100         }
101
102         /* hack: hide the spy so it don't gets blasted by sectdamage() */
103         land.lnd_own = 0;
104         putland(land.lnd_uid, &land);
105
106         sectdamage(&sect, dam);
107         putsect(&sect);
108
109         land.lnd_own = player->cnum;
110         if (chance(odds)) {
111             pr("%s dies in explosion.\n", prland(&land));
112             land.lnd_effic = 0;
113         }
114         putland(land.lnd_uid, &land);
115     }
116     return RET_OK;
117 }