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