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