]> git.pond.sub.org Git - empserver/blob - src/lib/commands/map.c
(map, draw_map): Remove undocumented feature that lets deities run map
[empserver] / src / lib / commands / map.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  *  map.c: Display a map of sectors.
29  * 
30  *  Known contributors to this file:
31  *     Dave Pare, 1986
32  *     Ken Stevens, 1995
33  */
34
35 #include "misc.h"
36 #include "nat.h"
37 #include "file.h"
38 #include "player.h"
39 #include "map.h"
40 #include "ship.h"
41 #include "land.h"
42 #include "xy.h"
43 #include "nsc.h"
44 #include "commands.h"
45 #include "optlist.h"
46
47 int
48 map(void)
49 {
50     register s_char *b;
51     int unit_type = 0;
52     int bmap = 0;
53     struct natstr *np;
54     s_char *str;
55     struct nstr_sect ns;
56     s_char origin = '\0';
57     int as_country;
58     int map_flags = 0;
59     int i;
60     s_char what[64];
61     s_char buf[1024];
62
63     if (**player->argp != 'm') {
64         if (**player->argp == 'b')
65             bmap = EF_BMAP;
66         else if (**player->argp == 'n')
67             bmap = EF_NMAP;
68         else {
69             if (**player->argp == 'l')
70                 unit_type = EF_LAND;
71             else if (**player->argp == 'p')
72                 unit_type = EF_PLANE;
73             else if (**player->argp == 's')
74                 unit_type = EF_SHIP;
75             else {
76                 logerror("map: bad player->argp[0]");
77                 return RET_SYN;
78             }
79             if (player->argp[0][1] == 'b')
80                 bmap = EF_BMAP;
81         }
82     }
83
84     if (player->argp[1] == (s_char *)0) {
85         if ((str = getstring("(sects)? ", buf)) == 0)
86             return RET_SYN;
87     } else {
88         str = player->argp[1];
89     }
90
91     np = getnatp(player->cnum);
92     if (*str == '*') {
93         sprintf(what, "%d:%d,%d:%d",
94                 -WORLD_X / 2, WORLD_X / 2 - 1,
95                 -WORLD_Y / 2, WORLD_Y / 2 - 1);
96         if (!snxtsct(&ns, what))
97             return RET_FAIL;
98     } else if (!snxtsct(&ns, str)) {
99         i = atoi(str);
100         if (unit_map(unit_type, i, &ns, &origin))
101             return RET_FAIL;
102     }
103     b = player->argp[2];
104     while (b != (s_char *)0 && (*b)) {
105         switch (*b) {
106         case 's':
107         case 'S':
108             map_flags |= MAP_SHIP;
109             break;
110         case 'l':
111         case 'L':
112             map_flags |= MAP_LAND;
113             break;
114         case 'p':
115         case 'P':
116             map_flags |= MAP_PLANE;
117             break;
118         case 'h':
119         case 'H':
120             map_flags |= MAP_HIGH;
121             break;
122         case '*':
123             map_flags |= MAP_ALL;
124             break;
125         case 't':
126             if (bmap != EF_BMAP)
127                 goto bad_flag;
128             bmap = EF_MAP;
129             *(b + 1) = 0;
130             break;
131         case 'r':
132             if (bmap != EF_BMAP)
133                 goto bad_flag;
134             bmap = EF_MAP + EF_BMAP;
135             *(b + 1) = 0;
136             break;
137         default:
138         bad_flag:
139             pr("Bad flag %c!\n", *b);
140             break;
141         }
142         b++;
143     }
144
145     return draw_map(bmap, origin, map_flags, &ns);
146 }