]> git.pond.sub.org Git - empserver/blob - src/lib/commands/conv.c
Update copyright notice
[empserver] / src / lib / commands / conv.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2015, 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  *  conv.c: Convert conquered populace into uw's
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1986
31  */
32
33 /*
34  * format: convert <SECTS> <NUMBER PER SECTOR>
35  */
36
37 #include <config.h>
38
39 #include "chance.h"
40 #include "commands.h"
41 #include "land.h"
42
43 int
44 conv(void)
45 {
46     struct natstr *natp;
47     struct sctstr sect;
48     struct nstr_sect nstr;
49     int uwtoconvert, newuw, totaluw, uw;
50     int maxpop, civ, mil, adj_mob, mob;
51     double security_extra = 1.0;
52     struct lndstr land;
53     struct nstr_item ni;
54
55     if (!snxtsct(&nstr, player->argp[1]))
56         return RET_SYN;
57     uwtoconvert = onearg(player->argp[2], "Number to convert: ");
58     if (uwtoconvert < 0)
59         return RET_SYN;
60
61     totaluw = 0;
62     while (nxtsct(&nstr, &sect)) {
63         if (!player->owner)
64             continue;
65         if (sect.sct_oldown == player->cnum)
66             continue;
67         natp = getnatp(sect.sct_own);
68         maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
69         civ = sect.sct_item[I_CIVIL];
70         mil = sect.sct_item[I_MILIT];
71
72         /*
73          * Military units count according to the number of
74          * mil in them. (i.e. attack/defense modifier don't
75          * count.
76          */
77         snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
78         while (nxtitem(&ni, &land)) {
79             mil += land.lnd_item[I_MILIT];
80
81             /* Anti-terrorist units count double */
82             if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
83
84                 /*
85                  * They also increase the efficiency of
86                  * the conversion process by 10% each.
87                  * (but they use 10 mobility doing it)
88                  */
89                 security_extra += .1;
90                 land.lnd_mobil -= 10;
91                 mil += land.lnd_item[I_MILIT];
92             }
93         }
94         /*
95          * Must have military control to convert captured civs.
96          */
97         if (mil * 10 < civ)
98             continue;
99         newuw = civ;
100         if (newuw > uwtoconvert)
101             newuw = uwtoconvert;
102         uw = sect.sct_item[I_UW];
103         if (newuw > maxpop - uw)
104             newuw = maxpop - uw;
105         if (newuw <= 0)
106             continue;
107         /*
108          * So entire civilian populations don't disappear immediately
109          * into re-education camps, charge a healthy mobility cost for
110          * conversions.
111          */
112         mob = sect.sct_mobil * 5;
113
114         /* security troops make conversion more effective */
115         adj_mob = ldround(((double)mob * security_extra), 1);
116
117         if (adj_mob < newuw)
118             newuw = adj_mob;
119         if (newuw <= 0)
120             continue;
121         if (player->dolcost + newuw * 1.5 > natp->nat_money) {
122             pr("You can't afford to convert %d civilians in %s!\n",
123                newuw, xyas(sect.sct_x, sect.sct_y, player->cnum));
124             break;
125         }
126         player->btused += (newuw - 1) / 100 + 1;
127         player->dolcost += newuw * 1.5;
128         if (newuw < mob)
129             mob = newuw;
130         sect.sct_item[I_UW] = newuw + uw;
131         civ -= newuw;
132         sect.sct_item[I_CIVIL] = civ;
133         mob = roundavg(mob * 0.2);
134         if (mob > sect.sct_mobil)
135             mob = sect.sct_mobil;
136         sect.sct_mobil -= mob;
137         pr("%3d conquered civilians converted in %s (%d)\n",
138            newuw, xyas(sect.sct_x, sect.sct_y, player->cnum), uw + newuw);
139         if (civ == 0) {
140             sect.sct_oldown = sect.sct_own;
141             pr("%s is now completely yours.\n",
142                xyas(sect.sct_x, sect.sct_y, player->cnum));
143         }
144         putsect(&sect);
145         totaluw += newuw;
146     }
147     pr("Total civilians converted: %d\n", totaluw);
148     pr("Paperwork at conversion places ... %d\n", player->btused);
149     return RET_OK;
150 }