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