2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * marc.c: March units around
30 * Known contributors to this file:
32 * Ken Stevens, 1995 (rewrite)
48 struct nstr_item ni_land;
49 struct emp_qelem land_list;
50 double minmob, maxmob;
54 struct empobj *leader;
64 if (!snxtitem(&ni_land, EF_LAND, player->argp[1]))
66 lnd_sel(&ni_land, &land_list);
67 lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);
68 if (QEMPTY(&land_list)) {
72 leader = get_leader(&land_list);
73 leader_uid = leader->uid;
74 pr("Leader is %s\n", obj_nameof(leader));
75 if (player->argp[2]) {
76 strcpy(buf, player->argp[2]);
77 if (!(cp = lnd_path(together, (struct lndstr *)leader, buf)))
81 while (!QEMPTY(&land_list)) {
84 if (cp == NULL || *cp == '\0' || stopping) {
86 lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);
87 if (QEMPTY(&land_list)) {
88 pr("No lands left\n");
91 leader = get_leader(&land_list);
92 if (leader->uid != leader_uid) {
93 leader_uid = leader->uid;
94 pr_leader_change(leader);
99 nav_map(leader->x, leader->y, 1);
102 sprintf(prompt, "<%.1f:%.1f: %s> ", maxmob,
103 minmob, xyas(leader->x, leader->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.
108 lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);
109 if (QEMPTY(&land_list)) {
110 pr("No lands left\n");
113 leader = get_leader(&land_list);
114 if (leader->uid != leader_uid) {
115 leader_uid = leader->uid;
116 pr_leader_change(leader);
120 if (cp && !(cp = lnd_path(together, (struct lndstr *)leader, buf)))
123 if (cp == NULL || *cp == '\0')
124 cp = &dirch[DIR_STOP];
125 dir = chkdir(*cp, DIR_STOP, DIR_LAST);
128 lnd_mar_one_sector(&land_list, dir, player->cnum, together);
132 ac = parse(cp, player->argp, NULL, scanspace, NULL);
134 sprintf(dp, "%d", leader->uid);
135 player->argp[1] = dp;
140 switch (*player->argp[0]) {
147 do_map(bmap_flag, EF_LAND, player->argp[1], player->argp[2]);
152 switch_leader(&land_list, -1);
154 switch_leader(&land_list, atoi(player->argp[1]));
155 leader = get_leader(&land_list);
156 if (leader->uid != leader_uid) {
157 leader_uid = leader->uid;
158 pr_leader_change(leader);
162 lnd_list(&land_list);
165 lnd_sweep(&land_list, 1, 1, player->cnum);
166 stopping |= lnd_check_mines(&land_list);
179 player->argp[2] = player->argp[1];
180 sprintf(dp, "%d", leader->uid);
181 player->argp[1] = dp;
188 direrr("`%c' to stop", 0, 0);
189 pr(", `i' to list units, `f' to change leader,\n");
190 pr("`r' to radar, `l' to look, `M' to map, `B' to bmap,\n");
191 pr("`d' to drop mines, and `m' to minesweep\n");
198 pr_leader_change(struct empobj *leader)
200 pr("Changing %s to %s\n",
201 leader->ef_type == EF_SHIP ? "flagship" : "leader",
206 get_leader(struct emp_qelem *list)
208 return &((struct ulist *)(list->q_back))->unit.gen;
212 switch_leader(struct emp_qelem *list, int uid)
214 struct emp_qelem *qp, *save;
220 save = qp = list->q_back;
223 emp_insque(qp, list);
225 ulp = (struct ulist *)qp;
226 if (ulp->unit.gen.uid == uid || uid == -1)
228 } while (list->q_back != save);