]> git.pond.sub.org Git - empserver/blob - src/lib/commands/enli.c
daa0d8ec4ef1c74810108c8838b86b5343ba9b11
[empserver] / src / lib / commands / enli.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  enli.c: Enlist some military
28  *
29  *  Known contributors to this file:
30  *
31  */
32
33 #include <config.h>
34
35 #include "chance.h"
36 #include "commands.h"
37
38 int
39 enli(void)
40 {
41     struct nstr_sect nstr;
42     struct sctstr sect;
43     struct natstr *natp;
44     int civ;
45     int mil;
46     int newmil;
47     int milwant;
48     int totalmil;
49     int reserve;
50     char *p;
51     int quota;
52     char prompt[128];
53     char buf[1024];
54
55     if (!snxtsct(&nstr, player->argp[1]))
56         return RET_SYN;
57     natp = getnatp(player->cnum);
58     newmil = 500;
59     sprintf(prompt, "Number to enlist (max %d) : ", newmil);
60     if (!(p = getstarg(player->argp[2], prompt, buf)))
61         return RET_SYN;
62     if ((milwant = atoi(p)) > newmil)
63         milwant = newmil;
64     if (0 != (quota = (milwant < 0)))
65         milwant = -milwant;
66     totalmil = 0;
67     reserve = natp->nat_reserve;
68     if (reserve <= 0) {
69         pr("No military reserves left\n");
70         return RET_OK;
71     }
72     while (nxtsct(&nstr, &sect)) {
73         if (!player->owner)
74             continue;
75         if (sect.sct_oldown != player->cnum)
76             continue;
77         civ = sect.sct_item[I_CIVIL];
78         if (civ == 0)
79             continue;
80         if (sect.sct_loyal > 70) {
81             pr("civilians refuse to report in %s!\n",
82                xyas(sect.sct_x, sect.sct_y, player->cnum));
83             continue;
84         }
85         if (sect.sct_mobil <= 0) {
86             pr("%s is out of mobility!\n",
87                xyas(sect.sct_x, sect.sct_y, player->cnum));
88         }
89         mil = sect.sct_item[I_MILIT];
90         newmil = civ * 0.5;
91         if (quota) {
92             if (newmil > milwant - mil)
93                 newmil = milwant - mil;
94             if (newmil > 500)
95                 newmil = 500;
96         } else if (newmil > milwant)
97             newmil = milwant;
98         if (newmil > 999 - mil)
99             newmil = 999 - mil;
100         if (newmil <= 0)
101             continue;
102         if (newmil > reserve)
103             newmil = reserve;
104         sect.sct_item[I_MILIT] = newmil + mil;
105         reserve -= newmil;
106         totalmil += newmil;
107         sect.sct_item[I_CIVIL] = civ - newmil;
108         pr("%3d enlisted in %s (%d)\n", newmil,
109            xyas(sect.sct_x, sect.sct_y, player->cnum), mil + newmil);
110         if (sect.sct_mobil > 0)
111             sect.sct_mobil *= 1.0 - (double)newmil / (double)civ;
112         putsect(&sect);
113         if (totalmil >= 10000) {
114             pr("Rioting in induction center interrupts enlistment\n");
115             break;
116         }
117         if (reserve == 0) {
118             pr("Military reserve exhausted\n");
119             break;
120         }
121     }
122     pr("Total new enlistment : %d\n", totalmil);
123     pr("Military reserves stand at %d\n", reserve);
124     if (totalmil) {
125         natp->nat_reserve -= totalmil;
126         putnat(natp);
127     }
128     if ((player->btused += roundavg(totalmil * 0.02)) > 0)
129         pr("Paperwork at recruiting stations ... %d\n", player->btused);
130     return RET_OK;
131 }