subs: Clean up convoluted logic in lnd_mar_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
777172c9cb
commit
4b83bb5ff4
1 changed files with 31 additions and 34 deletions
|
@ -984,7 +984,6 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor)
|
||||||
coord newx;
|
coord newx;
|
||||||
coord newy;
|
coord newy;
|
||||||
int move;
|
int move;
|
||||||
enum lnd_stuck stuck;
|
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
int visible;
|
int visible;
|
||||||
char dp[80];
|
char dp[80];
|
||||||
|
@ -1007,50 +1006,47 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor)
|
||||||
newx = xnorm(llp->unit.land.lnd_x + dx);
|
newx = xnorm(llp->unit.land.lnd_x + dx);
|
||||||
newy = ynorm(llp->unit.land.lnd_y + dy);
|
newy = ynorm(llp->unit.land.lnd_y + dy);
|
||||||
getsect(newx, newy, §);
|
getsect(newx, newy, §);
|
||||||
rel = relations_with(sect.sct_own, actor);
|
rel = sect.sct_own ? relations_with(sect.sct_own, actor) : ALLIED;
|
||||||
|
|
||||||
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;
|
||||||
llp = (struct ulist *)qp;
|
llp = (struct ulist *)qp;
|
||||||
stuck = lnd_check_mar(&llp->unit.land, §);
|
switch (lnd_check_mar(&llp->unit.land, §)) {
|
||||||
if (stuck == LND_STUCK_NOT
|
case LND_STUCK_NOT:
|
||||||
&& (!sect.sct_own || rel == ALLIED
|
if (rel == ALLIED
|
||||||
|| (lchr[llp->unit.land.lnd_type].l_flags & L_SPY))) {
|
|| (lchr[llp->unit.land.lnd_type].l_flags & L_SPY))
|
||||||
move = 1;
|
move = 1;
|
||||||
|
break;
|
||||||
|
case LND_STUCK_NO_RAIL:
|
||||||
|
if (rel == ALLIED)
|
||||||
|
mpr(actor, "no rail system in %s\n",
|
||||||
|
xyas(newx, newy, actor));
|
||||||
|
else
|
||||||
|
mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
CANT_REACH();
|
||||||
|
/* fall through */
|
||||||
|
case LND_STUCK_IMPASSABLE:
|
||||||
|
mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!move) {
|
||||||
|
mpr(actor, "can't go to %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;
|
||||||
llp = (struct ulist *)qp;
|
llp = (struct ulist *)qp;
|
||||||
stuck = lnd_check_mar(&llp->unit.land, §);
|
if (rel != ALLIED
|
||||||
if (stuck != LND_STUCK_NOT
|
&& !(lchr[llp->unit.land.lnd_type].l_flags & L_SPY)) {
|
||||||
|| (sect.sct_own && rel != ALLIED
|
|
||||||
&& !(lchr[llp->unit.land.lnd_type].l_flags & L_SPY))) {
|
|
||||||
if (stuck == LND_STUCK_NO_RAIL
|
|
||||||
&& (!sect.sct_own || rel == ALLIED)) {
|
|
||||||
if (!move) {
|
|
||||||
mpr(actor, "no rail system in %s\n",
|
|
||||||
xyas(newx, newy, actor));
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
sprintf(dp, "has no rail system in %s",
|
|
||||||
xyas(newx, newy, actor));
|
|
||||||
lnd_stays(actor, dp, llp);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!move) {
|
|
||||||
mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
|
sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
|
||||||
lnd_stays(actor, dp, llp);
|
lnd_stays(actor, dp, llp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if (llp->mobil <= 0.0) {
|
if (llp->mobil <= 0.0) {
|
||||||
lnd_stays(actor, "is out of mobility", llp);
|
lnd_stays(actor, "is out of mobility", llp);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1068,7 +1064,8 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor)
|
||||||
mpr(actor, "You no longer own %s\n",
|
mpr(actor, "You no longer own %s\n",
|
||||||
xyas(osect.sct_x, osect.sct_y, actor));
|
xyas(osect.sct_x, osect.sct_y, actor));
|
||||||
}
|
}
|
||||||
if (rel != ALLIED && sect.sct_own) { /* must be a spy */
|
if (rel != ALLIED) {
|
||||||
|
/* must be a spy */
|
||||||
/* Always a 10% chance of getting caught. */
|
/* Always a 10% chance of getting caught. */
|
||||||
if (chance(LND_SPY_DETECT_CHANCE(llp->unit.land.lnd_effic))) {
|
if (chance(LND_SPY_DETECT_CHANCE(llp->unit.land.lnd_effic))) {
|
||||||
if (rel == NEUTRAL || rel == FRIENDLY) {
|
if (rel == NEUTRAL || rel == FRIENDLY) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue