src/lib/commands/rada.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  *  rada.c: Do radar from a ship/unit/sector
00029  * 
00030  *  Known contributors to this file:
00031  *     Ron Koenderink, 2006
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "commands.h"
00037 #include "optlist.h"
00038 #include "empobj.h"
00039 
00040 int
00041 rada(void)
00042 {
00043     return radar(EF_SHIP);
00044 }
00045 
00046 int
00047 lrad(void)
00048 {
00049     return radar(EF_LAND);
00050 }
00051 
00052 int
00053 radar(short type)
00054 {
00055     char *cp;
00056     double tf;
00057     double tech;
00058     struct nstr_item ni;
00059     struct nstr_sect ns;
00060     union empobj_storage item;
00061     char buf[1024];
00062     char prompt[80];
00063 
00064     sprintf(prompt, "Radar from (%s # or sector(s)) : ", ef_nameof(type));
00065     cp = getstarg(player->argp[1], prompt, buf);
00066                       
00067     if (cp == 0)
00068         return RET_SYN;
00069     switch (sarg_type(cp)) {
00070     case NS_AREA:
00071         if (!snxtsct(&ns, cp))
00072             return RET_SYN;
00073         tech = tfact(player->cnum, 8.0);
00074         if (tech > WORLD_Y / 4.0)
00075             tech = WORLD_Y / 4.0;
00076         if (tech > WORLD_X / 8.0)
00077             tech = WORLD_X / 8.0;
00078         while (nxtsct(&ns, &item.sect)) {
00079             if (item.sect.sct_type != SCT_RADAR)
00080                 continue;
00081             if (!player->owner)
00082                 continue;
00083             radmap(item.sect.sct_x, item.sect.sct_y, item.sect.sct_effic,
00084                    (int)(tech * 2.0), 0.0);
00085         }
00086         break;
00087     case NS_LIST:
00088     case NS_GROUP:
00089         /* assumes a NS_LIST return is a unit no */
00090         if (!snxtitem(&ni, type, cp)) {
00091             pr("Specify at least one %s\n", ef_nameof(type));
00092             return RET_SYN;
00093         }
00094         while (nxtitem(&ni, &item)) {
00095             if (!player->owner)
00096                 continue;
00097             tf = 0.0;
00098             if (type == EF_SHIP) {
00099                 if (mchr[(int)item.ship.shp_type].m_flags & M_SONAR)
00100                     tf = techfact(item.ship.shp_tech, 1.0);
00101                 tech = techfact(item.ship.shp_tech,
00102                     mchr[(int)item.ship.shp_type].m_vrnge);
00103             } else {
00104                 if (!(lchr[(int)item.land.lnd_type].l_flags & L_RADAR)) {
00105                     pr("%s can't use radar!\n", prland(&item.land));
00106                     continue;
00107                 }
00108                 if (item.land.lnd_ship >= 0) {
00109                     pr("Units on ships can't use radar!\n");
00110                     continue;
00111                 }
00112                 tech = techfact(item.land.lnd_tech, item.land.lnd_spy);
00113             }
00114 
00115             pr("%s at ", obj_nameof(&item.gen));
00116             if (tech > WORLD_Y / 2.0)
00117                 tech = WORLD_Y / 2.0;
00118             if (tech > WORLD_X / 4.0)
00119                 tech = WORLD_X / 4.0;
00120             radmap(item.gen.x, item.gen.y, item.gen.effic,
00121                    (int)tech, tf);
00122         }
00123         break;
00124     default:
00125         pr("Must use a %s or sector specifier\n", ef_nameof(type));
00126         return RET_SYN;
00127     }
00128     return RET_OK;
00129 }

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