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