From 2732ac5d1dcfcdfebd460317e5a076e8afda37d7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 20 May 2006 16:39:58 +0000 Subject: [PATCH] (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. --- include/land.h | 2 -- src/lib/commands/conv.c | 4 ++-- src/lib/commands/land.c | 2 +- src/lib/commands/ldump.c | 2 +- src/lib/commands/look.c | 4 ++-- src/lib/commands/mfir.c | 4 ++-- src/lib/commands/shoo.c | 4 ++-- src/lib/subs/attsub.c | 6 +++--- src/lib/subs/control.c | 2 +- src/lib/subs/lndsub.c | 40 +++++++++++----------------------------- src/lib/subs/mission.c | 2 +- src/lib/subs/supply.c | 2 +- src/lib/update/land.c | 2 +- src/lib/update/revolt.c | 27 ++++++++++++++------------- src/lib/update/ship.c | 2 +- 15 files changed, 43 insertions(+), 62 deletions(-) diff --git a/include/land.h b/include/land.h index 82fa51d9b..7887fe088 100644 --- a/include/land.h +++ b/include/land.h @@ -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); diff --git a/src/lib/commands/conv.c b/src/lib/commands/conv.c index 89e511799..160daa929 100644 --- a/src/lib/commands/conv.c +++ b/src/lib/commands/conv.c @@ -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]; } } /* diff --git a/src/lib/commands/land.c b/src/lib/commands/land.c index e6a02fad2..a82a7d035 100644 --- a/src/lib/commands/land.c +++ b/src/lib/commands/land.c @@ -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]); diff --git a/src/lib/commands/ldump.c b/src/lib/commands/ldump.c index 08e4f1c3a..b6d9295ca 100644 --- a/src/lib/commands/ldump.c +++ b/src/lib/commands/ldump.c @@ -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); diff --git a/src/lib/commands/look.c b/src/lib/commands/look.c index ba51cd9b1..137fb0c57 100644 --- a/src/lib/commands/look.c +++ b/src/lib/commands/look.c @@ -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); diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index c3a5c6fe7..70cd0f4ab 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -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) diff --git a/src/lib/commands/shoo.c b/src/lib/commands/shoo.c index 44fd9fd13..28657c0d5 100644 --- a/src/lib/commands/shoo.c +++ b/src/lib/commands/shoo.c @@ -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++; } } diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 39321771d..e5d5bbda1 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -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; } } diff --git a/src/lib/subs/control.c b/src/lib/subs/control.c index 7193f7bfc..9c8bc68b0 100644 --- a/src/lib/subs/control.c +++ b/src/lib/subs/control.c @@ -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; diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 19d4d5655..f4b04ddb3 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -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; } diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index a4c48de49..27599f3e2 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -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)); diff --git a/src/lib/subs/supply.c b/src/lib/subs/supply.c index 04b0814e0..f1fce1e2b 100644 --- a/src/lib/subs/supply.c +++ b/src/lib/subs/supply.c @@ -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; diff --git a/src/lib/update/land.c b/src/lib/update/land.c index b4b4a3d25..3defbdb42 100644 --- a/src/lib/update/land.c +++ b/src/lib/update/land.c @@ -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) diff --git a/src/lib/update/revolt.c b/src/lib/update/revolt.c index a76db9cc8..fb6226cd7 100644 --- a/src/lib/update/revolt.c +++ b/src/lib/update/revolt.c @@ -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", diff --git a/src/lib/update/ship.c b/src/lib/update/ship.c index 3f3a1755e..07e2dce48 100644 --- a/src/lib/update/ship.c +++ b/src/lib/update/ship.c @@ -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; -- 2.43.0