]> git.pond.sub.org Git - empserver/blob - src/lib/commands/shoo.c
commands: Rename the command functions
[empserver] / src / lib / commands / shoo.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2021, 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  *     Markus Armbruster, 2004-2016
32  */
33
34 #include <config.h>
35
36 #include "chance.h"
37 #include "commands.h"
38 #include "item.h"
39 #include "news.h"
40
41 int
42 c_shoot(void)
43 {
44     struct sctstr sect;
45     struct nstr_sect nstr;
46     int seceff, nshot;
47     double secstr, m;
48     i_type item;
49     struct ichrstr *ip;
50     int targets;
51     char *p;
52     char prompt[128];
53     char buf[1024];
54
55     ip = whatitem(player->argp[1], "Shoot what <civ or uw> ");
56     if (!ip || (ip->i_uid != I_CIVIL && ip->i_uid != I_UW))
57         return RET_SYN;
58     item = ip->i_uid;
59     if (!snxtsct(&nstr, player->argp[2]))
60         return RET_SYN;
61     sprintf(prompt, "number of %s to shoot? ", ip->i_name);
62     p = getstarg(player->argp[3], prompt, buf);
63     if (!p || (targets = atoi(p)) <= 0)
64         return RET_SYN;
65     while (nxtsct(&nstr, &sect)) {
66         if (!player->owner)
67             continue;
68         secstr = security_strength(&sect, &seceff);
69         if (sect.sct_item[item] == 0 || sect.sct_item[I_CIVIL] > secstr * 10)
70             continue;
71         nshot = sect.sct_item[item] > targets ? targets : sect.sct_item[item];
72         if (nshot > sect.sct_mobil * 5)
73             nshot = sect.sct_mobil * 5;
74         m = nshot / 5.0;
75         /*
76          * Security units reduce mobility cost of shooting people by
77          * 10% per 100% unit efficiency, up to a 50% reduction.
78          */
79         if (seceff > 500)
80             seceff = 500;
81         m *= 1.0 - seceff / 1000.0;
82         if (nshot <= 0)
83             continue;
84         if (m < 0)
85             m = 0;
86         if (m > sect.sct_mobil)
87             m = sect.sct_mobil;
88         sect.sct_mobil -= roundavg(m);
89         sect.sct_item[item] -= nshot;
90         pr("BANG!! (thump) %d %s shot in %s!\n",
91            nshot, ip->i_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
92         if (chance(nshot / 100.0))
93             nreport(player->cnum, N_SHOOT_CIV, sect.sct_oldown, 1);
94         if (sect.sct_item[item] <= 0 && item == I_CIVIL
95             && (sect.sct_own != sect.sct_oldown)) {
96             sect.sct_oldown = sect.sct_own;
97             pr("  %s is now completely yours\n",
98                xyas(sect.sct_x, sect.sct_y, player->cnum));
99         }
100         putsect(&sect);
101     }
102     return RET_OK;
103 }