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