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;
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);
}
#include "empobj.h"
#include "unit.h"
+static void pr_leader_change(struct empobj *leader);
+static struct empobj *get_leader(struct emp_qelem *list);
+static void switch_leader(struct emp_qelem *list, int uid);
+
int
navi(void)
{
struct emp_qelem ship_list;
double minmob, maxmob;
int together;
+
+ if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1]))
+ return RET_SYN;
+ shp_sel(&ni_ship, &ship_list);
+ shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
+ if (QEMPTY(&ship_list)) {
+ pr("No ships\n");
+ return RET_FAIL;
+ }
+
+ return do_unit_move(&ship_list, &together, &minmob, &maxmob);
+}
+
+int
+do_unit_move(struct emp_qelem *unit_list, int *together,
+ double *minmob, double *maxmob)
+{
char *cp = NULL;
int leader_uid;
struct empobj *leader;
char buf[1024];
char prompt[128];
char scanspace[1024];
- char pathtaken[1024]; /* Doubtful we'll have a path longer than this */
+ char pathtaken[1024]; /* Doubtful we'll have a path longer than this */
char *pt = pathtaken;
char bmap_flag;
int ac;
- if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1]))
- return RET_SYN;
- shp_sel(&ni_ship, &ship_list);
- shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
- if (QEMPTY(&ship_list)) {
- pr("No ships\n");
- return RET_FAIL;
- }
- leader = get_leader(&ship_list);
+ leader = get_leader(unit_list);
leader_uid = leader->uid;
- pr("Flagship is %s\n", obj_nameof(leader));
+ pr("%s is %s\n",
+ leader->ef_type == EF_SHIP ? "Flagship" : "Leader",
+ obj_nameof(leader));
+
if (player->argp[2]) {
strcpy(buf, player->argp[2]);
- if (!(cp = shp_path(together, (struct shpstr *)leader, buf)))
- cp = player->argp[2];
+ if (leader->ef_type == EF_SHIP) {
+ if (!(cp = shp_path(*together, (struct shpstr *)leader, buf)))
+ cp = player->argp[2];
+ } else {
+ if (!(cp = lnd_path(*together, (struct lndstr *)leader, buf)))
+ cp = player->argp[2];
+ }
}
*pt = '\0';
- while (!QEMPTY(&ship_list)) {
+ while (!QEMPTY(unit_list)) {
char dp[80];
if (cp == NULL || *cp == '\0' || stopping) {
stopping = 0;
- shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
- if (QEMPTY(&ship_list)) {
- pr("No ships left\n");
+ if (leader->ef_type == EF_SHIP)
+ shp_nav(unit_list, minmob, maxmob, together, player->cnum);
+ else
+ lnd_mar(unit_list, minmob, maxmob, together, player->cnum);
+ if (QEMPTY(unit_list)) {
+ pr("No %s left\n",
+ leader->ef_type == EF_SHIP ? "ships" : "lands");
if (strlen(pathtaken) > 0) {
pathtaken[strlen(pathtaken) - 1] = '\0';
- if (strlen(pathtaken) > 0)
+ if (leader->ef_type == EF_SHIP && strlen(pathtaken) > 0)
pr("Path taken: %s\n", pathtaken);
}
return RET_OK;
}
- leader = get_leader(&ship_list);
+ leader = get_leader(unit_list);
if (leader->uid != leader_uid) {
leader_uid = leader->uid;
pr_leader_change(leader);
}
if (!skip)
nav_map(leader->x, leader->y,
- !(mchr[(int)leader->type].m_flags & M_SUB));
+ leader->ef_type == EF_SHIP ?
+ !(mchr[(int)leader->type].m_flags & M_SUB) : 1);
else
skip = 0;
- sprintf(prompt, "<%.1f:%.1f: %s> ", maxmob,
- minmob, xyas(leader->x, leader->y, player->cnum));
+ sprintf(prompt, "<%.1f:%.1f: %s> ", *maxmob,
+ *minmob, xyas(leader->x, leader->y, player->cnum));
cp = getstring(prompt, buf);
- /* Just in case any of our ships were shelled while we were
- * at the prompt, we call shp_nav() again.
+ /* Just in case any of our units were shelled while we were
+ * at the prompt, we call shp_nav() or lnd_mar() again.
*/
- shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum);
- if (QEMPTY(&ship_list)) {
- pr("No ships left\n");
+ if (leader->ef_type == EF_SHIP)
+ shp_nav(unit_list, minmob, maxmob, together, player->cnum);
+ else
+ lnd_mar(unit_list, minmob, maxmob, together, player->cnum);
+ if (QEMPTY(unit_list)) {
+ pr("No %s left\n",
+ leader->ef_type == EF_SHIP ? "ships" : "lands");
if (strlen(pathtaken) > 0) {
pathtaken[strlen(pathtaken) - 1] = '\0';
- if (strlen(pathtaken) > 0)
+ if (leader->ef_type == EF_SHIP && strlen(pathtaken) > 0)
pr("Path taken: %s\n", pathtaken);
}
return RET_OK;
}
- leader = get_leader(&ship_list);
+ leader = get_leader(unit_list);
if (leader->uid != leader_uid) {
leader_uid = leader->uid;
pr_leader_change(leader);
stopping = 1;
continue;
}
- if (cp && !(cp = shp_path(together, (struct shpstr *)leader, buf)))
- cp = buf;
+ if (leader->ef_type == EF_SHIP) {
+ if (!(cp = shp_path(*together, (struct shpstr *)leader,
+ buf)))
+ cp = buf;
+ } else {
+ if (!(cp = lnd_path(*together, (struct lndstr *)leader,
+ buf)))
+ cp = buf;
+ }
+ }
+ if (leader->ef_type == EF_SHIP) {
+ radmapnopr(leader->x, leader->y, (int)leader->effic,
+ (int)techfact(leader->tech,
+ mchr[(int)leader->type].m_vrnge),
+ (mchr[(int)leader->type].m_flags & M_SONAR)
+ ? techfact(leader->tech, 1.0) : 0.0);
}
- radmapnopr(leader->x, leader->y, (int)leader->effic,
- (int)techfact(leader->tech,
- mchr[(int)leader->type].m_vrnge),
- (mchr[(int)leader->type].m_flags & M_SONAR)
- ? techfact(leader->tech, 1.0) : 0.0);
if (cp == NULL || *cp == '\0')
cp = &dirch[DIR_STOP];
- dir = chkdir(*cp, DIR_STOP, DIR_VIEW);
+ dir = chkdir(*cp, DIR_STOP, leader->ef_type == EF_SHIP ?
+ DIR_VIEW : DIR_LAST);
if (dir >= 0) {
- if (dir == DIR_VIEW)
- shp_view(&ship_list);
- else {
- stopping |= shp_nav_one_sector(&ship_list, dir, player->cnum, together);
- if (stopping != 2) {
- *pt++ = dirch[dir];
- *pt = '\0';
+ if (leader->ef_type == EF_SHIP) {
+ if (dir == DIR_VIEW)
+ shp_view(unit_list);
+ else {
+ stopping |= shp_nav_one_sector(unit_list, dir,
+ player->cnum, *together);
+ if (stopping != 2) {
+ *pt++ = dirch[dir];
+ *pt = '\0';
+ }
}
- }
+ } else
+ stopping |=
+ lnd_mar_one_sector(unit_list, dir, player->cnum,
+ *together);
cp++;
continue;
}
* fall through
*/
case 'M':
- do_map(bmap_flag, EF_SHIP, player->argp[1], player->argp[2]);
+ do_map(bmap_flag, leader->ef_type, player->argp[1],
+ player->argp[2]);
skip = 1;
continue;
case 'f':
- if (ac <= 1)
- switch_leader(&ship_list, -1);
+ if (ac <= 1)
+ switch_leader(unit_list, -1);
else
- switch_leader(&ship_list, atoi(player->argp[1]));
- leader = get_leader(&ship_list);
+ switch_leader(unit_list, atoi(player->argp[1]));
+ leader = get_leader(unit_list);
if (leader->uid != leader_uid) {
leader_uid = leader->uid;
pr_leader_change(leader);
}
continue;
case 'i':
- shp_list(&ship_list);
+ if (leader->ef_type == EF_SHIP)
+ shp_list(unit_list);
+ else
+ lnd_list(unit_list);
continue;
case 'm':
- stopping |= shp_sweep(&ship_list, 1, 1, player->cnum);
+ if (leader->ef_type == EF_SHIP)
+ stopping |= shp_sweep(unit_list, 1, 1, player->cnum);
+ else {
+ lnd_sweep(unit_list, 1, 1, player->cnum);
+ stopping |= lnd_check_mines(unit_list);
+ }
continue;
case 'r':
- radar(EF_SHIP);
+ radar(leader->ef_type);
skip = 1;
player->btused++;
continue;
case 'l':
- look();
+ if (leader->ef_type == EF_SHIP)
+ look();
+ else
+ llook();
player->btused++;
continue;
case 's':
+ if (leader->ef_type != EF_SHIP)
+ break;
sona();
player->btused++;
skip = 1;
sprintf(dp, "%d", leader->uid);
player->argp[1] = dp;
}
- mine();
+ if (leader->ef_type == EF_SHIP)
+ mine();
+ else
+ landmine();
skip = 1;
player->btused++;
continue;
}
- direrr("`%c' to stop", ", `%c' to view, ", 0);
- pr("`i' to list ships, `f' to change flagship,\n");
- pr("`r' to radar, `s' to sonar, `l' to look, `M' to map, `B' to bmap,\n");
+ direrr("`%c' to stop",
+ leader->ef_type == EF_SHIP ? ", `%c' to view" : NULL, NULL);
+ pr(", `i' to list %s, `f' to change %s,\n",
+ leader->ef_type == EF_SHIP ? "ships" : "units",
+ leader->ef_type == EF_SHIP ? "flagship" : "leader");
+ pr("`r' to radar, %s`l' to look, `M' to map, `B' to bmap,\n",
+ leader->ef_type == EF_SHIP ? "`s' to sonar, " : "");
pr("`d' to drop mines, and `m' to minesweep\n");
stopping = 1;
}
if (strlen(pathtaken) > 0) {
pathtaken[strlen(pathtaken) - 1] = '\0';
- if (strlen(pathtaken) > 0)
+ if (leader->ef_type == EF_SHIP && strlen(pathtaken) > 0)
pr("Path taken: %s\n", pathtaken);
}
return RET_OK;
return RET_OK;
}
-void
+static void
pr_leader_change(struct empobj *leader)
{
pr("Changing %s to %s\n",
obj_nameof(leader));
}
-struct empobj *
+static struct empobj *
get_leader(struct emp_qelem *list)
{
return &((struct ulist *)(list->q_back))->unit.gen;
}
-void
+static void
switch_leader(struct emp_qelem *list, int uid)
{
struct emp_qelem *qp, *save;