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