]> 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-2004, 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 "var.h"
38 #include "sect.h"
39 #include "news.h"
40 #include "item.h"
41 #include "path.h"
42 #include "nat.h"
43 #include "file.h"
44 #include "nsc.h"
45 #include "land.h"
46 #include "commands.h"
47
48 int
49 shoo(void)
50 {
51     struct sctstr sect;
52     struct nstr_sect nstr;
53     struct nstr_item ni;
54     int nshot;
55     int mob_cost;
56     double m;
57     int item;
58     struct ichrstr *ip;
59     struct lndstr land;
60     int targets;
61     s_char *p;
62     int mil, nsec;
63     s_char prompt[128];
64     s_char buf[128];
65
66     ip = whatitem(player->argp[1], "Shoot what <civ or uw> ");
67     if (ip == 0 || (ip->i_vtype != I_CIVIL && ip->i_vtype != I_UW))
68         return RET_SYN;
69     item = ip->i_vtype;
70     if (!snxtsct(&nstr, player->argp[2]))
71         return RET_SYN;
72     sprintf(prompt, "number of %s to shoot (max 999)? ", ip->i_name);
73     p = getstarg(player->argp[3], prompt, buf);
74     if (p == 0 || (targets = atoi(p)) <= 0)
75         return RET_SYN;
76     if (targets > 999)
77         targets = 999;
78     while (nxtsct(&nstr, &sect)) {
79         if (!player->owner)
80             continue;
81         mil = sect.sct_item[I_MILIT];
82         nsec = 0;
83         snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
84         while (nxtitem(&ni, (s_char *)&land)) {
85             mil += total_mil(&land);
86
87             if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
88                 mil += total_mil(&land);
89                 nsec++;
90             }
91         }
92
93         if (sect.sct_item[item] == 0 || sect.sct_item[I_CIVIL] > mil * 10)
94             continue;
95         nshot = sect.sct_item[item] > targets ? targets : sect.sct_item[item];
96         m = ((double)nshot + 4.0) / 5.0;
97
98         if (m > sect.sct_mobil) {
99             nshot = sect.sct_mobil * 5;
100             m = sect.sct_mobil;
101         }
102         /*
103          * Each security unit lowers the cost of
104          * shooting a person by 10%. However, you
105          * can't go lower than 50% of normal cost
106          */
107         if (nsec > 5)
108             nsec = 5;
109         m = ((float)m * (1.0 - ((float)nsec * 0.1)));
110         if (nshot <= 0)
111             continue;
112         if (m < 0)
113             m = 0;
114         if (m > sect.sct_mobil)
115             m = sect.sct_mobil;
116         mob_cost = roundavg(m);
117         sect.sct_mobil -= (u_char)mob_cost;
118         sect.sct_item[item] -= nshot;
119         pr("BANG!! (thump) %d %s shot in %s!\n",
120            nshot, ip->i_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
121         if (chance(nshot / 100.0))
122             nreport(player->cnum, N_SHOOT_CIV, sect.sct_oldown, 1);
123         if (sect.sct_item[item] <= 0 && item == I_CIVIL
124             && (sect.sct_own != sect.sct_oldown)) {
125             sect.sct_oldown = sect.sct_own;
126             pr("  %s is now completely yours\n",
127                xyas(sect.sct_x, sect.sct_y, player->cnum));
128         }
129         putsect(&sect);
130     }
131     return RET_OK;
132 }