]> git.pond.sub.org Git - empserver/blob - src/lib/commands/conv.c
Import of Empire 4.2.12
[empserver] / src / lib / commands / conv.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 "var.h"
41 #include "sect.h"
42 #include "nat.h"
43 #include "xy.h"
44 #include "nsc.h"
45 #include "file.h"
46 #include "land.h"
47 #include "commands.h"
48
49 long do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real);
50
51 int
52 conv(void)
53 {
54         struct  natstr *natp;
55         long    cash;
56         long    cost;
57         struct  nstr_sect nstr;
58         int     uwtoconvert;
59
60         natp = getnatp(player->cnum);
61         cash = natp->nat_money;
62         if (!snxtsct(&nstr, player->argp[1]))
63                 return RET_SYN;
64         uwtoconvert = onearg(player->argp[2], "Number to convert: ");
65         if (uwtoconvert < 0)
66                 return RET_SYN;
67         cost = do_conv(nstr, uwtoconvert, 0);
68         if (chkmoney(cost, cash, player->argp[3]))
69                 return RET_SYN;
70         return (int)do_conv(nstr, uwtoconvert, 1);
71 }
72
73 long
74 do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
75 {
76         struct sctstr sect;
77         int newuw, totaluw, uw;
78         int 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         totaluw = 0;
85         while (nxtsct(&nstr, &sect)) {
86                 if (!player->owner)
87                         continue;
88                 if (sect.sct_oldown == player->cnum)
89                         continue;
90                 civ = getvar(V_CIVIL, (s_char *)&sect, EF_SECTOR);
91                 if (civ == 0)
92                         continue;
93                 mil = getvar(V_MILIT, (s_char *)&sect, EF_SECTOR);
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, (s_char *)&land)){
102                         mil += lnd_getmil(&land);
103 /*                      mil += (lnd_getmil(&land) *
104                                 ((double)land.lnd_effic/100.0));*/
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 /*                              mil += (lchr[land.lnd_type].l_mil *
120                                         ((double)land.lnd_effic/100.0));*/
121                         }
122                 }
123                 /*
124                  * Must have military control to convert captured civs.
125                  */
126                 if (mil * 10 < civ)
127                         continue;
128                 newuw = civ;
129                 if (newuw > uwtoconvert)
130                         newuw = uwtoconvert;
131                 uw = getvar(V_UW, (s_char *)&sect, EF_SECTOR);
132                 if (uw > 999)
133                         continue;
134                 if (newuw > 999 - uw)
135                         newuw = 999 - uw;
136                 if (newuw == 0)
137                         continue;
138                 /*
139                  * So entire civilian populations don't disappear immediately
140                  * into re-education camps, charge a healthy mobility cost for
141                  * conversions.
142                  */
143                 mob = sect.sct_mobil * 5;
144
145                 /* security troops make conversion more effective */
146                 adj_mob = ldround(((double)mob*security_extra),1);
147
148                 if (adj_mob < newuw)
149                         newuw = adj_mob;
150                 if (newuw <= 0)
151                         continue;
152                 if (!for_real) {
153                         cost += newuw * 1.5;
154                         continue;
155                 }
156                 player->btused += (newuw - 1) / 100 + 1;
157                 player->dolcost += newuw * 1.5;
158                 if (newuw < mob)
159                         mob = newuw;
160                 if (putvar(V_UW, newuw + uw, (s_char *)&sect, EF_SECTOR) == 0) {
161                         pr("No room for new uw in %s\n",
162                                 xyas(sect.sct_x, sect.sct_y, player->cnum));
163                         continue;
164                 }
165                 civ -= newuw;
166                 putvar(V_CIVIL, civ, (s_char *)&sect, EF_SECTOR);
167                 mob = roundavg(mob * 0.2);
168                 if (mob > sect.sct_mobil)
169                         mob = sect.sct_mobil;
170                 sect.sct_mobil -= (u_char)mob;
171                 pr("%3d conquered civilians converted in %s (%d)\n",
172                         newuw, xyas(sect.sct_x, sect.sct_y, player->cnum),
173                         uw + newuw);
174                 if (civ == 0) {
175                         sect.sct_oldown = sect.sct_own;
176                         pr("%s is now completely yours.\n",
177                                 xyas(sect.sct_x, sect.sct_y, player->cnum));
178                 }
179                 putsect(&sect);
180                 totaluw += newuw;
181         }
182         if (!for_real)
183                 return cost;
184         pr("Total civilians converted: %d\n", totaluw);
185         pr("Paperwork at conversion places ... %d\n", player->btused);
186         return RET_OK;
187 }