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