]> git.pond.sub.org Git - empserver/blob - src/lib/commands/shoo.c
Update copyright notice
[empserver] / src / lib / commands / shoo.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2014, 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  *  shoo.c: Shoot some conquered populace or pigeons.
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1986
31  */
32
33 #include <config.h>
34
35 #include "chance.h"
36 #include "commands.h"
37 #include "item.h"
38 #include "land.h"
39 #include "news.h"
40
41 int
42 shoo(void)
43 {
44     struct sctstr sect;
45     struct nstr_sect nstr;
46     struct nstr_item ni;
47     int nshot;
48     double m;
49     i_type item;
50     struct ichrstr *ip;
51     struct lndstr land;
52     int targets;
53     char *p;
54     int mil, nsec;
55     char prompt[128];
56     char buf[1024];
57
58     ip = whatitem(player->argp[1], "Shoot what <civ or uw> ");
59     if (!ip || (ip->i_uid != I_CIVIL && ip->i_uid != I_UW))
60         return RET_SYN;
61     item = ip->i_uid;
62     if (!snxtsct(&nstr, player->argp[2]))
63         return RET_SYN;
64     sprintf(prompt, "number of %s to shoot? ", ip->i_name);
65     p = getstarg(player->argp[3], prompt, buf);
66     if (!p || (targets = atoi(p)) <= 0)
67         return RET_SYN;
68     while (nxtsct(&nstr, &sect)) {
69         if (!player->owner)
70             continue;
71         mil = sect.sct_item[I_MILIT];
72         nsec = 0;
73         snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
74         while (nxtitem(&ni, &land)) {
75             mil += land.lnd_item[I_MILIT];
76
77             if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
78                 mil += land.lnd_item[I_MILIT];
79                 nsec++;
80             }
81         }
82
83         if (sect.sct_item[item] == 0 || sect.sct_item[I_CIVIL] > mil * 10)
84             continue;
85         nshot = sect.sct_item[item] > targets ? targets : sect.sct_item[item];
86         if (nshot > sect.sct_mobil * 5)
87             nshot = sect.sct_mobil * 5;
88         m = nshot / 5.0;
89         /*
90          * Each security unit lowers the cost of
91          * shooting a person by 10%. However, you
92          * can't go lower than 50% of normal cost
93          */
94         if (nsec > 5)
95             nsec = 5;
96         m *= 1.0 - nsec * 0.1;
97         if (nshot <= 0)
98             continue;
99         if (m < 0)
100             m = 0;
101         if (m > sect.sct_mobil)
102             m = sect.sct_mobil;
103         sect.sct_mobil -= roundavg(m);
104         sect.sct_item[item] -= nshot;
105         pr("BANG!! (thump) %d %s shot in %s!\n",
106            nshot, ip->i_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
107         if (chance(nshot / 100.0))
108             nreport(player->cnum, N_SHOOT_CIV, sect.sct_oldown, 1);
109         if (sect.sct_item[item] <= 0 && item == I_CIVIL
110             && (sect.sct_own != sect.sct_oldown)) {
111             sect.sct_oldown = sect.sct_own;
112             pr("  %s is now completely yours\n",
113                xyas(sect.sct_x, sect.sct_y, player->cnum));
114         }
115         putsect(&sect);
116     }
117     return RET_OK;
118 }