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