src/lib/commands/setres.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  *  setres.c: Set resources of a sector
00029  * 
00030  *  Known contributors to this file:
00031  *     David Muir Sharnoff
00032  *     Karl Hagen
00033  *     Steve McClure, 1998
00034  */
00035 
00036 #include <config.h>
00037 
00038 #include "commands.h"
00039 
00040 /*
00041  * format: setres resource <amt>  <sect>
00042  */
00043 int
00044 setres(void)
00045 {
00046     struct sctstr sect;
00047     char *what;
00048     int amt;
00049     char *p;
00050     struct nstr_sect nstr;
00051     char buf[1024];
00052 
00053     if ((what = getstarg(player->argp[1],
00054                          "Set What (iron, gold, oil, uranium, fertility)? ",
00055                          buf)) == 0)
00056         return RET_SYN;
00057     switch (what[0]) {
00058     case 'i':
00059         if (!snxtsct(&nstr, player->argp[2]))
00060             return RET_SYN;
00061         while (nxtsct(&nstr, &sect) > 0) {
00062             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
00063                 (*p == '\0'))
00064                 return RET_SYN;
00065             amt = atoi(p);
00066             if (amt > 100)
00067                 amt = 100;
00068             if (amt < 0)
00069                 amt = 0;
00070             if (sect.sct_own != 0)
00071                 resnoise(&sect, 1, "Iron ore content",
00072                          (int)sect.sct_min, amt);
00073             sect.sct_min = (unsigned char)amt;
00074             putsect(&sect);
00075         }
00076         break;
00077     case 'g':
00078         if (!snxtsct(&nstr, player->argp[2]))
00079             return RET_SYN;
00080         while (nxtsct(&nstr, &sect) > 0) {
00081             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
00082                 (*p == '\0'))
00083                 return RET_SYN;
00084             amt = atoi(p);
00085             if (amt > 100)
00086                 amt = 100;
00087             if (amt < 0)
00088                 amt = 0;
00089             if (sect.sct_own != 0)
00090                 resnoise(&sect, 1, "Gold content",
00091                          (int)sect.sct_gmin, amt);
00092             sect.sct_gmin = (unsigned char)amt;
00093             putsect(&sect);
00094         }
00095         break;
00096     case 'o':
00097         if (!snxtsct(&nstr, player->argp[2]))
00098             return RET_SYN;
00099         while (nxtsct(&nstr, &sect) > 0) {
00100             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
00101                 (*p == '\0'))
00102                 return RET_SYN;
00103             amt = atoi(p);
00104             if (amt > 100)
00105                 amt = 100;
00106             if (amt < 0)
00107                 amt = 0;
00108             if (sect.sct_own != 0)
00109                 resnoise(&sect, 1, "Oil content", (int)sect.sct_oil, amt);
00110             sect.sct_oil = (unsigned char)amt;
00111             putsect(&sect);
00112         }
00113         break;
00114     case 'f':
00115         if (!snxtsct(&nstr, player->argp[2]))
00116             return RET_SYN;
00117         while (nxtsct(&nstr, &sect) > 0) {
00118             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
00119                 (*p == '\0'))
00120                 return RET_SYN;
00121             amt = atoi(p);
00122             if (amt > 100)
00123                 amt = 100;
00124             if (amt < 0)
00125                 amt = 0;
00126             if (sect.sct_own != 0)
00127                 resnoise(&sect, 1, "Fertility content",
00128                          (int)sect.sct_fertil, amt);
00129             sect.sct_fertil = (unsigned char)amt;
00130             putsect(&sect);
00131         }
00132         break;
00133     case 'u':
00134         if (!snxtsct(&nstr, player->argp[2]))
00135             return RET_SYN;
00136         while (nxtsct(&nstr, &sect) > 0) {
00137             if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
00138                 (*p == '\0'))
00139                 return RET_SYN;
00140             amt = atoi(p);
00141             if (amt > 100)
00142                 amt = 100;
00143             if (amt < 0)
00144                 amt = 0;
00145             if (sect.sct_own != 0)
00146                 resnoise(&sect, 1, "Uranium content",
00147                          (int)sect.sct_uran, amt);
00148             sect.sct_uran = (unsigned char)amt;
00149             putsect(&sect);
00150         }
00151         break;
00152     default:
00153         pr("huh?\n");
00154         return RET_SYN;
00155     }
00156     return RET_OK;
00157 }

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