]> 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-2008, 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  *     Ron Koenderink, 2006
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37 #include "optlist.h"
38 #include "empobj.h"
39
40 int
41 rada(void)
42 {
43     return radar(EF_SHIP);
44 }
45
46 int
47 lrad(void)
48 {
49     return radar(EF_LAND);
50 }
51
52 int
53 radar(short type)
54 {
55     char *cp;
56     double tf;
57     double tech;
58     struct nstr_item ni;
59     struct nstr_sect ns;
60     union empobj_storage item;
61     char buf[1024];
62     char prompt[80];
63
64     sprintf(prompt, "Radar from (%s # or sector(s)) : ", ef_nameof(type));
65     cp = getstarg(player->argp[1], prompt, buf);
66                       
67     if (cp == 0)
68         return RET_SYN;
69     switch (sarg_type(cp)) {
70     case NS_AREA:
71         if (!snxtsct(&ns, cp))
72             return RET_SYN;
73         tech = tfact(player->cnum, 8.0);
74         if (tech > WORLD_Y / 4.0)
75             tech = WORLD_Y / 4.0;
76         if (tech > WORLD_X / 8.0)
77             tech = WORLD_X / 8.0;
78         while (nxtsct(&ns, &item.sect)) {
79             if (item.sect.sct_type != SCT_RADAR)
80                 continue;
81             if (!player->owner)
82                 continue;
83             radmap(item.sect.sct_x, item.sect.sct_y, item.sect.sct_effic,
84                    (int)(tech * 2.0), 0.0);
85         }
86         break;
87     case NS_LIST:
88     case NS_GROUP:
89         /* assumes a NS_LIST return is a unit no */
90         if (!snxtitem(&ni, type, cp)) {
91             pr("Specify at least one %s\n", ef_nameof(type));
92             return RET_SYN;
93         }
94         while (nxtitem(&ni, &item)) {
95             if (!player->owner)
96                 continue;
97             tf = 0.0;
98             if (type == EF_SHIP) {
99                 if (mchr[(int)item.ship.shp_type].m_flags & M_SONAR)
100                     tf = techfact(item.ship.shp_tech, 1.0);
101                 tech = techfact(item.ship.shp_tech,
102                     mchr[(int)item.ship.shp_type].m_vrnge);
103             } else {
104                 if (!(lchr[(int)item.land.lnd_type].l_flags & L_RADAR)) {
105                     pr("%s can't use radar!\n", prland(&item.land));
106                     continue;
107                 }
108                 if (item.land.lnd_ship >= 0) {
109                     pr("Units on ships can't use radar!\n");
110                     continue;
111                 }
112                 tech = techfact(item.land.lnd_tech, item.land.lnd_spy);
113             }
114
115             pr("%s at ", obj_nameof(&item.gen));
116             if (tech > WORLD_Y / 2.0)
117                 tech = WORLD_Y / 2.0;
118             if (tech > WORLD_X / 4.0)
119                 tech = WORLD_X / 4.0;
120             radmap(item.gen.x, item.gen.y, item.gen.effic,
121                    (int)tech, tf);
122         }
123         break;
124     default:
125         pr("Must use a %s or sector specifier\n", ef_nameof(type));
126         return RET_SYN;
127     }
128     return RET_OK;
129 }