]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/lndsub.c
(lnd_mobtype): New.
[empserver] / src / lib / subs / lndsub.c
index c89e9b66784db5e4068e83c50fe4230f4d4a77db..e8354ed49fe326680f9efed8b370d732005e4421 100644 (file)
@@ -64,8 +64,6 @@ attack_val(int combat_mode, struct lndstr *lp)
     struct lchrstr *lcp;
 
     if (lp->lnd_effic < LAND_MINEFF) {
-       makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
-       lp->lnd_own = 0;
        putland(lp->lnd_uid, lp);
        return 0;
     }
@@ -104,8 +102,6 @@ defense_val(struct lndstr *lp)
     struct lchrstr *lcp;
 
     if (lp->lnd_effic < LAND_MINEFF) {
-       makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
-       lp->lnd_own = 0;
        putland(lp->lnd_uid, lp);
        return 0;
     }
@@ -166,7 +162,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
     int taken;
     int nowhere_to_go = 0;
     struct sctstr rsect;
-    double mobcost;
+    double mobcost, bmcost;
     signed char orig;
     int mob;
 
@@ -231,12 +227,16 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
                    continue;
                if (sect.sct_type == SCT_MOUNT)
                    continue;
+               mobcost = lnd_mobcost(&llp->land, &rsect);
+               if (mobcost < 0)
+                   continue;
                ++nowned;
                civs = sect.sct_item[I_CIVIL];
                if (civs > biggest) {
                    biggest = civs;
                    bx = sect.sct_x;
                    by = sect.sct_y;
+                   bmcost = mobcost;
                }
            }
            if (!nowned)
@@ -246,8 +246,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
                llp->land.lnd_x = bx;
                llp->land.lnd_y = by;
                getsect(bx, by, &rsect);
-               mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
-               mob = llp->land.lnd_mobil - (int)mobcost;
+               mob = llp->land.lnd_mobil - (int)bmcost;
                if (mob < -127)
                    mob = -127;
                orig = llp->land.lnd_mobil;
@@ -635,7 +634,6 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
     struct llist *llp;
     struct sctstr sect;
     int mines, m, max, sshells, lshells;
-    double mobcost;
 
     for (qp = land_list->q_back; qp != land_list; qp = next) {
        next = qp->q_back;
@@ -665,11 +663,7 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
            continue;
        }
        if (takemob) {
-/*                     mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/
-           mobcost = llp->land.lnd_spd;
-           mobcost = 480.0 / (mobcost +
-                              techfact(llp->land.lnd_tech, mobcost));
-           llp->mobil -= mobcost;
+           llp->mobil -= lnd_pathcost(&llp->land, 0.2);
            llp->land.lnd_mobil = (int)llp->mobil;
            llp->land.lnd_harden = 0;
        }
@@ -765,7 +759,7 @@ lnd_list(struct emp_qelem *land_list)
        pr("%4d ", lnd->lnd_uid);
        pr("%-16.16s ", llp->lcp->l_name);
        prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
-       pr("%c", lnd->lnd_army);
+       pr("%1.1s", &lnd->lnd_army);
        pr("%4d%%", lnd->lnd_effic);
        pr("%4d", lnd->lnd_item[I_SHELL]);
        pr("%4d", lnd->lnd_item[I_GUN]);
@@ -998,40 +992,34 @@ lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp)
 }
 
 double
-lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
+lnd_pathcost(struct lndstr *lp, double pathcost)
 {
-    double mobcost;
-    double smobcost;
+    double effspd;
 
-    /* supply unit's speed depends on their eff, since
-       that is their purpose */
+    effspd = lp->lnd_spd;
     if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY)
-       mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd;
-    else
-       mobcost = lp->lnd_spd;
-    if (mobcost < 0.01)
-       mobcost = 0.01;
-
-/* sector_mcost now takes 2 different arguments, a sector pointer, and
-   whether or not to figure in the highway bonus, rail bonus or none.
-   bridge heads, bridges and highways have built-in highways bonus
-   because they are a 1, and this will discount that. */
-
-    smobcost = sector_mcost(sp, mobtype);
-    if (smobcost < 0.01)
-       smobcost = 0.01;
-
-/* marching through 0 mobility conquered sectors takes lots of mobility,
-   unless you are a train.  Capturing railways is a good thing. */
-
-    if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 &&
-       smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL)
-       smobcost = LND_MINMOBCOST;
+       effspd *= lp->lnd_effic * 0.01;
+
+    /*
+     * The return value must be PATHCOST times a factor that depends
+     * only on the land unit.  Anything else breaks path finding.  In
+     * particular, you can't add or enforce a minimum cost here.  Do
+     * it in sector_mcost().
+     */
+    return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
+}
 
-    mobcost = smobcost * 5.0 * 480.0 /
-       (mobcost + techfact(lp->lnd_tech, mobcost));
+int
+lnd_mobtype(struct lndstr *lp)
+{
+    return (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
+       ? MOB_RAIL : MOB_MARCH;
+}
 
-    return mobcost;
+double
+lnd_mobcost(struct lndstr *lp, struct sctstr *sp)
+{
+    return lnd_pathcost(lp, sector_mcost(sp, lnd_mobtype(lp)));
 }
 
 int
@@ -1123,11 +1111,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
        }
        llp->land.lnd_x = newx;
        llp->land.lnd_y = newy;
-       if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
-           llp->mobil -= lnd_mobcost(&llp->land, &sect, MOB_RAIL);
-       } else {
-           llp->mobil -= lnd_mobcost(&llp->land, &sect, MOB_ROAD);
-       }
+       llp->mobil -= lnd_mobcost(&llp->land, &sect);
        llp->land.lnd_mobil = (int)llp->mobil;
        llp->land.lnd_harden = 0;
        putland(llp->land.lnd_uid, &llp->land);
@@ -1207,7 +1191,6 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
  * find all artillery units belonging
  * to the attacker or defender that can fire.
  * Each arty unit adds +1%/damage point
- *
  */
 int
 lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
@@ -1231,8 +1214,6 @@ lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
            continue;
        if (land.lnd_land >= 0)
            continue;
-       if (land.lnd_mission > 0)
-           continue;
        if (land.lnd_effic < LAND_MINFIREEFF)
            continue;
        /* Do we have mil? */
@@ -1289,6 +1270,7 @@ lnd_path(int together, struct lndstr *lp, char *buf)
     struct sctstr d_sect, sect;
     char *cp;
     double dummy;
+    int mtype;
 
     if (!sarg_xy(buf, &destx, &desty))
        return 0;
@@ -1301,12 +1283,11 @@ lnd_path(int together, struct lndstr *lp, char *buf)
        return 0;
     }
     getsect(lp->lnd_x, lp->lnd_y, &sect);
-    if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
-       cp = BestLandPath(buf, &sect, &d_sect, &dummy, MOB_RAIL);
-    else
-       cp = BestLandPath(buf, &sect, &d_sect, &dummy, MOB_ROAD);
+    mtype = lnd_mobtype(lp);
+    cp = BestLandPath(buf, &sect, &d_sect, &dummy, mtype);
     if (!cp) {
-       pr("No owned path from %s to %s!\n",
+       pr("No owned %s from %s to %s!\n",
+          mtype == MOB_RAIL ? "railway" : "path",
           xyas(lp->lnd_x, lp->lnd_y, player->cnum),
           xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
        return 0;