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