(lnd_mobtype): New.
(lnd_path): Use it. (lnd_mobcost): Use it, remove last parameter. Callers changed. This fixes mobility use of trains when retreating, both for retreat orders and for failed morale checks. (retreat_land1): Fix test for impassable terrain. Before, trains could retreat off rail. (lnd_take_casualty): Test for impassable terrain. Before, trains could retreat off rail.
This commit is contained in:
parent
2e693275f1
commit
4e7c993a62
4 changed files with 31 additions and 26 deletions
|
@ -201,7 +201,8 @@ extern int lnd_interdict(struct emp_qelem *, coord, coord, natid);
|
||||||
extern void lnd_sel(struct nstr_item *, struct emp_qelem *);
|
extern void lnd_sel(struct nstr_item *, struct emp_qelem *);
|
||||||
extern int lnd_check_mines(struct emp_qelem *);
|
extern int lnd_check_mines(struct emp_qelem *);
|
||||||
extern double lnd_pathcost(struct lndstr *, double);
|
extern double lnd_pathcost(struct lndstr *, double);
|
||||||
extern double lnd_mobcost(struct lndstr *, struct sctstr *, int);
|
extern int lnd_mobtype(struct lndstr *);
|
||||||
|
extern double lnd_mobcost(struct lndstr *, struct sctstr *);
|
||||||
extern char *lnd_path(int, struct lndstr *, char *);
|
extern char *lnd_path(int, struct lndstr *, char *);
|
||||||
|
|
||||||
extern int attack_val(int, struct lndstr *);
|
extern int attack_val(int, struct lndstr *);
|
||||||
|
|
|
@ -1038,7 +1038,8 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
|
||||||
switch (combat_mode) {
|
switch (combat_mode) {
|
||||||
case A_ATTACK:
|
case A_ATTACK:
|
||||||
mobcost = lnd_pathcost(&land,
|
mobcost = lnd_pathcost(&land,
|
||||||
att_mobcost(off->own, def, MOB_MARCH));
|
att_mobcost(off->own, def,
|
||||||
|
lnd_mobtype(&land)));
|
||||||
if (land.lnd_mobil < mobcost) {
|
if (land.lnd_mobil < mobcost) {
|
||||||
pr("%s does not have enough mobility (%d needed)\n",
|
pr("%s does not have enough mobility (%d needed)\n",
|
||||||
prland(&land), (int)ceil(mobcost));
|
prland(&land), (int)ceil(mobcost));
|
||||||
|
@ -1530,7 +1531,8 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
getsect(def->x, def->y, &dsect);
|
getsect(def->x, def->y, &dsect);
|
||||||
if (!BestLandPath(buf, §, &dsect, &pathcost, MOB_MARCH))
|
if (!BestLandPath(buf, §, &dsect, &pathcost,
|
||||||
|
lnd_mobtype(&land)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
mobcost = lnd_pathcost(&land, pathcost);
|
mobcost = lnd_pathcost(&land, pathcost);
|
||||||
|
@ -2529,7 +2531,8 @@ take_move_in_mob(int combat_mode, struct llist *llp, struct combat *off,
|
||||||
switch (combat_mode) {
|
switch (combat_mode) {
|
||||||
case A_ATTACK:
|
case A_ATTACK:
|
||||||
mobcost = lnd_pathcost(&llp->land,
|
mobcost = lnd_pathcost(&llp->land,
|
||||||
att_mobcost(off->own, def, MOB_MARCH));
|
att_mobcost(off->own, def,
|
||||||
|
lnd_mobtype(&llp->land)));
|
||||||
new = llp->land.lnd_mobil - mobcost;
|
new = llp->land.lnd_mobil - mobcost;
|
||||||
if (new < -127)
|
if (new < -127)
|
||||||
new = -127;
|
new = -127;
|
||||||
|
|
|
@ -162,7 +162,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
|
||||||
int taken;
|
int taken;
|
||||||
int nowhere_to_go = 0;
|
int nowhere_to_go = 0;
|
||||||
struct sctstr rsect;
|
struct sctstr rsect;
|
||||||
double mobcost;
|
double mobcost, bmcost;
|
||||||
signed char orig;
|
signed char orig;
|
||||||
int mob;
|
int mob;
|
||||||
|
|
||||||
|
@ -227,12 +227,16 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
|
||||||
continue;
|
continue;
|
||||||
if (sect.sct_type == SCT_MOUNT)
|
if (sect.sct_type == SCT_MOUNT)
|
||||||
continue;
|
continue;
|
||||||
|
mobcost = lnd_mobcost(&llp->land, &rsect);
|
||||||
|
if (mobcost < 0)
|
||||||
|
continue;
|
||||||
++nowned;
|
++nowned;
|
||||||
civs = sect.sct_item[I_CIVIL];
|
civs = sect.sct_item[I_CIVIL];
|
||||||
if (civs > biggest) {
|
if (civs > biggest) {
|
||||||
biggest = civs;
|
biggest = civs;
|
||||||
bx = sect.sct_x;
|
bx = sect.sct_x;
|
||||||
by = sect.sct_y;
|
by = sect.sct_y;
|
||||||
|
bmcost = mobcost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!nowned)
|
if (!nowned)
|
||||||
|
@ -242,8 +246,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
|
||||||
llp->land.lnd_x = bx;
|
llp->land.lnd_x = bx;
|
||||||
llp->land.lnd_y = by;
|
llp->land.lnd_y = by;
|
||||||
getsect(bx, by, &rsect);
|
getsect(bx, by, &rsect);
|
||||||
mobcost = lnd_mobcost(&llp->land, &rsect, MOB_MARCH);
|
mob = llp->land.lnd_mobil - (int)bmcost;
|
||||||
mob = llp->land.lnd_mobil - (int)mobcost;
|
|
||||||
if (mob < -127)
|
if (mob < -127)
|
||||||
mob = -127;
|
mob = -127;
|
||||||
orig = llp->land.lnd_mobil;
|
orig = llp->land.lnd_mobil;
|
||||||
|
@ -998,7 +1001,7 @@ lnd_pathcost(struct lndstr *lp, double pathcost)
|
||||||
effspd *= lp->lnd_effic * 0.01;
|
effspd *= lp->lnd_effic * 0.01;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The return value must be pathcost times a factor that depends
|
* The return value must be PATHCOST times a factor that depends
|
||||||
* only on the land unit. Anything else breaks path finding. In
|
* only on the land unit. Anything else breaks path finding. In
|
||||||
* particular, you can't add or enforce a minimum cost here. Do
|
* particular, you can't add or enforce a minimum cost here. Do
|
||||||
* it in sector_mcost().
|
* it in sector_mcost().
|
||||||
|
@ -1006,10 +1009,17 @@ lnd_pathcost(struct lndstr *lp, double pathcost)
|
||||||
return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
|
return pathcost * 5.0 * speed_factor(effspd, lp->lnd_tech);
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
int
|
||||||
lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype)
|
lnd_mobtype(struct lndstr *lp)
|
||||||
{
|
{
|
||||||
return lnd_pathcost(lp, sector_mcost(sp, mobtype));
|
return (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
|
||||||
|
? MOB_RAIL : MOB_MARCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
lnd_mobcost(struct lndstr *lp, struct sctstr *sp)
|
||||||
|
{
|
||||||
|
return lnd_pathcost(lp, sector_mcost(sp, lnd_mobtype(lp)));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1101,11 +1111,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
|
||||||
}
|
}
|
||||||
llp->land.lnd_x = newx;
|
llp->land.lnd_x = newx;
|
||||||
llp->land.lnd_y = newy;
|
llp->land.lnd_y = newy;
|
||||||
if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) {
|
llp->mobil -= lnd_mobcost(&llp->land, §);
|
||||||
llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL);
|
|
||||||
} else {
|
|
||||||
llp->mobil -= lnd_mobcost(&llp->land, §, MOB_MARCH);
|
|
||||||
}
|
|
||||||
llp->land.lnd_mobil = (int)llp->mobil;
|
llp->land.lnd_mobil = (int)llp->mobil;
|
||||||
llp->land.lnd_harden = 0;
|
llp->land.lnd_harden = 0;
|
||||||
putland(llp->land.lnd_uid, &llp->land);
|
putland(llp->land.lnd_uid, &llp->land);
|
||||||
|
@ -1277,10 +1283,7 @@ lnd_path(int together, struct lndstr *lp, char *buf)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
getsect(lp->lnd_x, lp->lnd_y, §);
|
getsect(lp->lnd_x, lp->lnd_y, §);
|
||||||
if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN)
|
mtype = lnd_mobtype(lp);
|
||||||
mtype = MOB_RAIL;
|
|
||||||
else
|
|
||||||
mtype = MOB_MARCH;
|
|
||||||
cp = BestLandPath(buf, §, &d_sect, &dummy, mtype);
|
cp = BestLandPath(buf, §, &d_sect, &dummy, mtype);
|
||||||
if (!cp) {
|
if (!cp) {
|
||||||
pr("No owned %s from %s to %s!\n",
|
pr("No owned %s from %s to %s!\n",
|
||||||
|
|
|
@ -458,11 +458,10 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
||||||
newy = ynorm(lp->lnd_y + dy);
|
newy = ynorm(lp->lnd_y + dy);
|
||||||
|
|
||||||
getsect(newx, newy, §);
|
getsect(newx, newy, §);
|
||||||
if ((sect.sct_type == SCT_WATER) ||
|
mobcost = lnd_mobcost(lp, §);
|
||||||
(sect.sct_type == SCT_MOUNT) ||
|
if (mobcost < 0
|
||||||
(sect.sct_type == SCT_SANCT) ||
|
|| sect.sct_type == SCT_MOUNT
|
||||||
(sect.sct_type == SCT_WASTE) ||
|
|| sect.sct_own != lp->lnd_own) {
|
||||||
(sect.sct_own != lp->lnd_own)) {
|
|
||||||
wu(0, lp->lnd_own, "%s %s,\nbut could not retreat to %s!\n",
|
wu(0, lp->lnd_own, "%s %s,\nbut could not retreat to %s!\n",
|
||||||
prland(lp),
|
prland(lp),
|
||||||
conditions[findcondition(code)].desc[orig],
|
conditions[findcondition(code)].desc[orig],
|
||||||
|
@ -471,7 +470,6 @@ retreat_land1(struct lndstr *lp, char code, int orig)
|
||||||
putland(lp->lnd_uid, lp);
|
putland(lp->lnd_uid, lp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
mobcost = lnd_mobcost(lp, §, MOB_MARCH);
|
|
||||||
lp->lnd_x = newx;
|
lp->lnd_x = newx;
|
||||||
lp->lnd_y = newy;
|
lp->lnd_y = newy;
|
||||||
lp->lnd_mobil -= mobcost;
|
lp->lnd_mobil -= mobcost;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue