(do_unit_move): New, create from common code in navi() and march().

(navi, move): Use do_unit_move(), remove unneeded code.

(switch_leader, pr_leader_change, get_leader): Make static as only called
from marc.c.
This commit is contained in:
Ron Koenderink 2007-01-20 02:21:10 +00:00
parent d57a57155c
commit 0fda2a608a
3 changed files with 136 additions and 203 deletions

View file

@ -50,17 +50,6 @@ march(void)
struct emp_qelem land_list;
double minmob, maxmob;
int together;
char *cp = NULL;
int leader_uid;
struct empobj *leader;
int dir;
int stopping = 0;
int skip = 0;
char buf[1024];
char prompt[128];
char scanspace[1024];
char bmap_flag;
int ac;
if (!snxtitem(&ni_land, EF_LAND, player->argp[1]))
return RET_SYN;
@ -70,127 +59,5 @@ march(void)
pr("No lands\n");
return RET_FAIL;
}
leader = get_leader(&land_list);
leader_uid = leader->uid;
pr("Leader is %s\n", obj_nameof(leader));
if (player->argp[2]) {
strcpy(buf, player->argp[2]);
if (!(cp = lnd_path(together, (struct lndstr *)leader, buf)))
cp = player->argp[2];
}
while (!QEMPTY(&land_list)) {
char dp[80];
if (cp == NULL || *cp == '\0' || stopping) {
stopping = 0;
lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);
if (QEMPTY(&land_list)) {
pr("No lands left\n");
return RET_OK;
}
leader = get_leader(&land_list);
if (leader->uid != leader_uid) {
leader_uid = leader->uid;
pr_leader_change(leader);
stopping = 1;
continue;
}
if (!skip)
nav_map(leader->x, leader->y, 1);
else
skip = 0;
sprintf(prompt, "<%.1f:%.1f: %s> ", maxmob,
minmob, xyas(leader->x, leader->y, player->cnum));
cp = getstring(prompt, buf);
/* Just in case any of our lands were shelled while we were at the
* prompt, we call lnd_mar() again.
*/
lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum);
if (QEMPTY(&land_list)) {
pr("No lands left\n");
return RET_OK;
}
leader = get_leader(&land_list);
if (leader->uid != leader_uid) {
leader_uid = leader->uid;
pr_leader_change(leader);
stopping = 1;
continue;
}
if (cp && !(cp = lnd_path(together, (struct lndstr *)leader, buf)))
cp = buf;
}
if (cp == NULL || *cp == '\0')
cp = &dirch[DIR_STOP];
dir = chkdir(*cp, DIR_STOP, DIR_LAST);
if (dir >= 0) {
stopping |=
lnd_mar_one_sector(&land_list, dir, player->cnum, together);
cp++;
continue;
}
ac = parse(cp, player->argp, NULL, scanspace, NULL);
if (ac <= 1) {
sprintf(dp, "%d", leader->uid);
player->argp[1] = dp;
cp++;
} else
cp = NULL;
bmap_flag = 0;
switch (*player->argp[0]) {
case 'B':
bmap_flag = 'b';
/*
* fall through
*/
case 'M':
do_map(bmap_flag, EF_LAND, player->argp[1], player->argp[2]);
skip = 1;
continue;
case 'f':
if (ac <= 1)
switch_leader(&land_list, -1);
else
switch_leader(&land_list, atoi(player->argp[1]));
leader = get_leader(&land_list);
if (leader->uid != leader_uid) {
leader_uid = leader->uid;
pr_leader_change(leader);
}
continue;
case 'i':
lnd_list(&land_list);
continue;
case 'm':
lnd_sweep(&land_list, 1, 1, player->cnum);
stopping |= lnd_check_mines(&land_list);
continue;
case 'r':
radar(EF_LAND);
skip = 1;
player->btused++;
continue;
case 'l':
llook();
player->btused++;
continue;
case 'd':
if (ac == 2) {
player->argp[2] = player->argp[1];
sprintf(dp, "%d", leader->uid);
player->argp[1] = dp;
}
landmine();
skip = 1;
player->btused++;
continue;
}
direrr("`%c' to stop", 0, 0);
pr(", `i' to list units, `f' to change leader,\n");
pr("`r' to radar, `l' to look, `M' to map, `B' to bmap,\n");
pr("`d' to drop mines, and `m' to minesweep\n");
stopping = 1;
}
return RET_OK;
return do_unit_move(&land_list, &together, &minmob, &maxmob);
}