00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include "commands.h"
00037 #include "treaty.h"
00038
00039 int
00040 enli(void)
00041 {
00042 struct nstr_sect nstr;
00043 struct sctstr sect;
00044 struct natstr *natp;
00045 int civ;
00046 int mil;
00047 int newmil;
00048 int milwant;
00049 int totalmil;
00050 long reserve;
00051 char *p;
00052 int quota;
00053 char prompt[128];
00054 char buf[1024];
00055
00056 if (!snxtsct(&nstr, player->argp[1]))
00057 return RET_SYN;
00058 if (!trechk(player->cnum, 0, TRTENL))
00059 return RET_FAIL;
00060 natp = getnatp(player->cnum);
00061 newmil = 500;
00062 sprintf(prompt, "Number to enlist (max %d) : ", newmil);
00063 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
00064 return RET_SYN;
00065 if ((milwant = atoi(p)) > newmil)
00066 milwant = newmil;
00067 if (0 != (quota = (milwant < 0)))
00068 milwant = -milwant;
00069 totalmil = 0;
00070 reserve = natp->nat_reserve;
00071 if (reserve <= 0) {
00072 pr("No military reserves left\n");
00073 return RET_OK;
00074 }
00075 while (nxtsct(&nstr, §)) {
00076 if (!player->owner)
00077 continue;
00078 if (sect.sct_oldown != player->cnum)
00079 continue;
00080 civ = sect.sct_item[I_CIVIL];
00081 if (civ == 0)
00082 continue;
00083 if (sect.sct_loyal > 70) {
00084 pr("civilians refuse to report in %s!\n",
00085 xyas(sect.sct_x, sect.sct_y, player->cnum));
00086 continue;
00087 }
00088 if (sect.sct_mobil <= 0) {
00089 pr("%s is out of mobility!\n",
00090 xyas(sect.sct_x, sect.sct_y, player->cnum));
00091 }
00092 mil = sect.sct_item[I_MILIT];
00093 newmil = civ * 0.5;
00094 if (quota) {
00095 if (newmil > milwant - mil)
00096 newmil = milwant - mil;
00097 if (newmil > 500)
00098 newmil = 500;
00099 } else if (newmil > milwant)
00100 newmil = milwant;
00101 if (newmil > 999 - mil)
00102 newmil = 999 - mil;
00103 if (newmil <= 0)
00104 continue;
00105 if (newmil > reserve)
00106 newmil = reserve;
00107 sect.sct_item[I_MILIT] = newmil + mil;
00108 reserve -= newmil;
00109 totalmil += newmil;
00110 sect.sct_item[I_CIVIL] = civ - newmil;
00111 pr("%3d enlisted in %s (%d)\n", newmil,
00112 xyas(sect.sct_x, sect.sct_y, player->cnum), mil + newmil);
00113 if (sect.sct_mobil > 0)
00114 sect.sct_mobil *= 1.0 - (double)newmil / (double)civ;
00115 putsect(§);
00116 if (totalmil >= 10000) {
00117 pr("Rioting in induction center interrupts enlistment\n");
00118 break;
00119 }
00120 if (reserve == 0) {
00121 pr("Military reserve exhausted\n");
00122 break;
00123 }
00124 }
00125 pr("Total new enlistment : %d\n", totalmil);
00126 pr("Military reserves stand at %ld\n", reserve);
00127 if (totalmil) {
00128 natp->nat_reserve -= totalmil;
00129 putnat(natp);
00130 }
00131 if ((player->btused += roundavg(totalmil * 0.02)) > 0)
00132 pr("Paperwork at recruiting stations ... %d\n", player->btused);
00133 return RET_OK;
00134 }