src/lib/commands/deli.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  *  deli.c: Set deliveries from a sector
00029  * 
00030  *  Known contributors to this file:
00031  *     
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "commands.h"
00037 #include "item.h"
00038 #include "path.h"
00039 
00040 int
00041 deli(void)
00042 {
00043     struct sctstr sect;
00044     int dir, del;
00045     struct ichrstr *ich;
00046     int thresh;
00047     int sx, sy;
00048     struct nstr_sect nstr;
00049     char buf[1024];
00050     char prompt[128];
00051     char *p;
00052 
00053     if ((ich = whatitem(player->argp[1], "deliver what? ")) == 0)
00054         return RET_SYN;
00055     /*
00056        if (ich->i_uid == I_CIVIL || ich->i_uid == I_MILIT) {
00057        pr("You cannot deliver people!\n");
00058        return RET_FAIL;
00059        }
00060      */
00061     if (!snxtsct(&nstr, player->argp[2]))
00062         return RET_SYN;
00063 
00064     while (!player->aborted && nxtsct(&nstr, &sect) > 0) {
00065         if (!player->owner)
00066             continue;
00067 
00068         del = sect.sct_del[ich->i_uid];
00069         thresh = del & ~0x7;
00070         dir = del & 0x7;
00071 
00072         sprintf(prompt, "%s %s %s threshold or direction or 'query'? ",
00073                 xyas(nstr.x, nstr.y, player->cnum),
00074                 dchr[sect.sct_type].d_name, ich->i_name);
00075         if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
00076             return RET_SYN;
00077         if (*p != 'q') {
00078             sprintf(prompt, "%s %s %s direction? ",
00079                     xyas(nstr.x, nstr.y, player->cnum),
00080                     dchr[sect.sct_type].d_name, ich->i_name);
00081             if (((*p >= '0') && (*p <= '9')) || *p == '+') {
00082                 thresh = atoi(p) & ~0x7;
00083                 if (*p == '+')
00084                     p = NULL;
00085                 else {
00086                     p = getstarg(player->argp[4], prompt, buf);
00087                 }
00088             }
00089             if (p && *p) {
00090                 dir = chkdir(*p, DIR_STOP, DIR_LAST);
00091                 if (dir < 0) {
00092                     pr("'%c' is not a valid direction...\n", *p);
00093                     direrr(NULL, NULL, NULL);
00094                     return RET_SYN;
00095                 }
00096             }
00097 
00098             if (!check_sect_ok(&sect))
00099                 continue;
00100 
00101             thresh = MIN(thresh, ITEM_MAX) & ~7;
00102             del = thresh | dir;
00103             sect.sct_del[ich->i_uid] = del;
00104             putsect(&sect);
00105         }
00106 
00107         if (!del)
00108             continue;
00109 
00110         sx = diroff[dir][0] + sect.sct_x;
00111         sy = diroff[dir][1] + sect.sct_y;
00112         pr("Deliver %s from %s @ %s to %s",
00113            ich->i_name,
00114            dchr[sect.sct_type].d_name,
00115            xyas(sect.sct_x, sect.sct_y, player->cnum),
00116            xyas(sx, sy, player->cnum));
00117         if (!(del & ~0x7))
00118             pr("\n");
00119         else
00120             pr(" (cutoff %d)\n", thresh);
00121     }
00122 
00123     return RET_OK;
00124 }

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