]> git.pond.sub.org Git - empserver/commitdiff
subs: Make shp_check_nav() more like lnd_check_mar()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 28 Dec 2014 19:12:01 +0000 (20:12 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 28 Feb 2015 15:12:54 +0000 (16:12 +0100)
No functional change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/sect.h
include/ship.h
include/types.h
src/lib/subs/retreat.c
src/lib/subs/shpsub.c

index 44ed90232ce517574826f82d580099fc8c8a62d6..5da26bc91fbc27d228e7509007bd2400f7aafa91 100644 (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 */
index 948c29da3245a856052f29ac4b6e2f131422c0e0..826de914168a051cf66740ad6c8ef1b389148de7 100644 (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);
index 6709d0a55f7e909a4fee8c02b2f60fd8d0a1222e..1d7301892e564a5608f44b73a1df5d703c6af582 100644 (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
 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;
index 72048fcf6aa92fbb70fb175a64c0e36d061f94bb..38f0c2a0235a9e659651cff19b56bc81335b75ab 100644 (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",
index ce8f4fe9f25bdd7604ed2813ddbf81c2fa242e47..d0f9aa43312e2ad6abd72bd1dde9c61a5a338908 100644 (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));