]> git.pond.sub.org Git - empserver/blob - src/lib/commands/sabo.c
Indented with src/scripts/indent-emp.
[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 "deity.h"
43 #include "map.h"
44 #include "commands.h"
45 */
46
47 #include "misc.h"
48 #include "var.h"
49 #include "land.h"
50 #include "nsc.h"
51 #include "file.h"
52
53 int
54 sabo(void)
55 {
56     struct nstr_item ni;
57     struct lndstr land;
58     struct sctstr sect;
59     double odds;
60     int vec[I_MAX + 1];
61     int dam;
62
63     if (!snxtitem(&ni, EF_LAND, player->argp[1]))
64         return RET_SYN;
65
66     while (nxtitem(&ni, (s_char *)&land)) {
67         if (!player->owner)
68             continue;
69         if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
70             pr("%s is not a spy.\n", prland(&land));
71             continue;
72         }
73         if (land.lnd_ship >= 0) {
74             pr("%s is on ship %d.\n", prland(&land), land.lnd_ship);
75             continue;
76         }
77         if (land.lnd_land >= 0) {
78             pr("%s is on unit %d.\n", prland(&land), land.lnd_land);
79             continue;
80         }
81         if (!getsect(land.lnd_x, land.lnd_y, &sect))
82             continue;
83         getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND);
84         if (vec[I_SHELL] == 0) {
85             pr("%s has no shells.\n", prland(&land));
86             continue;
87         }
88         putvar(V_SHELL, vec[I_SHELL] - 1, (s_char *)&land, EF_LAND);
89
90         odds = (100 - land.lnd_effic) / 100.0 + .10;
91         if (chance(odds)) {
92             wu(0, sect.sct_own,
93                "%s spy shot in %s during sabotage attempt.\n",
94                cname(player->cnum),
95                xyas(sect.sct_x, sect.sct_y, sect.sct_own));
96             pr("%s was shot and killed.\n", prland(&land));
97             land.lnd_effic = 0;
98             putland(land.lnd_uid, &land);
99             continue;
100         }
101
102         land.lnd_own = 0;
103         putland(land.lnd_uid, &land);
104
105         getvec(VT_ITEM, vec, (s_char *)&sect, EF_SECTOR);
106         dam = landgun(3 * land.lnd_effic, 7);
107         if (vec[I_SHELL] > 20)
108             dam += seagun(land.lnd_effic, random() % (vec[I_SHELL] / 10));
109         if (vec[I_PETROL] > 100)
110             dam += seagun(land.lnd_effic, random() % (vec[I_PETROL] / 50));
111
112         pr("Explosion in %s causes %d damage.\n",
113            xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam);
114         if (sect.sct_own) {
115             wu(0, sect.sct_own,
116                "Sabotage in sector %s caused %d damage.\n",
117                xyas(sect.sct_x, sect.sct_y, sect.sct_own), dam);
118         }
119         sectdamage(&sect, dam, 0);
120         putsect(&sect);
121
122         land.lnd_own = player->cnum;
123         if (chance(odds)) {
124             pr("%s dies in explosion.\n", prland(&land));
125             land.lnd_effic = 0;
126         }
127         putland(land.lnd_uid, &land);
128     }
129     return RET_OK;
130 }