]> git.pond.sub.org Git - empserver/commitdiff
subs: Factor lnd_check_mar() out of lnd_mar_one_sector()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 28 Dec 2014 18:47:45 +0000 (19:47 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 28 Feb 2015 15:12:54 +0000 (16:12 +0100)
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/land.h
src/lib/subs/lndsub.c

index 022920ea92f751c0a1e104e940fd25eb3d692d91..8a86537a0634c733a472bf8a1ef4794d4b00b5b1 100644 (file)
@@ -136,6 +136,12 @@ enum {
     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_def(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 struct ulist *lnd_insque(struct lndstr *, 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 int lnd_mobtype(struct lndstr *);
 extern double lnd_mobcost(struct lndstr *, struct sctstr *);
index 80d155199422632ea2de9e2d9e3e09d7c13e3cd1..c5194ee06a021fdb1cd0fe5900a75af618c3c869 100644 (file)
@@ -695,6 +695,17 @@ lnd_stays(natid actor, char *str, struct ulist *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
 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 newx;
     coord newy;
+    enum lnd_stuck stuck;
     int stopping = 0;
     int visible;
     int stop;
@@ -975,29 +987,31 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
        newy = ynorm(llp->unit.land.lnd_y + dy);
        getsect(newx, newy, &sect);
        rel = relations_with(sect.sct_own, actor);
-       if ((rel != ALLIED && sect.sct_own
-            && !(lchr[llp->unit.land.lnd_type].l_flags & L_SPY))
-           || dchr[sect.sct_type].d_mob0 < 0) {
-           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;
-           }
-       }
-       if (!SCT_HAS_RAIL(&sect)
-           && lnd_mobtype(&llp->unit.land) == MOB_RAIL) {
-           if (together) {
-               mpr(actor, "no rail system in %s\n",
-                   xyas(newx, newy, actor));
-               return 1;
-           } else {
-               sprintf(dp, "has no rail system in %s",
+       stuck = lnd_check_mar(&llp->unit.land, &sect);
+       if (stuck != LND_STUCK_NOT
+           || (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 (together) {
+                   mpr(actor, "no rail system in %s\n",
                        xyas(newx, newy, actor));
-               lnd_stays(actor, dp, llp);
-               continue;
+                   return 1;
+               } else {
+                   sprintf(dp, "has no rail system in %s",
+                           xyas(newx, newy, actor));
+                   lnd_stays(actor, dp, llp);
+                   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