]> git.pond.sub.org Git - empserver/blob - src/lib/commands/map.c
5cae613b2a04155461a49c3b5be8489042d72e09
[empserver] / src / lib / commands / map.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 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  *  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 <config.h>
36
37 #include "misc.h"
38 #include "nat.h"
39 #include "file.h"
40 #include "player.h"
41 #include "map.h"
42 #include "ship.h"
43 #include "land.h"
44 #include "xy.h"
45 #include "nsc.h"
46 #include "commands.h"
47 #include "optlist.h"
48
49 int
50 map(void)
51 {
52     char *b;
53     int unit_type = EF_BAD;
54     int bmap = 0;
55     char *str;
56     struct nstr_sect ns;
57     char origin = '\0';
58     int map_flags = 0;
59     char buf[1024];
60     char prompt[128];
61
62     if (**player->argp != 'm') {
63         if (**player->argp == 'b')
64             bmap = 'b';
65         else if (**player->argp == 'n') {
66             unit_type = EF_NUKE;
67             if (player->argp[0][1] == 'b')
68                 bmap = 'b';
69             else
70                 bmap = 'n';
71         } else {
72             if (**player->argp == 'l')
73                 unit_type = EF_LAND;
74             else if (**player->argp == 'p')
75                 unit_type = EF_PLANE;
76             else if (**player->argp == 's')
77                 unit_type = EF_SHIP;
78             else {
79                 logerror("map: bad player->argp[0]");
80                 return RET_SYN;
81             }
82             if (player->argp[0][1] == 'b')
83                 bmap = 'b';
84         }
85     }
86
87     if (player->argp[1] == NULL) {
88         if (unit_type == EF_BAD) {
89             str = getstring("(sects)? ", buf);
90         } else {
91             sprintf(prompt, "(sects, %s)? ", ef_nameof(unit_type));
92             str = getstring(prompt, buf);
93         }
94
95         if (!str || !*str)
96             return RET_SYN;
97     } else
98         str = player->argp[1];
99
100     if (!snxtsct(&ns, str)) {
101         if (unit_map(unit_type, atoi(str), &ns, &origin))
102             return RET_FAIL;
103     }
104     for (b = player->argp[2]; b && *b; 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 'n':
119         case 'N':
120             map_flags |= MAP_NUKE;
121             break;
122         case 'h':
123         case 'H':
124             map_flags |= MAP_HIGH;
125             break;
126         case '*':
127             map_flags |= MAP_ALL;
128             break;
129         case 't':
130             if (bmap != 'b')
131                 goto bad_flag;
132             bmap = 't';
133             *(b + 1) = 0;
134             break;
135         case 'r':
136             if (bmap != 'b')
137                 goto bad_flag;
138             bmap = 'r';
139             *(b + 1) = 0;
140             break;
141         default:
142         bad_flag:
143             pr("Bad flag %c!\n", *b);
144             break;
145         }
146     }
147
148     return draw_map(bmap, origin, map_flags, &ns);
149 }