subs: Make shp_check_nav() more like lnd_check_mar()

No functional change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2014-12-28 20:12:01 +01:00
parent d87bd96496
commit c70d9375ef
5 changed files with 51 additions and 56 deletions

View file

@ -30,7 +30,7 @@
* Dave Pare
* Ken Stevens, 1995
* Steve McClure, 1998
* Markus Armbruster, 2004-2010
* Markus Armbruster, 2004-2014
*/
@ -92,6 +92,14 @@ struct sctstr {
unsigned char sct_defense; /* Defensive value of a sector */
};
enum d_navigation {
NAV_NONE, /* ships can't navigate */
NAVOK, /* ships can always navigate */
NAV_02, /* requires 2% effic to navigate */
NAV_CANAL, /* requires 2% effic to navigate and M_CANAL capability */
NAV_60 /* requires 60% effic to navigate */
};
struct dchrstr {
unsigned char d_uid;
char d_mnem; /* map symbol */

View file

@ -139,6 +139,14 @@ enum {
SHP_TORP_SHELLS = 3 /* number of shells used by a torpedo */
};
/* Whether and why a ship is stuck in a sector */
enum shp_stuck {
SHP_STUCK_NOT, /* not stuck */
SHP_STUCK_CONSTRUCTION, /* sector not efficient enough */
SHP_STUCK_CANAL, /* ship lacks M_CANAL */
SHP_STUCK_IMPASSABLE /* sector type not navigable */
};
extern int m_armor(struct mchrstr *, int);
extern int m_speed(struct mchrstr *, int);
extern int m_visib(struct mchrstr *, int);
@ -165,7 +173,7 @@ extern void shp_sel(struct nstr_item *, struct emp_qelem *);
extern struct ulist *shp_insque(struct shpstr *, struct emp_qelem *);
extern void shp_nav(struct emp_qelem *, double *, double *, int *, natid);
extern int shp_sweep(struct emp_qelem *, int, int, natid);
extern enum d_navigation shp_check_nav(struct shpstr *, struct sctstr *);
extern enum shp_stuck shp_check_nav(struct shpstr *, struct sctstr *);
extern int sect_has_dock(struct sctstr *);
extern int shp_hardtarget(struct shpstr *);
extern int shp_nav_one_sector(struct emp_qelem *, int, natid, int);

View file

@ -27,7 +27,7 @@
* types.h: Empire types
*
* Known contributors to this file:
* Markus Armbruster, 2006-2013
* Markus Armbruster, 2006-2014
*/
#ifndef TYPES_H
@ -36,14 +36,6 @@
typedef unsigned char natid; /* NSC_NATID must match this */
typedef short coord;
enum d_navigation {
NAV_NONE, /* ships can't navigate */
NAVOK, /* ships can always navigate */
NAV_02, /* requires 2% effic to navigate */
NAV_CANAL, /* requires 2% effic to navigate and M_CANAL capability */
NAV_60 /* requires 60% effic to navigate */
};
struct bp;
struct emp_qelem;
struct empobj;

View file

@ -146,24 +146,20 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
getsect(sp->shp_x, sp->shp_y, &sect);
switch (shp_check_nav(sp, &sect)) {
case NAV_02:
case NAV_60:
case SHP_STUCK_NOT:
break;
case SHP_STUCK_CONSTRUCTION:
wu(0, sp->shp_own,
"%s %s,\nbut was caught in a construction zone, and couldn't retreat!\n",
prship(sp), conditions[findcondition(code)].desc[orig]);
return 0;
case NAV_NONE:
case NAV_CANAL:
wu(0, sp->shp_own,
"%s %s,\nbut was landlocked, and couldn't retreat!\n",
prship(sp), conditions[findcondition(code)].desc[orig]);
return 0;
case NAVOK:
break;
default:
CANT_REACH();
/* fall through */
case SHP_STUCK_CANAL:
case SHP_STUCK_IMPASSABLE:
wu(0, sp->shp_own,
"%s %s,\nbut was subject to an empire error, and couldn't retreat!\n",
"%s %s,\nbut was landlocked, and couldn't retreat!\n",
prship(sp), conditions[findcondition(code)].desc[orig]);
return 0;
}
@ -199,7 +195,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
mobcost = shp_mobcost(sp);
getsect(newx, newy, &sect);
if (shp_check_nav(sp, &sect) != NAVOK ||
if (shp_check_nav(sp, &sect) != SHP_STUCK_NOT ||
(sect.sct_own
&& relations_with(sect.sct_own, sp->shp_own) < FRIENDLY)) {
wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",

View file

@ -142,19 +142,17 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
continue;
}
switch (shp_check_nav(sp, &sect)) {
case NAV_02:
case NAV_60:
case SHP_STUCK_NOT:
break;
case SHP_STUCK_CONSTRUCTION:
shp_stays(actor, "is caught in a construction zone", mlp);
continue;
case NAV_NONE:
case NAV_CANAL:
shp_stays(actor, "is landlocked", mlp);
continue;
case NAVOK:
break;
default:
CANT_REACH();
shp_stays(actor, "was just swallowed by a big green worm", mlp);
/* fall through */
case SHP_STUCK_CANAL:
case SHP_STUCK_IMPASSABLE:
shp_stays(actor, "is landlocked", mlp);
continue;
}
if (first) {
@ -321,41 +319,34 @@ shp_stays(natid actor, char *str, struct ulist *mlp)
}
/*
* Can SP navigate in SECTP?
* Sector ownership is *not* considered!
* Return NAVOK when yes.
* Return NAV_02 when it could if the sector was at least 2% efficient.
* Return NAV_60 when it could if the sector was at least 60% efficient.
* Return NAV_CANAL when it lacks capability M_CANAL.
* Return NAV_NONE when this sector type isn't navigable at all.
* Return whether and why SP would be stuck in SECTP.
*/
enum d_navigation
enum shp_stuck
shp_check_nav(struct shpstr *sp, struct sctstr *sectp)
{
switch (dchr[sectp->sct_type].d_nav) {
case NAVOK:
break;
case NAV_CANAL:
if (mchr[sp->shp_type].m_flags & M_CANAL) {
if (sectp->sct_effic < 2)
return NAV_02;
} else
return NAV_CANAL;
break;
if (!(mchr[sp->shp_type].m_flags & M_CANAL)) {
return SHP_STUCK_CANAL;
}
/* fall through */
case NAV_02:
if (sectp->sct_effic < 2)
return NAV_02;
return SHP_STUCK_CONSTRUCTION;
break;
case NAV_60:
if (sectp->sct_effic < 60)
return NAV_60;
return SHP_STUCK_CONSTRUCTION;
break;
default:
CANT_REACH();
/* fall through */
case NAV_NONE:
return NAV_NONE;
return SHP_STUCK_IMPASSABLE;
}
return NAVOK;
return SHP_STUCK_NOT;
}
int
@ -771,10 +762,10 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
coord newx;
coord newy;
int move;
enum shp_stuck stuck;
int stopping = 0;
double mobcost;
char dp[80];
int navigate;
if (dir <= DIR_STOP || dir >= DIR_VIEW) {
shp_nav_put(list, actor);
@ -790,8 +781,8 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
newx = xnorm(mlp->unit.ship.shp_x + dx);
newy = ynorm(mlp->unit.ship.shp_y + dy);
getsect(newx, newy, &sect);
navigate = shp_check_nav(&mlp->unit.ship, &sect);
if (navigate == NAVOK &&
stuck = shp_check_nav(&mlp->unit.ship, &sect);
if (stuck == SHP_STUCK_NOT &&
(!sect.sct_own
|| relations_with(sect.sct_own, actor) >= FRIENDLY))
move = 1;
@ -803,11 +794,11 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
newx = xnorm(mlp->unit.ship.shp_x + dx);
newy = ynorm(mlp->unit.ship.shp_y + dy);
getsect(newx, newy, &sect);
navigate = shp_check_nav(&mlp->unit.ship, &sect);
if (navigate != NAVOK ||
stuck = shp_check_nav(&mlp->unit.ship, &sect);
if (stuck != SHP_STUCK_NOT ||
(sect.sct_own
&& relations_with(sect.sct_own, actor) < FRIENDLY)) {
if (navigate == NAV_CANAL)
if (stuck == SHP_STUCK_CANAL)
sprintf(dp,
"is too large to fit into the canal system at %s",
xyas(newx, newy, actor));