]> git.pond.sub.org Git - empserver/blob - src/lib/commands/rada.c
Update copyright notice.
[empserver] / src / lib / commands / rada.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  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 <ctype.h>
35 #include "misc.h"
36 #include "player.h"
37 #include "xy.h"
38 #include "var.h"
39 #include "ship.h"
40 #include "land.h"
41 #include "sect.h"
42 #include "nsc.h"
43 #include "nat.h"
44 #include "file.h"
45 #include "commands.h"
46 #include "optlist.h"
47
48 int
49 rada(void)
50 {
51     s_char *cp;
52     double tf;
53     double tech;
54     struct nstr_item ni;
55     struct nstr_sect ns;
56     struct shpstr ship;
57     struct lndstr land;
58     struct sctstr sect;
59     int from_unit;
60     s_char buf[1024];
61
62     from_unit = (**player->argp == 'l');
63
64     if (!from_unit)
65         cp = getstarg(player->argp[1],
66                       "Radar from (ship # or sector(s)) : ", buf);
67     else
68         cp = getstarg(player->argp[1],
69                       "Radar from (unit # or sector(s)) : ", buf);
70     if (cp == 0)
71         return RET_SYN;
72     switch (sarg_type(cp)) {
73     case NS_AREA:
74         if (!snxtsct(&ns, cp))
75             return RET_SYN;
76         tech = tfact(player->cnum, 8.0);
77         if (tech > ((double)WORLD_Y / 4.0))
78             tech = ((double)WORLD_Y / 4.0);
79         if (tech > ((double)WORLD_X / 8.0))
80             tech = ((double)WORLD_X / 8.0);
81         while (nxtsct(&ns, &sect)) {
82             if (sect.sct_type != SCT_RADAR)
83                 continue;
84             if (!player->owner)
85                 continue;
86             radmap(sect.sct_x, sect.sct_y, (int)sect.sct_effic,
87                    (int)(tech * 2.0), 0.0);
88         }
89         break;
90     case NS_LIST:
91     case NS_GROUP:
92         if (!from_unit) {
93             /* assumes a NS_LIST return is a shipno */
94             if (!snxtitem(&ni, EF_SHIP, cp)) {
95                 pr("Specify at least one ship\n");
96                 return RET_SYN;
97             }
98             while (nxtitem(&ni, (s_char *)&ship)) {
99                 if (!player->owner)
100                     continue;
101                 if (mchr[(int)ship.shp_type].m_flags & M_SONAR)
102                     tf = techfact(ship.shp_tech, 1.0);
103                 else
104                     tf = 0.0;
105                 pr("%s at ", prship(&ship));
106                 tech = techfact(ship.shp_tech,
107                                 (double)mchr[(int)ship.shp_type].m_vrnge);
108                 if (tech > ((double)WORLD_Y / 2.0))
109                     tech = ((double)WORLD_Y / 2.0);
110                 if (tech > ((double)WORLD_X / 4.0))
111                     tech = ((double)WORLD_X / 4.0);
112                 radmap(ship.shp_x, ship.shp_y, ship.shp_effic,
113                        (int)tech, tf);
114             }
115         } else {
116             /* from a land unit */
117             if (!snxtitem(&ni, EF_LAND, cp)) {
118                 pr("Specify at least one unit\n");
119                 return RET_SYN;
120             }
121             while (nxtitem(&ni, (s_char *)&land)) {
122                 if (!player->owner)
123                     continue;
124                 if (!(lchr[(int)land.lnd_type].l_flags & L_RADAR)) {
125                     pr("%s can't use radar!\n", prland(&land));
126                     continue;
127                 }
128                 if (land.lnd_ship >= 0) {
129                     pr("Units on ships can't use radar!\n");
130                     continue;
131                 }
132                 tf = 0.0;
133                 pr("%s at ", prland(&land));
134                 tech = techfact(land.lnd_tech, (double)land.lnd_spy);
135                 if (tech > ((double)WORLD_Y / 2.0))
136                     tech = ((double)WORLD_Y / 2.0);
137                 if (tech > ((double)WORLD_X / 4.0))
138                     tech = ((double)WORLD_X / 4.0);
139                 radmap(land.lnd_x, land.lnd_y, land.lnd_effic,
140                        (int)tech, tf);
141             }
142         }
143         break;
144     default:
145         if (!from_unit)
146             pr("Must use a ship or sector specifier\n");
147         else
148             pr("Must use a unit or sector specifier\n");
149         return RET_SYN;
150     }
151     return RET_OK;
152 }