]> git.pond.sub.org Git - empserver/blob - src/lib/commands/map.c
(map): Simplify slightly.
[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     register s_char *b;
53     int unit_type = 0;
54     int bmap = 0;
55     struct natstr *np;
56     s_char *str;
57     struct nstr_sect ns;
58     s_char origin = '\0';
59     int map_flags = 0;
60     s_char what[64];
61     s_char buf[1024];
62
63     if (**player->argp != 'm') {
64         if (**player->argp == 'b')
65             bmap = 'b';
66         else if (**player->argp == 'n')
67             bmap = 'n';
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 = 'b';
81         }
82     }
83
84     if (player->argp[1] == NULL) {
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         if (unit_map(unit_type, atoi(str), &ns, &origin))
100             return RET_FAIL;
101     }
102     for (b = player->argp[2]; b && *b; b++) {
103         switch (*b) {
104         case 's':
105         case 'S':
106             map_flags |= MAP_SHIP;
107             break;
108         case 'l':
109         case 'L':
110             map_flags |= MAP_LAND;
111             break;
112         case 'p':
113         case 'P':
114             map_flags |= MAP_PLANE;
115             break;
116         case 'h':
117         case 'H':
118             map_flags |= MAP_HIGH;
119             break;
120         case '*':
121             map_flags |= MAP_ALL;
122             break;
123         case 't':
124             if (bmap != 'b')
125                 goto bad_flag;
126             bmap = 't';
127             *(b + 1) = 0;
128             break;
129         case 'r':
130             if (bmap != 'b')
131                 goto bad_flag;
132             bmap = 'r';
133             *(b + 1) = 0;
134             break;
135         default:
136         bad_flag:
137             pr("Bad flag %c!\n", *b);
138             break;
139         }
140     }
141
142     return draw_map(bmap, origin, map_flags, &ns);
143 }