]> git.pond.sub.org Git - empserver/blob - src/lib/commands/conv.c
Remove a bunch of redundant casts.
[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 sctstr sect;
76     int newuw, totaluw, uw;
77     int civ, mil, adj_mob, mob;
78     double security_extra = 1.0;
79     struct lndstr land;
80     struct nstr_item ni;
81     long cost = 0;
82
83     totaluw = 0;
84     while (nxtsct(&nstr, &sect)) {
85         if (!player->owner)
86             continue;
87         if (sect.sct_oldown == player->cnum)
88             continue;
89         civ = sect.sct_item[I_CIVIL];
90         if (civ == 0)
91             continue;
92         mil = sect.sct_item[I_MILIT];
93
94         /*
95          * Military units count according to the number of
96          * mil in them. (i.e. attack/defense modified don't
97          * count.
98          */
99         snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
100         while (nxtitem(&ni, &land)) {
101             mil += lnd_getmil(&land);
102 /*                      mil += (lnd_getmil(&land) *
103                                 ((double)land.lnd_effic/100.0));*/
104
105             /* Anti-terrorist units count double */
106             if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
107
108                 /*
109                  * They also increase the efficiency of
110                  * the conversion process by 10% each.
111                  * (but they use 10 mobility doing it)
112                  */
113                 security_extra += .1;
114                 land.lnd_mobil -= 10;
115                 if (for_real)
116                     putland(land.lnd_uid, &land);
117                 mil += lnd_getmil(&land);
118 /*                              mil += (lchr[land.lnd_type].l_mil *
119                                         ((double)land.lnd_effic/100.0));*/
120             }
121         }
122         /*
123          * Must have military control to convert captured civs.
124          */
125         if (mil * 10 < civ)
126             continue;
127         newuw = civ;
128         if (newuw > uwtoconvert)
129             newuw = uwtoconvert;
130         uw = sect.sct_item[I_UW];
131         if (uw > 999)
132             continue;
133         if (newuw > 999 - uw)
134             newuw = 999 - uw;
135         if (newuw == 0)
136             continue;
137         /*
138          * So entire civilian populations don't disappear immediately
139          * into re-education camps, charge a healthy mobility cost for
140          * conversions.
141          */
142         mob = sect.sct_mobil * 5;
143
144         /* security troops make conversion more effective */
145         adj_mob = ldround(((double)mob * security_extra), 1);
146
147         if (adj_mob < newuw)
148             newuw = adj_mob;
149         if (newuw <= 0)
150             continue;
151         if (!for_real) {
152             cost += newuw * 1.5;
153             continue;
154         }
155         player->btused += (newuw - 1) / 100 + 1;
156         player->dolcost += newuw * 1.5;
157         if (newuw < mob)
158             mob = newuw;
159         sect.sct_item[I_UW] = newuw + uw;
160         civ -= newuw;
161         sect.sct_item[I_CIVIL] = civ;
162         mob = roundavg(mob * 0.2);
163         if (mob > sect.sct_mobil)
164             mob = sect.sct_mobil;
165         sect.sct_mobil -= (u_char)mob;
166         pr("%3d conquered civilians converted in %s (%d)\n",
167            newuw, xyas(sect.sct_x, sect.sct_y, player->cnum), uw + newuw);
168         if (civ == 0) {
169             sect.sct_oldown = sect.sct_own;
170             pr("%s is now completely yours.\n",
171                xyas(sect.sct_x, sect.sct_y, player->cnum));
172         }
173         putsect(&sect);
174         totaluw += newuw;
175     }
176     if (!for_real)
177         return cost;
178     pr("Total civilians converted: %d\n", totaluw);
179     pr("Paperwork at conversion places ... %d\n", player->btused);
180     return RET_OK;
181 }