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