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