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