]> git.pond.sub.org Git - empserver/blob - src/lib/commands/map.c
Update copyright notice.
[empserver] / src / lib / commands / map.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2004, 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 'h':
122         case 'H':
123             map_flags |= MAP_HIGH;
124             break;
125         case '*':
126             map_flags |= MAP_ALL;
127             break;
128         case '0':
129         case '1':
130         case '2':
131         case '3':
132         case '4':
133         case '5':
134         case '6':
135         case '7':
136         case '8':
137         case '9':
138             where = 2;
139             break;
140         case 't':
141             if (!bmap)
142                 goto bad_flag;
143             bmap = EF_MAP;
144             *(b + 1) = 0;
145             break;
146         case 'r':
147             if (!bmap)
148                 goto bad_flag;
149             bmap = EF_MAP + EF_BMAP;
150             *(b + 1) = 0;
151             break;
152         default:
153         bad_flag:
154             pr("Bad flag %c!\n", *b);
155             break;
156         }
157         b++;
158     }
159
160     as_country = player->cnum;
161     if (player->god) {
162         if (player->argp[where] != (s_char *)0) {
163             as_country = atoi(player->argp[where]);
164             if ((as_country < 0) || (as_country > MAXNOC)) {
165                 as_country = player->cnum;
166             }
167         }
168     }
169
170     return draw_map(bmap, origin, map_flags, &ns, as_country);
171 }