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