]> git.pond.sub.org Git - empserver/blob - src/lib/commands/map.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / commands / map.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 "plane.h"
43 #include "xy.h"
44 #include "nsc.h"
45 #include "commands.h"
46 #include "optlist.h"
47
48 int
49 map(void)
50 {
51     register s_char *b;
52     int unit_type = 0;
53     int bmap = 0;
54     struct natstr *np;
55     s_char *str;
56     struct nstr_sect ns;
57     s_char origin = '\0';
58     int as_country;
59     int map_flags = 0;
60     int i;
61     int where = 2;
62     s_char what[64];
63     s_char buf[1024];
64
65     if (**player->argp != 'm') {
66         if (**player->argp == 'b')
67             bmap = EF_BMAP;
68         else if (**player->argp == 'n')
69             bmap = EF_NMAP;
70         else {
71             if (**player->argp == 'l')
72                 unit_type = EF_LAND;
73             else if (**player->argp == 'p')
74                 unit_type = EF_PLANE;
75             else if (**player->argp == 's')
76                 unit_type = EF_SHIP;
77             else {
78                 logerror("map: bad player->argp[0]");
79                 return RET_SYN;
80             }
81             if (player->argp[0][1] == 'b')
82                 bmap = EF_BMAP;
83         }
84     }
85
86     if (player->argp[1] == (s_char *)0) {
87         if ((str = getstring("(sects)? ", buf)) == 0)
88             return RET_SYN;
89     } else {
90         str = player->argp[1];
91     }
92
93     np = getnatp(player->cnum);
94     if (*str == '*') {
95         sprintf(what, "%d:%d,%d:%d",
96                 -WORLD_X / 2, WORLD_X / 2 - 1,
97                 -WORLD_Y / 2, WORLD_Y / 2 - 1);
98         if (!snxtsct(&ns, what))
99             return RET_FAIL;
100     } else if (!snxtsct(&ns, str)) {
101         i = atoi(str);
102         if (unit_map(unit_type, i, &ns, &origin))
103             return RET_FAIL;
104     }
105     b = player->argp[2];
106     while (b != (s_char *)0 && (*b)) {
107         where = 3;
108         switch (*b) {
109         case 's':
110         case 'S':
111             map_flags |= MAP_SHIP;
112             break;
113         case 'l':
114         case 'L':
115             map_flags |= MAP_LAND;
116             break;
117         case 'p':
118         case 'P':
119             map_flags |= MAP_PLANE;
120             break;
121         case '*':
122             map_flags |= MAP_ALL;
123             break;
124         case '0':
125         case '1':
126         case '2':
127         case '3':
128         case '4':
129         case '5':
130         case '6':
131         case '7':
132         case '8':
133         case '9':
134             where = 2;
135             break;
136         case 't':
137             bmap = EF_MAP;
138             *(b + 1) = 0;
139             break;
140         case 'r':
141             bmap = EF_MAP + EF_BMAP;
142             *(b + 1) = 0;
143             break;
144         default:
145             pr("Bad flag %c!\n", *b);
146             break;
147         }
148         b++;
149     }
150
151     as_country = player->cnum;
152     if (player->god) {
153         if (player->argp[where] != (s_char *)0) {
154             as_country = atoi(player->argp[where]);
155             if ((as_country < 0) || (as_country > MAXNOC)) {
156                 as_country = player->cnum;
157             }
158         }
159     }
160
161     return draw_map(bmap, origin, map_flags, &ns, as_country);
162 }