(att_reacting_units, attack_val, defense_val, intelligence_report):
Return double. Callers changed. (att_reacting_units): Remove silly truncation to int. (get_dlist): Return void, simplify.
This commit is contained in:
parent
3f23320a7e
commit
5dcd0dcd86
4 changed files with 28 additions and 46 deletions
|
@ -86,8 +86,8 @@ extern int att_get_offense(int, struct combat *, struct emp_qelem *,
|
||||||
extern int att_empty_attack(int, int, struct combat *);
|
extern int att_empty_attack(int, int, struct combat *);
|
||||||
extern int att_get_defense(struct emp_qelem *, struct combat *,
|
extern int att_get_defense(struct emp_qelem *, struct combat *,
|
||||||
struct emp_qelem *, int, int);
|
struct emp_qelem *, int, int);
|
||||||
extern int att_reacting_units(struct combat *, struct emp_qelem *, int,
|
extern double att_reacting_units(struct combat *, struct emp_qelem *, int,
|
||||||
int *, int);
|
int *, int);
|
||||||
extern int att_get_support(int, int, int, int, int, struct emp_qelem *,
|
extern int att_get_support(int, int, int, int, int, struct emp_qelem *,
|
||||||
struct combat *, struct emp_qelem *,
|
struct combat *, struct emp_qelem *,
|
||||||
struct combat *, double *, double *, int);
|
struct combat *, double *, double *, int);
|
||||||
|
|
|
@ -204,15 +204,15 @@ extern int lnd_mobtype(struct lndstr *);
|
||||||
extern double lnd_mobcost(struct lndstr *, struct sctstr *);
|
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 double attack_val(int, struct lndstr *);
|
||||||
extern int defense_val(struct lndstr *);
|
extern double defense_val(struct lndstr *);
|
||||||
extern void lnd_print(struct llist *, char *);
|
extern void lnd_print(struct llist *, char *);
|
||||||
extern void lnd_delete(struct llist *, char *);
|
extern void lnd_delete(struct llist *, char *);
|
||||||
extern int lnd_take_casualty(int, struct llist *, int);
|
extern int lnd_take_casualty(int, struct llist *, int);
|
||||||
extern void lnd_submil(struct lndstr *, int);
|
extern void lnd_submil(struct lndstr *, int);
|
||||||
extern void lnd_takemob(struct emp_qelem *, double);
|
extern void lnd_takemob(struct emp_qelem *, double);
|
||||||
extern int lnd_spyval(struct lndstr *);
|
extern int lnd_spyval(struct lndstr *);
|
||||||
extern int intelligence_report(int, struct lndstr *, int, char *);
|
extern double intelligence_report(int, struct lndstr *, int, char *);
|
||||||
extern int count_sect_units(struct sctstr *);
|
extern int count_sect_units(struct sctstr *);
|
||||||
extern void count_units(struct shpstr *);
|
extern void count_units(struct shpstr *);
|
||||||
extern void lnd_count_units(struct lndstr *);
|
extern void lnd_count_units(struct lndstr *);
|
||||||
|
|
|
@ -71,8 +71,8 @@ static int board_abort(struct combat *off, struct combat *def);
|
||||||
static int land_board_abort(struct combat *off, struct combat *def);
|
static int land_board_abort(struct combat *off, struct combat *def);
|
||||||
static int ask_off(int combat_mode, struct combat *off,
|
static int ask_off(int combat_mode, struct combat *off,
|
||||||
struct combat *def);
|
struct combat *def);
|
||||||
static int get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
|
static void get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
int *d_spyp);
|
int *d_spyp);
|
||||||
static int get_ototal(int combat_mode, struct combat *off,
|
static int get_ototal(int combat_mode, struct combat *off,
|
||||||
struct emp_qelem *olist, double osupport, int check);
|
struct emp_qelem *olist, double osupport, int check);
|
||||||
static int get_dtotal(struct combat *def, struct emp_qelem *list,
|
static int get_dtotal(struct combat *def, struct emp_qelem *list,
|
||||||
|
@ -982,7 +982,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
|
||||||
double mobcost;
|
double mobcost;
|
||||||
struct llist *llp;
|
struct llist *llp;
|
||||||
struct lchrstr *lcp;
|
struct lchrstr *lcp;
|
||||||
int att_val;
|
double att_val;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int maxland = 0;
|
int maxland = 0;
|
||||||
int first_time = 1;
|
int first_time = 1;
|
||||||
|
@ -1057,7 +1057,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
att_val = attack_val(combat_mode, &land);
|
att_val = attack_val(combat_mode, &land);
|
||||||
if (!att_val) {
|
if (att_val < 1.0) {
|
||||||
pr("%s has no offensive strength\n", prland(&land));
|
pr("%s has no offensive strength\n", prland(&land));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1072,7 +1072,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
|
||||||
first_time = 0;
|
first_time = 0;
|
||||||
pr("You may board with a maximum of %d land units\n", maxland);
|
pr("You may board with a maximum of %d land units\n", maxland);
|
||||||
}
|
}
|
||||||
pr("%s has a base %s value of %d\n",
|
pr("%s has a base %s value of %.0f\n",
|
||||||
prland(&land), att_mode[combat_mode], att_val);
|
prland(&land), att_mode[combat_mode], att_val);
|
||||||
if (land_answer[(int)land.lnd_army] != 'Y') {
|
if (land_answer[(int)land.lnd_army] != 'Y') {
|
||||||
sprintf(prompt,
|
sprintf(prompt,
|
||||||
|
@ -1125,7 +1125,6 @@ att_combat_eff(struct combat *com)
|
||||||
eff = 1.0 + ((str - 1.0) * eff);
|
eff = 1.0 + ((str - 1.0) * eff);
|
||||||
} else
|
} else
|
||||||
eff = sector_strength(getsectp(com->x, com->y));
|
eff = sector_strength(getsectp(com->x, com->y));
|
||||||
/* str = com->sct_dcp->d_dstr;*/
|
|
||||||
} else if (com->type == EF_SHIP && com->own != player->cnum) {
|
} else if (com->type == EF_SHIP && com->own != player->cnum) {
|
||||||
getship(com->shp_uid, &ship);
|
getship(com->shp_uid, &ship);
|
||||||
eff = 1.0 + ship.shp_armor / 100.0;
|
eff = 1.0 + ship.shp_armor / 100.0;
|
||||||
|
@ -1191,14 +1190,13 @@ att_get_defense(struct emp_qelem *olist, struct combat *def,
|
||||||
|
|
||||||
/* Get the defensive land units in the sector or on the ship */
|
/* Get the defensive land units in the sector or on the ship */
|
||||||
|
|
||||||
static int
|
static void
|
||||||
get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
|
get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
int *d_spyp)
|
int *d_spyp)
|
||||||
{
|
{
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
struct llist *llp;
|
struct llist *llp;
|
||||||
struct lndstr land;
|
struct lndstr land;
|
||||||
int estimate = 0;
|
|
||||||
|
|
||||||
/* In here is where you need to take out spies and trains from the defending
|
/* In here is where you need to take out spies and trains from the defending
|
||||||
lists. Spies try to hide, trains get trapped and can be boarded. */
|
lists. Spies try to hide, trains get trapped and can be boarded. */
|
||||||
|
@ -1218,15 +1216,14 @@ get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
if (def->type == EF_LAND && land.lnd_land != def->lnd_uid)
|
if (def->type == EF_LAND && land.lnd_land != def->lnd_uid)
|
||||||
continue;
|
continue;
|
||||||
if (!list) { /* Just estimating the enemy strength */
|
if (!list) { /* Just estimating the enemy strength */
|
||||||
estimate += intelligence_report(player->cnum,
|
intelligence_report(player->cnum, &land, a_spy,
|
||||||
&land, a_spy,
|
"Scouts report defending unit:");
|
||||||
"Scouts report defending unit:");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(llp = malloc(sizeof(struct llist)))) {
|
if (!(llp = malloc(sizeof(struct llist)))) {
|
||||||
logerror("Malloc failed in attack!\n");
|
logerror("Malloc failed in attack!\n");
|
||||||
abort_attack();
|
abort_attack();
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
memset(llp, 0, sizeof(struct llist));
|
memset(llp, 0, sizeof(struct llist));
|
||||||
emp_insque(&llp->queue, list);
|
emp_insque(&llp->queue, list);
|
||||||
|
@ -1236,7 +1233,6 @@ get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
if (lnd_spyval(&land) > *d_spyp)
|
if (lnd_spyval(&land) > *d_spyp)
|
||||||
*d_spyp = lnd_spyval(&land);
|
*d_spyp = lnd_spyval(&land);
|
||||||
}
|
}
|
||||||
return estimate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate the total offensive strength */
|
/* Calculate the total offensive strength */
|
||||||
|
@ -1318,7 +1314,6 @@ get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport,
|
||||||
for (qp = list->q_forw; qp != list; qp = next) {
|
for (qp = list->q_forw; qp != list; qp = next) {
|
||||||
next = qp->q_forw;
|
next = qp->q_forw;
|
||||||
llp = (struct llist *)qp;
|
llp = (struct llist *)qp;
|
||||||
d_unit = 0.0;
|
|
||||||
if (check && !get_land(A_DEFEND, def, llp->land.lnd_uid, llp, 1))
|
if (check && !get_land(A_DEFEND, def, llp->land.lnd_uid, llp, 1))
|
||||||
continue;
|
continue;
|
||||||
d_unit = defense_val(&llp->land);
|
d_unit = defense_val(&llp->land);
|
||||||
|
@ -1456,7 +1451,7 @@ put_land(struct emp_qelem *list)
|
||||||
* Note that the "strength" command also calls this routine.
|
* Note that the "strength" command also calls this routine.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
double
|
||||||
att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
int *d_spyp, int ototal)
|
int *d_spyp, int ototal)
|
||||||
{
|
{
|
||||||
|
@ -1465,7 +1460,7 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
struct sctstr sect, dsect;
|
struct sctstr sect, dsect;
|
||||||
struct llist *llp;
|
struct llist *llp;
|
||||||
int dtotal;
|
int dtotal;
|
||||||
int new_land = 0;
|
double new_land = 0;
|
||||||
double mobcost;
|
double mobcost;
|
||||||
double pathcost;
|
double pathcost;
|
||||||
int dist;
|
int dist;
|
||||||
|
@ -1474,22 +1469,12 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
double eff = att_combat_eff(def);
|
double eff = att_combat_eff(def);
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* All units that are within their reaction radius and not damaged
|
|
||||||
* below their morale value now get to react to the threatened sect.
|
|
||||||
* Once we've sent enough to counter the threat, stop sending them.
|
|
||||||
*
|
|
||||||
* Not anymore. All units get to react. :)
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (list)
|
if (list)
|
||||||
dtotal = get_dtotal(def, list, 1.0, 1);
|
dtotal = get_dtotal(def, list, 1.0, 1);
|
||||||
else
|
else
|
||||||
dtotal = 0;
|
dtotal = 0;
|
||||||
snxtitem_all(&ni, EF_LAND);
|
snxtitem_all(&ni, EF_LAND);
|
||||||
while (nxtitem(&ni, &land) &&
|
while (nxtitem(&ni, &land) && dtotal + new_land * eff < 1.2 * ototal) {
|
||||||
(dtotal + new_land * eff < (int)(1.2 * ototal))) {
|
|
||||||
if (!land.lnd_own)
|
if (!land.lnd_own)
|
||||||
continue;
|
continue;
|
||||||
if (!land.lnd_rad_max)
|
if (!land.lnd_rad_max)
|
||||||
|
@ -1502,12 +1487,8 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
|
||||||
continue;
|
continue;
|
||||||
if (land.lnd_land >= 0)
|
if (land.lnd_land >= 0)
|
||||||
continue;
|
continue;
|
||||||
if (!defense_val(&land))
|
if (defense_val(&land) < 1.0)
|
||||||
continue;
|
continue;
|
||||||
/*
|
|
||||||
if (land.lnd_effic <= land.lnd_retreat)
|
|
||||||
continue;
|
|
||||||
*/
|
|
||||||
if (!lnd_can_attack(&land))
|
if (!lnd_can_attack(&land))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
static void lnd_mess(char *, struct llist *);
|
static void lnd_mess(char *, struct llist *);
|
||||||
static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
|
static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
|
||||||
|
|
||||||
int
|
double
|
||||||
attack_val(int combat_mode, struct lndstr *lp)
|
attack_val(int combat_mode, struct lndstr *lp)
|
||||||
{
|
{
|
||||||
int men;
|
int men;
|
||||||
|
@ -81,20 +81,20 @@ attack_val(int combat_mode, struct lndstr *lp)
|
||||||
|
|
||||||
switch (combat_mode) {
|
switch (combat_mode) {
|
||||||
case A_ATTACK:
|
case A_ATTACK:
|
||||||
return (int)value;
|
return value;
|
||||||
case A_ASSAULT:
|
case A_ASSAULT:
|
||||||
if (!(lcp->l_flags & L_MARINE))
|
if (!(lcp->l_flags & L_MARINE))
|
||||||
return (int)(assault_penalty * value);
|
return assault_penalty * value;
|
||||||
break;
|
break;
|
||||||
case A_BOARD:
|
case A_BOARD:
|
||||||
if (!(lcp->l_flags & L_MARINE))
|
if (!(lcp->l_flags & L_MARINE))
|
||||||
return (int)(assault_penalty * men);
|
return assault_penalty * men;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
double
|
||||||
defense_val(struct lndstr *lp)
|
defense_val(struct lndstr *lp)
|
||||||
{
|
{
|
||||||
int men;
|
int men;
|
||||||
|
@ -122,7 +122,7 @@ defense_val(struct lndstr *lp)
|
||||||
if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
|
if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return (int)value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -245,6 +245,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
|
||||||
/* retreat to bx,by */
|
/* retreat to bx,by */
|
||||||
llp->land.lnd_x = bx;
|
llp->land.lnd_x = bx;
|
||||||
llp->land.lnd_y = by;
|
llp->land.lnd_y = by;
|
||||||
|
/* FIXME landmines */
|
||||||
getsect(bx, by, &rsect);
|
getsect(bx, by, &rsect);
|
||||||
mob = llp->land.lnd_mobil - (int)bmcost;
|
mob = llp->land.lnd_mobil - (int)bmcost;
|
||||||
if (mob < -127)
|
if (mob < -127)
|
||||||
|
@ -324,7 +325,7 @@ lnd_spyval(struct lndstr *lp)
|
||||||
return lp->lnd_spy * (lp->lnd_effic / 100.0);
|
return lp->lnd_spy * (lp->lnd_effic / 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
double
|
||||||
intelligence_report(int destination, struct lndstr *lp, int spy,
|
intelligence_report(int destination, struct lndstr *lp, int spy,
|
||||||
char *mess)
|
char *mess)
|
||||||
{
|
{
|
||||||
|
@ -391,7 +392,7 @@ intelligence_report(int destination, struct lndstr *lp, int spy,
|
||||||
if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
|
if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE)
|
||||||
estimate *= lp->lnd_def;
|
estimate *= lp->lnd_def;
|
||||||
|
|
||||||
return (int)estimate;
|
return estimate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used by the spy command to count land units in a sector. If used
|
/* Used by the spy command to count land units in a sector. If used
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue