]> git.pond.sub.org Git - empserver/blob - src/lib/commands/marc.c
8bc2795398a34c3be89db3dae6861182f2e43c74
[empserver] / src / lib / commands / marc.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  *  marc.c: March units around
29  * 
30  *  Known contributors to this file:
31  *     Thomas Ruschak
32  *     Ken Stevens, 1995 (rewrite)
33  */
34
35 #include <ctype.h>
36 #include "misc.h"
37 #include "player.h"
38 #include "var.h"
39 #include "land.h"
40 #include "sect.h"
41 #include "news.h"
42 #include "xy.h"
43 #include "nsc.h"
44 #include "nat.h"
45 #include "path.h"
46 #include "file.h"
47 #include "map.h"
48 #include "commands.h"
49
50 static int set_leader(struct emp_qelem *list, struct lndstr **leaderp);
51
52 int
53 march(void)
54 {
55     struct nstr_item ni_land;
56     struct emp_qelem land_list;
57     double minmob, maxmob;
58     int together;
59     s_char *cp = 0;
60     struct lndstr *lnd = 0;     /* leader */
61     struct nstr_sect ns;
62     s_char origin;
63     int dir;
64     int stopping = 0;
65     int skip = 0;
66     s_char buf[1024];
67     s_char prompt[128];
68
69     if (!snxtitem(&ni_land, EF_LAND, player->argp[1]))
70         return RET_SYN;
71     lnd_sel(&ni_land, &land_list);
72     lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);
73     if (QEMPTY(&land_list)) {
74         pr("No lands\n");
75         return RET_FAIL;
76     }
77     set_leader(&land_list, &lnd);
78     if (player->argp[2]) {
79         strcpy(buf, player->argp[2]);
80         if (!(cp = lnd_path(together, lnd, buf)))
81             cp = player->argp[2];
82     }
83
84     while (!QEMPTY(&land_list)) {
85         s_char *bp, dp[80];
86
87         if (cp == 0 || *cp == '\0' || stopping) {
88             stopping = 0;
89             lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);
90             if (QEMPTY(&land_list)) {
91                 pr("No lands left\n");
92                 return RET_OK;
93             }
94             if (set_leader(&land_list, &lnd)) {
95                 stopping = 1;
96                 continue;
97             }
98             if (!skip)
99                 nav_map(lnd->lnd_x, lnd->lnd_y, 1);
100             else
101                 skip = 0;
102             sprintf(prompt, "<%.1f:%.1f: %s> ", maxmob,
103                     minmob, xyas(lnd->lnd_x, lnd->lnd_y, player->cnum));
104             cp = getstring(prompt, buf);
105 /* Just in case any of our lands were shelled while we were at the
106  * prompt, we call lnd_mar() again.
107  */
108             lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);
109             if (QEMPTY(&land_list)) {
110                 pr("No lands left\n");
111                 return RET_OK;
112             }
113             if (set_leader(&land_list, &lnd)) {
114                 stopping = 1;
115                 continue;
116             }
117         }
118         if (cp == 0 || *cp == '\0')
119             cp = &dirch[DIR_STOP];
120         if (*cp == 'M' ||
121             *cp == 'B' || *cp == 'f' || *cp == 'i' || *cp == 'm') {
122             ++cp;
123             if (cp[-1] == 'M') {
124                 unit_map(EF_LAND, lnd->lnd_uid, &ns, &origin);
125                 draw_map(0, origin, 0, &ns, player->cnum);
126                 skip = 1;
127             } else if (cp[-1] == 'B') {
128                 unit_map(EF_LAND, lnd->lnd_uid, &ns, &origin);
129                 draw_map(EF_BMAP, origin, 0, &ns, player->cnum);
130                 skip = 1;
131             } else if (cp[-1] == 'f') {
132                 struct emp_qelem *qp;
133                 qp = land_list.q_back;
134                 emp_remque(land_list.q_back);
135                 emp_insque(qp, &land_list);
136                 set_leader(&land_list, &lnd);
137             } else if (cp[-1] == 'i') {
138                 lnd_list(&land_list);
139             } else {
140                 lnd_sweep(&land_list, 1, 1, player->cnum);
141                 stopping |= lnd_check_mines(&land_list);
142             }
143             continue;
144         } else if (*cp == 'r' || *cp == 'l') {
145             bp = ++cp;
146             while ((*bp != ' ') && (*bp))
147                 bp++;
148             while ((*bp == ' ') && (*bp))
149                 bp++;
150             if ((bp != (s_char *)0) && (*bp))
151                 player->argp[1] = bp;
152             else {
153                 sprintf(dp, "%d", lnd->lnd_uid);
154                 player->argp[1] = dp;
155             }
156             if (cp[-1] == 'r') {
157                 player->argp[0] = "lradar";
158                 rada();
159                 skip = 1;
160             } else
161                 llook();
162             *cp = 0;
163             player->btused++;
164             continue;
165         } else {
166             dir = chkdir(*cp++, DIR_STOP, DIR_LAST);
167             if (dir == -1) {
168                 if (NULL != (cp = lnd_path(together, lnd, buf)))
169                     continue;
170                 direrr("`%c' to stop", 0, 0);
171                 pr(", `i' to list units, `f' to change leader,\n");
172                 pr("`r' to radar, `l' to look, `M' to map, `B' to bmap,\n");
173                 pr("and `m' to minesweep\n");
174                 stopping = 1;
175                 continue;
176             }
177         }
178         stopping |=
179             lnd_mar_one_sector(&land_list, dir, player->cnum, together);
180     }
181     return RET_OK;
182 }
183
184 static int
185 set_leader(struct emp_qelem *list, struct lndstr **leaderp)
186 {
187     struct llist *llp = (struct llist *)(list->q_back);
188
189     if (!*leaderp)
190         pr("Leader is ");
191     else if ((*leaderp)->lnd_uid != llp->land.lnd_uid)
192         pr("Changing leader to ");
193     else
194         return 0;
195     *leaderp = &llp->land;
196     pr("%s\n", prland(&llp->land));
197     return 1;
198 }