subs: Factor lnd_check_mar() out of lnd_mar_one_sector()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
7fa0334c25
commit
f0e6551461
2 changed files with 43 additions and 22 deletions
|
@ -136,6 +136,12 @@ enum {
|
||||||
LND_AIROPS_EFF = 50 /* min. efficiency for air ops */
|
LND_AIROPS_EFF = 50 /* min. efficiency for air ops */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum lnd_stuck {
|
||||||
|
LND_STUCK_NOT, /* not stuck */
|
||||||
|
LND_STUCK_NO_RAIL, /* land needs rail */
|
||||||
|
LND_STUCK_IMPASSABLE /* sector type not marchable */
|
||||||
|
};
|
||||||
|
|
||||||
extern float l_att(struct lchrstr *, int);
|
extern float l_att(struct lchrstr *, int);
|
||||||
extern float l_def(struct lchrstr *, int);
|
extern float l_def(struct lchrstr *, int);
|
||||||
extern int l_vul(struct lchrstr *, int);
|
extern int l_vul(struct lchrstr *, int);
|
||||||
|
@ -172,6 +178,7 @@ extern int lnd_interdict(struct emp_qelem *, coord, coord, natid);
|
||||||
extern void lnd_sel(struct nstr_item *, struct emp_qelem *);
|
extern void lnd_sel(struct nstr_item *, struct emp_qelem *);
|
||||||
extern struct ulist *lnd_insque(struct lndstr *, struct emp_qelem *);
|
extern struct ulist *lnd_insque(struct lndstr *, struct emp_qelem *);
|
||||||
extern int lnd_check_mines(struct emp_qelem *);
|
extern int lnd_check_mines(struct emp_qelem *);
|
||||||
|
extern enum lnd_stuck lnd_check_mar(struct lndstr *, struct sctstr *);
|
||||||
extern double lnd_pathcost(struct lndstr *, double);
|
extern double lnd_pathcost(struct lndstr *, double);
|
||||||
extern int lnd_mobtype(struct lndstr *);
|
extern int lnd_mobtype(struct lndstr *);
|
||||||
extern double lnd_mobcost(struct lndstr *, struct sctstr *);
|
extern double lnd_mobcost(struct lndstr *, struct sctstr *);
|
||||||
|
|
|
@ -695,6 +695,17 @@ lnd_stays(natid actor, char *str, struct ulist *llp)
|
||||||
lnd_mar_put_one(llp);
|
lnd_mar_put_one(llp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return whether and why SP would be stuck in SECTP. */
|
||||||
|
enum lnd_stuck
|
||||||
|
lnd_check_mar(struct lndstr *lp, struct sctstr *sectp)
|
||||||
|
{
|
||||||
|
if (dchr[sectp->sct_type].d_mob0 < 0)
|
||||||
|
return LND_STUCK_IMPASSABLE;
|
||||||
|
if (lnd_mobtype(lp) == MOB_RAIL && !SCT_HAS_RAIL(sectp))
|
||||||
|
return LND_STUCK_NO_RAIL;
|
||||||
|
return LND_STUCK_NOT;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lnd_count(struct emp_qelem *list)
|
lnd_count(struct emp_qelem *list)
|
||||||
{
|
{
|
||||||
|
@ -953,6 +964,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
|
||||||
coord dy;
|
coord dy;
|
||||||
coord newx;
|
coord newx;
|
||||||
coord newy;
|
coord newy;
|
||||||
|
enum lnd_stuck stuck;
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
int visible;
|
int visible;
|
||||||
int stop;
|
int stop;
|
||||||
|
@ -975,20 +987,12 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
|
||||||
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 = relations_with(sect.sct_own, actor);
|
||||||
if ((rel != ALLIED && sect.sct_own
|
stuck = lnd_check_mar(&llp->unit.land, §);
|
||||||
&& !(lchr[llp->unit.land.lnd_type].l_flags & L_SPY))
|
if (stuck != LND_STUCK_NOT
|
||||||
|| dchr[sect.sct_type].d_mob0 < 0) {
|
|| (sect.sct_own && rel != ALLIED
|
||||||
if (together) {
|
&& !(lchr[llp->unit.land.lnd_type].l_flags & L_SPY))) {
|
||||||
mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
|
if (stuck == LND_STUCK_NO_RAIL
|
||||||
return 1;
|
&& (!sect.sct_own || rel == ALLIED)) {
|
||||||
} else {
|
|
||||||
sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
|
|
||||||
lnd_stays(actor, dp, llp);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!SCT_HAS_RAIL(§)
|
|
||||||
&& lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
|
|
||||||
if (together) {
|
if (together) {
|
||||||
mpr(actor, "no rail system in %s\n",
|
mpr(actor, "no rail system in %s\n",
|
||||||
xyas(newx, newy, actor));
|
xyas(newx, newy, actor));
|
||||||
|
@ -999,6 +1003,16 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
|
||||||
lnd_stays(actor, dp, llp);
|
lnd_stays(actor, dp, llp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (together) {
|
||||||
|
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));
|
||||||
|
lnd_stays(actor, dp, llp);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Note we check would_abandon first because we don't want
|
/* Note we check would_abandon first because we don't want
|
||||||
to always have to do these checks */
|
to always have to do these checks */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue