(lnd_getmil, total_mil): Trivial, inline into callers and remove. The

abstraction from actual land unit mil encoding provided by them was
too leaky to be relied upon anyway.
This commit is contained in:
Markus Armbruster 2006-05-20 16:39:58 +00:00
parent 3a38e91a5c
commit 2732ac5d1d
15 changed files with 43 additions and 62 deletions

View file

@ -203,9 +203,7 @@ extern double lnd_mobcost(struct lndstr *, struct sctstr *, int);
extern char *lnd_path(int, struct lndstr *, char *);
extern int attack_val(int, struct lndstr *);
extern int total_mil(struct lndstr *);
extern int defense_val(struct lndstr *);
extern int lnd_getmil(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);

View file

@ -101,7 +101,7 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
*/
snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
while (nxtitem(&ni, &land)) {
mil += lnd_getmil(&land);
mil += land.lnd_item[I_MILIT];
/* Anti-terrorist units count double */
if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
@ -115,7 +115,7 @@ do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real)
land.lnd_mobil -= 10;
if (for_real)
putland(land.lnd_uid, &land);
mil += lnd_getmil(&land);
mil += land.lnd_item[I_MILIT];
}
}
/*

View file

@ -79,7 +79,7 @@ land(void)
prxy(" %4d,%-4d", land.lnd_x, land.lnd_y, player->cnum);
pr("%c", land.lnd_army);
pr("%4d%%", land.lnd_effic);
pr("%4d", lnd_getmil(&land));
pr("%4d", land.lnd_item[I_MILIT]);
pr("%4d", land.lnd_harden);
pr("%4d", land.lnd_mobil);
pr("%4d", land.lnd_item[I_FOOD]);

View file

@ -335,7 +335,7 @@ ldump(void)
pr(" %d", land.lnd_effic);
break;
case 6:
pr(" %d", lnd_getmil(&land));
pr(" %d", land.lnd_item[I_MILIT]);
break;
case 7:
pr(" %d", land.lnd_harden);

View file

@ -206,7 +206,7 @@ llook(void)
continue;
/* Spies don't need military to do a "llook". Other
units do */
if ((lnd_getmil(&myland) <= 0) &&
if ((myland.lnd_item[I_MILIT] <= 0) &&
!(lchr[(int)myland.lnd_type].l_flags & L_SPY))
continue;
look_land(&myland);
@ -288,7 +288,7 @@ look_land(struct lndstr *lookland)
pr("%s (#%d) %s (approx %d mil) @ %s\n",
cname(lp->lnd_own), lp->lnd_own,
prland(lp), roundintby(total_mil(lp), 20),
prland(lp), roundintby(lp->lnd_item[I_MILIT], 20),
xyas(lp->lnd_x, lp->lnd_y, player->cnum));
if (opt_HIDDEN)
setcont(player->cnum, lp->lnd_own, FOUND_LOOK);

View file

@ -172,7 +172,7 @@ multifire(void)
pr("Unit %d cannot fire!\n", fland.lnd_uid);
continue;
}
if (lnd_getmil(&fland) < 1) {
if (fland.lnd_item[I_MILIT] < 1) {
pr("Unit %d cannot fire because it has no military!\n",
fland.lnd_uid);
continue;
@ -856,7 +856,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
if (land.lnd_land >= 0)
continue;
/* Gotta have military */
if (lnd_getmil(&land) < 1)
if (land.lnd_item[I_MILIT] < 1)
continue;
/* Don't shoot yourself */
if (land.lnd_own == aown)

View file

@ -80,10 +80,10 @@ shoo(void)
nsec = 0;
snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
while (nxtitem(&ni, &land)) {
mil += total_mil(&land);
mil += land.lnd_item[I_MILIT];
if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) {
mil += total_mil(&land);
mil += land.lnd_item[I_MILIT];
nsec++;
}
}

View file

@ -1751,7 +1751,7 @@ count_bodies(struct combat *off, struct emp_qelem *list)
bodies += off[n].troops;
for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
llp = (struct llist *)qp;
bodies += total_mil(&llp->land);
bodies += llp->land.lnd_item[I_MILIT];
}
return bodies;
}
@ -2117,8 +2117,8 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist)
for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
llp = (struct llist *)qp;
if (total_mil(&llp->land) > biggest_mil) {
biggest_mil = total_mil(&llp->land);
if (llp->land.lnd_item[I_MILIT] > biggest_mil) {
biggest_mil = llp->land.lnd_item[I_MILIT];
biggest = qp;
}
}

