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