Make land unit attack mobility cost consistent with march cost:
(att_mobcost): New. (ask_olist, take_move_in_mob): Use it. Attacking land units can now use roads and suffer the newly taken penalty. No difference in most cases, because the penalty commonly cancels the road bonus. (get_mob_support, calc_mobcost, ask_move_in_off): Use it. No functional change now; ensures that military's attack mobility cost will stay consistent with move cost. (MOB_NONE): Unused, remove. (sector_mcost): Simplify.
This commit is contained in:
parent
bcd35e15fb
commit
2e693275f1
3 changed files with 55 additions and 32 deletions
|
@ -164,7 +164,7 @@ extern int sctoff(coord x, coord y);
|
||||||
|
|
||||||
extern struct dchrstr dchr[SCT_MAXDEF + 1];
|
extern struct dchrstr dchr[SCT_MAXDEF + 1];
|
||||||
extern struct dchrstr bigcity_dchr;
|
extern struct dchrstr bigcity_dchr;
|
||||||
#define IS_BIG_CITY(sect) (dchr[(sect)].d_pkg == UPKG)
|
#define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG)
|
||||||
|
|
||||||
/* Minimal efficiency of sectors that can be knocked down (bridges) */
|
/* Minimal efficiency of sectors that can be knocked down (bridges) */
|
||||||
#define SCT_MINEFF 20
|
#define SCT_MINEFF 20
|
||||||
|
@ -178,10 +178,9 @@ extern struct dchrstr bigcity_dchr;
|
||||||
#define MIN_MOBCOST 0.001 /* lowest cost a sector can have to move into */
|
#define MIN_MOBCOST 0.001 /* lowest cost a sector can have to move into */
|
||||||
#define FORTEFF 5 /* forts must be 5% efficient to fire. */
|
#define FORTEFF 5 /* forts must be 5% efficient to fire. */
|
||||||
|
|
||||||
#define MOB_NONE 0
|
#define MOB_MOVE 0
|
||||||
#define MOB_MOVE 1
|
#define MOB_MARCH 1
|
||||||
#define MOB_MARCH 2
|
#define MOB_RAIL 2
|
||||||
#define MOB_RAIL 3
|
|
||||||
|
|
||||||
#define INT_ROAD 0
|
#define INT_ROAD 0
|
||||||
#define INT_RAIL 1
|
#define INT_RAIL 1
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
double
|
double
|
||||||
sector_mcost(struct sctstr *sp, int do_bonus)
|
sector_mcost(struct sctstr *sp, int mobtype)
|
||||||
{
|
{
|
||||||
double d;
|
double d;
|
||||||
|
|
||||||
|
@ -49,16 +49,15 @@ sector_mcost(struct sctstr *sp, int do_bonus)
|
||||||
if (d <= 0)
|
if (d <= 0)
|
||||||
return -1.0;
|
return -1.0;
|
||||||
|
|
||||||
if (do_bonus == MOB_MOVE || do_bonus == MOB_MARCH) {
|
if (mobtype == MOB_MOVE || mobtype == MOB_MARCH) {
|
||||||
d = d / (1.0 + sp->sct_road / 122.0);
|
d = d / (1.0 + sp->sct_road / 122.0);
|
||||||
} else if (do_bonus == MOB_RAIL) {
|
} else if (mobtype == MOB_RAIL) {
|
||||||
if (sp->sct_rail <= 0)
|
if (sp->sct_rail <= 0)
|
||||||
return -1.0;
|
return -1.0;
|
||||||
d = d / (1.0 + sp->sct_rail / 100.0);
|
d = d / (1.0 + sp->sct_rail / 100.0);
|
||||||
} else {
|
} else
|
||||||
if (d < 2.0)
|
CANT_REACH();
|
||||||
d = 2.0;
|
|
||||||
}
|
|
||||||
if (d < 1.0)
|
if (d < 1.0)
|
||||||
d = 1.0;
|
d = 1.0;
|
||||||
if (dchr[sp->sct_type].d_mcst < 25)
|
if (dchr[sp->sct_type].d_mcst < 25)
|
||||||
|
@ -66,10 +65,10 @@ sector_mcost(struct sctstr *sp, int do_bonus)
|
||||||
else
|
else
|
||||||
d = (d * 10.0 - sp->sct_effic) / 115;
|
d = (d * 10.0 - sp->sct_effic) / 115;
|
||||||
|
|
||||||
if (do_bonus == MOB_MOVE)
|
if (mobtype == MOB_MOVE)
|
||||||
return MAX(d, MIN_MOBCOST);
|
return MAX(d, MIN_MOBCOST);
|
||||||
if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0
|
if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0
|
||||||
&& do_bonus != MOB_RAIL)
|
&& mobtype != MOB_RAIL)
|
||||||
return MAX(d, LND_MINMOBCOST);
|
return MAX(d, LND_MINMOBCOST);
|
||||||
return MAX(d, 0.01);
|
return MAX(d, 0.01);
|
||||||
}
|
}
|
||||||
|
|
|
@ -783,21 +783,51 @@ att_ask_offense(int combat_mode, struct combat *off, struct combat *def,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return path cost for ATTACKER to enter sector given by DEF.
|
||||||
|
* MOBTYPE is a mobility type accepted by sector_mcost().
|
||||||
|
*/
|
||||||
|
static double
|
||||||
|
att_mobcost(natid attacker, struct combat *def, int mobtype)
|
||||||
|
{
|
||||||
|
struct sctstr sect;
|
||||||
|
int ok;
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(def->type != EF_SECTOR))
|
||||||
|
return -1.0;
|
||||||
|
ok = getsect(def->x, def->y, §);
|
||||||
|
if (CANT_HAPPEN(!ok))
|
||||||
|
return -1.0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We want the cost to move/march into the sector. If we just
|
||||||
|
* called sector_mcost(), we'd get the defender's cost. The
|
||||||
|
* attacker's cost is higher unless he's the old-owner. Note: if
|
||||||
|
* there are no civilians, a victorious attacker will become the
|
||||||
|
* old-owner. But he isn't now.
|
||||||
|
*/
|
||||||
|
sect.sct_own = attacker;
|
||||||
|
sect.sct_mobil = 0;
|
||||||
|
return sector_mcost(§, mobtype);
|
||||||
|
}
|
||||||
|
|
||||||
/* How many mil is off allowed to attack with when it attacks def? */
|
/* How many mil is off allowed to attack with when it attacks def? */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_mob_support(int combat_mode, struct combat *off, struct combat *def)
|
get_mob_support(int combat_mode, struct combat *off, struct combat *def)
|
||||||
{
|
{
|
||||||
int mob_support;
|
int mob_support;
|
||||||
|
double mobcost;
|
||||||
|
|
||||||
switch (combat_mode) {
|
switch (combat_mode) {
|
||||||
case A_ATTACK:
|
case A_ATTACK:
|
||||||
mob_support = off->mob / sector_mcost(getsectp(def->x, def->y),
|
mobcost = att_mobcost(off->own, def, MOB_MOVE);
|
||||||
MOB_MOVE);
|
if (mobcost < 0 || off->mob <= 0)
|
||||||
if (mob_support < 0)
|
return 0;
|
||||||
mob_support = 0;
|
mob_support = off->mob / mobcost;
|
||||||
if (mob_support < off->troops)
|
if (mob_support < off->troops)
|
||||||
pr("Sector %s has %d mobility which can only support %d mil,\n", xyas(off->x, off->y, player->cnum), off->mob, mob_support);
|
pr("Sector %s has %d mobility which can only support %d mil,\n",
|
||||||
|
xyas(off->x, off->y, player->cnum), off->mob, mob_support);
|
||||||
else
|
else
|
||||||
mob_support = off->troops;
|
mob_support = off->troops;
|
||||||
return mob_support;
|
return mob_support;
|
||||||
|
@ -850,10 +880,9 @@ calc_mobcost(int combat_mode, struct combat *off, struct combat *def,
|
||||||
return;
|
return;
|
||||||
switch (combat_mode) {
|
switch (combat_mode) {
|
||||||
case A_ATTACK:
|
case A_ATTACK:
|
||||||
off->mobcost +=
|
off->mobcost += MAX(1,
|
||||||
MAX(1,
|
(int)(attacking_mil
|
||||||
(int)(attacking_mil *
|
* att_mobcost(off->own, def, MOB_MOVE)));
|
||||||
sector_mcost(getsectp(def->x, def->y), MOB_MOVE)));
|
|
||||||
break;
|
break;
|
||||||
case A_LBOARD:
|
case A_LBOARD:
|
||||||
off->mobcost += MAX(1, attacking_mil / 5);
|
off->mobcost += MAX(1, attacking_mil / 5);
|
||||||
|
@ -1008,8 +1037,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 =
|
mobcost = lnd_pathcost(&land,
|
||||||
lnd_mobcost(&land, getsectp(def->x, def->y), MOB_NONE);
|
att_mobcost(off->own, def, MOB_MARCH));
|
||||||
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));
|
||||||
|
@ -1103,10 +1132,6 @@ att_combat_eff(struct combat *com)
|
||||||
return eff;
|
return eff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Estimate the defense strength and give the attacker a chance to abort
|
|
||||||
* if the odds are less than 50%
|
|
||||||
*/
|
|
||||||
int
|
int
|
||||||
att_get_offense(int combat_mode, struct combat *off,
|
att_get_offense(int combat_mode, struct combat *off,
|
||||||
struct emp_qelem *olist, struct combat *def)
|
struct emp_qelem *olist, struct combat *def)
|
||||||
|
@ -2441,7 +2466,7 @@ ask_move_in_off(struct combat *off, struct combat *def)
|
||||||
return;
|
return;
|
||||||
if (off->own != player->cnum)
|
if (off->own != player->cnum)
|
||||||
return;
|
return;
|
||||||
d = sector_mcost(getsectp(def->x, def->y), MOB_MOVE);
|
d = att_mobcost(off->own, def, MOB_MOVE);
|
||||||
if ((mob_support = MIN(off->troops, (int)(off->mob / d))) <= 0)
|
if ((mob_support = MIN(off->troops, (int)(off->mob / d))) <= 0)
|
||||||
return;
|
return;
|
||||||
sprintf(prompt, "How many mil to move in from %s (%d max)? ",
|
sprintf(prompt, "How many mil to move in from %s (%d max)? ",
|
||||||
|
@ -2503,8 +2528,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 =
|
mobcost = lnd_pathcost(&llp->land,
|
||||||
lnd_mobcost(&llp->land, getsectp(def->x, def->y), MOB_NONE);
|
att_mobcost(off->own, def, MOB_MARCH));
|
||||||
new = llp->land.lnd_mobil - mobcost;
|
new = llp->land.lnd_mobil - mobcost;
|
||||||
if (new < -127)
|
if (new < -127)
|
||||||
new = -127;
|
new = -127;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue