subs: Clean up convoluted logic in shp_nav_one_sector()
Handle "no movement" before the movement loop instead of relying on the first iteration of the loop. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
b1b072448d
commit
777172c9cb
1 changed files with 33 additions and 22 deletions
|
@ -775,39 +775,50 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor)
|
||||||
newy = ynorm(mlp->unit.ship.shp_y + dy);
|
newy = ynorm(mlp->unit.ship.shp_y + dy);
|
||||||
getsect(newx, newy, §);
|
getsect(newx, newy, §);
|
||||||
|
|
||||||
|
if (sect.sct_own && relations_with(sect.sct_own, actor) < FRIENDLY) {
|
||||||
|
mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
move = 0;
|
move = 0;
|
||||||
for (qp = list->q_back; qp != list; qp = next) {
|
for (qp = list->q_back; qp != list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
mlp = (struct ulist *)qp;
|
mlp = (struct ulist *)qp;
|
||||||
stuck = shp_check_nav(&mlp->unit.ship, §);
|
switch (shp_check_nav(&mlp->unit.ship, §)) {
|
||||||
if (stuck == SHP_STUCK_NOT &&
|
case SHP_STUCK_NOT:
|
||||||
(!sect.sct_own
|
|
||||||
|| relations_with(sect.sct_own, actor) >= FRIENDLY))
|
|
||||||
move = 1;
|
move = 1;
|
||||||
|
break;
|
||||||
|
case SHP_STUCK_CANAL:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
CANT_REACH();
|
||||||
|
/* fall through */
|
||||||
|
case SHP_STUCK_CONSTRUCTION:
|
||||||
|
case SHP_STUCK_IMPASSABLE:
|
||||||
|
mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!move) {
|
||||||
|
mpr(actor, "is too large to fit into the canal system at %s\n",
|
||||||
|
xyas(newx, newy, actor));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (qp = list->q_back; qp != list; qp = next) {
|
for (qp = list->q_back; qp != list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
mlp = (struct ulist *)qp;
|
mlp = (struct ulist *)qp;
|
||||||
stuck = shp_check_nav(&mlp->unit.ship, §);
|
stuck = shp_check_nav(&mlp->unit.ship, §);
|
||||||
if (stuck != SHP_STUCK_NOT ||
|
if (stuck == SHP_STUCK_CANAL) {
|
||||||
(sect.sct_own
|
sprintf(dp,
|
||||||
&& relations_with(sect.sct_own, actor) < FRIENDLY)) {
|
"is too large to fit into the canal system at %s",
|
||||||
if (stuck == SHP_STUCK_CANAL &&
|
xyas(newx, newy, actor));
|
||||||
(!sect.sct_own
|
shp_stays(actor, dp, mlp);
|
||||||
|| relations_with(sect.sct_own, actor) >= FRIENDLY))
|
continue;
|
||||||
sprintf(dp,
|
} else if (CANT_HAPPEN(stuck != SHP_STUCK_NOT)) {
|
||||||
"is too large to fit into the canal system at %s",
|
sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
|
||||||
xyas(newx, newy, actor));
|
shp_stays(actor, dp, mlp);
|
||||||
else
|
continue;
|
||||||
sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
|
|
||||||
if (!move) {
|
|
||||||
mpr(actor, "%s\n", dp);
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
shp_stays(actor, dp, mlp);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mlp->mobil <= 0.0) {
|
if (mlp->mobil <= 0.0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue