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