View file

@ -60,7 +60,7 @@ military_control(struct sctstr *sp)
snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
while (nxtitem(&ni, &land)) {
if (land.lnd_own == sp->sct_own)
tot_mil += total_mil(&land);
tot_mil += land.lnd_item[I_MILIT];
}
if ((sp->sct_item[I_MILIT] + tot_mil) * 10 < sp->sct_item[I_CIVIL])
return 0;

View file

@ -78,7 +78,7 @@ attack_val(int combat_mode, struct lndstr *lp)
if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT)
return 1;
men = total_mil(lp);
men = lp->lnd_item[I_MILIT];
value = ldround(((double)men * (double)lp->lnd_att), 1);
@ -115,7 +115,7 @@ defense_val(struct lndstr *lp)
lcp = &lchr[(int)lp->lnd_type];
men = total_mil(lp);
men = lp->lnd_item[I_MILIT];
if (men < 0)
men = 0;
@ -138,20 +138,6 @@ defense_val(struct lndstr *lp)
return (int)value;
}
int
total_mil(struct lndstr *lp)
{
struct lchrstr *lcp;
double men;
lcp = &lchr[(int)lp->lnd_type];
men = lnd_getmil(lp);
/* men *= ((double)lp->lnd_effic)/100.0;*/
return ldround(men, 1);
}
void
lnd_print(struct llist *llp, char *s)
{
@ -193,7 +179,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
signed char orig;
int mob;
taken = lnd_getmil(&llp->land);
taken = llp->land.lnd_item[I_MILIT];
/* Spies always die */
if (llp->lcp->l_flags & L_SPY) {
eff_eq = 100;
@ -214,7 +200,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
return taken;
} else {
/* Ok, now, how many did we take off? (sould be the diff) */
taken = taken - lnd_getmil(&llp->land);
taken = taken - llp->land.lnd_item[I_MILIT];
}
if (llp->land.lnd_effic >= llp->land.lnd_retreat)
@ -332,11 +318,6 @@ lnd_takemob(struct emp_qelem *list, double loss)
llp->land.lnd_mobil = (signed char)new;
}
}
int
lnd_getmil(struct lndstr *lp)
{
return lp->lnd_item[I_MILIT];
}
void
lnd_submil(struct lndstr *lp, int num)
@ -379,18 +360,19 @@ intelligence_report(int destination, struct lndstr *lp, int spy,
else
sprintf(buf1, "%s %s", mess, prland(lp));
estimate = lnd_getmil(lp);
estimate = lp->lnd_item[I_MILIT];
if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
if (destination == player->cnum)
pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5),
roundintby(lnd_getmil(lp), 10));
pr(" (eff %d, mil %d",
roundintby(lp->lnd_effic, 5),
roundintby(lp->lnd_item[I_MILIT], 10));
else
sprintf(buf2, " (eff %d, mil %d",
roundintby(lp->lnd_effic, 5),
roundintby(lnd_getmil(lp), 10));
estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0;
roundintby(lp->lnd_item[I_MILIT], 10));
estimate = lp->lnd_item[I_MILIT] * lp->lnd_effic / 100.0;
if (chance((double)(spy + lp->lnd_vis) / 20.0)) {
int t;
@ -600,7 +582,7 @@ lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp,
}
if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) &&
!(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) &&
lnd_getmil(&llp->land) == 0) {
llp->land.lnd_item[I_MILIT] == 0) {
lnd_mess("has no mil on it to guide it", llp);
continue;
}

View file

@ -468,7 +468,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
if ((lp->lnd_ship != -1) || (lp->lnd_land != -1))
continue;
if (lnd_getmil(lp) < 1)
if (lp->lnd_item[I_MILIT] < 1)
continue;
range = roundrange(effrange(lp->lnd_frg, lp->lnd_tech));

View file

@ -439,7 +439,7 @@ get_minimum(struct lndstr *lp, i_type type)
if (opt_NOFOOD)
return 0; /* no food reqd, get out */
want = (((double)etu_per_update * eatrate) *
(double)total_mil(lp)) + 1;
(double)lp->lnd_item[I_MILIT]) + 1;
break;
case I_SHELL:
want = lp->lnd_ammo;

View file

