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:
parent
d87bd96496
commit
c70d9375ef
5 changed files with 51 additions and 56 deletions
|
@ -30,7 +30,7 @@
|
||||||
* Dave Pare
|
* Dave Pare
|
||||||
* Ken Stevens, 1995
|
* Ken Stevens, 1995
|
||||||
* Steve McClure, 1998
|
* 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 */
|
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 {
|
struct dchrstr {
|
||||||
unsigned char d_uid;
|
unsigned char d_uid;
|
||||||
char d_mnem; /* map symbol */
|
char d_mnem; /* map symbol */
|
||||||
|
|
|
@ -139,6 +139,14 @@ enum {
|
||||||
SHP_TORP_SHELLS = 3 /* number of shells used by a torpedo */
|
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_armor(struct mchrstr *, int);
|
||||||
extern int m_speed(struct mchrstr *, int);
|
extern int m_speed(struct mchrstr *, int);
|
||||||
extern int m_visib(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 struct ulist *shp_insque(struct shpstr *, struct emp_qelem *);
|
||||||
extern void shp_nav(struct emp_qelem *, double *, double *, int *, natid);
|
extern void shp_nav(struct emp_qelem *, double *, double *, int *, natid);
|
||||||
extern int shp_sweep(struct emp_qelem *, int, 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 sect_has_dock(struct sctstr *);
|
||||||
extern int shp_hardtarget(struct shpstr *);
|
extern int shp_hardtarget(struct shpstr *);
|
||||||
extern int shp_nav_one_sector(struct emp_qelem *, int, natid, int);
|
extern int shp_nav_one_sector(struct emp_qelem *, int, natid, int);
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
* types.h: Empire types
|
* types.h: Empire types
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Markus Armbruster, 2006-2013
|
* Markus Armbruster, 2006-2014
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
|
@ -36,14 +36,6 @@
|
||||||
typedef unsigned char natid; /* NSC_NATID must match this */
|
typedef unsigned char natid; /* NSC_NATID must match this */
|
||||||
typedef short coord;
|
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 bp;
|
||||||
struct emp_qelem;
|
struct emp_qelem;
|
||||||
struct empobj;
|
struct empobj;
|
||||||
|
|
|
@ -146,24 +146,20 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
||||||
|
|
||||||
getsect(sp->shp_x, sp->shp_y, §);
|
getsect(sp->shp_x, sp->shp_y, §);
|
||||||
switch (shp_check_nav(sp, §)) {
|
switch (shp_check_nav(sp, §)) {
|
||||||
case NAV_02:
|
case SHP_STUCK_NOT:
|
||||||
case NAV_60:
|
break;
|
||||||
|
case SHP_STUCK_CONSTRUCTION:
|
||||||
wu(0, sp->shp_own,
|
wu(0, sp->shp_own,
|
||||||
"%s %s,\nbut was caught in a construction zone, and couldn't retreat!\n",
|
"%s %s,\nbut was caught in a construction zone, and couldn't retreat!\n",
|
||||||
prship(sp), conditions[findcondition(code)].desc[orig]);
|
prship(sp), conditions[findcondition(code)].desc[orig]);
|
||||||
return 0;
|
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:
|
default:
|
||||||
CANT_REACH();
|
CANT_REACH();
|
||||||
|
/* fall through */
|
||||||
|
case SHP_STUCK_CANAL:
|
||||||
|
case SHP_STUCK_IMPASSABLE:
|
||||||
wu(0, sp->shp_own,
|
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]);
|
prship(sp), conditions[findcondition(code)].desc[orig]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +195,7 @@ retreat_ship1(struct shpstr *sp, char code, int orig)
|
||||||
mobcost = shp_mobcost(sp);
|
mobcost = shp_mobcost(sp);
|
||||||
|
|
||||||
getsect(newx, newy, §);
|
getsect(newx, newy, §);
|
||||||
if (shp_check_nav(sp, §) != NAVOK ||
|
if (shp_check_nav(sp, §) != SHP_STUCK_NOT ||
|
||||||
(sect.sct_own
|
(sect.sct_own
|
||||||
&& relations_with(sect.sct_own, sp->shp_own) < FRIENDLY)) {
|
&& relations_with(sect.sct_own, sp->shp_own) < FRIENDLY)) {
|
||||||
wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",
|
wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n",
|
||||||
|
|
|
@ -142,19 +142,17 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (shp_check_nav(sp, §)) {
|
switch (shp_check_nav(sp, §)) {
|
||||||
case NAV_02:
|
case SHP_STUCK_NOT:
|
||||||
case NAV_60:
|
break;
|
||||||
|
case SHP_STUCK_CONSTRUCTION:
|
||||||
shp_stays(actor, "is caught in a construction zone", mlp);
|
shp_stays(actor, "is caught in a construction zone", mlp);
|
||||||
continue;
|
continue;
|
||||||
case NAV_NONE:
|
|
||||||
case NAV_CANAL:
|
|
||||||
shp_stays(actor, "is landlocked", mlp);
|
|
||||||
continue;
|
|
||||||
case NAVOK:
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
CANT_REACH();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
|
@ -321,41 +319,34 @@ shp_stays(natid actor, char *str, struct ulist *mlp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Can SP navigate in SECTP?
|
* Return whether and why SP would be stuck 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.
|
|
||||||
*/
|
*/
|
||||||
enum d_navigation
|
enum shp_stuck
|
||||||
shp_check_nav(struct shpstr *sp, struct sctstr *sectp)
|
shp_check_nav(struct shpstr *sp, struct sctstr *sectp)
|
||||||
{
|
{
|
||||||
switch (dchr[sectp->sct_type].d_nav) {
|
switch (dchr[sectp->sct_type].d_nav) {
|
||||||
case NAVOK:
|
case NAVOK:
|
||||||
break;
|
break;
|
||||||
case NAV_CANAL:
|
case NAV_CANAL:
|
||||||
if (mchr[sp->shp_type].m_flags & M_CANAL) {
|
if (!(mchr[sp->shp_type].m_flags & M_CANAL)) {
|
||||||
if (sectp->sct_effic < 2)
|
return SHP_STUCK_CANAL;
|
||||||
return NAV_02;
|
}
|
||||||
} else
|
/* fall through */
|
||||||
return NAV_CANAL;
|
|
||||||
break;
|
|
||||||
case NAV_02:
|
case NAV_02:
|
||||||
if (sectp->sct_effic < 2)
|
if (sectp->sct_effic < 2)
|
||||||
return NAV_02;
|
return SHP_STUCK_CONSTRUCTION;
|
||||||
break;
|
break;
|
||||||
case NAV_60:
|
case NAV_60:
|
||||||
if (sectp->sct_effic < 60)
|
if (sectp->sct_effic < 60)
|
||||||
return NAV_60;
|
return SHP_STUCK_CONSTRUCTION;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
CANT_REACH();
|
CANT_REACH();
|
||||||
|
/* fall through */
|
||||||
case NAV_NONE:
|
case NAV_NONE:
|
||||||
return NAV_NONE;
|
return SHP_STUCK_IMPASSABLE;
|
||||||
}
|
}
|
||||||
return NAVOK;
|
return SHP_STUCK_NOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -771,10 +762,10 @@ shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
|
||||||
coord newx;
|
coord newx;
|
||||||
coord newy;
|
coord newy;
|
||||||
int move;
|
int move;
|
||||||
|
enum shp_stuck stuck;
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
double mobcost;
|
double mobcost;
|
||||||
char dp[80];
|
char dp[80];
|
||||||
int navigate;
|
|
||||||
|
|
||||||
if (dir <= DIR_STOP || dir >= DIR_VIEW) {
|
if (dir <= DIR_STOP || dir >= DIR_VIEW) {
|
||||||
shp_nav_put(list, actor);
|
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);
|
newx = xnorm(mlp->unit.ship.shp_x + dx);
|
||||||
newy = ynorm(mlp->unit.ship.shp_y + dy);
|
newy = ynorm(mlp->unit.ship.shp_y + dy);
|
||||||
getsect(newx, newy, §);
|
getsect(newx, newy, §);
|
||||||
navigate = shp_check_nav(&mlp->unit.ship, §);
|
stuck = shp_check_nav(&mlp->unit.ship, §);
|
||||||
if (navigate == NAVOK &&
|
if (stuck == SHP_STUCK_NOT &&
|
||||||
(!sect.sct_own
|
(!sect.sct_own
|
||||||
|| relations_with(sect.sct_own, actor) >= FRIENDLY))
|
|| relations_with(sect.sct_own, actor) >= FRIENDLY))
|
||||||
move = 1;
|
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);
|
newx = xnorm(mlp->unit.ship.shp_x + dx);
|
||||||
newy = ynorm(mlp->unit.ship.shp_y + dy);
|
newy = ynorm(mlp->unit.ship.shp_y + dy);
|
||||||
getsect(newx, newy, §);
|
getsect(newx, newy, §);
|
||||||
navigate = shp_check_nav(&mlp->unit.ship, §);
|
stuck = shp_check_nav(&mlp->unit.ship, §);
|
||||||
if (navigate != NAVOK ||
|
if (stuck != SHP_STUCK_NOT ||
|
||||||
(sect.sct_own
|
(sect.sct_own
|
||||||
&& relations_with(sect.sct_own, actor) < FRIENDLY)) {
|
&& relations_with(sect.sct_own, actor) < FRIENDLY)) {
|
||||||
if (navigate == NAV_CANAL)
|
if (stuck == SHP_STUCK_CANAL)
|
||||||
sprintf(dp,
|
sprintf(dp,
|
||||||
"is too large to fit into the canal system at %s",
|
"is too large to fit into the canal system at %s",
|
||||||
xyas(newx, newy, actor));
|
xyas(newx, newy, actor));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue