#define FORTEFF 5 /* forts must be 5% efficient to fire. */
#define MOB_NONE 0
-#define MOB_ROAD 1
-#define MOB_RAIL 2
+#define MOB_MOVE 1
+#define MOB_MARCH 2
+#define MOB_RAIL 3
#define INT_ROAD 0
#define INT_RAIL 1
pr(" ");
pr("%4d%% ", sect.sct_effic);
pr("%4d%% ", sect.sct_road);
- pr("%4.3f ", sector_mcost(§, MOB_ROAD));
+ pr("%4.3f ", sector_mcost(§, MOB_MOVE));
pr("%4d%% ", sect.sct_rail);
pr("%4.3f ", sector_mcost(§, MOB_RAIL));
pr("%4d%% ", SCT_DEFENSE(§));
{
double d;
- if (!(d = dchr[sp->sct_type].d_mcst))
+ d = dchr[sp->sct_type].d_mcst;
+ if (d <= 0)
return -1.0;
-/* Note, the best you can get is a 1.0 here. */
-
- if (do_bonus == MOB_ROAD) {
+ if (do_bonus == MOB_MOVE || do_bonus == MOB_MARCH) {
d = d / (1.0 + sp->sct_road / 122.0);
} else if (do_bonus == MOB_RAIL) {
if (sp->sct_rail <= 0)
d = 1.0;
if (dchr[sp->sct_type].d_mcst < 25)
d = (d * 100.0 - sp->sct_effic) / 500.0;
-/* d = (200.0 + (d - 3.0) * sp->sct_effic) / 500.0;*/
else
d = (d * 10.0 - sp->sct_effic) / 115;
- if (d <= 0.0 || d < MIN_MOBCOST)
- return MIN_MOBCOST;
- return d;
+ if (do_bonus == MOB_MOVE)
+ return MAX(d, MIN_MOBCOST);
+ if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0
+ && do_bonus != MOB_RAIL)
+ return MAX(d, LND_MINMOBCOST);
+ return MAX(d, 0.01);
}
struct sctstr *from,
struct sctstr *to, double *cost)
{
- return BestLandPath(path, from, to, cost, MOB_ROAD);
+ return BestLandPath(path, from, to, cost, MOB_MOVE);
}
char *
switch (combat_mode) {
case A_ATTACK:
mob_support = off->mob / sector_mcost(getsectp(def->x, def->y),
- MOB_ROAD);
+ MOB_MOVE);
if (mob_support < 0)
mob_support = 0;
/* mob_support = off->mob / sector_mcost(def->sct_type, def->eff);*/
off->mobcost +=
MAX(1,
(int)(attacking_mil *
- sector_mcost(getsectp(def->x, def->y), MOB_ROAD)));
+ sector_mcost(getsectp(def->x, def->y), MOB_MOVE)));
break;
case A_LBOARD:
off->mobcost += MAX(1, attacking_mil / 5);
continue;
getsect(def->x, def->y, &dsect);
- if (!BestLandPath(buf, §, &dsect, &move_cost, MOB_ROAD))
+ if (!BestLandPath(buf, §, &dsect, &move_cost, MOB_MARCH))
continue;
mobcost = land.lnd_effic * 0.01 * lchr[(int)land.lnd_type].l_spd;
return;
if (off->own != player->cnum)
return;
- d = sector_mcost(getsectp(def->x, def->y), MOB_ROAD);
+ d = sector_mcost(getsectp(def->x, def->y), MOB_MOVE);
if ((mob_support = MIN(off->troops, (int)(off->mob / d))) <= 0)
return;
sprintf(prompt, "How many mil to move in from %s (%d max)? ",
llp->land.lnd_x = bx;
llp->land.lnd_y = by;
getsect(bx, by, &rsect);
- mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD);
+ mobcost = lnd_mobcost(&llp->land, &rsect, MOB_MARCH);
mob = llp->land.lnd_mobil - (int)mobcost;
if (mob < -127)
mob = -127;
double
lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
{
- 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;
-
- mobcost = smobcost * 5.0 * 480.0 /
- (mobcost + techfact(lp->lnd_tech, mobcost));
-
- return mobcost;
+ effspd *= lp->lnd_effic * 0.01;
+
+ /*
+ * The return value must be sector_mcost(...) 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 sector_mcost(sp, mobtype) * 5.0 * 480.0
+ / (effspd + techfact(lp->lnd_tech, effspd));
}
int
if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
} else {
- llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD);
+ llp->mobil -= lnd_mobcost(&llp->land, §, MOB_MARCH);
}
llp->land.lnd_mobil = (int)llp->mobil;
llp->land.lnd_harden = 0;
struct sctstr d_sect, sect;
char *cp;
double dummy;
+ int mtype;
if (!sarg_xy(buf, &destx, &desty))
return 0;
}
getsect(lp->lnd_x, lp->lnd_y, §);
if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
- cp = BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL);
+ mtype = MOB_RAIL;
else
- cp = BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD);
+ mtype = MOB_MARCH;
+ cp = BestLandPath(buf, §, &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;
}
pr("Looking for best path to %s\n", path);
path = BestLandPath(buf2, start, &ending_sect, &total_mcost,
- MOB_ROAD);
+ MOB_MOVE);
if (exploring && path) /* take off the 'h' */
path[strlen(path) - 1] = '\0';
if (!path)
if (movstr && sarg_xy(movstr, &dx, &dy)) {
if (getsect(dx, dy, &dsect)) {
movstr = BestLandPath(buf2, §, &dsect, &mv_cost,
- MOB_ROAD);
+ MOB_MOVE);
} else {
pr("Invalid destination sector!\n");
movstr = NULL;
*movstr = 0;
continue;
}
- sect_mcost = sector_mcost(&next, MOB_ROAD);
+ sect_mcost = sector_mcost(&next, MOB_MOVE);
if ((!player->owner && (!exploring
|| next.sct_item[I_MILIT]
|| next.sct_item[I_CIVIL]))
putland(lp->lnd_uid, lp);
return 0;
}
- mobcost = lnd_mobcost(lp, §, MOB_ROAD);
+ mobcost = lnd_mobcost(lp, §, MOB_MARCH);
lp->lnd_x = newx;
lp->lnd_y = newy;
lp->lnd_mobil -= mobcost;
continue;
if (sect.sct_effic < 60)
continue;
- if (!BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD))
+ if (!BestLandPath(buf, &dest, §, &move_cost, MOB_MOVE))
continue;
if (!opt_NOFOOD && type == I_FOOD)
minimum = 1 + (int)ceil(food_needed(sect.sct_item,
continue;
if (sect.sct_effic < 2)
continue;
- if (!BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD))
+ if (!BestLandPath(buf, &dest, §, &move_cost, MOB_MOVE))
continue;
if (!opt_NOFOOD && type == I_FOOD)
minimum = 1 + (int)ceil(food_needed(ship.shp_item,
continue;
getsect(land.lnd_x, land.lnd_y, §);
- if (!BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD))
+ if (!BestLandPath(buf, &dest, §, &move_cost, MOB_MOVE))
continue;
if ((land.lnd_ship >= 0) && (sect.sct_type != SCT_HARBR))
* calculate unit movement cost; decrease amount if
* there isn't enough mobility.
*/
- mcost = sector_mcost(to, MOB_ROAD) * ip->i_lbs / ip->i_pkg[packing];
+ mcost = sector_mcost(to, MOB_MOVE) * ip->i_lbs / ip->i_pkg[packing];
mcost /= DELIVER_BONUS;
if (mobility < mcost * amt_moved) {
p = ReversePath(path);
/* And walk the path back to the dist center to get the export
cost */
- infptr->excost = pathcost(sp, p, MOB_ROAD);
+ infptr->excost = pathcost(sp, p, MOB_MOVE);
#ifdef SAVE_FINISH_PATHS
memcpy(infptr->path, p, len);
#else