]> git.pond.sub.org Git - empserver/blob - src/lib/commands/marc.c
(march): Add the ability mine using 'd' while in the march command.
[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     char *cp = NULL;
58     struct lndstr *lnd = NULL;  /* leader */
59     struct nstr_sect ns;
60     char origin;
61     int dir;
62     int stopping = 0;
63     int skip = 0;
64     char buf[1024];
65     char prompt[128];
66     char scanspace[1024];
67     char bmap_flag;
68     int ac;
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         char dp[80];
87
88         if (cp == NULL || *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             if (cp && !(cp = lnd_path(together, lnd, buf)))
119                 cp = buf;
120         }
121         if (cp == NULL || *cp == '\0')
122             cp = &dirch[DIR_STOP];
123         dir = chkdir(*cp, DIR_STOP, DIR_LAST);
124         if (dir >= 0) {
125             stopping |=
126                 lnd_mar_one_sector(&land_list, dir, player->cnum, together);
127             cp++;
128             continue;
129         }
130         ac = parse(cp, player->argp, NULL, scanspace, NULL);
131         if (ac <= 1) {
132             sprintf(dp, "%d", lnd->lnd_uid);
133             player->argp[1] = dp;
134             cp++;
135         } else
136             cp = NULL;
137         bmap_flag = 0;
138         switch (*player->argp[0]) {
139         case 'B':
140             bmap_flag = 'b';
141             /*
142              * fall through
143              */
144         case 'M':
145             unit_map(EF_LAND, lnd->lnd_uid, &ns, &origin);
146             draw_map(bmap_flag, origin, 0, &ns);
147             skip = 1;
148             break;
149         case 'f':
150             {
151                 struct emp_qelem *qp;
152
153                 qp = land_list.q_back;
154                 emp_remque(land_list.q_back);
155                 emp_insque(qp, &land_list);
156                 set_leader(&land_list, &lnd);
157             }
158             break;
159         case 'i':
160             lnd_list(&land_list);
161             break;
162         case 'm':
163             lnd_sweep(&land_list, 1, 1, player->cnum);
164             stopping |= lnd_check_mines(&land_list);
165             break;
166         case 'r':
167             player->argp[0] = "lradar";
168             rada();
169             skip = 1;
170             player->btused++;
171             break;
172         case 'l':
173             llook();
174             player->btused++;
175             break;
176         case 'd':
177             if (ac == 2) {
178                 player->argp[2] = player->argp[1];
179                 sprintf(dp, "%d", lnd->lnd_uid);
180                 player->argp[1] = dp;
181             }
182             landmine();
183             skip = 1;
184             player->btused++;
185             break;
186         default:
187             direrr("`%c' to stop", 0, 0);
188             pr(", `i' to list units, `f' to change leader,\n");
189             pr("`r' to radar, `l' to look, `M' to map, `B' to bmap,\n");
190             pr("`d' to drop mines, and `m' to minesweep\n");
191             stopping = 1;
192         }
193     }
194     return RET_OK;
195 }
196
197 static int
198 set_leader(struct emp_qelem *list, struct lndstr **leaderp)
199 {
200     struct llist *llp = (struct llist *)(list->q_back);
201
202     if (!*leaderp)
203         pr("Leader is ");
204     else if ((*leaderp)->lnd_uid != llp->land.lnd_uid)
205         pr("Changing leader to ");
206     else
207         return 0;
208     *leaderp = &llp->land;
209     pr("%s\n", prland(&llp->land));
210     return 1;
211 }