@ -351,7 +351,7 @@ feed_land(struct lndstr *lp, int etus, int *needed, int doit)
if (opt_NOFOOD)
return 0; /* no food no work to be done */
total_people = total_mil(lp);
total_people = lp->lnd_item[I_MILIT];
food_eaten = etus * eatrate * total_people;
ifood_eaten = (int)food_eaten;
if (food_eaten - ifood_eaten > 0)

View file

@ -174,15 +174,15 @@ guerrilla(struct sctstr *sp)
if (lp->lnd_own != sp->sct_own)
continue;
mil += lnd_getmil(lp);
mil += lp->lnd_item[I_MILIT];
/* Security troops can now kill up to 1/2 their complement each
update, before doing anything else. */
if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY) {
int che_kill, r;
mil += lnd_getmil(lp);
r = (lnd_getmil(lp) * lp->lnd_effic) / 500;
mil += lp->lnd_item[I_MILIT];
r = (lp->lnd_item[I_MILIT] * lp->lnd_effic) / 500;
che_kill = r < 1 ? 0 : roll(r);
if (che_kill > che)
che_kill = che;
@ -477,14 +477,15 @@ take_casualties(struct sctstr *sp, int mc)
if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
continue;
cantake = ((lp->lnd_effic - 40) / 100.0) * lnd_getmil(lp) * 2.0;
cantake = ((lp->lnd_effic - 40) / 100.0)
* lp->lnd_item[I_MILIT] * 2.0;
if (cantake >= each) {
deq = ((double)each / (lnd_getmil(lp) * 2.0)) * 100.0;
deq = (each / (lp->lnd_item[I_MILIT] * 2.0)) * 100.0;
mc -= each;
} else if (cantake > 0) {
deq = ((double)cantake / (lnd_getmil(lp) * 2.0)) * 100.0;
mc -= (deq / 100.0) * lnd_getmil(lp) * 2.0;
deq = (cantake / (lp->lnd_item[I_MILIT] * 2.0)) * 100.0;
mc -= (deq / 100.0) * lp->lnd_item[I_MILIT] * 2.0;
} else
deq = 0;
@ -502,14 +503,14 @@ take_casualties(struct sctstr *sp, int mc)
if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
continue;
cantake = ((lp->lnd_effic - 40) / 100.0) * lnd_getmil(lp);
cantake = ((lp->lnd_effic - 40) / 100.0) * lp->lnd_item[I_MILIT];
if (cantake >= each) {
deq = ((double)each / (lnd_getmil(lp) * 2.0)) * 100.0;
deq = ((double)each / (lp->lnd_item[I_MILIT] * 2.0)) * 100.0;
mc -= each;
} else if (cantake > 0) {
deq = ((double)cantake / lnd_getmil(lp)) * 100.0;
mc -= (deq / 100.0) * lnd_getmil(lp);
deq = ((double)cantake / lp->lnd_item[I_MILIT]) * 100.0;
mc -= (deq / 100.0) * lp->lnd_item[I_MILIT];
} else
deq = 0;
@ -528,7 +529,7 @@ take_casualties(struct sctstr *sp, int mc)
if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY)
continue;
mc -= (lp->lnd_effic / 100.0) * lnd_getmil(lp);
mc -= (lp->lnd_effic / 100.0) * lp->lnd_item[I_MILIT];
lp->lnd_effic = 0;
lnd_submil(lp, 1000); /* Remove 'em all */
wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n",
@ -546,7 +547,7 @@ take_casualties(struct sctstr *sp, int mc)
if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY))
continue;
mc -= (lp->lnd_effic / 100.0) * lnd_getmil(lp) * 2.0;
mc -= (lp->lnd_effic / 100.0) * lp->lnd_item[I_MILIT] * 2.0;
lp->lnd_effic = 0;
lnd_submil(lp, 1000); /* Kill 'em all */
wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n",

View file

@ -431,7 +431,7 @@ feed_ship(struct shpstr *sp, int etus, int *needed, int doit)
if (lp->lnd_ship != sp->shp_uid)
continue;
need = ifood_eaten - sp->shp_item[I_FOOD];
land_eaten = etus * eatrate * lnd_getmil(lp);
land_eaten = etus * eatrate * lp->lnd_item[I_MILIT];
if (lp->lnd_item[I_FOOD] - need > land_eaten) {
sp->shp_item[I_FOOD] += need;
lp->lnd_item[I_FOOD] -= need;