]> git.pond.sub.org Git - empserver/blob - src/lib/commands/map.c
Import of Empire 4.2.12
[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':       map_flags |= MAP_SHIP; break;
111                         case 'l':
112                         case 'L':       map_flags |= MAP_LAND; break;
113                         case 'p':
114                         case 'P':       map_flags |= MAP_PLANE; break;
115                         case '*':       map_flags |= MAP_ALL;   break;
116                         case '0':
117                         case '1':
118                         case '2':
119                         case '3':
120                         case '4':
121                         case '5':
122                         case '6':
123                         case '7':
124                         case '8':
125                         case '9':       where = 2; break;
126                         case 't':       bmap = EF_MAP; *(b+1)=0;break;
127                         case 'r':       bmap = EF_MAP + EF_BMAP;*(b+1)=0;break;
128                         default:        pr("Bad flag %c!\n",*b);
129                                         break;
130                 }
131                 b++;
132         }
133
134         as_country = player->cnum;
135         if (player->god){
136                 if (player->argp[where] != (s_char *) 0) {
137                         as_country=atoi(player->argp[where]);
138                         if ((as_country < 0) || (as_country > MAXNOC)){
139                                 as_country = player->cnum;
140                         }
141                 }
142         }
143
144         return draw_map(bmap, origin, map_flags, &ns, as_country);
145 }