src/lib/commands/enli.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  enli.c: Enlist some military
00029  * 
00030  *  Known contributors to this file:
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, &sect)) {
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(&sect);
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 }

Generated on Fri Mar 28 11:01:12 2008 for empserver by  doxygen 1.5.2