]> git.pond.sub.org Git - empserver/blob - src/lib/commands/enli.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / commands / enli.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  *  enli.c: Enlist some military
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "var.h"
37 #include "xy.h"
38 #include "sect.h"
39 #include "nsc.h"
40 #include "nat.h"
41 #include "treaty.h"
42 #include "file.h"
43 #include "commands.h"
44
45 int
46 enli(void)
47 {
48     struct nstr_sect nstr;
49     struct sctstr sect;
50     struct natstr *natp;
51     int civ;
52     int mil;
53     int newmil;
54     int milwant;
55     int totalmil;
56     long reserve;
57     s_char *p;
58     int quota;
59     s_char prompt[128];
60     s_char buf[1024];
61
62     if (!snxtsct(&nstr, player->argp[1]))
63         return RET_SYN;
64     if (!trechk(player->cnum, 0, TRTENL))
65         return RET_FAIL;
66     natp = getnatp(player->cnum);
67     newmil = 500;
68     sprintf(prompt, "Number to enlist (max %d) : ", newmil);
69     if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
70         return RET_SYN;
71     if ((milwant = atoi(p)) > newmil)
72         milwant = newmil;
73     if (0 != (quota = (milwant < 0)))
74         milwant = -milwant;
75     totalmil = 0;
76     reserve = natp->nat_reserve;
77     if (reserve <= 0) {
78         pr("No military reserves left\n");
79         return RET_OK;
80     }
81     while (nxtsct(&nstr, &sect)) {
82         if (!player->owner)
83             continue;
84         if (sect.sct_oldown != player->cnum)
85             continue;
86         civ = getvar(V_CIVIL, (s_char *)&sect, EF_SECTOR);
87         if (civ == 0)
88             continue;
89         if (sect.sct_loyal > 70) {
90             pr("civilians refuse to report in %s!\n",
91                xyas(sect.sct_x, sect.sct_y, player->cnum));
92             continue;
93         }
94         if (sect.sct_mobil <= 0) {
95             pr("%s is out of mobility!\n",
96                xyas(sect.sct_x, sect.sct_y, player->cnum));
97         }
98         mil = getvar(V_MILIT, (s_char *)&sect, EF_SECTOR);
99         newmil = civ * 0.5;
100         if (quota) {
101             if (newmil > milwant - mil)
102                 newmil = milwant - mil;
103             if (newmil > 500)
104                 newmil = 500;
105         } else if (newmil > milwant)
106             newmil = milwant;
107         if (newmil > 999 - mil)
108             newmil = 999 - mil;
109         if (newmil <= 0)
110             continue;
111         if (newmil > reserve)
112             newmil = reserve;
113         if (!putvar(V_MILIT, newmil + mil, (s_char *)&sect, EF_SECTOR)) {
114             pr("No room for military in %s\n",
115                xyas(sect.sct_x, sect.sct_y, player->cnum));
116             continue;
117         }
118         reserve -= newmil;
119         totalmil += newmil;
120         putvar(V_CIVIL, civ - newmil, (s_char *)&sect, EF_SECTOR);
121         pr("%3d enlisted in %s (%d)\n", newmil,
122            xyas(sect.sct_x, sect.sct_y, player->cnum), mil + newmil);
123         if (sect.sct_mobil > 0) {
124             sect.sct_mobil = (u_char)((float)sect.sct_mobil *
125                                       (1.0 - (float)newmil / (float)civ));
126         }
127         putsect(&sect);
128         if (totalmil >= 10000) {
129             pr("Rioting in induction center interrupts enlistment\n");
130             break;
131         }
132         if (reserve == 0) {
133             pr("Military reserve exhausted\n");
134             break;
135         }
136     }
137     pr("Total new enlistment : %d\n", totalmil);
138     pr("Military reserves stand at %d\n", reserve);
139     if (totalmil) {
140         natp->nat_reserve -= totalmil;
141         putnat(natp);
142     }
143     if ((player->btused += roundavg((float)totalmil * 0.02)) > 0)
144         pr("Paperwork at recruiting stations ... %d\n", player->btused);
145     return RET_OK;
146 }