]> git.pond.sub.org Git - empserver/blob - src/lib/commands/rada.c
3dd6ec1e1a524b47597c4cf340e15974c96ac679
[empserver] / src / lib / commands / rada.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  rada.c: Do radar from a ship/unit/sector
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include <config.h>
35
36 #include <ctype.h>
37 #include "commands.h"
38 #include "optlist.h"
39 #include "empobj.h"
40
41 int
42 rada(void)
43 {
44     return radar(EF_SHIP);
45 }
46
47 int
48 lrad(void)
49 {
50     return radar(EF_LAND);
51 }
52
53 int
54 radar(short type)
55 {
56     char *cp;
57     double tf;
58     double tech;
59     struct nstr_item ni;
60     struct nstr_sect ns;
61     union empobj_storage item;
62     char buf[1024];
63     char prompt[80];
64
65     sprintf(prompt, "Radar from (%s # or sector(s)) : ", ef_nameof(type));
66     cp = getstarg(player->argp[1], prompt, buf);
67                       
68     if (cp == 0)
69         return RET_SYN;
70     switch (sarg_type(cp)) {
71     case NS_AREA:
72         if (!snxtsct(&ns, cp))
73             return RET_SYN;
74         tech = tfact(player->cnum, 8.0);
75         if (tech > WORLD_Y / 4.0)
76             tech = WORLD_Y / 4.0;
77         if (tech > WORLD_X / 8.0)
78             tech = WORLD_X / 8.0;
79         while (nxtsct(&ns, &item.sect)) {
80             if (item.sect.sct_type != SCT_RADAR)
81                 continue;
82             if (!player->owner)
83                 continue;
84             radmap(item.sect.sct_x, item.sect.sct_y, item.sect.sct_effic,
85                    (int)(tech * 2.0), 0.0);
86         }
87         break;
88     case NS_LIST:
89     case NS_GROUP:
90         /* assumes a NS_LIST return is a unit no */
91         if (!snxtitem(&ni, type, cp)) {
92             pr("Specify at least one %s\n", ef_nameof(type));
93             return RET_SYN;
94         }
95         while (nxtitem(&ni, &item)) {
96             if (!player->owner)
97                 continue;
98             tf = 0.0;
99             if (type == EF_SHIP) {
100                 if (mchr[(int)item.ship.shp_type].m_flags & M_SONAR)
101                     tf = techfact(item.ship.shp_tech, 1.0);
102                 tech = techfact(item.ship.shp_tech,
103                     mchr[(int)item.ship.shp_type].m_vrnge);
104             } else {
105                 if (!(lchr[(int)item.land.lnd_type].l_flags & L_RADAR)) {
106                     pr("%s can't use radar!\n", prland(&item.land));
107                     continue;
108                 }
109                 if (item.land.lnd_ship >= 0) {
110                     pr("Units on ships can't use radar!\n");
111                     continue;
112                 }
113                 tech = techfact(item.land.lnd_tech, item.land.lnd_spy);
114             }
115
116             pr("%s at ", obj_nameof(&item.gen));
117             if (tech > WORLD_Y / 2.0)
118                 tech = WORLD_Y / 2.0;
119             if (tech > WORLD_X / 4.0)
120                 tech = WORLD_X / 4.0;
121             radmap(item.gen.x, item.gen.y, item.gen.effic,
122                    (int)tech, tf);
123         }
124         break;
125     default:
126         pr("Must use a %s or sector specifier\n", ef_nameof(type));
127         return RET_SYN;
128     }
129     return RET_OK;
130 }