]> git.pond.sub.org Git - empserver/blob - src/lib/commands/sabo.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / sabo.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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 "misc.h"
37 #include "land.h"
38 #include "nsc.h"
39 #include "file.h"
40 #include "commands.h"
41
42 int
43 sabo(void)
44 {
45     struct nstr_item ni;
46     struct lndstr land;
47     struct sctstr sect;
48     double odds;
49     int dam;
50
51     if (!snxtitem(&ni, EF_LAND, player->argp[1]))
52         return RET_SYN;
53
54     while (nxtitem(&ni, &land)) {
55         if (!player->owner)
56             continue;
57         if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
58             pr("%s is not a spy.\n", prland(&land));
59             continue;
60         }
61         if (land.lnd_ship >= 0) {
62             pr("%s is on ship %d.\n", prland(&land), land.lnd_ship);
63             continue;
64         }
65         if (land.lnd_land >= 0) {
66             pr("%s is on unit %d.\n", prland(&land), land.lnd_land);
67             continue;
68         }
69         if (!getsect(land.lnd_x, land.lnd_y, &sect))
70             continue;
71         if (land.lnd_item[I_SHELL] == 0) {
72             pr("%s has no shells.\n", prland(&land));
73             continue;
74         }
75         --land.lnd_item[I_SHELL];
76
77         odds = LND_SPY_DETECT_CHANCE(land.lnd_effic);
78         if (chance(odds)) {
79             wu(0, sect.sct_own,
80                "%s spy shot in %s during sabotage attempt.\n",
81                cname(player->cnum),
82                xyas(sect.sct_x, sect.sct_y, sect.sct_own));
83             pr("%s was shot and killed.\n", prland(&land));
84             land.lnd_effic = 0;
85             putland(land.lnd_uid, &land);
86             continue;
87         }
88
89         dam = landgun(3 * land.lnd_effic, 7);
90         if (sect.sct_item[I_SHELL] > 20)
91             dam += seagun(land.lnd_effic,
92                           random() % (sect.sct_item[I_SHELL] / 10));
93         if (sect.sct_item[I_PETROL] > 100)
94             dam += seagun(land.lnd_effic,
95                           random() % (sect.sct_item[I_PETROL] / 50));
96
97         pr("Explosion in %s causes %d damage.\n",
98            xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam);
99         if (sect.sct_own) {
100             wu(0, sect.sct_own,
101                "Sabotage in sector %s caused %d damage.\n",
102                xyas(sect.sct_x, sect.sct_y, sect.sct_own), dam);
103         }
104
105         /* hack: hide the spy so it don't gets blasted by sectdamage() */
106         land.lnd_own = 0;
107         putland(land.lnd_uid, &land);
108
109         sectdamage(&sect, dam, 0);
110         putsect(&sect);
111
112         land.lnd_own = player->cnum;
113         if (chance(odds)) {
114             pr("%s dies in explosion.\n", prland(&land));
115             land.lnd_effic = 0;
116         }
117         putland(land.lnd_uid, &land);
118     }
119     return RET_OK;
120 }