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