src/lib/commands/give.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  *  give.c: give stuff to countries (deity)
00029  * 
00030  *  Known contributors to this file:
00031  *     David Muir Sharnoff
00032  *     Steve McClure, 1997
00033  */
00034 
00035 #include <config.h>
00036 
00037 #include "commands.h"
00038 #include "item.h"
00039 #include "news.h"
00040 #include "optlist.h"
00041 
00042 /*
00043  * format: give <commod> <sect> <amt>
00044  */
00045 int
00046 give(void)
00047 {
00048     struct sctstr sect;
00049     int amt;
00050     struct ichrstr *ip;
00051     int m, n;
00052     char *p;
00053     struct nstr_sect nstr;
00054     char buf[1024];
00055 
00056     if (!(ip = whatitem(player->argp[1], "which commodity? ")))
00057         return RET_SYN;
00058     if (!snxtsct(&nstr, player->argp[2]))
00059         return RET_SYN;
00060     while (nxtsct(&nstr, &sect) > 0) {
00061         p = getstarg(player->argp[3], "how much : ", buf);
00062         if (p == 0 || *p == '\0')
00063             return RET_SYN;
00064         if ((amt = atoi(p)) == 0)
00065             return RET_SYN;
00066         n = sect.sct_item[ip->i_uid];
00067         if (amt < 0 && -amt > n) {
00068             m = 0;
00069         } else if (amt > 0 && amt + n > ITEM_MAX) {
00070             m = ITEM_MAX;
00071         } else
00072             m = n + amt;
00073         sect.sct_item[ip->i_uid] = m;
00074         putsect(&sect);
00075         if (sect.sct_own != 0 && m != n) {
00076             if (m > n) {
00077                 if (opt_GODNEWS)
00078                     nreport(player->cnum, N_GIFT, sect.sct_own, 1);
00079                 wu(player->cnum, sect.sct_own, "%s gave you %d %s in %s\n",
00080                    cname(player->cnum), m - n, ip->i_name,
00081                    xyas(sect.sct_x, sect.sct_y, sect.sct_own));
00082             } else {
00083                 if (opt_GODNEWS)
00084                     nreport(sect.sct_own, N_TAKE, player->cnum, 1);
00085                 wu(player->cnum, sect.sct_own, "%s stole %d %s from %s\n",
00086                    cname(player->cnum), n - m, ip->i_name,
00087                    xyas(sect.sct_x, sect.sct_y, sect.sct_own));
00088             }
00089         }
00090         pr("%d %s in %s\n", m, ip->i_name,
00091            xyas(sect.sct_x, sect.sct_y, player->cnum));
00092     }
00093     return RET_OK;
00094 }

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