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