]> git.pond.sub.org Git - empserver/commitdiff
navigate march: Fix "same mob type" and "not on sale" checks
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 5 Jan 2015 12:10:14 +0000 (13:10 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 2 Mar 2015 07:20:47 +0000 (08:20 +0100)
Unlike the other "may move" conditions, "same mobility type
(MOB_MARCH, MOB_RAIL) as leader" and "not on sale" are only checked
when collecting ships and land units.

The former breaks when a deity unwisely edits a land unit's type while
it is being marched.  Messed up when the check was added in commit
36e41e5 (v4.3.7).  However, editing has become possible only recently,
in commit 6b0b6f1.

The latter would break if a ship could be put on the market while it
is being navigated, but that's not possible, because only the owner
can navigate (see also commit 8c502d4), and only the owner can sell.
Same for land units.  Messed up in 4.0.9.  Clean it up anyway.  Bonus:
nicer error message, even spelled correctly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/subs/lndsub.c
src/lib/subs/shpsub.c
tests/navi-march/journal.log

index b5a4d11394c854bf4541c8a22040b2f4c0f0dd96..0fd6b7830fd4d36f4c65b3078c64bb5a18680a72 100644 (file)
@@ -404,12 +404,19 @@ int
 lnd_may_mar(struct lndstr *lp, struct lndstr *ldr, char *suffix)
 {
     struct sctstr sect;
+    int mobtype;
 
     if (!lp->lnd_own || !getsect(lp->lnd_x, lp->lnd_y, &sect)) {
        CANT_REACH();
        return 0;
     }
 
+    if (opt_MARKET && ontradingblock(EF_LAND, lp)) {
+       mpr(lp->lnd_own, "%s is on the trading block%s\n",
+           prland(lp), suffix);
+       return 0;
+    }
+
     if (lp->lnd_ship >= 0) {
        mpr(lp->lnd_own, "%s is on a ship%s\n", prland(lp), suffix);
        return 0;
@@ -455,6 +462,25 @@ lnd_may_mar(struct lndstr *lp, struct lndstr *ldr, char *suffix)
            prland(lp), suffix);
        return 0;
     }
+
+    /*
+     * The marching code gets confused when trains and non-trains
+     * march together.  Disallow for now.
+     */
+    mobtype = lnd_mobtype(lp);
+    if (!ldr || mobtype == lnd_mobtype(ldr))
+       ;
+    else if (mobtype == MOB_RAIL) {
+       mpr(lp->lnd_own,
+           "%s is a train and can't march with the leader%s\n",
+           prland(lp), suffix);
+       return 0;
+    } else {
+       mpr(lp->lnd_own, "%s can't rail-march with the leading train%s\n",
+           prland(lp), suffix);
+       return 0;
+    }
+
     return 1;
 }
 
@@ -463,8 +489,6 @@ lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
 {
     struct lndstr land, *ldr = NULL;
     struct ulist *llp;
-    int this_mot;
-    int mobtype = MOB_MOVE;    /* indeterminate */
 
     emp_initque(list);
     while (nxtitem(ni, &land)) {
@@ -475,33 +499,8 @@ lnd_sel(struct nstr_item *ni, struct emp_qelem *list)
         */
        if (!land.lnd_own || land.lnd_own != player->cnum)
            continue;
-       if (opt_MARKET) {
-           if (ontradingblock(EF_LAND, &land)) {
-               pr("unit #%d inelligible - it's for sale.\n",
-                  land.lnd_uid);
-               continue;
-           }
-       }
        if (!lnd_may_mar(&land, ldr, ""))
            continue;
-       /*
-        * The marching code gets confused when trains and non-trains
-        * march together.  Disallow for now.
-        */
-       this_mot = lnd_mobtype(&land);
-       if (this_mot != mobtype) {
-           if (mobtype == MOB_MOVE)
-               mobtype = this_mot;
-           else if (mobtype == MOB_MARCH) {
-               pr("%s is a train and can't march with the leader.\n",
-                  prland(&land));
-               continue;
-           } else {
-               pr("%s can't rail-march with the leading train.\n",
-                  prland(&land));
-               continue;
-           }
-       }
 
        land.lnd_mission = 0;
        land.lnd_rflags = 0;
index 92e5f0b8a27a12329e454ca8ae8665cad39fb834..1ab137f15499f9fd20d2c78d684348e3a24d866f 100644 (file)
@@ -82,6 +82,12 @@ shp_may_nav(struct shpstr *sp, struct shpstr *flg, char *suffix)
        return 0;
     }
 
+    if (opt_MARKET && ontradingblock(EF_SHIP, sp)) {
+       mpr(sp->shp_own, "%s is on the trading block%s\n",
+           prship(sp), suffix);
+       return 0;
+    }
+
     if (sp->shp_item[I_MILIT] == 0 && sp->shp_item[I_CIVIL] == 0) {
        mpr(sp->shp_own, "%s is crewless%s\n", prship(sp), suffix);
        return 0;
@@ -126,13 +132,6 @@ shp_sel(struct nstr_item *ni, struct emp_qelem *list)
         */
        if (!ship.shp_own || ship.shp_own != player->cnum)
            continue;
-       if (opt_MARKET) {
-           if (ontradingblock(EF_SHIP, &ship)) {
-               pr("ship #%d inelligible - it's for sale.\n",
-                  ship.shp_uid);
-               continue;
-           }
-       }
        if (!shp_may_nav(&ship, flg, ""))
            continue;
 
index cd7474590c75a693ebe3338a5b443f5f406cf1b6..96557690651fde98594c375d846e37d9edb8388e 100644 (file)
@@ -64,7 +64,7 @@
     Play#1 output Play#1 6 0 638
     Play#1 input navi 12/10/19/11/13
     Play#1 command navigate
-    Play#1 output Play#1 1 ship #12 inelligible - it's for sale.
+    Play#1 output Play#1 1 pt   patrol boat (#12) is on the trading block
     Play#1 output Play#1 1 pt   patrol boat (#13) is crewless
     Play#1 output Play#1 1 Flagship is pt   patrol boat (#10)
     Play#1 output Play#1 1  . i
     Play#1 output Play#1 6 0 588
     Play#1 input march 12/10/19/11/13/14/15
     Play#1 command march
-    Play#1 output Play#1 1 unit #12 inelligible - it's for sale.
+    Play#1 output Play#1 1 cav  cavalry #12 is on the trading block
     Play#1 output Play#1 1 cav  cavalry #13 has no mil on it to guide it
     Play#1 output Play#1 1 cav  cavalry #14 is on a ship
     Play#1 output Play#1 1 cav  cavalry #15 is on a unit
     Play#1 output Play#1 6 0 587
     Play#1 input march 20/22 jh
     Play#1 command march
-    Play#1 output Play#1 1 tra  train #22 is a train and can't march with the leader.
+    Play#1 output Play#1 1 tra  train #22 is a train and can't march with the leader
     Play#1 output Play#1 1 Leader is cav  cavalry #20
     Play#1 output Play#1 1 cav  cavalry #20 stopped at 3,3
     Play#1 output Play#1 6 0 586
     Play#1 input march 22/21/23 jh
     Play#1 command march
-    Play#1 output Play#1 1 cav  cavalry #21 can't rail-march with the leading train.
+    Play#1 output Play#1 1 cav  cavalry #21 can't rail-march with the leading train
     Play#1 output Play#1 1 Leader is tra  train #22
     Play#1 output Play#1 1 tra  train #22 stopped at 3,3
     Play#1 output Play#1 1 tra  train #23 stopped at 3,3