(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:
Markus Armbruster 2006-06-15 18:55:15 +00:00
parent 3f23320a7e
commit 5dcd0dcd86
4 changed files with 28 additions and 46 deletions

View file

@ -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_get_defense(struct emp_qelem *, struct combat *,
struct emp_qelem *, int, int);
extern int att_reacting_units(struct combat *, struct emp_qelem *, int,
int *, int);
extern double att_reacting_units(struct combat *, struct emp_qelem *, int,
int *, int);
extern int att_get_support(int, int, int, int, int, struct emp_qelem *,
struct combat *, struct emp_qelem *,
struct combat *, double *, double *, int);

View file

@ -204,15 +204,15 @@ extern int lnd_mobtype(struct lndstr *);
extern double lnd_mobcost(struct lndstr *, struct sctstr *);
extern char *lnd_path(int, struct lndstr *, char *);
extern int attack_val(int, struct lndstr *);
extern int defense_val(struct lndstr *);
extern double attack_val(int, struct lndstr *);
extern double defense_val(struct lndstr *);
extern void lnd_print(struct llist *, char *);
extern void lnd_delete(struct llist *, char *);
extern int lnd_take_casualty(int, struct llist *, int);
extern void lnd_submil(struct lndstr *, int);
extern void lnd_takemob(struct emp_qelem *, double);
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 void count_units(struct shpstr *);
extern void lnd_count_units(struct lndstr *);

View file

@ -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 ask_off(int combat_mode, struct combat *off,
struct combat *def);
static int get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
int *d_spyp);
static void get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
int *d_spyp);
static int get_ototal(int combat_mode, struct combat *off,
struct emp_qelem *olist, double osupport, int check);
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;
struct llist *llp;
struct lchrstr *lcp;
int att_val;
double att_val;
int count = 0;
int maxland = 0;
int first_time = 1;
@ -1057,7 +1057,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
return;
}
att_val = attack_val(combat_mode, &land);
if (!att_val) {
if (att_val < 1.0) {
pr("%s has no offensive strength\n", prland(&land));
continue;
}
@ -1072,7 +1072,7 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
first_time = 0;
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);
if (land_answer[(int)land.lnd_army] != 'Y') {
sprintf(prompt,
@ -1125,7 +1125,6 @@ att_combat_eff(struct combat *com)
eff = 1.0 + ((str - 1.0) * eff);
} else
eff = sector_strength(getsectp(com->x, com->y));
/* str = com->sct_dcp->d_dstr;*/
} else if (com->type == EF_SHIP && com->own != player->cnum) {
getship(com->shp_uid, &ship);
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 */
static int
static void
get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
int *d_spyp)
{
struct nstr_item ni;
struct llist *llp;
struct lndstr land;
int estimate = 0;
/* 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. */
@ -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)
continue;
if (!list) { /* Just estimating the enemy strength */
estimate += intelligence_report(player->cnum,
&land, a_spy,
"Scouts report defending unit:");
intelligence_report(player->cnum, &land, a_spy,
"Scouts report defending unit:");
continue;
}
if (!(llp = malloc(sizeof(struct llist)))) {
logerror("Malloc failed in attack!\n");
abort_attack();
return 0;
return;
}
memset(llp, 0, sizeof(struct llist));
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)
*d_spyp = lnd_spyval(&land);
}
return estimate;
}
/* 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) {
next = qp->q_forw;
llp = (struct llist *)qp;
d_unit = 0.0;
if (check && !get_land(A_DEFEND, def, llp->land.lnd_uid, llp, 1))
continue;
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.
*/
int
double
att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
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 llist *llp;
int dtotal;
int new_land = 0;
double new_land = 0;
double mobcost;
double pathcost;
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);
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)
dtotal = get_dtotal(def, list, 1.0, 1);
else
dtotal = 0;
snxtitem_all(&ni, EF_LAND);
while (nxtitem(&ni, &land) &&
(dtotal + new_land * eff < (int)(1.2 * ototal))) {
while (nxtitem(&ni, &land) && dtotal + new_land * eff < 1.2 * ototal) {
if (!land.lnd_own)
continue;
if (!land.lnd_rad_max)
@ -1502,12 +1487,8 @@ att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy,
continue;
if (land.lnd_land >= 0)
continue;
if (!defense_val(&land))
if (defense_val(&land) < 1.0)
continue;
/*
if (land.lnd_effic <= land.lnd_retreat)
continue;
*/
if (!lnd_can_attack(&land))
continue;

View file

@ -56,7 +56,7 @@
static void lnd_mess(char *, struct llist *);
static int lnd_hit_mine(struct lndstr *, struct lchrstr *);
int
double
attack_val(int combat_mode, struct lndstr *lp)
{
int men;
@ -81,20 +81,20 @@ attack_val(int combat_mode, struct lndstr *lp)
switch (combat_mode) {
case A_ATTACK:
return (int)value;
return value;
case A_ASSAULT:
if (!(lcp->l_flags & L_MARINE))
return (int)(assault_penalty * value);
return assault_penalty * value;
break;
case A_BOARD:
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)
{
int men;
@ -122,7 +122,7 @@ defense_val(struct lndstr *lp)
if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY))
return 1;
return (int)value;
return value;
}
void
@ -245,6 +245,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
/* retreat to bx,by */
llp->land.lnd_x = bx;
llp->land.lnd_y = by;
/* FIXME landmines */
getsect(bx, by, &rsect);
mob = llp->land.lnd_mobil - (int)bmcost;
if (mob < -127)
@ -324,7 +325,7 @@ lnd_spyval(struct lndstr *lp)
return lp->lnd_spy * (lp->lnd_effic / 100.0);
}
int
double
intelligence_report(int destination, struct lndstr *lp, int spy,
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)
estimate *= lp->lnd_def;
return (int)estimate;
return estimate;
}
/* Used by the spy command to count land units in a sector. If used