]> git.pond.sub.org Git - empserver/blob - src/lib/commands/sabo.c
44ff4c769e257d1695b6e744f6b6080aa9054620
[empserver] / src / lib / commands / sabo.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  sabo.c: Spy terrorist bombing
28  *
29  *  Known contributors to this file:
30  *     John Yockey, 2001
31  *     Markus Armbruster, 2003-2010
32  */
33
34 #include <config.h>
35
36 #include "chance.h"
37 #include "commands.h"
38 #include "land.h"
39
40 int
41 sabo(void)
42 {
43     struct nstr_item ni;
44     struct lndstr land, tmp;
45     struct sctstr sect;
46     double odds;
47     int dam;
48
49     if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
50         return RET_SYN;
51
52     while (nxtitem(&ni, &land)) {
53         if (!player->owner)
54             continue;
55         if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
56             pr("%s is not a spy.\n", prland(&land));
57             continue;
58         }
59         if (land.lnd_ship >= 0) {
60             pr("%s is on ship %d.\n", prland(&land), land.lnd_ship);
61             continue;
62         }
63         if (land.lnd_land >= 0) {
64             pr("%s is on unit %d.\n", prland(&land), land.lnd_land);
65             continue;
66         }
67         if (!getsect(land.lnd_x, land.lnd_y, &sect))
68             continue;
69         if (land.lnd_item[I_SHELL] == 0) {
70             pr("%s has no shells.\n", prland(&land));
71             continue;
72         }
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 = lnd_sabo(&land, sect.sct_item);
87         if (dam < 0)
88             continue;
89
90         pr("Explosion in %s causes %d damage.\n",
91            xyas(land.lnd_x, land.lnd_y, player->cnum), dam);
92         if (sect.sct_own) {
93             wu(0, sect.sct_own,
94                "Sabotage in sector %s caused %d damage.\n",
95                xyas(sect.sct_x, sect.sct_y, sect.sct_own), dam);
96         }
97
98         /* hack: hide the spy so it don't gets blasted by sectdamage() */
99         tmp = land;
100         tmp.lnd_own = 0;
101         putland(land.lnd_uid, &tmp);
102         land.lnd_seqno = tmp.lnd_seqno;
103
104         sectdamage(&sect, dam);
105         putsect(&sect);
106
107         if (chance(odds)) {
108             pr("%s dies in explosion.\n", prland(&land));
109             land.lnd_effic = 0;
110         }
111         putland(land.lnd_uid, &land);
112     }
113     return RET_OK;
114 }