]> git.pond.sub.org Git - empserver/blob - src/lib/commands/enli.c
Update copyright notice
[empserver] / src / lib / commands / enli.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2012, 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 "commands.h"
36 #include "treaty.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     long 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     if (!trechk(player->cnum, 0, TRTENL))
58         return RET_FAIL;
59     natp = getnatp(player->cnum);
60     newmil = 500;
61     sprintf(prompt, "Number to enlist (max %d) : ", newmil);
62     if (!(p = getstarg(player->argp[2], prompt, buf)))
63         return RET_SYN;
64     if ((milwant = atoi(p)) > newmil)
65         milwant = newmil;
66     if (0 != (quota = (milwant < 0)))
67         milwant = -milwant;
68     totalmil = 0;
69     reserve = natp->nat_reserve;
70     if (reserve <= 0) {
71         pr("No military reserves left\n");
72         return RET_OK;
73     }
74     while (nxtsct(&nstr, &sect)) {
75         if (!player->owner)
76             continue;
77         if (sect.sct_oldown != player->cnum)
78             continue;
79         civ = sect.sct_item[I_CIVIL];
80         if (civ == 0)
81             continue;
82         if (sect.sct_loyal > 70) {
83             pr("civilians refuse to report in %s!\n",
84                xyas(sect.sct_x, sect.sct_y, player->cnum));
85             continue;
86         }
87         if (sect.sct_mobil <= 0) {
88             pr("%s is out of mobility!\n",
89                xyas(sect.sct_x, sect.sct_y, player->cnum));
90         }
91         mil = sect.sct_item[I_MILIT];
92         newmil = civ * 0.5;
93         if (quota) {
94             if (newmil > milwant - mil)
95                 newmil = milwant - mil;
96             if (newmil > 500)
97                 newmil = 500;
98         } else if (newmil > milwant)
99             newmil = milwant;
100         if (newmil > 999 - mil)
101             newmil = 999 - mil;
102         if (newmil <= 0)
103             continue;
104         if (newmil > reserve)
105             newmil = reserve;
106         sect.sct_item[I_MILIT] = newmil + mil;
107         reserve -= newmil;
108         totalmil += newmil;
109         sect.sct_item[I_CIVIL] = civ - newmil;
110         pr("%3d enlisted in %s (%d)\n", newmil,
111            xyas(sect.sct_x, sect.sct_y, player->cnum), mil + newmil);
112         if (sect.sct_mobil > 0)
113             sect.sct_mobil *= 1.0 - (double)newmil / (double)civ;
114         putsect(&sect);
115         if (totalmil >= 10000) {
116             pr("Rioting in induction center interrupts enlistment\n");
117             break;
118         }
119         if (reserve == 0) {
120             pr("Military reserve exhausted\n");
121             break;
122         }
123     }
124     pr("Total new enlistment : %d\n", totalmil);
125     pr("Military reserves stand at %ld\n", reserve);
126     if (totalmil) {
127         natp->nat_reserve -= totalmil;
128         putnat(natp);
129     }
130     if ((player->btused += roundavg(totalmil * 0.02)) > 0)
131         pr("Paperwork at recruiting stations ... %d\n", player->btused);
132     return RET_OK;
133 }