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